Settings: support per-app volume [3/3]
Change-Id: I3e72a4b0fda68a5cd1e9a35fc161a1d7ddae6d7e Signed-off-by: AnierinB <anierin@evolution-x.org> Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -5085,6 +5085,10 @@
|
|||||||
<action android:name="android.settings.panel.action.VOLUME" />
|
<action android:name="android.settings.panel.action.VOLUME" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.settings.panel.action.APP_VOLUME" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".wifi.addappnetworks.AddAppNetworksActivity"
|
<activity android:name=".wifi.addappnetworks.AddAppNetworksActivity"
|
||||||
|
|||||||
@@ -72,4 +72,9 @@
|
|||||||
<string name="private_dns_mode_quad9_unsecured_ecs" translatable="false">Quad9 Unsecured with ECS DNS</string>
|
<string name="private_dns_mode_quad9_unsecured_ecs" translatable="false">Quad9 Unsecured with ECS DNS</string>
|
||||||
<!-- Quad9 Unsecured ECS DNS hostname -->
|
<!-- Quad9 Unsecured ECS DNS hostname -->
|
||||||
<string name="private_dns_hostname_quad9_unsecured_ecs" translatable="false">dns12.quad9.net</string>
|
<string name="private_dns_hostname_quad9_unsecured_ecs" translatable="false">dns12.quad9.net</string>
|
||||||
|
|
||||||
|
<!-- Per-app volume -->
|
||||||
|
<string name="app_volume">App volume</string>
|
||||||
|
<string name="app_volume_title">Per-app volume control</string>
|
||||||
|
<string name="app_volume_summary">Show per-app volume button into volume dialog</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -168,6 +168,13 @@
|
|||||||
android:ringtoneType="alarm"
|
android:ringtoneType="alarm"
|
||||||
android:order="-60"/>
|
android:order="-60"/>
|
||||||
|
|
||||||
|
<org.evolution.settings.preferences.SystemSettingSwitchPreference
|
||||||
|
android:key="show_app_volume"
|
||||||
|
android:title="@string/app_volume_title"
|
||||||
|
android:summary="@string/app_volume_summary"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:order="-5"/>
|
||||||
|
|
||||||
<!-- Dial pad tones -->
|
<!-- Dial pad tones -->
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:key="dtmf_tone"
|
android:key="dtmf_tone"
|
||||||
|
|||||||
150
src/com/android/settings/media/AppVolumeSlice.java
Normal file
150
src/com/android/settings/media/AppVolumeSlice.java
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Project Kaleidoscope
|
||||||
|
*
|
||||||
|
* 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.android.settings.media;
|
||||||
|
|
||||||
|
import static android.app.slice.Slice.EXTRA_RANGE_VALUE;
|
||||||
|
import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
|
||||||
|
|
||||||
|
import static com.android.settings.slices.CustomSliceRegistry.APP_VOLUME_SLICE_URI;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.AppVolume;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.core.graphics.drawable.IconCompat;
|
||||||
|
import androidx.slice.Slice;
|
||||||
|
import androidx.slice.builders.ListBuilder;
|
||||||
|
import androidx.slice.builders.ListBuilder.InputRangeBuilder;
|
||||||
|
import androidx.slice.builders.SliceAction;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.slices.CustomSliceable;
|
||||||
|
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AppVolumeSlice implements CustomSliceable {
|
||||||
|
|
||||||
|
private static final String TAG = "AppVolumeSlice";
|
||||||
|
private static final String PACKAGE_NAME = "package_name";
|
||||||
|
private static final String ACTION_LAUNCH_DIALOG = "action_launch_dialog";
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final AudioManager mAudioManager;
|
||||||
|
|
||||||
|
public AppVolumeSlice(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
mAudioManager = context.getSystemService(AudioManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNotifyChange(Intent intent) {
|
||||||
|
final int newPosition = intent.getIntExtra(EXTRA_RANGE_VALUE, -1);
|
||||||
|
final String packageName = intent.getStringExtra(PACKAGE_NAME);
|
||||||
|
if (!TextUtils.isEmpty(packageName)) {
|
||||||
|
mAudioManager.setAppVolume(packageName, newPosition / 100.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Slice getSlice() {
|
||||||
|
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||||
|
.setAccentColor(COLOR_NOT_TINTED);
|
||||||
|
|
||||||
|
// Only displaying active tracks
|
||||||
|
final List<AppVolume> appVols = new ArrayList<>();
|
||||||
|
for (AppVolume vol : mAudioManager.listAppVolumes()) {
|
||||||
|
if (vol.isActive()) {
|
||||||
|
appVols.add(vol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appVols.isEmpty()) {
|
||||||
|
Log.d(TAG, "No active tracks");
|
||||||
|
return listBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (AppVolume vol : appVols) {
|
||||||
|
final CharSequence appName = Utils.getApplicationLabel(
|
||||||
|
mContext, vol.getPackageName());
|
||||||
|
IconCompat icon = getApplicationIcon(vol.getPackageName());
|
||||||
|
final SliceAction primarySliceAction = SliceAction.create(
|
||||||
|
getBroadcastIntent(mContext), icon, ListBuilder.ICON_IMAGE, appName);
|
||||||
|
listBuilder.addInputRange(new InputRangeBuilder()
|
||||||
|
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||||
|
.setTitle(appName)
|
||||||
|
.setInputAction(getSliderInputAction(vol.getPackageName()))
|
||||||
|
.setMax(100)
|
||||||
|
.setValue((int)(vol.getVolume() * 100))
|
||||||
|
.setPrimaryAction(primarySliceAction));
|
||||||
|
}
|
||||||
|
return listBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IconCompat getApplicationIcon(String packageName) {
|
||||||
|
PackageManager pm = mContext.getPackageManager();
|
||||||
|
try {
|
||||||
|
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
|
||||||
|
Resources resources = pm.getResourcesForApplication(ai);
|
||||||
|
IconCompat icon = IconCompat.createWithResource(resources, packageName, ai.icon);
|
||||||
|
return icon;
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
Log.e(TAG, "Failed to get icon of " + packageName, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
||||||
|
return IconCompat.createWithBitmap(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private PendingIntent getSliderInputAction(String packageName) {
|
||||||
|
final int requestCode = packageName.hashCode();
|
||||||
|
final Intent intent = new Intent(getUri().toString())
|
||||||
|
.setData(getUri())
|
||||||
|
.putExtra(PACKAGE_NAME, packageName)
|
||||||
|
.setClass(mContext, SliceBroadcastReceiver.class);
|
||||||
|
return PendingIntent.getBroadcast(mContext, requestCode, intent,
|
||||||
|
PendingIntent.FLAG_MUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uri getUri() {
|
||||||
|
return APP_VOLUME_SLICE_URI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Intent getIntent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_sound;
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/com/android/settings/panel/AppVolumePanel.java
Normal file
65
src/com/android/settings/panel/AppVolumePanel.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Project Kaleidoscope
|
||||||
|
*
|
||||||
|
* 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.android.settings.panel;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.slices.CustomSliceRegistry;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AppVolumePanel implements PanelContent {
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
public static AppVolumePanel create(Context context) {
|
||||||
|
return new AppVolumePanel(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AppVolumePanel(Context context) {
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getTitle() {
|
||||||
|
return mContext.getText(R.string.app_volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Uri> getSlices() {
|
||||||
|
final List<Uri> uris = new ArrayList<>();
|
||||||
|
uris.add(CustomSliceRegistry.APP_VOLUME_SLICE_URI);
|
||||||
|
return uris;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.PANEL_VOLUME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Intent getSeeMoreIntent() {
|
||||||
|
return new Intent(Settings.ACTION_SOUND_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -87,6 +87,8 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
|||||||
return VolumePanel.create(context);
|
return VolumePanel.create(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case Settings.Panel.ACTION_APP_VOLUME:
|
||||||
|
return AppVolumePanel.create(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException("No matching panel for: " + panelType);
|
throw new IllegalStateException("No matching panel for: " + panelType);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.android.settings.homepage.contextualcards.slices.DarkThemeSlice;
|
|||||||
import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
|
import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
|
||||||
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
||||||
import com.android.settings.location.LocationSlice;
|
import com.android.settings.location.LocationSlice;
|
||||||
|
import com.android.settings.media.AppVolumeSlice;
|
||||||
import com.android.settings.media.MediaOutputIndicatorSlice;
|
import com.android.settings.media.MediaOutputIndicatorSlice;
|
||||||
import com.android.settings.media.RemoteMediaSlice;
|
import com.android.settings.media.RemoteMediaSlice;
|
||||||
import com.android.settings.network.ProviderModelSlice;
|
import com.android.settings.network.ProviderModelSlice;
|
||||||
@@ -291,6 +292,16 @@ public class CustomSliceRegistry {
|
|||||||
.appendPath("always_on_display")
|
.appendPath("always_on_display")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backing Uri for the App Volume Slice.
|
||||||
|
*/
|
||||||
|
public static Uri APP_VOLUME_SLICE_URI = new Uri.Builder()
|
||||||
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
|
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
|
.appendPath("app_volume")
|
||||||
|
.build();
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final Map<Uri, Class<? extends CustomSliceable>> sUriToSlice;
|
static final Map<Uri, Class<? extends CustomSliceable>> sUriToSlice;
|
||||||
|
|
||||||
@@ -305,6 +316,7 @@ public class CustomSliceRegistry {
|
|||||||
sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class);
|
sUriToSlice.put(ALWAYS_ON_SLICE_URI, AlwaysOnDisplaySlice.class);
|
||||||
sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
|
sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
|
||||||
sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
|
sUriToSlice.put(REMOTE_MEDIA_SLICE_URI, RemoteMediaSlice.class);
|
||||||
|
sUriToSlice.put(APP_VOLUME_SLICE_URI, AppVolumeSlice.class);
|
||||||
|
|
||||||
// Slices for contextual card.
|
// Slices for contextual card.
|
||||||
sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
|
sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user