blob: 8be8c3d18b5e93f51c87e79d6cba52518461e50a [file] [log] [blame]
Michael Kolb4bd767d2011-05-27 11:33:55 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb4bd767d2011-05-27 11:33:55 -070018
19import android.content.Context;
Michael Kolb9ef259a2011-07-12 15:33:08 -070020import android.graphics.Bitmap;
Michael Kolb4bd767d2011-05-27 11:33:55 -070021import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.View;
Michael Kolbc3af0672011-08-09 10:24:41 -070024import android.view.ViewGroup;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080025import org.codeaurora.swe.WebView;
26
Bijan Amirzada41242f22014-03-21 12:12:18 -070027import com.android.browser.R;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080028
Michael Kolb4bd767d2011-05-27 11:33:55 -070029import android.widget.ImageView;
30import android.widget.LinearLayout;
31import android.widget.TextView;
32
33public class NavTabView extends LinearLayout {
34
Michael Kolbc3af0672011-08-09 10:24:41 -070035 private ViewGroup mContent;
Michael Kolb0f91e032011-06-01 09:54:20 -070036 private Tab mTab;
Michael Kolb0f91e032011-06-01 09:54:20 -070037 private TextView mTitle;
38 private View mTitleBar;
John Reck8ee633f2011-08-09 16:00:35 -070039 ImageView mImage;
Michael Kolb0f91e032011-06-01 09:54:20 -070040 private OnClickListener mClickListener;
41 private boolean mHighlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070042
43 public NavTabView(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
45 init();
46 }
47
48 public NavTabView(Context context, AttributeSet attrs) {
49 super(context, attrs);
50 init();
51 }
52
53 public NavTabView(Context context) {
54 super(context);
55 init();
56 }
57
58 private void init() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080059 LayoutInflater.from(getContext()).inflate(R.layout.nav_tab_view, this);
Enrico Rosd6efa972014-12-02 19:49:59 -080060 mContent = (ViewGroup) findViewById(R.id.nav_tab);
Michael Kolb4bd767d2011-05-27 11:33:55 -070061 mTitle = (TextView) findViewById(R.id.title);
Michael Kolb4bd767d2011-05-27 11:33:55 -070062 mTitleBar = findViewById(R.id.titlebar);
Tarun Nainani87a86682015-02-05 11:47:35 -080063 mImage = (ImageView) findViewById(R.id.tab_preview);
Michael Kolb4bd767d2011-05-27 11:33:55 -070064 }
65
Michael Kolb4bd767d2011-05-27 11:33:55 -070066 protected boolean isTitle(View v) {
67 return v == mTitleBar;
68 }
69
Michael Kolb4bd767d2011-05-27 11:33:55 -070070 protected boolean isWebView(View v) {
Michael Kolb9ef259a2011-07-12 15:33:08 -070071 return v == mImage;
Michael Kolb4bd767d2011-05-27 11:33:55 -070072 }
73
Michael Kolb4bd767d2011-05-27 11:33:55 -070074 private void setTitle() {
75 if (mTab == null) return;
76 if (mHighlighted) {
77 mTitle.setText(mTab.getUrl());
78 } else {
79 String txt = mTab.getTitle();
Michael Kolb9829b432011-06-04 13:29:00 -070080 if (txt == null) {
81 txt = mTab.getUrl();
82 }
Michael Kolb4bd767d2011-05-27 11:33:55 -070083 mTitle.setText(txt);
84 }
John Reck502a3532011-08-16 14:21:46 -070085 if (mTab.isSnapshot()) {
Enrico Rosd6efa972014-12-02 19:49:59 -080086 setTitleIcon(R.drawable.ic_suggest_history_normal);
Ze G Riande2a675c22015-06-03 11:15:24 -070087 } else if (mTab.isDistilled()) {
88 setTitleIcon(R.drawable.ic_deco_reader_mode_normal);
John Reck502a3532011-08-16 14:21:46 -070089 } else if (mTab.isPrivateBrowsingEnabled()) {
Enrico Rosd6efa972014-12-02 19:49:59 -080090 mContent.setBackgroundResource(R.drawable.nav_tab_title_incognito);
91 mTitle.setTextColor(getResources().getColor(R.color.white));
Enrico Rosd6efa972014-12-02 19:49:59 -080092 setTitleIcon(R.drawable.ic_deco_incognito_normal);
John Reck502a3532011-08-16 14:21:46 -070093 } else {
94 setTitleIcon(0);
95 }
96 }
97
98 private void setTitleIcon(int id) {
99 if (id == 0) {
100 mTitle.setPadding(mTitle.getCompoundDrawablePadding(), 0, 0, 0);
101 } else {
102 mTitle.setPadding(0, 0, 0, 0);
103 }
104 mTitle.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700105 }
106
107 protected boolean isHighlighted() {
108 return mHighlighted;
109 }
110
Michael Kolbc3af0672011-08-09 10:24:41 -0700111 protected void setWebView(Tab tab) {
Michael Kolb4bd767d2011-05-27 11:33:55 -0700112 mTab = tab;
Michael Kolb4bd767d2011-05-27 11:33:55 -0700113 setTitle();
Michael Kolb9ef259a2011-07-12 15:33:08 -0700114 Bitmap image = tab.getScreenshot();
115 if (image != null) {
116 mImage.setImageBitmap(image);
Michael Kolba9a59672011-11-17 12:50:10 -0800117 if (tab != null) {
118 mImage.setContentDescription(tab.getTitle());
119 }
John Reckd8c74522011-06-14 08:45:00 -0700120 }
Michael Kolb4bd767d2011-05-27 11:33:55 -0700121 }
122
Michael Kolb4bd767d2011-05-27 11:33:55 -0700123 @Override
124 public void setOnClickListener(OnClickListener listener) {
125 mClickListener = listener;
126 mTitleBar.setOnClickListener(mClickListener);
Michael Kolb9ef259a2011-07-12 15:33:08 -0700127 if (mImage != null) {
128 mImage.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700129 }
130 }
131
Michael Kolb4bd767d2011-05-27 11:33:55 -0700132}