Introduce volume styles

This commit is contained in:
elpaablo 2024-06-15 13:08:39 +01:00
parent cad4d44d5b
commit 1f1580d3e9
4 changed files with 268 additions and 0 deletions

View file

@ -0,0 +1,40 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="vertical">
<FrameLayout
android:id="@+id/option_tile"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:layout_gravity="center"
android:paddingHorizontal="10dp"
android:paddingVertical="10dp"
android:background="@drawable/option_border_custom">
<TextView
android:id="@+id/option_label"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="@style/OptionTitleTextAppearance"/>
</FrameLayout>
</LinearLayout>

View file

@ -137,6 +137,11 @@
<string name="theme_customization_notifications_title">Notifications style</string>
<string name="theme_customization_notifications_summary">Set custom notifications style</string>
<!-- Volume panel styles -->
<string name="theme_customization_volume_panel_styles_title">Volume panel style</string>
<string name="theme_customization_volume_panel_styles_summary">Set custom volume panel style</string>
<!-- Extra battery styles -->
<string name="status_bar_battery_style_icon_big_circle">Big circle</string>
<string name="status_bar_battery_style_icon_big_dotted_circle">Big dotted circle</string>

View file

@ -44,6 +44,14 @@
android:summary="@string/volume_steps_summary"
android:fragment="com.alpha.settings.fragments.sound.VolumeSteps" />
<!-- Volume panel styles -->
<Preference
android:key="android.theme.customization.volume_style"
android:icon="@drawable/ic_settings_sound"
android:title="@string/theme_customization_volume_panel_styles_title"
android:summary="@string/theme_customization_volume_panel_styles_summary"
android:fragment="com.alpha.settings.fragments.sound.VolumePanelStyles" />
<!-- Screenshot Sound -->
<com.alpha.settings.preferences.SystemSettingSwitchPreference
android:key="screenshot_shutter_sound"

View file

@ -0,0 +1,215 @@
/*
* Copyright (C) 2023 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.alpha.settings.fragments.sound;
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.os.UserHandle;
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.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 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.crdroid.ThemeUtils;
import java.util.ArrayList;
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 VolumePanelStyles extends SettingsPreferenceFragment {
private RecyclerView mRecyclerView;
private ThemeUtils mThemeUtils;
private String mCategory = "android.theme.customization.volume_style";
private List<String> mPkgs;
@Override
public void onCreate(Bundle savedInstanceState) {
setCategory("android.theme.customization.volume_style");
String title = getContext().getString(R.string.theme_customization_volume_panel_styles_title);
setTitle(title);
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.theme_customization_volume_panel_styles_title);
mThemeUtils = new ThemeUtils(getActivity());
mPkgs = mThemeUtils.getOverlayPackagesForCategory(mCategory, "com.android.systemui");
}
@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(), 1);
mRecyclerView.setLayoutManager(gridLayoutManager);
Adapter mAdapter = new Adapter(getActivity());
mRecyclerView.setAdapter(mAdapter);
return view;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.ALPHA;
}
@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.volume_style_option, parent, false);
CustomViewHolder vh = new CustomViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(CustomViewHolder holder, final int position) {
String navPkg = mPkgs.get(position);
String currentPackageName = mThemeUtils.getOverlayInfos(mCategory, "com.android.systemui").stream()
.filter(info -> info.isEnabled())
.map(info -> info.packageName)
.findFirst()
.orElse("com.android.systemui");
holder.name.setText("com.android.systemui".equals(navPkg) ? "Default" : getLabel(holder.name.getContext(), navPkg));
holder.name.setTextSize(24);
if (currentPackageName.equals(navPkg)) {
mAppliedPkg = navPkg;
if (mSelectedPkg == null) {
mSelectedPkg = navPkg;
}
}
holder.itemView.setActivated(navPkg == mSelectedPkg);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateActivatedStatus(mSelectedPkg, false);
updateActivatedStatus(navPkg, true);
mSelectedPkg = navPkg;
enableOverlays(position);
}
});
}
@Override
public int getItemCount() {
return mPkgs.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
TextView name;
public CustomViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.option_label);
}
}
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 = pm.getResourcesForApplication(pkg);
int resId = res.getIdentifier(drawableName, "drawable", pkg);
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), "com.android.systemui");
}
}