-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the app will now show if the background service is on or off
- Loading branch information
Showing
10 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,101 @@ | ||
package nl.devluuk.sleepywifi; | ||
|
||
import android.app.Activity; | ||
import android.app.ActivityManager; | ||
import android.app.Service; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Color; | ||
import android.graphics.ColorMatrix; | ||
import android.graphics.ColorMatrixColorFilter; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.drawable.Drawable; | ||
import android.net.wifi.WifiManager; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
|
||
public class MainActivity extends Activity { | ||
|
||
private static final String TAG = MainActivity.class.getSimpleName(); | ||
public int state; | ||
public String status; | ||
public String state; | ||
public Boolean status; | ||
public Drawable playIcon; | ||
public Drawable grayIcon; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
|
||
final TextView stateText = findViewById(R.id.OnOffText); | ||
Button startButton = (Button) findViewById(R.id.OnOffButton); | ||
|
||
startButton.setOnClickListener(new View.OnClickListener() { | ||
final ImageView imageButton = findViewById(R.id.powerButton); | ||
getStatus(); | ||
imageButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
stateText.setText(state); | ||
playOrPauseService(imageButton); | ||
} | ||
}); | ||
|
||
startService(new Intent(this, BackgroundService.class)); | ||
|
||
} | ||
|
||
public void playOrPauseService(ImageView image) { | ||
final TextView stateText = findViewById(R.id.OnOffText); | ||
if (getStatus()) { | ||
stopService(new Intent(this, BackgroundService.class)); | ||
|
||
grayIcon = getResources().getDrawable(R.drawable.ic_launcher_round_gray, null); | ||
makeGrayIcon(grayIcon); | ||
image.setImageDrawable(grayIcon); | ||
|
||
stateText.setText("Current state is: " + setState()); | ||
} else { | ||
startService(new Intent(this, BackgroundService.class)); | ||
|
||
playIcon = getResources().getDrawable(R.drawable.ic_launcher_round, null); | ||
|
||
image.setImageDrawable(playIcon); | ||
|
||
stateText.setText("Current state is: " + setState()); | ||
} | ||
} | ||
|
||
private boolean isMyServiceRunning(Class<?> serviceClass) { | ||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); | ||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { | ||
if (serviceClass.getName().equals(service.service.getClassName())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private Drawable makeGrayIcon(Drawable icon){ | ||
ColorMatrix matrix = new ColorMatrix(); | ||
matrix.setSaturation(0); | ||
|
||
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); | ||
icon.setColorFilter(filter); | ||
return icon; | ||
} | ||
|
||
private boolean getStatus() { | ||
status = isMyServiceRunning(BackgroundService.class); | ||
return status; | ||
} | ||
|
||
private String setState() { | ||
if (status) { | ||
state = "OFF"; | ||
} else { | ||
state = "ON"; | ||
} | ||
return state; | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- drawable/power.xml --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M16.56,5.44L15.11,6.89C16.84,7.94 18,9.83 18,12A6,6 0 0,1 12,18A6,6 0 0,1 6,12C6,9.83 7.16,7.94 8.88,6.88L7.44,5.44C5.36,6.88 4,9.28 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,12C20,9.28 18.64,6.88 16.56,5.44M13,3H11V13H13" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- drawable/power-standby.xml --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:width="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path android:fillColor="#000" android:pathData="M13,3H11V13H13V3M17.83,5.17L16.41,6.59C18.05,7.91 19,9.9 19,12A7,7 0 0,1 12,19C8.14,19 5,15.88 5,12C5,9.91 5.95,7.91 7.58,6.58L6.17,5.17C2.38,8.39 1.92,14.07 5.14,17.86C8.36,21.64 14.04,22.1 17.83,18.88C19.85,17.17 21,14.65 21,12C21,9.37 19.84,6.87 17.83,5.17Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
<color name="colorPrimary">#125688</color> | ||
<color name="colorPrimaryDark">#125688</color> | ||
<color name="textColorPrimary">#FFFFFF</color> | ||
<color name="windowBackground">#FFFFFF</color> | ||
<color name="navigationBarColor">#000000</color> | ||
<color name="colorAccent">#c8e8ff</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
<dimen name="tab_max_width">264dp</dimen> | ||
<dimen name="tab_padding_bottom">16dp</dimen> | ||
<dimen name="tab_label">16dp</dimen> | ||
<dimen name="nav_header_vertical_spacing">8dp</dimen> | ||
<dimen name="nav_header_height">176dp</dimen> | ||
<dimen name="fab_margin">16dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<resources> | ||
<string name="app_name">SleepyWifi</string> | ||
<string name="title_activity_settings">Settings</string> | ||
<string name="on">On</string> | ||
<string name="off">Off</string> | ||
</resources> |