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 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 setPaddingRelative( 45 getPaddingStart(), 46 getPaddingTop(), 47 getResources().getDimensionPixelSize(R.dimen.toolbar_end_padding), 48 getPaddingBottom()); 49 } 50 51 @Override 52 public void setTitle(@StringRes int id) { 53 setTitle(getResources().getString(id)); 54 } 55 56 @Override 57 public void setTitle(CharSequence charSequence) { 58 title.setText(charSequence); 59 } 60 61 @Override 62 public void setSubtitle(@StringRes int id) { 63 setSubtitle(getResources().getString(id)); 64 } 65 66 @Override 67 public void setSubtitle(CharSequence charSequence) { 68 if (charSequence != null) { 69 subtitle.setText(charSequence); 70 subtitle.setVisibility(VISIBLE); 71 } 72 } 73 } 74