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 RingerVibrateConditionController extends AbnormalRingerConditionController { 29 static final int ID = Objects.hash("RingerVibrateConditionController"); 30 31 private final Context mAppContext; 32 RingerVibrateConditionController(Context appContext, ConditionManager conditionManager)33 public RingerVibrateConditionController(Context appContext, ConditionManager conditionManager) { 34 super(appContext, conditionManager); 35 mAppContext = appContext; 36 37 } 38 39 @Override getId()40 public long getId() { 41 return ID; 42 } 43 44 @Override isDisplayable()45 public boolean isDisplayable() { 46 return mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE; 47 } 48 49 @Override buildContextualCard()50 public ContextualCard buildContextualCard() { 51 return new ConditionalContextualCard.Builder() 52 .setConditionId(ID) 53 .setMetricsConstant(SettingsEnums.SETTINGS_CONDITION_DEVICE_VIBRATE) 54 .setActionText( 55 mAppContext.getText(R.string.condition_device_muted_action_turn_on_sound)) 56 .setName(mAppContext.getPackageName() + "/" 57 + mAppContext.getText(R.string.condition_device_vibrate_title)) 58 .setTitleText( 59 mAppContext.getText(R.string.condition_device_vibrate_title).toString()) 60 .setSummaryText( 61 mAppContext.getText(R.string.condition_device_vibrate_summary).toString()) 62 .setIconDrawable(mAppContext.getDrawable(R.drawable.ic_volume_ringer_vibrate)) 63 .setViewType(ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH) 64 .build(); 65 } 66 } 67