public static void inAppDial(final BaseActivity activity, String dial) { if (TextUtils.isEmpty(dial)) { return; } final String phone = StringUtils.phoneFormat(dial); if (Constant.noCall.contains(phone)) { call(activity, phone); } else { HttpServer hServer = new HttpServer(Constant.URL.phoneCall, activity.getHandlerContext()); Map<String, String> headers = new HashMap<String, String>(); headers.put("sign", User.ACCESSKEY); hServer.setHeaders(headers); Map<String, String> params = new HashMap<String, String>(); params.put("accessid", User.ACCESSID); params.put("userTel", activity.getAppContext().currentUser().getPhone()); params.put("oppno", phone); hServer.setParams(params); hServer.get( new HttpRunnable() { @Override public void run(Response response) throws AppException { Map<String, String> info = response.getMapData("serverinfo"); RecordingContentView.isRefreshData = true; BaseContext.getSharedPreferences() .putString(Constant.Preferences.SP_CALL_DIAL, phone); call(activity, info.get("serverno")); activity.getRecentDaoImpl().insertCallLog(phone); } }); } }
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_extraction_view); clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); tv_recorded_appeal_taobao_code_url = (TextView) findViewById(R.id.recorded_appeal_taobao_code_url); tv_recorded_appeal_taobao_code = (TextView) findViewById(R.id.recorded_appeal_taobao_code); tv_recorded_appeal_taobao_limit_time = (TextView) findViewById(R.id.recorded_appeal_taobao_limit_time); btn_recorded_appeal_taobao_btn_copy = (Button) findViewById(R.id.recorded_appeal_taobao_btn_copy); btn_recorded_appeal_taobao_btn_copy.setOnClickListener(this); btn_recorded_appeal_taobao_btn_send_to_mobile = (Button) findViewById(R.id.recorded_appeal_taobao_btn_send_to_mobile); btn_recorded_appeal_taobao_btn_send_to_mobile.setOnClickListener(this); btn_recorded_appeal_taobao_btn_cancel = (Button) findViewById(R.id.recorded_appeal_taobao_btn_cancel); btn_recorded_appeal_taobao_btn_cancel.setOnClickListener(this); fileno = getIntent().getExtras().getString(RecordingAdapter.RECORDED_FILENO); if (fileno != null) { String accstatus = getIntent().getExtras().getString(RecordingAdapter.RECORDED_ACCSTATUS); if ("1".equals(accstatus)) { setMainHeadTitle(getString(R.string.view_extractioncode)); // 有效 getDataTask(2); } else { setMainHeadTitle(getString(R.string.reg_extractioncode)); // 生成 getDataTask(1); } } }
public static void call(BaseActivity activity, String phone) { if (TextUtils.isEmpty(phone)) { return; } DialContentView.isRefreshData = true; CallRecordsContentView.isRefreshData = true; Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone)); activity.startActivity(intent); }
@Override public void onClick(View v) { String strContent = String.valueOf(tv_recorded_appeal_taobao_code_url.getText()) + String.valueOf(tv_recorded_appeal_taobao_code.getText()); if (v.getId() == R.id.recorded_appeal_taobao_btn_copy) { clipboard.setText(strContent); btn_recorded_appeal_taobao_btn_copy.setEnabled(false); getHandlerContext().makeTextShort(getString(R.string.copy_success)); } else if (v.getId() == R.id.recorded_appeal_taobao_btn_send_to_mobile) { Uri smsToUri = Uri.parse("smsto:"); Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO, smsToUri); String strContent1 = "您申请的录音提取码为:" + strContent + " ,凭该提取码可在官网公开查询、下载本条通话录音,请妥善保管。客服电话:" + getString(R.string.app_phone) + "【" + getString(R.string.app_compayname) + "】"; mIntent.putExtra("sms_body", strContent1); startActivity(mIntent); } else if (v.getId() == R.id.recorded_appeal_taobao_btn_cancel) { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_info) .setMessage(R.string.undo_extraction_code_sure) .setPositiveButton(R.string.cancle, null) .setNeutralButton( R.string.sure, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getDataTask(3); } }) .show(); } else { super.onClick(v); } }
/** 重置手势密码 */ public static void resetGesture(BaseActivity activity) { if (BaseContext.getSharedPreferences().getBoolean(Preferences.SP_IS_RESET_LOCK_KEY, false)) { activity.startActivity(new Intent(activity, LockSetupActivity.class)); BaseContext.getSharedPreferences().putBoolean(Preferences.SP_IS_RESET_LOCK_KEY, false); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_OFFHOOK: IDLE = true; if (myFV == null) { wm = (WindowManager) currentActivity.getAppContext().getSystemService(Context.WINDOW_SERVICE); View view = LayoutInflater.from(currentActivity.getAppContext()) .inflate(R.layout.module_diallistener, null); ImageView ivClose = (ImageView) view.findViewById(R.id.dial_listener_btn_close); ivClose.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // 关闭悬浮窗口 if (wm != null && myFV != null) { wm.removeView(myFV); myFV = null; } } }); TextView tvMessage = (TextView) view.findViewById(R.id.dial_listener_text); tvMessage.setText("您正在与" + SP_CALL_DIAL + "录音通话中…"); myFV = new DialFloatView(currentActivity.getAppContext()); myFV.addView(view); // 设置LayoutParams(全局变量)相关参数 WindowManager.LayoutParams wmParams = myFV.getMywmParams(); // 设置window type wmParams.type = LayoutParams.TYPE_PHONE; // 设置图片格式,效果为背景透明 wmParams.format = PixelFormat.RGBA_8888; // 设置Window flag wmParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE; // 调整悬浮窗口至左上角 wmParams.gravity = Gravity.LEFT | Gravity.TOP; // 以屏幕左上角为原点,设置x、y初始值 wmParams.x = 0; wmParams.y = 0; // 设置悬浮窗口长宽数据 wmParams.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT; wmParams.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; // 显示myFloatView图像 wm.addView(myFV, wmParams); } break; case TelephonyManager.CALL_STATE_IDLE: // 拨打电话状态顺序1.CALL_STATE_IDLE 2.CALL_STATE_OFFHOOK // 3.CALL_STATE_IDLE由于只需要取最后一个CALL_STATE_IDLE所以在这里需要一个逻辑判断 if (IDLE) { IDLE = false; // 停止监听手机通话状态 if (manager != null) { manager.listen(stateListener, PhoneStateListener.LISTEN_NONE); } // 通话结束后关闭悬浮窗口 if (wm != null && myFV != null) { wm.removeView(myFV); myFV = null; } // 设置拨打的号码为空 BaseContext.getSharedPreferences() .putString(Constant.Preferences.SP_CALL_DIAL, AppConstant.EMPTYSTR); ActivityManager am = (ActivityManager) currentActivity.getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; if (!cn.getClassName().equals(MainActivity.class.getName())) { // Android4.0以上系统默认打完电话后会跳转到 Intent intent = new Intent(currentActivity, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); currentActivity.startActivity(intent); } } break; } }