Android Open Source - Chopping Brightness Refresh Activity






From Project

Back to project page Chopping.

License

The source code is released under:

Apache License

If you think the Android project Chopping 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.chopping.activities;
//from w  ww .ja  v  a2 s. c om

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.view.Window;
import android.view.WindowManager;

public final class BrightnessRefreshActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    refreshBrightness(getBrightnessLevel());

    Thread t = new Thread() {
      public void run() {
        try {
          sleep(10);
        } catch (InterruptedException e) {
        }
        finish();
      }
    };
    t.start();
  }

  //----------------------------------------------------------
  // Description: Refresh brightness
  //
  // No all devices can react the change of brightness.
  // See.
  // http://stackoverflow.com/questions/14101669/change-brightness-according-to-surrounding-light-in-android
  //----------------------------------------------------------

  private void refreshBrightness(float brightness) {
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    if (brightness < 0) {
      lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    } else {
      lp.screenBrightness = brightness;
    }
    getWindow().setAttributes(lp);
  }

  int getBrightnessLevel() {
    try {
      int value = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
      // convert brightness level to range 0..1
      value = value / 255;
      return value;
    } catch (SettingNotFoundException e) {
      return 0;
    }
  }
}




Java Source Code List

com.android.internal.telephony.ITelephony.java
com.chopping.ApplicationTest.java
com.chopping.activities.BaseActivity.java
com.chopping.activities.BrightnessRefreshActivity.java
com.chopping.activities.ErrorHandlerActivity.java
com.chopping.application.BasicPrefs.java
com.chopping.application.ErrorHandler.java
com.chopping.application.IApp.java
com.chopping.application.InstalledAppReceiver.java
com.chopping.application.LL.java
com.chopping.bus.AirplaneModeOnEvent.java
com.chopping.bus.ApplicationConfigurationDownloadedEvent.java
com.chopping.bus.ApplicationConfigurationLoadingIgnoredEvent.java
com.chopping.bus.CloseDrawerEvent.java
com.chopping.bus.ExternalAppChangedEvent.java
com.chopping.bus.LinkToExternalAppEvent.java
com.chopping.bus.ReloadEvent.java
com.chopping.data.AppListItem.java
com.chopping.data.AppList.java
com.chopping.exceptions.CanNotOpenOrFindAppPropertiesException.java
com.chopping.exceptions.InvalidAppPropertiesException.java
com.chopping.exceptions.OperationFailException.java
com.chopping.fragments.AppListFragment.java
com.chopping.fragments.BaseFragment.java
com.chopping.fragments.ErrorHandlerFragment.java
com.chopping.net.GsonRequestTask.java
com.chopping.net.TaskHelper.java
com.chopping.utils.Consts.java
com.chopping.utils.DeviceUtils.java
com.chopping.utils.IncomingCallReceiver.java
com.chopping.utils.MediaUtils.java
com.chopping.utils.NetworkUtils.java
com.chopping.utils.Utils.java
com.chopping.utils.views.OneDirectionScrollView.java