blob: 3bcd7a2eec1b0b3b0ffa4a2a0c68c670a33297c0 [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 Kolb9829b432011-06-04 13:29:00 -070037 private ImageView mClose;
Michael Kolb0f91e032011-06-01 09:54:20 -070038 private TextView mTitle;
39 private View mTitleBar;
John Reck8ee633f2011-08-09 16:00:35 -070040 ImageView mImage;
Michael Kolb0f91e032011-06-01 09:54:20 -070041 private OnClickListener mClickListener;
42 private boolean mHighlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070043
44 public NavTabView(Context context, AttributeSet attrs, int defStyle) {
45 super(context, attrs, defStyle);
46 init();
47 }
48
49 public NavTabView(Context context, AttributeSet attrs) {
50 super(context, attrs);
51 init();
52 }
53
54 public NavTabView(Context context) {
55 super(context);
56 init();
57 }
58
59 private void init() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080060 LayoutInflater.from(getContext()).inflate(R.layout.nav_tab_view, this);
Michael Kolbc3af0672011-08-09 10:24:41 -070061 mContent = (ViewGroup) findViewById(R.id.main);
Michael Kolb9829b432011-06-04 13:29:00 -070062 mClose = (ImageView) findViewById(R.id.closetab);
Michael Kolb4bd767d2011-05-27 11:33:55 -070063 mTitle = (TextView) findViewById(R.id.title);
Michael Kolb4bd767d2011-05-27 11:33:55 -070064 mTitleBar = findViewById(R.id.titlebar);
Michael Kolb9ef259a2011-07-12 15:33:08 -070065 mImage = (ImageView) findViewById(R.id.tab_view);
Michael Kolb4bd767d2011-05-27 11:33:55 -070066 }
67
68 protected boolean isClose(View v) {
69 return v == mClose;
70 }
71
72 protected boolean isTitle(View v) {
73 return v == mTitleBar;
74 }
75
Michael Kolb4bd767d2011-05-27 11:33:55 -070076 protected boolean isWebView(View v) {
Michael Kolb9ef259a2011-07-12 15:33:08 -070077 return v == mImage;
Michael Kolb4bd767d2011-05-27 11:33:55 -070078 }
79
Michael Kolb4bd767d2011-05-27 11:33:55 -070080 private void setTitle() {
81 if (mTab == null) return;
82 if (mHighlighted) {
83 mTitle.setText(mTab.getUrl());
84 } else {
85 String txt = mTab.getTitle();
Michael Kolb9829b432011-06-04 13:29:00 -070086 if (txt == null) {
87 txt = mTab.getUrl();
88 }
Michael Kolb4bd767d2011-05-27 11:33:55 -070089 mTitle.setText(txt);
90 }
John Reck502a3532011-08-16 14:21:46 -070091 if (mTab.isSnapshot()) {
92 setTitleIcon(R.drawable.ic_history_holo_dark);
93 } else if (mTab.isPrivateBrowsingEnabled()) {
94 setTitleIcon(R.drawable.ic_incognito_holo_dark);
95 } else {
96 setTitleIcon(0);
97 }
98 }
99
100 private void setTitleIcon(int id) {
101 if (id == 0) {
102 mTitle.setPadding(mTitle.getCompoundDrawablePadding(), 0, 0, 0);
103 } else {
104 mTitle.setPadding(0, 0, 0, 0);
105 }
106 mTitle.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700107 }
108
109 protected boolean isHighlighted() {
110 return mHighlighted;
111 }
112
Michael Kolbc3af0672011-08-09 10:24:41 -0700113 protected void setWebView(Tab tab) {
Michael Kolb4bd767d2011-05-27 11:33:55 -0700114 mTab = tab;
Michael Kolb4bd767d2011-05-27 11:33:55 -0700115 setTitle();
Michael Kolb9ef259a2011-07-12 15:33:08 -0700116 Bitmap image = tab.getScreenshot();
117 if (image != null) {
118 mImage.setImageBitmap(image);
Michael Kolba9a59672011-11-17 12:50:10 -0800119 if (tab != null) {
120 mImage.setContentDescription(tab.getTitle());
121 }
John Reckd8c74522011-06-14 08:45:00 -0700122 }
Michael Kolb4bd767d2011-05-27 11:33:55 -0700123 }
124
Michael Kolb4bd767d2011-05-27 11:33:55 -0700125 @Override
126 public void setOnClickListener(OnClickListener listener) {
127 mClickListener = listener;
128 mTitleBar.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700129 mClose.setOnClickListener(mClickListener);
Michael Kolb9ef259a2011-07-12 15:33:08 -0700130 if (mImage != null) {
131 mImage.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700132 }
133 }
134
Michael Kolb4bd767d2011-05-27 11:33:55 -0700135}