2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-12-08 23:42:58 +01:00
|
|
|
import android.app.AlertDialog;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.app.NotificationManager;
|
2015-09-02 22:43:22 +02:00
|
|
|
import android.app.PendingIntent;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-12-08 23:42:58 +01:00
|
|
|
import android.content.DialogInterface;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2015-08-03 01:17:02 +02:00
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.os.Bundle;
|
2015-03-27 11:23:30 +01:00
|
|
|
import android.support.v4.app.NavUtils;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2016-01-09 15:33:18 +01:00
|
|
|
import android.support.v4.app.RemoteInput;
|
2016-04-24 17:34:36 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-03-27 11:23:30 +01:00
|
|
|
import android.view.MenuItem;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2015-07-08 23:03:34 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2016-05-16 17:30:11 +02:00
|
|
|
import net.e175.klaus.solarpositioning.DeltaT;
|
|
|
|
import net.e175.klaus.solarpositioning.SPA;
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.io.File;
|
2016-05-16 17:30:11 +02:00
|
|
|
import java.util.GregorianCalendar;
|
2015-07-08 23:03:34 +02:00
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-03 01:17:02 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
2015-07-08 23:03:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
2016-05-16 17:30:11 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
2016-04-04 20:08:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
2016-04-24 17:34:36 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
2016-04-04 20:08:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
2015-07-08 23:03:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2016-05-16 17:30:11 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-02-08 23:53:40 +01:00
|
|
|
|
2016-04-14 15:21:25 +02:00
|
|
|
public class DebugActivity extends GBActivity {
|
2015-07-08 23:03:34 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class);
|
|
|
|
|
2016-01-09 15:33:18 +01:00
|
|
|
private static final String EXTRA_REPLY = "reply";
|
|
|
|
private static final String ACTION_REPLY
|
|
|
|
= "nodomain.freeyourgadget.gadgetbridge.DebugActivity.action.reply";
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
private Button sendSMSButton;
|
|
|
|
private Button sendEmailButton;
|
|
|
|
private Button incomingCallButton;
|
|
|
|
private Button outgoingCallButton;
|
|
|
|
private Button startCallButton;
|
|
|
|
private Button endCallButton;
|
|
|
|
private Button testNotificationButton;
|
|
|
|
private Button setMusicInfoButton;
|
|
|
|
private Button setTimeButton;
|
|
|
|
private Button rebootButton;
|
2016-02-29 22:05:29 +01:00
|
|
|
private Button HeartRateButton;
|
2015-07-08 23:03:34 +02:00
|
|
|
private Button exportDBButton;
|
|
|
|
private Button importDBButton;
|
2015-12-08 23:42:58 +01:00
|
|
|
private Button deleteDBButton;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-12-08 23:42:58 +01:00
|
|
|
private EditText editContent;
|
2015-11-23 23:04:46 +01:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
2015-02-07 12:58:18 +01:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2016-01-09 15:33:18 +01:00
|
|
|
switch (intent.getAction()) {
|
2016-04-24 17:34:36 +02:00
|
|
|
case GBApplication.ACTION_QUIT: {
|
2016-01-09 15:33:18 +01:00
|
|
|
finish();
|
|
|
|
break;
|
2016-04-24 17:34:36 +02:00
|
|
|
}
|
|
|
|
case ACTION_REPLY: {
|
2016-01-09 15:33:18 +01:00
|
|
|
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
|
|
|
CharSequence reply = remoteInput.getCharSequence(EXTRA_REPLY);
|
|
|
|
LOG.info("got wearable reply: " + reply);
|
|
|
|
GB.toast(context, "got wearable reply: " + reply, Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
break;
|
2016-04-24 17:34:36 +02:00
|
|
|
}
|
|
|
|
case DeviceService.ACTION_HEARTRATE_MEASUREMENT: {
|
|
|
|
int hrValue = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, -1);
|
|
|
|
GB.toast(DebugActivity.this, "Heart Rate measured: " + hrValue, Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
break;
|
|
|
|
}
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_debug);
|
|
|
|
|
2016-01-09 15:33:18 +01:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(GBApplication.ACTION_QUIT);
|
|
|
|
filter.addAction(ACTION_REPLY);
|
2016-04-24 17:34:36 +02:00
|
|
|
filter.addAction(DeviceService.ACTION_HEARTRATE_MEASUREMENT);
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
|
|
|
registerReceiver(mReceiver, filter); // for ACTION_REPLY
|
2015-02-07 12:58:18 +01:00
|
|
|
|
|
|
|
editContent = (EditText) findViewById(R.id.editContent);
|
|
|
|
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
|
|
|
sendSMSButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-09-24 14:45:21 +02:00
|
|
|
NotificationSpec notificationSpec = new NotificationSpec();
|
2015-12-14 23:31:31 +01:00
|
|
|
notificationSpec.phoneNumber = editContent.getText().toString();
|
2015-09-24 14:45:21 +02:00
|
|
|
notificationSpec.body = editContent.getText().toString();
|
|
|
|
notificationSpec.type = NotificationType.SMS;
|
|
|
|
notificationSpec.id = -1;
|
|
|
|
GBApplication.deviceService().onNotification(notificationSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
sendEmailButton = (Button) findViewById(R.id.sendEmailButton);
|
|
|
|
sendEmailButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-09-24 14:45:21 +02:00
|
|
|
NotificationSpec notificationSpec = new NotificationSpec();
|
|
|
|
notificationSpec.sender = getResources().getText(R.string.app_name).toString();
|
|
|
|
notificationSpec.subject = editContent.getText().toString();
|
|
|
|
notificationSpec.body = editContent.getText().toString();
|
|
|
|
notificationSpec.type = NotificationType.EMAIL;
|
|
|
|
notificationSpec.id = -1;
|
|
|
|
GBApplication.deviceService().onNotification(notificationSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
incomingCallButton = (Button) findViewById(R.id.incomingCallButton);
|
|
|
|
incomingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
|
|
|
callSpec.command = CallSpec.CALL_INCOMING;
|
|
|
|
callSpec.number = editContent.getText().toString();
|
|
|
|
GBApplication.deviceService().onSetCallState(callSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
outgoingCallButton = (Button) findViewById(R.id.outgoingCallButton);
|
|
|
|
outgoingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
|
|
|
callSpec.command = CallSpec.CALL_OUTGOING;
|
|
|
|
callSpec.number = editContent.getText().toString();
|
|
|
|
GBApplication.deviceService().onSetCallState(callSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
startCallButton = (Button) findViewById(R.id.startCallButton);
|
|
|
|
startCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
|
|
|
callSpec.command = CallSpec.CALL_START;
|
|
|
|
GBApplication.deviceService().onSetCallState(callSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
endCallButton = (Button) findViewById(R.id.endCallButton);
|
|
|
|
endCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
CallSpec callSpec = new CallSpec();
|
|
|
|
callSpec.command = CallSpec.CALL_END;
|
|
|
|
GBApplication.deviceService().onSetCallState(callSpec);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
exportDBButton = (Button) findViewById(R.id.exportDBButton);
|
|
|
|
exportDBButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
exportDB();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
importDBButton = (Button) findViewById(R.id.importDBButton);
|
|
|
|
importDBButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
importDB();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-08 23:42:58 +01:00
|
|
|
deleteDBButton = (Button) findViewById(R.id.emptyDBButton);
|
|
|
|
deleteDBButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
deleteActivityDatabase();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-17 21:58:08 +02:00
|
|
|
rebootButton = (Button) findViewById(R.id.rebootButton);
|
|
|
|
rebootButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onReboot();
|
2015-05-17 21:58:08 +02:00
|
|
|
}
|
|
|
|
});
|
2016-02-29 22:05:29 +01:00
|
|
|
HeartRateButton = (Button) findViewById(R.id.HearRateButton);
|
|
|
|
HeartRateButton.setOnClickListener(new View.OnClickListener() {
|
2015-12-28 14:38:56 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-03-04 23:07:41 +01:00
|
|
|
GB.toast("Measuring heart rate, please wait...", Toast.LENGTH_LONG, GB.INFO);
|
2016-02-29 22:05:29 +01:00
|
|
|
GBApplication.deviceService().onHeartRateTest();
|
2015-12-28 14:38:56 +01:00
|
|
|
}
|
|
|
|
});
|
2015-05-17 21:58:08 +02:00
|
|
|
|
2015-02-08 23:53:40 +01:00
|
|
|
setMusicInfoButton = (Button) findViewById(R.id.setMusicInfoButton);
|
|
|
|
setMusicInfoButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
MusicSpec musicSpec = new MusicSpec();
|
|
|
|
musicSpec.artist = editContent.getText().toString() + "(artist)";
|
|
|
|
musicSpec.album = editContent.getText().toString() + "(album)";
|
|
|
|
musicSpec.track = editContent.getText().toString() + "(track)";
|
|
|
|
musicSpec.duration = 10;
|
|
|
|
musicSpec.trackCount = 5;
|
|
|
|
musicSpec.trackNr = 2;
|
|
|
|
|
|
|
|
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
2015-02-08 23:53:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
setTimeButton = (Button) findViewById(R.id.setTimeButton);
|
|
|
|
setTimeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetTime();
|
2016-05-16 17:30:11 +02:00
|
|
|
|
2016-05-16 23:37:40 +02:00
|
|
|
//FIXME: dont do it here, and make another button
|
|
|
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, 1);
|
2016-05-16 23:48:18 +02:00
|
|
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, 2);
|
|
|
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, 1);
|
2016-05-16 23:37:40 +02:00
|
|
|
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, 2);
|
2016-05-16 17:30:11 +02:00
|
|
|
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
|
|
|
|
float latitude = prefs.getFloat("location_latitude", 0);
|
|
|
|
float longitude = prefs.getFloat("location_longitude", 0);
|
2016-05-16 23:37:40 +02:00
|
|
|
final GregorianCalendar dateTimeToday = new GregorianCalendar();
|
|
|
|
final GregorianCalendar dateTimeTomorrow = new GregorianCalendar();
|
|
|
|
dateTimeTomorrow.add(GregorianCalendar.DAY_OF_MONTH, 1);
|
2016-05-16 17:30:11 +02:00
|
|
|
|
2016-05-16 23:37:40 +02:00
|
|
|
GregorianCalendar[] sunriseTransitSetToday = SPA.calculateSunriseTransitSet(dateTimeToday, latitude, longitude, DeltaT.estimate(dateTimeToday));
|
|
|
|
GregorianCalendar[] sunriseTransitSetTomorrow = SPA.calculateSunriseTransitSet(dateTimeTomorrow, latitude, longitude, DeltaT.estimate(dateTimeToday));
|
|
|
|
|
|
|
|
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
|
|
|
calendarEventSpec.durationInSeconds = 0;
|
|
|
|
calendarEventSpec.description = null;
|
|
|
|
|
|
|
|
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNRISE;
|
|
|
|
calendarEventSpec.title = "Sunrise";
|
|
|
|
if (sunriseTransitSetToday[0] != null) {
|
|
|
|
calendarEventSpec.id = 1;
|
|
|
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetToday[0].getTimeInMillis() / 1000);
|
|
|
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
|
|
|
}
|
|
|
|
if (sunriseTransitSetTomorrow[0] != null) {
|
|
|
|
calendarEventSpec.id = 2;
|
|
|
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[0].getTimeInMillis() / 1000);
|
|
|
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
calendarEventSpec.type = CalendarEventSpec.TYPE_SUNSET;
|
|
|
|
calendarEventSpec.title = "Sunset";
|
|
|
|
if (sunriseTransitSetToday[2] != null) {
|
|
|
|
calendarEventSpec.id = 1;
|
|
|
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetToday[2].getTimeInMillis() / 1000);
|
2016-05-16 17:30:11 +02:00
|
|
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
|
|
|
}
|
2016-05-16 23:37:40 +02:00
|
|
|
if (sunriseTransitSetTomorrow[2] != null) {
|
|
|
|
calendarEventSpec.id = 2;
|
|
|
|
calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[2].getTimeInMillis() / 1000);
|
2016-05-16 17:30:11 +02:00
|
|
|
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
|
|
|
}
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testNotificationButton = (Button) findViewById(R.id.testNotificationButton);
|
|
|
|
testNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNotification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
private void exportDB() {
|
2015-08-03 01:17:02 +02:00
|
|
|
DBHandler dbHandler = null;
|
2015-07-08 23:03:34 +02:00
|
|
|
try {
|
2015-08-03 01:17:02 +02:00
|
|
|
dbHandler = GBApplication.acquireDB();
|
2015-07-08 23:03:34 +02:00
|
|
|
DBHelper helper = new DBHelper(this);
|
|
|
|
File dir = FileUtils.getExternalFilesDir();
|
2015-08-03 01:17:02 +02:00
|
|
|
File destFile = helper.exportDB(dbHandler.getHelper(), dir);
|
|
|
|
GB.toast(this, "Exported to: " + destFile.getAbsolutePath(), Toast.LENGTH_LONG, GB.INFO);
|
2015-07-08 23:03:34 +02:00
|
|
|
} catch (Exception ex) {
|
2015-10-26 22:31:57 +01:00
|
|
|
GB.toast(this, "Error exporting DB: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
2015-08-03 01:17:02 +02:00
|
|
|
} finally {
|
|
|
|
if (dbHandler != null) {
|
|
|
|
dbHandler.release();
|
|
|
|
}
|
2015-07-08 23:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void importDB() {
|
2016-01-09 15:33:18 +01:00
|
|
|
new AlertDialog.Builder(this)
|
2016-01-06 00:24:39 +01:00
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle("Import Activity Data?")
|
|
|
|
.setMessage("Really overwrite the current activity database? All your activity data (if any) will be lost.")
|
|
|
|
.setPositiveButton("Overwrite", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
DBHandler dbHandler = null;
|
|
|
|
try {
|
|
|
|
dbHandler = GBApplication.acquireDB();
|
|
|
|
DBHelper helper = new DBHelper(DebugActivity.this);
|
|
|
|
File dir = FileUtils.getExternalFilesDir();
|
|
|
|
SQLiteOpenHelper sqLiteOpenHelper = dbHandler.getHelper();
|
|
|
|
File sourceFile = new File(dir, sqLiteOpenHelper.getDatabaseName());
|
|
|
|
helper.importDB(sqLiteOpenHelper, sourceFile);
|
|
|
|
helper.validateDB(sqLiteOpenHelper);
|
|
|
|
GB.toast(DebugActivity.this, "Import successful.", Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
GB.toast(DebugActivity.this, "Error importing DB: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
|
|
|
|
} finally {
|
|
|
|
if (dbHandler != null) {
|
|
|
|
dbHandler.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
2015-07-08 23:03:34 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 23:42:58 +01:00
|
|
|
private void deleteActivityDatabase() {
|
2016-01-09 15:33:18 +01:00
|
|
|
new AlertDialog.Builder(this)
|
2015-12-08 23:42:58 +01:00
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle("Delete Activity Data?")
|
|
|
|
.setMessage("Really delete the entire activity database? All your activity data will be lost.")
|
|
|
|
.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if (GBApplication.deleteActivityDatabase()) {
|
|
|
|
GB.toast(DebugActivity.this, "Activity database successfully deleted.", Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
} else {
|
|
|
|
GB.toast(DebugActivity.this, "Activity database deletion failed.", Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
private void testNotification() {
|
2015-09-02 22:43:22 +02:00
|
|
|
Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
2016-01-09 15:33:18 +01:00
|
|
|
|
|
|
|
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Intent replyIntent = new Intent(ACTION_REPLY);
|
|
|
|
|
|
|
|
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(this, 0, replyIntent, 0);
|
|
|
|
|
|
|
|
NotificationCompat.Action action =
|
|
|
|
new NotificationCompat.Action.Builder(android.R.drawable.ic_input_add, "Reply", replyPendingIntent)
|
|
|
|
.addRemoteInput(remoteInput)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(action);
|
|
|
|
|
|
|
|
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this)
|
|
|
|
.setContentTitle(getString(R.string.test_notification))
|
|
|
|
.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge))
|
|
|
|
.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge))
|
|
|
|
.setSmallIcon(R.drawable.ic_notification)
|
|
|
|
.setAutoCancel(true)
|
|
|
|
.setContentIntent(pendingIntent)
|
|
|
|
.extend(wearableExtender);
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
|
|
|
|
}
|
|
|
|
|
2015-03-27 11:23:30 +01:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
NavUtils.navigateUpFromSameTask(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
2016-04-24 17:34:36 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
2015-02-07 12:58:18 +01:00
|
|
|
unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|