增加WLAN、蓝牙、移动数据、LAN、GPS、声音、屏幕亮度、电磁屏开关、屏幕旋转开关
由于是源码环境所以不需要反射获得方法,不是源码环境的话可能就会报错了,需要通过反射来获取方法
frameworks/base/packages/SystemUI/res/layout/status_bar_expanded.xml添加以下代码
<HorizontalScrollView
android:id="@+id/switchHSV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/wifiLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/wifiSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_wifi_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wifi" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/LanLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/LanSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_torch_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lan" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/btLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/btSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_bluetooth_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bt" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/gpsLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/gpsSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_gps_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gps" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/dataLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/dataSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_data_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/data" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/volumeLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/volumeSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_mute_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/volume" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/backlightLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/backLightSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_brightness_auto" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/backlight" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/rotationLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/rotationSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_rotate_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rotate" />
</LinearLayout>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/EMScreenLinearLayout"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="2"
android:background="@drawable/ic_notify_button_bg"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/EMScreenSwitchIv"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:src="@drawable/status_bar_toggle_drive_mode_off" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/EMScreen" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java添加以下代码
LinearLayout wifiLinearLayout;
LinearLayout lanLinearLayout;
LinearLayout btLinearLayout;
LinearLayout gpsLinearLayout;
LinearLayout dataLinearLayout;
LinearLayout volumeLinearLayout;
LinearLayout backlightLinearLayout;
LinearLayout rotationLinearLayout;
LinearLayout EMScreenLinearLayout;
ImageView wifiSwitchIv;
ImageView lanSwitchIv;
ImageView btSwitchIv;
ImageView gpsSwitchIv;
ImageView dataSwitchIv;
ImageView volumeSwitchIv;
ImageView backLightSwitchIv;
ImageView rotationSwitchIv;
ImageView EMScreenSwitchIv;
HorizontalScrollView switchHSV;
private WifiManager mWifiManager;
public static final String WIFI_STATE_CHANGED = "android.net.wifi.WIFI_STATE_CHANGED";
private BluetoothAdapter mBluetoothAdapter;
public static final String BLUETOOTH_STATE_CHANGED = "android.bluetooth.adapter.action.STATE_CHANGED";
private static final String BLUETOOTH_ACTION = "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED";
private ConnectivityManager mConnectivityManager;
private static final String NETWORK_CHANGE = "android.intent.action.ANY_DATA_STATE";
public static final String RINGER_MODE_CHANGED = "android.media.RINGER_MODE_CHANGED";
private PowerManager mPowerManager;
private static final int LIGHT_NORMAL = 64;
private static final int LIGHT_50_PERCENT = 127;
private static final int LIGHT_100_PERCENT = 255;
private static final int LIGHT_AUTO = 0;
private AudioManager mAudioManager;
private BrightAndGPSObserver mBrightAndGPSObserver;
boolean mQuickSwitchShow;
private boolean quickSwitchEnable = false;
private static final String EMSCREENPATH = SystemProperties.get("persist.sys.elecscreen.path", "");
private static final String ETHNET_ENABLE_ACTION = "com.zctt.action.ETHNET_ENABLE";
switchHSV = (HorizontalScrollView) mStatusBarWindow
.findViewById(R.id.switchHSV);
switchHSV.setVisibility(View.VISIBLE);
wifiLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.wifiLinearLayout);
wifiLinearLayout.setOnClickListener(mWifiLinearLayout);
lanLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.LanLinearLayout);
lanLinearLayout.setOnClickListener(mLanLinearLayout);
btLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.btLinearLayout);
btLinearLayout.setOnClickListener(mBTLinearLayout);
gpsLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.gpsLinearLayout);
gpsLinearLayout.setOnClickListener(mGPSLinearLayout);
dataLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.dataLinearLayout);
dataLinearLayout.setOnClickListener(mDataLinearLayout);
volumeLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.volumeLinearLayout);
volumeLinearLayout.setOnClickListener(mVolumeLinearLayout);
backlightLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.backlightLinearLayout);
backlightLinearLayout.setOnClickListener(mBackLightLinearLayout);
rotationLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.rotationLinearLayout);
rotationLinearLayout.setOnClickListener(mRotationLinearLayout);
EMScreenLinearLayout = (LinearLayout) mStatusBarWindow
.findViewById(R.id.EMScreenLinearLayout);
EMScreenLinearLayout.setOnClickListener(mEMScreenLinearLayout);
wifiSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.wifiSwitchIv);
lanSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.LanSwitchIv);
btSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.btSwitchIv);
gpsSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.gpsSwitchIv);
dataSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.dataSwitchIv);
volumeSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.volumeSwitchIv);
backLightSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.backLightSwitchIv);
rotationSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.rotationSwitchIv);
EMScreenSwitchIv = (ImageView) mStatusBarWindow
.findViewById(R.id.EMScreenSwitchIv);
refreshRotationSwitchImage();
refreshGPSSwitchImage();
refreshEMScreenSwitchImage();
refreshBackLightSwitchImage();
mWifiManager = (WifiManager) mContext
.getSystemService(Context.WIFI_SERVICE);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mPowerManager = (PowerManager) mContext
.getSystemService(Context.POWER_SERVICE);
mAudioManager = (AudioManager) mContext
.getSystemService(Context.AUDIO_SERVICE);
mBrightAndGPSObserver = new BrightAndGPSObserver(new Handler());
mBrightAndGPSObserver.startObServer();
IntentFilter filter = new IntentFilter();
filter.addAction(WIFI_STATE_CHANGED);
filter.addAction(BLUETOOTH_STATE_CHANGED);
filter.addAction(BLUETOOTH_ACTION);
filter.addAction(NETWORK_CHANGE);
filter.addAction(RINGER_MODE_CHANGED);
context.registerReceiver(mBroadcastReceiver, filter);
private View.OnClickListener mWifiLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mWifiManager.isWifiEnabled()) {
mWifiManager.setWifiEnabled(false);
} else {
mWifiManager.setWifiEnabled(true);
}
}
};
private View.OnClickListener mBTLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
setBluetoothStatus();
}
};
private View.OnClickListener mGPSLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getGpsStatus(mContext)) {
setGpsStatus(mContext, false);
} else {
setGpsStatus(mContext, true);
}
}
};
private View.OnClickListener mDataLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getMobileDataStatus()) {
setMobileDataStatus(false);
} else {
setMobileDataStatus(true);
}
refreshDataSwitchImage();
}
};
private View.OnClickListener mVolumeLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
setSilentMode();
}
};
private View.OnClickListener mBackLightLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
setBrightStatus();
refreshBackLightSwitchImage();
}
};
private View.OnClickListener mRotationLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getRotationStatus(mContext) == 1) {
setRotationStatus(mContext.getContentResolver(), 0);
} else {
setRotationStatus(mContext.getContentResolver(), 1);
}
}
};
private View.OnClickListener mLanLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getLanStatus(mContext) == EthernetDataTracker.ETHERNET_STATE_ENABLED) {
setLanStatus(mContext.getContentResolver(), 0);
} else {
setLanStatus(mContext.getContentResolver(), 1);
}
}
};
private View.OnClickListener mEMScreenLinearLayout = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getEMScreenStatus(mContext) == 1) {
setEMScreenStatus(mContext.getContentResolver(), 0);
} else {
setEMScreenStatus(mContext.getContentResolver(), 1);
}
}
};
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WIFI_STATE_CHANGED.equals(action)) {
refreshWifiSwitchImage();
} else if (BLUETOOTH_STATE_CHANGED.equals(action)
|| BLUETOOTH_ACTION.equals(action)) {
refreshBtSwitchImage();
} else if (NETWORK_CHANGE.equals(action)) {
if (mConnectivityManager == null) {
mConnectivityManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
}
refreshDataSwitchImage();
} else if (RINGER_MODE_CHANGED.equals(action)) {
refreshVolumeButton();
}
}
}
}
// Update WiFi switch
private void refreshWifiSwitchImage() {
wifiSwitchIv
.setImageResource(mWifiManager.isWifiEnabled() ? R.drawable.status_bar_toggle_wifi_on
: R.drawable.status_bar_toggle_wifi_off);
}
// Updated Bluetooth switch
private void refreshBtSwitchImage() {
switch (getBluetoothStatus()) {
case BluetoothAdapter.STATE_ON:
btSwitchIv
.setImageResource(R.drawable.status_bar_toggle_bluetooth_on);
break;
case BluetoothAdapter.STATE_OFF:
btSwitchIv
.setImageResource(R.drawable.status_bar_toggle_bluetooth_off);
break;
}
}
// Update brightness switch
private void refreshBackLightSwitchImage() {
switch (getBrightStatus()) {
case LIGHT_NORMAL:
backLightSwitchIv
.setImageResource(R.drawable.status_bar_toggle_brightness_off);
break;
case LIGHT_50_PERCENT:
backLightSwitchIv
.setImageResource(R.drawable.status_bar_toggle_brightness_half);
break;
case LIGHT_100_PERCENT:
backLightSwitchIv
.setImageResource(R.drawable.status_bar_toggle_brightness_on);
break;
case LIGHT_AUTO:
backLightSwitchIv
.setImageResource(R.drawable.status_bar_toggle_brightness_auto);
break;
}
}
// Update GPS switch
private void refreshGPSSwitchImage() {
gpsSwitchIv
.setImageResource(getGpsStatus(mContext) ? R.drawable.status_bar_toggle_gps_on
: R.drawable.status_bar_toggle_gps_off);
}
// Update the data flow switch
private void refreshDataSwitchImage() {
dataSwitchIv
.setImageResource(getMobileDataStatus() ? R.drawable.status_bar_toggle_data_on
: R.drawable.status_bar_toggle_data_off);
}
private void refreshVolumeButton() {
switch (getSilentStatus()) {
case AudioManager.RINGER_MODE_SILENT:
volumeSwitchIv.setImageResource(R.drawable.status_bar_toggle_mute_on);
break;
case AudioManager.RINGER_MODE_NORMAL:
volumeSwitchIv.setImageResource(R.drawable.status_bar_toggle_mute_off);
break;
case AudioManager.RINGER_MODE_VIBRATE:
volumeSwitchIv.setImageResource(R.drawable.status_bar_toggle_vibrate_on);
break;
}
}
private void refreshRotationSwitchImage() {
if (getRotationStatus(mContext) == 1) {
rotationSwitchIv
.setImageResource(R.drawable.status_bar_toggle_rotate_on);
} else {
rotationSwitchIv
.setImageResource(R.drawable.status_bar_toggle_rotate_off);
}
}
private void refreshLanSwitchImage() {
if (getLanStatus(mContext) == EthernetDataTracker.ETHERNET_STATE_ENABLED) {
lanSwitchIv.setImageResource(R.drawable.status_bar_toggle_torch_on);
} else {
lanSwitchIv
.setImageResource(R.drawable.status_bar_toggle_torch_off);
}
}
private void refreshEMScreenSwitchImage() {
if (getEMScreenStatus(mContext) == 1) {
EMScreenSwitchIv
.setImageResource(R.drawable.status_bar_toggle_drive_mode_on);
} else {
EMScreenSwitchIv
.setImageResource(R.drawable.status_bar_toggle_drive_mode_off);
}
}
// Gets the current Bluetooth status
private int getBluetoothStatus() {
return mBluetoothAdapter.getState();
}
// Bluetooth switch
private void setBluetoothStatus() {
switch (getBluetoothStatus()) {
case BluetoothAdapter.STATE_ON:
mBluetoothAdapter.disable();
break;
case BluetoothAdapter.STATE_TURNING_ON:
mBluetoothAdapter.disable();
break;
case BluetoothAdapter.STATE_OFF:
mBluetoothAdapter.enable();
break;
case BluetoothAdapter.STATE_TURNING_OFF:
mBluetoothAdapter.enable();
break;
}
}
// Gets the Gps open or closed
private boolean getGpsStatus(Context context) {
boolean status = Secure.isLocationProviderEnabled(
context.getContentResolver(), LocationManager.GPS_PROVIDER);
return status;
}
// Turn on or off the Gps
private void setGpsStatus(Context context, boolean enabled) {
Secure.setLocationProviderEnabled(context.getContentResolver(),
LocationManager.GPS_PROVIDER, enabled);
}
private boolean getMobileDataStatus() {
Boolean isOpen = null;
isOpen = mConnectivityManager.getMobileDataEnabled();
return isOpen;
}
private void setMobileDataStatus(boolean enabled) {
mConnectivityManager.setMobileDataEnabled(enabled);
}
private void setBrightStatus() {
int light = 0;
switch (getBrightStatus()) {
case LIGHT_NORMAL:
light = LIGHT_50_PERCENT - 1;
break;
case LIGHT_50_PERCENT:
light = LIGHT_100_PERCENT - 1;
break;
case LIGHT_100_PERCENT:
startAutoBrightness(mContext.getContentResolver());
break;
case LIGHT_AUTO:
light = LIGHT_NORMAL - 1;
stopAutoBrightness(mContext.getContentResolver());
break;
}
setLight(light);
setScreenLightValue(mContext.getContentResolver(), light);
}
private int getBrightStatus() {
int light = 0;
boolean auto = false;
ContentResolver cr = mContext.getContentResolver();
try {
auto = Settings.System.getInt(cr,
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
if (!auto) {
light = android.provider.Settings.System.getInt(cr,
Settings.System.SCREEN_BRIGHTNESS, -1);
if (light > 0 && light <= LIGHT_NORMAL) {
return LIGHT_NORMAL;
} else if (light > LIGHT_NORMAL && light <= LIGHT_50_PERCENT) {
return LIGHT_50_PERCENT;
} else if (light > LIGHT_50_PERCENT
&& light <= LIGHT_100_PERCENT) {
return LIGHT_100_PERCENT;
}
} else {
return LIGHT_AUTO;
}
} catch (SettingNotFoundException e1) {
e1.printStackTrace();
}
return LIGHT_NORMAL;
}
// Start automatically adjust brightness
public void startAutoBrightness(ContentResolver cr) {
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
}
// Turn off the automatic adjust brightness
public void stopAutoBrightness(ContentResolver cr) {
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
}
private void setLight(int light) {
mPowerManager.setBacklightBrightness(light);
}
// The setting change brightness value
public void setScreenLightValue(ContentResolver resolver, int value) {
android.provider.Settings.System.putInt(resolver,
Settings.System.SCREEN_BRIGHTNESS, value);
}
// Gets the current state of the mobile phone on silent mode
private int getSilentStatus() {
return mAudioManager.getRingerMode();
}
private void setSilentMode() {
switch (getSilentStatus()) {
case AudioManager.RINGER_MODE_SILENT:
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
break;
case AudioManager.RINGER_MODE_NORMAL:
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
break;
case AudioManager.RINGER_MODE_VIBRATE:
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
break;
}
}
private int getRotationStatus(Context context) {
int status = 0;
try {
status = android.provider.Settings.System.getInt(
context.getContentResolver(),
android.provider.Settings.System.ACCELEROMETER_ROTATION);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return status;
}
private void setRotationStatus(ContentResolver resolver, int status) {
android.provider.Settings.System.putInt(resolver,
"accelerometer_rotation", status);
}
private void setLanStatus(ContentResolver resolver, int status){
Intent action = new Intent(ETHNET_ENABLE_ACTION);
action.putExtra("enable", status);
mContext.sendBroadcast(action);
}
private int getLanStatus(Context context) {
int status = 0;
try {
status = Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ETHERNET_ON, -1);
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
private void setEMScreenStatus(ContentResolver resolver, int status){
FileOutputStream fos = null;
File mFile = new File(EMSCREENPATH);
try{
fos = new FileOutputStream(mFile);
fos.write((String.valueOf(status)).getBytes());
Settings.System.putInt(mContext.getContentResolver(),"electromagnetic_screen", status);
}catch(Exception e){
e.printStackTrace();
}finally{
if(fos!=null){
try{
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
private int getEMScreenStatus(Context context) {
int status = 0;
status = Settings.System.getInt(mContext.getContentResolver(),
"electromagnetic_screen", 0);
return status;
}
private class BrightAndGPSObserver extends ContentObserver {
ContentResolver mResolver;
public BrightAndGPSObserver(Handler handler) {
super(handler);
mResolver = mContext.getContentResolver();
}
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if (uri.equals(Settings.System
.getUriFor(Settings.System.LOCATION_PROVIDERS_ALLOWED))) {
refreshGPSSwitchImage();
} else if (uri.equals(Settings.System
.getUriFor(Settings.System.ACCELEROMETER_ROTATION))) {
refreshRotationSwitchImage();
} else if(uri.equals(Settings.System
.getUriFor("electromagnetic_screen"))){
refreshEMScreenSwitchImage();
} else if (uri.equals(Settings.Secure
.getUriFor(Settings.Secure.ETHERNET_ON))) {
refreshLanSwitchImage();
}
else {
refreshBackLightSwitchImage();
}
}
public void startObServer() {
mResolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.SCREEN_BRIGHTNESS), false, this);
mResolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE), false,
this);
mResolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.LOCATION_PROVIDERS_ALLOWED),
false, this);
mResolver.registerContentObserver(Settings.System
.getUriFor(Settings.System.ACCELEROMETER_ROTATION), false,
this);
mResolver.registerContentObserver(
Settings.System.getUriFor("electromagnetic_screen"), false,
this);
mResolver.registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.ETHERNET_ON),
false, this);
}
}