Search in sources :

Example 6 with NotificationType

use of nodomain.freeyourgadget.gadgetbridge.model.NotificationType in project Gadgetbridge by Freeyourgadget.

the class DebugActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_debug);
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_REPLY);
    filter.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
    // for ACTION_REPLY
    registerReceiver(mReceiver, filter);
    editContent = findViewById(R.id.editContent);
    final ArrayList<String> spinnerArray = new ArrayList<>();
    for (NotificationType notificationType : NotificationType.values()) {
        spinnerArray.add(notificationType.name());
    }
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
    sendTypeSpinner = findViewById(R.id.sendTypeSpinner);
    sendTypeSpinner.setAdapter(spinnerArrayAdapter);
    Button sendButton = findViewById(R.id.sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NotificationSpec notificationSpec = new NotificationSpec();
            String testString = editContent.getText().toString();
            notificationSpec.phoneNumber = testString;
            notificationSpec.body = testString;
            notificationSpec.sender = testString;
            notificationSpec.subject = testString;
            notificationSpec.type = NotificationType.values()[sendTypeSpinner.getSelectedItemPosition()];
            notificationSpec.pebbleColor = notificationSpec.type.color;
            GBApplication.deviceService().onNotification(notificationSpec);
        }
    });
    Button incomingCallButton = findViewById(R.id.incomingCallButton);
    incomingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_INCOMING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button outgoingCallButton = findViewById(R.id.outgoingCallButton);
    outgoingCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_OUTGOING;
            callSpec.number = editContent.getText().toString();
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button startCallButton = findViewById(R.id.startCallButton);
    startCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_START;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button endCallButton = findViewById(R.id.endCallButton);
    endCallButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_END;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    });
    Button rebootButton = findViewById(R.id.rebootButton);
    rebootButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_REBOOT);
        }
    });
    Button factoryResetButton = findViewById(R.id.factoryResetButton);
    factoryResetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.debugactivity_really_factoryreset_title).setMessage(R.string.debugactivity_really_factoryreset).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_FACTORY_RESET);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    Button heartRateButton = findViewById(R.id.HeartRateButton);
    heartRateButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GB.toast("Measuring heart rate, please wait...", Toast.LENGTH_LONG, GB.INFO);
            GBApplication.deviceService().onHeartRateTest();
        }
    });
    Button setFetchTimeButton = findViewById(R.id.SetFetchTimeButton);
    setFetchTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar currentDate = Calendar.getInstance();
            Context context = getApplicationContext();
            if (context instanceof GBApplication) {
                GBApplication gbApp = (GBApplication) context;
                final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
                if (device != null) {
                    new DatePickerDialog(DebugActivity.this, new DatePickerDialog.OnDateSetListener() {

                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Calendar date = Calendar.getInstance();
                            date.set(year, monthOfYear, dayOfMonth);
                            long timestamp = date.getTimeInMillis() - 1000;
                            GB.toast("Setting lastSyncTimeMillis: " + timestamp, Toast.LENGTH_LONG, GB.INFO);
                            SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
                            // FIXME: key reconstruction is BAD
                            editor.remove("lastSyncTimeMillis");
                            editor.putLong("lastSyncTimeMillis", timestamp);
                            editor.apply();
                        }
                    }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
                } else {
                    GB.toast("Device not selected/connected", Toast.LENGTH_LONG, GB.INFO);
                }
            }
        }
    });
    Button setMusicInfoButton = findViewById(R.id.setMusicInfoButton);
    setMusicInfoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MusicSpec musicSpec = new MusicSpec();
            String testString = editContent.getText().toString();
            musicSpec.artist = testString + "(artist)";
            musicSpec.album = testString + "(album)";
            musicSpec.track = testString + "(track)";
            musicSpec.duration = 10;
            musicSpec.trackCount = 5;
            musicSpec.trackNr = 2;
            GBApplication.deviceService().onSetMusicInfo(musicSpec);
            MusicStateSpec stateSpec = new MusicStateSpec();
            stateSpec.position = 0;
            // playing
            stateSpec.state = 0x01;
            stateSpec.playRate = 100;
            stateSpec.repeat = 1;
            stateSpec.shuffle = 1;
            GBApplication.deviceService().onSetMusicState(stateSpec);
        }
    });
    Button setTimeButton = findViewById(R.id.setTimeButton);
    setTimeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onSetTime();
        }
    });
    Button testNotificationButton = findViewById(R.id.testNotificationButton);
    testNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNotification();
        }
    });
    Button testPebbleKitNotificationButton = findViewById(R.id.testPebbleKitNotificationButton);
    testPebbleKitNotificationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testPebbleKitNotification();
        }
    });
    Button fetchDebugLogsButton = findViewById(R.id.fetchDebugLogsButton);
    fetchDebugLogsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_DEBUGLOGS);
        }
    });
    Button testNewFunctionalityButton = findViewById(R.id.testNewFunctionality);
    testNewFunctionalityButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            testNewFunctionality();
        }
    });
    Button shareLogButton = findViewById(R.id.shareLog);
    shareLogButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showWarning();
        }
    });
    Button showWidgetsButton = findViewById(R.id.showWidgetsButton);
    showWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAllRegisteredAppWidgets();
        }
    });
    Button unregisterWidgetsButton = findViewById(R.id.deleteWidgets);
    unregisterWidgetsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            unregisterAllRegisteredAppWidgets();
        }
    });
    Button showWidgetsPrefsButton = findViewById(R.id.showWidgetsPrefs);
    showWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showAppWidgetsPrefs();
        }
    });
    Button deleteWidgetsPrefsButton = findViewById(R.id.deleteWidgetsPrefs);
    deleteWidgetsPrefsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            deleteWidgetsPrefs();
        }
    });
    Button removeDevicePreferencesButton = findViewById(R.id.removeDevicePreferences);
    removeDevicePreferencesButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Context context = getApplicationContext();
            GBApplication gbApp = (GBApplication) context;
            final GBDevice device = gbApp.getDeviceManager().getSelectedDevice();
            if (device != null) {
                GBApplication.deleteDeviceSpecificSharedPrefs(device.getAddress());
            }
        }
    });
    Button runDebugFunction = findViewById(R.id.runDebugFunction);
    runDebugFunction.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
        // editor.remove("notification_list_is_blacklist").apply();
        }
    });
    Button addDeviceButtonDebug = findViewById(R.id.addDeviceButtonDebug);
    addDeviceButtonDebug.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LinkedHashMap<String, Pair<Long, Integer>> allDevices;
            allDevices = getAllSupportedDevices(getApplicationContext());
            final LinearLayout linearLayout = new LinearLayout(DebugActivity.this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            final LinearLayout macLayout = new LinearLayout(DebugActivity.this);
            macLayout.setOrientation(LinearLayout.HORIZONTAL);
            macLayout.setPadding(20, 0, 20, 0);
            final TextView textView = new TextView(DebugActivity.this);
            textView.setText("MAC Address: ");
            final EditText editText = new EditText(DebugActivity.this);
            selectedTestDeviceMAC = randomMac();
            editText.setText(selectedTestDeviceMAC);
            editText.addTextChangedListener(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    selectedTestDeviceMAC = editable.toString();
                }
            });
            macLayout.addView(textView);
            macLayout.addView(editText);
            final Spinner deviceListSpinner = new Spinner(DebugActivity.this);
            ArrayList<SpinnerWithIconItem> deviceListArray = new ArrayList<>();
            for (Map.Entry<String, Pair<Long, Integer>> item : allDevices.entrySet()) {
                deviceListArray.add(new SpinnerWithIconItem(item.getKey(), item.getValue().first, item.getValue().second));
            }
            final SpinnerWithIconAdapter deviceListAdapter = new SpinnerWithIconAdapter(DebugActivity.this, R.layout.spinner_with_image_layout, R.id.spinner_item_text, deviceListArray);
            deviceListSpinner.setAdapter(deviceListAdapter);
            addListenerOnSpinnerDeviceSelection(deviceListSpinner);
            linearLayout.addView(deviceListSpinner);
            linearLayout.addView(macLayout);
            new AlertDialog.Builder(DebugActivity.this).setCancelable(true).setTitle(R.string.add_test_device).setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTestDevice(DebugActivity.this, selectedTestDeviceKey, selectedTestDeviceMAC);
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
        }
    });
    CheckBox activity_list_debug_extra_time_range = findViewById(R.id.activity_list_debug_extra_time_range);
    activity_list_debug_extra_time_range.setAllCaps(true);
    boolean activity_list_debug_extra_time_range_value = GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
    activity_list_debug_extra_time_range.setChecked(activity_list_debug_extra_time_range_value);
    activity_list_debug_extra_time_range.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            GBApplication.getPrefs().getPreferences().getBoolean("activity_list_debug_extra_time_range", false);
            SharedPreferences.Editor editor = GBApplication.getPrefs().getPreferences().edit();
            editor.putBoolean("activity_list_debug_extra_time_range", b).apply();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) SpinnerWithIconItem(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) LinkedHashMap(java.util.LinkedHashMap) MusicStateSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec) MusicSpec(nodomain.freeyourgadget.gadgetbridge.model.MusicSpec) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) Context(android.content.Context) EditText(android.widget.EditText) IntentFilter(android.content.IntentFilter) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) NotificationType(nodomain.freeyourgadget.gadgetbridge.model.NotificationType) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) DatePicker(android.widget.DatePicker) ArrayAdapter(android.widget.ArrayAdapter) LinearLayout(android.widget.LinearLayout) SpinnerWithIconAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter) CompoundButton(android.widget.CompoundButton)

Aggregations

NotificationType (nodomain.freeyourgadget.gadgetbridge.model.NotificationType)6 ArrayList (java.util.ArrayList)2 AppNotificationType (nodomain.freeyourgadget.gadgetbridge.model.AppNotificationType)2 CallSpec (nodomain.freeyourgadget.gadgetbridge.model.CallSpec)2 MusicSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicSpec)2 MusicStateSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec)2 NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Notification (android.app.Notification)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 PowerManager (android.os.PowerManager)1 RemoteException (android.os.RemoteException)1 Preference (android.preference.Preference)1