2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2019-2021 Carsten Pfeiffer, Daniel Dakhno, Taavi Eomäe
|
2019-12-06 22:49:44 +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
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2019-07-14 19:45:40 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
2019-10-20 01:42:31 +02:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2019-07-14 19:45:40 +02:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.NumberPicker;
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.SeekBar;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2019-07-21 16:47:17 +02:00
|
|
|
|
2019-11-17 04:55:12 +01:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2020-08-26 04:38:55 +02:00
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-11-17 04:55:12 +01:00
|
|
|
|
2019-07-26 16:42:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2019-07-14 19:45:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2019-07-26 16:42:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2019-07-21 16:47:17 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
2019-11-21 23:22:55 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails;
|
2019-07-14 19:45:40 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
|
2019-11-17 04:55:12 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload;
|
2019-10-30 02:50:00 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
2019-07-14 19:45:40 +02:00
|
|
|
|
2019-07-26 16:42:53 +02:00
|
|
|
public class ConfigActivity extends AbstractGBActivity {
|
2019-07-14 19:45:40 +02:00
|
|
|
PackageAdapter adapter;
|
2019-10-28 12:35:22 +01:00
|
|
|
ArrayList<NotificationConfiguration> list;
|
2019-07-14 19:45:40 +02:00
|
|
|
PackageConfigHelper helper;
|
|
|
|
|
|
|
|
final int REQUEST_CODE_ADD_APP = 0;
|
|
|
|
|
|
|
|
private boolean hasControl = false;
|
|
|
|
|
|
|
|
SharedPreferences prefs;
|
|
|
|
|
2019-11-20 18:59:13 +01:00
|
|
|
TextView timeOffsetView, timezoneOffsetView;
|
2019-07-14 19:45:40 +02:00
|
|
|
|
2019-07-21 16:47:17 +02:00
|
|
|
GBDevice device;
|
2019-07-14 19:45:40 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-07-26 16:42:53 +02:00
|
|
|
|
2019-07-14 19:45:40 +02:00
|
|
|
setContentView(R.layout.activity_qhybrid_settings);
|
|
|
|
|
|
|
|
findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2019-07-21 16:47:17 +02:00
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS));
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
|
|
|
timeOffsetView = findViewById(R.id.qhybridTimeOffset);
|
|
|
|
timeOffsetView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
|
|
|
LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
|
|
|
|
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
|
|
|
|
hourPicker.setMinValue(0);
|
|
|
|
hourPicker.setMaxValue(23);
|
|
|
|
hourPicker.setValue(timeOffset / 60);
|
|
|
|
|
|
|
|
final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
|
|
|
|
minPicker.setMinValue(0);
|
|
|
|
minPicker.setMaxValue(59);
|
|
|
|
minPicker.setValue(timeOffset % 60);
|
|
|
|
|
|
|
|
layout2.addView(hourPicker);
|
|
|
|
TextView tw = new TextView(ConfigActivity.this);
|
|
|
|
tw.setText(":");
|
|
|
|
layout2.addView(tw);
|
|
|
|
layout2.addView(minPicker);
|
|
|
|
|
|
|
|
layout2.setGravity(Gravity.CENTER);
|
|
|
|
|
|
|
|
new AlertDialog.Builder(ConfigActivity.this)
|
2019-12-04 00:59:43 +01:00
|
|
|
.setTitle(getString(R.string.qhybrid_offset_time_by))
|
2019-07-14 19:45:40 +02:00
|
|
|
.setView(layout2)
|
|
|
|
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
prefs.edit().putInt("QHYBRID_TIME_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
|
|
|
updateTimeOffset();
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE));
|
2019-12-04 00:59:43 +01:00
|
|
|
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton("cancel", null)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateTimeOffset();
|
|
|
|
|
2019-11-20 18:59:13 +01:00
|
|
|
|
|
|
|
timezoneOffsetView = findViewById(R.id.timezoneOffset);
|
|
|
|
timezoneOffsetView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0);
|
|
|
|
LinearLayout layout2 = new LinearLayout(ConfigActivity.this);
|
|
|
|
layout2.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
|
|
|
final NumberPicker hourPicker = new NumberPicker(ConfigActivity.this);
|
|
|
|
hourPicker.setMinValue(0);
|
|
|
|
hourPicker.setMaxValue(23);
|
|
|
|
hourPicker.setValue(timeOffset / 60);
|
|
|
|
|
|
|
|
final NumberPicker minPicker = new NumberPicker(ConfigActivity.this);
|
|
|
|
minPicker.setMinValue(0);
|
|
|
|
minPicker.setMaxValue(59);
|
|
|
|
minPicker.setValue(timeOffset % 60);
|
|
|
|
|
|
|
|
layout2.addView(hourPicker);
|
|
|
|
TextView tw = new TextView(ConfigActivity.this);
|
|
|
|
tw.setText(":");
|
|
|
|
layout2.addView(tw);
|
|
|
|
layout2.addView(minPicker);
|
|
|
|
|
|
|
|
layout2.setGravity(Gravity.CENTER);
|
|
|
|
|
|
|
|
new AlertDialog.Builder(ConfigActivity.this)
|
2019-12-04 00:59:43 +01:00
|
|
|
.setTitle(getString(R.string.qhybrid_offset_timezone))
|
2019-11-20 18:59:13 +01:00
|
|
|
.setView(layout2)
|
|
|
|
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
prefs.edit().putInt("QHYBRID_TIMEZONE_OFFSET", hourPicker.getValue() * 60 + minPicker.getValue()).apply();
|
|
|
|
updateTimezoneOffset();
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_TIMEZONE));
|
2019-12-04 00:59:43 +01:00
|
|
|
GB.toast(getString(R.string.qhybrid_changes_delay_prompt), Toast.LENGTH_SHORT, GB.INFO);
|
2019-11-20 18:59:13 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton("cancel", null)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
updateTimezoneOffset();
|
|
|
|
|
2019-07-14 19:45:40 +02:00
|
|
|
setTitle(R.string.preferences_qhybrid_settings);
|
|
|
|
|
|
|
|
ListView appList = findViewById(R.id.qhybrid_appList);
|
|
|
|
|
2019-10-30 02:50:00 +01:00
|
|
|
try {
|
|
|
|
helper = new PackageConfigHelper(getApplicationContext());
|
|
|
|
list = helper.getNotificationConfigurations();
|
2020-01-29 19:56:29 +01:00
|
|
|
} catch (Exception e) {
|
2019-10-30 02:50:00 +01:00
|
|
|
GB.toast("error getting configurations", Toast.LENGTH_SHORT, GB.ERROR, e);
|
|
|
|
list = new ArrayList<>();
|
|
|
|
}
|
2019-12-04 00:22:19 +01:00
|
|
|
// null is added to indicate the plus button added handled in PackageAdapter#getView
|
2019-07-14 19:45:40 +02:00
|
|
|
list.add(null);
|
|
|
|
appList.setAdapter(adapter = new PackageAdapter(this, R.layout.qhybrid_package_settings_item, list));
|
|
|
|
appList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
2019-08-01 22:39:34 +02:00
|
|
|
public boolean onItemLongClick(final AdapterView<?> adapterView, View view, final int i, long l) {
|
2019-07-14 19:45:40 +02:00
|
|
|
PopupMenu menu = new PopupMenu(ConfigActivity.this, view);
|
2019-12-04 00:18:12 +01:00
|
|
|
menu.getMenu().add(0, 0, 0, "edit");
|
|
|
|
menu.getMenu().add(0, 1, 1, "delete");
|
2019-07-14 19:45:40 +02:00
|
|
|
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
2019-12-04 00:18:12 +01:00
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case 0: {
|
2019-10-28 12:35:22 +01:00
|
|
|
TimePicker picker = new TimePicker(ConfigActivity.this, (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
2019-07-14 19:45:40 +02:00
|
|
|
picker.finishListener = new TimePicker.OnFinishListener() {
|
|
|
|
@Override
|
2019-10-28 12:35:22 +01:00
|
|
|
public void onFinish(boolean success, NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
setControl(false, null);
|
|
|
|
if (success) {
|
2019-10-30 02:50:00 +01:00
|
|
|
try {
|
|
|
|
helper.saveNotificationConfiguration(config);
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
2020-01-29 19:56:29 +01:00
|
|
|
} catch (Exception e) {
|
2019-10-30 02:50:00 +01:00
|
|
|
GB.toast("error saving notification", Toast.LENGTH_SHORT, GB.ERROR, e);
|
|
|
|
}
|
2019-07-14 19:45:40 +02:00
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
picker.handsListener = new TimePicker.OnHandsSetListener() {
|
|
|
|
@Override
|
2019-10-28 12:35:22 +01:00
|
|
|
public void onHandsSet(NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
setHands(config);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
picker.vibrationListener = new TimePicker.OnVibrationSetListener() {
|
|
|
|
@Override
|
2019-10-28 12:35:22 +01:00
|
|
|
public void onVibrationSet(NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
vibrate(config);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setControl(true, picker.getSettings());
|
|
|
|
break;
|
|
|
|
}
|
2019-12-04 00:18:12 +01:00
|
|
|
case 1: {
|
2019-10-30 02:50:00 +01:00
|
|
|
try {
|
|
|
|
helper.deleteNotificationConfiguration((NotificationConfiguration) adapterView.getItemAtPosition(i));
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION_CONFIG_CHANGED));
|
2020-01-29 19:56:29 +01:00
|
|
|
} catch (Exception e) {
|
2019-10-30 02:50:00 +01:00
|
|
|
GB.toast("error deleting setting", Toast.LENGTH_SHORT, GB.ERROR, e);
|
|
|
|
}
|
2019-07-14 19:45:40 +02:00
|
|
|
refreshList();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-01 22:39:34 +02:00
|
|
|
return true;
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
menu.show();
|
2019-08-01 22:39:34 +02:00
|
|
|
return true;
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
appList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2019-07-21 16:47:17 +02:00
|
|
|
Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
|
2019-10-28 12:35:22 +01:00
|
|
|
notificationIntent.putExtra("CONFIG", (NotificationConfiguration) adapterView.getItemAtPosition(i));
|
2019-07-21 16:47:17 +02:00
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(notificationIntent);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar);
|
|
|
|
vibeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
int start;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
|
|
start = seekBar.getProgress();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
|
int progress;
|
|
|
|
if ((progress = seekBar.getProgress()) == start) return;
|
2019-07-21 16:47:17 +02:00
|
|
|
String[] values = {"25", "50", "100"};
|
|
|
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress]));
|
|
|
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
|
|
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH);
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
2019-07-26 16:42:53 +02:00
|
|
|
|
2022-06-14 18:05:41 +02:00
|
|
|
List<GBDevice> devices = GBApplication.app().getDeviceManager().getSelectedDevices();
|
|
|
|
for(GBDevice device : devices){
|
|
|
|
if (device.getType() == DeviceType.FOSSILQHYBRID && device.getFirmwareVersion().charAt(2) == '0') {
|
|
|
|
updateSettings();
|
|
|
|
return;
|
|
|
|
}
|
2019-07-26 16:42:53 +02:00
|
|
|
}
|
2022-06-14 18:05:41 +02:00
|
|
|
setSettingsError(getString(R.string.watch_not_connected));
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateTimeOffset() {
|
|
|
|
int timeOffset = prefs.getInt("QHYBRID_TIME_OFFSET", 0);
|
|
|
|
DecimalFormat format = new DecimalFormat("00");
|
|
|
|
timeOffsetView.setText(
|
|
|
|
format.format(timeOffset / 60) + ":" +
|
|
|
|
format.format(timeOffset % 60)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-20 18:59:13 +01:00
|
|
|
|
|
|
|
private void updateTimezoneOffset() {
|
|
|
|
int timeOffset = prefs.getInt("QHYBRID_TIMEZONE_OFFSET", 0);
|
|
|
|
DecimalFormat format = new DecimalFormat("00");
|
|
|
|
timezoneOffsetView.setText(
|
|
|
|
format.format(timeOffset / 60) + ":" +
|
|
|
|
format.format(timeOffset % 60)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-21 16:47:17 +02:00
|
|
|
private void setSettingsEnabled(boolean enables) {
|
2019-07-14 19:45:40 +02:00
|
|
|
findViewById(R.id.settingsLayout).setAlpha(enables ? 1f : 0.2f);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSettings() {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-07-21 16:47:17 +02:00
|
|
|
EditText et = findViewById(R.id.stepGoalEt);
|
|
|
|
et.setOnEditorActionListener(null);
|
2019-10-20 01:42:31 +02:00
|
|
|
final String text = device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails();
|
|
|
|
et.setText(text);
|
|
|
|
et.setSelection(text.length());
|
2019-07-21 16:47:17 +02:00
|
|
|
et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
2019-07-14 19:45:40 +02:00
|
|
|
@Override
|
2019-07-21 16:47:17 +02:00
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
String t = textView.getText().toString();
|
2019-12-04 00:09:38 +01:00
|
|
|
if (!t.isEmpty()) {
|
2019-07-21 16:47:17 +02:00
|
|
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, t));
|
|
|
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
|
|
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_STEP_GOAL);
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
|
|
|
updateSettings();
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
2019-07-21 16:47:17 +02:00
|
|
|
((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
|
|
|
|
}
|
|
|
|
return true;
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
2019-07-21 16:47:17 +02:00
|
|
|
|
2019-12-04 00:19:48 +01:00
|
|
|
if ("true".equals(device.getDeviceInfo(QHybridSupport.ITEM_EXTENDED_VIBRATION_SUPPORT).getDetails())) {
|
2019-07-21 16:47:17 +02:00
|
|
|
final int strengthProgress = (int) (Math.log(Double.parseDouble(device.getDeviceInfo(QHybridSupport.ITEM_VIBRATION_STRENGTH).getDetails()) / 25) / Math.log(2));
|
|
|
|
|
|
|
|
setSettingsEnabled(true);
|
|
|
|
SeekBar seekBar = findViewById(R.id.vibrationStrengthBar);
|
|
|
|
seekBar.setProgress(strengthProgress);
|
2019-10-20 01:42:31 +02:00
|
|
|
} else {
|
2019-07-21 17:09:14 +02:00
|
|
|
findViewById(R.id.vibrationStrengthBar).setEnabled(false);
|
2019-07-21 16:47:17 +02:00
|
|
|
findViewById(R.id.vibrationStrengthLayout).setAlpha(0.5f);
|
|
|
|
}
|
2019-10-20 01:42:31 +02:00
|
|
|
CheckBox activityHandCheckbox = findViewById(R.id.checkBoxUserActivityHand);
|
|
|
|
if (device.getDeviceInfo(QHybridSupport.ITEM_HAS_ACTIVITY_HAND).getDetails().equals("true")) {
|
|
|
|
if (device.getDeviceInfo(QHybridSupport.ITEM_USE_ACTIVITY_HAND).getDetails().equals("true")) {
|
|
|
|
activityHandCheckbox.setChecked(true);
|
|
|
|
}
|
|
|
|
activityHandCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
|
2019-11-17 04:55:12 +01:00
|
|
|
if (!device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails().equals("1000000")) {
|
2019-10-20 01:42:31 +02:00
|
|
|
new AlertDialog.Builder(ConfigActivity.this)
|
2019-12-04 00:59:43 +01:00
|
|
|
.setMessage(getString(R.string.qhybrid_prompt_million_steps))
|
2019-10-20 01:42:31 +02:00
|
|
|
.setPositiveButton("ok", null)
|
|
|
|
.show();
|
|
|
|
buttonView.setChecked(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_USE_ACTIVITY_HAND, String.valueOf(checked)));
|
|
|
|
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
|
|
|
|
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_USE_ACTIVITY_HAND);
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2019-10-30 16:42:44 +01:00
|
|
|
// activityHandCheckbox.setEnabled(false);
|
|
|
|
activityHandCheckbox.setAlpha(0.2f);
|
|
|
|
activityHandCheckbox.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
GB.toast("nah.", Toast.LENGTH_SHORT, GB.INFO);
|
2019-11-17 04:55:12 +01:00
|
|
|
((CheckBox) v).setChecked(false);
|
2019-10-30 16:42:44 +01:00
|
|
|
}
|
|
|
|
});
|
2019-10-20 01:42:31 +02:00
|
|
|
}
|
2019-11-17 04:55:12 +01:00
|
|
|
|
2019-12-15 14:58:19 +01:00
|
|
|
ItemWithDetails item = device.getDeviceInfo(FossilWatchAdapter.ITEM_BUTTONS);
|
|
|
|
String buttonJson = null;
|
|
|
|
if(item != null) {
|
|
|
|
buttonJson = item.getDetails();
|
|
|
|
}
|
2019-11-21 23:22:55 +01:00
|
|
|
try {
|
2019-11-24 00:44:14 +01:00
|
|
|
JSONArray buttonConfig_;
|
|
|
|
if (buttonJson == null || buttonJson.isEmpty()) {
|
|
|
|
buttonConfig_ = new JSONArray(new String[]{"", "", ""});
|
|
|
|
}else{
|
|
|
|
buttonConfig_ = new JSONArray(buttonJson);
|
2019-11-21 23:22:55 +01:00
|
|
|
}
|
|
|
|
|
2019-11-24 00:44:14 +01:00
|
|
|
final JSONArray buttonConfig = buttonConfig_;
|
|
|
|
|
2019-11-21 23:22:55 +01:00
|
|
|
LinearLayout buttonLayout = findViewById(R.id.buttonConfigLayout);
|
|
|
|
buttonLayout.removeAllViews();
|
|
|
|
findViewById(R.id.buttonOverwriteButtons).setVisibility(View.GONE);
|
|
|
|
final ConfigPayload[] payloads = ConfigPayload.values();
|
|
|
|
final String[] names = new String[payloads.length];
|
|
|
|
for (int i = 0; i < payloads.length; i++)
|
|
|
|
names[i] = payloads[i].getDescription();
|
|
|
|
for (int i = 0; i < buttonConfig.length(); i++) {
|
|
|
|
final int currentIndex = i;
|
|
|
|
String configName = buttonConfig.getString(i);
|
|
|
|
TextView buttonTextView = new TextView(ConfigActivity.this);
|
|
|
|
buttonTextView.setTextSize(20);
|
|
|
|
try {
|
|
|
|
ConfigPayload payload = ConfigPayload.valueOf(configName);
|
|
|
|
buttonTextView.setText("Button " + (i + 1) + ": " + payload.getDescription());
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
buttonTextView.setText("Button " + (i + 1) + ": Unknown");
|
|
|
|
}
|
2019-11-17 04:55:12 +01:00
|
|
|
|
2019-11-21 23:22:55 +01:00
|
|
|
buttonTextView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(ConfigActivity.this)
|
|
|
|
.setItems(names, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.cancel();
|
|
|
|
ConfigPayload selected = payloads[which];
|
2019-11-24 00:44:14 +01:00
|
|
|
|
2019-11-21 23:22:55 +01:00
|
|
|
try {
|
2019-11-24 00:44:14 +01:00
|
|
|
buttonConfig.put(currentIndex, selected.toString());
|
|
|
|
device.addDeviceInfo(new GenericItem(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString()));
|
2019-11-21 23:22:55 +01:00
|
|
|
updateSettings();
|
2019-11-24 00:44:14 +01:00
|
|
|
Intent buttonIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS);
|
|
|
|
buttonIntent.putExtra(FossilWatchAdapter.ITEM_BUTTONS, buttonConfig.toString());
|
|
|
|
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(buttonIntent);
|
2019-11-21 23:22:55 +01:00
|
|
|
} catch (JSONException e) {
|
2019-12-04 00:36:42 +01:00
|
|
|
GB.log("error", GB.ERROR, e);
|
2019-11-17 04:55:12 +01:00
|
|
|
}
|
2019-11-21 23:22:55 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setTitle("Button " + (currentIndex + 1))
|
|
|
|
.create();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
});
|
2019-11-17 04:55:12 +01:00
|
|
|
|
2019-11-21 23:22:55 +01:00
|
|
|
buttonLayout.addView(buttonTextView);
|
2019-11-17 04:55:12 +01:00
|
|
|
}
|
2019-11-24 00:44:14 +01:00
|
|
|
} catch (JSONException e) {
|
|
|
|
GB.toast("error parsing button config", Toast.LENGTH_LONG, GB.ERROR);
|
2019-11-17 04:55:12 +01:00
|
|
|
}
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
private void setControl(boolean control, NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
if (hasControl == control) return;
|
|
|
|
Intent intent = new Intent(control ? QHybridSupport.QHYBRID_COMMAND_CONTROL : QHybridSupport.QHYBRID_COMMAND_UNCONTROL);
|
|
|
|
intent.putExtra("CONFIG", config);
|
|
|
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
|
|
|
this.hasControl = control;
|
|
|
|
}
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
private void setHands(NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
sendControl(config, QHybridSupport.QHYBRID_COMMAND_SET);
|
|
|
|
}
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
private void vibrate(NotificationConfiguration config) {
|
2019-07-14 19:45:40 +02:00
|
|
|
sendControl(config, QHybridSupport.QHYBRID_COMMAND_VIBRATE);
|
|
|
|
}
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
private void sendControl(NotificationConfiguration config, String request) {
|
2019-07-14 19:45:40 +02:00
|
|
|
Intent intent = new Intent(request);
|
|
|
|
intent.putExtra("CONFIG", config);
|
|
|
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshList() {
|
|
|
|
list.clear();
|
2019-10-30 02:50:00 +01:00
|
|
|
try {
|
|
|
|
list.addAll(helper.getNotificationConfigurations());
|
2020-01-29 19:56:29 +01:00
|
|
|
} catch (Exception e) {
|
2019-10-30 02:50:00 +01:00
|
|
|
GB.toast("error getting configurations", Toast.LENGTH_SHORT, GB.ERROR, e);
|
|
|
|
}
|
2019-12-04 00:22:19 +01:00
|
|
|
// null is added to indicate the plus button added handled in PackageAdapter#getView
|
2019-07-14 19:45:40 +02:00
|
|
|
list.add(null);
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
refreshList();
|
|
|
|
registerReceiver(buttonReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_BUTTON_PRESS));
|
2019-07-21 16:47:17 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(settingsReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_SETTINGS_UPDATED));
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(fileReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_FILE_UPLOADED));
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
unregisterReceiver(buttonReceiver);
|
2019-07-21 16:47:17 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(settingsReceiver);
|
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(fileReceiver);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setSettingsError(final String error) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-07-21 16:47:17 +02:00
|
|
|
setSettingsEnabled(false);
|
2019-07-14 19:45:40 +02:00
|
|
|
((TextView) findViewById(R.id.settingsErrorText)).setVisibility(View.VISIBLE);
|
|
|
|
((TextView) findViewById(R.id.settingsErrorText)).setText(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
class PackageAdapter extends ArrayAdapter<NotificationConfiguration> {
|
2019-07-14 19:45:40 +02:00
|
|
|
PackageManager manager;
|
|
|
|
|
2019-10-28 12:35:22 +01:00
|
|
|
PackageAdapter(@NonNull Context context, int resource, @NonNull List<NotificationConfiguration> objects) {
|
2019-07-14 19:45:40 +02:00
|
|
|
super(context, resource, objects);
|
|
|
|
manager = context.getPackageManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) {
|
|
|
|
if (!(view instanceof RelativeLayout))
|
|
|
|
view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.qhybrid_package_settings_item, null);
|
2019-10-28 12:35:22 +01:00
|
|
|
NotificationConfiguration settings = getItem(position);
|
2019-07-14 19:45:40 +02:00
|
|
|
|
2019-07-21 16:47:17 +02:00
|
|
|
if (settings == null) {
|
2019-07-14 19:45:40 +02:00
|
|
|
Button addButton = new Button(ConfigActivity.this);
|
|
|
|
addButton.setText("+");
|
|
|
|
addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
addButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
startActivityForResult(new Intent(ConfigActivity.this, QHybridAppChoserActivity.class), REQUEST_CODE_ADD_APP);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return addButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
((ImageView) view.findViewById(R.id.packageIcon)).setImageDrawable(manager.getApplicationIcon(settings.getPackageName()));
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
2019-12-04 00:36:42 +01:00
|
|
|
GB.log("error", GB.ERROR, e);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
2020-08-26 04:41:06 +02:00
|
|
|
final int square_side = 100;
|
2019-07-14 19:45:40 +02:00
|
|
|
((TextView) view.findViewById(R.id.packageName)).setText(settings.getAppName());
|
2020-08-26 04:41:06 +02:00
|
|
|
Bitmap bitmap = Bitmap.createBitmap(square_side, square_side, Bitmap.Config.ARGB_8888);
|
2019-07-14 19:45:40 +02:00
|
|
|
Canvas c = new Canvas(bitmap);
|
|
|
|
|
|
|
|
Paint black = new Paint();
|
|
|
|
black.setColor(Color.BLACK);
|
|
|
|
black.setStyle(Paint.Style.STROKE);
|
|
|
|
black.setStrokeWidth(5);
|
|
|
|
|
2020-08-26 04:41:06 +02:00
|
|
|
c.drawCircle(square_side / 2, square_side / 2, square_side / 2 - 3, black);
|
2019-07-14 19:45:40 +02:00
|
|
|
|
2020-08-26 04:41:06 +02:00
|
|
|
int center = square_side / 2;
|
2019-07-14 19:45:40 +02:00
|
|
|
if (settings.getHour() != -1) {
|
|
|
|
c.drawLine(
|
|
|
|
center,
|
|
|
|
center,
|
2020-08-26 04:41:06 +02:00
|
|
|
(float) (center + Math.sin(Math.toRadians(settings.getHour())) * (square_side / 4)),
|
|
|
|
(float) (center - Math.cos(Math.toRadians(settings.getHour())) * (square_side / 4)),
|
2019-07-14 19:45:40 +02:00
|
|
|
black
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (settings.getMin() != -1) {
|
|
|
|
c.drawLine(
|
|
|
|
center,
|
|
|
|
center,
|
2020-08-26 04:41:06 +02:00
|
|
|
(float) (center + Math.sin(Math.toRadians(settings.getMin())) * (square_side / 3)),
|
|
|
|
(float) (center - Math.cos(Math.toRadians(settings.getMin())) * (square_side / 3)),
|
2019-07-14 19:45:40 +02:00
|
|
|
black
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
((ImageView) view.findViewById(R.id.packageClock)).setImageBitmap(bitmap);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 16:47:17 +02:00
|
|
|
BroadcastReceiver fileReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2019-10-20 01:42:31 +02:00
|
|
|
boolean error = intent.getBooleanExtra("EXTRA_ERROR", false);
|
|
|
|
if (error) {
|
2019-12-04 00:59:43 +01:00
|
|
|
GB.toast(getString(R.string.qhybrid_buttons_overwrite_error), Toast.LENGTH_SHORT, GB.ERROR);
|
2019-07-21 16:47:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-12-04 00:59:43 +01:00
|
|
|
GB.toast(getString(R.string.qhybrid_buttons_overwrite_success), Toast.LENGTH_SHORT, GB.INFO);
|
2019-07-21 16:47:17 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-14 19:45:40 +02:00
|
|
|
BroadcastReceiver buttonReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2019-12-04 00:25:08 +01:00
|
|
|
GB.toast("Button " + intent.getIntExtra("BUTTON", -1) + " pressed", Toast.LENGTH_SHORT, GB.INFO);
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-21 16:47:17 +02:00
|
|
|
BroadcastReceiver settingsReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2019-12-04 00:25:08 +01:00
|
|
|
GB.toast("Setting updated", Toast.LENGTH_SHORT, GB.INFO);
|
2019-07-21 16:47:17 +02:00
|
|
|
updateSettings();
|
|
|
|
}
|
|
|
|
};
|
2019-07-14 19:45:40 +02:00
|
|
|
}
|