Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions res/layout/new_incoming.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
android:layout_height="match_parent"
android:background="@color/main_app_color">

<SurfaceView
android:id="@+id/PREVIEW"
android:layout_width="1dip"
android:layout_height="1dip"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
79 changes: 0 additions & 79 deletions src/org/linphone/CameraPreviewTorch.java

This file was deleted.

16 changes: 11 additions & 5 deletions src/org/linphone/InCallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ of the License, or (at your option) any later version.
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
Expand All @@ -42,6 +43,7 @@ of the License, or (at your option) any later version.
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
Expand Down Expand Up @@ -85,6 +87,7 @@ of the License, or (at your option) any later version.
import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.ui.Numpad;
import org.linphone.vtcsecure.LinphoneTorchFlasher;
import org.linphone.vtcsecure.Utils;
import org.linphone.vtcsecure.g;

Expand Down Expand Up @@ -2498,6 +2501,7 @@ protected void onDestroy() {

if(isFlashing) {
isFlashing = false;
LinphoneTorchFlasher.instance().stopFlashTorch();
HueController.getInstance().stopFlashing();
}
LinphoneService.instance().setActivityToLaunchOnIncomingReceived(LinphoneActivity.class);
Expand Down Expand Up @@ -2854,7 +2858,7 @@ void invalidateHeader() {
HueController.getInstance().startFlashing(null);
vibrate();
flashOrangeBackground();
//flashTorch();
flashTorch();
}
mInComingCallHeader.setVisibility(View.VISIBLE);
mInPassiveCallHeader.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -2907,6 +2911,7 @@ public void onAnimationRepeat(Animation animation) {
if (isFlashing) {
System.out.println("++++++++++++++++++++++" + isFlashing);
isFlashing = false;
LinphoneTorchFlasher.instance().stopFlashTorch();
HueController.getInstance().stopFlashing();

}
Expand Down Expand Up @@ -2940,6 +2945,7 @@ public void onAnimationRepeat(Animation animation) {
if (isFlashing) {
System.out.println("++++++++++++++++++++++" + isFlashing);
isFlashing = false;
LinphoneTorchFlasher.instance().stopFlashTorch();
HueController.getInstance().stopFlashing();
}
mInComingCallHeader.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -3001,10 +3007,10 @@ public void onAnimationUpdate(ValueAnimator animator) {
}, 0, (long) (flashFrequencyInSeconds * 2000));
}

// private void flashTorch() {
// if (!getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) return;
// LinphoneTorchFlasher.instance().startFlashTorch();
// }
private void flashTorch() {
if (!getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) return;
LinphoneTorchFlasher.instance().startFlashTorch();
}


private void vibrate() {
Expand Down
54 changes: 16 additions & 38 deletions src/org/linphone/IncomingCallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ of the License, or (at your option) any later version.
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
Expand All @@ -53,6 +53,7 @@ of the License, or (at your option) any later version.
import org.linphone.mediastream.Log;
import org.linphone.setup.ApplicationPermissionManager;
import org.linphone.ui.RoundedImageView;
import org.linphone.vtcsecure.LinphoneTorchFlasher;

import java.util.List;
import java.util.Timer;
Expand All @@ -69,11 +70,6 @@ of the License, or (at your option) any later version.
*/
public class IncomingCallActivity extends Activity {


public CameraPreviewTorch cpt;
public Timer Torch_Timer;
SurfaceView preview;

private static IncomingCallActivity instance;

private TextView mNameView;
Expand All @@ -87,15 +83,14 @@ public class IncomingCallActivity extends Activity {
private LinphoneCoreListenerBase mListener;
private RelativeLayout topLayout;
private Boolean backgroundIsRed = false;
private Boolean torchIsOn = false;
private Boolean torhcIsOn = false;
private Timer flashOrangeBackgroundTimer;
private Timer vibrateTimer;
private boolean terminated = false;
private int ringCount = 0;
private LinearLayout mCallLaterLayout;
private TextView mOutgoingRingCountTextView;


public static IncomingCallActivity instance() {
return instance;
}
Expand Down Expand Up @@ -154,18 +149,6 @@ void sendDeclineReason(String reason)
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.new_incoming);
super.onCreate(savedInstanceState);

}

@Override
protected void onResume() {
super.onResume();
instance = this;
preview = (SurfaceView) findViewById(R.id.PREVIEW);
cpt=new CameraPreviewTorch(this,preview);



mNameView = (TextView) findViewById(R.id.incoming_caller_name);
// mNumberView = (TextView) findViewById(R.id.incoming_caller_number);
Expand Down Expand Up @@ -214,6 +197,14 @@ public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State sta
}
};

super.onCreate(savedInstanceState);
instance = this;
}

@Override
protected void onResume() {
super.onResume();
instance = this;
// Try to automatically connect to the last known bridge. For first time use this will be empty so a bridge search is automatically started.
HueSharedPreferences prefs = HueSharedPreferences.getInstance(getApplicationContext());
String lastIpAddress = prefs.getLastConnectedIPAddress();
Expand Down Expand Up @@ -283,28 +274,25 @@ public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State sta
} else {
mNameView.setText(contact.getName());
}

}

@Override
protected void onPause() {
terminated = true;
LinphoneTorchFlasher.instance().stopFlashTorch();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.removeListener(mListener);
}
stopRingCount();
super.onPause();
HueController.getInstance().stopFlashing();
Torch_Timer.cancel();
cpt.surfaceDestroyed(null);
}

@Override
protected void onDestroy() {
super.onDestroy();
instance = null;
//cpt.surfaceDestroyed(null);
}

@Override
Expand Down Expand Up @@ -393,30 +381,20 @@ public void run() {
}

private void flashTorch() {
float flashFrequencyInSeconds = LinphonePreferences.instance().getConfig().getFloat("vtcsecure", "incoming_flashlight_frequency", 0.3f);
Torch_Timer = new Timer();
Torch_Timer.schedule(new TimerTask() {
@Override
public void run() {
if(torchIsOn){
cpt.torchOff();
}else{
cpt.torchOn();
}
torchIsOn = !torchIsOn;
System.out.println("torchIsOn"+torchIsOn);
}
}, 0, (long)(flashFrequencyInSeconds*1000));
if (!getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) return;
LinphoneTorchFlasher.instance().startFlashTorch();
}


private void decline() {
LinphoneTorchFlasher.instance().stopFlashTorch();
LinphoneManager.getLc().terminateCall(mCall);
}

private void answer() {
LinphoneCallParams params = LinphoneManager.getLc().createCallParams(mCall);

LinphoneTorchFlasher.instance().stopFlashTorch();

boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(this);
if (isLowBandwidthConnection) {
Expand Down
2 changes: 2 additions & 0 deletions src/org/linphone/LinphoneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ of the License, or (at your option) any later version.
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.setup.ApplicationPermissionManager;
import org.linphone.vtcsecure.LinphoneTorchFlasher;
import org.linphone.vtcsecure.g;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -542,6 +543,7 @@ public boolean toggleEnableCamera() {

public void enableCamera(LinphoneCall call, boolean enable) {
if (call != null) {
LinphoneTorchFlasher.instance().stopFlashTorch();
call.enableCamera(enable);
if (mServiceContext.getResources().getBoolean(R.bool.enable_call_notification))
LinphoneService.instance().refreshIncallIcon(mLc.getCurrentCall());
Expand Down
65 changes: 65 additions & 0 deletions src/org/linphone/vtcsecure/LinphoneTorchFlasher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.linphone.vtcsecure;

import java.util.Timer;
import java.util.TimerTask;

import org.linphone.LinphonePreferences;
import org.linphone.mediastream.Log;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;

public class LinphoneTorchFlasher extends Object {
private Camera cam;
private Parameters p;
private boolean torhcIsOn = false;
private boolean stopped = true;
private Timer timer;
public static LinphoneTorchFlasher instance;


public static synchronized LinphoneTorchFlasher instance() {
if (instance == null ) {
instance = new LinphoneTorchFlasher();
}
return instance;
}

public synchronized void stopFlashTorch() {
if (stopped) return;
timer.cancel();
timer = null;
stopped = true;
p.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.release();
}

public void startFlashTorch() {
if (!stopped) return;
float flashFrequencyInSeconds = LinphonePreferences.instance().getConfig().getFloat("vtcsecure", "incoming_flashlight_frequency", 0.3f);
try {
cam = Camera.open();
p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
} catch (Exception e) {
Log.e("Failed tunrning torch on");
return;
}
stopped = false;
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
if (stopped) return;
if (torhcIsOn) p.setFlashMode(Parameters.FLASH_MODE_OFF);
else p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
torhcIsOn = !torhcIsOn;
}
}, 0, (long)(flashFrequencyInSeconds*1000));
}

}