デバイスの明るさを制御できる Andorid 設定ウィジェットを模倣しようとしています。意図したとおりに機能し、設定で確認できます。しかし、デバイスが明るくなることはありません。
コードは次のとおりです。
WindowManager.LayoutParams lp = getWindow().getAttributes();
SeekBar brightnessControl = (SeekBar) findViewById(R.id.sbBrightness);
int currentBrightness = 10;
brightnessControl.setProgress(currentBrightness);
lp.screenBrightness = currentBrightness/100f;
brightnessControl.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
//set local brightness
WindowManager.LayoutParams lp = getWindow().getAttributes();
progress = (progress <= 10)?10:progress;
lp.screenBrightness = progress/100f;
getWindow().setAttributes(lp);
//put local to system wide brightness
int sysWideBrightness = (int) (progress/100f * 255);
android.provider.Settings.System.putInt(
getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
sysWideBrightness);
}
});
このアクティビティは [アクティビティ] タブで実行されます。タブに入れる前は正常に動作しますが、そうではありません。
デバイスに新しいバージョンの Android (現在は 4.2.2 がルート化されています) をインストールすると、意図したとおりに動作することがわかりました。ルート化されたジンジャーブレッド デバイスでテストしましたが、動作しません。
これが役立つ場合があります。これは Main.java ファイルで、ActivityTab を開始する方法は次のとおりです。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* TabHost will have Tabs */
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
TabSpec fifthTabSpec = tabHost.newTabSpec("tid5");
firstTabSpec.setIndicator("", getResources().getDrawable(R.drawable.clear_cache_tab)).setContent(showClearCache());
secondTabSpec.setIndicator("", getResources().getDrawable(R.drawable.move_sd_tab)).setContent(showMoveToSd());
thirdTabSpec.setIndicator("", getResources().getDrawable(R.drawable.remove_app_tab)).setContent(showRemoveApp());
fourthTabSpec.setIndicator("", getResources().getDrawable(R.drawable.feature_manager_tab)).setContent(showFeatureManager());
fifthTabSpec.setIndicator("", getResources().getDrawable(R.drawable.feature_manager_tab)).setContent(showProcessKill());
tabHost.setOnTabChangedListener(this);
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);
tabHost.addTab(fourthTabSpec);
tabHost.addTab(fifthTabSpec);
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#303030"));
}
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#C8C8C8"));
}
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#303030"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#C8C8C8"));
}