Cherish: Custom FOD Icon [2/2]
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -483,6 +483,12 @@
|
||||
<!-- Udfps Haptic Feedback -->
|
||||
<string name="udfps_haptic_feedback_title">FOD haptic feedback</string>
|
||||
<string name="udfps_haptic_feedback_summary">Vibrate when touching FOD icon</string>
|
||||
|
||||
<!-- Custom FOD Icon -->
|
||||
<string name="custom_fp_icon_title">Custom UDFPS Icon</string>
|
||||
<string name="custom_fp_icon_summary">Enable custom UDFPS Icon from files</string>
|
||||
<string name="custom_fp_select_title">Select Custom UDFPS Icon</string>
|
||||
<string name="custom_fp_select_summary">Select custom image from your saved files or gallery</string>
|
||||
|
||||
<!-- Location privacy indicator -->
|
||||
<string name="location_privacy_indicator_title">Show privacy indicator for location</string>
|
||||
|
||||
@@ -31,6 +31,20 @@
|
||||
android:key="udfps_customization"
|
||||
android:title="UDFPS Customization">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="custom_fp_icon_enabled"
|
||||
android:title="@string/custom_fp_icon_title"
|
||||
android:summary="@string/custom_fp_icon_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<Preference
|
||||
android:key="custom_fp_file_select"
|
||||
android:title="@string/custom_fp_select_title"
|
||||
android:summary="@string/custom_fp_select_summary"
|
||||
android:dependency="custom_fp_icon_enabled"
|
||||
android:persistent="false" >
|
||||
</Preference>
|
||||
|
||||
<Preference
|
||||
android:key="udfps_icon_picker"
|
||||
android:title="@string/udfps_icon_picker_title"
|
||||
|
||||
@@ -27,8 +27,16 @@ import android.app.WallpaperManager;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
@@ -38,6 +46,7 @@ import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
@@ -45,10 +54,25 @@ import com.android.internal.util.cherish.fod.FodUtils;
|
||||
import com.android.internal.util.cherish.CherishUtils;
|
||||
|
||||
import com.cherish.settings.preferences.SystemSettingSwitchPreference;
|
||||
import com.cherish.settings.fragments.UdfpsIconPicker;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class UdfpsSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String CUSTOM_FOD_ICON_KEY = "custom_fp_icon_enabled";
|
||||
private static final String CUSTOM_FP_FILE_SELECT = "custom_fp_file_select";
|
||||
private static final int REQUEST_PICK_IMAGE = 0;
|
||||
|
||||
private Preference mCustomFPImage;
|
||||
private SystemSettingSwitchPreference mCustomFodIcon;
|
||||
private Preference mUdfpsIconPicker;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -57,19 +81,88 @@ public class UdfpsSettings extends SettingsPreferenceFragment implements
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
Resources resources = getResources();
|
||||
|
||||
/**
|
||||
boolean udfpsResPkgInstalled = CherishUtils.isPackageInstalled(getContext(),
|
||||
"com.cherish.udfps.resources");
|
||||
PreferenceCategory udfps_custom = (PreferenceCategory) prefScreen.findPreference("udfps_customization");
|
||||
if (!udfpsResPkgInstalled) {
|
||||
prefScreen.removePreference(udfps_custom);
|
||||
PreferenceCategory udfps_custom = (PreferenceCategory) prefScreen.findPreference("udfps_customization");*/
|
||||
|
||||
mUdfpsIconPicker = (Preference) prefScreen.findPreference("udfps_icon_picker");
|
||||
|
||||
mCustomFPImage = findPreference(CUSTOM_FP_FILE_SELECT);
|
||||
final String customIconURI = Settings.System.getString(getContext().getContentResolver(),
|
||||
Settings.System.OMNI_CUSTOM_FP_ICON);
|
||||
if (!TextUtils.isEmpty(customIconURI)) {
|
||||
setPickerIcon(customIconURI);
|
||||
}
|
||||
|
||||
mCustomFodIcon = (SystemSettingSwitchPreference) findPreference(CUSTOM_FOD_ICON_KEY);
|
||||
boolean val = Settings.System.getIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.OMNI_CUSTOM_FP_ICON_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
||||
mCustomFodIcon.setOnPreferenceChangeListener(this);
|
||||
if (val) {
|
||||
mUdfpsIconPicker.setEnabled(false);
|
||||
} else {
|
||||
mUdfpsIconPicker.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference == mCustomFPImage) {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK);
|
||||
intent.setType("image/*");
|
||||
startActivityForResult(intent, REQUEST_PICK_IMAGE);
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
if (preference == mCustomFodIcon) {
|
||||
boolean val = (Boolean) newValue;
|
||||
Settings.System.putIntForUser(getActivity().getContentResolver(),
|
||||
Settings.System.OMNI_CUSTOM_FP_ICON_ENABLED, val ? 1 : 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
if (val) {
|
||||
mUdfpsIconPicker.setEnabled(false);
|
||||
} else {
|
||||
mUdfpsIconPicker.setEnabled(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent result) {
|
||||
if (requestCode == REQUEST_PICK_IMAGE && resultCode == Activity.RESULT_OK) {
|
||||
Uri uri = null;
|
||||
if (result != null) {
|
||||
uri = result.getData();
|
||||
setPickerIcon(uri.toString());
|
||||
Settings.System.putString(getContentResolver(), Settings.System.OMNI_CUSTOM_FP_ICON,
|
||||
uri.toString());
|
||||
}
|
||||
} else if (requestCode == REQUEST_PICK_IMAGE && resultCode == Activity.RESULT_CANCELED) {
|
||||
mCustomFPImage.setIcon(new ColorDrawable(Color.TRANSPARENT));
|
||||
Settings.System.putString(getContentResolver(), Settings.System.OMNI_CUSTOM_FP_ICON, "");
|
||||
}
|
||||
}
|
||||
|
||||
private void setPickerIcon(String uri) {
|
||||
try {
|
||||
ParcelFileDescriptor parcelFileDescriptor =
|
||||
getContext().getContentResolver().openFileDescriptor(Uri.parse(uri), "r");
|
||||
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
|
||||
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
||||
parcelFileDescriptor.close();
|
||||
Drawable d = new BitmapDrawable(getResources(), image);
|
||||
mCustomFPImage.setIcon(d);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
|
||||
Reference in New Issue
Block a user