Add 'Try' button to vibration profile preferences, closes #405
This commit is contained in:
parent
9e32e7d0d3
commit
db034a246c
|
@ -18,8 +18,14 @@ public final class MiBandConst {
|
|||
public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection";
|
||||
public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours";
|
||||
|
||||
public static final String PREF_TRY_SMS = "mi_try_sms";
|
||||
|
||||
|
||||
public static final String ORIGIN_SMS = "sms";
|
||||
public static final String ORIGIN_CHAT = "chat";
|
||||
public static final String ORIGIN_TELEGRAM = "telegram";
|
||||
public static final String ORIGIN_TWITTER = "twitter";
|
||||
public static final String ORIGIN_FACEBOOK = "facebook";
|
||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||
public static final String ORIGIN_K9MAIL = "k9mail";
|
||||
public static final String ORIGIN_PEBBLEMSG = "pebblemsg";
|
||||
|
|
|
@ -4,22 +4,31 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_CHAT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_TRY_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
|
||||
|
@ -43,6 +52,8 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||
|
||||
});
|
||||
|
||||
addTryListeners();
|
||||
|
||||
final Preference enableHeartrateSleepSupport = findPreference(PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION);
|
||||
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
|
@ -53,6 +64,30 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||
});
|
||||
}
|
||||
|
||||
private void addTryListeners() {
|
||||
for (final NotificationType type : NotificationType.values()) {
|
||||
String prefKey = "mi_try_" + type.name();
|
||||
final Preference tryPref = findPreference(prefKey);
|
||||
if (tryPref != null) {
|
||||
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
tryVibration(type);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
GB.toast(getBaseContext(), "Unable to find preference key: " + prefKey + ", trying the vibration won't work", Toast.LENGTH_LONG, GB.WARN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tryVibration(NotificationType type) {
|
||||
NotificationSpec spec = new NotificationSpec();
|
||||
spec.type = type;
|
||||
GBApplication.deviceService().onNotification(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getPreferenceKeysWithSummary() {
|
||||
return new String[]{
|
||||
|
@ -62,6 +97,10 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
|||
PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,
|
||||
PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS,
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_CHAT),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_TELEGRAM),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_TWITTER),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_FACEBOOK),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_K9MAIL),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_PEBBLEMSG),
|
||||
|
|
|
@ -74,10 +74,14 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FL
|
|||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_ORIGINAL_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_CHAT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_PAUSE;
|
||||
|
@ -572,22 +576,22 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||
break;
|
||||
case FACEBOOK:
|
||||
task = "facebook message received";
|
||||
origin = ORIGIN_GENERIC;
|
||||
origin = ORIGIN_FACEBOOK;
|
||||
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
|
||||
break;
|
||||
case TWITTER:
|
||||
task = "twitter message received";
|
||||
origin = ORIGIN_GENERIC;
|
||||
origin = ORIGIN_TWITTER;
|
||||
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
|
||||
break;
|
||||
case TELEGRAM:
|
||||
task = "telegram message received";
|
||||
origin = ORIGIN_GENERIC;
|
||||
origin = ORIGIN_TELEGRAM;
|
||||
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
|
||||
break;
|
||||
case CHAT:
|
||||
task = "chat message received";
|
||||
origin = ORIGIN_PEBBLEMSG;
|
||||
origin = ORIGIN_CHAT;
|
||||
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
|
||||
break;
|
||||
case UNDEFINED:
|
||||
|
|
|
@ -77,10 +77,13 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FL
|
|||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_ORIGINAL_COLOUR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_PAUSE;
|
||||
|
@ -473,7 +476,9 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||
int originalColour = getPreferredOriginalColour(notificationOrigin, prefs);
|
||||
int flashDuration = getPreferredFlashDuration(notificationOrigin, prefs);
|
||||
|
||||
// setLowLatency(builder);
|
||||
sendCustomNotification(profile, flashTimes, flashColour, originalColour, flashDuration, extraAction, builder);
|
||||
// setHighLatency(builder);
|
||||
// sendCustomNotification(vibrateDuration, vibrateTimes, vibratePause, flashTimes, flashColour, originalColour, flashDuration, builder);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
|
@ -548,6 +553,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||
case CHAT:
|
||||
performPreferredNotification("chat message received", ORIGIN_PEBBLEMSG, null);
|
||||
break;
|
||||
case TELEGRAM:
|
||||
performPreferredNotification("chat message received", ORIGIN_TELEGRAM, null);
|
||||
break;
|
||||
case TWITTER:
|
||||
performPreferredNotification("chat message received", ORIGIN_TWITTER, null);
|
||||
break;
|
||||
case FACEBOOK:
|
||||
performPreferredNotification("chat message received", ORIGIN_FACEBOOK, null);
|
||||
break;
|
||||
default:
|
||||
performPreferredNotification("generic notification received", ORIGIN_GENERIC, null);
|
||||
}
|
||||
|
|
|
@ -333,4 +333,9 @@
|
|||
|
||||
<!-- Strings related to Vibration Activity -->
|
||||
<string name="title_activity_vibration">Vibration</string>
|
||||
<string name="vibration_try">Try</string>
|
||||
<string name="pref_screen_notification_profile_chat">Chat</string>
|
||||
<string name="pref_screen_notification_profile_facebook">Facebook</string>
|
||||
<string name="pref_screen_notification_profile_twitter">Twitter</string>
|
||||
<string name="pref_screen_notification_profile_telegram">Telegram</string>
|
||||
</resources>
|
||||
|
|
|
@ -68,6 +68,10 @@
|
|||
android:key="mi_vibration_count_sms"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
|
||||
<Preference
|
||||
android:key="mi_try_SMS"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
|
@ -110,6 +114,9 @@
|
|||
android:key="mi_vibration_count_k9mail"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_EMAIL"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
|
@ -133,6 +140,102 @@
|
|||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vibration_profile_key"
|
||||
android:title="@string/pref_screen_notification_profile_telegram"
|
||||
android:persistent="false">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/p_waterdrop"
|
||||
android:entries="@array/vibration_profile"
|
||||
android:entryValues="@array/vibration_profile_values"
|
||||
android:key="mi_vibration_profile_telegram"
|
||||
android:title="@string/miband_prefs_vibration"
|
||||
android:summary="%s" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="3"
|
||||
android:inputType="number"
|
||||
android:key="mi_vibration_count_telegram"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_TELEGRAM"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vibration_profile_key"
|
||||
android:title="@string/pref_screen_notification_profile_chat"
|
||||
android:persistent="false">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/p_waterdrop"
|
||||
android:entries="@array/vibration_profile"
|
||||
android:entryValues="@array/vibration_profile_values"
|
||||
android:key="mi_vibration_profile_chat"
|
||||
android:title="@string/miband_prefs_vibration"
|
||||
android:summary="%s" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="3"
|
||||
android:inputType="number"
|
||||
android:key="mi_vibration_count_chat"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_CHAT"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vibration_profile_key"
|
||||
android:title="@string/pref_screen_notification_profile_twitter"
|
||||
android:persistent="false">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/p_waterdrop"
|
||||
android:entries="@array/vibration_profile"
|
||||
android:entryValues="@array/vibration_profile_values"
|
||||
android:key="mi_vibration_profile_twitter"
|
||||
android:title="@string/miband_prefs_vibration"
|
||||
android:summary="%s" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="3"
|
||||
android:inputType="number"
|
||||
android:key="mi_vibration_count_twitter"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_TWITTER"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vibration_profile_key"
|
||||
android:title="@string/pref_screen_notification_profile_facebook"
|
||||
android:persistent="false">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/p_waterdrop"
|
||||
android:entries="@array/vibration_profile"
|
||||
android:entryValues="@array/vibration_profile_values"
|
||||
android:key="mi_vibration_profile_facebook"
|
||||
android:title="@string/miband_prefs_vibration"
|
||||
android:summary="%s" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="3"
|
||||
android:inputType="number"
|
||||
android:key="mi_vibration_count_facebook"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_FACEBOOK"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vibration_profile_key"
|
||||
android:title="@string/pref_screen_notification_profile_generic"
|
||||
|
@ -152,6 +255,9 @@
|
|||
android:key="mi_vibration_count_generic"
|
||||
android:maxLength="1"
|
||||
android:title="@string/pref_title_notifications_repetitions" />
|
||||
<Preference
|
||||
android:key="mi_try_UNDEFINED"
|
||||
android:title="@string/vibration_try"/>
|
||||
</PreferenceScreen>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
|
Loading…
Reference in New Issue