Skip to content

Commit

Permalink
Merge pull request #10 from DevLuuk/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DevLuuk committed Jan 2, 2019
2 parents 81df2d9 + a605747 commit 9f240e8
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 49 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "nl.devluuk.sleepywifi"
minSdkVersion 23
targetSdkVersion 27
versionCode 3
versionName '1.2'
versionCode 4
versionName '1.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
32 changes: 22 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.devluuk.sleepywifi">

<!--<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />-->
<!-- <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Expand All @@ -13,12 +13,12 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">

android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -28,16 +28,28 @@

<service android:name=".BackgroundService" />

<receiver android:name=".OnStart" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<receiver
android:name=".OnStart"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />

<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver android:name=".ScreenReceiver" />

<activity
android:name=".AboutActivity"
android:label="@string/action_about"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
</application>

</manifest>
45 changes: 45 additions & 0 deletions app/src/main/java/nl/devluuk/sleepywifi/AboutActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package nl.devluuk.sleepywifi;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;

public class AboutActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
ActionBar actionBar = this.getActionBar();
if (actionBar != null){
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

/**
* This hook is called whenever an item in your options menu is selected.
* The default implementation simply returns false to have the normal
* processing happen (calling the item's Runnable or sending a message to
* its Handler as appropriate). You can use this method for any items
* for which you would like to do processing without those other
* facilities.
*
* <p>Derived classes should call through to the base class for it to
* perform the default menu handling.</p>
*
* @param item The menu item that was selected.
* @return boolean Return false to allow normal menu processing to
* proceed, true to consume it here.
* @see #onCreateOptionsMenu
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.home){
NavUtils.navigateUpFromSameTask(this);
}
return super.onOptionsItemSelected(item);
}
}
35 changes: 27 additions & 8 deletions app/src/main/java/nl/devluuk/sleepywifi/BackgroundService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import java.net.URL;
import java.util.concurrent.TimeUnit;

public class BackgroundService extends Service {
Expand Down Expand Up @@ -49,17 +51,33 @@ public void onCreate() {
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(this.screenReciever, filter);
try {
TimeUnit.SECONDS.sleep(10);
stopForeground(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
new DismissNotification().execute();
// remove start notification
stopForeground(false);
//NotificationManager.cancel(1);
//stopForeground(false);
}

private class DismissNotification extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
try {
TimeUnit.SECONDS.sleep(5);
//Thread.sleep(5000);
stopForeground(true);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}

protected void onProgressUpdate(Void... progress) {

}

protected void onPostExecute(Void result) {

}
}


@Override
public void onDestroy() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Expand All @@ -77,6 +95,7 @@ public void onDestroy() {
super.onDestroy();
}


@Override
public IBinder onBind(Intent intent) {
return null;
Expand Down
46 changes: 25 additions & 21 deletions app/src/main/java/nl/devluuk/sleepywifi/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
Expand Down Expand Up @@ -45,7 +48,6 @@ public void onClick(View v) {
playOrPauseService(imageButton);
}
});

}

@Override
Expand All @@ -62,6 +64,25 @@ protected void onResume() {
// .unregisterOnSharedPreferenceChangeListener(this);
// }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int menuItemSelected = item.getItemId();
if (menuItemSelected == R.id.action_about) {
Intent aboutActivity = new Intent(this, AboutActivity.class);
startActivity(aboutActivity);
return true;
}
return super.onOptionsItemSelected(item);
}

public void playOrPauseService(ImageView image) {
final TextView stateText = findViewById(R.id.OnOffText);
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -143,30 +164,13 @@ public void setPreference(boolean status) {

private void setStateText(TextView stateText) {
if (checkPrefStatus()) {
state = "ON";
state = getResources().getString(R.string.on);
} else {
state = "OFF";
state = getResources().getString(R.string.off);
}
stateText.setText("The app service is: " + state);
stateText.setText(getResources().getString(R.string.app_state) + " " + state);
}

// private void setStateText(TextView stateText) {
// if (checkPrefStatus()) {
// state = "OFF";
// } else {
// state = "ON";
// }
// stateText.setText("Current state is: " + state);
// }

private void setStateInToast() {
if (checkPrefStatus()) {
Toast.makeText(this, "Value is true", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Value is false", Toast.LENGTH_SHORT).show();
}

}

private Drawable makeGrayIcon(Drawable icon, int colorID) {
ColorMatrix matrix = new ColorMatrix();
Expand Down
74 changes: 74 additions & 0 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AboutActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="145dp"
android:layout_height="145dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="71dp"
android:contentDescription="@string/image_description"
android:src="@drawable/ic_launcher_round" />

<TextView
android:id="@+id/about_info"
android:layout_width="320dp"
android:layout_height="79dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="46dp"
android:layout_marginBottom="285dp"
android:fontFamily="sans-serif-condensed"
android:text="@string/about_infoT"
android:textAlignment="center"
android:textSize="18sp"
android:typeface="normal" />

<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="240dp"
android:text="@string/about_author"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textSize="30sp" />

<TextView
android:id="@+id/author_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="220dp"
android:text="@string/about_authorT"
android:textSize="16sp" />

<TextView
android:id="@+id/license"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="160dp"
android:text="@string/about_license"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textSize="30sp" />

<TextView
android:id="@+id/license_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="140dp"
android:text="@string/about_licenseT"
android:textSize="16sp" />
</RelativeLayout>
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

<ImageView
android:id="@+id/powerButton"
android:layout_width="128dp"
android:layout_height="147dp"
android:layout_centerInParent="true"
android:layout_width="146dp"
android:layout_height="164dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="211dp"
android:contentDescription="@string/image_description"
android:src="@drawable/ic_launcher_round" />
</RelativeLayout>
14 changes: 14 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--<item-->
<!--android:orderInCategory="1"-->
<!--android:id="@+id/action_settings"-->
<!--android:title="@string/settings"-->
<!--app:showAsAction="never" />-->
<item
android:orderInCategory="2"
android:id="@+id/action_about"
android:title="@string/about"
app:showAsAction="never"/>
</menu>
17 changes: 17 additions & 0 deletions app/src/main/res/values-nl-rNL/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">SleepyWifi</string>
<string name="on">Aan</string>
<string name="off">Uit</string>
<string name="about">Over</string>
<string name="action_about">Over SleepyWifi</string>
<string name="settings">Instellingen</string>
<string name="action_settings">SleepyWifi Instellingen</string>
<string name="about_info">SleepyWifi Informatie</string>
<string name="about_license">Licensie</string>
<string name="about_author">Auteur</string>
<string name="about_licenseT">SleepyWifi heeft de GPL-3.0 of later licensie</string>
<string name="about_authorT">SleepyWifi is ontwikkeld door Devluuk</string>
<string name="about_infoT">Deze Android app brengt de optie \'Zet Wifi uit als de telefoon in slaapstand is\' terug voor android 8.1 of nieuwer.</string>
<string name="app_state">"De app service staat: "</string>
</resources>
Loading

0 comments on commit 9f240e8

Please sign in to comment.