Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.content.Context; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 24 | import android.widget.ImageView; |
| 25 | import android.widget.LinearLayout; |
| 26 | import android.widget.TextView; |
| 27 | |
| 28 | public class NavTabView extends LinearLayout { |
| 29 | |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 30 | private Tab mTab; |
Michael Kolb | 9829b43 | 2011-06-04 13:29:00 -0700 | [diff] [blame] | 31 | private ImageView mClose; |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 32 | private TextView mTitle; |
| 33 | private View mTitleBar; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 34 | private ImageView mImage; |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 35 | private OnClickListener mClickListener; |
| 36 | private boolean mHighlighted; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 37 | |
| 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 Kolb | 9829b43 | 2011-06-04 13:29:00 -0700 | [diff] [blame] | 54 | LayoutInflater.from(mContext).inflate(R.layout.nav_tab_view, this); |
Michael Kolb | 9829b43 | 2011-06-04 13:29:00 -0700 | [diff] [blame] | 55 | mClose = (ImageView) findViewById(R.id.closetab); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 56 | mTitle = (TextView) findViewById(R.id.title); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 57 | mTitleBar = findViewById(R.id.titlebar); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 58 | mImage = (ImageView) findViewById(R.id.tab_view); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 59 | } |
| 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 Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 69 | protected boolean isWebView(View v) { |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 70 | return v == mImage; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | protected void setHighlighted(boolean highlighted) { |
| 74 | if (highlighted == mHighlighted) return; |
| 75 | mHighlighted = highlighted; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 76 | } |
| 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 Kolb | 9829b43 | 2011-06-04 13:29:00 -0700 | [diff] [blame] | 84 | if (txt == null) { |
| 85 | txt = mTab.getUrl(); |
| 86 | } |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 87 | 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 Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 97 | setTitle(); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 98 | Bitmap image = tab.getScreenshot(); |
| 99 | if (image != null) { |
| 100 | mImage.setImageBitmap(image); |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 101 | } |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 102 | } |
| 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 Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 112 | mClose.setOnClickListener(mClickListener); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 113 | if (mImage != null) { |
| 114 | mImage.setOnClickListener(mClickListener); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 118 | } |