• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.widget;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.support.annotation.Nullable;
22 import android.support.annotation.StringRes;
23 import android.support.v7.widget.Toolbar;
24 import android.util.AttributeSet;
25 import android.widget.TextView;
26 
27 /** Toolbar widget for Dialer. */
28 public class DialerToolbar extends Toolbar {
29 
30   private final TextView title;
31   private final TextView subtitle;
32 
DialerToolbar(Context context, @Nullable AttributeSet attributeSet)33   public DialerToolbar(Context context, @Nullable AttributeSet attributeSet) {
34     super(context, attributeSet);
35     inflate(context, R.layout.dialer_toolbar, this);
36     title = (TextView) findViewById(R.id.title);
37     subtitle = (TextView) findViewById(R.id.subtitle);
38 
39     setElevation(getResources().getDimensionPixelSize(R.dimen.toolbar_elevation));
40     setBackgroundColor(getResources().getColor(R.color.dialer_theme_color));
41     setNavigationIcon(R.drawable.quantum_ic_close_white_24);
42     setNavigationContentDescription(R.string.toolbar_close);
43     setNavigationOnClickListener(v -> ((Activity) context).finish());
44   }
45 
46   @Override
setTitle(@tringRes int id)47   public void setTitle(@StringRes int id) {
48     setTitle(getResources().getString(id));
49   }
50 
51   @Override
setTitle(CharSequence charSequence)52   public void setTitle(CharSequence charSequence) {
53     title.setText(charSequence);
54   }
55 
56   @Override
setSubtitle(@tringRes int id)57   public void setSubtitle(@StringRes int id) {
58     setSubtitle(getResources().getString(id));
59   }
60 
61   @Override
setSubtitle(CharSequence charSequence)62   public void setSubtitle(CharSequence charSequence) {
63     if (charSequence != null) {
64       subtitle.setText(charSequence);
65       subtitle.setVisibility(VISIBLE);
66     }
67   }
68 }
69