Cherish:AOKP custom system animations [2/2]

- Work by AOKP team and ported by @cristianomatos @crdroidandroid

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Stevespear426
2018-09-13 20:19:48 +05:30
committed by Hưng Phan
parent fd8b4b59fa
commit 608b76ded5
3 changed files with 257 additions and 15 deletions

View File

@@ -16,53 +16,230 @@
package com.cherish.settings.fragments;
import android.app.Activity;
import android.content.Context;
import android.content.ContentResolver;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.View;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.SwitchPreference;
import android.provider.Settings;
import android.view.View;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.cherish.settings.preferences.CustomSeekBarPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.cherish.AwesomeAnimationHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
public class AnimationsSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
public class AnimationsSettings extends SettingsPreferenceFragment
implements OnPreferenceChangeListener {
private static final String ACTIVITY_OPEN = "activity_open";
private static final String ACTIVITY_CLOSE = "activity_close";
private static final String TASK_OPEN = "task_open";
private static final String TASK_CLOSE = "task_close";
private static final String TASK_MOVE_TO_FRONT = "task_move_to_front";
private static final String TASK_MOVE_TO_BACK = "task_move_to_back";
private static final String ANIMATION_NO_OVERRIDE = "animation_no_override";
private static final String WALLPAPER_OPEN = "wallpaper_open";
private static final String WALLPAPER_CLOSE = "wallpaper_close";
private static final String WALLPAPER_INTRA_OPEN = "wallpaper_intra_open";
private static final String WALLPAPER_INTRA_CLOSE = "wallpaper_intra_close";
ListPreference mActivityOpenPref;
ListPreference mActivityClosePref;
ListPreference mTaskOpenPref;
ListPreference mTaskClosePref;
ListPreference mTaskMoveToFrontPref;
ListPreference mTaskMoveToBackPref;
ListPreference mWallpaperOpen;
ListPreference mWallpaperClose;
ListPreference mWallpaperIntraOpen;
ListPreference mWallpaperIntraClose;
private int[] mAnimations;
private String[] mAnimationsStrings;
private String[] mAnimationsNum;
private Context mContext;
@Override
public int getMetricsCategory() {
return MetricsEvent.CHERISH_SETTINGS;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.cherish_settings_animations);
ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefs = getPreferenceScreen();
mContext = getActivity();
mAnimations = AwesomeAnimationHelper.getAnimationsList();
int animqty = mAnimations.length;
mAnimationsStrings = new String[animqty];
mAnimationsNum = new String[animqty];
for (int i = 0; i < animqty; i++) {
mAnimationsStrings[i] = AwesomeAnimationHelper.getProperName(mContext, mAnimations[i]);
mAnimationsNum[i] = String.valueOf(mAnimations[i]);
}
mActivityOpenPref = (ListPreference) findPreference(ACTIVITY_OPEN);
mActivityOpenPref.setOnPreferenceChangeListener(this);
mActivityOpenPref.setSummary(getProperSummary(mActivityOpenPref));
mActivityOpenPref.setEntries(mAnimationsStrings);
mActivityOpenPref.setEntryValues(mAnimationsNum);
mActivityClosePref = (ListPreference) findPreference(ACTIVITY_CLOSE);
mActivityClosePref.setOnPreferenceChangeListener(this);
mActivityClosePref.setSummary(getProperSummary(mActivityClosePref));
mActivityClosePref.setEntries(mAnimationsStrings);
mActivityClosePref.setEntryValues(mAnimationsNum);
mTaskOpenPref = (ListPreference) findPreference(TASK_OPEN);
mTaskOpenPref.setOnPreferenceChangeListener(this);
mTaskOpenPref.setSummary(getProperSummary(mTaskOpenPref));
mTaskOpenPref.setEntries(mAnimationsStrings);
mTaskOpenPref.setEntryValues(mAnimationsNum);
mTaskClosePref = (ListPreference) findPreference(TASK_CLOSE);
mTaskClosePref.setOnPreferenceChangeListener(this);
mTaskClosePref.setSummary(getProperSummary(mTaskClosePref));
mTaskClosePref.setEntries(mAnimationsStrings);
mTaskClosePref.setEntryValues(mAnimationsNum);
mTaskMoveToFrontPref = (ListPreference) findPreference(TASK_MOVE_TO_FRONT);
mTaskMoveToFrontPref.setOnPreferenceChangeListener(this);
mTaskMoveToFrontPref.setSummary(getProperSummary(mTaskMoveToFrontPref));
mTaskMoveToFrontPref.setEntries(mAnimationsStrings);
mTaskMoveToFrontPref.setEntryValues(mAnimationsNum);
mTaskMoveToBackPref = (ListPreference) findPreference(TASK_MOVE_TO_BACK);
mTaskMoveToBackPref.setOnPreferenceChangeListener(this);
mTaskMoveToBackPref.setSummary(getProperSummary(mTaskMoveToBackPref));
mTaskMoveToBackPref.setEntries(mAnimationsStrings);
mTaskMoveToBackPref.setEntryValues(mAnimationsNum);
mWallpaperOpen = (ListPreference) findPreference(WALLPAPER_OPEN);
mWallpaperOpen.setOnPreferenceChangeListener(this);
mWallpaperOpen.setSummary(getProperSummary(mWallpaperOpen));
mWallpaperOpen.setEntries(mAnimationsStrings);
mWallpaperOpen.setEntryValues(mAnimationsNum);
mWallpaperClose = (ListPreference) findPreference(WALLPAPER_CLOSE);
mWallpaperClose.setOnPreferenceChangeListener(this);
mWallpaperClose.setSummary(getProperSummary(mWallpaperClose));
mWallpaperClose.setEntries(mAnimationsStrings);
mWallpaperClose.setEntryValues(mAnimationsNum);
mWallpaperIntraOpen = (ListPreference) findPreference(WALLPAPER_INTRA_OPEN);
mWallpaperIntraOpen.setOnPreferenceChangeListener(this);
mWallpaperIntraOpen.setSummary(getProperSummary(mWallpaperIntraOpen));
mWallpaperIntraOpen.setEntries(mAnimationsStrings);
mWallpaperIntraOpen.setEntryValues(mAnimationsNum);
mWallpaperIntraClose = (ListPreference) findPreference(WALLPAPER_INTRA_CLOSE);
mWallpaperIntraClose.setOnPreferenceChangeListener(this);
mWallpaperIntraClose.setSummary(getProperSummary(mWallpaperIntraClose));
mWallpaperIntraClose.setEntries(mAnimationsStrings);
mWallpaperIntraClose.setEntryValues(mAnimationsNum);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
return false;
ContentResolver resolver = getActivity().getContentResolver();
boolean result = false;
if (preference == mActivityOpenPref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[0], val);
} else if (preference == mActivityClosePref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[1], val);
} else if (preference == mTaskOpenPref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[2], val);
} else if (preference == mTaskClosePref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[3], val);
} else if (preference == mTaskMoveToFrontPref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[4], val);
} else if (preference == mTaskMoveToBackPref) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[5], val);
} else if (preference == mWallpaperOpen) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[6], val);
} else if (preference == mWallpaperClose) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[7], val);
} else if (preference == mWallpaperIntraOpen) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[8], val);
} else if (preference == mWallpaperIntraClose) {
int val = Integer.parseInt((String) newValue);
result = Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ACTIVITY_ANIMATION_CONTROLS[9], val);
}
preference.setSummary(getProperSummary(preference));
return result;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
private String getProperSummary(Preference preference) {
String mString = "";
if (preference == mActivityOpenPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[0];
} else if (preference == mActivityClosePref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[1];
} else if (preference == mTaskOpenPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[2];
} else if (preference == mTaskClosePref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[3];
} else if (preference == mTaskMoveToFrontPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[4];
} else if (preference == mTaskMoveToBackPref) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[5];
} else if (preference == mWallpaperOpen) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[6];
} else if (preference == mWallpaperClose) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[7];
} else if (preference == mWallpaperIntraOpen) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[8];
} else if (preference == mWallpaperIntraClose) {
mString = Settings.Global.ACTIVITY_ANIMATION_CONTROLS[9];
}
int mNum = Settings.Global.getInt(mContext.getContentResolver(), mString, 0);
return mAnimationsStrings[mNum];
}
}
}