Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of 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, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.graphics.drawable.Drawable; |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 24 | import android.webkit.WebView; |
| 25 | import android.widget.ImageView; |
| 26 | import android.widget.LinearLayout; |
| 27 | import android.widget.ProgressBar; |
| 28 | import android.widget.TextView; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 29 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 30 | public class TitleBar extends LinearLayout { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 31 | private TextView mTitle; |
| 32 | private TextView mUrl; |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 33 | private ImageView mLftButton; |
| 34 | private Drawable mBookmarkDrawable; |
| 35 | private View mRtButton; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 36 | private View mDivider; |
| 37 | private ProgressBar mCircularProgress; |
| 38 | private ProgressBar mHorizontalProgress; |
| 39 | private ImageView mFavicon; |
| 40 | private ImageView mLockIcon; |
| 41 | private boolean mInLoad; |
Leon Scroggins | d7c3dd5 | 2009-07-20 13:38:47 -0400 | [diff] [blame^] | 42 | private boolean mTitleSet; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 43 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 44 | public TitleBar(Context context) { |
| 45 | this(context, null); |
| 46 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 47 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 48 | public TitleBar(Context context, AttributeSet attrs) { |
| 49 | super(context, attrs); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 50 | LayoutInflater factory = LayoutInflater.from(context); |
| 51 | factory.inflate(R.layout.title_bar, this); |
| 52 | |
| 53 | mTitle = (TextView) findViewById(R.id.title); |
| 54 | mUrl = (TextView) findViewById(R.id.url); |
| 55 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 56 | mLftButton = (ImageView) findViewById(R.id.lft_button); |
| 57 | mRtButton = findViewById(R.id.rt_button); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 58 | |
| 59 | mCircularProgress = (ProgressBar) findViewById(R.id.progress_circular); |
| 60 | mHorizontalProgress = (ProgressBar) findViewById( |
| 61 | R.id.progress_horizontal); |
| 62 | mFavicon = (ImageView) findViewById(R.id.favicon); |
| 63 | mLockIcon = (ImageView) findViewById(R.id.lock_icon); |
| 64 | mDivider = findViewById(R.id.divider); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* package */ void setBrowserActivity(final BrowserActivity activity) { |
| 68 | mLftButton.setOnClickListener(new View.OnClickListener() { |
| 69 | public void onClick(View v) { |
| 70 | if (mInLoad) { |
| 71 | WebView webView = activity.getTopWindow(); |
| 72 | if (webView != null) { |
| 73 | webView.stopLoading(); |
| 74 | } |
| 75 | } else { |
| 76 | activity.bookmarksOrHistoryPicker(false); |
| 77 | } |
| 78 | } |
| 79 | }); |
| 80 | mRtButton.setOnClickListener(new View.OnClickListener() { |
| 81 | public void onClick(View v) { |
| 82 | WebView webView = activity.getTopWindow(); |
| 83 | if (webView != null) { |
| 84 | webView.zoomScrollOut(); |
| 85 | } |
| 86 | } |
| 87 | }); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 88 | setOnClickListener(new View.OnClickListener() { |
| 89 | public void onClick(View v) { |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 90 | activity.onSearchRequested(); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 91 | } |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | /* package */ void setFavicon(Drawable d) { |
| 96 | mFavicon.setImageDrawable(d); |
| 97 | } |
| 98 | |
| 99 | /* package */ void setLock(Drawable d) { |
| 100 | if (d == null) { |
| 101 | mLockIcon.setVisibility(View.GONE); |
| 102 | } else { |
| 103 | mLockIcon.setImageDrawable(d); |
| 104 | mLockIcon.setVisibility(View.VISIBLE); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* package */ void setProgress(int newProgress) { |
| 109 | if (newProgress == mCircularProgress.getMax()) { |
| 110 | mCircularProgress.setVisibility(View.GONE); |
| 111 | mHorizontalProgress.setVisibility(View.GONE); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 112 | mDivider.setVisibility(View.VISIBLE); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 113 | mRtButton.setVisibility(View.VISIBLE); |
| 114 | mLftButton.setImageDrawable(mBookmarkDrawable); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 115 | mInLoad = false; |
Leon Scroggins | d7c3dd5 | 2009-07-20 13:38:47 -0400 | [diff] [blame^] | 116 | if (!mTitleSet) { |
| 117 | mTitle.setText(mUrl.getText()); |
| 118 | mUrl.setText(null); |
| 119 | mTitleSet = true; |
| 120 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 121 | } else { |
| 122 | mCircularProgress.setProgress(newProgress); |
| 123 | mHorizontalProgress.setProgress(newProgress); |
| 124 | mCircularProgress.setVisibility(View.VISIBLE); |
| 125 | mHorizontalProgress.setVisibility(View.VISIBLE); |
| 126 | mDivider.setVisibility(View.GONE); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 127 | mRtButton.setVisibility(View.GONE); |
| 128 | if (mBookmarkDrawable == null) { |
| 129 | // The drawable was assigned in the xml file, so it already |
| 130 | // exists. Keep a pointer to it when we switch to the resource |
| 131 | // so we can easily switch back. |
| 132 | mBookmarkDrawable = mLftButton.getDrawable(); |
| 133 | } |
| 134 | mLftButton.setImageResource( |
| 135 | com.android.internal.R.drawable.ic_menu_stop); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 136 | mInLoad = true; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* package */ void setTitleAndUrl(CharSequence title, CharSequence url) { |
Leon Scroggins | 176215d | 2009-06-15 12:38:58 -0400 | [diff] [blame] | 141 | if (url != null) { |
| 142 | url = BrowserActivity.buildTitleUrl(url.toString()); |
| 143 | } |
Leon Scroggins | d7c3dd5 | 2009-07-20 13:38:47 -0400 | [diff] [blame^] | 144 | if (null == title) { |
| 145 | if (mInLoad) { |
| 146 | mTitleSet = false; |
| 147 | mTitle.setText(R.string.title_bar_loading); |
| 148 | } else { |
| 149 | // If the page has no title, put the url in the title space |
| 150 | // and leave the url blank. |
| 151 | mTitle.setText(url); |
| 152 | mUrl.setText(null); |
| 153 | mTitleSet = true; |
| 154 | return; |
| 155 | } |
| 156 | } else { |
| 157 | mTitle.setText(title); |
| 158 | mTitleSet = true; |
| 159 | } |
Leon Scroggins | 176215d | 2009-06-15 12:38:58 -0400 | [diff] [blame] | 160 | mUrl.setText(url); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* package */ void setToTabPicker() { |
| 164 | mTitle.setText(R.string.tab_picker_title); |
| 165 | setFavicon(null); |
| 166 | setLock(null); |
| 167 | mCircularProgress.setVisibility(View.GONE); |
| 168 | mHorizontalProgress.setVisibility(View.GONE); |
| 169 | } |
| 170 | } |