2 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.android.settings.profiles.actions.item;
18 import android.content.Context;
19 import android.media.AudioManager;
20 import android.provider.Settings;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.TextView;
26 import cyanogenmod.profiles.StreamSettings;
28 import com.android.settings.R;
29 import com.android.settings.profiles.actions.ItemListAdapter;
31 public class VolumeStreamItem implements Item {
32 private int mStreamId;
33 private StreamSettings mStreamSettings;
34 private boolean mEnabled;
36 public VolumeStreamItem(int streamId, StreamSettings streamSettings) {
38 mStreamSettings = streamSettings;
42 public ItemListAdapter.RowType getRowType() {
43 return ItemListAdapter.RowType.VOLUME_STREAM_ITEM;
47 public boolean isEnabled() {
52 public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
54 if (convertView == null) {
55 view = inflater.inflate(R.layout.list_two_line_item, parent, false);
56 // Do some initialization
61 Context context = inflater.getContext();
62 final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
64 TextView text = (TextView) view.findViewById(R.id.title);
65 text.setText(getNameForStream(mStreamId));
67 TextView desc = (TextView) view.findViewById(R.id.summary);
68 int denominator = mStreamSettings.getValue();
69 int numerator = am.getStreamMaxVolume(mStreamId);
70 if (mStreamSettings.isOverride()) {
71 desc.setText(context.getResources().getString(R.string.volume_override_summary,
72 denominator, numerator));
74 desc.setText(context.getString(R.string.profile_action_none));
77 final boolean volumeLinkNotification = Settings.Secure.getInt(context
78 .getContentResolver(), Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;
80 if (mStreamId == AudioManager.STREAM_NOTIFICATION && volumeLinkNotification) {
82 text.setEnabled(false);
83 desc.setEnabled(false);
89 public static int getNameForStream(int stream) {
91 case AudioManager.STREAM_ALARM:
92 return R.string.alarm_volume_title;
93 case AudioManager.STREAM_MUSIC:
94 return R.string.media_volume_title;
95 case AudioManager.STREAM_RING:
96 return R.string.incoming_call_volume_title;
97 case AudioManager.STREAM_NOTIFICATION:
98 return R.string.notification_volume_title;
103 public int getStreamType() {
107 public StreamSettings getSettings() {
108 return mStreamSettings;