2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2016-02-21 15:26:24 +01:00
|
|
|
import android.Manifest;
|
|
|
|
import android.annotation.TargetApi;
|
2015-03-07 15:32:34 +01:00
|
|
|
import android.app.Activity;
|
2015-06-21 00:34:05 +02:00
|
|
|
import android.app.ProgressDialog;
|
2015-03-21 18:18:07 +01:00
|
|
|
import android.bluetooth.BluetoothDevice;
|
2015-02-06 13:55:44 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-06-21 00:34:05 +02:00
|
|
|
import android.content.DialogInterface;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.content.Intent;
|
2015-02-06 13:55:44 +01:00
|
|
|
import android.content.IntentFilter;
|
2015-01-18 22:44:38 +01:00
|
|
|
import android.content.SharedPreferences;
|
2016-02-21 15:26:24 +01:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Build;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.os.Bundle;
|
2015-01-18 22:44:38 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2016-02-21 15:26:24 +01:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
import android.support.v4.content.ContextCompat;
|
2015-03-27 10:56:08 +01:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-10-18 01:39:25 +02:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
2015-06-01 16:57:45 +02:00
|
|
|
import android.view.ContextMenu;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2015-03-21 18:18:07 +01:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
2015-03-27 12:33:51 +01:00
|
|
|
import android.widget.TextView;
|
2015-03-21 18:18:07 +01:00
|
|
|
import android.widget.Toast;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2015-05-28 00:26:41 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2015-04-26 00:53:48 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2016-03-02 00:36:39 +01:00
|
|
|
import de.cketti.library.changelog.ChangeLog;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
2015-04-26 00:53:48 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
2015-08-07 22:07:48 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2015-04-26 00:53:48 +02:00
|
|
|
|
2015-03-07 15:32:34 +01:00
|
|
|
public class ControlCenter extends Activity {
|
2015-02-06 13:55:44 +01:00
|
|
|
|
2015-05-28 00:26:41 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(ControlCenter.class);
|
2015-03-21 18:18:07 +01:00
|
|
|
|
2015-03-22 12:46:28 +01:00
|
|
|
public static final String ACTION_REFRESH_DEVICELIST
|
2015-07-18 23:38:59 +02:00
|
|
|
= "nodomain.freeyourgadget.gadgetbridge.controlcenter.action.set_version";
|
2015-03-22 00:34:54 +01:00
|
|
|
|
2015-08-16 00:17:16 +02:00
|
|
|
private TextView hintTextView;
|
2015-10-18 01:39:25 +02:00
|
|
|
private SwipeRefreshLayout swipeLayout;
|
2015-08-16 00:17:16 +02:00
|
|
|
private GBDeviceAdapter mGBDeviceAdapter;
|
2015-06-01 16:57:45 +02:00
|
|
|
private GBDevice selectedDevice = null;
|
|
|
|
|
2015-08-16 00:17:16 +02:00
|
|
|
private final List<GBDevice> deviceList = new ArrayList<>();
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2015-08-16 00:17:16 +02:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
2015-02-06 13:55:44 +01:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2015-03-22 00:34:54 +01:00
|
|
|
String action = intent.getAction();
|
2015-05-10 16:56:09 +02:00
|
|
|
switch (action) {
|
2015-12-07 23:33:32 +01:00
|
|
|
case GBApplication.ACTION_QUIT:
|
2015-05-10 16:56:09 +02:00
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
case ACTION_REFRESH_DEVICELIST:
|
|
|
|
case BluetoothDevice.ACTION_BOND_STATE_CHANGED:
|
|
|
|
refreshPairedDevices();
|
|
|
|
break;
|
|
|
|
case GBDevice.ACTION_DEVICE_CHANGED:
|
2015-05-28 00:26:41 +02:00
|
|
|
GBDevice dev = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
2015-05-10 16:56:09 +02:00
|
|
|
if (dev.getAddress() != null) {
|
|
|
|
int index = deviceList.indexOf(dev); // search by address
|
|
|
|
if (index >= 0) {
|
|
|
|
deviceList.set(index, dev);
|
|
|
|
} else {
|
|
|
|
deviceList.add(dev);
|
|
|
|
}
|
2015-03-22 00:34:54 +01:00
|
|
|
}
|
2015-10-18 01:39:25 +02:00
|
|
|
updateSelectedDevice(dev);
|
2015-05-10 16:56:09 +02:00
|
|
|
refreshPairedDevices();
|
2015-04-24 23:08:47 +02:00
|
|
|
|
2015-06-06 19:39:04 +02:00
|
|
|
refreshBusyState(dev);
|
2015-10-18 01:39:25 +02:00
|
|
|
enableSwipeRefresh(selectedDevice);
|
2015-05-10 16:56:09 +02:00
|
|
|
break;
|
2015-02-06 13:55:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-18 01:39:25 +02:00
|
|
|
private void updateSelectedDevice(GBDevice dev) {
|
|
|
|
if (selectedDevice == null) {
|
|
|
|
selectedDevice = dev;
|
|
|
|
} else {
|
|
|
|
if (!selectedDevice.equals(dev)) {
|
|
|
|
if (selectedDevice.isConnected() && dev.isConnected()) {
|
|
|
|
LOG.warn("multiple connected devices -- this is currently not really supported");
|
|
|
|
selectedDevice = dev; // use the last one that changed
|
|
|
|
}
|
|
|
|
if (!selectedDevice.isConnected()) {
|
|
|
|
selectedDevice = dev; // use the last one that changed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 19:39:04 +02:00
|
|
|
private void refreshBusyState(GBDevice dev) {
|
2015-10-18 01:39:25 +02:00
|
|
|
if (dev.isBusy()) {
|
|
|
|
swipeLayout.setRefreshing(true);
|
|
|
|
} else {
|
|
|
|
boolean wasBusy = swipeLayout.isRefreshing();
|
|
|
|
if (wasBusy) {
|
|
|
|
swipeLayout.setRefreshing(false);
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 19:39:04 +02:00
|
|
|
mGBDeviceAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_controlcenter);
|
2015-03-28 23:23:10 +01:00
|
|
|
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
2015-12-01 11:39:34 +01:00
|
|
|
ListView deviceListView = (ListView) findViewById(R.id.deviceListView);
|
2015-03-21 18:18:07 +01:00
|
|
|
mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList);
|
|
|
|
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
|
|
|
deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
2015-01-12 00:35:15 +01:00
|
|
|
@Override
|
2015-03-21 18:18:07 +01:00
|
|
|
public void onItemClick(AdapterView parent, View v, int position, long id) {
|
2015-07-20 23:20:24 +02:00
|
|
|
GBDevice gbDevice = deviceList.get(position);
|
2016-03-03 14:29:46 +01:00
|
|
|
if (gbDevice.isInitialized()) {
|
2015-07-20 23:20:24 +02:00
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
|
|
|
Class<? extends Activity> primaryActivity = coordinator.getPrimaryActivity();
|
|
|
|
if (primaryActivity != null) {
|
|
|
|
Intent startIntent = new Intent(ControlCenter.this, primaryActivity);
|
2015-07-21 00:06:20 +02:00
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice);
|
2015-07-20 23:20:24 +02:00
|
|
|
startActivity(startIntent);
|
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
} else {
|
2015-12-13 00:43:07 +01:00
|
|
|
GBApplication.deviceService().connect(deviceList.get(position));
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|
2015-01-12 00:35:15 +01:00
|
|
|
}
|
|
|
|
});
|
2015-03-21 18:18:07 +01:00
|
|
|
|
2015-10-18 01:39:25 +02:00
|
|
|
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.controlcenter_swipe_layout);
|
|
|
|
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
|
|
|
fetchActivityData();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-01 16:57:45 +02:00
|
|
|
registerForContextMenu(deviceListView);
|
|
|
|
|
2015-05-10 17:05:24 +02:00
|
|
|
IntentFilter filterLocal = new IntentFilter();
|
2015-12-07 23:33:32 +01:00
|
|
|
filterLocal.addAction(GBApplication.ACTION_QUIT);
|
2015-05-10 17:05:24 +02:00
|
|
|
filterLocal.addAction(ACTION_REFRESH_DEVICELIST);
|
|
|
|
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
|
|
|
filterLocal.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
|
|
|
|
|
|
|
registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
|
2015-03-21 18:18:07 +01:00
|
|
|
|
2015-03-22 12:46:28 +01:00
|
|
|
refreshPairedDevices();
|
2015-01-18 22:44:38 +01:00
|
|
|
/*
|
|
|
|
* Ask for permission to intercept notifications on first run.
|
|
|
|
*/
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (sharedPrefs.getBoolean("firstrun", true)) {
|
2015-05-10 16:56:09 +02:00
|
|
|
sharedPrefs.edit().putBoolean("firstrun", false).apply();
|
2015-01-18 22:44:38 +01:00
|
|
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
|
|
|
startActivity(enableIntent);
|
|
|
|
}
|
2016-02-21 15:26:24 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
checkAndRequestPermissions();
|
|
|
|
}
|
|
|
|
|
2016-03-02 00:36:39 +01:00
|
|
|
ChangeLog cl = new ChangeLog(this);
|
|
|
|
if (cl.isFirstRun()) {
|
|
|
|
cl.getLogDialog().show();
|
|
|
|
}
|
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().start();
|
2015-02-06 13:55:44 +01:00
|
|
|
|
2015-10-18 01:39:25 +02:00
|
|
|
enableSwipeRefresh(selectedDevice);
|
2015-05-07 22:15:53 +02:00
|
|
|
if (GB.isBluetoothEnabled() && deviceList.isEmpty()) {
|
2015-05-06 22:59:31 +02:00
|
|
|
// start discovery when no devices are present
|
|
|
|
startActivity(new Intent(this, DiscoveryActivity.class));
|
|
|
|
} else {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().requestDeviceInfo();
|
2015-05-06 22:59:31 +02:00
|
|
|
}
|
2015-04-24 23:08:47 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 16:57:45 +02:00
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
|
|
|
selectedDevice = deviceList.get(acmi.position);
|
2015-06-07 15:31:42 +02:00
|
|
|
if (selectedDevice != null && selectedDevice.isBusy()) {
|
|
|
|
// no context menu when device is busy
|
|
|
|
return;
|
|
|
|
}
|
2015-06-22 22:16:19 +02:00
|
|
|
getMenuInflater().inflate(R.menu.controlcenter_context, menu);
|
|
|
|
|
2015-10-24 23:28:02 +02:00
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(selectedDevice);
|
2015-12-09 00:03:39 +01:00
|
|
|
if (!coordinator.supportsActivityDataFetching()) {
|
2015-06-22 22:16:19 +02:00
|
|
|
menu.removeItem(R.id.controlcenter_fetch_activity_data);
|
|
|
|
}
|
2015-12-09 00:03:39 +01:00
|
|
|
if (!coordinator.supportsScreenshots()) {
|
2015-06-24 00:23:38 +02:00
|
|
|
menu.removeItem(R.id.controlcenter_take_screenshot);
|
|
|
|
}
|
|
|
|
|
2015-08-24 13:19:17 +02:00
|
|
|
if (selectedDevice.getState() == GBDevice.State.NOT_CONNECTED) {
|
2015-06-22 22:16:19 +02:00
|
|
|
menu.removeItem(R.id.controlcenter_disconnect);
|
2015-08-24 13:19:17 +02:00
|
|
|
}
|
|
|
|
if (!selectedDevice.isInitialized()) {
|
2015-06-22 22:16:19 +02:00
|
|
|
menu.removeItem(R.id.controlcenter_find_device);
|
2015-12-09 00:03:39 +01:00
|
|
|
menu.removeItem(R.id.controlcenter_fetch_activity_data);
|
|
|
|
menu.removeItem(R.id.controlcenter_configure_alarms);
|
|
|
|
menu.removeItem(R.id.controlcenter_take_screenshot);
|
2015-06-22 22:16:19 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 16:57:45 +02:00
|
|
|
menu.setHeaderTitle(selectedDevice.getName());
|
|
|
|
}
|
|
|
|
|
2015-10-18 01:39:25 +02:00
|
|
|
private void enableSwipeRefresh(GBDevice device) {
|
2015-10-24 23:28:02 +02:00
|
|
|
if (device == null) {
|
|
|
|
swipeLayout.setEnabled(false);
|
|
|
|
} else {
|
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
|
|
|
boolean enable = coordinator.allowFetchActivityData(device);
|
|
|
|
swipeLayout.setEnabled(enable);
|
|
|
|
}
|
2015-10-18 01:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchActivityData() {
|
|
|
|
if (selectedDevice == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (selectedDevice.isInitialized()) {
|
|
|
|
GBApplication.deviceService().onFetchActivityData();
|
|
|
|
} else {
|
|
|
|
swipeLayout.setRefreshing(false);
|
|
|
|
GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 16:57:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.controlcenter_start_sleepmonitor:
|
|
|
|
if (selectedDevice != null) {
|
2015-06-13 20:37:53 +02:00
|
|
|
Intent startIntent;
|
2015-07-11 00:03:41 +02:00
|
|
|
startIntent = new Intent(ControlCenter.this, ChartsActivity.class);
|
2015-08-03 01:17:02 +02:00
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, selectedDevice);
|
2015-06-01 16:57:45 +02:00
|
|
|
startActivity(startIntent);
|
|
|
|
}
|
|
|
|
return true;
|
2015-06-06 19:39:04 +02:00
|
|
|
case R.id.controlcenter_fetch_activity_data:
|
2015-10-18 01:39:25 +02:00
|
|
|
fetchActivityData();
|
2015-06-08 23:30:51 +02:00
|
|
|
return true;
|
2015-06-07 15:31:42 +02:00
|
|
|
case R.id.controlcenter_disconnect:
|
|
|
|
if (selectedDevice != null) {
|
|
|
|
selectedDevice = null;
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().disconnect();
|
2015-06-07 15:31:42 +02:00
|
|
|
}
|
2015-06-08 23:30:51 +02:00
|
|
|
return true;
|
2015-06-21 00:34:05 +02:00
|
|
|
case R.id.controlcenter_find_device:
|
|
|
|
if (selectedDevice != null) {
|
|
|
|
findDevice(true);
|
2015-06-24 00:23:38 +02:00
|
|
|
ProgressDialog.show(
|
2015-06-21 00:34:05 +02:00
|
|
|
this,
|
|
|
|
getString(R.string.control_center_find_lost_device),
|
|
|
|
getString(R.string.control_center_cancel_to_stop_vibration),
|
|
|
|
true, true,
|
|
|
|
new DialogInterface.OnCancelListener() {
|
|
|
|
@Override
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
2015-06-22 22:16:19 +02:00
|
|
|
findDevice(false);
|
2015-06-21 00:34:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-06-30 21:18:27 +02:00
|
|
|
return true;
|
2015-06-24 20:14:08 +02:00
|
|
|
case R.id.controlcenter_configure_alarms:
|
|
|
|
if (selectedDevice != null) {
|
|
|
|
Intent startIntent;
|
|
|
|
startIntent = new Intent(ControlCenter.this, ConfigureAlarms.class);
|
|
|
|
startActivity(startIntent);
|
|
|
|
}
|
2015-06-24 00:23:38 +02:00
|
|
|
return true;
|
|
|
|
case R.id.controlcenter_take_screenshot:
|
|
|
|
if (selectedDevice != null) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onScreenshotReq();
|
2015-06-24 00:23:38 +02:00
|
|
|
}
|
|
|
|
return true;
|
2015-06-01 16:57:45 +02:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-21 00:34:05 +02:00
|
|
|
private void findDevice(boolean start) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onFindDevice(start);
|
2015-06-21 00:34:05 +02:00
|
|
|
}
|
2015-06-01 16:57:45 +02:00
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2015-03-27 11:23:30 +01:00
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_settings:
|
|
|
|
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
|
|
|
startActivity(settingsIntent);
|
|
|
|
return true;
|
|
|
|
case R.id.action_debug:
|
|
|
|
Intent debugIntent = new Intent(this, DebugActivity.class);
|
|
|
|
startActivity(debugIntent);
|
|
|
|
return true;
|
|
|
|
case R.id.action_quit:
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().quit();
|
2015-03-27 11:23:30 +01:00
|
|
|
|
2015-12-07 23:33:32 +01:00
|
|
|
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
2015-03-27 11:23:30 +01:00
|
|
|
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
|
|
|
return true;
|
2015-05-05 00:48:02 +02:00
|
|
|
case R.id.action_discover:
|
|
|
|
Intent discoverIntent = new Intent(this, DiscoveryActivity.class);
|
|
|
|
startActivity(discoverIntent);
|
|
|
|
return true;
|
2015-03-22 13:10:45 +01:00
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2015-03-27 10:56:08 +01:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
2015-05-10 17:05:24 +02:00
|
|
|
unregisterReceiver(mReceiver);
|
2015-02-06 13:55:44 +01:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2015-03-22 12:46:28 +01:00
|
|
|
private void refreshPairedDevices() {
|
2015-12-13 00:43:07 +01:00
|
|
|
Set<GBDevice> availableDevices = DeviceHelper.getInstance().getAvailableDevices(this);
|
|
|
|
deviceList.retainAll(availableDevices);
|
|
|
|
for (GBDevice availableDevice : availableDevices) {
|
|
|
|
if (!deviceList.contains(availableDevice)) {
|
|
|
|
deviceList.add(availableDevice);
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 23:25:46 +02:00
|
|
|
boolean connected = false;
|
2015-04-19 12:35:23 +02:00
|
|
|
for (GBDevice device : deviceList) {
|
2015-04-20 10:50:30 +02:00
|
|
|
if (device.isConnected() || device.isConnecting()) {
|
2015-04-20 23:25:46 +02:00
|
|
|
connected = true;
|
2015-12-13 00:43:07 +01:00
|
|
|
break;
|
2015-04-19 12:35:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 00:43:07 +01:00
|
|
|
if (connected) {
|
|
|
|
hintTextView.setText(R.string.tap_connected_device_for_app_mananger);
|
|
|
|
} else if (!deviceList.isEmpty()) {
|
|
|
|
hintTextView.setText(R.string.tap_a_device_to_connect);
|
2015-03-22 12:46:28 +01:00
|
|
|
}
|
2015-10-18 01:01:13 +02:00
|
|
|
|
2015-12-13 00:43:07 +01:00
|
|
|
mGBDeviceAdapter.notifyDataSetChanged();
|
2015-10-18 01:01:13 +02:00
|
|
|
}
|
2016-02-21 15:26:24 +01:00
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.M)
|
|
|
|
private void checkAndRequestPermissions() {
|
|
|
|
List<String> wantedPermissions = new ArrayList<>();
|
|
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.BLUETOOTH);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.BLUETOOTH_ADMIN);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_CONTACTS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.CALL_PHONE);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_PHONE_STATE);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.PROCESS_OUTGOING_CALLS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.PROCESS_OUTGOING_CALLS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_SMS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.SEND_SMS);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add(Manifest.permission.READ_CALENDAR);
|
|
|
|
if (ContextCompat.checkSelfPermission(this, "com.fsck.k9.permission.READ_MESSAGES") == PackageManager.PERMISSION_DENIED)
|
|
|
|
wantedPermissions.add("com.fsck.k9.permission.READ_MESSAGES");
|
|
|
|
|
|
|
|
if (!wantedPermissions.isEmpty())
|
|
|
|
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
}
|