parent
9879d48713
commit
c6aece095c
|
@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
|
|||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
buildToolsVersion '28.0.2'
|
||||
buildToolsVersion '28.0.3'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
@ -16,10 +15,9 @@ import android.widget.EditText;
|
|||
import android.widget.TextView;
|
||||
|
||||
public class CompleteActivity extends Activity {
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private MeditationAssistant ma;
|
||||
private Handler handler = new Handler();
|
||||
private Runnable runnable = new Runnable() {
|
||||
private Runnable completeRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.removeCallbacks(this);
|
||||
|
@ -44,13 +42,6 @@ public class CompleteActivity extends Activity {
|
|||
}
|
||||
}
|
||||
};
|
||||
private Runnable clearWakeLock = new Runnable() {
|
||||
public void run() {
|
||||
handler.removeCallbacks(clearWakeLock);
|
||||
|
||||
WakeLocker.release();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -259,20 +250,7 @@ public class CompleteActivity extends Activity {
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
getMeditationAssistant().utility_ads.destroyAd(this);
|
||||
if (mMediaPlayer != null) {
|
||||
try {
|
||||
mMediaPlayer.release();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
WakeLocker.release();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
handler.removeCallbacks(runnable);
|
||||
handler.removeCallbacks(completeRunnable);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -312,8 +290,8 @@ public class CompleteActivity extends Activity {
|
|||
getMeditationAssistant().getMediNET().session.message = getSessionMessage();
|
||||
getMeditationAssistant().getMediNET().postSession();
|
||||
|
||||
handler.removeCallbacks(runnable);
|
||||
handler.postDelayed(runnable, 5);
|
||||
handler.removeCallbacks(completeRunnable);
|
||||
handler.postDelayed(completeRunnable, 5);
|
||||
}
|
||||
|
||||
private void saveLastMessage() {
|
||||
|
|
|
@ -169,10 +169,12 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
private Runnable clearWakeLock = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
WakeLocker.release();
|
||||
getMeditationAssistant().releaseWakeLock(wakeLockID);
|
||||
wakeLockID = null;
|
||||
}
|
||||
};
|
||||
private Boolean finishedTutorial = null;
|
||||
private String wakeLockID;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -1563,6 +1565,7 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
Log.d("MeditationAssistant", "Cancelled interval alarm");
|
||||
}
|
||||
|
||||
getMeditationAssistant().releaseAllWakeLocks();
|
||||
getMeditationAssistant().restoreVolume();
|
||||
|
||||
if (getMeditationAssistant().getTimeStartMeditate() != 0) {
|
||||
|
@ -1773,7 +1776,6 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
public void updateTexts() {
|
||||
String pref_full_screen = getMeditationAssistant().getPrefs().getString("pref_full_screen", "");
|
||||
|
||||
/* Log.d("MeditationAssistant", "Updating texts..."); */
|
||||
TextView txtMainStatus = (TextView) findViewById(R.id.txtMainStatus);
|
||||
Button btnMeditationStreak = (Button) findViewById(R.id.btnMeditationStreak);
|
||||
Resources res = getResources();
|
||||
|
@ -1814,19 +1816,16 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
}
|
||||
|
||||
if (getMeditationAssistant().getMediNET().status != null) {
|
||||
Log.d("MeditationAssistant", "Updating texts with status "
|
||||
+ getMeditationAssistant().getMediNET().status);
|
||||
if (getMeditationAssistant().getMediNET().status
|
||||
.equals("connecting")) {
|
||||
txtMainStatus.setText(getString(R.string.mediNETConnecting));
|
||||
} else if (getMeditationAssistant().getMediNET().status
|
||||
.equals("success")) {
|
||||
txtMainStatus.setText(getString(R.string.mediNETConnected));
|
||||
} else if (getMeditationAssistant().getMediNET().status
|
||||
.equals("connectingasf")) {
|
||||
txtMainStatus.setText(getString(R.string.mediNETConnecting));
|
||||
} else {
|
||||
txtMainStatus.setText("");
|
||||
switch (getMeditationAssistant().getMediNET().status) {
|
||||
case "connecting":
|
||||
txtMainStatus.setText(getString(R.string.mediNETConnecting));
|
||||
break;
|
||||
case "success":
|
||||
txtMainStatus.setText(getString(R.string.mediNETConnected));
|
||||
break;
|
||||
default:
|
||||
txtMainStatus.setText("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1866,7 +1865,10 @@ public class MainActivity extends Activity implements OnShowcaseEventListener {
|
|||
Boolean wakeUpInterval = intent.getBooleanExtra("wakeupinterval", false);
|
||||
Log.d("MeditationAssistant", "ALARM RECEIVER INTEGRATED: Received broadcast - Full: " + (fullWakeUp ? "Full" : "Partial") + " - Start/interval: " + (wakeUpStart ? "Start" : (wakeUpInterval ? "Interval" : "Neither")));
|
||||
|
||||
WakeLocker.acquire(getApplicationContext(), fullWakeUp);
|
||||
if (wakeLockID != null) {
|
||||
getMeditationAssistant().releaseWakeLock(wakeLockID);
|
||||
}
|
||||
wakeLockID = getMeditationAssistant().acquireWakeLock(fullWakeUp);
|
||||
|
||||
handler.removeCallbacks(clearWakeLock);
|
||||
handler.postDelayed(clearWakeLock, 7000);
|
||||
|
|
|
@ -117,6 +117,7 @@ public class MeditationAssistant extends Application {
|
|||
private Activity signin_activity = null;
|
||||
private Bundle signin_options = new Bundle();
|
||||
private SharedPreferences prefs = null;
|
||||
private WakeLocker wakeLocker = new WakeLocker();
|
||||
|
||||
public static void setAlphaCompat(View view, float alpha) {
|
||||
view.setAlpha(alpha);
|
||||
|
@ -381,7 +382,7 @@ public class MeditationAssistant extends Application {
|
|||
}
|
||||
|
||||
public void playSound(int soundresource, String soundpath, boolean restoreVolume) {
|
||||
WakeLocker.acquire(getApplicationContext(), false);
|
||||
String wakeLockID = acquireWakeLock(false);
|
||||
|
||||
MediaPlayer soundPlayer = null;
|
||||
try {
|
||||
|
@ -405,7 +406,7 @@ public class MeditationAssistant extends Application {
|
|||
restoreVolume();
|
||||
}
|
||||
|
||||
WakeLocker.release();
|
||||
releaseWakeLock(wakeLockID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -414,7 +415,7 @@ public class MeditationAssistant extends Application {
|
|||
restoreVolume();
|
||||
}
|
||||
mp.release();
|
||||
WakeLocker.release();
|
||||
releaseWakeLock(wakeLockID);
|
||||
});
|
||||
soundPlayer.setOnPreparedListener(mp -> {
|
||||
SystemClock.sleep(MeditationAssistant.MEDIA_DELAY);
|
||||
|
@ -1316,6 +1317,18 @@ public class MeditationAssistant extends Application {
|
|||
return BuildConfig.VERSION_CODE;
|
||||
}
|
||||
|
||||
public String acquireWakeLock(Boolean fullWakeUp) {
|
||||
return wakeLocker.acquire(getApplicationContext(), fullWakeUp);
|
||||
}
|
||||
|
||||
public void releaseWakeLock(String wakeLockID) {
|
||||
wakeLocker.release(wakeLockID);
|
||||
}
|
||||
|
||||
public void releaseAllWakeLocks() {
|
||||
wakeLocker.releaseAll();
|
||||
}
|
||||
|
||||
public enum TrackerName {
|
||||
APP_TRACKER, // Tracker used only in this app.
|
||||
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
|
||||
|
|
|
@ -1,36 +1,68 @@
|
|||
package sh.ftp.rocketninelabs.meditationassistant;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
public abstract class WakeLocker {
|
||||
private static PowerManager.WakeLock wakeLock;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public static void acquire(Context ctx, Boolean turnScreenOn) {
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Acquiring wakelock");
|
||||
if (wakeLock != null) {
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Releasing old wakelock first...");
|
||||
wakeLock.release();
|
||||
class WakeLocker {
|
||||
private List<String> wakeLocks = new CopyOnWriteArrayList<String>();
|
||||
|
||||
private PowerManager.WakeLock wakeLockScreenOff;
|
||||
private PowerManager.WakeLock wakeLockScreenOn;
|
||||
|
||||
@SuppressLint({"WakelockTimeout"})
|
||||
String acquire(Context ctx, Boolean turnScreenOn) {
|
||||
String wakeLockID = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Acquiring wakelock " + wakeLockID);
|
||||
wakeLocks.add(wakeLockID);
|
||||
|
||||
if (wakeLockScreenOff == null || wakeLockScreenOn == null) {
|
||||
PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
|
||||
if (wakeLockScreenOff == null) {
|
||||
wakeLockScreenOff = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "meditationassistant:screenoff");
|
||||
}
|
||||
if (wakeLockScreenOn == null) {
|
||||
wakeLockScreenOn = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "meditationassistant:screenon");
|
||||
}
|
||||
}
|
||||
|
||||
PowerManager pm = (PowerManager) ctx
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
if (turnScreenOn) {
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK |
|
||||
PowerManager.ON_AFTER_RELEASE, "MeditationAssistant");
|
||||
if (!turnScreenOn) {
|
||||
if (!wakeLockScreenOff.isHeld()) {
|
||||
wakeLockScreenOff.acquire();
|
||||
}
|
||||
} else {
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MeditationAssistant");
|
||||
if (!wakeLockScreenOn.isHeld()) {
|
||||
wakeLockScreenOn.acquire();
|
||||
}
|
||||
}
|
||||
wakeLock.acquire();
|
||||
|
||||
return wakeLockID;
|
||||
}
|
||||
|
||||
public static void release() {
|
||||
if (wakeLock != null) {
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Releasing wakelock");
|
||||
wakeLock.release();
|
||||
void release(String wakeLockID) {
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Releasing wakelock " + wakeLockID);
|
||||
wakeLocks.remove(wakeLockID);
|
||||
|
||||
if (wakeLocks.isEmpty()) {
|
||||
if (wakeLockScreenOff != null && wakeLockScreenOff.isHeld()) {
|
||||
wakeLockScreenOff.release();
|
||||
}
|
||||
if (wakeLockScreenOn != null && wakeLockScreenOn.isHeld()) {
|
||||
wakeLockScreenOn.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void releaseAll() {
|
||||
Log.d("MeditationAssistant", "WAKELOCKER: Releasing all wakelocks");
|
||||
|
||||
for (String wakeLockID : wakeLocks) {
|
||||
release(wakeLockID);
|
||||
}
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
29
TODO
29
TODO
|
@ -1,29 +0,0 @@
|
|||
https://developer.android.com/about/versions/android-5.1.html
|
||||
|
||||
Migrate to URLConnection, check if apache is being used
|
||||
|
||||
Figure out better way to show alertdialogs, they seem to be the cause of the rare badwindowtoken exceptions
|
||||
|
||||
Daily goal, colored box on progress window when met
|
||||
|
||||
Week total, comapred to last week in stats
|
||||
|
||||
Add better sounds, ask users to submit their sounds
|
||||
|
||||
Export sessions to standard format
|
||||
|
||||
Finish writing Android Wear app
|
||||
|
||||
Migrate all icons to vectors
|
||||
|
||||
Merge 2x1 and 3x1 widgets into a single size-aware widget
|
||||
|
||||
Automatic session upload
|
||||
|
||||
Add warning for all MedINET connections <= version 5, as version 6 is used by all still-supported (Android 4.1+) devices
|
||||
|
||||
Allow OpenID signin using AppAuth
|
||||
|
||||
Update remaining logo icons to new logo, including notification icon, check on new material guides for new format
|
||||
|
||||
Set new default theme to use blue that matches logo, offer old theme still as "Holographic Dark"
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Mon Jul 30 17:00:02 PDT 2018
|
||||
#Fri Oct 19 00:43:02 PDT 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
|
|
Loading…
Reference in New Issue