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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 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 | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 24 | import android.view.ViewGroup; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 25 | import org.codeaurora.swe.WebView; |
| 26 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 27 | import com.android.browser.R; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 28 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 29 | import android.widget.ImageView; |
| 30 | import android.widget.LinearLayout; |
| 31 | import android.widget.TextView; |
| 32 | |
| 33 | public class NavTabView extends LinearLayout { |
| 34 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 35 | private ViewGroup mContent; |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 36 | private Tab mTab; |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 37 | private TextView mTitle; |
| 38 | private View mTitleBar; |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 39 | ImageView mImage; |
Michael Kolb | 0f91e03 | 2011-06-01 09:54:20 -0700 | [diff] [blame] | 40 | private OnClickListener mClickListener; |
| 41 | private boolean mHighlighted; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 42 | |
| 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 Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 59 | LayoutInflater.from(getContext()).inflate(R.layout.nav_tab_view, this); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 60 | mContent = (ViewGroup) findViewById(R.id.nav_tab); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 61 | mTitle = (TextView) findViewById(R.id.title); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 62 | mTitleBar = findViewById(R.id.titlebar); |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 63 | mImage = (ImageView) findViewById(R.id.tab_preview); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 66 | protected boolean isTitle(View v) { |
| 67 | return v == mTitleBar; |
| 68 | } |
| 69 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 70 | protected boolean isWebView(View v) { |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 71 | return v == mImage; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 74 | private void setTitle() { |
| 75 | if (mTab == null) return; |
| 76 | if (mHighlighted) { |
| 77 | mTitle.setText(mTab.getUrl()); |
| 78 | } else { |
| 79 | String txt = mTab.getTitle(); |
Michael Kolb | 9829b43 | 2011-06-04 13:29:00 -0700 | [diff] [blame] | 80 | if (txt == null) { |
| 81 | txt = mTab.getUrl(); |
| 82 | } |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 83 | mTitle.setText(txt); |
| 84 | } |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 85 | if (mTab.isSnapshot()) { |
jrizzoli | 82682a0 | 2015-10-11 16:51:09 +0200 | [diff] [blame] | 86 | setTitleIcon(R.drawable.ic_suggest_history_inverted); |
Ze G Riande | 2a675c2 | 2015-06-03 11:15:24 -0700 | [diff] [blame] | 87 | } else if (mTab.isDistilled()) { |
| 88 | setTitleIcon(R.drawable.ic_deco_reader_mode_normal); |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 89 | } else if (mTab.isPrivateBrowsingEnabled()) { |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 90 | setTitleIcon(R.drawable.ic_deco_incognito_normal); |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 91 | } else { |
| 92 | setTitleIcon(0); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | private void setTitleIcon(int id) { |
| 97 | if (id == 0) { |
| 98 | mTitle.setPadding(mTitle.getCompoundDrawablePadding(), 0, 0, 0); |
| 99 | } else { |
| 100 | mTitle.setPadding(0, 0, 0, 0); |
| 101 | } |
| 102 | mTitle.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | protected boolean isHighlighted() { |
| 106 | return mHighlighted; |
| 107 | } |
| 108 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 109 | protected void setWebView(Tab tab) { |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 110 | mTab = tab; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 111 | setTitle(); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 112 | Bitmap image = tab.getScreenshot(); |
| 113 | if (image != null) { |
| 114 | mImage.setImageBitmap(image); |
Michael Kolb | a9a5967 | 2011-11-17 12:50:10 -0800 | [diff] [blame] | 115 | if (tab != null) { |
| 116 | mImage.setContentDescription(tab.getTitle()); |
| 117 | } |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 118 | } |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 121 | @Override |
| 122 | public void setOnClickListener(OnClickListener listener) { |
| 123 | mClickListener = listener; |
| 124 | mTitleBar.setOnClickListener(mClickListener); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 125 | if (mImage != null) { |
| 126 | mImage.setOnClickListener(mClickListener); |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 130 | } |