Fixed KitKat crashes and changed to RelativeLayout. Using CCv2 as default launcher activity.
Added lost-device icon and action, added background to buttons. Overflow reveal is now animated inside the card. Bind connect and disconnect actions to device-icon (short press to connect/launch default activity; long press to disconnect).
This commit is contained in:
parent
84f36b528a
commit
cde09d71bc
|
@ -67,6 +67,7 @@ dependencies {
|
|||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:23.4.0'
|
||||
compile 'com.android.support:cardview-v7:23.4.0'
|
||||
compile 'com.android.support:recyclerview-v7:23.4.0'
|
||||
compile 'com.android.support:support-v4:23.4.0'
|
||||
compile 'com.android.support:design:23.4.0'
|
||||
compile 'com.github.tony19:logback-android-classic:1.1.1-4'
|
||||
|
|
|
@ -302,6 +302,7 @@
|
|||
android:label="@string/title_activity_controlcenter"
|
||||
android:theme="@style/GadgetbridgeTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
|
|
@ -2,12 +2,12 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
|||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
@ -19,13 +19,16 @@ import android.support.v4.view.GravityCompat;
|
|||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -45,11 +48,18 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|||
public class ControlCenterv2 extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
//needed for KK compatibility
|
||||
static {
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
}
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
private ImageView background;
|
||||
private TextView hintTextView;
|
||||
|
||||
private List<GBDevice> deviceList;
|
||||
private GBDeviceAdapterv2 mGBDeviceAdapter;
|
||||
private RecyclerView deviceListView;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
|
@ -99,30 +109,51 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||
//end of material design boilerplate
|
||||
deviceManager = GBApplication.getDeviceManager();
|
||||
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
||||
ListView deviceListView = (ListView) findViewById(R.id.deviceListView);
|
||||
|
||||
deviceListView = (RecyclerView) findViewById(R.id.deviceListView);
|
||||
deviceListView.setHasFixedSize(true);
|
||||
deviceListView.setLayoutManager(new LinearLayoutManager(this));
|
||||
background = (ImageView) findViewById(R.id.no_items_bg);
|
||||
|
||||
final List<GBDevice> deviceList = deviceManager.getDevices();
|
||||
deviceList = deviceManager.getDevices();
|
||||
mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList);
|
||||
|
||||
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
||||
deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
||||
ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
|
||||
ItemTouchHelper.LEFT , ItemTouchHelper.RIGHT) {
|
||||
@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<? extends Activity> primaryActivity = coordinator.getPrimaryActivity();
|
||||
if (primaryActivity != null) {
|
||||
Intent startIntent = new Intent(ControlCenterv2.this, primaryActivity);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, gbDevice);
|
||||
startActivity(startIntent);
|
||||
}
|
||||
} else {
|
||||
GBApplication.deviceService().connect(gbDevice);
|
||||
}
|
||||
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
|
||||
if(dX>50)
|
||||
dX = 50;
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildDrawOver(Canvas c, RecyclerView recyclerView,
|
||||
RecyclerView.ViewHolder viewHolder, float dX, float dY,
|
||||
int actionState, boolean isCurrentlyActive) {
|
||||
}
|
||||
});
|
||||
|
||||
//uncomment to enable fixed-swipe to reveal more actions
|
||||
//swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
|
||||
|
||||
|
||||
registerForContextMenu(deviceListView);
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
|
@ -257,5 +288,4 @@ public class ControlCenterv2 extends AppCompatActivity
|
|||
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.transition.TransitionManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -27,213 +32,282 @@ import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
|||
/**
|
||||
* Adapter for displaying GBDevice instances.
|
||||
*/
|
||||
public class GBDeviceAdapterv2 extends ArrayAdapter<GBDevice> {
|
||||
public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.ViewHolder> {
|
||||
|
||||
private final Context context;
|
||||
private DeviceCoordinator coordinator;
|
||||
private List<GBDevice> deviceList;
|
||||
private int expandedDevicePosition = RecyclerView.NO_POSITION;
|
||||
private ViewGroup parent;
|
||||
|
||||
public GBDeviceAdapterv2(Context context, List<GBDevice> deviceList) {
|
||||
super(context, 0, deviceList);
|
||||
|
||||
this.context = context;
|
||||
this.deviceList = deviceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
final GBDevice device = getItem(position);
|
||||
coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
public GBDeviceAdapterv2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
this.parent = parent;
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.device_itemv2, parent, false);
|
||||
ViewHolder vh = new ViewHolder(view);
|
||||
return vh;
|
||||
}
|
||||
|
||||
if (view == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, final int position) {
|
||||
final GBDevice device = deviceList.get(position);
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
|
||||
view = inflater.inflate(R.layout.device_itemv2, parent, false);
|
||||
}
|
||||
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
|
||||
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
|
||||
holder.deviceImageView.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
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 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
|
||||
GBApplication.deviceService().connect(device);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.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);
|
||||
|
||||
deviceNameLabel.setText(getUniqueDeviceName(device));
|
||||
holder.deviceNameLabel.setText(getUniqueDeviceName(device));
|
||||
|
||||
if (device.isBusy()) {
|
||||
deviceStatusLabel.setText(device.getBusyTask());
|
||||
busyIndicator.setVisibility(View.VISIBLE);
|
||||
holder.deviceStatusLabel.setText(device.getBusyTask());
|
||||
holder.busyIndicator.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
deviceStatusLabel.setText(device.getStateString());
|
||||
busyIndicator.setVisibility(View.INVISIBLE);
|
||||
holder.deviceStatusLabel.setText(device.getStateString());
|
||||
holder.busyIndicator.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
//begin of action row
|
||||
//battery
|
||||
LinearLayout batteryStatusBox = (LinearLayout) view.findViewById(R.id.device_battery_status_box);
|
||||
batteryStatusBox.setVisibility(View.GONE);
|
||||
|
||||
ImageView batteryIcon = (ImageView) view.findViewById(R.id.device_battery_status);
|
||||
|
||||
holder.batteryStatusBox.setVisibility(View.GONE);
|
||||
short batteryLevel = device.getBatteryLevel();
|
||||
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
||||
batteryStatusBox.setVisibility(View.VISIBLE);
|
||||
batteryStatusLabel.setText(device.getBatteryLevel() + "%");
|
||||
holder.batteryStatusBox.setVisibility(View.VISIBLE);
|
||||
holder.batteryStatusLabel.setText(device.getBatteryLevel() + "%");
|
||||
BatteryState batteryState = device.getBatteryState();
|
||||
if (BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
||||
BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
|
||||
batteryIcon.setImageLevel(device.getBatteryLevel() + 100);
|
||||
holder.batteryIcon.setImageLevel(device.getBatteryLevel() + 100);
|
||||
} else {
|
||||
batteryIcon.setImageLevel(device.getBatteryLevel());
|
||||
holder.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);
|
||||
holder.fetchActivityDataBox.setVisibility((device.isInitialized() && coordinator.supportsActivityDataFetching()) ? View.VISIBLE : View.GONE);
|
||||
holder.fetchActivityData.setOnClickListener(new View.OnClickListener()
|
||||
|
||||
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
|
||||
holder.takeScreenshotView.setVisibility((device.isInitialized() && coordinator.supportsScreenshots()) ? View.VISIBLE : View.GONE);
|
||||
holder.takeScreenshotView.setOnClickListener(new View.OnClickListener()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onScreenshotReq();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//set alarms
|
||||
holder.setAlarmsView.setVisibility(coordinator.supportsAlarmConfiguration() ? View.VISIBLE : View.GONE);
|
||||
holder.setAlarmsView.setOnClickListener(new View.OnClickListener()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(context, ConfigureAlarms.class);
|
||||
context.startActivity(startIntent);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//show graphs
|
||||
holder.showActivityGraphs.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
||||
holder.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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//Info icon is last in the row
|
||||
ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos());
|
||||
infoAdapter.setHorizontalAlignment(true);
|
||||
holder.deviceInfoList.setAdapter(infoAdapter);
|
||||
justifyListViewHeightBasedOnChildren(holder.deviceInfoList);
|
||||
holder.deviceInfoList.setFocusable(false);
|
||||
|
||||
final boolean detailsShown = position == expandedDevicePosition;
|
||||
boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
|
||||
holder.deviceInfoView.setVisibility(showInfoIcon ? View.VISIBLE : View.GONE);
|
||||
holder.deviceInfoBox.setActivated(detailsShown);
|
||||
holder.deviceInfoBox.setVisibility(detailsShown ? View.VISIBLE : View.GONE);
|
||||
holder.deviceInfoView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
expandedDevicePosition = detailsShown ? -1 : position;
|
||||
TransitionManager.beginDelayedTransition(parent);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
//find lost device, hidden under details
|
||||
holder.findDevice.setVisibility(device.isInitialized() ? View.VISIBLE : View.GONE);
|
||||
holder.findDevice.setOnClickListener(new View.OnClickListener()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onFetchActivityData();
|
||||
GBApplication.deviceService().onFindDevice(true);
|
||||
ProgressDialog.show(
|
||||
context,
|
||||
context.getString(R.string.control_center_find_lost_device),
|
||||
context.getString(R.string.control_center_cancel_to_stop_vibration),
|
||||
true, true,
|
||||
new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
GBApplication.deviceService().onFindDevice(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
//take screenshot
|
||||
ImageView takeScreenshotView = (ImageView) view.findViewById(R.id.device_action_take_screenshot);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
//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()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(context, ChartsActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
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);
|
||||
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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
|
||||
switch (device.getType())
|
||||
holder.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()) {
|
||||
case PEBBLE:
|
||||
if (device.isConnected()) {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_pebble);
|
||||
} else {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
|
||||
}
|
||||
break;
|
||||
case MIBAND:
|
||||
case MIBAND2:
|
||||
if (device.isConnected()) {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_miband);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_miband);
|
||||
} else {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_miband_disabled);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_miband_disabled);
|
||||
}
|
||||
break;
|
||||
case VIBRATISSIMO:
|
||||
if (device.isConnected()) {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_lovetoy);
|
||||
} else {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (device.isConnected()) {
|
||||
deviceImageView.setImageResource(R.drawable.ic_launcher);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_launcher);
|
||||
} else {
|
||||
deviceImageView.setImageResource(R.drawable.ic_device_default_disabled);
|
||||
holder.deviceImageView.setImageResource(R.drawable.ic_device_default_disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return deviceList.size();
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
ImageView deviceImageView;
|
||||
TextView deviceNameLabel;
|
||||
TextView deviceStatusLabel;
|
||||
|
||||
//actions
|
||||
LinearLayout batteryStatusBox;
|
||||
TextView batteryStatusLabel;
|
||||
ImageView batteryIcon;
|
||||
LinearLayout fetchActivityDataBox;
|
||||
ImageView fetchActivityData;
|
||||
ProgressBar busyIndicator;
|
||||
ImageView takeScreenshotView;
|
||||
ImageView setAlarmsView;
|
||||
ImageView showActivityGraphs;
|
||||
|
||||
ImageView deviceInfoView;
|
||||
//overflow
|
||||
final RelativeLayout deviceInfoBox;
|
||||
ListView deviceInfoList;
|
||||
ImageView findDevice;
|
||||
ImageView removeDevice;
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
||||
deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
|
||||
deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
|
||||
|
||||
//actions
|
||||
batteryStatusBox = (LinearLayout) view.findViewById(R.id.device_battery_status_box);
|
||||
batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
|
||||
batteryIcon = (ImageView) view.findViewById(R.id.device_battery_status);
|
||||
fetchActivityDataBox = (LinearLayout) view.findViewById(R.id.device_action_fetch_activity_box);
|
||||
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);
|
||||
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);
|
||||
|
||||
deviceInfoBox = (RelativeLayout) view.findViewById(R.id.device_item_infos_box);
|
||||
//overflow
|
||||
deviceInfoList = (ListView) view.findViewById(R.id.device_item_infos);
|
||||
findDevice = (ImageView) view.findViewById(R.id.device_action_find);
|
||||
removeDevice = (ImageView) view.findViewById(R.id.device_action_remove);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void justifyListViewHeightBasedOnChildren(ListView listView) {
|
||||
|
@ -272,8 +346,8 @@ public class GBDeviceAdapterv2 extends ArrayAdapter<GBDevice> {
|
|||
}
|
||||
|
||||
private boolean isUniqueDeviceName(GBDevice device, String deviceName) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
GBDevice item = getItem(i);
|
||||
for (int i = 0; i < deviceList.size(); i++) {
|
||||
GBDevice item = deviceList.get(i);
|
||||
if (item == device) {
|
||||
continue;
|
||||
}
|
||||
|
@ -283,5 +357,4 @@ public class GBDeviceAdapterv2 extends ArrayAdapter<GBDevice> {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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="M19,2L5,2c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h4l3,3 3,-3h4c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM13,18h-2v-2h2v2zM15.07,10.25l-0.9,0.92C13.45,11.9 13,12.5 13,14h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,8c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
|
||||
</vector>
|
|
@ -17,7 +17,7 @@
|
|||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/gadgetbridge_img" />
|
||||
|
||||
<ListView
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/deviceListView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -27,7 +26,9 @@
|
|||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:contentDescription="@string/candidate_item_device_image"
|
||||
android:clickable="true"
|
||||
android:longClickable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
tools:src="@drawable/ic_device_pebble" />
|
||||
|
||||
<TextView
|
||||
|
@ -100,6 +101,7 @@
|
|||
android:clickable="true"
|
||||
android:contentDescription="@string/controlcenter_fetch_activity_data"
|
||||
android:tint="?android:attr/textColor"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_action_fetch_activity_data" />
|
||||
|
||||
<ProgressBar
|
||||
|
@ -123,6 +125,7 @@
|
|||
android:clickable="true"
|
||||
android:contentDescription="@string/controlcenter_take_screenshot"
|
||||
android:tint="?android:attr/textColor"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_screenshot" />
|
||||
|
||||
<ImageView
|
||||
|
@ -135,6 +138,7 @@
|
|||
android:clickable="true"
|
||||
android:contentDescription="@string/controlcenter_start_configure_alarms"
|
||||
android:tint="?android:attr/textColor"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_device_set_alarms" />
|
||||
|
||||
<ImageView
|
||||
|
@ -146,7 +150,9 @@
|
|||
android:layout_toRightOf="@id/device_action_set_alarms"
|
||||
android:clickable="true"
|
||||
android:tint="?android:attr/textColor"
|
||||
card_view:srcCompat="@drawable/ic_activity_graphs" />
|
||||
card_view:srcCompat="@drawable/ic_activity_graphs"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/controlcenter_start_activitymonitor" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/device_info_image"
|
||||
|
@ -161,7 +167,8 @@
|
|||
android:clickable="true"
|
||||
android:contentDescription="@string/candidate_item_device_image"
|
||||
android:tint="?android:attr/textColor"
|
||||
android:src="@drawable/ic_more_vert" />
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_more_vert" />
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
|
@ -184,7 +191,7 @@
|
|||
android:scrollbars="none" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/device_action_remove"
|
||||
android:id="@+id/device_action_find"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_alignParentRight="true"
|
||||
|
@ -195,7 +202,25 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:clickable="true"
|
||||
android:tint="?android:attr/textColor"
|
||||
card_view:srcCompat="@drawable/ic_remove_device" />
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_action_find_lost_device"
|
||||
android:contentDescription="@string/controlcenter_find_device" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/device_action_remove"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/device_action_find"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:clickable="true"
|
||||
android:tint="?android:attr/textColor"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
card_view:srcCompat="@drawable/ic_remove_device"
|
||||
android:contentDescription="@string/controlcenter_delete_device" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -203,4 +228,4 @@
|
|||
</android.support.v7.widget.CardView>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
Loading…
Reference in New Issue