Start sleep activity with context menu (long press on a device)

This allows to see sleep data even if devices are not connected.
This commit is contained in:
Andreas Shimokawa 2015-06-01 16:57:45 +02:00
parent 81b1d1d28d
commit 6ea9537d38
5 changed files with 60 additions and 6 deletions

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
import nodomain.freeyourgadget.gadgetbridge.pebble.MorpheuzSupport;
public class AppManagerActivity extends Activity {
@ -73,10 +72,6 @@ public class AppManagerActivity extends Activity {
startAppIntent.setAction(BluetoothCommunicationService.ACTION_STARTAPP);
startAppIntent.putExtra("app_uuid", uuid.toString());
startService(startAppIntent);
if (MorpheuzSupport.uuid.equals(uuid)) {
Intent startIntent = new Intent(AppManagerActivity.this, SleepMonitorActivity.class);
startActivity(startIntent);
}
}
});

View File

@ -11,6 +11,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -39,6 +40,8 @@ public class ControlCenter extends Activity {
TextView hintTextView;
ListView deviceListView;
GBDeviceAdapter mGBDeviceAdapter;
private GBDevice selectedDevice = null;
final List<GBDevice> deviceList = new ArrayList<>();
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@ -96,6 +99,8 @@ public class ControlCenter extends Activity {
}
});
registerForContextMenu(deviceListView);
IntentFilter filterLocal = new IntentFilter();
filterLocal.addAction(ACTION_QUIT);
filterLocal.addAction(ACTION_REFRESH_DEVICELIST);
@ -140,6 +145,33 @@ public class ControlCenter extends Activity {
startService(versionInfoIntent);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(
R.menu.controlcenter_context, menu);
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
selectedDevice = deviceList.get(acmi.position);
menu.setHeaderTitle(selectedDevice.getName());
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.controlcenter_start_sleepmonitor:
if (selectedDevice != null) {
Intent startIntent = new Intent(ControlCenter.this, SleepMonitorActivity.class);
startIntent.putExtra("device", selectedDevice);
startActivity(startIntent);
}
return true;
default:
return super.onContextItemSelected(item);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.

View File

@ -38,6 +38,7 @@ public class SleepMonitorActivity extends Activity implements SurfaceHolder.Call
private int mSmartAlarmTo = -1;
private int mTimestampFrom = -1;
private int mSmartAlarmGoneOff = -1;
private GBDevice mGBDevice = null;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@ -56,12 +57,25 @@ public class SleepMonitorActivity extends Activity implements SurfaceHolder.Call
};
private void refresh() {
if (mGBDevice == null) {
return;
}
if (mTimestampFrom == -1) {
Long ts = System.currentTimeMillis();
mTimestampFrom = (int) ((ts / 1000) - (24 * 60 * 60) & 0xffffffff); // -24 hours
}
ArrayList<GBActivitySample> samples = GBApplication.getActivityDatabaseHandler().getGBActivitySamples(mTimestampFrom, -1, (byte) 1);
byte provider = -1;
switch (mGBDevice.getType()) {
case MIBAND:
provider = GBActivitySample.PROVIDER_MIBAND;
break;
case PEBBLE:
provider = GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ; // FIXME
break;
}
ArrayList<GBActivitySample> samples = GBApplication.getActivityDatabaseHandler().getGBActivitySamples(mTimestampFrom, -1, provider);
Calendar cal = Calendar.getInstance();
Date date;
String dateStringFrom = "";
@ -129,6 +143,12 @@ public class SleepMonitorActivity extends Activity implements SurfaceHolder.Call
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
mGBDevice = extras.getParcelable("device");
}
setContentView(R.layout.activity_sleepmonitor);
textView = (TextView) findViewById(R.id.textView);

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/controlcenter_start_sleepmonitor"
android:title="@string/controlcenter_start_sleepmonitor"/>
</menu>

View File

@ -6,6 +6,7 @@
<string name="action_settings">Settings</string>
<string name="action_debug">Debug</string>
<string name="action_quit">Quit</string>
<string name="controlcenter_start_sleepmonitor">Sleep Monitor (ALPHA)</string>
<string name="title_activity_debug">Debug</string>