2015-02-07 12:58:18 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
2015-03-07 15:32:34 +01:00
|
|
|
import android.app.Activity;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
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;
|
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-02-08 23:53:40 +01:00
|
|
|
|
2015-03-07 15:32:34 +01:00
|
|
|
public class DebugActivity extends Activity {
|
2015-02-07 12:58:18 +01:00
|
|
|
Button sendSMSButton;
|
|
|
|
Button sendEmailButton;
|
|
|
|
Button incomingCallButton;
|
|
|
|
Button outgoingCallButton;
|
|
|
|
Button startCallButton;
|
|
|
|
Button endCallButton;
|
|
|
|
Button testNotificationButton;
|
2015-02-08 23:53:40 +01:00
|
|
|
Button setMusicInfoButton;
|
2015-02-07 12:58:18 +01:00
|
|
|
Button setTimeButton;
|
2015-05-17 21:58:08 +02:00
|
|
|
Button rebootButton;
|
2015-02-07 12:58:18 +01:00
|
|
|
EditText editContent;
|
|
|
|
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.getAction().equals(ControlCenter.ACTION_QUIT)) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_debug);
|
2015-03-27 11:23:30 +01:00
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
2015-02-07 12:58:18 +01:00
|
|
|
|
|
|
|
registerReceiver(mReceiver, new IntentFilter(ControlCenter.ACTION_QUIT));
|
|
|
|
|
|
|
|
editContent = (EditText) findViewById(R.id.editContent);
|
|
|
|
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
|
|
|
sendSMSButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
2015-05-13 23:18:54 +02:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_SMS);
|
|
|
|
startIntent.putExtra("notification_sender", getResources().getText(R.string.app_name));
|
2015-02-07 12:58:18 +01:00
|
|
|
startIntent.putExtra("notification_body", editContent.getText().toString());
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sendEmailButton = (Button) findViewById(R.id.sendEmailButton);
|
|
|
|
sendEmailButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL);
|
2015-05-13 23:18:54 +02:00
|
|
|
startIntent.putExtra("notification_sender", getResources().getText(R.string.app_name));
|
|
|
|
startIntent.putExtra("notification_subject", getResources().getText(R.string.test));
|
2015-02-07 12:58:18 +01:00
|
|
|
startIntent.putExtra("notification_body", editContent.getText().toString());
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
incomingCallButton = (Button) findViewById(R.id.incomingCallButton);
|
|
|
|
incomingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
|
|
|
|
startIntent.putExtra("call_phonenumber", editContent.getText().toString());
|
2015-02-12 16:00:45 +01:00
|
|
|
startIntent.putExtra("call_command", GBCommand.CALL_INCOMING.ordinal());
|
2015-02-07 12:58:18 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
outgoingCallButton = (Button) findViewById(R.id.outgoingCallButton);
|
|
|
|
outgoingCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
|
|
|
|
startIntent.putExtra("call_phonenumber", editContent.getText().toString());
|
2015-02-12 16:00:45 +01:00
|
|
|
startIntent.putExtra("call_command", GBCommand.CALL_OUTGOING.ordinal());
|
2015-02-07 12:58:18 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
startCallButton = (Button) findViewById(R.id.startCallButton);
|
|
|
|
startCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
|
2015-02-12 16:00:45 +01:00
|
|
|
startIntent.putExtra("call_command", GBCommand.CALL_START.ordinal());
|
2015-02-07 12:58:18 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
endCallButton = (Button) findViewById(R.id.endCallButton);
|
|
|
|
endCallButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CALLSTATE);
|
2015-02-12 16:00:45 +01:00
|
|
|
startIntent.putExtra("call_command", GBCommand.CALL_END.ordinal());
|
2015-02-07 12:58:18 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_REBOOT);
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_SETMUSICINFO);
|
|
|
|
startIntent.putExtra("music_artist", editContent.getText().toString() + "(artist)");
|
|
|
|
startIntent.putExtra("music_album", editContent.getText().toString() + "(album)");
|
|
|
|
startIntent.putExtra("music_track", editContent.getText().toString() + "(track)");
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
Intent startIntent = new Intent(DebugActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testNotificationButton = (Button) findViewById(R.id.testNotificationButton);
|
|
|
|
testNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNotification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void testNotification() {
|
|
|
|
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
|
2015-05-01 01:26:12 +02:00
|
|
|
ncomp.setContentTitle(getString(R.string.test_notification));
|
|
|
|
ncomp.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
|
|
|
ncomp.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
2015-04-03 22:39:25 +02:00
|
|
|
ncomp.setSmallIcon(R.drawable.ic_notification);
|
2015-02-07 12:58:18 +01:00
|
|
|
ncomp.setAutoCancel(true);
|
|
|
|
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();
|
|
|
|
unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|