Merge "Small refactor to allow more customization of AutoRotate settings in extending classes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f1128f0c21
@@ -31,7 +31,7 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
|
|||||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The switch controller for the location.
|
* The switch controller for auto-rotate.
|
||||||
*/
|
*/
|
||||||
public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener,
|
public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener,
|
||||||
LifecycleObserver, OnStart, OnStop {
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
@@ -63,7 +63,7 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
|||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private Preference mPreference;
|
protected Preference mPreference;
|
||||||
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
|
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
|
||||||
|
|
||||||
public SmartAutoRotateController(Context context, String preferenceKey) {
|
public SmartAutoRotateController(Context context, String preferenceKey) {
|
||||||
@@ -84,10 +84,14 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
|||||||
if (!isRotationResolverServiceAvailable(mContext)) {
|
if (!isRotationResolverServiceAvailable(mContext)) {
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
return UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
return !RotationPolicy.isRotationLocked(mContext) && hasSufficientPermission(mContext)
|
return !isRotationLocked() && hasSufficientPermission(mContext)
|
||||||
&& !isCameraLocked() && !isPowerSaveMode() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
&& !isCameraLocked() && !isPowerSaveMode() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isRotationLocked() {
|
||||||
|
return RotationPolicy.isRotationLocked(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
@@ -136,7 +140,7 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return !RotationPolicy.isRotationLocked(mContext) && hasSufficientPermission(mContext)
|
return !isRotationLocked() && hasSufficientPermission(mContext)
|
||||||
&& !isCameraLocked() && !isPowerSaveMode() && Settings.Secure.getInt(
|
&& !isCameraLocked() && !isPowerSaveMode() && Settings.Secure.getInt(
|
||||||
mContext.getContentResolver(),
|
mContext.getContentResolver(),
|
||||||
CAMERA_AUTOROTATE, 0) == 1;
|
CAMERA_AUTOROTATE, 0) == 1;
|
||||||
@@ -163,7 +167,10 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
|||||||
return R.string.menu_key_display;
|
return R.string.menu_key_display;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isRotationResolverServiceAvailable(Context context) {
|
/**
|
||||||
|
* Returns true if there is a {@link RotationResolverService} available
|
||||||
|
*/
|
||||||
|
public static boolean isRotationResolverServiceAvailable(Context context) {
|
||||||
final PackageManager packageManager = context.getPackageManager();
|
final PackageManager packageManager = context.getPackageManager();
|
||||||
final String resolvePackage = packageManager.getRotationResolverPackageName();
|
final String resolvePackage = packageManager.getRotationResolverPackageName();
|
||||||
if (TextUtils.isEmpty(resolvePackage)) {
|
if (TextUtils.isEmpty(resolvePackage)) {
|
||||||
|
Reference in New Issue
Block a user