OSDN Git Service

Merge tag 'android-6.0.1_r74' into HEAD
[android-x86/packages-apps-Settings.git] / src / com / android / settings / profiles / actions / item / VolumeStreamItem.java
1 /*
2  * Copyright (C) 2014 The CyanogenMod Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.android.settings.profiles.actions.item;
17
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;
25
26 import cyanogenmod.profiles.StreamSettings;
27
28 import com.android.settings.R;
29 import com.android.settings.profiles.actions.ItemListAdapter;
30
31 public class VolumeStreamItem implements Item {
32     private int mStreamId;
33     private StreamSettings mStreamSettings;
34     private boolean mEnabled;
35
36     public VolumeStreamItem(int streamId, StreamSettings streamSettings) {
37         mStreamId = streamId;
38         mStreamSettings = streamSettings;
39     }
40
41     @Override
42     public ItemListAdapter.RowType getRowType() {
43         return ItemListAdapter.RowType.VOLUME_STREAM_ITEM;
44     }
45
46     @Override
47     public boolean isEnabled() {
48         return mEnabled;
49     }
50
51     @Override
52     public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) {
53         View view;
54         if (convertView == null) {
55             view = inflater.inflate(R.layout.list_two_line_item, parent, false);
56             // Do some initialization
57         } else {
58             view = convertView;
59         }
60
61         Context context = inflater.getContext();
62         final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
63
64         TextView text = (TextView) view.findViewById(R.id.title);
65         text.setText(getNameForStream(mStreamId));
66
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));
73         } else {
74             desc.setText(context.getString(R.string.profile_action_none));
75         }
76
77         final boolean volumeLinkNotification = Settings.Secure.getInt(context
78                 .getContentResolver(), Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;
79         mEnabled = true;
80         if (mStreamId == AudioManager.STREAM_NOTIFICATION && volumeLinkNotification) {
81             mEnabled = false;
82             text.setEnabled(false);
83             desc.setEnabled(false);
84         }
85
86         return view;
87     }
88
89     public static int getNameForStream(int stream) {
90         switch (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;
99             default: return 0;
100         }
101     }
102
103     public int getStreamType() {
104         return mStreamId;
105     }
106
107     public StreamSettings getSettings() {
108         return mStreamSettings;
109     }
110 }