Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old September 20th, 2010, 01:10 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Sep 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Post setting brightness through program

Hi..
should any one knows how to control screen brightness through program for android device. ..i did one application but it works only for that window of a android device..i need control of brightness for the whole system not for single window..i posted my code here..please do the needful..please post full code..

package com.anand.brightness;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.SeekBar;

public class brightness_control extends Activity {
private static final String BRIGHTNESS_PREFERENCE_KEY = "brightness";
private View brightnessPanel;
private SeekBar brightnessControl;
private int brightness = 50;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
brightnessPanel = findViewById(R.id.panel);
brightnessControl = (SeekBar) findViewById(R.id.seek);
Button btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showBrightnessPanel();
}
});
brightnessControl
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
setBrightness(progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
hideBrightnessPanel();
}
});
}
private void showBrightnessPanel() {
Animation animation = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
brightnessControl.setProgress(this.brightness);
brightnessPanel.setVisibility(View.VISIBLE);
brightnessPanel.startAnimation(animation);
}
private void setBrightness(int value) {
if (value < 10) {
value = 10;
} else if (value > 100) {
value = 100;
}
brightness = value;
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) value / 100;
lp.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(lp);
}
private void hideBrightnessPanel() {
Animation animation = AnimationUtils.loadAnimation(brightness_control.th is,
android.R.anim.slide_out_right);
brightnessPanel.startAnimation(animation);
brightnessPanel.setVisibility(View.GONE);
PreferenceManager.getDefaultSharedPreferences(this ).edit().putInt(
BRIGHTNESS_PREFERENCE_KEY, brightnessControl.getProgress())
.commit();

}
}


xml code:


<?
xmlversion="1.0"encoding="utf-8"?>
<
LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

androidrientation="vertical"android:layout_width="fill_parent"

android:layout_height="fill_parent"android:background="#3399CC">



<Buttonandroid:text="Show Brightness Panel"android:id="@+id/Button01"

android:layout_width="wrap_content"android:layout_height="wrap_content"></Button>



<LinearLayoutandroid:id="@+id/panel"androidrientation="vertical"

android:layout_width="fill_parent"android:layout_height="wrap_content"

android:layout_alignParentBottom="true"androidaddingTop="10dip"

androidaddingBottom="30dip"androidaddingLeft="20dip"

androidaddingRight="20dip"android:gravity="center_horizontal"

android:visibility="gone">


<TextViewandroid:text="Brightness Level"

android:layout_width="fill_parent"android:layout_height="wrap_content"

android:gravity="center"android:textAppearance="?android:attr/textAppearanceLarge"/>


<SeekBarandroid:id="@+id/seek"android:layout_width="fill_parent"

android:layout_height="wrap_content"android:max="100"

androidrogress="100"/>


</LinearLayout>


</
LinearLayout>


anandkgowda is offline  
Reply With Quote
sponsored links
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:09 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.