Cherish: Add signal and wifi icon style theming
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -543,6 +543,10 @@
|
|||||||
<!-- [CHAR_LIMIT=NONE] Developer Settings: Title of the setting which enables overlays to customize the system wide icon pack. -->
|
<!-- [CHAR_LIMIT=NONE] Developer Settings: Title of the setting which enables overlays to customize the system wide icon pack. -->
|
||||||
<string name="theme_customization_icon_pack_title">Icon pack</string>
|
<string name="theme_customization_icon_pack_title">Icon pack</string>
|
||||||
<string name="theme_customization_icon_pack_summary">Set custom icon pack style</string>
|
<string name="theme_customization_icon_pack_summary">Set custom icon pack style</string>
|
||||||
|
<string name="theme_customization_signal_icon_title">Signal icon style</string>
|
||||||
|
<string name="theme_customization_signal_icon_summary">Set custom signal icon style</string>
|
||||||
|
<string name="theme_customization_wifi_icon_title">WiFi icon style</string>
|
||||||
|
<string name="theme_customization_wifi_icon_summary">Set custom wifi icon style</string>
|
||||||
|
|
||||||
<!-- Custom Signal bar icons -->
|
<!-- Custom Signal bar icons -->
|
||||||
<string name="custom_signal_bar_title">Signal</string>
|
<string name="custom_signal_bar_title">Signal</string>
|
||||||
|
|||||||
@@ -49,13 +49,19 @@
|
|||||||
android:summary="@string/theme_customization_icon_shape_summary"
|
android:summary="@string/theme_customization_icon_shape_summary"
|
||||||
android:fragment="com.cherish.settings.fragments.ui.IconShapes"/>
|
android:fragment="com.cherish.settings.fragments.ui.IconShapes"/>
|
||||||
|
|
||||||
<ListPreference
|
<!-- Signal icon style -->
|
||||||
android:key="android.theme.customization.signal_icon"
|
<Preference
|
||||||
android:title="@string/custom_signal_bar_title" />
|
android:key="android.theme.customization.signal_icon"
|
||||||
|
android:title="@string/theme_customization_signal_icon_title"
|
||||||
|
android:summary="@string/theme_customization_signal_icon_summary"
|
||||||
|
android:fragment="com.cherish.settings.fragments.ui.SignalIcons"/>
|
||||||
|
|
||||||
<ListPreference
|
<!-- Wifi icon style -->
|
||||||
android:key="android.theme.customization.wifi_icon"
|
<Preference
|
||||||
android:title="@string/custom_wifi_bar_title" />
|
android:key="android.theme.customization.wifi_icon"
|
||||||
|
android:title="@string/theme_customization_wifi_icon_title"
|
||||||
|
android:summary="@string/theme_customization_wifi_icon_summary"
|
||||||
|
android:fragment="com.cherish.settings.fragments.ui.WifiIcons"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -96,10 +96,6 @@ public class ThemeSettings extends DashboardFragment implements OnPreferenceChan
|
|||||||
Context context, Lifecycle lifecycle, Fragment fragment) {
|
Context context, Lifecycle lifecycle, Fragment fragment) {
|
||||||
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
|
||||||
"android.theme.customization.signal_icon"));
|
|
||||||
controllers.add(new OverlayCategoryPreferenceController(context,
|
|
||||||
"android.theme.customization.wifi_icon"));
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
244
src/com/cherish/settings/fragments/ui/SignalIcons.java
Normal file
244
src/com/cherish/settings/fragments/ui/SignalIcons.java
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 crDroid Android 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.ui;
|
||||||
|
|
||||||
|
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 com.android.internal.util.cherish.ThemeUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
public class SignalIcons extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private ThemeUtils mThemeUtils;
|
||||||
|
private String mCategory = "android.theme.customization.signal_icon";
|
||||||
|
|
||||||
|
private List<String> mPkgs;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
getActivity().setTitle(R.string.theme_customization_signal_icon_title);
|
||||||
|
|
||||||
|
mThemeUtils = new ThemeUtils(getActivity());
|
||||||
|
mPkgs = mThemeUtils.getOverlayPackagesForCategory(mCategory, "android");
|
||||||
|
Collections.sort(mPkgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
Adapter mAdapter = new Adapter(getActivity());
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsEvent.CHERISH_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Adapter extends RecyclerView.Adapter<Adapter.CustomViewHolder> {
|
||||||
|
Context context;
|
||||||
|
String mSelectedPkg;
|
||||||
|
String mAppliedPkg;
|
||||||
|
|
||||||
|
public Adapter(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.icon_option, parent, false);
|
||||||
|
CustomViewHolder vh = new CustomViewHolder(v);
|
||||||
|
return vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(CustomViewHolder holder, final int position) {
|
||||||
|
String iconPkg = mPkgs.get(position);
|
||||||
|
|
||||||
|
holder.image1.setBackgroundDrawable(getDrawable(holder.image1.getContext(), iconPkg, "ic_signal_cellular_0_5_bar"));
|
||||||
|
holder.image2.setBackgroundDrawable(getDrawable(holder.image2.getContext(), iconPkg, "ic_signal_cellular_1_5_bar"));
|
||||||
|
holder.image3.setBackgroundDrawable(getDrawable(holder.image3.getContext(), iconPkg, "ic_signal_cellular_3_5_bar"));
|
||||||
|
holder.image4.setBackgroundDrawable(getDrawable(holder.image4.getContext(), iconPkg, "ic_signal_cellular_5_5_bar"));
|
||||||
|
|
||||||
|
String currentPackageName = mThemeUtils.getOverlayInfos(mCategory).stream()
|
||||||
|
.filter(info -> info.isEnabled())
|
||||||
|
.map(info -> info.packageName)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("android");
|
||||||
|
|
||||||
|
holder.name.setText("android".equals(iconPkg) ? "Default" : getLabel(holder.name.getContext(), iconPkg));
|
||||||
|
|
||||||
|
if (currentPackageName.equals(iconPkg)) {
|
||||||
|
mAppliedPkg = iconPkg;
|
||||||
|
if (mSelectedPkg == null) {
|
||||||
|
mSelectedPkg = iconPkg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.itemView.setActivated(iconPkg == mSelectedPkg);
|
||||||
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
updateActivatedStatus(mSelectedPkg, false);
|
||||||
|
updateActivatedStatus(iconPkg, true);
|
||||||
|
mSelectedPkg = iconPkg;
|
||||||
|
enableOverlays(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mPkgs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CustomViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
TextView name;
|
||||||
|
ImageView image1;
|
||||||
|
ImageView image2;
|
||||||
|
ImageView image3;
|
||||||
|
ImageView image4;
|
||||||
|
public CustomViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
name = (TextView) itemView.findViewById(R.id.option_label);
|
||||||
|
image1 = (ImageView) itemView.findViewById(R.id.image1);
|
||||||
|
image2 = (ImageView) itemView.findViewById(R.id.image2);
|
||||||
|
image3 = (ImageView) itemView.findViewById(R.id.image3);
|
||||||
|
image4 = (ImageView) itemView.findViewById(R.id.image4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateActivatedStatus(String pkg, boolean isActivated) {
|
||||||
|
int index = mPkgs.indexOf(pkg);
|
||||||
|
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 pkg, String drawableName) {
|
||||||
|
try {
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
Resources res = pkg.equals("android") ? Resources.getSystem()
|
||||||
|
: pm.getResourcesForApplication(pkg);
|
||||||
|
int resId = res.getIdentifier(drawableName, "drawable", pkg);
|
||||||
|
if (resId == 0) {
|
||||||
|
return Resources.getSystem().getDrawable(
|
||||||
|
Resources.getSystem().getIdentifier(drawableName, "drawable", "android"));
|
||||||
|
}
|
||||||
|
return res.getDrawable(resId);
|
||||||
|
}
|
||||||
|
catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel(Context context, String pkg) {
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
try {
|
||||||
|
return pm.getApplicationInfo(pkg, 0)
|
||||||
|
.loadLabel(pm).toString();
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return pkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableOverlays(int position) {
|
||||||
|
mThemeUtils.setOverlayEnabled(mCategory, mPkgs.get(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableOverlay(String category, String target, String pattern) {
|
||||||
|
if (pattern.isEmpty()) {
|
||||||
|
mThemeUtils.setOverlayEnabled(category, "android");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String pkg: mThemeUtils.getOverlayPackagesForCategory(category, target)) {
|
||||||
|
if (pkg.contains(pattern)) {
|
||||||
|
mThemeUtils.setOverlayEnabled(category, pkg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
244
src/com/cherish/settings/fragments/ui/WifiIcons.java
Normal file
244
src/com/cherish/settings/fragments/ui/WifiIcons.java
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 crDroid Android 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.ui;
|
||||||
|
|
||||||
|
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 com.android.internal.util.cherish.ThemeUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
public class WifiIcons extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private ThemeUtils mThemeUtils;
|
||||||
|
private String mCategory = "android.theme.customization.wifi_icon";
|
||||||
|
|
||||||
|
private List<String> mPkgs;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
getActivity().setTitle(R.string.theme_customization_wifi_icon_title);
|
||||||
|
|
||||||
|
mThemeUtils = new ThemeUtils(getActivity());
|
||||||
|
mPkgs = mThemeUtils.getOverlayPackagesForCategory(mCategory, "android");
|
||||||
|
Collections.sort(mPkgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
Adapter mAdapter = new Adapter(getActivity());
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsEvent.CHERISH_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Adapter extends RecyclerView.Adapter<Adapter.CustomViewHolder> {
|
||||||
|
Context context;
|
||||||
|
String mSelectedPkg;
|
||||||
|
String mAppliedPkg;
|
||||||
|
|
||||||
|
public Adapter(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.icon_option, parent, false);
|
||||||
|
CustomViewHolder vh = new CustomViewHolder(v);
|
||||||
|
return vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(CustomViewHolder holder, final int position) {
|
||||||
|
String iconPkg = mPkgs.get(position);
|
||||||
|
|
||||||
|
holder.image1.setBackgroundDrawable(getDrawable(holder.image1.getContext(), iconPkg, "ic_wifi_signal_0"));
|
||||||
|
holder.image2.setBackgroundDrawable(getDrawable(holder.image2.getContext(), iconPkg, "ic_wifi_signal_2"));
|
||||||
|
holder.image3.setBackgroundDrawable(getDrawable(holder.image3.getContext(), iconPkg, "ic_wifi_signal_3"));
|
||||||
|
holder.image4.setBackgroundDrawable(getDrawable(holder.image4.getContext(), iconPkg, "ic_wifi_signal_4"));
|
||||||
|
|
||||||
|
String currentPackageName = mThemeUtils.getOverlayInfos(mCategory).stream()
|
||||||
|
.filter(info -> info.isEnabled())
|
||||||
|
.map(info -> info.packageName)
|
||||||
|
.findFirst()
|
||||||
|
.orElse("android");
|
||||||
|
|
||||||
|
holder.name.setText("android".equals(iconPkg) ? "Default" : getLabel(holder.name.getContext(), iconPkg));
|
||||||
|
|
||||||
|
if (currentPackageName.equals(iconPkg)) {
|
||||||
|
mAppliedPkg = iconPkg;
|
||||||
|
if (mSelectedPkg == null) {
|
||||||
|
mSelectedPkg = iconPkg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.itemView.setActivated(iconPkg == mSelectedPkg);
|
||||||
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
updateActivatedStatus(mSelectedPkg, false);
|
||||||
|
updateActivatedStatus(iconPkg, true);
|
||||||
|
mSelectedPkg = iconPkg;
|
||||||
|
enableOverlays(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mPkgs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CustomViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
TextView name;
|
||||||
|
ImageView image1;
|
||||||
|
ImageView image2;
|
||||||
|
ImageView image3;
|
||||||
|
ImageView image4;
|
||||||
|
public CustomViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
name = (TextView) itemView.findViewById(R.id.option_label);
|
||||||
|
image1 = (ImageView) itemView.findViewById(R.id.image1);
|
||||||
|
image2 = (ImageView) itemView.findViewById(R.id.image2);
|
||||||
|
image3 = (ImageView) itemView.findViewById(R.id.image3);
|
||||||
|
image4 = (ImageView) itemView.findViewById(R.id.image4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateActivatedStatus(String pkg, boolean isActivated) {
|
||||||
|
int index = mPkgs.indexOf(pkg);
|
||||||
|
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 pkg, String drawableName) {
|
||||||
|
try {
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
Resources res = pkg.equals("android") ? Resources.getSystem()
|
||||||
|
: pm.getResourcesForApplication(pkg);
|
||||||
|
int resId = res.getIdentifier(drawableName, "drawable", pkg);
|
||||||
|
if (resId == 0) {
|
||||||
|
return Resources.getSystem().getDrawable(
|
||||||
|
Resources.getSystem().getIdentifier(drawableName, "drawable", "android"));
|
||||||
|
}
|
||||||
|
return res.getDrawable(resId);
|
||||||
|
}
|
||||||
|
catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel(Context context, String pkg) {
|
||||||
|
PackageManager pm = context.getPackageManager();
|
||||||
|
try {
|
||||||
|
return pm.getApplicationInfo(pkg, 0)
|
||||||
|
.loadLabel(pm).toString();
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return pkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableOverlays(int position) {
|
||||||
|
mThemeUtils.setOverlayEnabled(mCategory, mPkgs.get(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableOverlay(String category, String target, String pattern) {
|
||||||
|
if (pattern.isEmpty()) {
|
||||||
|
mThemeUtils.setOverlayEnabled(category, "android");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String pkg: mThemeUtils.getOverlayPackagesForCategory(category, target)) {
|
||||||
|
if (pkg.contains(pattern)) {
|
||||||
|
mThemeUtils.setOverlayEnabled(category, pkg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user