diff options
author | Hongwei Wang <hwwang@google.com> | 2018-02-12 10:29:08 -0800 |
---|---|---|
committer | Hongwei Wang <hwwang@google.com> | 2018-02-16 18:31:20 -0800 |
commit | 33707a9d6e5beb03c5ae010e661035f820cc4bb8 (patch) | |
tree | 0752a73150d6dfbfce5a9eaeaf7fb62bd36d7bbc /service/src/com/android/car/CarVolumeGroupsHelper.java | |
parent | 3e1b71d5709d3a844bcc2812dd993a6ce3cdd0a0 (diff) | |
download | Car-33707a9d6e5beb03c5ae010e661035f820cc4bb8.tar.gz |
Switches volume control to groupId based
New APIs added
- getVolumeGroupForUsage(int)
- getGroup{Min,Max,}Volume(int)
- setGroupVolume(int)
Old APIs removed
- getUsage{Min,Max,}Volume
- setUsageVolume
Known issue
- No volume sliders in Mojave board since there is no volume group configured
Adds also the validation pass for volume groups configuration
Bug: 72555604
Test: run Car Settings in emulator
Change-Id: I2507a45f2771e26fedc5cfbdb017023fa3d67d46
Diffstat (limited to 'service/src/com/android/car/CarVolumeGroupsHelper.java')
-rw-r--r-- | service/src/com/android/car/CarVolumeGroupsHelper.java | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/service/src/com/android/car/CarVolumeGroupsHelper.java b/service/src/com/android/car/CarVolumeGroupsHelper.java index 86e0a8944a..af2c6ddb93 100644 --- a/service/src/com/android/car/CarVolumeGroupsHelper.java +++ b/service/src/com/android/car/CarVolumeGroupsHelper.java @@ -16,9 +16,7 @@ package com.android.car; import android.annotation.XmlRes; -import android.car.media.CarVolumeGroup; import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.util.AttributeSet; @@ -37,17 +35,17 @@ import java.util.List; private static final String TAG_GROUP = "group"; private static final String TAG_CONTEXT = "context"; - private final Resources mResources; + private final Context mContext; private final @XmlRes int mXmlConfiguration; CarVolumeGroupsHelper(Context context, @XmlRes int xmlConfiguration) { - mResources = context.getResources(); + mContext = context; mXmlConfiguration = xmlConfiguration; } CarVolumeGroup[] loadVolumeGroups() { List<CarVolumeGroup> carVolumeGroups = new ArrayList<>(); - try (XmlResourceParser parser = mResources.getXml(mXmlConfiguration)) { + try (XmlResourceParser parser = mContext.getResources().getXml(mXmlConfiguration)) { AttributeSet attrs = Xml.asAttributeSet(parser); int type; // Traverse to the first start tag @@ -59,13 +57,15 @@ import java.util.List; throw new RuntimeException("Meta-data does not start with volumeGroups tag"); } int outerDepth = parser.getDepth(); + int id = 0; while ((type=parser.next()) != XmlResourceParser.END_DOCUMENT && (type != XmlResourceParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlResourceParser.END_TAG) { continue; } if (TAG_GROUP.equals(parser.getName())) { - carVolumeGroups.add(parseVolumeGroup(attrs, parser)); + carVolumeGroups.add(parseVolumeGroup(id, attrs, parser)); + id++; } } } catch (Exception e) { @@ -74,12 +74,9 @@ import java.util.List; return carVolumeGroups.toArray(new CarVolumeGroup[carVolumeGroups.size()]); } - private CarVolumeGroup parseVolumeGroup(AttributeSet attrs, XmlResourceParser parser) + private CarVolumeGroup parseVolumeGroup(int id, AttributeSet attrs, XmlResourceParser parser) throws XmlPullParserException, IOException { int type; - TypedArray a = mResources.obtainAttributes(attrs, R.styleable.volumeGroups_group); - String title = a.getString(R.styleable.volumeGroups_group_name); - a.recycle(); List<Integer> contexts = new ArrayList<>(); int innerDepth = parser.getDepth(); @@ -89,14 +86,14 @@ import java.util.List; continue; } if (TAG_CONTEXT.equals(parser.getName())) { - TypedArray c = mResources.obtainAttributes( + TypedArray c = mContext.getResources().obtainAttributes( attrs, R.styleable.volumeGroups_context); contexts.add(c.getInt(R.styleable.volumeGroups_context_context, -1)); c.recycle(); } } - return new CarVolumeGroup(title, + return new CarVolumeGroup(mContext, id, contexts.stream().mapToInt(i -> i).filter(i -> i >= 0).toArray()); } } |