|
|
|
Create Account – Sign in
|
|
Toggle Utilities for Android Phones
[ Toggle Screen Timeout - Toggle Brightness ]
Like many other smart phones android phones have many knows and dials, but to
access them you have to go through multiple menus. Some of them I need quite
frequently, and fortunately there are applications that toggle just one setting.
Some of the ones I use toggle GPS, Wifi and Bluetooth on and off.
However, I also frequently like to change the brightness of the screen
and stop the screen from turning off in some cases (in partiuclar if I
use the map on a sunny day). As I could not find any applications that
do that I wrote my own, which can be downloaded from the Android market,
or below: Toggle Screen Timeout and Toggle Brightness.
Those are the two first applications I wrote for android, and it took
me a while to get all the required information I needed to write them.
In order to simplify other developers life you can download the
complete source code here.
|
Toggle Screen Timeout
|
Download Source: | ToggleScreen.tar.gz
|
Download Application: | ToggleScreen.apk
|
Icon: | Time-Machine by Babasse |
ToggleBrightness.java: |
/**
* ToggleScreen: Android application to toggle screen timeouts.
* Copyright 2009 by Claudio Fleiner
* http://www.mensus.net/phone/toggle.shtml
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package net.mensus.togglescreen;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
public class ToggleScreen extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
SharedPreferences settings=
getSharedPreferences("net.mensus.togglescreen", MODE_PRIVATE);
ContentResolver c=getContentResolver();
int val=android.provider.Settings.System.getInt(getContentResolver(),
SCREEN_OFF_TIMEOUT);
if(val==-1 || val==0) {
int nval=settings.getInt("ScreenTimeout",60000);
if(nval<=0) nval=60000;
String t;
if(nval==30000) t="1/2 min";
else if(nval>=60000) t=""+(nval/60000)+" min";
else t=""+(nval/1000)+" sec";
Toast.makeText(this,
"Screen Timeout set to "+t,
Toast.LENGTH_LONG).show();
android.provider.Settings.System.putInt(getContentResolver(),
SCREEN_OFF_TIMEOUT, nval);
} else {
android.provider.Settings.System.putInt(getContentResolver(),
SCREEN_OFF_TIMEOUT, -1);
Toast.makeText(this, "Disabled Screen Timeout", Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ScreenTimeout",val);
editor.commit();
}
} catch(Throwable er) {
Toast.makeText(this, "Error "+er.getMessage(), Toast.LENGTH_LONG).show();
} finally {
finish();
}
}
}
|
|
Toggle Screen Brightness |
Download Source: | ToggleBrightness.tar.gz |
Download Application: | ToggleBrightness.apk |
Icon: | Orbz-Sun by Arrioch |
ToggleBrightness.java: |
/**
* ToggleBrightness: Android application to toggle screen brightness.
* Copyright 2009 by Claudio Fleiner
* http://www.mensus.net/phone/toggle.shtml
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package net.mensus.togglebrightness;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.IHardwareService;
import android.os.ServiceManager;
import android.widget.Toast;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
public class ToggleBrightness extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
SharedPreferences settings=
getSharedPreferences("net.mensus.togglebrightness", MODE_PRIVATE);
ContentResolver c=getContentResolver();
int val=android.provider.Settings.System.getInt(
getContentResolver(), SCREEN_BRIGHTNESS);
IHardwareService hardware=
IHardwareService.Stub.asInterface( ServiceManager.getService("hardware"));
if(val==255) {
int nval=settings.getInt("ScreenBrightness",128);
if(nval<=0) nval=128;
if(nval>255) nval=255;
Toast.makeText(this,
""+(nval*100/255)+"% Brightness",
Toast.LENGTH_LONG).show();
android.provider.Settings.System.putInt(getContentResolver(),
SCREEN_BRIGHTNESS, nval);
if(hardware!=null) hardware.setScreenBacklight(nval);
} else {
android.provider.Settings.System.putInt(getContentResolver(),
SCREEN_BRIGHTNESS, 255);
Toast.makeText(this, "Maximum Brightness", Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ScreenBrightness",val);
editor.commit();
if(hardware!=null) hardware.setScreenBacklight(255);
}
} catch(Throwable er) {
Toast.makeText(this, "Error "+er.getMessage(), Toast.LENGTH_LONG).show();
} finally {
finish();
}
}
}
|
Use this feature to comment on this page, to suggest features, ask question or propose changes. Comments are shown in a threaded format, with newer comments at the top. The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way. You need to signin if you want to post a comment
|
|
|
Privacy Policy — Terms of Use Agreement — © 2006 - 2024
mensus.net |
|
|