Further refinements:

- disconnect by long-pressing device icon (temporary)
- use level-list to show battery level + charging
- remove padding around cards list
- use style colors for action icons (supports dark theme)
- add secondary text to the themes, even though the color is the same
- replace the info icon with three vertical dots
master
Daniele Gobbetti 2016-10-21 17:44:36 +02:00
parent 68f83d3f33
commit 00938baf7d
14 changed files with 206 additions and 70 deletions

View File

@ -2,7 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -14,7 +13,6 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.Collections;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -24,7 +22,6 @@ import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
/**
@ -57,6 +54,16 @@ public class GBDeviceAdapterv2 extends ArrayAdapter<GBDevice> {
TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
final ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
deviceImageView.setOnLongClickListener(new View.OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
//TODO: move somewhere else
GBApplication.deviceService().disconnect();
return true;
}
});
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
@ -82,110 +89,120 @@ public class GBDeviceAdapterv2 extends ArrayAdapter<GBDevice> {
batteryStatusBox.setVisibility(View.VISIBLE);
batteryStatusLabel.setText(device.getBatteryLevel() + "%");
BatteryState batteryState = device.getBatteryState();
if (BatteryState.BATTERY_LOW.equals(batteryState)) {
//batteryIcon.setImageTintMode(olor.RED);
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
batteryIcon.setImageLevel(device.getBatteryLevel() + 100);
} else {
batteryStatusLabel.setTextColor(ContextCompat.getColor(getContext(), R.color.secondarytext));
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
batteryStatusLabel.append(" CHG");
}
batteryIcon.setImageLevel(device.getBatteryLevel());
}
}
//fetch activity data
ImageView fetchActivityData = (ImageView) view.findViewById(R.id.device_action_fetch_activity);
LinearLayout fetchActivityDataBox = (LinearLayout) view.findViewById(R.id.device_action_fetch_activity_box);
fetchActivityDataBox.setVisibility((device.isConnected() && coordinator.supportsActivityDataFetching()) ? View.VISIBLE : View.GONE);
fetchActivityData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GBApplication.deviceService().onFetchActivityData();
}
}
fetchActivityDataBox.setVisibility((device.isInitialized() && coordinator.supportsActivityDataFetching()) ? View.VISIBLE : View.GONE);
fetchActivityData.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
GBApplication.deviceService().onFetchActivityData();
}
}
);
//take screenshot
ImageView takeScreenshotView = (ImageView) view.findViewById(R.id.device_action_take_screenshot);
takeScreenshotView.setVisibility((device.isConnected() && coordinator.supportsScreenshots()) ? View.VISIBLE : View.GONE);
takeScreenshotView.setOnClickListener(new View.OnClickListener() {
takeScreenshotView.setVisibility((device.isInitialized() && coordinator.supportsScreenshots()) ? View.VISIBLE : View.GONE);
takeScreenshotView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
GBApplication.deviceService().onScreenshotReq();
}
}
);
//set alarms
ImageView setAlarmsView = (ImageView) view.findViewById(R.id.device_action_set_alarms);
setAlarmsView.setVisibility(coordinator.supportsAlarmConfiguration() ? View.VISIBLE : View.GONE);
setAlarmsView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent startIntent;
startIntent = new Intent(context, ConfigureAlarms.class);
context.startActivity(startIntent);
}
}
setAlarmsView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent startIntent;
startIntent = new Intent(context, ConfigureAlarms.class);
context.startActivity(startIntent);
}
}
);
//show graphs
ImageView showActivityGraphs = (ImageView) view.findViewById(R.id.device_action_show_activity_graphs);
showActivityGraphs.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
showActivityGraphs.setOnClickListener(new View.OnClickListener() {
showActivityGraphs.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
Intent startIntent;
startIntent = new Intent(context, ChartsActivity.class);
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
context.startActivity(startIntent); }
context.startActivity(startIntent);
}
}
);
//Info icon is last in the row
ImageView deviceInfoView = (ImageView) view.findViewById(R.id.device_info_image);
final RelativeLayout deviceInfoBox = (RelativeLayout) view.findViewById(R.id.device_item_infos_box);
final ListView deviceInfoList = (ListView) view.findViewById(R.id.device_item_infos);
//TODO: can we spare all these additional layouts? find out more.
ListView deviceInfoList = (ListView) view.findViewById(R.id.device_item_infos);
ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos());
infoAdapter.setHorizontalAlignment(true);
deviceInfoList.setAdapter(infoAdapter);
justifyListViewHeightBasedOnChildren(deviceInfoList);
deviceInfoList.setFocusable(false);
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 (deviceInfoBox.getVisibility() == View.VISIBLE) {
deviceInfoBox.setVisibility(View.GONE);
} else {
ArrayAdapter adapter = (ArrayAdapter) deviceInfoList.getAdapter();
adapter.clear();
List<ItemWithDetails> infos = device.getDeviceInfos();
Collections.sort(infos);
adapter.addAll(infos);
justifyListViewHeightBasedOnChildren(deviceInfoList);
deviceInfoBox.setVisibility(View.VISIBLE);
deviceInfoBox.setFocusable(false);
}
}
});
@Override
public void onClick(View v) {
if (deviceInfoBox.getVisibility() == View.VISIBLE) {
deviceInfoBox.setVisibility(View.GONE);
} else {
deviceInfoBox.setVisibility(View.VISIBLE);
}
}
}
);
//remove device, hidden under details
ImageView removeDevice = (ImageView) view.findViewById(R.id.device_action_remove);
removeDevice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: the logic is bolted to controlcenter, but I don't think it belongs here
}
}
removeDevice.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
//TODO: the logic is bolted to controlcenter, but I don't think it belongs here
}
}
);
switch (device.getType()) {
switch (device.getType())
{
case PEBBLE:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_pebble);

View File

@ -0,0 +1,13 @@
<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="M7,17v3.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V17H7z"/>
<path
android:fillColor="#FF000000"
android:pathData="M17,5.33C17,4.6 16.4,4 15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V17h10V5.33z"
android:fillAlpha=".3"/>
</vector>

View File

@ -0,0 +1,13 @@
<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="M17,5.33C17,4.6 16.4,4 15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V13h10V5.33z"
android:fillAlpha=".3"/>
<path
android:fillColor="#FF000000"
android:pathData="M7,13v7.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V13H7z"/>
</vector>

View File

@ -0,0 +1,13 @@
<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="M17,5.33C17,4.6 16.4,4 15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V9h10V5.33z"
android:fillAlpha=".3"/>
<path
android:fillColor="#FF000000"
android:pathData="M7,9v11.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V9H7z"/>
</vector>

View File

@ -0,0 +1,13 @@
<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="M11,20v-3H7v3.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V17h-4.4L11,20z"/>
<path
android:fillColor="#FF000000"
android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V17h4v-2.5H9L13,7v5.5h2L12.6,17H17V5.33C17,4.6 16.4,4 15.67,4z"
android:fillAlpha=".3"/>
</vector>

View File

@ -0,0 +1,13 @@
<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="M14.47,13.5L11,20v-5.5H9l0.53,-1H7v7.17C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V13.5h-2.53z"/>
<path
android:fillColor="#FF000000"
android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v8.17h2.53L13,7v5.5h2l-0.53,1H17V5.33C17,4.6 16.4,4 15.67,4z"
android:fillAlpha=".3"/>
</vector>

View File

@ -0,0 +1,13 @@
<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="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33V9h4.93L13,7v2h4V5.33C17,4.6 16.4,4 15.67,4z"
android:fillAlpha=".3"/>
<path
android:fillColor="#FF000000"
android:pathData="M13,12.5h2L11,20v-5.5H9L11.93,9H7v11.67C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V9h-4v3.5z"/>
</vector>

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="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V5.33C17,4.6 16.4,4 15.67,4zM11,20v-5.5H9L13,7v5.5h2L11,20z"/>
</vector>

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="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="20" android:drawable="@drawable/ic_battery_20" />
<item android:maxLevel="50" android:drawable="@drawable/ic_battery_50" />
<item android:maxLevel="80" android:drawable="@drawable/ic_battery_80" />
<item android:maxLevel="100" android:drawable="@drawable/ic_battery_full" />
<item android:maxLevel="120" android:drawable="@drawable/ic_battery_charging_20" />
<item android:maxLevel="150" android:drawable="@drawable/ic_battery_charging_50" />
<item android:maxLevel="180" android:drawable="@drawable/ic_battery_charging_80" />
<item android:maxLevel="200" android:drawable="@drawable/ic_battery_charging_full" />
</level-list>

View File

@ -5,10 +5,6 @@
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2"
tools:showIn="@layout/activity_controlcenterv2_app_bar_main">

View File

@ -24,8 +24,10 @@
android:id="@+id/device_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="left|top"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/candidate_item_device_image"
android:longClickable="true"
tools:src="@drawable/ic_device_pebble" />
<TextView
@ -56,25 +58,27 @@
android:layout_below="@id/device_image"
android:layout_marginBottom="8dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="8dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:minWidth="36dp"
android:minWidth="48dp"
android:orientation="vertical">
<ImageView
android:id="@+id/device_battery_status"
android:layout_width="match_parent"
android:layout_height="36dp"
card_view:srcCompat="@drawable/ic_battery" />
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/level_list_battery" />
<TextView
android:id="@+id/battery_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/secondarytext"
android:gravity="center_horizontal"
android:minWidth="36dp"
android:textColor="?android:attr/textColor"
android:textStyle="bold"
tools:text="100% CHG" />
tools:text="100%" />
</LinearLayout>
@ -95,6 +99,7 @@
android:layout_height="36dp"
android:clickable="true"
android:contentDescription="@string/controlcenter_fetch_activity_data"
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/ic_action_fetch_activity_data" />
<ProgressBar
@ -117,6 +122,7 @@
android:layout_toRightOf="@id/device_action_fetch_activity_box"
android:clickable="true"
android:contentDescription="@string/controlcenter_take_screenshot"
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/ic_screenshot" />
<ImageView
@ -128,6 +134,7 @@
android:layout_toRightOf="@id/device_action_take_screenshot"
android:clickable="true"
android:contentDescription="@string/controlcenter_start_configure_alarms"
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/ic_device_set_alarms" />
<ImageView
@ -138,6 +145,7 @@
android:layout_margin="8dp"
android:layout_toRightOf="@id/device_action_set_alarms"
android:clickable="true"
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/ic_activity_graphs" />
<ImageView
@ -152,7 +160,8 @@
android:layout_marginTop="8dp"
android:clickable="true"
android:contentDescription="@string/candidate_item_device_image"
android:src="@drawable/ic_information_outline_grey600_24dp" />
android:tint="?android:attr/textColor"
android:src="@drawable/ic_more_vert" />
<RelativeLayout
@ -162,25 +171,30 @@
android:layout_alignParentBottom="true"
android:layout_below="@id/device_info_image"
android:layout_marginTop="8dp"
android:focusable="false"
android:visibility="gone">
<!--TODO: set width-->
<ListView
android:id="@+id/device_item_infos"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
android:focusable="false"
android:layout_alignParentLeft="true"
android:layout_toStartOf="@+id/device_action_remove"
android:scrollbars="none" />
<ImageView
android:id="@+id/device_action_remove"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="0dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:tint="?android:attr/textColor"
card_view:srcCompat="@drawable/ic_remove_device" />
</RelativeLayout>

View File

@ -2,6 +2,7 @@
<style name="GadgetbridgeTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/primarytext_light</item>
<item name="android:textColorSecondary">@color/secondarytext</item>
<item name="colorPrimary">@color/primary_light</item>
<item name="colorPrimaryDark">@color/primarydark_light</item>
<item name="colorAccent">@color/accent</item>
@ -15,6 +16,7 @@
</style>
<style name="GadgetbridgeThemeDark" parent="Theme.AppCompat">
<item name="android:textColor">@color/primarytext_dark</item>
<item name="android:textColorSecondary">@color/secondarytext</item>
<item name="colorPrimary">@color/primary_dark</item>
<item name="colorPrimaryDark">@color/primarydark_dark</item>
<item name="colorAccent">@color/accent</item>