Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.

Commit

Permalink
added preference activity for customization - version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DVDAndroid committed Feb 19, 2015
1 parent 40437c8 commit c9eebf2
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Enable Ambient Display - Xposed

Easy Xposed module for Lollipop which add Ambient Display

<img src="https://github.com/DVDAndroid/Xposed-EnableAmbientDisplay/blob/master/screenshots/settings.png" width="720" height="1280" />

<img src="https://github.com/DVDAndroid/Xposed-EnableAmbientDisplay/blob/master/screenshots/ambient-display.png" width="720" height="1280" />
<img src="https://github.com/DVDAndroid/Xposed-EnableAmbientDisplay/blob/master/screenshots/settings.png"/>
<img src="https://github.com/DVDAndroid/Xposed-EnableAmbientDisplay/blob/master/screenshots/main_activity.png"/>
<img src="https://github.com/DVDAndroid/Xposed-EnableAmbientDisplay/blob/master/screenshots/ambient-display.png"/>


Credits
Expand All @@ -16,4 +16,4 @@ Credits
LICENSE
-------

[MIT License](http://opensource.org/licenses/MIT)
[MIT License](http://opensource.org/licenses/MIT)
Binary file modified app/app-release.apk
Binary file not shown.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,28 @@





apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.dvd.android.xposed.enableambientdisplay"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
versionCode 2
versionName '1.1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@
~ SOFTWARE.
-->

<manifest package="com.dvd.android.xposed.enableambientdisplay"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest
package="com.dvd.android.xposed.enableambientdisplay"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="de.robv.android.xposed.category.MODULE_SETTINGS"/>
</intent-filter>
</activity>

<meta-data
android:name="xposedmodule"
android:value="true"/>
Expand All @@ -37,7 +48,7 @@
android:value="@string/xposed_descr"/>
<meta-data
android:name="xposedminversion"
android:value="30"/>
android:value="54"/>
</application>

</manifest>
Binary file removed app/src/main/ic_launcher-web.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 DVDAndroid
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dvd.android.xposed.enableambientdisplay;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.NumberPicker;

public class MainActivity extends PreferenceActivity implements
SharedPreferences.OnSharedPreferenceChangeListener {

@Override
@SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(
Context.MODE_WORLD_READABLE);
addPreferencesFromResource(R.xml.prefs);
}

@Override
@SuppressWarnings("deprecation")
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}

@Override
@SuppressWarnings("deprecation")
protected void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}

@Override
@SuppressWarnings("deprecation")
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (sharedPreferences.getString(key, "").equals("")) {
if (key.equals("doze_pulse_duration_visible")) {
sharedPreferences.edit().putString(key, "3000").apply();
} else {
sharedPreferences.edit().putString(key, "1000").apply();
}
EditTextPreference editTextPreference = (EditTextPreference) findPreference(key);
editTextPreference.setText(sharedPreferences.getString(key, ""));
}
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.reboot:
try {
Process proc = Runtime.getRuntime().exec(
new String[] { "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
break;
case R.id.hot_reboot:
try {
Process proc = Runtime.getRuntime().exec(
new String[] { "su", "-c",
"busybox killall system_server" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
break;
}

return super.onOptionsItemSelected(item);
}

@Override
@SuppressWarnings("deprecation")
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {

switch (preference.getKey()) {
case "doze_small_icon_alpha":
createAlert(preference.getKey(), "222", 255);
break;
case "config_screenBrightnessDoze":
createAlert(preference.getKey(), "17", 100);
break;
}

return super.onPreferenceTreeClick(preferenceScreen, preference);
}

@SuppressWarnings("deprecation")
private void createAlert(final String key, String defaultValue, int maxValue) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getResources().getIdentifier(key, "string",
getPackageName()));
final NumberPicker np = new NumberPicker(this);
np.setMinValue(1);
np.setMaxValue(maxValue);/**/
np.setValue(Integer.parseInt(getPreferenceManager()
.getSharedPreferences().getString(key, defaultValue)));
alert.setView(np);
alert.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getPreferenceManager()
.getSharedPreferences()
.edit()
.putString(key, Integer.toString(np.getValue()))
.apply();
}
});
alert.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@

import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;

public class XposedMod implements IXposedHookInitPackageResources,
IXposedHookZygoteInit {

XSharedPreferences prefs;

@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam)
throws Throwable {

prefs = new XSharedPreferences(MainActivity.class.getPackage()
.getName());
prefs.makeWorldReadable();

// change values in framework-res
XResources.setSystemWideReplacement("android", "string",
"config_dozeComponent",
Expand All @@ -45,8 +52,10 @@ public void initZygote(IXposedHookZygoteInit.StartupParam startupParam)
"config_dozeAfterScreenOff", true);
XResources.setSystemWideReplacement("android", "bool",
"config_powerDecoupleInteractiveModeFromDisplay", true);

XResources.setSystemWideReplacement("android", "integer",
"config_screenBrightnessDoze", 17);
"config_screenBrightnessDoze", Integer.parseInt(prefs
.getString("config_screenBrightnessDoze", "17")));
}

@Override
Expand All @@ -63,5 +72,23 @@ public void handleInitPackageResources(
"bool", "doze_display_state_supported", true);
initPackageResourcesParam.res.setReplacement("com.android.systemui",
"bool", "doze_pulse_on_pick_up", true);

initPackageResourcesParam.res.setReplacement("com.android.systemui",
"integer", "doze_pulse_duration_in", Integer.parseInt(prefs
.getString("doze_pulse_duration_in", "1000")));

initPackageResourcesParam.res.setReplacement("com.android.systemui",
"integer", "doze_pulse_duration_visible", Integer
.parseInt(prefs.getString(
"doze_pulse_duration_visible", "3000")));

initPackageResourcesParam.res.setReplacement("com.android.systemui",
"integer", "doze_pulse_duration_out", Integer.parseInt(prefs
.getString("doze_pulse_duration_out", "1000")));

initPackageResourcesParam.res.setReplacement("com.android.systemui",
"integer", "doze_small_icon_alpha", Integer.parseInt(prefs
.getString("doze_small_icon_alpha", "222")));

}
}
36 changes: 36 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2015 DVDAndroid
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/reboot"
android:title="@string/reboot"/>

<item
android:id="@+id/hot_reboot"
android:title="@string/hot_reboot"/>

</menu>
10 changes: 10 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
<resources>
<string name="app_name">Abilita Ambient Display - Xposed</string>
<string name="xposed_descr">Semplice modulo Xposed che aggiunge Ambient Display</string>

<string name="config_screenBrightnessDoze">Luminosità dello schermo usata per oscurare lo schermo</string>
<string name="doze_pulse_duration_in">Quanto tempo ci vuole per accendersi? (ms)</string>
<string name="doze_pulse_duration_out">Quanto tempo ci vuole per spegnersi? (ms)</string>
<string name="doze_pulse_duration_visible">Una volta acceso, quanto tempo ci vuole rimanere acceso? (ms)</string>
<string name="doze_small_icon_alpha">Opacità da applcare alle piccole icone durante il dozing</string>
<string name="warning_battery">Un valore più elevato determina un maggiore utilizzo di batteria</string>
<string name="warning_visibility">Un valore inferiore oscura l\'icona</string>
<string name="hot_reboot">Riavvio veloce</string>
<string name="reboot">Riavvio</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@
<resources>
<string name="app_name">Enable Ambient Display - Xposed</string>
<string name="xposed_descr">Easy Xposed module for Lollipop which add Ambient Display</string>

<string name="doze_pulse_duration_in">How long does it take to fade in? (ms)</string>
<string name="doze_pulse_duration_visible">Once faded in, how long does it stay visible? (ms)</string>
<string name="doze_pulse_duration_out">How long does it take to fade out? (ms)</string>
<string name="warning_battery">A higher value causes a higher use of battery</string>
<string name="warning_visibility">A lower value obscures the icon</string>
<string name="doze_small_icon_alpha">Alpha to apply to small icons when dozing</string>
<string name="config_screenBrightnessDoze">Screen brightness used to dim the screen while dozing.</string>

<string name="hot_reboot">Hot reboot</string>
<string name="reboot">Reboot</string>
</resources>
Loading

0 comments on commit c9eebf2

Please sign in to comment.