parent
2798f0779b
commit
e179b93f6e
|
@ -2,6 +2,7 @@
|
|||
- Add resources menu linking to how to meditate, /r/meditation, an overview of MediNET and replaying the tutorial
|
||||
- Add presets to tutorial
|
||||
- Add session volume preview
|
||||
- Add custom vibration patterns
|
||||
- Resolve possible crash when waking device
|
||||
- Resolve duration not being preselected when editing
|
||||
- Remove usage of Google Play Services (was previously used in releases on Google Play and Amazon)
|
||||
|
|
|
@ -146,8 +146,8 @@ public class CompleteActivity extends Activity {
|
|||
}
|
||||
|
||||
String finishSoundPath = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_finish", "");
|
||||
if (!manual && !finishSoundPath.equals("none")) {
|
||||
getMeditationAssistant().playSessionSound(2, false);
|
||||
if (!manual) {
|
||||
getMeditationAssistant().notifySession(2, false, false);
|
||||
} else {
|
||||
getMeditationAssistant().restoreVolume();
|
||||
}
|
||||
|
@ -156,8 +156,6 @@ public class CompleteActivity extends Activity {
|
|||
}
|
||||
|
||||
if (!manual) {
|
||||
getMeditationAssistant().vibrateDevice();
|
||||
|
||||
String autosave = getMeditationAssistant().getPrefs().getString("pref_autosave", "");
|
||||
if (autosave.equals("save")) {
|
||||
saveMediNET(null);
|
||||
|
|
|
@ -43,8 +43,6 @@ public class ListPreferenceSound extends ListPreference {
|
|||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.ListPreference, 0, 0);
|
||||
// mEntries = a.getTextArray(R.styleable.ListPreference_entries);
|
||||
// mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
|
||||
setEntries(a.getTextArray(R.styleable.ListPreference_entries));
|
||||
setEntryValues(a.getTextArray(R.styleable.ListPreference_entryValues));
|
||||
|
||||
|
@ -99,7 +97,6 @@ public class ListPreferenceSound extends ListPreference {
|
|||
if (mSummary == null || entry == null) {
|
||||
return super.getSummary();
|
||||
} else {
|
||||
//Log.d("MeditationAssistant", "getsummary(): " + String.valueOf(mSummary) + " " + String.valueOf(entry));
|
||||
try {
|
||||
return String.format(mSummary.toString(), entry);
|
||||
} catch (Exception e) {
|
||||
|
@ -152,8 +149,7 @@ public class ListPreferenceSound extends ListPreference {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (positiveResult && mClickedDialogEntryIndex >= 0
|
||||
&& mEntryValues != null) {
|
||||
if (positiveResult && mClickedDialogEntryIndex >= 0 && mEntryValues != null) {
|
||||
String value = mEntryValues[mClickedDialogEntryIndex].toString();
|
||||
if (callChangeListener(value)) {
|
||||
setValue(value);
|
||||
|
@ -262,10 +258,8 @@ public class ListPreferenceSound extends ListPreference {
|
|||
builder.setPositiveButton(
|
||||
builder.getContext().getString(R.string.set),
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.d("MeditationAssistant", "Set clicked");
|
||||
ListPreferenceSound.this.onClick(dialog,
|
||||
DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
|
|
|
@ -0,0 +1,240 @@
|
|||
package sh.ftp.rocketninelabs.meditationassistant;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
public class ListPreferenceVibration extends ListPreference {
|
||||
private int mClickedDialogEntryIndex;
|
||||
private CharSequence[] mEntries;
|
||||
private CharSequence[] mEntryValues;
|
||||
private CharSequence mSummary;
|
||||
private String mValue;
|
||||
private Context ctx = null;
|
||||
private SharedPreferences prefs = null;
|
||||
|
||||
public ListPreferenceVibration(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ListPreferenceVibration(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
ctx = context;
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.ListPreference, 0, 0);
|
||||
setEntries(a.getTextArray(R.styleable.ListPreference_entries));
|
||||
setEntryValues(a.getTextArray(R.styleable.ListPreference_entryValues));
|
||||
|
||||
a.recycle();
|
||||
mSummary = super.getSummary();
|
||||
}
|
||||
|
||||
public int findIndexOfValue(String value) {
|
||||
if (value != null && mEntryValues != null) {
|
||||
for (int i = mEntryValues.length - 1; i >= 0; i--) {
|
||||
if (mEntryValues[i].equals(value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public CharSequence[] getEntries() {
|
||||
return mEntries;
|
||||
}
|
||||
|
||||
public void setEntries(CharSequence[] entries) {
|
||||
mEntries = entries;
|
||||
}
|
||||
|
||||
public void setEntries(int entriesResId) {
|
||||
setEntries(getContext().getResources().getTextArray(entriesResId));
|
||||
}
|
||||
|
||||
public CharSequence getEntry() {
|
||||
int index = getValueIndex();
|
||||
return index >= 0 && mEntries != null ? mEntries[index] : null;
|
||||
}
|
||||
|
||||
public CharSequence[] getEntryValues() {
|
||||
return mEntryValues;
|
||||
}
|
||||
|
||||
public void setEntryValues(CharSequence[] entryValues) {
|
||||
mEntryValues = entryValues;
|
||||
}
|
||||
|
||||
public void setEntryValues(int entryValuesResId) {
|
||||
setEntryValues(getContext().getResources().getTextArray(
|
||||
entryValuesResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final CharSequence entry = getEntry();
|
||||
if (mSummary == null || entry == null) {
|
||||
return super.getSummary();
|
||||
} else {
|
||||
try {
|
||||
return String.format(mSummary.toString(), entry);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return mSummary.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
super.setSummary(summary);
|
||||
if (summary == null && mSummary != null) {
|
||||
mSummary = null;
|
||||
} else if (summary != null && !summary.equals(mSummary)) {
|
||||
mSummary = summary;
|
||||
}
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
mValue = value;
|
||||
persistString(value);
|
||||
}
|
||||
|
||||
private int getValueIndex() {
|
||||
return findIndexOfValue(mValue);
|
||||
}
|
||||
|
||||
public void setValueIndex(int index) {
|
||||
if (mEntryValues != null) {
|
||||
setValue(mEntryValues[index].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult && mClickedDialogEntryIndex >= 0 && mEntryValues != null) {
|
||||
String value = mEntryValues[mClickedDialogEntryIndex].toString();
|
||||
if (callChangeListener(value)) {
|
||||
setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return a.getString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
if (mEntries == null || mEntryValues == null) {
|
||||
throw new IllegalStateException(
|
||||
"ListPreference requires an entries array and an entryValues array.");
|
||||
}
|
||||
mClickedDialogEntryIndex = getValueIndex();
|
||||
builder.setSingleChoiceItems(mEntries, mClickedDialogEntryIndex,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mClickedDialogEntryIndex = which;
|
||||
String itemSelected = mEntryValues[mClickedDialogEntryIndex]
|
||||
.toString();
|
||||
|
||||
Log.d("MeditationAssistant",
|
||||
"Selected: " + which + " - "
|
||||
+ itemSelected
|
||||
);
|
||||
|
||||
if (itemSelected.equals("custom")) {
|
||||
ListPreferenceVibration.this.onClick(dialog,
|
||||
DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
} else if (!itemSelected.equals("")) {
|
||||
((MeditationAssistant) ctx.getApplicationContext()).vibrateDevice(itemSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
builder.setPositiveButton(
|
||||
builder.getContext().getString(R.string.set),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ListPreferenceVibration.this.onClick(dialog,
|
||||
DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state == null || !state.getClass().equals(SavedState.class)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
SavedState myState = (SavedState) state;
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
setValue(myState.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
if (isPersistent()) {
|
||||
return superState;
|
||||
}
|
||||
final SavedState myState = new SavedState(superState);
|
||||
myState.value = getValue();
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||
mValue = restoreValue ? getPersistedString(mValue)
|
||||
: (String) defaultValue;
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
String value;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
value = source.readString();
|
||||
}
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(value);
|
||||
}
|
||||
}
|
||||
|
||||
public SharedPreferences getPrefs() {
|
||||
if (prefs == null) {
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
}
|
||||
return prefs;
|
||||
}
|
||||
}
|
|
@ -105,42 +105,34 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
return; // No interval sounds during the final 30 seconds
|
||||
}
|
||||
|
||||
String intervalSoundPath = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_interval", "");
|
||||
getMeditationAssistant().notifySession(1, false, false);
|
||||
|
||||
if (!intervalSoundPath.equals("none") || getMeditationAssistant().vibrationEnabled()) {
|
||||
if (!intervalSoundPath.equals("none")) {
|
||||
getMeditationAssistant().playSessionSound(1, false);
|
||||
}
|
||||
long interval = Math.max(
|
||||
getMeditationAssistant().timePreferenceValueToSeconds(getMeditationAssistant().getPrefs().getString("pref_session_interval", "00:00"), "00:00"), 0);
|
||||
Log.d("MeditationAssistant", "Interval is set to " + interval + " seconds");
|
||||
|
||||
getMeditationAssistant().vibrateDevice();
|
||||
if (interval > 0 && (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000) > (interval + 30) || getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false))) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, (int) interval);
|
||||
|
||||
long interval = Math.max(
|
||||
getMeditationAssistant().timePreferenceValueToSeconds(getMeditationAssistant().getPrefs().getString("pref_session_interval", "00:00"), "00:00"), 0);
|
||||
Log.d("MeditationAssistant", "Interval is set to " + interval + " seconds");
|
||||
Log.d("MeditationAssistant", "Setting INTERVAL WAKEUP alarm for "
|
||||
+ cal.getTimeInMillis() + " (Now: "
|
||||
+ System.currentTimeMillis() + ", in: " + (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000 + ")");
|
||||
|
||||
if (interval > 0 && (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000) > (interval + 30) || getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false))) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, (int) interval);
|
||||
Intent intent_interval = new Intent(
|
||||
getApplicationContext(), MainActivity.class);
|
||||
intent_interval.putExtra("wakeup", true);
|
||||
intent_interval.putExtra("wakeupinterval", true);
|
||||
intent_interval.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
intent_interval.setAction(BROADCAST_ACTION_ALARM);
|
||||
pendingintent_interval = PendingIntent.getActivity(
|
||||
getApplicationContext(), ID_INTERVAL,
|
||||
intent_interval, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
getMeditationAssistant().setAlarm(true, cal.getTimeInMillis(), pendingintent_interval);
|
||||
|
||||
Log.d("MeditationAssistant", "Setting INTERVAL WAKEUP alarm for "
|
||||
+ cal.getTimeInMillis() + " (Now: "
|
||||
+ System.currentTimeMillis() + ", in: " + (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000 + ")");
|
||||
|
||||
Intent intent_interval = new Intent(
|
||||
getApplicationContext(), MainActivity.class);
|
||||
intent_interval.putExtra("wakeup", true);
|
||||
intent_interval.putExtra("wakeupinterval", true);
|
||||
intent_interval.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
intent_interval.setAction(BROADCAST_ACTION_ALARM);
|
||||
pendingintent_interval = PendingIntent.getActivity(
|
||||
getApplicationContext(), ID_INTERVAL,
|
||||
intent_interval, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
getMeditationAssistant().setAlarm(true, cal.getTimeInMillis(), pendingintent_interval);
|
||||
|
||||
handler.postDelayed(this, interval * 1000);
|
||||
}
|
||||
handler.postDelayed(this, interval * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,19 +324,8 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
editPresetTitle.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
||||
|
||||
builder.setIcon(
|
||||
getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMeditationAssistant()
|
||||
.getMATheme(),
|
||||
new int[]{R.attr.actionIconForward}
|
||||
)
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(), new int[]{R.attr.actionIconForward}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.setPreset))
|
||||
.setView(presetLayout)
|
||||
.setPositiveButton(getString(R.string.set),
|
||||
|
@ -361,7 +342,8 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
// Do nothing
|
||||
}
|
||||
}).show();
|
||||
})
|
||||
.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -405,25 +387,13 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setIcon(
|
||||
getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMeditationAssistant()
|
||||
.getMATheme(),
|
||||
new int[]{R.attr.actionIconNotImportant}
|
||||
)
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(), new int[]{R.attr.actionIconNotImportant}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.translate))
|
||||
.setMessage(
|
||||
getString(R.string.translateMeditationAssistantText))
|
||||
.setPositiveButton(getString(R.string.yes),
|
||||
dialogClickListener)
|
||||
.setNegativeButton(getString(R.string.no),
|
||||
dialogClickListener).show();
|
||||
.setMessage(getString(R.string.translateMeditationAssistantText))
|
||||
.setPositiveButton(getString(R.string.yes), dialogClickListener)
|
||||
.setNegativeButton(getString(R.string.no), dialogClickListener)
|
||||
.show();
|
||||
}
|
||||
|
||||
showNextTutorial(false);
|
||||
|
@ -991,6 +961,14 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
// Start vibration
|
||||
if (presetSettings.contains("startvibration") && preset.has("startvibration")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_start", preset.getString("startvibration")).apply();
|
||||
if (preset.getString("startvibration").equals("custom") && preset.has("startvibrationcustom")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_start_custom", preset.getString("startvibrationcustom")).apply();
|
||||
}
|
||||
}
|
||||
|
||||
// Interval duration
|
||||
if (presetSettings.contains("intervalduration")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_session_interval", preset.getString("intervalduration")).apply();
|
||||
|
@ -1004,6 +982,14 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
// Interval vibration
|
||||
if (presetSettings.contains("intervalvibration") && preset.has("intervalvibration")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_interval", preset.getString("intervalvibration")).apply();
|
||||
if (preset.getString("intervalvibration").equals("custom") && preset.has("intervalvibrationcustom")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_interval_custom", preset.getString("intervalvibrationcustom")).apply();
|
||||
}
|
||||
}
|
||||
|
||||
// Interval count
|
||||
if (presetSettings.contains("intervalcount")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_interval_count", preset.getString("intervalcount")).apply();
|
||||
|
@ -1017,6 +1003,14 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
// Complete vibration
|
||||
if (presetSettings.contains("completevibration") && preset.has("completevibration")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_finish", preset.getString("completevibration")).apply();
|
||||
if (preset.getString("completevibration").equals("custom") && preset.has("completevibrationcustom")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_meditation_vibrate_finish_custom", preset.getString("completevibrationcustom")).apply();
|
||||
}
|
||||
}
|
||||
|
||||
// Ringtone and notifications
|
||||
if (presetSettings.contains("ringtone")) {
|
||||
getMeditationAssistant().getPrefs().edit().putString("pref_notificationcontrol", preset.getString("ringtone")).apply();
|
||||
|
@ -1032,11 +1026,6 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
getMeditationAssistant().getPrefs().edit().putBoolean("pref_softfinish", preset.getBoolean("endless")).apply();
|
||||
}
|
||||
|
||||
// Vibrate
|
||||
if (presetSettings.contains("vibrate")) {
|
||||
getMeditationAssistant().getPrefs().edit().putBoolean("pref_vibrate", preset.getBoolean("vibrate")).apply();
|
||||
}
|
||||
|
||||
successfulRestore = true;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -1105,16 +1094,21 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
preset.delay = getMeditationAssistant().getPrefs().getString("pref_session_delay", "00:15");
|
||||
preset.startsound = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_start", "");
|
||||
preset.startsoundcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_start_custom", "");
|
||||
preset.startvibration = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_start", "");
|
||||
preset.startvibrationcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_start_custom", "");
|
||||
preset.intervalduration = getMeditationAssistant().getPrefs().getString("pref_session_interval", "00:00");
|
||||
preset.intervalsound = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_interval", "");
|
||||
preset.intervalsoundcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_interval_custom", "");
|
||||
preset.intervalvibration = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_interval", "");
|
||||
preset.intervalvibrationcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_interval_custom", "");
|
||||
preset.intervalcount = getMeditationAssistant().getPrefs().getString("pref_interval_count", "");
|
||||
preset.completesound = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_finish", "");
|
||||
preset.completesoundcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_finish_custom", "");
|
||||
preset.completevibration = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_finish", "");
|
||||
preset.completevibrationcustom = getMeditationAssistant().getPrefs().getString("pref_meditation_vibrate_finish_custom", "");
|
||||
preset.ringtone = getMeditationAssistant().getPrefs().getString("pref_notificationcontrol", "");
|
||||
preset.volume = getMeditationAssistant().getPrefs().getInt("pref_sessionvolume", 50);
|
||||
preset.endless = getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false);
|
||||
preset.vibrate = getMeditationAssistant().getPrefs().getBoolean("pref_vibrate", false);
|
||||
|
||||
String exported = preset.export().toString();
|
||||
Log.d("MeditationAssistant", "Setting preset: " + exported);
|
||||
|
@ -1389,11 +1383,7 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
getMeditationAssistant().setAlarm(true, cal.getTimeInMillis(), pendingintent);
|
||||
}
|
||||
|
||||
if (!skipDelay) {
|
||||
getMeditationAssistant().vibrateDevice();
|
||||
}
|
||||
|
||||
getMeditationAssistant().playSessionSound(0, false);
|
||||
getMeditationAssistant().notifySession(0, skipDelay, false);
|
||||
|
||||
setIntervalAlarm();
|
||||
}
|
||||
|
@ -1660,25 +1650,13 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setIcon(
|
||||
getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMeditationAssistant()
|
||||
.getMATheme(),
|
||||
new int[]{R.attr.actionIconNotImportant}
|
||||
)
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(), new int[]{R.attr.actionIconNotImportant}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.rateMeditationAssistant))
|
||||
.setMessage(
|
||||
getString(R.string.rateMeditationAssistantText))
|
||||
.setPositiveButton(getString(R.string.yes),
|
||||
dialogClickListener)
|
||||
.setNegativeButton(getString(R.string.no),
|
||||
dialogClickListener).show();
|
||||
.setMessage(getString(R.string.rateMeditationAssistantText))
|
||||
.setPositiveButton(getString(R.string.yes), dialogClickListener)
|
||||
.setNegativeButton(getString(R.string.no), dialogClickListener)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1851,63 +1829,53 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
return; // No further intervals
|
||||
}
|
||||
|
||||
String intervalSoundPath = getMeditationAssistant().getPrefs().getString("pref_meditation_sound_interval", "");
|
||||
if (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| ((System.currentTimeMillis() / 1000) > getMeditationAssistant().getTimeToStopMeditate() && (System.currentTimeMillis() / 1000) - getMeditationAssistant().getTimeToStopMeditate() >= 5) || getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000) >= 5) { // Not within last 5 seconds
|
||||
getMeditationAssistant().notifySession(1, false, false);
|
||||
}
|
||||
|
||||
if (!intervalSoundPath.equals("none") || getMeditationAssistant().vibrationEnabled()) {
|
||||
if (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| ((System.currentTimeMillis() / 1000) > getMeditationAssistant().getTimeToStopMeditate() && (System.currentTimeMillis() / 1000) - getMeditationAssistant().getTimeToStopMeditate() >= 5) || getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000) >= 5) { // Not within last 5 seconds
|
||||
if (!intervalSoundPath.equals("none")) {
|
||||
getMeditationAssistant().playSessionSound(1, false);
|
||||
}
|
||||
long interval = Math.max(
|
||||
getMeditationAssistant().timePreferenceValueToSeconds(getMeditationAssistant().getPrefs().getString("pref_session_interval", "00:00"), "00:00"), 0);
|
||||
Log.d("MeditationAssistant", "Interval is set to " + interval + " seconds");
|
||||
|
||||
getMeditationAssistant().vibrateDevice();
|
||||
if (interval > 0 && (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| ((getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000)) > (interval + 30)) || getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false))) {
|
||||
intervals++;
|
||||
|
||||
if (Integer.valueOf(interval_limit) > 0 && intervals >= Integer.valueOf(interval_limit)) {
|
||||
Log.d("MeditationAssistant", "Interval - reached interval limit, not firing B");
|
||||
return; // No further intervals
|
||||
}
|
||||
|
||||
long interval = Math.max(
|
||||
getMeditationAssistant().timePreferenceValueToSeconds(getMeditationAssistant().getPrefs().getString("pref_session_interval", "00:00"), "00:00"), 0);
|
||||
Log.d("MeditationAssistant", "Interval is set to " + interval + " seconds");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, (int) interval);
|
||||
|
||||
if (interval > 0 && (getMeditationAssistant().getTimeToStopMeditate() == -1
|
||||
|| ((getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000)) > (interval + 30)) || getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false))) {
|
||||
intervals++;
|
||||
Log.d("MeditationAssistant", "Setting INTERVAL WAKEUP alarm for "
|
||||
+ cal.getTimeInMillis() + " (Now: "
|
||||
+ System.currentTimeMillis() + ", in: " + (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000 + ") - TOTAL TIME LEFT: " + (getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000)));
|
||||
|
||||
if (Integer.valueOf(interval_limit) > 0 && intervals >= Integer.valueOf(interval_limit)) {
|
||||
Log.d("MeditationAssistant", "Interval - reached interval limit, not firing B");
|
||||
return; // No further intervals
|
||||
}
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.SECOND, (int) interval);
|
||||
|
||||
Log.d("MeditationAssistant", "Setting INTERVAL WAKEUP alarm for "
|
||||
+ cal.getTimeInMillis() + " (Now: "
|
||||
+ System.currentTimeMillis() + ", in: " + (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000 + ") - TOTAL TIME LEFT: " + (getMeditationAssistant().getTimeToStopMeditate()
|
||||
- (System.currentTimeMillis() / 1000)));
|
||||
|
||||
Intent intent_interval = new Intent(
|
||||
getApplicationContext(), MainActivity.class);
|
||||
intent_interval.putExtra("wakeup", true);
|
||||
intent_interval.putExtra("wakeupinterval", true);
|
||||
intent_interval.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
intent_interval.setAction(BROADCAST_ACTION_ALARM);
|
||||
pendingintent_interval = PendingIntent.getActivity(
|
||||
getApplicationContext(), ID_INTERVAL,
|
||||
intent_interval, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
getMeditationAssistant().setAlarm(true, cal.getTimeInMillis(), pendingintent_interval);
|
||||
} else {
|
||||
Log.d("MeditationAssistant", "Skipping INTERVAL WAKEUP alarm");
|
||||
}
|
||||
Intent intent_interval = new Intent(
|
||||
getApplicationContext(), MainActivity.class);
|
||||
intent_interval.putExtra("wakeup", true);
|
||||
intent_interval.putExtra("wakeupinterval", true);
|
||||
intent_interval.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
intent_interval.setAction(BROADCAST_ACTION_ALARM);
|
||||
pendingintent_interval = PendingIntent.getActivity(
|
||||
getApplicationContext(), ID_INTERVAL,
|
||||
intent_interval, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
getMeditationAssistant().setAlarm(true, cal.getTimeInMillis(), pendingintent_interval);
|
||||
} else {
|
||||
Log.d("MeditationAssistant", "Skipping INTERVAL WAKEUP alarm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fullWakeUp) {
|
||||
if (getMeditationAssistant().getPrefs().getBoolean("pref_softfinish", false)) {
|
||||
getMeditationAssistant().playSessionSound(2, false);
|
||||
|
||||
getMeditationAssistant().vibrateDevice();
|
||||
getMeditationAssistant().notifySession(2, false, false);
|
||||
} else {
|
||||
Intent openAlarmReceiverActivity = new Intent(getApplicationContext(), CompleteActivity.class);
|
||||
openAlarmReceiverActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
@ -2162,21 +2130,16 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setIcon(
|
||||
getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(
|
||||
getMeditationAssistant().getMATheme(),
|
||||
new int[]{R.attr.actionIconSignOut})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(), new int[]{R.attr.actionIconSignOut}).getResourceId(0, 0)))
|
||||
.setTitle(
|
||||
getString(R.string.signOut))
|
||||
.setMessage(getString(R.string.signOutOfMediNETConfirmTitle))
|
||||
.setPositiveButton(getString(R.string.signOut),
|
||||
dialogClickListener)
|
||||
.setNegativeButton(getString(R.string.cancel),
|
||||
dialogClickListener).show();
|
||||
dialogClickListener)
|
||||
.show();
|
||||
}
|
||||
} else {
|
||||
askToSignIn();
|
||||
|
|
|
@ -56,6 +56,8 @@ import org.acra.annotation.AcraCore;
|
|||
import org.acra.annotation.AcraHttpSender;
|
||||
import org.acra.data.StringFormat;
|
||||
import org.acra.sender.HttpSender;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -81,6 +83,8 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@AcraCore(buildConfigClass = BuildConfig.class, reportFormat = StringFormat.KEY_VALUE_LIST)
|
||||
|
@ -94,8 +98,6 @@ public class MeditationAssistant extends Application {
|
|||
public static String ACTION_REMINDER = "sh.ftp.rocketninelabs.meditationassistant.DAILY_NOTIFICATION";
|
||||
public static String ACTION_UPDATED = "sh.ftp.rocketninelabs.meditationassistant.DAILY_NOTIFICATION_UPDATED";
|
||||
|
||||
public static int REQUEST_FIT = 22;
|
||||
|
||||
public static int CSV_COLUMN_COUNT = 5;
|
||||
|
||||
public boolean ispaused = false;
|
||||
|
@ -137,6 +139,7 @@ public class MeditationAssistant extends Application {
|
|||
private SharedPreferences prefs = null;
|
||||
private AlarmManager am;
|
||||
private WakeLocker wakeLocker = new WakeLocker();
|
||||
private Lock wakeLockerLock = new ReentrantLock();
|
||||
String pausedTimerHoursMinutes;
|
||||
String pausedTimerSeconds;
|
||||
private HashMap<String, MediaPlayer> mediaPlayers = new HashMap<String, MediaPlayer>();
|
||||
|
@ -291,16 +294,6 @@ public class MeditationAssistant extends Application {
|
|||
return string.substring(0, 1).toUpperCase() + string.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
public boolean canVibrate() {
|
||||
try {
|
||||
Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
return vi.hasVibrator();
|
||||
} catch (NoSuchMethodError e) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void restoreVolume() {
|
||||
if (previous_volume != null) {
|
||||
try {
|
||||
|
@ -650,9 +643,9 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
public void playSessionSound(int sound, boolean restoreVolume) {
|
||||
public void notifySession(int phase, boolean skipVibration, boolean restoreVolume) {
|
||||
String label;
|
||||
switch (sound) {
|
||||
switch (phase) {
|
||||
case 0:
|
||||
label = "start";
|
||||
break;
|
||||
|
@ -665,8 +658,9 @@ public class MeditationAssistant extends Application {
|
|||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = getPrefs();
|
||||
|
||||
// Play sound
|
||||
String soundPath = prefs.getString("pref_meditation_sound_" + label, "");
|
||||
if (!soundPath.equals("none")) {
|
||||
if (soundPath.equals("custom")) {
|
||||
|
@ -675,6 +669,18 @@ public class MeditationAssistant extends Application {
|
|||
playSound(MeditationSounds.getMeditationSound(soundPath), "", restoreVolume);
|
||||
}
|
||||
}
|
||||
|
||||
// Vibrate device
|
||||
if (!skipVibration) {
|
||||
String vibration = prefs.getString("pref_meditation_vibrate_" + label, "");
|
||||
if (!vibration.equals("none")) {
|
||||
if (vibration.equals("custom")) {
|
||||
vibrateDevice(prefs.getString("pref_meditation_vibrate_" + label + "_custom", ""));
|
||||
} else {
|
||||
vibrateDevice(vibration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startAuth(Context context, boolean showToast) {
|
||||
|
@ -1141,6 +1147,16 @@ public class MeditationAssistant extends Application {
|
|||
+ Build.VERSION.SDK_INT
|
||||
);
|
||||
|
||||
if (getPrefs().getBoolean("pref_vibrate", false)) {
|
||||
getPrefs()
|
||||
.edit()
|
||||
.putString("pref_meditation_vibrate_start", "medium")
|
||||
.putString("pref_meditation_vibrate_interval", "medium")
|
||||
.putString("pref_meditation_vibrate_finish", "medium")
|
||||
.putBoolean("pref_vibrate", false)
|
||||
.apply();
|
||||
}
|
||||
|
||||
getPrefs().registerOnSharedPreferenceChangeListener(sharedPrefslistener);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
@ -1289,8 +1305,7 @@ public class MeditationAssistant extends Application {
|
|||
|
||||
if (getMediNET().activity != null
|
||||
&& !getMediNET().announcement.equals("")) {
|
||||
AlertDialog announceDialog = new AlertDialog.Builder(
|
||||
getMediNET().activity)
|
||||
AlertDialog announceDialog = new AlertDialog.Builder(getMediNET().activity)
|
||||
.setPositiveButton(R.string.dismiss,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -1302,21 +1317,11 @@ public class MeditationAssistant extends Application {
|
|||
)
|
||||
.setTitle(title == null ? getString(R.string.announcement) : title)
|
||||
.setMessage(medinet.announcement)
|
||||
.setIcon(
|
||||
getMediNET().activity
|
||||
.getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setCancelable(false).create();
|
||||
.setIcon(getMediNET().activity.getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setCancelable(false)
|
||||
.create();
|
||||
|
||||
announceDialog.show();
|
||||
|
||||
return announceDialog;
|
||||
}
|
||||
|
||||
|
@ -1356,8 +1361,7 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
getPrefs().edit().putBoolean("meditationstreakwarningshown", true).apply();
|
||||
|
||||
AlertDialog streakDifferenceDialog = new AlertDialog.Builder(
|
||||
activity)
|
||||
AlertDialog streakDifferenceDialog = new AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.yes,
|
||||
(dialog, id) -> {
|
||||
setMeditationStreak(newstreak, twodays ? getStreakExpiresTwoDaysTimestamp() : getStreakExpiresOneDayTimestamp());
|
||||
|
@ -1370,12 +1374,9 @@ public class MeditationAssistant extends Application {
|
|||
)
|
||||
.setTitle(R.string.warning)
|
||||
.setMessage(String.format(getString(R.string.streakdifferencewarning), oldstreak, newstreak))
|
||||
.setIcon(activity.getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setCancelable(false).create();
|
||||
.setIcon(activity.getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setCancelable(false)
|
||||
.create();
|
||||
|
||||
streakDifferenceDialog.show();
|
||||
}
|
||||
|
@ -1616,13 +1617,7 @@ public class MeditationAssistant extends Application {
|
|||
});
|
||||
|
||||
sessionDialog = new AlertDialog.Builder(sessionDialogActivity)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{session._id == 0 ? R.attr.actionIconNew : R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{session._id == 0 ? R.attr.actionIconNew : R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setTitle(getString(session._id == 0 ? R.string.addSession : R.string.editSession))
|
||||
.setView(sessionDialogView)
|
||||
.setPositiveButton(getString(session._id == 0 ? R.string.add : R.string.edit), new DialogInterface.OnClickListener() {
|
||||
|
@ -1686,9 +1681,7 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
|
||||
AlertDialog postSessionDialog = new AlertDialog.Builder(activity)
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{R.attr.actionIconInfo})
|
||||
.getResourceId(0, 0)))
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconInfo}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.sessionPosted))
|
||||
.setMessage(getString(R.string.postUpdatedSession))
|
||||
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
||||
|
@ -1939,17 +1932,7 @@ public class MeditationAssistant extends Application {
|
|||
)
|
||||
.setTitle(R.string.downloadsessionstitle)
|
||||
.setMessage(R.string.downloadsessionsmessage)
|
||||
.setIcon(
|
||||
getMediNET().activity
|
||||
.getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMATheme(true),
|
||||
new int[]{R.attr.actionIconDownCloud})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getMediNET().activity.getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconDownCloud}).getResourceId(0, 0)))
|
||||
.create();
|
||||
|
||||
staleDataDialog.show();
|
||||
|
@ -1975,20 +1958,10 @@ public class MeditationAssistant extends Application {
|
|||
|
||||
public void askToDonate(Activity activity) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setIcon(
|
||||
getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMATheme(true),
|
||||
new int[]{R.attr.actionIconInfo}
|
||||
)
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconInfo}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.announcement))
|
||||
.setMessage(
|
||||
getString(R.string.donate156))
|
||||
.setMessage(getString(R.string.donate156))
|
||||
.setPositiveButton(getString(R.string.donate),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -2001,25 +1974,16 @@ public class MeditationAssistant extends Application {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
}
|
||||
}).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public void showImportSessionsDialog(Activity activity) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setIcon(
|
||||
getResources()
|
||||
.getDrawable(
|
||||
getTheme()
|
||||
.obtainStyledAttributes(
|
||||
getMATheme(true),
|
||||
new int[]{R.attr.actionIconForward}
|
||||
)
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
builder
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconForward}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.importsessions))
|
||||
.setMessage(
|
||||
getString(R.string.importsessions_utc_or_local))
|
||||
.setMessage(getString(R.string.importsessions_utc_or_local))
|
||||
.setPositiveButton(getString(R.string.utc),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -2033,7 +1997,8 @@ public class MeditationAssistant extends Application {
|
|||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
showFilePickerDialog(activity, SettingsActivity.FILEPICKER_IMPORT_SESSIONS_LOCAL, FilePickerActivity.MODE_FILE);
|
||||
}
|
||||
}).show();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public void importSessions(Activity activity, Uri uri, boolean useLocalTimeZone) {
|
||||
|
@ -2171,13 +2136,7 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
|
||||
AlertDialog sessionsImportedDialog = new AlertDialog.Builder(activity)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{R.attr.actionIconForward})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconForward}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.importsessions))
|
||||
.setMessage(String.format(getString(R.string.importsessions_complete), existingSessions, sessions.size()))
|
||||
.setPositiveButton(getString(R.string.wordimport), new DialogInterface.OnClickListener() {
|
||||
|
@ -2255,13 +2214,7 @@ public class MeditationAssistant extends Application {
|
|||
txtSessionsExportedPath.setText(file.getPath());
|
||||
|
||||
AlertDialog sessionsExportedDialog = new AlertDialog.Builder(activity)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getTheme().obtainStyledAttributes(getMATheme(true),
|
||||
new int[]{R.attr.actionIconSignOut})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getResources().getDrawable(getTheme().obtainStyledAttributes(getMATheme(true), new int[]{R.attr.actionIconSignOut}).getResourceId(0, 0)))
|
||||
.setTitle(getString(R.string.exportSessions))
|
||||
.setView(exp)
|
||||
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
||||
|
@ -2292,29 +2245,50 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
|
||||
public void updateWidgets() {
|
||||
AppWidgetManager man = AppWidgetManager
|
||||
.getInstance(getApplicationContext());
|
||||
/*int[] ids = man.getAppWidgetIds(new ComponentName(
|
||||
getApplicationContext(), WidgetStreakProvider.class));*/
|
||||
Intent updateIntent = new Intent();
|
||||
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
getApplicationContext().sendBroadcast(updateIntent);
|
||||
}
|
||||
|
||||
public Boolean vibrationEnabled() {
|
||||
return (getPrefs().getBoolean("pref_vibrate", false) && canVibrate());
|
||||
}
|
||||
public void vibrateDevice(String pattern) {
|
||||
ArrayList<Long> p = new ArrayList<Long>();
|
||||
if (pattern.equals("short")) {
|
||||
p.add((long) 110);
|
||||
p.add((long) 225);
|
||||
p.add((long) 110);
|
||||
} else if (pattern.equals("medium")) {
|
||||
p.add((long) 420);
|
||||
p.add((long) 375);
|
||||
p.add((long) 420);
|
||||
} else if (pattern.equals("long")) {
|
||||
p.add((long) 840);
|
||||
p.add((long) 550);
|
||||
p.add((long) 840);
|
||||
} else {
|
||||
String[] patternSplit = pattern.split(",");
|
||||
for (String pp : patternSplit) {
|
||||
pp = pp.trim();
|
||||
if (pp.isEmpty() || !StringUtils.isNumeric(pp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
public void vibrateDevice() {
|
||||
if (vibrationEnabled()) {
|
||||
try {
|
||||
Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
long[] pattern = {225, 110, 225, 110, 225, 110};
|
||||
vi.vibrate(pattern, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
long ppv = Long.parseLong(pp);
|
||||
if (ppv < 0L) {
|
||||
ppv = 0L;
|
||||
} else if (ppv > 15000L) {
|
||||
ppv = 15000L;
|
||||
}
|
||||
p.add(ppv);
|
||||
}
|
||||
}
|
||||
p.add(0, 0L);
|
||||
|
||||
try {
|
||||
Vibrator vi = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vi.vibrate(ArrayUtils.toPrimitive(p.toArray(new Long[p.size()])), -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean haveNotificationPermission() {
|
||||
|
@ -2446,21 +2420,23 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
|
||||
public String acquireWakeLock(Boolean fullWakeUp) {
|
||||
synchronized (wakeLocker) {
|
||||
return wakeLocker.acquire(getApplicationContext(), fullWakeUp);
|
||||
}
|
||||
wakeLockerLock.lock();
|
||||
String wakelockID = wakeLocker.acquire(getApplicationContext(), fullWakeUp);
|
||||
wakeLockerLock.unlock();
|
||||
|
||||
return wakelockID;
|
||||
}
|
||||
|
||||
public void releaseWakeLock(String wakeLockID) {
|
||||
synchronized (wakeLocker) {
|
||||
wakeLocker.release(wakeLockID);
|
||||
}
|
||||
wakeLockerLock.lock();
|
||||
wakeLocker.release(wakeLockID);
|
||||
wakeLockerLock.unlock();
|
||||
}
|
||||
|
||||
public void releaseAllWakeLocks() {
|
||||
synchronized (wakeLocker) {
|
||||
wakeLocker.releaseAll();
|
||||
}
|
||||
wakeLockerLock.lock();
|
||||
wakeLocker.releaseAll();
|
||||
wakeLockerLock.unlock();
|
||||
}
|
||||
|
||||
public enum TrackerName {
|
||||
|
|
|
@ -9,12 +9,18 @@ public class Preset {
|
|||
public String delay = "";
|
||||
public String startsound = "";
|
||||
public String startsoundcustom = "";
|
||||
public String startvibration = "";
|
||||
public String startvibrationcustom = "";
|
||||
public String intervalduration = "";
|
||||
public String intervalsound = "";
|
||||
public String intervalsoundcustom = "";
|
||||
public String intervalvibration = "";
|
||||
public String intervalvibrationcustom = "";
|
||||
public String intervalcount = "";
|
||||
public String completesound = "";
|
||||
public String completesoundcustom = "";
|
||||
public String completevibration = "";
|
||||
public String completevibrationcustom = "";
|
||||
public String ringtone = "";
|
||||
public Integer volume = 50;
|
||||
public Boolean endless = false;
|
||||
|
@ -28,12 +34,18 @@ public class Preset {
|
|||
jobj.put("delay", delay);
|
||||
jobj.put("startsound", startsound);
|
||||
jobj.put("startsoundcustom", startsoundcustom);
|
||||
jobj.put("startvibration", startvibration);
|
||||
jobj.put("startvibrationcustom", startvibrationcustom);
|
||||
jobj.put("intervalduration", intervalduration);
|
||||
jobj.put("intervalsound", intervalsound);
|
||||
jobj.put("intervalsoundcustom", intervalsoundcustom);
|
||||
jobj.put("intervalvibration", intervalvibration);
|
||||
jobj.put("intervalvibrationcustom", intervalvibrationcustom);
|
||||
jobj.put("intervalcount", intervalcount);
|
||||
jobj.put("completesound", completesound);
|
||||
jobj.put("completesoundcustom", completesoundcustom);
|
||||
jobj.put("completevibration", completevibration);
|
||||
jobj.put("completevibrationcustom", completevibrationcustom);
|
||||
jobj.put("ringtone", ringtone);
|
||||
jobj.put("volume", volume);
|
||||
jobj.put("endless", endless);
|
||||
|
|
|
@ -134,13 +134,7 @@ public class ProgressActivity extends FragmentActivity {
|
|||
}
|
||||
|
||||
sessionDetailsDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getResources().getDrawable(getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setTitle(sdf.format(sess_date))
|
||||
.setAdapter(sessionsDialogAdapter,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
@ -206,13 +200,7 @@ public class ProgressActivity extends FragmentActivity {
|
|||
}
|
||||
|
||||
sessionDetailsDialog = new AlertDialog.Builder(this)
|
||||
.setIcon(
|
||||
getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getResources().getDrawable(getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setTitle(session_title)
|
||||
.setView(detailsView)
|
||||
.create();
|
||||
|
|
|
@ -59,13 +59,7 @@ public class SessionsFragment extends ListFragment {
|
|||
|
||||
selected_session = (SessionSQL) getListView().getItemAtPosition(position);
|
||||
sessionDialog = new AlertDialog.Builder(getActivity())
|
||||
.setIcon(
|
||||
getActivity().getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
.setIcon(getActivity().getResources().getDrawable(getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setTitle(session_title)
|
||||
.setItems(R.array.session_actions,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
@ -94,15 +88,8 @@ public class SessionsFragment extends ListFragment {
|
|||
getMeditationAssistant().getMediNET().postSession(0, null, null);
|
||||
}
|
||||
} else { // Delete
|
||||
AlertDialog deleteDialog = new AlertDialog.Builder(
|
||||
getActivity())
|
||||
.setIcon(
|
||||
getActivity().getResources().getDrawable(
|
||||
getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true),
|
||||
new int[]{R.attr.actionIconGoToToday})
|
||||
.getResourceId(0, 0)
|
||||
)
|
||||
)
|
||||
AlertDialog deleteDialog = new AlertDialog.Builder(getActivity())
|
||||
.setIcon(getActivity().getResources().getDrawable(getMeditationAssistant().getTheme().obtainStyledAttributes(getMeditationAssistant().getMATheme(true), new int[]{R.attr.actionIconGoToToday}).getResourceId(0, 0)))
|
||||
.setTitle(session_title)
|
||||
.setItems(
|
||||
R.array.session_delete_actions,
|
||||
|
@ -137,15 +124,16 @@ public class SessionsFragment extends ListFragment {
|
|||
}
|
||||
}
|
||||
}
|
||||
).create();
|
||||
)
|
||||
.create();
|
||||
deleteDialog.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
).create();
|
||||
)
|
||||
.create();
|
||||
|
||||
sessionDialog.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|