Android Open Source - Fast-Brightness-Control-Widget Brightness Control Activity






From Project

Back to project page Fast-Brightness-Control-Widget.

License

The source code is released under:

Apache License

If you think the Android project Fast-Brightness-Control-Widget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mod.android.widget.fbcw;
//from w  w w  .  j  a  v a  2 s. c om
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.WindowManager;
import android.widget.Toast;
import static com.mod.android.widget.fbcw.MyConstants.*;

public class BrightnessControlActivity extends Activity {  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
        
    //get the ID of the clicked button
    Integer buttonId = (Integer) getIntent().getExtras().get(BUTTON_ID);
    
    //get the brightness level for clicked button
    SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
    int brightness = preferences.getInt(buttonId.toString(), DEFAULT_BRIGHTNESS_LEVELS.get(buttonId));
    boolean showMessage = preferences.getBoolean(SHOW_MESSAGE, true);
    
    //display message if needed
    if (showMessage) {
      Toast.makeText(getApplicationContext(), "Brightness: " +brightness + "%", Toast.LENGTH_SHORT).show();
    }
        
    //set screen brightness
    Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, (int) Math.ceil(brightness/100.0f*255));
    
    //refresh state
    // window manager accepts brightness in float hence dividing brightness by 100.0f
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.screenBrightness = brightness / 100.0f;
    getWindow().setAttributes(lp);  
                
    super.onCreate(savedInstanceState);
    
    //wait a bit before closing (so the settings can be updated)
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {      
      public void run() {
        BrightnessControlActivity.this.finish();      
      }
    }, ACTIVITY_FINISH_DELAY);  
    
  }
}




Java Source Code List

com.mod.android.widget.fbcw.BaseWidgetProvider.java
com.mod.android.widget.fbcw.BrightnessControlActivity.java
com.mod.android.widget.fbcw.ConfigurationActivity.java
com.mod.android.widget.fbcw.HorizontalWidgetProvider.java
com.mod.android.widget.fbcw.MyConstants.java
com.mod.android.widget.fbcw.VerticalWidgetProvider.java
com.mod.android.widget.fbcw.bean.ApplicationState.java
com.mod.android.widget.fbcw.listener.SeekBarListener.java