1 /*
2  * Copyright (C) 2018 The Android Open Source 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 
17 package com.android.settings.homepage.contextualcards.conditional;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.media.AudioManager;
22 
23 import com.android.settings.R;
24 import com.android.settings.homepage.contextualcards.ContextualCard;
25 
26 import java.util.Objects;
27 
28 public class RingerMutedConditionController extends AbnormalRingerConditionController {
29     static final int ID = Objects.hash("RingerMutedConditionController");
30 
31     private final Context mAppContext;
32 
RingerMutedConditionController(Context appContext, ConditionManager conditionManager)33     public RingerMutedConditionController(Context appContext, ConditionManager conditionManager) {
34         super(appContext, conditionManager);
35         mAppContext = appContext;
36     }
37 
38     @Override
getId()39     public long getId() {
40         return ID;
41     }
42 
43     @Override
isDisplayable()44     public boolean isDisplayable() {
45         return mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
46     }
47 
48     @Override
buildContextualCard()49     public ContextualCard buildContextualCard() {
50         return new ConditionalContextualCard.Builder()
51                 .setConditionId(ID)
52                 .setMetricsConstant(SettingsEnums.SETTINGS_CONDITION_DEVICE_MUTED)
53                 .setActionText(
54                         mAppContext.getText(R.string.condition_device_muted_action_turn_on_sound))
55                 .setName(mAppContext.getPackageName() + "/"
56                         + mAppContext.getText(R.string.condition_device_muted_title))
57                 .setTitleText(mAppContext.getText(R.string.condition_device_muted_title).toString())
58                 .setSummaryText(
59                         mAppContext.getText(R.string.condition_device_muted_summary).toString())
60                 .setIconDrawable(mAppContext.getDrawable(R.drawable.ic_notifications_off_24dp))
61                 .setViewType(ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH)
62                 .build();
63     }
64 }
65