2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2015-2024 Andreas Shimokawa, Arjan Schrijver, Carsten
|
|
|
|
Pfeiffer, Daniel Dakhno, Daniele Gobbetti, Dmitriy Bogdanov, Frank Slezak,
|
|
|
|
Ganblejs, ivanovlev, José Rebelo, Kamalei Zestri, Kasha, Lem Dulfo, Pavel
|
|
|
|
Elagin, Petr Vaněk, Steffen Liebergeld, Tim
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2021-06-27 13:12:40 +02:00
|
|
|
import static android.content.Intent.EXTRA_SUBJECT;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
|
|
|
|
2023-05-13 18:07:02 +02:00
|
|
|
import android.app.Activity;
|
2019-10-30 22:08:09 +01:00
|
|
|
import android.app.DatePickerDialog;
|
2015-09-02 22:43:22 +02:00
|
|
|
import android.app.PendingIntent;
|
2020-12-07 22:13:49 +01:00
|
|
|
import android.appwidget.AppWidgetHost;
|
|
|
|
import android.appwidget.AppWidgetManager;
|
2023-05-13 18:07:02 +02:00
|
|
|
import android.bluetooth.BluetoothDevice;
|
|
|
|
import android.companion.AssociationRequest;
|
|
|
|
import android.companion.BluetoothDeviceFilter;
|
2022-08-23 00:53:38 +02:00
|
|
|
import android.companion.CompanionDeviceManager;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
2023-08-25 23:32:17 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2020-12-07 22:13:49 +01:00
|
|
|
import android.content.ComponentName;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.Context;
|
2018-08-28 14:03:57 +02:00
|
|
|
import android.content.DialogInterface;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2023-05-13 18:07:02 +02:00
|
|
|
import android.content.IntentSender;
|
2019-10-30 22:08:09 +01:00
|
|
|
import android.content.SharedPreferences;
|
2018-08-28 14:03:57 +02:00
|
|
|
import android.net.Uri;
|
2022-08-23 00:53:38 +02:00
|
|
|
import android.os.Build;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.os.Bundle;
|
2022-02-20 15:43:52 +01:00
|
|
|
import android.os.Handler;
|
2022-07-30 21:40:31 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2021-06-27 13:12:40 +02:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.Pair;
|
2015-03-27 11:23:30 +01:00
|
|
|
import android.view.MenuItem;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.view.View;
|
2021-06-27 13:12:40 +02:00
|
|
|
import android.widget.AdapterView;
|
2016-10-03 20:51:28 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.widget.Button;
|
2021-03-03 19:03:02 +01:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2019-10-30 22:08:09 +01:00
|
|
|
import android.widget.DatePicker;
|
2015-02-07 12:58:18 +01:00
|
|
|
import android.widget.EditText;
|
2021-06-27 13:12:40 +02:00
|
|
|
import android.widget.LinearLayout;
|
2016-10-03 20:51:28 +02:00
|
|
|
import android.widget.Spinner;
|
2021-06-27 13:12:40 +02:00
|
|
|
import android.widget.TextView;
|
2015-07-08 23:03:34 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2023-11-28 19:12:12 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2023-05-13 18:07:02 +02:00
|
|
|
import androidx.annotation.RequiresApi;
|
2023-07-22 21:23:27 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2023-05-13 18:07:02 +02:00
|
|
|
import androidx.core.app.ActivityCompat;
|
2019-10-30 22:08:09 +01:00
|
|
|
import androidx.core.app.NavUtils;
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.RemoteInput;
|
2022-06-07 01:47:07 +02:00
|
|
|
import androidx.core.content.FileProvider;
|
2019-10-30 22:08:09 +01:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
2023-07-22 21:23:27 +02:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
|
|
2015-07-08 23:03:34 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-08-28 14:03:57 +02:00
|
|
|
import java.io.File;
|
2018-11-05 23:27:29 +01:00
|
|
|
import java.io.Serializable;
|
2023-08-25 23:32:17 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
2016-10-03 20:51:28 +02:00
|
|
|
import java.util.ArrayList;
|
2019-10-30 22:08:09 +01:00
|
|
|
import java.util.Calendar;
|
2022-08-23 00:53:38 +02:00
|
|
|
import java.util.Collections;
|
2023-08-25 23:32:17 +02:00
|
|
|
import java.util.Date;
|
2021-06-27 13:12:40 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2022-06-14 18:05:41 +02:00
|
|
|
import java.util.List;
|
2021-06-27 13:12:40 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2018-03-31 16:21:25 +02:00
|
|
|
import java.util.Objects;
|
2021-06-27 13:12:40 +02:00
|
|
|
import java.util.Random;
|
2021-12-23 22:41:50 +01:00
|
|
|
import java.util.TreeMap;
|
2016-10-03 20:51:28 +02:00
|
|
|
|
2022-08-18 23:03:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2020-12-07 22:13:49 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.Widget;
|
2021-06-27 13:12:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconAdapter;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.SpinnerWithIconItem;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
2022-06-04 22:20:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.gps.GBLocationManager;
|
2022-05-22 18:11:45 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksContentObserver;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksController;
|
2019-10-30 22:08:09 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2018-11-05 23:27:29 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
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;
|
2021-06-27 13:12:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2016-04-04 20:08:34 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
2016-06-08 20:32:32 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
2018-03-31 16:21:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
2022-08-18 23:03:28 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
2018-12-16 16:05:13 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2022-10-09 14:53:04 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.PendingIntentUtils;
|
2022-07-30 21:40:31 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2022-08-23 00:53:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
2020-12-07 22:13:49 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.WidgetPreferenceStorage;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2017-09-03 01:02:31 +02:00
|
|
|
public class DebugActivity extends AbstractGBActivity {
|
2015-07-08 23:03:34 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class);
|
|
|
|
|
2022-01-14 08:21:00 +01:00
|
|
|
private static Bundle dataLossSave;
|
|
|
|
|
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-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) {
|
2018-03-31 16:21:25 +02:00
|
|
|
switch (Objects.requireNonNull(intent.getAction())) {
|
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
|
|
|
}
|
2018-11-05 23:27:29 +01:00
|
|
|
case DeviceService.ACTION_REALTIME_SAMPLES:
|
|
|
|
handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
|
|
|
break;
|
2018-03-31 16:21:25 +02:00
|
|
|
default:
|
|
|
|
LOG.info("ignoring intent action " + intent.getAction());
|
2016-04-24 17:34:36 +02:00
|
|
|
break;
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-10-30 22:08:09 +01:00
|
|
|
private Spinner sendTypeSpinner;
|
|
|
|
private EditText editContent;
|
2023-10-22 01:33:08 +02:00
|
|
|
public static final long SELECT_DEVICE = -1;
|
2021-06-27 13:12:40 +02:00
|
|
|
private long selectedTestDeviceKey = SELECT_DEVICE;
|
|
|
|
private String selectedTestDeviceMAC;
|
|
|
|
|
2023-05-13 18:07:02 +02:00
|
|
|
private static final int SELECT_DEVICE_REQUEST_CODE = 1;
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2018-11-05 23:27:29 +01:00
|
|
|
private void handleRealtimeSample(Serializable extra) {
|
|
|
|
if (extra instanceof ActivitySample) {
|
|
|
|
ActivitySample sample = (ActivitySample) extra;
|
|
|
|
GB.toast(this, "Heart Rate measured: " + sample.getHeartRate(), Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(ACTION_REPLY);
|
2018-11-05 23:27:29 +01:00
|
|
|
filter.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
|
2016-04-24 17:34:36 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
|
|
|
registerReceiver(mReceiver, filter); // for ACTION_REPLY
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
editContent = findViewById(R.id.editContent);
|
2016-10-03 20:51:28 +02:00
|
|
|
|
2021-06-27 13:12:40 +02:00
|
|
|
final ArrayList<String> spinnerArray = new ArrayList<>();
|
2022-06-14 20:15:51 +02:00
|
|
|
for (NotificationType notificationType : NotificationType.sortedValues()) {
|
2016-10-03 20:51:28 +02:00
|
|
|
spinnerArray.add(notificationType.name());
|
|
|
|
}
|
|
|
|
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
|
2018-03-31 16:21:25 +02:00
|
|
|
sendTypeSpinner = findViewById(R.id.sendTypeSpinner);
|
2016-10-03 20:51:28 +02:00
|
|
|
sendTypeSpinner.setAdapter(spinnerArrayAdapter);
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button sendButton = findViewById(R.id.sendButton);
|
2016-10-03 20:51:28 +02:00
|
|
|
sendButton.setOnClickListener(new View.OnClickListener() {
|
2016-10-02 23:04:59 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
NotificationSpec notificationSpec = new NotificationSpec();
|
2016-10-03 20:51:28 +02:00
|
|
|
String testString = editContent.getText().toString();
|
|
|
|
notificationSpec.phoneNumber = testString;
|
|
|
|
notificationSpec.body = testString;
|
|
|
|
notificationSpec.sender = testString;
|
|
|
|
notificationSpec.subject = testString;
|
2022-10-31 13:01:19 +01:00
|
|
|
if (notificationSpec.type != NotificationType.GENERIC_SMS) {
|
|
|
|
// SMS notifications don't have a source app ID when sent by the SMSReceiver,
|
|
|
|
// so let's not set it here as well for consistency
|
|
|
|
notificationSpec.sourceAppId = BuildConfig.APPLICATION_ID;
|
|
|
|
}
|
2022-08-18 23:03:28 +02:00
|
|
|
notificationSpec.sourceName = getApplicationContext().getApplicationInfo()
|
|
|
|
.loadLabel(getApplicationContext().getPackageManager())
|
|
|
|
.toString();
|
2022-06-14 20:15:51 +02:00
|
|
|
notificationSpec.type = NotificationType.sortedValues()[sendTypeSpinner.getSelectedItemPosition()];
|
2017-09-19 13:24:31 +02:00
|
|
|
notificationSpec.pebbleColor = notificationSpec.type.color;
|
2022-08-18 23:03:28 +02:00
|
|
|
notificationSpec.attachedActions = new ArrayList<>();
|
|
|
|
|
|
|
|
if (notificationSpec.type == NotificationType.GENERIC_SMS) {
|
|
|
|
// REPLY action
|
|
|
|
NotificationSpec.Action replyAction = new NotificationSpec.Action();
|
|
|
|
replyAction.title = "Reply";
|
|
|
|
replyAction.type = NotificationSpec.Action.TYPE_SYNTECTIC_REPLY_PHONENR;
|
|
|
|
notificationSpec.attachedActions.add(replyAction);
|
|
|
|
}
|
|
|
|
|
2016-10-02 23:04:59 +02:00
|
|
|
GBApplication.deviceService().onNotification(notificationSpec);
|
|
|
|
}
|
|
|
|
});
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button incomingCallButton = findViewById(R.id.incomingCallButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2018-03-31 16:21:25 +02:00
|
|
|
Button outgoingCallButton = findViewById(R.id.outgoingCallButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button startCallButton = findViewById(R.id.startCallButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2018-03-31 16:21:25 +02:00
|
|
|
Button endCallButton = findViewById(R.id.endCallButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button rebootButton = findViewById(R.id.rebootButton);
|
2015-05-17 21:58:08 +02:00
|
|
|
rebootButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2018-12-16 16:05:13 +01:00
|
|
|
GBApplication.deviceService().onReset(GBDeviceProtocol.RESET_FLAGS_REBOOT);
|
2015-05-17 21:58:08 +02:00
|
|
|
}
|
|
|
|
});
|
2018-12-16 16:05:13 +01:00
|
|
|
|
|
|
|
Button factoryResetButton = findViewById(R.id.factoryResetButton);
|
|
|
|
factoryResetButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
2018-12-16 16:05:13 +01:00
|
|
|
.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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button heartRateButton = findViewById(R.id.HeartRateButton);
|
|
|
|
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
|
|
|
|
2019-10-30 22:08:09 +01:00
|
|
|
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;
|
2022-06-14 18:05:41 +02:00
|
|
|
final List<GBDevice> devices = gbApp.getDeviceManager().getSelectedDevices();
|
|
|
|
if(devices.size() == 0){
|
|
|
|
GB.toast("Device not selected/connected", Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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);
|
2019-10-30 22:08:09 +01:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
long timestamp = date.getTimeInMillis() - 1000;
|
|
|
|
GB.toast("Setting lastSyncTimeMillis: " + timestamp, Toast.LENGTH_LONG, GB.INFO);
|
2019-10-30 22:08:09 +01:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
for(GBDevice device : devices){
|
2019-10-30 22:08:09 +01:00
|
|
|
SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
|
|
|
|
editor.remove("lastSyncTimeMillis"); //FIXME: key reconstruction is BAD
|
|
|
|
editor.putLong("lastSyncTimeMillis", timestamp);
|
|
|
|
editor.apply();
|
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
}
|
|
|
|
}, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
|
2019-10-30 22:08:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-18 23:03:28 +02:00
|
|
|
Button setWeatherButton = findViewById(R.id.setWeatherButton);
|
|
|
|
setWeatherButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (Weather.getInstance().getWeatherSpec() == null) {
|
|
|
|
final WeatherSpec weatherSpec = new WeatherSpec();
|
|
|
|
weatherSpec.forecasts = new ArrayList<>();
|
|
|
|
|
|
|
|
weatherSpec.location = "Green Hill";
|
|
|
|
weatherSpec.currentConditionCode = 601; // snow
|
|
|
|
weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
|
|
|
|
|
|
|
|
weatherSpec.currentTemp = 15 + 273;
|
|
|
|
weatherSpec.currentHumidity = 30;
|
|
|
|
|
|
|
|
weatherSpec.windSpeed = 10;
|
|
|
|
weatherSpec.windDirection = 12;
|
|
|
|
weatherSpec.timestamp = (int) (System.currentTimeMillis() / 1000);
|
|
|
|
weatherSpec.todayMinTemp = 10 + 273;
|
|
|
|
weatherSpec.todayMaxTemp = 25 + 273;
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
2023-08-25 23:32:17 +02:00
|
|
|
final WeatherSpec.Daily gbForecast = new WeatherSpec.Daily();
|
2022-08-18 23:03:28 +02:00
|
|
|
gbForecast.minTemp = 10 + i + 273;
|
|
|
|
gbForecast.maxTemp = 25 + i + 273;
|
|
|
|
|
|
|
|
gbForecast.conditionCode = 800; // clear
|
|
|
|
weatherSpec.forecasts.add(gbForecast);
|
|
|
|
}
|
|
|
|
|
2024-03-29 22:10:40 +01:00
|
|
|
Weather.getInstance().setWeatherSpec(new ArrayList<>(Collections.singletonList(weatherSpec)));
|
2022-08-18 23:03:28 +02:00
|
|
|
}
|
2024-03-29 22:10:40 +01:00
|
|
|
GBApplication.deviceService().onSendWeather(new ArrayList<>(Collections.singletonList(Weather.getInstance().getWeatherSpec())));
|
2022-08-18 23:03:28 +02:00
|
|
|
}
|
|
|
|
});
|
2019-10-30 22:08:09 +01:00
|
|
|
|
2023-03-16 21:46:56 +01:00
|
|
|
Button showCachedWeatherButton = findViewById(R.id.showCachedWeatherButton);
|
|
|
|
showCachedWeatherButton.setOnClickListener(new View.OnClickListener(){
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2024-03-29 22:10:40 +01:00
|
|
|
final List<WeatherSpec> weatherSpecs = Weather.getInstance().getWeatherSpecs();
|
|
|
|
|
|
|
|
if (weatherSpecs == null || weatherSpecs.isEmpty()) {
|
|
|
|
displayWeatherInfo(null);
|
|
|
|
return;
|
|
|
|
} else if (weatherSpecs.size() == 1) {
|
|
|
|
displayWeatherInfo(weatherSpecs.get(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String[] weatherLocations = new String[weatherSpecs.size()];
|
|
|
|
|
|
|
|
for (int i = 0; i < weatherSpecs.size(); i++) {
|
|
|
|
weatherLocations[i] = weatherSpecs.get(i).location;
|
|
|
|
}
|
2023-03-16 21:46:56 +01:00
|
|
|
|
2023-08-20 22:17:34 +02:00
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
2023-08-20 11:01:15 +02:00
|
|
|
.setCancelable(true)
|
2024-03-29 22:10:40 +01:00
|
|
|
.setTitle("Choose Location")
|
|
|
|
.setItems(weatherLocations, (dialog, which) -> displayWeatherInfo(weatherSpecs.get(which)))
|
|
|
|
.setNegativeButton("Cancel", (dialog, which) -> {
|
2023-08-25 23:32:17 +02:00
|
|
|
})
|
2023-03-16 21:46:56 +01:00
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button setMusicInfoButton = findViewById(R.id.setMusicInfoButton);
|
2015-02-08 23:53:40 +01:00
|
|
|
setMusicInfoButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-04-04 20:08:34 +02:00
|
|
|
MusicSpec musicSpec = new MusicSpec();
|
2017-01-24 19:04:06 +01:00
|
|
|
String testString = editContent.getText().toString();
|
|
|
|
musicSpec.artist = testString + "(artist)";
|
|
|
|
musicSpec.album = testString + "(album)";
|
|
|
|
musicSpec.track = testString + "(track)";
|
2016-04-04 20:08:34 +02:00
|
|
|
musicSpec.duration = 10;
|
|
|
|
musicSpec.trackCount = 5;
|
|
|
|
musicSpec.trackNr = 2;
|
|
|
|
|
|
|
|
GBApplication.deviceService().onSetMusicInfo(musicSpec);
|
2016-06-08 20:32:32 +02:00
|
|
|
|
|
|
|
MusicStateSpec stateSpec = new MusicStateSpec();
|
|
|
|
stateSpec.position = 0;
|
|
|
|
stateSpec.state = 0x01; // playing
|
|
|
|
stateSpec.playRate = 100;
|
|
|
|
stateSpec.repeat = 1;
|
|
|
|
stateSpec.shuffle = 1;
|
|
|
|
|
|
|
|
GBApplication.deviceService().onSetMusicState(stateSpec);
|
2015-02-08 23:53:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button setTimeButton = findViewById(R.id.setTimeButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
setTimeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSetTime();
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
Button testNotificationButton = findViewById(R.id.testNotificationButton);
|
2015-02-07 12:58:18 +01:00
|
|
|
testNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNotification();
|
|
|
|
}
|
|
|
|
});
|
2016-10-11 23:27:56 +02:00
|
|
|
|
2018-11-01 15:04:16 +01:00
|
|
|
Button testPebbleKitNotificationButton = findViewById(R.id.testPebbleKitNotificationButton);
|
|
|
|
testPebbleKitNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testPebbleKitNotification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-31 16:21:25 +02:00
|
|
|
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);
|
2016-10-11 23:27:56 +02:00
|
|
|
testNewFunctionalityButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNewFunctionality();
|
|
|
|
}
|
|
|
|
});
|
2018-08-28 14:03:57 +02:00
|
|
|
|
|
|
|
Button shareLogButton = findViewById(R.id.shareLog);
|
|
|
|
shareLogButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-07-30 21:40:31 +02:00
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(DebugActivity.this);
|
|
|
|
Prefs prefs = new Prefs(sharedPrefs);
|
|
|
|
boolean logging_enabled = prefs.getBoolean("log_to_file", false);
|
|
|
|
if (logging_enabled) {
|
|
|
|
showLogSharingWarning();
|
|
|
|
} else {
|
|
|
|
showLogSharingNotEnabledAlert();
|
|
|
|
}
|
2018-08-28 14:03:57 +02:00
|
|
|
}
|
|
|
|
});
|
2020-12-07 22:13:49 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-18 22:27:15 +02:00
|
|
|
Button removeDevicePreferencesButton = findViewById(R.id.removeDevicePreferences);
|
|
|
|
removeDevicePreferencesButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
2022-10-30 10:37:42 +01:00
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle(R.string.debugactivity_confirm_remove_device_preferences_title)
|
|
|
|
.setMessage(R.string.debugactivity_confirm_remove_device_preferences)
|
|
|
|
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
|
|
|
final GBApplication gbApp = (GBApplication) getApplicationContext();
|
|
|
|
final List<GBDevice> devices = gbApp.getDeviceManager().getSelectedDevices();
|
|
|
|
for(final GBDevice device : devices){
|
|
|
|
GBApplication.deleteDeviceSpecificSharedPrefs(device.getAddress());
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, (dialog, which) -> {})
|
|
|
|
.show();
|
2021-09-18 22:27:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-26 21:59:11 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-27 13:12:40 +02:00
|
|
|
Button addDeviceButtonDebug = findViewById(R.id.addDeviceButtonDebug);
|
|
|
|
addDeviceButtonDebug.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2023-08-30 16:28:43 +02:00
|
|
|
Map<String, Pair<Long, Integer>> allDevices = getAllSupportedDevices(getApplicationContext());
|
2021-06-27 13:12:40 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
2021-06-27 13:12:40 +02:00
|
|
|
.setCancelable(true)
|
2021-12-23 22:41:50 +01:00
|
|
|
.setTitle(R.string.add_test_device)
|
2021-06-27 13:12:40 +02:00
|
|
|
.setView(linearLayout)
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2021-12-23 22:41:50 +01:00
|
|
|
createTestDevice(DebugActivity.this, selectedTestDeviceKey, selectedTestDeviceMAC);
|
2021-06-27 13:12:40 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-03 19:03:02 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-20 15:43:52 +01:00
|
|
|
Button startFitnessAppTracking = findViewById(R.id.startFitnessAppTracking);
|
|
|
|
startFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
OpenTracksController.startRecording(DebugActivity.this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Button stopFitnessAppTracking = findViewById(R.id.stopFitnessAppTracking);
|
|
|
|
stopFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
OpenTracksController.stopRecording(DebugActivity.this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-04 22:20:28 +02:00
|
|
|
Button stopPhoneGpsLocationListener = findViewById(R.id.stopPhoneGpsLocationListener);
|
|
|
|
stopPhoneGpsLocationListener.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
GBLocationManager.stopAll(getBaseContext());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-23 00:53:38 +02:00
|
|
|
Button showCompanionDevices = findViewById(R.id.showCompanionDevices);
|
|
|
|
showCompanionDevices.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
|
|
|
|
showCompanionDevices.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
LOG.warn("Android version < O, companion devices not supported");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final CompanionDeviceManager manager = (CompanionDeviceManager) GBApplication.getContext().getSystemService(Context.COMPANION_DEVICE_SERVICE);
|
|
|
|
final List<String> associations = new ArrayList<>(manager.getAssociations());
|
|
|
|
Collections.sort(associations);
|
|
|
|
String companionDevicesList = String.format(Locale.ROOT, "%d companion devices", associations.size());
|
|
|
|
if (!associations.isEmpty()) {
|
|
|
|
companionDevicesList += "\n\n" + StringUtils.join("\n", associations.toArray(new String[0]));
|
|
|
|
}
|
|
|
|
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
2022-08-23 00:53:38 +02:00
|
|
|
.setCancelable(false)
|
|
|
|
.setTitle("Companion Devices")
|
|
|
|
.setMessage(companionDevicesList)
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-13 18:07:02 +02:00
|
|
|
final Button pairAsCompanion = findViewById(R.id.pairAsCompanion);
|
|
|
|
pairAsCompanion.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
|
|
|
|
pairAsCompanion.setOnClickListener(v -> {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
pairCurrentAsCompanion();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-20 15:43:52 +01:00
|
|
|
Button showStatusFitnessAppTracking = findViewById(R.id.showStatusFitnessAppTracking);
|
|
|
|
final int delay = 2 * 1000;
|
|
|
|
|
|
|
|
showStatusFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
|
|
|
|
final Handler handler = new Handler();
|
|
|
|
Runnable runnable;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2023-07-22 21:23:27 +02:00
|
|
|
final MaterialAlertDialogBuilder fitnesStatusBuilder = new MaterialAlertDialogBuilder(DebugActivity.this);
|
2022-02-20 15:43:52 +01:00
|
|
|
fitnesStatusBuilder
|
|
|
|
.setCancelable(false)
|
|
|
|
.setTitle("openTracksObserver Status")
|
|
|
|
.setMessage("Starting openTracksObserver watcher, waiting for an update, refreshing every: " + delay + "ms")
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
handler.removeCallbacks(runnable);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
final AlertDialog alert = fitnesStatusBuilder.show();
|
|
|
|
|
|
|
|
|
|
|
|
runnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
LOG.debug("openTracksObserver debug watch dialog running");
|
|
|
|
handler.postDelayed(this, delay); //schedule next execution
|
|
|
|
|
|
|
|
OpenTracksContentObserver openTracksObserver = GBApplication.app().getOpenTracksObserver();
|
|
|
|
if (openTracksObserver == null) {
|
|
|
|
LOG.debug("openTracksObserver is null");
|
|
|
|
alert.cancel();
|
|
|
|
alert.setMessage("openTracksObserver not running");
|
|
|
|
alert.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG.debug("openTracksObserver is not null, updating debug view");
|
|
|
|
long timeSecs = openTracksObserver.getTimeMillisChange() / 1000;
|
|
|
|
float distanceCM = openTracksObserver.getDistanceMeterChange() * 100;
|
|
|
|
|
|
|
|
LOG.debug("Time: " + timeSecs + " distanceCM " + distanceCM);
|
|
|
|
alert.cancel();
|
|
|
|
alert.setMessage("TimeSec: " + timeSecs + " distanceCM " + distanceCM);
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
handler.postDelayed(runnable, delay);
|
|
|
|
}
|
|
|
|
});
|
2020-12-07 22:13:49 +01:00
|
|
|
}
|
|
|
|
|
2023-05-13 18:07:02 +02:00
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
|
|
|
requestCode == SELECT_DEVICE_REQUEST_CODE &&
|
|
|
|
resultCode == Activity.RESULT_OK) {
|
|
|
|
|
|
|
|
final BluetoothDevice deviceToPair = data.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE);
|
|
|
|
|
|
|
|
if (deviceToPair != null) {
|
|
|
|
if (deviceToPair.getBondState() != BluetoothDevice.BOND_BONDED) {
|
|
|
|
GB.toast("Creating bond...", Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
deviceToPair.createBond();
|
|
|
|
} else {
|
|
|
|
GB.toast("Bonding complete", Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GB.toast("No device to pair", Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.O)
|
|
|
|
private void pairCurrentAsCompanion() {
|
|
|
|
final GBApplication gbApp = (GBApplication) getApplicationContext();
|
|
|
|
final List<GBDevice> devices = gbApp.getDeviceManager().getSelectedDevices();
|
|
|
|
if (devices.size() != 1) {
|
|
|
|
GB.toast("Please connect to a single device that you want to pair as companion", Toast.LENGTH_LONG, GB.WARN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final GBDevice device = devices.get(0);
|
|
|
|
|
2023-11-28 19:12:12 +01:00
|
|
|
final CompanionDeviceManager manager = (CompanionDeviceManager) getSystemService(Context.COMPANION_DEVICE_SERVICE);
|
2023-05-13 18:07:02 +02:00
|
|
|
|
|
|
|
if (manager.getAssociations().contains(device.getAddress())) {
|
|
|
|
GB.toast(device.getAliasOrName() + " already paired as companion", Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final BluetoothDeviceFilter deviceFilter = new BluetoothDeviceFilter.Builder()
|
|
|
|
.setAddress(device.getAddress())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
final AssociationRequest pairingRequest = new AssociationRequest.Builder()
|
|
|
|
.addDeviceFilter(deviceFilter)
|
|
|
|
.setSingleDevice(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
CompanionDeviceManager.Callback callback = new CompanionDeviceManager.Callback() {
|
|
|
|
@Override
|
|
|
|
public void onFailure(final CharSequence error) {
|
|
|
|
GB.toast("Companion pairing failed: " + error, Toast.LENGTH_LONG, GB.ERROR);
|
|
|
|
}
|
2022-01-14 08:21:00 +01:00
|
|
|
|
2023-05-13 18:07:02 +02:00
|
|
|
@Override
|
2023-11-28 19:12:12 +01:00
|
|
|
public void onDeviceFound(@NonNull final IntentSender chooserLauncher) {
|
2023-05-13 18:07:02 +02:00
|
|
|
GB.toast("Found device", Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
|
|
|
|
try {
|
|
|
|
ActivityCompat.startIntentSenderForResult(
|
|
|
|
DebugActivity.this,
|
|
|
|
chooserLauncher,
|
|
|
|
SELECT_DEVICE_REQUEST_CODE,
|
|
|
|
null,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
} catch (final IntentSender.SendIntentException e) {
|
|
|
|
LOG.error("Failed to send intent", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
manager.associate(pairingRequest, callback, null);
|
|
|
|
}
|
2022-01-14 08:21:00 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
if (dataLossSave != null ) {
|
|
|
|
dataLossSave.clear();
|
|
|
|
dataLossSave = null ;
|
|
|
|
}
|
|
|
|
dataLossSave = new Bundle();
|
|
|
|
dataLossSave.putString("editContent", editContent.getText().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (dataLossSave != null ) {
|
|
|
|
editContent.setText(dataLossSave.getString("editContent", ""));
|
|
|
|
}else{
|
|
|
|
editContent.setText("Test");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:13:49 +01:00
|
|
|
private void deleteWidgetsPrefs() {
|
|
|
|
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
|
|
|
widgetPreferenceStorage.deleteWidgetsPrefs(DebugActivity.this);
|
|
|
|
widgetPreferenceStorage.showAppWidgetsPrefs(DebugActivity.this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAppWidgetsPrefs() {
|
|
|
|
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
|
|
|
widgetPreferenceStorage.showAppWidgetsPrefs(DebugActivity.this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAllRegisteredAppWidgets() {
|
|
|
|
//https://stackoverflow.com/questions/17387191/check-if-a-widget-is-exists-on-homescreen-using-appwidgetid
|
|
|
|
|
|
|
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(DebugActivity.this);
|
|
|
|
AppWidgetHost appWidgetHost = new AppWidgetHost(DebugActivity.this, 1); // for removing phantoms
|
|
|
|
int[] appWidgetIDs = appWidgetManager.getAppWidgetIds(new ComponentName(DebugActivity.this, Widget.class));
|
|
|
|
GB.toast("Number of registered app widgets: " + appWidgetIDs.length, Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
for (int appWidgetID : appWidgetIDs) {
|
|
|
|
GB.toast("Widget: " + appWidgetID, Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unregisterAllRegisteredAppWidgets() {
|
|
|
|
//https://stackoverflow.com/questions/17387191/check-if-a-widget-is-exists-on-homescreen-using-appwidgetid
|
|
|
|
|
|
|
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(DebugActivity.this);
|
|
|
|
AppWidgetHost appWidgetHost = new AppWidgetHost(DebugActivity.this, 1); // for removing phantoms
|
|
|
|
int[] appWidgetIDs = appWidgetManager.getAppWidgetIds(new ComponentName(DebugActivity.this, Widget.class));
|
|
|
|
GB.toast("Number of registered app widgets: " + appWidgetIDs.length, Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
for (int appWidgetID : appWidgetIDs) {
|
|
|
|
appWidgetHost.deleteAppWidgetId(appWidgetID);
|
|
|
|
GB.toast("Removing widget: " + appWidgetID, Toast.LENGTH_SHORT, GB.INFO);
|
|
|
|
}
|
2018-08-28 14:03:57 +02:00
|
|
|
}
|
|
|
|
|
2022-07-30 21:40:31 +02:00
|
|
|
private void showLogSharingNotEnabledAlert() {
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(this)
|
2022-07-30 21:40:31 +02:00
|
|
|
.setTitle(R.string.note)
|
|
|
|
.setPositiveButton(R.string.ok, null)
|
|
|
|
.setMessage(R.string.share_log_not_enabled_message)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showLogSharingWarning() {
|
2023-07-22 21:23:27 +02:00
|
|
|
new MaterialAlertDialogBuilder(this)
|
2018-08-28 14:03:57 +02:00
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle(R.string.warning)
|
|
|
|
.setMessage(R.string.share_log_warning)
|
|
|
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2018-12-16 16:05:13 +01:00
|
|
|
shareLog();
|
2018-08-28 14:03:57 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
2016-10-11 23:27:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void testNewFunctionality() {
|
|
|
|
GBApplication.deviceService().onTestNewFunction();
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
|
2018-08-28 14:03:57 +02:00
|
|
|
private void shareLog() {
|
|
|
|
String fileName = GBApplication.getLogPath();
|
2019-10-30 22:08:09 +01:00
|
|
|
if (fileName != null && fileName.length() > 0) {
|
2019-02-28 22:04:05 +01:00
|
|
|
File logFile = new File(fileName);
|
|
|
|
if (!logFile.exists()) {
|
|
|
|
GB.toast("File does not exist", Toast.LENGTH_LONG, GB.INFO);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-07 01:47:07 +02:00
|
|
|
final Uri providerUri = FileProvider.getUriForFile(
|
|
|
|
this,
|
|
|
|
getApplicationContext().getPackageName() + ".screenshot_provider",
|
|
|
|
logFile
|
|
|
|
);
|
|
|
|
|
2018-08-28 14:03:57 +02:00
|
|
|
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
|
2022-06-07 01:47:07 +02:00
|
|
|
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
2018-08-28 14:03:57 +02:00
|
|
|
emailIntent.setType("*/*");
|
|
|
|
emailIntent.putExtra(EXTRA_SUBJECT, "Gadgetbridge log file");
|
2022-06-07 01:47:07 +02:00
|
|
|
emailIntent.putExtra(Intent.EXTRA_STREAM, providerUri);
|
2018-08-28 14:03:57 +02:00
|
|
|
startActivity(Intent.createChooser(emailIntent, "Share File"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2022-10-09 14:53:04 +02:00
|
|
|
PendingIntent pendingIntent = PendingIntentUtils.getActivity(getApplicationContext(), 0,
|
|
|
|
notificationIntent, 0, false);
|
2015-09-02 22:43:22 +02:00
|
|
|
|
2016-01-09 15:33:18 +01:00
|
|
|
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Intent replyIntent = new Intent(ACTION_REPLY);
|
|
|
|
|
2022-10-09 14:53:04 +02:00
|
|
|
PendingIntent replyPendingIntent = PendingIntentUtils.getBroadcast(this, 0, replyIntent, 0, true);
|
2016-01-09 15:33:18 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-02-14 21:27:24 +01:00
|
|
|
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
2016-01-09 15:33:18 +01:00
|
|
|
.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);
|
|
|
|
|
2021-05-14 18:30:54 +02:00
|
|
|
GB.notify((int) System.currentTimeMillis(), ncomp.build(), this);
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|
|
|
|
|
2018-11-01 15:04:16 +01:00
|
|
|
private void testPebbleKitNotification() {
|
|
|
|
Intent pebbleKitIntent = new Intent("com.getpebble.action.SEND_NOTIFICATION");
|
|
|
|
pebbleKitIntent.putExtra("messageType", "PEBBLE_ALERT");
|
|
|
|
pebbleKitIntent.putExtra("notificationData", "[{\"title\":\"PebbleKitTest\",\"body\":\"sent from Gadgetbridge\"}]");
|
|
|
|
getApplicationContext().sendBroadcast(pebbleKitIntent);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-06-27 13:12:40 +02:00
|
|
|
private void addListenerOnSpinnerDeviceSelection(Spinner spinner) {
|
|
|
|
spinner.setOnItemSelectedListener(new CustomOnDeviceSelectedListener());
|
|
|
|
}
|
|
|
|
|
2023-08-30 16:28:43 +02:00
|
|
|
public static void createTestDevice(Context context, long deviceKey, String deviceMac) {
|
2021-12-23 22:41:50 +01:00
|
|
|
if (deviceKey == SELECT_DEVICE) {
|
2021-06-27 13:12:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-10-22 01:33:08 +02:00
|
|
|
DeviceType deviceType = DeviceType.values()[(int) deviceKey];
|
2024-03-28 22:07:05 +01:00
|
|
|
String deviceName = deviceType.name();
|
|
|
|
int deviceNameResource = deviceType.getDeviceCoordinator().getDeviceNameResource();
|
|
|
|
if(deviceNameResource != 0){
|
|
|
|
deviceName = context.getString(deviceNameResource);
|
|
|
|
}
|
2021-06-27 13:12:40 +02:00
|
|
|
try (
|
2021-12-23 22:41:50 +01:00
|
|
|
DBHandler db = GBApplication.acquireDB()) {
|
2021-06-27 13:12:40 +02:00
|
|
|
DaoSession daoSession = db.getDaoSession();
|
2024-03-28 22:07:05 +01:00
|
|
|
GBDevice gbDevice = new GBDevice(deviceMac, deviceName, "", null, deviceType);
|
2021-12-23 22:41:50 +01:00
|
|
|
gbDevice.setFirmwareVersion("N/A");
|
|
|
|
gbDevice.setFirmwareVersion2("N/A");
|
2021-06-27 13:12:40 +02:00
|
|
|
|
|
|
|
//this causes the attributes (fw version) to be stored as well. Not much useful, but still...
|
|
|
|
gbDevice.setState(GBDevice.State.INITIALIZED);
|
|
|
|
|
2021-12-23 22:41:50 +01:00
|
|
|
Device device = DBHelper.getDevice(gbDevice, daoSession); //the addition happens here
|
2021-06-27 13:12:40 +02:00
|
|
|
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
|
2021-12-23 22:41:50 +01:00
|
|
|
LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
|
2024-03-28 22:07:05 +01:00
|
|
|
GB.toast(context, "Added test device: " + deviceName, Toast.LENGTH_SHORT, GB.INFO);
|
2021-06-27 13:12:40 +02:00
|
|
|
|
|
|
|
} catch (
|
|
|
|
Exception e) {
|
|
|
|
GB.log("Error accessing database", GB.ERROR, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String randomMac() {
|
|
|
|
Random random = new Random();
|
|
|
|
String separator = ":";
|
|
|
|
String[] mac = {
|
|
|
|
String.format("%02x", random.nextInt(0xff)),
|
|
|
|
String.format("%02x", random.nextInt(0xff)),
|
|
|
|
String.format("%02x", random.nextInt(0xff)),
|
|
|
|
String.format("%02x", random.nextInt(0xff)),
|
|
|
|
String.format("%02x", random.nextInt(0xff)),
|
|
|
|
String.format("%02x", random.nextInt(0xff))
|
|
|
|
};
|
|
|
|
return TextUtils.join(separator, mac).toUpperCase(Locale.ROOT);
|
|
|
|
}
|
|
|
|
|
2024-03-29 22:10:40 +01:00
|
|
|
private void displayWeatherInfo(final WeatherSpec weatherSpec) {
|
|
|
|
final String weatherInfo = getWeatherInfo(weatherSpec);
|
|
|
|
|
|
|
|
new MaterialAlertDialogBuilder(DebugActivity.this)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setTitle("Cached Weather Data")
|
|
|
|
.setMessage(weatherInfo)
|
|
|
|
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
|
|
|
})
|
|
|
|
.setNeutralButton(android.R.string.copy, (dialog, which) -> {
|
|
|
|
final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText("Weather Info", weatherInfo);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getWeatherInfo(final WeatherSpec weatherSpec) {
|
2023-08-25 23:32:17 +02:00
|
|
|
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ROOT);
|
|
|
|
|
|
|
|
final StringBuilder builder = new StringBuilder();
|
2023-03-16 21:46:56 +01:00
|
|
|
|
|
|
|
if (weatherSpec == null)
|
2024-03-29 22:10:40 +01:00
|
|
|
return "Weather cache is empty.";
|
2023-03-16 21:46:56 +01:00
|
|
|
|
2023-08-25 23:32:17 +02:00
|
|
|
builder.append("Location: ").append(weatherSpec.location).append("\n");
|
|
|
|
builder.append("Timestamp: ").append(weatherSpec.timestamp).append("\n");
|
|
|
|
builder.append("Current Temp: ").append(weatherSpec.currentTemp).append(" K\n");
|
|
|
|
builder.append("Max Temp: ").append(weatherSpec.todayMaxTemp).append(" K\n");
|
|
|
|
builder.append("Min Temp: ").append(weatherSpec.todayMinTemp).append(" K\n");
|
|
|
|
builder.append("Condition: ").append(weatherSpec.currentCondition).append("\n");
|
|
|
|
builder.append("Condition Code: ").append(weatherSpec.currentConditionCode).append("\n");
|
|
|
|
builder.append("Humidity: ").append(weatherSpec.currentHumidity).append("\n");
|
|
|
|
builder.append("Wind Speed: ").append(weatherSpec.windSpeed).append(" kmph\n");
|
|
|
|
builder.append("Wind Direction: ").append(weatherSpec.windDirection).append(" deg\n");
|
|
|
|
builder.append("UV Index: ").append(weatherSpec.uvIndex).append("\n");
|
|
|
|
builder.append("Precip Probability: ").append(weatherSpec.precipProbability).append(" %\n");
|
|
|
|
builder.append("Dew Point: ").append(weatherSpec.dewPoint).append(" K\n");
|
|
|
|
builder.append("Pressure: ").append(weatherSpec.pressure).append(" mb\n");
|
|
|
|
builder.append("Cloud Cover: ").append(weatherSpec.cloudCover).append(" %\n");
|
|
|
|
builder.append("Visibility: ").append(weatherSpec.visibility).append(" m\n");
|
|
|
|
builder.append("Sun Rise: ").append(sdf.format(new Date(weatherSpec.sunRise * 1000L))).append("\n");
|
|
|
|
builder.append("Sun Set: ").append(sdf.format(new Date(weatherSpec.sunSet * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Rise: ").append(sdf.format(new Date(weatherSpec.moonRise * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Set: ").append(sdf.format(new Date(weatherSpec.moonSet * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Phase: ").append(weatherSpec.moonPhase).append(" deg\n");
|
|
|
|
builder.append("Latitude: ").append(weatherSpec.latitude).append("\n");
|
|
|
|
builder.append("Longitude: ").append(weatherSpec.longitude).append("\n");
|
|
|
|
builder.append("Feels Like Temp: ").append(weatherSpec.feelsLikeTemp).append(" K\n");
|
|
|
|
builder.append("Is Current Location: ").append(weatherSpec.isCurrentLocation).append("\n");
|
|
|
|
|
|
|
|
if (weatherSpec.airQuality != null) {
|
|
|
|
builder.append("Air Quality aqi: ").append(weatherSpec.airQuality.aqi).append("\n");
|
|
|
|
builder.append("Air Quality co: ").append(weatherSpec.airQuality.co).append("\n");
|
|
|
|
builder.append("Air Quality no2: ").append(weatherSpec.airQuality.no2).append("\n");
|
|
|
|
builder.append("Air Quality o3: ").append(weatherSpec.airQuality.o3).append("\n");
|
|
|
|
builder.append("Air Quality pm10: ").append(weatherSpec.airQuality.pm10).append("\n");
|
|
|
|
builder.append("Air Quality pm25: ").append(weatherSpec.airQuality.pm25).append("\n");
|
|
|
|
builder.append("Air Quality so2: ").append(weatherSpec.airQuality.so2).append("\n");
|
|
|
|
builder.append("Air Quality coAqi: ").append(weatherSpec.airQuality.coAqi).append("\n");
|
|
|
|
builder.append("Air Quality no2Aqi: ").append(weatherSpec.airQuality.no2Aqi).append("\n");
|
|
|
|
builder.append("Air Quality o3Aqi: ").append(weatherSpec.airQuality.o3Aqi).append("\n");
|
|
|
|
builder.append("Air Quality pm10Aqi: ").append(weatherSpec.airQuality.pm10Aqi).append("\n");
|
|
|
|
builder.append("Air Quality pm25Aqi: ").append(weatherSpec.airQuality.pm25Aqi).append("\n");
|
|
|
|
builder.append("Air Quality so2Aqi: ").append(weatherSpec.airQuality.so2Aqi).append("\n");
|
|
|
|
} else {
|
|
|
|
builder.append("Air Quality: null\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (final WeatherSpec.Daily daily : weatherSpec.forecasts) {
|
|
|
|
builder.append("-------------\n");
|
|
|
|
builder.append("-->Day ").append(i++).append("\n");
|
|
|
|
builder.append("Max Temp: ").append(daily.maxTemp).append(" K\n");
|
|
|
|
builder.append("Min Temp: ").append(daily.minTemp).append(" K\n");
|
|
|
|
builder.append("Condition Code: ").append(daily.conditionCode).append("\n");
|
|
|
|
builder.append("Humidity: ").append(daily.humidity).append("\n");
|
|
|
|
builder.append("Wind Speed: ").append(daily.windSpeed).append(" kmph\n");
|
|
|
|
builder.append("Wind Direction: ").append(daily.windDirection).append(" deg\n");
|
|
|
|
builder.append("UV Index: ").append(daily.uvIndex).append("\n");
|
|
|
|
builder.append("Precip Probability: ").append(daily.precipProbability).append(" %\n");
|
|
|
|
builder.append("Sun Rise: ").append(sdf.format(new Date(daily.sunRise * 1000L))).append("\n");
|
|
|
|
builder.append("Sun Set: ").append(sdf.format(new Date(daily.sunSet * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Rise: ").append(sdf.format(new Date(daily.moonRise * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Set: ").append(sdf.format(new Date(daily.moonSet * 1000L))).append("\n");
|
|
|
|
builder.append("Moon Phase: ").append(daily.moonPhase).append(" deg\n");
|
|
|
|
|
|
|
|
if (daily.airQuality != null) {
|
|
|
|
builder.append("Air Quality aqi: ").append(daily.airQuality.aqi).append("\n");
|
|
|
|
builder.append("Air Quality co: ").append(daily.airQuality.co).append("\n");
|
|
|
|
builder.append("Air Quality no2: ").append(daily.airQuality.no2).append("\n");
|
|
|
|
builder.append("Air Quality o3: ").append(daily.airQuality.o3).append("\n");
|
|
|
|
builder.append("Air Quality pm10: ").append(daily.airQuality.pm10).append("\n");
|
|
|
|
builder.append("Air Quality pm25: ").append(daily.airQuality.pm25).append("\n");
|
|
|
|
builder.append("Air Quality so2: ").append(daily.airQuality.so2).append("\n");
|
|
|
|
builder.append("Air Quality coAqi: ").append(daily.airQuality.coAqi).append("\n");
|
|
|
|
builder.append("Air Quality no2Aqi: ").append(daily.airQuality.no2Aqi).append("\n");
|
|
|
|
builder.append("Air Quality o3Aqi: ").append(daily.airQuality.o3Aqi).append("\n");
|
|
|
|
builder.append("Air Quality pm10Aqi: ").append(daily.airQuality.pm10Aqi).append("\n");
|
|
|
|
builder.append("Air Quality pm25Aqi: ").append(daily.airQuality.pm25Aqi).append("\n");
|
|
|
|
builder.append("Air Quality so2Aqi: ").append(daily.airQuality.so2Aqi).append("\n");
|
|
|
|
} else {
|
|
|
|
builder.append("Air Quality: null\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.append("=============\n");
|
|
|
|
|
|
|
|
for (final WeatherSpec.Hourly hourly : weatherSpec.hourly) {
|
|
|
|
builder.append("-------------\n");
|
|
|
|
builder.append("-->Hour: ").append(sdf.format(new Date(hourly.timestamp * 1000L))).append("\n");
|
|
|
|
builder.append("Max Temp: ").append(hourly.temp).append(" K\n");
|
|
|
|
builder.append("Condition Code: ").append(hourly.conditionCode).append("\n");
|
|
|
|
builder.append("Humidity: ").append(hourly.humidity).append("\n");
|
|
|
|
builder.append("Wind Speed: ").append(hourly.windSpeed).append(" kmph\n");
|
|
|
|
builder.append("Wind Direction: ").append(hourly.windDirection).append(" deg\n");
|
|
|
|
builder.append("UV Index: ").append(hourly.uvIndex).append("\n");
|
|
|
|
builder.append("Precip Probability: ").append(hourly.precipProbability).append(" %\n");
|
2023-03-16 21:46:56 +01:00
|
|
|
}
|
|
|
|
|
2023-08-25 23:32:17 +02:00
|
|
|
return builder.toString();
|
2023-03-16 21:46:56 +01:00
|
|
|
}
|
|
|
|
|
2023-08-30 16:28:43 +02:00
|
|
|
public static Map<String, Pair<Long, Integer>> getAllSupportedDevices(Context appContext) {
|
2021-06-27 13:12:40 +02:00
|
|
|
LinkedHashMap<String, Pair<Long, Integer>> newMap = new LinkedHashMap<>(1);
|
|
|
|
GBApplication app = (GBApplication) appContext;
|
2023-09-27 23:11:02 +02:00
|
|
|
for (DeviceType deviceType : DeviceType.values()) {
|
|
|
|
DeviceCoordinator coordinator = deviceType.getDeviceCoordinator();
|
|
|
|
int icon = coordinator.getDefaultIconResource();
|
|
|
|
String name = app.getString(coordinator.getDeviceNameResource()) + " (" + coordinator.getManufacturer() + ")";
|
2023-10-22 01:33:08 +02:00
|
|
|
long deviceId = deviceType.ordinal();
|
2021-06-27 13:12:40 +02:00
|
|
|
newMap.put(name, new Pair(deviceId, icon));
|
|
|
|
}
|
2021-12-23 22:41:50 +01:00
|
|
|
TreeMap <String, Pair<Long, Integer>> sortedMap = new TreeMap<>(newMap);
|
|
|
|
newMap = new LinkedHashMap<>(1);
|
|
|
|
newMap.put(app.getString(R.string.widget_settings_select_device_title), new Pair(SELECT_DEVICE, R.drawable.ic_device_unknown));
|
|
|
|
newMap.putAll(sortedMap);
|
2021-06-27 13:12:40 +02:00
|
|
|
|
|
|
|
return newMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CustomOnDeviceSelectedListener implements AdapterView.OnItemSelectedListener {
|
|
|
|
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
|
|
|
SpinnerWithIconItem selectedItem = (SpinnerWithIconItem) parent.getItemAtPosition(pos);
|
|
|
|
selectedTestDeviceKey = selectedItem.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> arg0) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-07 12:58:18 +01:00
|
|
|
}
|