| | |
| | | import android.content.Intent; |
| | | import android.content.IntentFilter; |
| | | import android.graphics.Bitmap; |
| | | import android.media.AudioAttributes; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.CountDownTimer; |
| | | import android.os.SystemClock; |
| | | import android.os.Vibrator; |
| | | import android.text.TextUtils; |
| | | import android.util.DisplayMetrics; |
| | | import android.util.Log; |
| | |
| | | import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; |
| | | import com.hdl.hdllinphonesdk.R; |
| | | import com.hdl.hdllinphonesdk.utils.HDLImageUtils; |
| | | import com.hdl.hdllinphonesdk.utils.HDLLog; |
| | | |
| | | import org.linphone.core.Call; |
| | | import org.linphone.core.Core; |
| | | import org.linphone.core.CoreListenerStub; |
| | | |
| | | /** |
| | | * Linphone接听页面 |
| | |
| | | private LinearLayout ll_video_lp_rendering; |
| | | private TextureView video_lp_rendering; |
| | | private TextureView video_lp_rendering2; |
| | | // private TextView tv_lp_calltime; |
| | | private Chronometer timer_lp_calltime ; |
| | | // private TextView tv_lp_calltime; |
| | | private Chronometer timer_lp_calltime; |
| | | private TextView tv_lp_calltime; |
| | | |
| | | //参数 |
| | | private boolean isAnswer;//是否已经接听了 |
| | | private int callTime;//通话时间 |
| | | |
| | | //倒计时 |
| | | private CountDownTimer mCountDownTimer; |
| | | /** |
| | | * 手机振动器 |
| | | */ |
| | | private Vibrator mVibrator; |
| | | |
| | | //Linphone |
| | | private CoreListenerStub mCoreListener; |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | initCallBack(); |
| | | initCountDownTimer(); |
| | | initLinphone(); |
| | | initVibrator(); |
| | | |
| | | } |
| | | |
| | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | |
| | | //1.挂断 |
| | | HDLLinphoneKit.getInstance().hangUp(); |
| | | //2.暂停计时 |
| | | if (null != timer_lp_calltime) { |
| | | timer_lp_calltime.stop(); |
| | | } |
| | | |
| | | //3.注销callBack |
| | | HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null); |
| | | |
| | | //4.取消震动器 |
| | | cancelVibrator(); |
| | | //5. |
| | | if (mCountDownTimer != null) { |
| | | mCountDownTimer.cancel(); |
| | | mCountDownTimer = null; |
| | | } |
| | | //5. |
| | | onDestroyLinphone(); |
| | | |
| | | if (mReceiver != null) { |
| | | unregisterReceiver(mReceiver); |
| | | } |
| | | HDLLinphoneKit.getInstance().onDestroy(); |
| | | |
| | | Log.i(TAG,"onDestroy"); |
| | | HDLLog.i(TAG, "onDestroy"); |
| | | |
| | | } |
| | | |
| | |
| | | video_lp_rendering = findViewById(R.id.video_lp_rendering); |
| | | video_lp_rendering2 = findViewById(R.id.video_lp_rendering2); |
| | | // tv_lp_calltime = findViewById(R.id.tv_lp_calltime); |
| | | timer_lp_calltime = (Chronometer)findViewById(R.id.timer_lp_calltime); |
| | | timer_lp_calltime = (Chronometer) findViewById(R.id.timer_lp_calltime); |
| | | tv_lp_calltime = findViewById(R.id.tv_lp_calltime); |
| | | setWidthHeightWithRatio(ll_video_lp_rendering,16,9); |
| | | setWidthHeightWithRatio(ll_video_lp_rendering, 16, 9); |
| | | |
| | | iv_lp_screenshot.setEnabled(false); |
| | | iv_lp_unlock.setEnabled(false); |
| | | } |
| | | |
| | | /** |
| | | * initData |
| | | */ |
| | | private void initData(){ |
| | | private void initData() { |
| | | Bundle extras = getIntent().getExtras(); |
| | | if(extras != null){ |
| | | String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME); |
| | | if(!TextUtils.isEmpty(titleName)){ |
| | | if (extras != null) { |
| | | String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME); |
| | | if (!TextUtils.isEmpty(titleName)) { |
| | | tv_lp_title.setText(titleName); |
| | | } |
| | | } |
| | |
| | | view.setLayoutParams(layoutParams); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * init OnClickListener |
| | | */ |
| | |
| | | /** |
| | | * 初始化开门回调事件 |
| | | */ |
| | | void initCallBack(){ |
| | | void initCallBack() { |
| | | HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(new OnLPOpenDoorCallBack() { |
| | | @Override |
| | | public void onOpenSuccess() { |
| | |
| | | /** |
| | | * 初始化开锁屏蔽倒计时 |
| | | */ |
| | | void initCountDownTimer(){ |
| | | void initCountDownTimer() { |
| | | |
| | | mCountDownTimer = new CountDownTimer(10*1000, 1000) { |
| | | mCountDownTimer = new CountDownTimer(10 * 1000, 1000) { |
| | | @Override |
| | | public void onTick(long millisUntilFinished) { |
| | | if (!HDLLinphoneIntercomActivity.this.isFinishing()) { |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void onFinish() { |
| | | // showToast("开锁onFinish"); |
| | | iv_lp_unlock.setEnabled(true); |
| | | } |
| | | |
| | | }; |
| | | // |
| | | } |
| | | |
| | | @Override |
| | |
| | | private void onClickScreenshot() { |
| | | // Bitmap img = HDLImageUtils.createViewBitmap(video_lp_rendering); |
| | | Bitmap img = video_lp_rendering.getBitmap(); |
| | | boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img); |
| | | boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img); |
| | | |
| | | if(isSuccess){ |
| | | if (isSuccess) { |
| | | showToast(getString(R.string.lp_saveToTheAlbumsStr)); |
| | | }else { |
| | | } else { |
| | | showToast(getString(R.string.lp_operationFailedStr)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 开锁点击事件 |
| | |
| | | if (isAnswer) { |
| | | //如果之前已经接听了,回调是挂断 |
| | | callTime = getTimerCallTime(); |
| | | Log.i("callTime","callTime"+callTime); |
| | | HDLLog.i("callTime", "callTime" + callTime); |
| | | HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onHangUpAction(callTime); |
| | | } else { |
| | | //如果之前没接听了,回调是拒接 |
| | |
| | | private void onClickAnswer() { |
| | | //1.接听 |
| | | HDLLinphoneKit.getInstance().acceptCall(); |
| | | //2.取消震动 |
| | | cancelVibrator(); |
| | | //3.修改UI |
| | | isAnswer = true; |
| | | tv_lp_hangUp.setText(getString(R.string.lp_hangupStr)); |
| | | setViewGone(rl_lp_answerView); |
| | |
| | | if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { |
| | | HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onAnswerAction(); |
| | | } |
| | | |
| | | iv_lp_screenshot.setEnabled(true); |
| | | iv_lp_unlock.setEnabled(true); |
| | | } |
| | | |
| | | /****************开锁成功********/ |
| | |
| | | iv_lp_unlock.setEnabled(false); |
| | | startOpenDoorCountdown(); |
| | | } |
| | | |
| | | /** |
| | | * 开启倒计时 |
| | | */ |
| | | void startOpenDoorCountdown() { |
| | | mCountDownTimer.start(); |
| | | } |
| | | |
| | | /** |
| | | * 通话记录开启倒计时 |
| | | */ |
| | |
| | | timer_lp_calltime.setBase(SystemClock.elapsedRealtime());//计时器清零 |
| | | timer_lp_calltime.start(); |
| | | } |
| | | int getTimerCallTime(){ |
| | | |
| | | int getTimerCallTime() { |
| | | int temp0 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[0]); |
| | | int temp1 =Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]); |
| | | int temp1 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]); |
| | | return temp0 * 60 + temp1; |
| | | } |
| | | |
| | | |
| | | |
| | | /****************封装常用方法********/ |
| | |
| | | } |
| | | |
| | | /**********LinPhone**********/ |
| | | void initLinphone(){ |
| | | IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY); |
| | | mReceiver = new FinishVideoActivityReceiver(); |
| | | registerReceiver(mReceiver, intentFilter); |
| | | HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2); |
| | | /** |
| | | * initLinphone |
| | | */ |
| | | void initLinphone() { |
| | | mCoreListener = new CoreListenerStub() { |
| | | @Override |
| | | public void onCallStateChanged(Core core, Call call, Call.State state, String message) { |
| | | if (state == Call.State.End || state == Call.State.Released) { |
| | | // Once call is finished (end state), terminate the activity |
| | | // We also check for released state (called a few seconds later) just in case |
| | | // we missed the first one |
| | | showToast(getString(R.string.lp_endOfCallStr)); |
| | | finish(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Core core = HDLLinphoneKit.getInstance().getCore(); |
| | | // We need to tell the core in which to display what |
| | | if (core != null) { |
| | | core.setNativeVideoWindowId(video_lp_rendering); |
| | | core.setNativePreviewWindowId(video_lp_rendering2); |
| | | // Listen for call state changes |
| | | core.addListener(mCoreListener); |
| | | core.enableMic(true);//开启麦克风 |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * onDestroyLinphone |
| | | */ |
| | | void onDestroyLinphone() { |
| | | Core core = HDLLinphoneKit.getInstance().getCore(); |
| | | if (core != null) { |
| | | core.removeListener(mCoreListener); |
| | | core.setNativeVideoWindowId(null); |
| | | core.setNativePreviewWindowId(null); |
| | | } |
| | | video_lp_rendering = null; |
| | | video_lp_rendering2 = null; |
| | | } |
| | | |
| | | public class FinishVideoActivityReceiver extends BroadcastReceiver { |
| | | @Override |
| | | public void onReceive(Context context, Intent intent) { |
| | | HDLLinphoneIntercomActivity.this.finish(); |
| | | /** |
| | | * 初始化震动器 |
| | | */ |
| | | void initVibrator() { |
| | | mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); |
| | | if (mVibrator.hasVibrator()) { |
| | | long[] patern = {0, 1000, 1000}; |
| | | AudioAttributes audioAttributes = null; |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| | | audioAttributes = new AudioAttributes.Builder() |
| | | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| | | .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) //key |
| | | .build(); |
| | | mVibrator.vibrate(patern, 1, audioAttributes); |
| | | } else { |
| | | mVibrator.vibrate(patern, 1); |
| | | } |
| | | } else { |
| | | HDLLog.E("当前手机没有震动器"); |
| | | } |
| | | } |
| | | |
| | | private FinishVideoActivityReceiver mReceiver; |
| | | public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity"; |
| | | /** |
| | | * 关闭震动器 |
| | | */ |
| | | void cancelVibrator() { |
| | | if (mVibrator != null) { |
| | | mVibrator.cancel(); |
| | | mVibrator = null; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |