[Galaxy S II General] Namoi:
Hi mate,

Sorry for my late answer.

In fact the it "seems" to work, but one must have auto brightness disable + the slider not at 100%.

But if you look at the slider you will see it moving as you click on the toggle, but its position is inaccurate (always -40 comparing to the value it should be on).

I'm gonna try to write a chart for each cycle with the corresponding values that should be applied and the value reported by the BrightnessObserver (which is the one we can see on the slider) to see if there is indeed a pattern.

I had time to dex2jar again the systemui from JB reloaded and the one from alliance for comparing the smalis that maybe are the cause of the bugs (brightness and brightnessButton) : they are totally the same... So, it would be great to know if it really works on Alliance Rom...

Here is the code of Brightness :

package com.wanam.systemui.quickpanel;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.os.Handler;
import android.os.IPowerManager;
import android.os.IPowerManager.Stub;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings.System;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class Brightness extends LinearLayout
{
private static Boolean SUPPORTS_AUTO_BACKLIGHT = null;
private CheckBox mAuto;
Handler mHandler = new Handler();
BrightnessObserver mObserver = new BrightnessObserver();
private ContentResolver mResolver;
private SeekBar mSeekBar;
private IPowerManager power;

public Brightness(Context paramContext, AttributeSet paramAttributeSet)
{
super(paramContext, paramAttributeSet);
this.mResolver = paramContext.getContentResolver();
this.power = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
View.inflate(paramContext, 84082688, this);
}

private static int getBrightness(Context paramContext)
{
return 100 * (-10 + Settings.System.getInt(paramContext.getContentResolver(), "screen_brightness", 0)) / 245;
}

public static boolean getShowBrightness(Context paramContext)
{
int i = 1;
if (Settings.System.getInt(paramContext.getContentResolver(), "brightness_adjust_in_expand_status_bar", i) > 0);
while (true)
{
return i;
int j = 0;
}
}

private boolean isAutomaticModeSupported()
{
if (SUPPORTS_AUTO_BACKLIGHT == null)
if (!getContext().getResources().getBoolean(17891347))
break label35;
label35: for (SUPPORTS_AUTO_BACKLIGHT = Boolean.valueOf(true); ; SUPPORTS_AUTO_BACKLIGHT = Boolean.valueOf(false))
return SUPPORTS_AUTO_BACKLIGHT.booleanValue();
}

private boolean isBrightnessSetToAutomatic()
{
int i = 1;
try
{
int j = Settings.System.getInt(this.mResolver, "screen_brightness_mode");
if (j == i);
while (true)
{
return i;
i = 0;
}
}
catch (Exception localException)
{
while (true)
{
localException.printStackTrace();
i = 0;
}
}
}

private void registerObiserver()
{
this.mResolver.registerContentObserver(Settings.System.getUriFor("screen_brightness"), false, this.mObserver);
this.mResolver.registerContentObserver(Settings.System.getUriFor("screen_brightness_mode"), false, this.mObserver);
this.mResolver.registerContentObserver(Settings.System.getUriFor("brightness_adjust_in_expand_status_bar"), false, this.mObserver);
}

protected void adjustBrightness(int paramInt, boolean paramBoolean)
{
adjustBrightness(paramInt, paramBoolean, false);
}

protected void adjustBrightness(int paramInt, boolean paramBoolean1, boolean paramBoolean2)
{
getContext();
try
{
if (this.power != null)
if (paramBoolean1)
{
Settings.System.putInt(this.mResolver, "screen_brightness_mode", 1);
}
else
{
if (isAutomaticModeSupported())
Settings.System.putInt(this.mResolver, "screen_brightness_mode", 0);
int i = 10 + paramInt * 245 / 100;
this.power.setBacklightBrightness(i);
if (paramBoolean2)
Settings.System.putInt(this.mResolver, "screen_brightness", i);
}
}
catch (RemoteException localRemoteException)
{
}
}

public void onFinishInflate()
{
this.mSeekBar = ((SeekBar)findViewById(84279298));
this.mAuto = ((CheckBox)findViewById(84279299));
this.mAuto.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
boolean bool1 = true;
boolean bool2 = Brightness.this.mAuto.isChecked();
Brightness.this.adjustBrightness(Brightness.this.mSeekBar.getProgress(), bool2, bool1);
SeekBar localSeekBar = Brightness.this.mSeekBar;
if (!bool2);
while (true)
{
localSeekBar.setEnabled(bool1);
return;
bool1 = false;
}
}
});
this.mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar paramAnonymousSeekBar, int paramAnonymousInt, boolean paramAnonymousBoolean)
{
if (paramAnonymousBoolean)
Brightness.this.adjustBrightness(paramAnonymousInt, false);
}

public void onStartTrackingTouch(SeekBar paramAnonymousSeekBar)
{
}

public void onStopTrackingTouch(SeekBar paramAnonymousSeekBar)
{
Brightness.this.adjustBrightness(Brightness.this.mSeekBar.getProgress(), Brightness.this.mAuto.isChecked(), true);
}
});
this.mObserver.onChange(false);
registerObiserver();
}

class BrightnessObserver extends ContentObserver
{
public BrightnessObserver()
{
super();
}

public void onChange(boolean paramBoolean)
{
int i;
boolean bool2;
if (!Brightness.getShowBrightness(Brightness.this.getContext()))
{
Brightness.this.setVisibility(8);
i = Brightness.getBrightness(Brightness.this.getContext());
boolean bool1 = Brightness.this.isAutomaticModeSupported();
bool2 = Brightness.this.isBrightnessSetToAutomatic();
if (bool1)
break label128;
Brightness.this.mAuto.setVisibility(8);
}
while (true)
{
Brightness.this.mSeekBar.setProgress(i);
Brightness.this.mAuto.setChecked(bool2);
SeekBar localSeekBar = Brightness.this.mSeekBar;
boolean bool3 = false;
if (!bool2)
bool3 = true;
localSeekBar.setEnabled(bool3);
return;
Brightness.this.setVisibility(0);
break;
label128: Brightness.this.mAuto.setVisibility(0);
}
}
}
}

And here is the code of BrightnessButton

package com.wanam.systemui.quickpanel;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.IPowerManager;
import android.os.IPowerManager.Stub;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings.System;
import android.util.Log;
import android.view.View;
import java.util.ArrayList;
import java.util.List;

public class BrightnessButton extends PowerButton
{
private static final int AUTO_BACKLIGHT = -1;
private static final int CM_MODE_AUTO_LOW_MAX = 2;
private static final int CM_MODE_AUTO_MIN_DEF_MAX = 0;
private static final int CM_MODE_AUTO_MIN_LOW_MID_HIGH_MAX = 1;
private static final int CM_MODE_MIN_MAX = 3;
private static final int DEFAULT_BACKLIGHT = 102;
private static final int HIGH_BACKLIGHT = 191;
private static final int LOW_BACKLIGHT = 63;
private static final int MAX_BACKLIGHT = 255;
private static final int MID_BACKLIGHT = 127;
private static final int MIN_BACKLIGHT = 30;
private static final List<Uri> OBSERVED_URIS;
private static Boolean SUPPORTS_AUTO_BACKLIGHT = null;

static
{
OBSERVED_URIS = new ArrayList();
OBSERVED_URIS.add(Settings.System.getUriFor("screen_brightness"));
OBSERVED_URIS.add(Settings.System.getUriFor("screen_brightness_mode"));
}

public BrightnessButton()
{
this.mType = "toggleBrightness";
}

private static int getBrightnessState(Context paramContext)
{
int i = 2;
int j = Settings.System.getInt(paramContext.getContentResolver(), "screen_brightness", 0);
int k = getCurrentCMMode(paramContext);
if (j < 63);
while (true)
{
return i;
if (j >= 102)
if (j < 127)
{
if (k != 1)
i = 4;
}
else if (j < 191)
{
if (k == 1)
i = 4;
else
i = 3;
}
else if (j < 255)
i = 3;
else
i = 1;
}
}

private static int getCurrentCMMode(Context paramContext)
{
return Settings.System.getInt(paramContext.getContentResolver(), "expanded_brightness_mode", 1);
}

private static int getMinBacklight(Context paramContext)
{
int i = 30;
if (Settings.System.getInt(paramContext.getContentResolver(), "light_sensor_custom", 0) != 0)
i = Settings.System.getInt(paramContext.getContentResolver(), "light_screen_dim", i);
return i;
}

private static int getNextBrightnessValue(Context paramContext)
{
int i = 63;
int j = Settings.System.getInt(paramContext.getContentResolver(), "screen_brightness", 0);
int k = getCurrentCMMode(paramContext);
if ((isAutomaticModeSupported(paramContext)) && (isBrightnessSetToAutomatic(paramContext)))
if (k != 2);
while (true)
{
return i;
i = getMinBacklight(paramContext);
continue;
if (j < i)
{
if (k != 2)
if (k == 3)
i = 255;
else
i = 102;
}
else if (j < 102)
{
if (k == 0)
i = 102;
else if ((k == 2) || (k == 3))
i = 255;
else
i = 127;
}
else if (j < 127)
{
if (k == 1)
i = 127;
else
i = 255;
}
else if (j < 191)
{
if (k == 1)
i = 191;
else
i = 255;
}
else if (j < 255)
i = 255;
else if ((isAutomaticModeSupported(paramContext)) && (k != 3))
i = -1;
else if (k != 2)
i = getMinBacklight(paramContext);
}
}

private static boolean isAutomaticModeSupported(Context paramContext)
{
if (SUPPORTS_AUTO_BACKLIGHT == null)
if (!paramContext.getResources().getBoolean(17891347))
break label32;
label32: for (SUPPORTS_AUTO_BACKLIGHT = Boolean.valueOf(true); ; SUPPORTS_AUTO_BACKLIGHT = Boolean.valueOf(false))
return SUPPORTS_AUTO_BACKLIGHT.booleanValue();
}

private static boolean isBrightnessSetToAutomatic(Context paramContext)
{
int i = 1;
try
{
if (IPowerManager.Stub.asInterface(ServiceManager.getService("power")) != null)
{
int j = Settings.System.getInt(paramContext.getContentResolver(), "screen_brightness_mode");
if (j == i);
while (true)
{
return i;
i = 0;
}
}
}
catch (Exception localException)
{
while (true)
{
Log.d("PowerWidget", "getBrightnessMode: " + localException);
i = 0;
}
}
}

protected List<Uri> getObservedUris()
{
return OBSERVED_URIS;
}

protected int getText()
{
return 84607049;
}

protected boolean handleLongClick()
{
Intent localIntent = new Intent("android.settings.DISPLAY_SETTINGS");
localIntent.addCategory("android.intent.category.DEFAULT");
localIntent.addFlags(268435456);
this.mView.getContext().startActivity(localIntent);
return true;
}

protected void toggleState()
{
Context localContext = this.mView.getContext();
try
{
IPowerManager localIPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if (localIPowerManager != null)
{
int i = getNextBrightnessValue(localContext);
ContentResolver localContentResolver = localContext.getContentResolver();
if (i == -1)
{
Settings.System.putInt(localContentResolver, "screen_brightness_mode", 1);
}
else
{
if (isAutomaticModeSupported(localContext))
Settings.System.putInt(localContentResolver, "screen_brightness_mode", 0);
localIPowerManager.setBacklightBrightness(i);
Settings.System.putInt(localContentResolver, "screen_brightness", i);
}
}
}
catch (RemoteException localRemoteException)
{
Log.d("PowerWidget", "toggleBrightness: " + localRemoteException);
}
}

protected void updateState()
{
Context localContext = this.mView.getContext();
if (isBrightnessSetToAutomatic(localContext))
{
this.mIcon = 84017283;
this.mState = 1;
}
while (true)
{
return;
switch (getBrightnessState(localContext))
{
case 2:
default:
this.mIcon = 84017285;
this.mState = 2;
break;
case 1:
this.mIcon = 84017286;
this.mState = 1;
break;
case 3:
this.mIcon = 84017286;
this.mState = 5;
break;
case 4:
this.mIcon = 84017284;
this.mState = 5;
}
}
}
}

Cheers