blob: 07ac1647e6b661c9f3f5217a8e490b4300d2c6c9 [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 Kolbc3af0672011-08-09 10:24:41 -070024import android.view.ViewGroup;
25import android.webkit.WebView;
Michael Kolb4bd767d2011-05-27 11:33:55 -070026import android.widget.ImageView;
27import android.widget.LinearLayout;
28import android.widget.TextView;
29
30public class NavTabView extends LinearLayout {
31
Michael Kolbc3af0672011-08-09 10:24:41 -070032 private ViewGroup mContent;
Michael Kolb0f91e032011-06-01 09:54:20 -070033 private Tab mTab;
Michael Kolb9829b432011-06-04 13:29:00 -070034 private ImageView mClose;
Michael Kolb0f91e032011-06-01 09:54:20 -070035 private TextView mTitle;
36 private View mTitleBar;
John Reck8ee633f2011-08-09 16:00:35 -070037 ImageView mImage;
Michael Kolb0f91e032011-06-01 09:54:20 -070038 private OnClickListener mClickListener;
39 private boolean mHighlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070040
41 public NavTabView(Context context, AttributeSet attrs, int defStyle) {
42 super(context, attrs, defStyle);
43 init();
44 }
45
46 public NavTabView(Context context, AttributeSet attrs) {
47 super(context, attrs);
48 init();
49 }
50
51 public NavTabView(Context context) {
52 super(context);
53 init();
54 }
55
56 private void init() {
Michael Kolb9829b432011-06-04 13:29:00 -070057 LayoutInflater.from(mContext).inflate(R.layout.nav_tab_view, this);
Michael Kolbc3af0672011-08-09 10:24:41 -070058 mContent = (ViewGroup) findViewById(R.id.main);
Michael Kolb9829b432011-06-04 13:29:00 -070059 mClose = (ImageView) findViewById(R.id.closetab);
Michael Kolb4bd767d2011-05-27 11:33:55 -070060 mTitle = (TextView) findViewById(R.id.title);
Michael Kolb4bd767d2011-05-27 11:33:55 -070061 mTitleBar = findViewById(R.id.titlebar);
Michael Kolb9ef259a2011-07-12 15:33:08 -070062 mImage = (ImageView) findViewById(R.id.tab_view);
Michael Kolb4bd767d2011-05-27 11:33:55 -070063 }
64
65 protected boolean isClose(View v) {
66 return v == mClose;
67 }
68
69 protected boolean isTitle(View v) {
70 return v == mTitleBar;
71 }
72
Michael Kolb4bd767d2011-05-27 11:33:55 -070073 protected boolean isWebView(View v) {
Michael Kolb9ef259a2011-07-12 15:33:08 -070074 return v == mImage;
Michael Kolb4bd767d2011-05-27 11:33:55 -070075 }
76
77 protected void setHighlighted(boolean highlighted) {
78 if (highlighted == mHighlighted) return;
79 mHighlighted = highlighted;
Michael Kolb4bd767d2011-05-27 11:33:55 -070080 }
81
82 private void setTitle() {
83 if (mTab == null) return;
84 if (mHighlighted) {
85 mTitle.setText(mTab.getUrl());
86 } else {
87 String txt = mTab.getTitle();
Michael Kolb9829b432011-06-04 13:29:00 -070088 if (txt == null) {
89 txt = mTab.getUrl();
90 }
Michael Kolb4bd767d2011-05-27 11:33:55 -070091 mTitle.setText(txt);
92 }
93 }
94
95 protected boolean isHighlighted() {
96 return mHighlighted;
97 }
98
Michael Kolbc3af0672011-08-09 10:24:41 -070099 protected void setWebView(WebView w) {
100 mContent.addView(w, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
101 }
102
103 protected void setWebView(Tab tab) {
Michael Kolb4bd767d2011-05-27 11:33:55 -0700104 mTab = tab;
Michael Kolb4bd767d2011-05-27 11:33:55 -0700105 setTitle();
Michael Kolb9ef259a2011-07-12 15:33:08 -0700106 Bitmap image = tab.getScreenshot();
107 if (image != null) {
108 mImage.setImageBitmap(image);
John Reckd8c74522011-06-14 08:45:00 -0700109 }
Michael Kolb4bd767d2011-05-27 11:33:55 -0700110 }
111
112 protected void hideTitle() {
113 mTitleBar.setVisibility(View.INVISIBLE);
114 }
115
116 @Override
117 public void setOnClickListener(OnClickListener listener) {
118 mClickListener = listener;
119 mTitleBar.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700120 mClose.setOnClickListener(mClickListener);
Michael Kolb9ef259a2011-07-12 15:33:08 -0700121 if (mImage != null) {
122 mImage.setOnClickListener(mClickListener);
Michael Kolb4bd767d2011-05-27 11:33:55 -0700123 }
124 }
125
Michael Kolb4bd767d2011-05-27 11:33:55 -0700126}