Merge "Add illustrations to fold lock setting" into main

This commit is contained in:
Shivangi Dubey
2023-09-21 10:05:11 +00:00
committed by Android (Google) Code Review
5 changed files with 66 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -48,18 +48,18 @@ public class FoldLockBehaviorSettings extends RadioButtonPickerFragment implemen
public static final String SETTING_VALUE_STAY_AWAKE_ON_FOLD = "stay_awake_on_fold_key";
public static final String SETTING_VALUE_SELECTIVE_STAY_AWAKE = "selective_stay_awake_key";
public static final String SETTING_VALUE_SLEEP_ON_FOLD = "sleep_on_fold_key";
private static final String SETTING_VALUE_DEFAULT = SETTING_VALUE_SELECTIVE_STAY_AWAKE;
public static final String TAG = "FoldLockBehaviorSetting";
public static final HashSet<String> SETTING_VALUES = new HashSet<>(
Set.of(SETTING_VALUE_STAY_AWAKE_ON_FOLD, SETTING_VALUE_SELECTIVE_STAY_AWAKE,
SETTING_VALUE_SLEEP_ON_FOLD));
private static final String SETTING_VALUE_DEFAULT = SETTING_VALUE_SELECTIVE_STAY_AWAKE;
private Context mContext;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
setIllustrationLottieAnimation(getDefaultKey());
}
@Override
@@ -136,6 +136,31 @@ public class FoldLockBehaviorSettings extends RadioButtonPickerFragment implemen
UserHandle.USER_CURRENT);
}
@Override
protected void onSelectionPerformed(boolean success) {
if (success) {
setIllustrationLottieAnimation(getDefaultKey());
updateCandidates();
}
}
private void setIllustrationLottieAnimation(String foldSettingValue) {
switch (foldSettingValue) {
case SETTING_VALUE_STAY_AWAKE_ON_FOLD:
setIllustration(R.raw.fold_setting_stay_awake_on_fold_lottie,
IllustrationType.LOTTIE_ANIMATION);
break;
case SETTING_VALUE_SELECTIVE_STAY_AWAKE:
setIllustration(R.raw.fold_setting_selective_stay_awake_lottie,
IllustrationType.LOTTIE_ANIMATION);
break;
case SETTING_VALUE_SLEEP_ON_FOLD:
setIllustration(R.raw.fold_setting_sleep_on_fold_lottie,
IllustrationType.LOTTIE_ANIMATION);
break;
}
}
private String resourceToString(int resource) {
return mContext.getText(resource).toString();
}

View File

@@ -16,6 +16,7 @@
package com.android.settings.widget;
import android.annotation.AnyRes;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
@@ -38,6 +39,7 @@ import com.android.settings.Utils;
import com.android.settings.core.PreferenceXmlParserUtils;
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settingslib.widget.CandidateInfo;
import com.android.settingslib.widget.IllustrationPreference;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.xmlpull.v1.XmlPullParserException;
@@ -64,7 +66,7 @@ public abstract class RadioButtonPickerFragment extends SettingsPreferenceFragme
protected int mUserId;
private int mIllustrationId;
private int mIllustrationPreviewId;
private VideoPreference mVideoPreference;
private IllustrationType mIllustrationType;
@Override
public void onAttach(Context context) {
@@ -252,18 +254,41 @@ public abstract class RadioButtonPickerFragment extends SettingsPreferenceFragme
/**
* Allows you to set an illustration at the top of this screen. Set the illustration id to 0
* if you want to remove the illustration.
* @param illustrationId The res id for the raw of the illustration.
* @param previewId The res id for the drawable of the illustration
*
* @param illustrationId The res id for the raw of the illustration.
* @param previewId The res id for the drawable of the illustration.
* @param illustrationType The illustration type for the raw of the illustration.
*/
protected void setIllustration(int illustrationId, int previewId) {
protected void setIllustration(@AnyRes int illustrationId, @AnyRes int previewId,
IllustrationType illustrationType) {
mIllustrationId = illustrationId;
mIllustrationPreviewId = previewId;
mIllustrationType = illustrationType;
}
/**
* Allows you to set an illustration at the top of this screen. Set the illustration id to 0
* if you want to remove the illustration.
*
* @param illustrationId The res id for the raw of the illustration.
* @param illustrationType The illustration type for the raw of the illustration.
*/
protected void setIllustration(@AnyRes int illustrationId, IllustrationType illustrationType) {
setIllustration(illustrationId, 0, illustrationType);
}
private void addIllustration(PreferenceScreen screen) {
mVideoPreference = new VideoPreference(getContext());
mVideoPreference.setVideo(mIllustrationId, mIllustrationPreviewId);
screen.addPreference(mVideoPreference);
switch (mIllustrationType) {
case LOTTIE_ANIMATION:
IllustrationPreference illustrationPreference = new IllustrationPreference(
getContext());
illustrationPreference.setLottieAnimationResId(mIllustrationId);
screen.addPreference(illustrationPreference);
break;
default:
throw new IllegalArgumentException(
"Invalid illustration type: " + mIllustrationType);
}
}
protected abstract List<? extends CandidateInfo> getCandidates();
@@ -284,4 +309,8 @@ public abstract class RadioButtonPickerFragment extends SettingsPreferenceFragme
return 0;
}
protected enum IllustrationType {
LOTTIE_ANIMATION
}
}