From 0ac77fc0a46b8726613ddc3682a0562cef792845 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Sat, 11 Mar 2017 19:49:57 +0100 Subject: [PATCH] Remove the legacy ControlCenter and its usages. Add New GUI to the changelog. --- CHANGELOG.md | 3 +- app/src/main/AndroidManifest.xml | 36 +- .../activities/ControlCenter.java | 451 ------------------ .../gadgetbridge/adapter/GBDeviceAdapter.java | 187 -------- .../devices/UnknownDeviceCoordinator.java | 4 +- .../devices/miband/MiBandPairingActivity.java | 4 +- .../devices/pebble/PebblePairingActivity.java | 5 +- .../res/layout/activity_controlcenter.xml | 62 --- .../res/layout/activity_db_management.xml | 2 +- app/src/main/res/layout/activity_debug.xml | 2 +- app/src/main/res/layout/device_item.xml | 95 ---- .../main/res/menu/controlcenter_context.xml | 32 -- app/src/main/res/menu/menu_main.xml | 16 - app/src/main/res/xml/changelog_master.xml | 1 + 14 files changed, 25 insertions(+), 875 deletions(-) delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java delete mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java delete mode 100644 app/src/main/res/layout/activity_controlcenter.xml delete mode 100644 app/src/main/res/layout/device_item.xml delete mode 100644 app/src/main/res/menu/controlcenter_context.xml delete mode 100644 app/src/main/res/menu/menu_main.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a608e7f..82201e061 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ###Changelog -###Version 0.18.0 (next) +###Version 0.18.0 +* All new GUI for the control center * Add Portuguese pt_PT and pt_BR translations * Add Czech translation * Add Hebrew translation and transliteration diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c1908a39b..df30fac78 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,18 +37,19 @@ android:label="@string/app_name" android:theme="@style/GadgetbridgeTheme"> + android:name=".activities.ControlCenterv2" + android:label="@string/title_activity_controlcenter" + android:theme="@style/GadgetbridgeTheme.NoActionBar"> + - + android:parentActivityName=".activities.ControlCenterv2" /> + android:parentActivityName=".activities.ControlCenterv2" /> + android:parentActivityName=".activities.ControlCenterv2"> @@ -303,19 +304,19 @@ + android:parentActivityName=".activities.ControlCenterv2" /> @@ -328,7 +329,7 @@ + android:parentActivityName=".activities.ControlCenterv2" /> + android:parentActivityName=".activities.ControlCenterv2" /> + android:value="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2" /> @@ -385,16 +386,7 @@ - - - - - - - + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java deleted file mode 100644 index 0359eb434..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ /dev/null @@ -1,451 +0,0 @@ -/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Daniele - Gobbetti, Lem Dulfo - - This file is part of Gadgetbridge. - - Gadgetbridge is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Gadgetbridge is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . */ -package nodomain.freeyourgadget.gadgetbridge.activities; - -import android.Manifest; -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.ProgressDialog; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v4.widget.SwipeRefreshLayout; -import android.view.ContextMenu; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.Toast; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -import de.cketti.library.changelog.ChangeLog; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; -import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity; -import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter; -import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; -import nodomain.freeyourgadget.gadgetbridge.util.GB; -import nodomain.freeyourgadget.gadgetbridge.util.Prefs; - -public class ControlCenter extends GBActivity { - - private static final Logger LOG = LoggerFactory.getLogger(ControlCenter.class); - - private TextView hintTextView; - private FloatingActionButton fab; - private ImageView background; - - private SwipeRefreshLayout swipeLayout; - private GBDeviceAdapter mGBDeviceAdapter; - private DeviceManager deviceManager; - /** - * Temporary field for the context menu - */ - private GBDevice selectedDevice; - - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - switch (action) { - case GBApplication.ACTION_QUIT: - finish(); - break; - case DeviceManager.ACTION_DEVICES_CHANGED: - refreshPairedDevices(); - GBDevice selectedDevice = deviceManager.getSelectedDevice(); - if (selectedDevice != null) { - refreshBusyState(selectedDevice); - enableSwipeRefresh(selectedDevice); - } - break; - } - } - }; - - private void refreshBusyState(GBDevice dev) { - if (dev != null && dev.isBusy()) { - swipeLayout.setRefreshing(true); - } else { - boolean wasBusy = swipeLayout.isRefreshing(); - if (wasBusy) { - swipeLayout.setRefreshing(false); - } - } - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_controlcenter); - - deviceManager = ((GBApplication)getApplication()).getDeviceManager(); - - hintTextView = (TextView) findViewById(R.id.hintTextView); - ListView deviceListView = (ListView) findViewById(R.id.deviceListView); - fab = (FloatingActionButton) findViewById(R.id.fab); - background = (ImageView) findViewById(R.id.no_items_bg); - - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - launchDiscoveryActivity(); - } - }); - - final List deviceList = deviceManager.getDevices(); - mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList); - deviceListView.setAdapter(this.mGBDeviceAdapter); - deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View v, int position, long id) { - GBDevice gbDevice = mGBDeviceAdapter.getItem(position); - if (gbDevice.isInitialized()) { - DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice); - Class primaryActivity = coordinator.getPrimaryActivity(); - if (primaryActivity != null) { - Intent startIntent = new Intent(ControlCenter.this, primaryActivity); - startIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice); - startActivity(startIntent); - } - } else { - GBApplication.deviceService().connect(gbDevice); - } - } - }); - - swipeLayout = (SwipeRefreshLayout) findViewById(R.id.controlcenter_swipe_layout); - swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - fetchActivityData(); - } - }); - - registerForContextMenu(deviceListView); - - IntentFilter filterLocal = new IntentFilter(); - filterLocal.addAction(GBApplication.ACTION_QUIT); - filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED); - LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal); - - refreshPairedDevices(); - /* - * Ask for permission to intercept notifications on first run. - */ - Prefs prefs = GBApplication.getPrefs(); - if (prefs.getBoolean("firstrun", true)) { - prefs.getPreferences().edit().putBoolean("firstrun", false).apply(); - Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); - startActivity(enableIntent); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - checkAndRequestPermissions(); - } - - ChangeLog cl = new ChangeLog(this); - if (cl.isFirstRun()) { - cl.getLogDialog().show(); - } - - GBApplication.deviceService().start(); - - enableSwipeRefresh(deviceManager.getSelectedDevice()); - if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - startActivity(new Intent(this, DiscoveryActivity.class)); - } else { - GBApplication.deviceService().requestDeviceInfo(); - } - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo; - selectedDevice = mGBDeviceAdapter.getItem(acmi.position); - if (selectedDevice != null && selectedDevice.isBusy()) { - // no context menu when device is busy - return; - } - getMenuInflater().inflate(R.menu.controlcenter_context, menu); - - DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(selectedDevice); - if (!coordinator.supportsActivityDataFetching()) { - menu.removeItem(R.id.controlcenter_fetch_activity_data); - } - if (!coordinator.supportsScreenshots()) { - menu.removeItem(R.id.controlcenter_take_screenshot); - } - if (!coordinator.supportsAlarmConfiguration()) { - menu.removeItem(R.id.controlcenter_configure_alarms); - } - if (!coordinator.supportsActivityTracking()) { - menu.removeItem(R.id.controlcenter_start_sleepmonitor); - } - - if (selectedDevice.getState() == GBDevice.State.NOT_CONNECTED) { - menu.removeItem(R.id.controlcenter_disconnect); - } - if (!selectedDevice.isInitialized()) { - menu.removeItem(R.id.controlcenter_find_device); - menu.removeItem(R.id.controlcenter_fetch_activity_data); - menu.removeItem(R.id.controlcenter_configure_alarms); - menu.removeItem(R.id.controlcenter_take_screenshot); - } - - menu.setHeaderTitle(selectedDevice.getName()); - } - - private void enableSwipeRefresh(GBDevice device) { - if (device == null) { - swipeLayout.setEnabled(false); - } else { - DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device); - boolean enable = coordinator.allowFetchActivityData(device); - swipeLayout.setEnabled(enable); - } - } - - private void fetchActivityData() { - GBDevice selectedDevice = deviceManager.getSelectedDevice(); - 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); - } - } - - @Override - public boolean onContextItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.controlcenter_start_sleepmonitor: - if (selectedDevice != null) { - Intent startIntent; - startIntent = new Intent(ControlCenter.this, ChartsActivity.class); - startIntent.putExtra(GBDevice.EXTRA_DEVICE, selectedDevice); - startActivity(startIntent); - } - return true; - case R.id.controlcenter_fetch_activity_data: - fetchActivityData(); - return true; - case R.id.controlcenter_disconnect: - if (selectedDevice != null) { - selectedDevice = null; - GBApplication.deviceService().disconnect(); - } - return true; - case R.id.controlcenter_find_device: - if (selectedDevice != null) { - findDevice(true); - ProgressDialog.show( - 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) { - findDevice(false); - } - }); - } - return true; - case R.id.controlcenter_configure_alarms: - if (selectedDevice != null) { - Intent startIntent; - startIntent = new Intent(ControlCenter.this, ConfigureAlarms.class); - startIntent.putExtra(GBDevice.EXTRA_DEVICE, selectedDevice); - startActivity(startIntent); - } - return true; - case R.id.controlcenter_take_screenshot: - if (selectedDevice != null) { - GBApplication.deviceService().onScreenshotReq(); - } - return true; - case R.id.controlcenter_delete_device: - if (selectedDevice != null) { - confirmDeleteDevice(selectedDevice); - } - return true; - default: - return super.onContextItemSelected(item); - } - } - - private void findDevice(boolean start) { - GBApplication.deviceService().onFindDevice(start); - } - - @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) { - - 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_db_management: - Intent dbIntent = new Intent(this, DbManagementActivity.class); - startActivity(dbIntent); - return true; - case R.id.action_quit: - GBApplication.quit(); - return true; - } - - return super.onOptionsItemSelected(item); - } - - private void launchDiscoveryActivity() { - startActivity(new Intent(this, DiscoveryActivity.class)); - } - - private void confirmDeleteDevice(final GBDevice gbDevice) { - new AlertDialog.Builder(this) - .setCancelable(true) - .setTitle(getString(R.string.controlcenter_delete_device_name, gbDevice.getName())) - .setMessage(R.string.controlcenter_delete_device_dialogmessage) - .setPositiveButton(R.string.Delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - try { - DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice); - if (coordinator != null) { - coordinator.deleteDevice(selectedDevice); - } - DeviceHelper.getInstance().removeBond(selectedDevice); - } catch (Exception ex) { - GB.toast(ControlCenter.this, "Error deleting device: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex); - } finally { - selectedDevice = null; - Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST); - LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(refreshIntent); - } - } - }) - .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // do nothing - } - }) - .show(); - } - - @Override - protected void onDestroy() { - LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); - super.onDestroy(); - } - - private void refreshPairedDevices() { - List deviceList = deviceManager.getDevices(); - GBDevice connectedDevice = null; - - for (GBDevice device : deviceList) { - if (device.isConnected() || device.isConnecting()) { - connectedDevice = device; - break; - } - } - - if (deviceList.isEmpty()) { - background.setVisibility(View.VISIBLE); - } else { - background.setVisibility(View.INVISIBLE); - } - - if (connectedDevice != null) { - DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(connectedDevice); - hintTextView.setText(coordinator.getTapString()); - } else if (!deviceList.isEmpty()) { - hintTextView.setText(R.string.tap_a_device_to_connect); - } - - mGBDeviceAdapter.notifyDataSetChanged(); - } - - @TargetApi(Build.VERSION_CODES.M) - private void checkAndRequestPermissions() { - List 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 (!wantedPermissions.isEmpty()) - ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0); - } - - -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java deleted file mode 100644 index 42661e8b2..000000000 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAdapter.java +++ /dev/null @@ -1,187 +0,0 @@ -/* Copyright (C) 2015-2017 Andreas Shimokawa, Carsten Pfeiffer, Daniele - Gobbetti, João Paulo Barraca, Lem Dulfo - - This file is part of Gadgetbridge. - - Gadgetbridge is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Gadgetbridge is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . */ -package nodomain.freeyourgadget.gadgetbridge.adapter; - -import android.content.Context; -import android.graphics.Color; -import android.support.v4.content.ContextCompat; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; - -import java.util.Collections; -import java.util.List; - -import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; -import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails; - -/** - * Adapter for displaying GBDevice instances. - */ -public class GBDeviceAdapter extends ArrayAdapter { - - private final Context context; - - public GBDeviceAdapter(Context context, List deviceList) { - super(context, 0, deviceList); - - this.context = context; - } - - @Override - public View getView(int position, View view, ViewGroup parent) { - final GBDevice device = getItem(position); - - if (view == null) { - LayoutInflater inflater = (LayoutInflater) context - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - - view = inflater.inflate(R.layout.device_item, parent, false); - } - TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status); - TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name); - final ListView deviceInfoList = (ListView) view.findViewById(R.id.device_item_infos); - ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos()); - infoAdapter.setHorizontalAlignment(true); - deviceInfoList.setAdapter(infoAdapter); - TextView batteryLabel = (TextView) view.findViewById(R.id.battery_label); - TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status); - final ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image); - ImageView deviceInfoView = (ImageView) view.findViewById(R.id.device_info_image); - ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator); - - deviceNameLabel.setText(getUniqueDeviceName(device)); - - if (device.isBusy()) { - deviceStatusLabel.setText(device.getBusyTask()); - busyIndicator.setVisibility(View.VISIBLE); - batteryLabel.setVisibility(View.INVISIBLE); - batteryStatusLabel.setVisibility(View.INVISIBLE); - } else { - deviceStatusLabel.setText(device.getStateString()); - busyIndicator.setVisibility(View.INVISIBLE); - batteryLabel.setVisibility(View.VISIBLE); - batteryStatusLabel.setVisibility(View.VISIBLE); - } - - boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy(); - deviceInfoView.setVisibility(showInfoIcon ? View.VISIBLE : View.GONE); - deviceInfoView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (deviceInfoList.getVisibility() == View.VISIBLE) { - deviceInfoList.setVisibility(View.GONE); - } else { - ArrayAdapter adapter = (ArrayAdapter) deviceInfoList.getAdapter(); - adapter.clear(); - List infos = device.getDeviceInfos(); - Collections.sort(infos); - adapter.addAll(infos); - justifyListViewHeightBasedOnChildren(deviceInfoList); - deviceInfoList.setVisibility(View.VISIBLE); - deviceInfoList.setFocusable(false); - } - } - }); - - short batteryLevel = device.getBatteryLevel(); - if (batteryLevel != GBDevice.BATTERY_UNKNOWN) { - batteryLabel.setText("BAT:"); - batteryStatusLabel.setText(device.getBatteryLevel() + "%"); - BatteryState batteryState = device.getBatteryState(); - if (BatteryState.BATTERY_LOW.equals(batteryState)) { - batteryLabel.setTextColor(Color.RED); - batteryStatusLabel.setTextColor(Color.RED); - } else { - batteryLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext)); - batteryStatusLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext)); - - if (BatteryState.BATTERY_CHARGING.equals(batteryState) || - BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) { - batteryStatusLabel.append(" CHG"); - } - } - } else { - batteryLabel.setText(""); - batteryStatusLabel.setText(""); - } - - if (device.isConnected()) { - deviceImageView.setImageResource(device.getType().getIcon()); - } else { - deviceImageView.setImageResource(device.getType().getDisabledIcon()); - } - - return view; - } - - public void justifyListViewHeightBasedOnChildren(ListView listView) { - ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter(); - - if (adapter == null) { - return; - } - ViewGroup vg = listView; - int totalHeight = 0; - for (int i = 0; i < adapter.getCount(); i++) { - View listItem = adapter.getView(i, null, vg); - listItem.measure(0, 0); - totalHeight += listItem.getMeasuredHeight(); - } - - ViewGroup.LayoutParams par = listView.getLayoutParams(); - par.height = totalHeight + (listView.getDividerHeight() * (adapter.getCount() - 1)); - listView.setLayoutParams(par); - listView.requestLayout(); - } - - private String getUniqueDeviceName(GBDevice device) { - String deviceName = device.getName(); - if (!isUniqueDeviceName(device, deviceName)) { - if (device.getModel() != null) { - deviceName = deviceName + " " + device.getModel(); - if (!isUniqueDeviceName(device, deviceName)) { - deviceName = deviceName + " " + device.getShortAddress(); - } - } else { - deviceName = deviceName + " " + device.getShortAddress(); - } - } - return deviceName; - } - - private boolean isUniqueDeviceName(GBDevice device, String deviceName) { - for (int i = 0; i < getCount(); i++) { - GBDevice item = getItem(i); - if (item == device) { - continue; - } - if (deviceName.equals(item.getName())) { - return false; - } - } - return true; - } -} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java index e24315689..9451190e6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/UnknownDeviceCoordinator.java @@ -26,7 +26,7 @@ import android.support.annotation.Nullable; import java.util.List; import nodomain.freeyourgadget.gadgetbridge.GBException; -import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter; +import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2; import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; @@ -114,7 +114,7 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator { @Override public Class getPairingActivity() { - return ControlCenter.class; + return ControlCenterv2.class; } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java index c3b1348e5..5e5a33f33 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPairingActivity.java @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter; +import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2; import nodomain.freeyourgadget.gadgetbridge.activities.DiscoveryActivity; import nodomain.freeyourgadget.gadgetbridge.activities.GBActivity; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; @@ -219,7 +219,7 @@ public class MiBandPairingActivity extends GBActivity { Prefs prefs = GBApplication.getPrefs(); prefs.getPreferences().edit().putString(MiBandConst.PREF_MIBAND_ADDRESS, macAddress).apply(); } - Intent intent = new Intent(this, ControlCenter.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + Intent intent = new Intent(this, ControlCenterv2.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } finish(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebblePairingActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebblePairingActivity.java index cb7833f21..017a60504 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebblePairingActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebblePairingActivity.java @@ -23,7 +23,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import android.os.Parcelable; import android.support.v4.content.LocalBroadcastManager; import android.widget.TextView; import android.widget.Toast; @@ -36,7 +35,7 @@ import java.util.List; import de.greenrobot.dao.query.Query; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter; +import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2; import nodomain.freeyourgadget.gadgetbridge.activities.DiscoveryActivity; import nodomain.freeyourgadget.gadgetbridge.activities.GBActivity; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; @@ -184,7 +183,7 @@ public class PebblePairingActivity extends GBActivity { unregisterReceiver(mBondingReceiver); if (pairedSuccessfully) { - Intent intent = new Intent(this, ControlCenter.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + Intent intent = new Intent(this, ControlCenterv2.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } finish(); diff --git a/app/src/main/res/layout/activity_controlcenter.xml b/app/src/main/res/layout/activity_controlcenter.xml deleted file mode 100644 index 1be7d667c..000000000 --- a/app/src/main/res/layout/activity_controlcenter.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_db_management.xml b/app/src/main/res/layout/activity_db_management.xml index 0bf641ccf..a66eba216 100644 --- a/app/src/main/res/layout/activity_db_management.xml +++ b/app/src/main/res/layout/activity_db_management.xml @@ -2,7 +2,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter"> + tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2"> + tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2"> - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/controlcenter_context.xml b/app/src/main/res/menu/controlcenter_context.xml deleted file mode 100644 index 6a927e0d2..000000000 --- a/app/src/main/res/menu/controlcenter_context.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml deleted file mode 100644 index a27653150..000000000 --- a/app/src/main/res/menu/menu_main.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index 30d16c40a..d8314326c 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -1,6 +1,7 @@ + All new GUI for the control center Add Portuguese pt_PT and pt_BR translations Add Czech translation Add Hebrew translation and transliteration