1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

ControlCenterv2: further steps:

Close drawer before launching activities (feels sloow).
Implement device deletion (untested).
Add app-management icon, remove tap-connected-device-for-primary-activity, hidden (not removed) text hint.
Use level-list for device icon.
Use the new control center when tapping GB notifications.
Added icons to the legacy control center context menu, perhaps it can be embedded in the card?
This commit is contained in:
Daniele Gobbetti 2016-10-25 17:49:21 +02:00
parent d93a5be57a
commit d467b37493
8 changed files with 117 additions and 55 deletions

View File

@ -203,6 +203,9 @@ public class ControlCenterv2 extends AppCompatActivity
@Override
public boolean onNavigationItemSelected(MenuItem item) {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
switch (item.getItemId()) {
case R.id.action_settings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
@ -221,8 +224,6 @@ public class ControlCenterv2 extends AppCompatActivity
return true;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

View File

@ -1,10 +1,12 @@
package nodomain.freeyourgadget.gadgetbridge.adapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.RecyclerView;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
@ -17,6 +19,7 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
@ -25,9 +28,11 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureAlarms;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
/**
* Adapter for displaying GBDevice instances.
@ -57,29 +62,23 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
final GBDevice device = deviceList.get(position);
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
holder.deviceImageView.setImageResource(R.drawable.level_list_device);
//level-list does not allow negative values, hence we always add 100 to the key.
holder.deviceImageView.setImageLevel(device.getType().getKey() + 100 + (device.isInitialized() ? 100 : 0));
holder.deviceImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (device.isInitialized()) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
Class<? extends Activity> primaryActivity = coordinator.getPrimaryActivity();
if (primaryActivity != null) {
Intent startIntent = new Intent(context, primaryActivity);
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
context.startActivity(startIntent);
}
} else {
//TODO: move somewhere else
//TODO: move somewhere else?
GBApplication.deviceService().connect(device);
}
}
});
holder.deviceImageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//TODO: move somewhere else
//TODO: move somewhere else?
GBApplication.deviceService().disconnect();
return true;
}
@ -87,6 +86,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
holder.deviceNameLabel.setText(getUniqueDeviceName(device));
//TODO: snackbar!
if (device.isBusy()) {
holder.deviceStatusLabel.setText(device.getBusyTask());
holder.busyIndicator.setVisibility(View.VISIBLE);
@ -136,6 +136,24 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
}
);
//manage apps
holder.manageAppsView.setVisibility((device.isInitialized() && coordinator.supportsAppsManagement()) ? View.VISIBLE : View.GONE);
holder.manageAppsView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
Class<? extends Activity> appsManagementActivity = coordinator.getAppsManagementActivity();
if (appsManagementActivity != null) {
Intent startIntent = new Intent(context, appsManagementActivity);
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
context.startActivity(startIntent);
}
}
}
);
//set alarms
holder.setAlarmsView.setVisibility(coordinator.supportsAlarmConfiguration() ? View.VISIBLE : View.GONE);
holder.setAlarmsView.setOnClickListener(new View.OnClickListener()
@ -218,40 +236,37 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
{
@Override
public void onClick(View v) {
//TODO: the logic is bolted to controlcenter, but I don't think it belongs here
new AlertDialog.Builder(context)
.setCancelable(true)
.setTitle(context.getString(R.string.controlcenter_delete_device_name, device.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(device);
if (coordinator != null) {
coordinator.deleteDevice(device);
}
DeviceHelper.getInstance().removeBond(device);
} catch (Exception ex) {
GB.toast(context, "Error deleting device: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
} finally {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
}
}
})
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.show();
}
});
switch (device.getType()) {
case PEBBLE:
if (device.isConnected()) {
holder.deviceImageView.setImageResource(R.drawable.ic_device_pebble);
} else {
holder.deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
}
break;
case MIBAND:
case MIBAND2:
if (device.isConnected()) {
holder.deviceImageView.setImageResource(R.drawable.ic_device_miband);
} else {
holder.deviceImageView.setImageResource(R.drawable.ic_device_miband_disabled);
}
break;
case VIBRATISSIMO:
if (device.isConnected()) {
holder.deviceImageView.setImageResource(R.drawable.ic_device_lovetoy);
} else {
holder.deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
}
break;
default:
if (device.isConnected()) {
holder.deviceImageView.setImageResource(R.drawable.ic_launcher);
} else {
holder.deviceImageView.setImageResource(R.drawable.ic_device_default_disabled);
}
}
}
@Override
@ -273,6 +288,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
ImageView fetchActivityData;
ProgressBar busyIndicator;
ImageView takeScreenshotView;
ImageView manageAppsView;
ImageView setAlarmsView;
ImageView showActivityGraphs;
@ -297,6 +313,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
fetchActivityData = (ImageView) view.findViewById(R.id.device_action_fetch_activity);
busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
takeScreenshotView = (ImageView) view.findViewById(R.id.device_action_take_screenshot);
manageAppsView = (ImageView) view.findViewById(R.id.device_action_manage_apps);
setAlarmsView = (ImageView) view.findViewById(R.id.device_action_set_alarms);
showActivityGraphs = (ImageView) view.findViewById(R.id.device_action_show_activity_graphs);
deviceInfoView = (ImageView) view.findViewById(R.id.device_info_image);

View File

@ -26,7 +26,7 @@ import java.nio.ByteOrder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBEnvironment;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
public class GB {
@ -49,7 +49,7 @@ public class GB {
if (env().isLocalTest()) {
return null;
}
Intent notificationIntent = new Intent(context, ControlCenter.class);
Intent notificationIntent = new Intent(context, ControlCenterv2.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
@ -245,7 +245,7 @@ public class GB {
private static Notification createTransferNotification(String text, boolean ongoing,
int percentage, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class);
Intent notificationIntent = new Intent(context, ControlCenterv2.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
@ -286,7 +286,7 @@ public class GB {
private static Notification createInstallNotification(String text, boolean ongoing,
int percentage, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class);
Intent notificationIntent = new Intent(context, ControlCenterv2.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
@ -316,7 +316,7 @@ public class GB {
}
private static Notification createBatteryNotification(String text, String bigText, Context context) {
Intent notificationIntent = new Intent(context, ControlCenter.class);
Intent notificationIntent = new Intent(context, ControlCenterv2.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
</vector>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="99" android:drawable="@drawable/ic_device_default_disabled" />
<item android:maxLevel="101" android:drawable="@drawable/ic_device_pebble_disabled" />
<item android:maxLevel="110" android:drawable="@drawable/ic_device_miband_disabled" />
<item android:maxLevel="111" android:drawable="@drawable/ic_device_miband_disabled" />
<item android:maxLevel="120" android:drawable="@drawable/ic_device_lovetoy_disabled" />
<item android:maxLevel="199" android:drawable="@drawable/ic_launcher" />
<item android:maxLevel="201" android:drawable="@drawable/ic_device_pebble" />
<item android:maxLevel="210" android:drawable="@drawable/ic_device_miband" />
<item android:maxLevel="211" android:drawable="@drawable/ic_device_miband" />
<item android:maxLevel="220" android:drawable="@drawable/ic_device_lovetoy" />
</level-list>

View File

@ -23,7 +23,7 @@
<include layout="@layout/activity_controlcenterv2_content_main" />
<TextView
<!-- <TextView
android:id="@+id/hintTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -35,7 +35,7 @@
android:textStyle="italic"
android:text="@string/tap_connected_device_for_app_mananger"
android:elevation="0dp" />
-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"

View File

@ -129,13 +129,26 @@
card_view:srcCompat="@drawable/ic_screenshot" />
<ImageView
android:id="@+id/device_action_set_alarms"
android:id="@+id/device_action_manage_apps"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_below="@id/device_image"
android:layout_margin="8dp"
android:layout_toRightOf="@id/device_action_take_screenshot"
android:clickable="true"
android:contentDescription="@string/title_activity_appmanager"
android:tint="@color/secondarytext"
android:background="?android:attr/selectableItemBackground"
card_view:srcCompat="@drawable/ic_action_manage_apps" />
<ImageView
android:id="@+id/device_action_set_alarms"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_below="@id/device_image"
android:layout_margin="8dp"
android:layout_toRightOf="@id/device_action_manage_apps"
android:clickable="true"
android:contentDescription="@string/controlcenter_start_configure_alarms"
android:tint="@color/secondarytext"
android:background="?android:attr/selectableItemBackground"

View File

@ -2,21 +2,29 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/controlcenter_fetch_activity_data"
android:title="@string/controlcenter_fetch_activity_data"/>
android:icon="@drawable/ic_action_fetch_activity_data"
android:title="@string/controlcenter_fetch_activity_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<item
android:id="@+id/controlcenter_start_sleepmonitor"
android:icon="@drawable/ic_activity_graphs"
android:title="@string/controlcenter_start_activitymonitor"/>
<item
android:id="@+id/controlcenter_configure_alarms"
android:icon="@drawable/ic_device_set_alarms"
android:title="@string/controlcenter_start_configure_alarms"/>
<item
android:id="@+id/controlcenter_find_device"
android:icon="@drawable/ic_action_find_lost_device"
android:title="@string/controlcenter_find_device"/>
<item
android:id="@+id/controlcenter_take_screenshot"
android:icon="@drawable/ic_screenshot"
android:title="@string/controlcenter_take_screenshot"/>
<item
android:id="@+id/controlcenter_delete_device"
android:icon="@drawable/ic_remove_device"
android:title="@string/controlcenter_delete_device"/>
<item
android:id="@+id/controlcenter_disconnect"