package com.android.systemui.statusbar.powerwidget;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import com.android.systemui.R;
public class AutoRotateButton extends PowerButton {
private static final List<Uri> OBSERVED_URIS = new ArrayList<Uri>();
static {
OBSERVED_URIS.add(Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION));
}
public AutoRotateButton() { mType = BUTTON_AUTOROTATE; }
@Override
protected void updateState() {
if (getOrientationState(mView.getContext()) == 1) {
mIcon = R.drawable.stat_orientation_on;
mState = STATE_ENABLED;
} else {
mIcon = R.drawable.stat_orientation_off;
mState = STATE_DISABLED;
}
}
@Override
protected void toggleState() {
Context context = mView.getContext();
if(getOrientationState(context) == 0) {
Settings.System.putInt(
context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 1);
} else {
Settings.System.putInt(
context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0);
}
}
@Override
protected boolean handleLongClick() {
Intent intent = new Intent("android.settings.DISPLAY_SETTINGS");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mView.getContext().startActivity(intent);
return true;
}
@Override
protected List<Uri> getObservedUris() {
return OBSERVED_URIS;
}
private static int getOrientationState(Context context) {
return Settings.System.getInt(
context.getContentResolver(),
Settings.System.ACCELEROMETER_ROTATION, 0);
}
}