Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
LaunchActivity: Fix
Browse files Browse the repository at this point in the history
Signed-off-by: fython <fython@163.com>
  • Loading branch information
fython committed Feb 3, 2016
1 parent dc025ee commit fd4fceb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</intent-filter>
</activity>

<service android:name=".services.MaskService" android:process=":standalone"/>
<service android:name=".services.MaskService"/>
<receiver android:name=".receiver.TileReceiver">
<intent-filter>
<action android:name="info.papdt.blackbulb.ACTION_UPDATE_STATUS"/>
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/info/papdt/blackblub/services/MaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
Expand Down Expand Up @@ -59,14 +60,14 @@ public void onCreate() {
@Override
public void onDestroy() {
super.onDestroy();
mSettings.putBoolean(Settings.KEY_ALIVE, false);
try {
Utility.createStatusBarTiles(this, false);
} catch (Exception e) {

}
cancelNotification();
if (mLayout != null) {
mSettings.putBoolean(Settings.KEY_ALIVE, false);
mLayout.animate()
.alpha(0f)
.setDuration(ANIMATE_DURATION_MILES)
Expand Down Expand Up @@ -243,7 +244,22 @@ public int onStartCommand(Intent intent, int flags, int arg) {

@Override
public IBinder onBind(Intent intent) {
return null;
return mBinder;
}

@Override
public boolean onUnbind(Intent intent) {
return super.onUnbind(intent);
}

private MaskBinder mBinder = new MaskBinder();

public class MaskBinder extends Binder {

public boolean isMaskShowing() {
return mLayout.getAlpha() != 0f;
}

}

}
46 changes: 31 additions & 15 deletions app/src/main/java/info/papdt/blackblub/ui/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -48,9 +51,6 @@ public class LaunchActivity extends Activity implements PopupMenu.OnMenuItemClic
protected void onCreate(Bundle savedInstanceState) {
mSettings = Settings.getInstance(getApplicationContext());

// A foolish method to check if it was enabled. Sometimes it may get a wrong result.
isRunning = mSettings.getBoolean(Settings.KEY_ALIVE, false);

// Don't worry too much. Min SDK is 21.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);
Expand All @@ -60,26 +60,42 @@ protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_Dark);
}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);

// A foolish method to check if it was enabled. Sometimes it may get a wrong result.
ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
isRunning = ((MaskService.MaskBinder) iBinder).isMaskShowing();
if (isRunning) {
// If I don't use postDelayed, Switch may cause a NPE because its animator wasn't initialized.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSwitch.toggle();
}
}, 200);
}
}

@Override
public void onServiceDisconnected(ComponentName componentName) {

}
};
Intent i = new Intent();
i.setClass(this, MaskService.class);
bindService(i, mConnection, BIND_AUTO_CREATE);

// Publish CM Tiles
try {
Utility.createStatusBarTiles(this, isRunning);
} catch (Exception e) {

}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);

mSwitch = (MaterialAnimatedSwitch) findViewById(R.id.toggle);
if (isRunning) {
// If I don't use postDelayed, Switch will cause a NPE because its animator wasn't initialized.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSwitch.toggle();
}
}, 200);
}
mSwitch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(boolean b) {
Expand Down

0 comments on commit fd4fceb

Please sign in to comment.