blob: 23ad2f14d00190c47c162d3592b94592cfddf291 [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
17package com.android.browser;
18
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 Kolb4bd767d2011-05-27 11:33:55 -070024import android.widget.ImageView;
25import android.widget.LinearLayout;
26import android.widget.TextView;
27
28public class NavTabView extends LinearLayout {
29
Michael Kolb0f91e032011-06-01 09:54:20 -070030 private Tab mTab;
Michael Kolb9829b432011-06-04 13:29:00 -070031 private ImageView mClose;
Michael Kolb0f91e032011-06-01 09:54:20 -070032 private TextView mTitle;
33 private View mTitleBar;
Michael Kolb9ef259a2011-07-12 15:33:08 -070034 private ImageView mImage;
Michael Kolb0f91e032011-06-01 09:54:20 -070035 private OnClickListener mClickListener;
36 private boolean mHighlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070037
38 public NavTabView(Context context, AttributeSet attrs, int defStyle) {
39 super(context, attrs, defStyle);
40 init();
41 }
42
43 public NavTabView(Context context, AttributeSet attrs) {
44 super(context, attrs);
45 init();
46 }
47
48 public NavTabView(Context context) {
49 super(context);
50 init();
51 }
52
53 private void init() {
Michael Kolb9829b432011-06-04 13:29:00 -070054 LayoutInflater.from(mContext).inflate(R.layout.nav_tab_view, this);
Michael Kolb9829b432011-06-04 13:29:00 -070055 mClose = (ImageView) findViewById(R.id.closetab);
Michael Kolb4bd767d2011-05-27 11:33:55 -070056 mTitle = (TextView) findViewById(R.id.title);
Michael Kolb4bd767d2011-05-27 11:33:55 -070057 mTitleBar = findViewById(R.id.titlebar);
Michael Kolb9ef259a2011-07-12 15:33:08 -070058 mImage = (ImageView) findViewById(R.id.tab_view);
Michael Kolb4bd767d2011-05-27 11:33:55 -070059 }
60
61 protected boolean isClose(View v) {
62 return v == mClose;
63 }
64
65 protected boolean isTitle(View v) {
66 return v == mTitleBar;
67 }
68
Michael Kolb4bd767d2011-05-27 11:33:55 -070069 protected boolean isWebView(View v) {
Michael Kolb9ef259a2011-07-12 15:33:08 -070070 return v == mImage;
Michael Kolb4bd767d2011-05-27 11:33:55 -070071 }
72
73 protected void setHighlighted(boolean highlighted) {
74 if (highlighted == mHighlighted) return;
75 mHighlighted = highlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070076 }
77
78 private void setTitle() {
79 if (mTab == null) return;
80 if (mHighlighted) {
81 mTitle.setText(mTab.getUrl());
82 } else {
83 String txt = mTab.getTitle();
Michael Kolb9829b432011-06-04 13:29:00 -070084 if (txt == null) {
85 txt = mTab.getUrl();
86 }
Michael Kolb4bd767d2011-05-27 11:33:55 -070087 mTitle.setText(txt);
88 }
89 }
90
91 protected boolean isHighlighted() {
92 return mHighlighted;
93 }
94
95 protected void setWebView(PhoneUi ui, Tab tab) {
96 mTab = tab;
Michael Kolb4bd767d2011-05-27 11:33:55 -070097 setTitle();
Michael Kolb9ef259a2011-07-12 15:33:08 -070098 Bitmap image = tab.getScreenshot();
99 if (image != null) {
100 mImage.setImageBitmap(image);
John Reckd8c74522011-06-14 08:45:00 -0700101 }
Michael Kolb4bd767d2011-05-27 11:33:55 -0700102 }
103
104 protected void hideTitle() {
105 mTitleBar.setVisibility(View.INVISIBLE);
106 }
107
108 @Override
109 public void setOnClickListener(OnClickListener listener) {
110 mClickListener = listener;
111 mTitleBar.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700112 mClose.setOnClickListener(mClickListener);
Michael Kolb9ef259a2011-07-12 15:33:08 -0700113 if (mImage != null) {
114 mImage.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700115 }
116 }
117
Michael Kolb4bd767d2011-05-27 11:33:55 -0700118}