[SQUASH] Bring back Udfps icons and Animations [2/3]
Change-Id: I21db60139dceaa595324a2a35f05ed39006eec66 Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Bring back icon shapes, icon packs, fonts Customisation Signed-off-by: sb6596 <shubhamprince111@gmail.com> Change-Id: I0a80a90faa83d94ec8652fc48faee8e1ae710f09 Signed-off-by: SagarMakhar <sagarmakhar@gmail.com> Signed-off-by: SuperDroidBond <superdroidbond@yahoo.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
25
res/color/option_border_color.xml
Normal file
25
res/color/option_border_color.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2019 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_activated="true"
|
||||
android:color="?android:colorAccent" />
|
||||
<item
|
||||
android:state_activated="false"
|
||||
android:alpha="0.24"
|
||||
android:color="?android:colorAccent" />
|
||||
<item
|
||||
android:alpha="0.05"
|
||||
android:color="@color/option_border_default"/>
|
||||
</selector>
|
||||
19
res/drawable/icon_background.xml
Normal file
19
res/drawable/icon_background.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 AospExtended ROM Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="100dp" />
|
||||
<solid android:color="#FFF" />
|
||||
</shape>
|
||||
21
res/drawable/option_border_custom.xml
Normal file
21
res/drawable/option_border_custom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright (C) 2019 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/shape">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="?android:attr/colorPrimary"/>
|
||||
<corners android:radius="?android:dialogCornerRadius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:drawable="@drawable/option_border_edge_custom" />
|
||||
</layer-list>
|
||||
31
res/drawable/option_border_edge_custom.xml
Normal file
31
res/drawable/option_border_edge_custom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2019 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_activated="true">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke
|
||||
android:color="@color/option_border_color"
|
||||
android:width="4dp" />
|
||||
<corners android:radius="?android:dialogCornerRadius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_activated="false">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke
|
||||
android:color="@color/option_border_color"
|
||||
android:width="4dp" />
|
||||
<corners android:radius="?android:dialogCornerRadius" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
45
res/layout/item_option.xml
Normal file
45
res/layout/item_option.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="7dp"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/option_tile"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingHorizontal="10dp"
|
||||
android:paddingVertical="10dp"
|
||||
android:background="@drawable/option_border_custom">
|
||||
<ImageView
|
||||
android:id="@+id/option_thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/option_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="@style/OptionTitleTextAppearance"/>
|
||||
</LinearLayout>
|
||||
17
res/layout/item_view.xml
Normal file
17
res/layout/item_view.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="7dp"
|
||||
android:paddingRight="7dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -687,5 +687,16 @@
|
||||
<string name="volume_steps_system_title">Volume steps: System</string>
|
||||
<string name="volume_steps_voice_call_title">Volume steps: Voice Call</string>
|
||||
<string name="volume_steps_reset">Reset</string>
|
||||
|
||||
<!-- Udfps animations -->
|
||||
<string name="udfps_category">Udfps</string>
|
||||
<string name="udfps_recog_animation">Udfps animation</string>
|
||||
<string name="udfps_recog_animation_summary">Shows an animation while reading your finger</string>
|
||||
<string name="udfps_recog_animation_effect_title">Udfps animation effect</string>
|
||||
<string name="udfps_recog_animation_effect_summary">Choose animation effect</string>
|
||||
|
||||
<!-- Udfps icon picker -->
|
||||
<string name="udfps_icon_picker_title">Udfps icon picker</string>
|
||||
<string name="udfps_icon_picker_summary">Choose your favorite fingerprint icon</string>
|
||||
|
||||
</resources>
|
||||
|
||||
24
res/values/colors.xml
Normal file
24
res/values/colors.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014-2016 The Dirty Unicorns Project
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<color name="google_grey700">#5f6368</color>
|
||||
<color name="edit_background_base">@color/google_grey700</color>
|
||||
<color name="option_border_default">@color/edit_background_base</color>
|
||||
|
||||
</resources>
|
||||
21
res/values/styles.xml
Normal file
21
res/values/styles.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<style name="OptionTitleTextAppearance" parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title">
|
||||
<item name="android:textAlignment">center</item>
|
||||
<item name="android:textSize">15sp</item>
|
||||
<item name="android:lineHeight">15sp</item>
|
||||
<item name="android:textColor">?android:attr/textColorSecondary</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -91,6 +91,10 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="udfps_category"
|
||||
android:title="@string/udfps_category">
|
||||
|
||||
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="udfps_haptic_feedback"
|
||||
android:title="@string/udfps_haptic_feedback_title"
|
||||
@@ -102,5 +106,19 @@
|
||||
android:title="@string/screen_off_fod_title"
|
||||
android:summary="@string/screen_off_fod_summary"
|
||||
android:defaultValue="true" />
|
||||
|
||||
<Preference
|
||||
android:key="udfps_icon_picker"
|
||||
android:title="@string/udfps_icon_picker_title"
|
||||
android:summary="@string/udfps_icon_picker_summary"
|
||||
android:fragment="com.cherish.settings.fragments.UdfpsIconPicker" />
|
||||
|
||||
<Preference
|
||||
android:key="udfps_recognizing_animation_preview"
|
||||
android:title="@string/udfps_recog_animation_effect_title"
|
||||
android:summary="@string/udfps_recog_animation_effect_summary"
|
||||
android:fragment="com.cherish.settings.fragments.UdfpsAnimation"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import com.android.internal.util.cherish.fod.FodUtils;
|
||||
import com.android.internal.util.cherish.CherishUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -92,11 +93,11 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PreferenceCategory udfps = (PreferenceCategory) prefScreen.findPreference("udfps_category");
|
||||
mFODScreenOff = (SystemSettingSwitchPreference) findPreference(SCREEN_OFF_FOD_KEY);
|
||||
mUdfpsHapticFeedback = (SystemSettingSwitchPreference) findPreference(UDFPS_HAPTIC_FEEDBACK);
|
||||
if (!FodUtils.hasFodSupport(getContext())) {
|
||||
prefScreen.removePreference(mFODScreenOff);
|
||||
prefScreen.removePreference(mUdfpsHapticFeedback);
|
||||
prefScreen.removePreference(udfps);
|
||||
}
|
||||
|
||||
mAODPref = findPreference(AOD_SCHEDULE_KEY);
|
||||
|
||||
264
src/com/cherish/settings/fragments/UdfpsAnimation.java
Normal file
264
src/com/cherish/settings/fragments/UdfpsAnimation.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (C) 2021 AospExtended ROM Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.text.TextUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.net.Uri;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import android.widget.Switch;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class UdfpsAnimation extends SettingsPreferenceFragment implements
|
||||
OnMainSwitchChangeListener {
|
||||
|
||||
private Switch mSwitch;
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private String mPkg = "com.cherish.udfps.resources";
|
||||
private AnimationDrawable animation;
|
||||
|
||||
private Resources udfpsRes;
|
||||
|
||||
private String[] mAnims;
|
||||
private String[] mAnimPreviews;
|
||||
private String[] mTitles;
|
||||
|
||||
private boolean mEnabled;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getActivity().setTitle(R.string.udfps_recog_animation_effect_title);
|
||||
|
||||
loadResources();
|
||||
}
|
||||
|
||||
private void loadResources() {
|
||||
try {
|
||||
PackageManager pm = getActivity().getPackageManager();
|
||||
udfpsRes = pm.getResourcesForApplication(mPkg);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mAnims = udfpsRes.getStringArray(udfpsRes.getIdentifier("udfps_animation_styles",
|
||||
"array", mPkg));
|
||||
mAnimPreviews = udfpsRes.getStringArray(udfpsRes.getIdentifier("udfps_animation_previews",
|
||||
"array", mPkg));
|
||||
mTitles = udfpsRes.getStringArray(udfpsRes.getIdentifier("udfps_animation_titles",
|
||||
"array", mPkg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(
|
||||
R.layout.item_view, container, false);
|
||||
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
|
||||
mRecyclerView.setLayoutManager(gridLayoutManager);
|
||||
UdfpsAnimAdapter mUdfpsAnimAdapter = new UdfpsAnimAdapter(getActivity());
|
||||
mRecyclerView.setAdapter(mUdfpsAnimAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
|
||||
mSwitch = switchBar.getSwitch();
|
||||
mEnabled = Settings.System.getInt(getActivity().getContentResolver(),
|
||||
Settings.System.UDFPS_ANIM, 0) == 1;
|
||||
mSwitch.setChecked(mEnabled);
|
||||
setEnabled(mEnabled);
|
||||
switchBar.setTitle(getActivity().getString(R.string.udfps_recog_animation));
|
||||
switchBar.addOnSwitchChangeListener(this);
|
||||
switchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.UDFPS_ANIM, isChecked ? 1 : 0);
|
||||
setEnabled(isChecked);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
for (int i = 0; i < mRecyclerView.getChildCount(); ++i) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(mRecyclerView.getChildAt(i));
|
||||
holder.itemView.setEnabled(enabled);
|
||||
holder.itemView.findViewById(R.id.option_thumbnail).setAlpha(enabled ? 1f : 0.5f);
|
||||
holder.itemView.findViewById(R.id.option_label).setAlpha(enabled ? 1f : 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public class UdfpsAnimAdapter extends RecyclerView.Adapter<UdfpsAnimAdapter.UdfpsAnimViewHolder> {
|
||||
Context context;
|
||||
String mSelectedAnim;
|
||||
String mAppliedAnim;
|
||||
|
||||
public UdfpsAnimAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UdfpsAnimViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_option, parent, false);
|
||||
UdfpsAnimViewHolder vh = new UdfpsAnimViewHolder(v);
|
||||
return vh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(UdfpsAnimViewHolder holder, final int position) {
|
||||
String animName = mAnims[position];
|
||||
|
||||
Glide.with(holder.image.getContext())
|
||||
.load("")
|
||||
.placeholder(getDrawable(holder.image.getContext(), mAnimPreviews[position]))
|
||||
.into(holder.image);
|
||||
|
||||
holder.name.setText(mTitles[position]);
|
||||
|
||||
if (position == Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.System.UDFPS_ANIM_STYLE, 0)) {
|
||||
mAppliedAnim = animName;
|
||||
if (mSelectedAnim == null) {
|
||||
mSelectedAnim = animName;
|
||||
}
|
||||
}
|
||||
|
||||
holder.itemView.setActivated(animName == mSelectedAnim);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateActivatedStatus(mSelectedAnim, false);
|
||||
updateActivatedStatus(animName, true);
|
||||
mSelectedAnim = animName;
|
||||
holder.image.setBackgroundDrawable(getDrawable(v.getContext(), mAnims[position]));
|
||||
animation = (AnimationDrawable) holder.image.getBackground();
|
||||
animation.setOneShot(true);
|
||||
animation.start();
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.UDFPS_ANIM_STYLE, position);
|
||||
}
|
||||
});
|
||||
|
||||
holder.itemView.setEnabled(mEnabled);
|
||||
holder.itemView.findViewById(R.id.option_thumbnail).setAlpha(mEnabled ? 1f : 0.5f);
|
||||
holder.itemView.findViewById(R.id.option_label).setAlpha(mEnabled ? 1f : 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mAnims.length;
|
||||
}
|
||||
|
||||
public class UdfpsAnimViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView name;
|
||||
ImageView image;
|
||||
public UdfpsAnimViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
name = (TextView) itemView.findViewById(R.id.option_label);
|
||||
image = (ImageView) itemView.findViewById(R.id.option_thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateActivatedStatus(String anim, boolean isActivated) {
|
||||
int index = Arrays.asList(mAnims).indexOf(anim);
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(index);
|
||||
if (holder != null && holder.itemView != null) {
|
||||
holder.itemView.setActivated(isActivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Drawable getDrawable(Context context, String drawableName) {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Resources res = pm.getResourcesForApplication(mPkg);
|
||||
return res.getDrawable(res.getIdentifier(drawableName, "drawable", mPkg));
|
||||
}
|
||||
catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
211
src/com/cherish/settings/fragments/UdfpsIconPicker.java
Normal file
211
src/com/cherish/settings/fragments/UdfpsIconPicker.java
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (C) 2021 AospExtended ROM Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.text.TextUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.net.Uri;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class UdfpsIconPicker extends SettingsPreferenceFragment {
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
private Resources udfpsRes;
|
||||
|
||||
private String mPkg = "com.cherish.udfps.resources";
|
||||
|
||||
private String[] mIcons;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getActivity().setTitle(R.string.udfps_icon_picker_title);
|
||||
|
||||
loadResources();
|
||||
}
|
||||
|
||||
private void loadResources() {
|
||||
try {
|
||||
PackageManager pm = getActivity().getPackageManager();
|
||||
udfpsRes = pm.getResourcesForApplication(mPkg);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mIcons = udfpsRes.getStringArray(udfpsRes.getIdentifier("udfps_icons",
|
||||
"array", mPkg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(
|
||||
R.layout.item_view, container, false);
|
||||
|
||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 3);
|
||||
mRecyclerView.setLayoutManager(gridLayoutManager);
|
||||
UdfpsIconAdapter mUdfpsIconAdapter = new UdfpsIconAdapter(getActivity());
|
||||
mRecyclerView.setAdapter(mUdfpsIconAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
public class UdfpsIconAdapter extends RecyclerView.Adapter<UdfpsIconAdapter.UdfpsIconViewHolder> {
|
||||
Context context;
|
||||
String mSelectedIcon;
|
||||
String mAppliedIcon;
|
||||
|
||||
public UdfpsIconAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UdfpsIconViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_option, parent, false);
|
||||
UdfpsIconViewHolder vh = new UdfpsIconViewHolder(v);
|
||||
return vh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(UdfpsIconViewHolder holder, final int position) {
|
||||
String iconRes = mIcons[position];
|
||||
|
||||
Glide.with(holder.image.getContext())
|
||||
.load("")
|
||||
.placeholder(getDrawable(holder.image.getContext(), mIcons[position]))
|
||||
.into(holder.image);
|
||||
|
||||
holder.image.setPadding(20,20,20,20);
|
||||
|
||||
holder.name.setVisibility(View.GONE);
|
||||
|
||||
if (position == Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.System.UDFPS_ICON, 0)) {
|
||||
mAppliedIcon = iconRes;
|
||||
if (mSelectedIcon == null) {
|
||||
mSelectedIcon = iconRes;
|
||||
}
|
||||
}
|
||||
holder.itemView.setActivated(iconRes == mSelectedIcon);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateActivatedStatus(mSelectedIcon, false);
|
||||
updateActivatedStatus(iconRes, true);
|
||||
mSelectedIcon = iconRes;
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.UDFPS_ICON, position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mIcons.length;
|
||||
}
|
||||
|
||||
public class UdfpsIconViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView name;
|
||||
ImageView image;
|
||||
public UdfpsIconViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
name = (TextView) itemView.findViewById(R.id.option_label);
|
||||
image = (ImageView) itemView.findViewById(R.id.option_thumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateActivatedStatus(String icon, boolean isActivated) {
|
||||
int index = Arrays.asList(mIcons).indexOf(icon);
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(index);
|
||||
if (holder != null && holder.itemView != null) {
|
||||
holder.itemView.setActivated(isActivated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Drawable getDrawable(Context context, String drawableName) {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Resources res = pm.getResourcesForApplication(mPkg);
|
||||
Context ctx = context.createPackageContext(
|
||||
mPkg, Context.CONTEXT_IGNORE_SECURITY);
|
||||
return ctx.getDrawable(res.getIdentifier(drawableName, "drawable", mPkg));
|
||||
}
|
||||
catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user