01hanst 01hanst - 3 months ago 23
Android Question

how to adjust screen color brightness?

I am trying to create a screen filter applications.

so I'm looking for a way to change the color of the screen.

Looking for a lot of web sites, it is hard to find a way that I think.

First, how to gain access to the system, but is not suitable for distribution.

I think the second way to replace or overlay a color, it is not easy.

There comes a lot of pages to introduce the application.

The layout was created.

Now find a way.

I just do not see the page?


Answer

Android Permission to Change Screen Brightness

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

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="26dp"
    android:max="10" />
    </RelativeLayout>

MainActivity.java

  package com.example.android_adjustbrightness;
  import android.os.Bundle;
  import android.provider.Settings.SettingNotFoundException;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.SeekBar;
  import android.widget.SeekBar.OnSeekBarChangeListener;

  public class MainActivity extends Activity {

  private SeekBar seekBar;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 seekBar = (SeekBar) findViewById(R.id.seekBar1);
 seekBar.setMax(255);

 float curBrightnessValue = 0;
 try {
 curBrightnessValue = android.provider.Settings.System.getInt(
 getContentResolver(),
 android.provider.Settings.System.SCREEN_BRIGHTNESS);
 } catch (SettingNotFoundException e) {
  e.printStackTrace();
  }

 int screen_brightness = (int) curBrightnessValue;
 seekBar.setProgress(screen_brightness);
 seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
 int progress = 0;

@Override
 public void onProgressChanged(SeekBar seekBar, int progresValue,
 boolean fromUser) {
  progress = progresValue;
}

@Override
 public void onStartTrackingTouch(SeekBar seekBar) {
 // Do something here,
 // if you want to do anything at the start of
 // touching the seekbar
 }

@Override
 public void onStopTrackingTouch(SeekBar seekBar) {
 android.provider.Settings.System.putInt(getContentResolver(),
  android.provider.Settings.System.SCREEN_BRIGHTNESS,
  progress);
 }
 });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }

 }

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_adjustbrightness"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.android_adjustbrightness.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Comments