|
@@ -1,27 +1,15 @@
|
|
|
package com.sxr.sdk.ble.keepfit.client;
|
|
|
|
|
|
-import android.Manifest;
|
|
|
import android.app.Activity;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
-import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.ServiceConnection;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
-import android.net.Uri;
|
|
|
-import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
import android.os.Message;
|
|
|
-import android.os.Process;
|
|
|
-import android.provider.Settings;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
-import android.support.v4.app.ActivityCompat;
|
|
|
-import android.support.v4.content.ContextCompat;
|
|
|
-import android.support.v7.app.AlertDialog;
|
|
|
-import android.telephony.TelephonyManager;
|
|
|
import android.text.Html;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
@@ -36,7 +24,6 @@ import android.widget.ListView;
|
|
|
import android.widget.PopupWindow;
|
|
|
import android.widget.ScrollView;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
import com.sxr.sdk.ble.keepfit.bean.BleDeviceItem;
|
|
|
import com.sxr.sdk.ble.keepfit.client.adapter.ListDeviceViewAdapter;
|
|
@@ -45,8 +32,9 @@ import com.sxr.sdk.ble.keepfit.service.ReportService;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
@@ -72,6 +60,10 @@ public class GyeeActivity extends Activity {
|
|
|
*/
|
|
|
public static final int MSG_CODE_DISCONNECTED_REACELET = 11;
|
|
|
|
|
|
+ public String userId;
|
|
|
+
|
|
|
+ private Timer timer = new Timer();
|
|
|
+
|
|
|
private ProgressDialog progressDialog;
|
|
|
|
|
|
@BindView(R2.id.phone_number)
|
|
@@ -114,6 +106,9 @@ public class GyeeActivity extends Activity {
|
|
|
// initPermission();
|
|
|
// }
|
|
|
reportIntent = new Intent(this, ReportService.class);
|
|
|
+ Intent intent = getIntent();
|
|
|
+ userId = intent.getStringExtra("userId");
|
|
|
+
|
|
|
startService(reportIntent);
|
|
|
initProgressDialog();
|
|
|
initView();
|
|
@@ -150,35 +145,38 @@ public class GyeeActivity extends Activity {
|
|
|
if (restBinder != null) {
|
|
|
if(restBinder.isBound() == true){
|
|
|
if (restBinder.callRemoteIsConnected() == false) {
|
|
|
- phoneNumber.setVisibility(View.GONE);
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
+// phoneNumber.setVisibility(View.GONE);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
+
|
|
|
btScan.setEnabled(true);
|
|
|
btDisconnect.setEnabled(false);
|
|
|
llConnect.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
- phoneNumber.setVisibility(View.GONE);
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
+// phoneNumber.setVisibility(View.GONE);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
btScan.setEnabled(false);
|
|
|
btDisconnect.setEnabled(true);
|
|
|
llConnect.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
- }else if (restBinder.callRemoteIsConnected() == false) {
|
|
|
- phoneNumber.setVisibility(View.VISIBLE);
|
|
|
- btBind.setEnabled(true);
|
|
|
- btUnbind.setEnabled(false);
|
|
|
- btScan.setEnabled(false);
|
|
|
- btDisconnect.setEnabled(false);
|
|
|
- llConnect.setVisibility(View.GONE);
|
|
|
+// }
|
|
|
+// else if (restBinder.callRemoteIsConnected() == false) {
|
|
|
+// phoneNumber.setVisibility(View.VISIBLE);
|
|
|
+// btBind.setEnabled(true);
|
|
|
+// btUnbind.setEnabled(false);
|
|
|
+// btScan.setEnabled(false);
|
|
|
+// btDisconnect.setEnabled(false);
|
|
|
+// llConnect.setVisibility(View.GONE);
|
|
|
}
|
|
|
+ eventBindDeviceService();
|
|
|
}
|
|
|
restBinder.setActivity(GyeeActivity.this);
|
|
|
restBinder.setMessageHandler(messageHandler);
|
|
|
restBinder.setScanDeviceHandler(scanDeviceHandler);
|
|
|
restBinder.setUpdateConnectStateHandler(updateConnectStateHandler);
|
|
|
restBinder.setDevicesData(devicesData);
|
|
|
- restBinder.setMobile(phoneNumberStr);
|
|
|
+// restBinder.setMobile(phoneNumberStr);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -189,30 +187,30 @@ public class GyeeActivity extends Activity {
|
|
|
|
|
|
|
|
|
private void initView() {
|
|
|
- try {
|
|
|
- TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
- // String deviceid = tm.getDeviceId();//获取智能设备唯一编号
|
|
|
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
- // TODO: Consider calling
|
|
|
- // ActivityCompat#requestPermissions
|
|
|
- // here to request the missing permissions, and then overriding
|
|
|
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
- // int[] grantResults)
|
|
|
- // to handle the case where the user grants the permission. See the documentation
|
|
|
- // for ActivityCompat#requestPermissions for more details.
|
|
|
- return;
|
|
|
- }
|
|
|
- phoneNumberStr = tm.getLine1Number();//获取本机号码
|
|
|
- System.out.println(phoneNumberStr);
|
|
|
- } catch (Exception ex) {
|
|
|
- System.out.println(ex.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- if (phoneNumberStr != null && phoneNumberStr.length() == 11) {
|
|
|
- restBinder.setMobile(phoneNumberStr);
|
|
|
- } else {
|
|
|
- phoneNumber.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
+// try {
|
|
|
+// TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
+// // String deviceid = tm.getDeviceId();//获取智能设备唯一编号
|
|
|
+// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+// // TODO: Consider calling
|
|
|
+// // ActivityCompat#requestPermissions
|
|
|
+// // here to request the missing permissions, and then overriding
|
|
|
+// // public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
+// // int[] grantResults)
|
|
|
+// // to handle the case where the user grants the permission. See the documentation
|
|
|
+// // for ActivityCompat#requestPermissions for more details.
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// phoneNumberStr = tm.getLine1Number();//获取本机号码
|
|
|
+// System.out.println(phoneNumberStr);
|
|
|
+// } catch (Exception ex) {
|
|
|
+// System.out.println(ex.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (phoneNumberStr != null && phoneNumberStr.length() == 11) {
|
|
|
+// restBinder.setMobile(phoneNumberStr);
|
|
|
+// } else {
|
|
|
+// phoneNumber.setVisibility(View.VISIBLE);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
private boolean bColor = false;
|
|
@@ -250,35 +248,36 @@ public class GyeeActivity extends Activity {
|
|
|
/**
|
|
|
* 绑定设备(手环)服务
|
|
|
*/
|
|
|
- @OnClick(R2.id.bind)
|
|
|
+// @OnClick(R2.id.bind)
|
|
|
void eventBindDeviceService() {
|
|
|
//获取手机号码
|
|
|
- if (phoneNumber.getVisibility() == View.VISIBLE) {
|
|
|
- phoneNumberStr = phoneNumber.getText().toString().trim();
|
|
|
- if (phoneNumberStr.length() != 11) {
|
|
|
- Toast.makeText(this, "手机号格式错误", Toast.LENGTH_LONG).show();
|
|
|
- return;
|
|
|
- } else {
|
|
|
- restBinder.setMobile(phoneNumberStr);
|
|
|
- phoneNumber.setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+// if (phoneNumber.getVisibility() == View.VISIBLE) {
|
|
|
+// phoneNumberStr = phoneNumber.getText().toString().trim();
|
|
|
+// if (phoneNumberStr.length() != 11) {
|
|
|
+// Toast.makeText(this, "手机号格式错误", Toast.LENGTH_LONG).show();
|
|
|
+// return;
|
|
|
+// } else {
|
|
|
+
|
|
|
+// phoneNumber.setVisibility(View.GONE);
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+ restBinder.setMobile(userId);
|
|
|
//绑定手环服务
|
|
|
restBinder.bindBraceletService();
|
|
|
}
|
|
|
|
|
|
- @OnClick(R2.id.unbind)
|
|
|
+// @OnClick(R2.id.unbind)
|
|
|
void eventUnBindDeviceService() {
|
|
|
if (restBinder.isBound()) {
|
|
|
- btBind.setEnabled(true);
|
|
|
- btUnbind.setEnabled(false);
|
|
|
- btScan.setEnabled(false);
|
|
|
+// btBind.setEnabled(true);
|
|
|
+// btUnbind.setEnabled(false);
|
|
|
+// btScan.setEnabled(false);
|
|
|
btDisconnect.setEnabled(false);
|
|
|
llConnect.setVisibility(View.GONE);
|
|
|
- phoneNumber.setVisibility(View.VISIBLE);
|
|
|
+// phoneNumber.setVisibility(View.VISIBLE);
|
|
|
//解绑手环服务
|
|
|
restBinder.unBindBraceletService();
|
|
|
+ eventBindDeviceService();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -295,6 +294,7 @@ public class GyeeActivity extends Activity {
|
|
|
*/
|
|
|
@OnClick(R2.id.scan)
|
|
|
void eventScanDevices() {
|
|
|
+ restBinder.setMobile(userId);
|
|
|
scanDevices();
|
|
|
}
|
|
|
|
|
@@ -305,6 +305,10 @@ public class GyeeActivity extends Activity {
|
|
|
void eventRemoteDisconnect() {
|
|
|
//断连事件
|
|
|
restBinder.callRemoteDisconnect();
|
|
|
+ //解綁
|
|
|
+ eventUnBindDeviceService();
|
|
|
+ if (nearbyListAdapter != null)
|
|
|
+ nearbyListAdapter.clear();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -424,8 +428,8 @@ public class GyeeActivity extends Activity {
|
|
|
restBinder.callRemoteConnect(holder.name, holder.mac);
|
|
|
progressDialog.show();
|
|
|
dismissPopWindow();
|
|
|
+ timer();
|
|
|
} catch (Exception e) {
|
|
|
- progressDialog.dismiss();
|
|
|
e.printStackTrace();
|
|
|
Log.e("BLE service", "ble connect ble device: excption");
|
|
|
}
|
|
@@ -457,19 +461,21 @@ public class GyeeActivity extends Activity {
|
|
|
int state = data.getInt("state");
|
|
|
|
|
|
if (state == 2) {
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
- btScan.setEnabled(true);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
+ btScan.setEnabled(false);
|
|
|
btDisconnect.setEnabled(true);
|
|
|
llConnect.setVisibility(View.VISIBLE);
|
|
|
progressDialog.dismiss();
|
|
|
} else {
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
- btScan.setEnabled(true);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
+ btScan.setEnabled(false);
|
|
|
btDisconnect.setEnabled(false);
|
|
|
llConnect.setVisibility(View.GONE);
|
|
|
+// progressDialog.dismiss();
|
|
|
}
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
@@ -502,20 +508,20 @@ public class GyeeActivity extends Activity {
|
|
|
int what = msg.what;
|
|
|
|
|
|
if (what == MSG_CODE_REMOTE_CONNECTED_BRACELET_IS_SUCCESS) {
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
btScan.setEnabled(true);
|
|
|
btDisconnect.setEnabled(true);
|
|
|
llConnect.setVisibility(View.GONE);
|
|
|
} else if (what == MSG_CODE_REMOTE_CONNECTED_BRACELET_IS_FAILED) {
|
|
|
- btBind.setEnabled(false);
|
|
|
- btUnbind.setEnabled(true);
|
|
|
+// btBind.setEnabled(false);
|
|
|
+// btUnbind.setEnabled(true);
|
|
|
btScan.setEnabled(true);
|
|
|
btDisconnect.setEnabled(false);
|
|
|
llConnect.setVisibility(View.VISIBLE);
|
|
|
} else if (what == MSG_CODE_DISCONNECTED_REACELET) {
|
|
|
- btBind.setEnabled(true);
|
|
|
- btUnbind.setEnabled(false);
|
|
|
+// btBind.setEnabled(true);
|
|
|
+// btUnbind.setEnabled(false);
|
|
|
btScan.setEnabled(false);
|
|
|
btDisconnect.setEnabled(false);
|
|
|
llConnect.setVisibility(View.GONE);
|
|
@@ -538,6 +544,20 @@ public class GyeeActivity extends Activity {
|
|
|
progressDialog.setCancelable(false);//false不能取消显示,true可以取消显示
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 定时器===关闭正在加载弹窗
|
|
|
+ */
|
|
|
+ private void timer(){
|
|
|
+ TimerTask task = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ timer.cancel();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.schedule(task,60*1000,60*1000);
|
|
|
+ }
|
|
|
+
|
|
|
// //申请两个权限,录音和文件读写
|
|
|
// //1、首先声明一个数组permissions,将需要的权限都放在里面
|
|
|
// String[] permissions = new String[]{
|