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 import com.android.dialer.theme.base.ThemeComponent;
27 
28 /** Toolbar widget for Dialer. */
29 public class DialerToolbar extends Toolbar {
30 
31   private final TextView title;
32   private final BidiTextView subtitle;
33 
DialerToolbar(Context context, @Nullable AttributeSet attributeSet)34   public DialerToolbar(Context context, @Nullable AttributeSet attributeSet) {
35     super(context, attributeSet);
36     inflate(context, R.layout.dialer_toolbar, this);
37     title = (TextView) findViewById(R.id.title);
38     subtitle = (BidiTextView) findViewById(R.id.subtitle);
39 
40     setElevation(getResources().getDimensionPixelSize(R.dimen.toolbar_elevation));
41     setBackgroundColor(ThemeComponent.get(context).theme().getColorPrimary());
42     setNavigationIcon(R.drawable.quantum_ic_close_white_24);
43     setNavigationContentDescription(R.string.toolbar_close);
44     setNavigationOnClickListener(v -> ((Activity) context).finish());
45     setPaddingRelative(
46         getPaddingStart(),
47         getPaddingTop(),
48         getResources().getDimensionPixelSize(R.dimen.toolbar_end_padding),
49         getPaddingBottom());
50   }
51 
52   @Override
setTitle(@tringRes int id)53   public void setTitle(@StringRes int id) {
54     setTitle(getResources().getString(id));
55   }
56 
57   @Override
setTitle(CharSequence charSequence)58   public void setTitle(CharSequence charSequence) {
59     title.setText(charSequence);
60   }
61 
62   @Override
setSubtitle(@tringRes int id)63   public void setSubtitle(@StringRes int id) {
64     setSubtitle(getResources().getString(id));
65   }
66 
67   @Override
setSubtitle(CharSequence charSequence)68   public void setSubtitle(CharSequence charSequence) {
69     if (charSequence != null) {
70       subtitle.setText(charSequence);
71       subtitle.setVisibility(VISIBLE);
72     }
73   }
74 }
75