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 | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 42 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 43 | public TitleBar(Context context) { |
| 44 | this(context, null); |
| 45 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 46 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 47 | public TitleBar(Context context, AttributeSet attrs) { |
| 48 | super(context, attrs); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 49 | LayoutInflater factory = LayoutInflater.from(context); |
| 50 | factory.inflate(R.layout.title_bar, this); |
| 51 | |
| 52 | mTitle = (TextView) findViewById(R.id.title); |
| 53 | mUrl = (TextView) findViewById(R.id.url); |
| 54 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 55 | mLftButton = (ImageView) findViewById(R.id.lft_button); |
| 56 | mRtButton = findViewById(R.id.rt_button); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 57 | |
| 58 | mCircularProgress = (ProgressBar) findViewById(R.id.progress_circular); |
| 59 | mHorizontalProgress = (ProgressBar) findViewById( |
| 60 | R.id.progress_horizontal); |
| 61 | mFavicon = (ImageView) findViewById(R.id.favicon); |
| 62 | mLockIcon = (ImageView) findViewById(R.id.lock_icon); |
| 63 | mDivider = findViewById(R.id.divider); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* package */ void setBrowserActivity(final BrowserActivity activity) { |
| 67 | mLftButton.setOnClickListener(new View.OnClickListener() { |
| 68 | public void onClick(View v) { |
| 69 | if (mInLoad) { |
| 70 | WebView webView = activity.getTopWindow(); |
| 71 | if (webView != null) { |
| 72 | webView.stopLoading(); |
| 73 | } |
| 74 | } else { |
| 75 | activity.bookmarksOrHistoryPicker(false); |
| 76 | } |
| 77 | } |
| 78 | }); |
| 79 | mRtButton.setOnClickListener(new View.OnClickListener() { |
| 80 | public void onClick(View v) { |
| 81 | WebView webView = activity.getTopWindow(); |
| 82 | if (webView != null) { |
| 83 | webView.zoomScrollOut(); |
| 84 | } |
| 85 | } |
| 86 | }); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 87 | setOnClickListener(new View.OnClickListener() { |
| 88 | public void onClick(View v) { |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 89 | activity.onSearchRequested(); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 90 | } |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | /* package */ void setFavicon(Drawable d) { |
| 95 | mFavicon.setImageDrawable(d); |
| 96 | } |
| 97 | |
| 98 | /* package */ void setLock(Drawable d) { |
| 99 | if (d == null) { |
| 100 | mLockIcon.setVisibility(View.GONE); |
| 101 | } else { |
| 102 | mLockIcon.setImageDrawable(d); |
| 103 | mLockIcon.setVisibility(View.VISIBLE); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* package */ void setProgress(int newProgress) { |
| 108 | if (newProgress == mCircularProgress.getMax()) { |
| 109 | mCircularProgress.setVisibility(View.GONE); |
| 110 | mHorizontalProgress.setVisibility(View.GONE); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 111 | mDivider.setVisibility(View.VISIBLE); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 112 | mRtButton.setVisibility(View.VISIBLE); |
| 113 | mLftButton.setImageDrawable(mBookmarkDrawable); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 114 | mInLoad = false; |
| 115 | } else { |
| 116 | mCircularProgress.setProgress(newProgress); |
| 117 | mHorizontalProgress.setProgress(newProgress); |
| 118 | mCircularProgress.setVisibility(View.VISIBLE); |
| 119 | mHorizontalProgress.setVisibility(View.VISIBLE); |
| 120 | mDivider.setVisibility(View.GONE); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 121 | mRtButton.setVisibility(View.GONE); |
| 122 | if (mBookmarkDrawable == null) { |
| 123 | // The drawable was assigned in the xml file, so it already |
| 124 | // exists. Keep a pointer to it when we switch to the resource |
| 125 | // so we can easily switch back. |
| 126 | mBookmarkDrawable = mLftButton.getDrawable(); |
| 127 | } |
| 128 | mLftButton.setImageResource( |
| 129 | com.android.internal.R.drawable.ic_menu_stop); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 130 | mInLoad = true; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* package */ void setTitleAndUrl(CharSequence title, CharSequence url) { |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 135 | if (null == title) { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 136 | mTitle.setText(R.string.title_bar_loading); |
| 137 | } else { |
| 138 | mTitle.setText(title); |
| 139 | } |
| 140 | mUrl.setText(url); |
| 141 | } |
| 142 | |
| 143 | /* package */ void setToTabPicker() { |
| 144 | mTitle.setText(R.string.tab_picker_title); |
| 145 | setFavicon(null); |
| 146 | setLock(null); |
| 147 | mCircularProgress.setVisibility(View.GONE); |
| 148 | mHorizontalProgress.setVisibility(View.GONE); |
| 149 | } |
| 150 | } |