Skip to content

Commit

Permalink
Wear: wakelock cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Jan 3, 2017
1 parent 80f27a2 commit 4e7ecfa
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 255 deletions.
119 changes: 60 additions & 59 deletions wear/src/main/java/com/eveningoutpost/dexdrip/CircleWatchface.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.WindowManager;
import android.widget.TextView;

import com.eveningoutpost.dexdrip.Models.JoH;
import com.google.android.gms.wearable.DataMap;
import com.ustwo.clockwise.wearable.WatchFace;
import com.ustwo.clockwise.common.WatchFaceTime;
Expand Down Expand Up @@ -88,33 +89,35 @@ public void onCreate() {
super.onCreate();

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CreateWakelock");
wakeLock.acquire(50);//KS 30000
final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CreateWakelock");
wakeLock.acquire(30000);
try {

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
display.getSize(displaySize);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
display.getSize(displaySize);

specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
View.MeasureSpec.EXACTLY);
specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
View.MeasureSpec.EXACTLY);
specW = View.MeasureSpec.makeMeasureSpec(displaySize.x,
View.MeasureSpec.EXACTLY);
specH = View.MeasureSpec.makeMeasureSpec(displaySize.y,
View.MeasureSpec.EXACTLY);

sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
sharedPrefs.registerOnSharedPreferenceChangeListener(this);

//register Message Receiver
LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(Intent.ACTION_SEND));
//register Message Receiver
LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(Intent.ACTION_SEND));

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myLayout = inflater.inflate(R.layout.modern_layout, null);
prepareLayout();
prepareDrawTime();

ListenerService.requestData(this); //usually connection is not set up yet //KS uncomment
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myLayout = inflater.inflate(R.layout.modern_layout, null);
prepareLayout();
prepareDrawTime();

wakeLock.release();
ListenerService.requestData(this); //usually connection is not set up yet //KS uncomment
} finally {
wakeLock.release();
}
}


Expand Down Expand Up @@ -538,46 +541,44 @@ public void run() {
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire(50);//KS 30000

Bundle bundle = intent.getBundleExtra("data");
if (bundle!= null) {
DataMap dataMap = DataMap.fromBundle(bundle);
setSgvLevel((int) dataMap.getLong("sgvLevel"));
Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
setSgvString(dataMap.getString("sgvString"));
Log.d("CircleWatchface", "sgv string : " + getSgvString());
setRawString(dataMap.getString("rawString"));
setDelta(dataMap.getString("delta"));
setDatetime(dataMap.getDouble("timestamp"));
addToWatchSet(dataMap);


//start animation?
// dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
startAnimation();
}
final PowerManager.WakeLock wl = JoH.getWakeLock("circle-message-receiver", 60000);
try {
Bundle bundle = intent.getBundleExtra("data");
if (bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
setSgvLevel((int) dataMap.getLong("sgvLevel"));
Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
setSgvString(dataMap.getString("sgvString"));
Log.d("CircleWatchface", "sgv string : " + getSgvString());
setRawString(dataMap.getString("rawString"));
setDelta(dataMap.getString("delta"));
setDatetime(dataMap.getDouble("timestamp"));
addToWatchSet(dataMap);


//start animation?
// dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
startAnimation();
}

prepareLayout();
prepareDrawTime();
invalidate();
}
//status
bundle = intent.getBundleExtra("status");
if (bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
wakeLock.acquire(50);
setStatusString(dataMap.getString("externalStatusString"));

prepareLayout();
prepareDrawTime();
invalidate();
prepareLayout();
prepareDrawTime();
invalidate();
}
//status
bundle = intent.getBundleExtra("status");
if (bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
setStatusString(dataMap.getString("externalStatusString"));

prepareLayout();
prepareDrawTime();
invalidate();
}
} finally {
JoH.releaseWakeLock(wl);
}
wakeLock.release();
}
}

Expand Down
Loading

0 comments on commit 4e7ecfa

Please sign in to comment.