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; |
| 21 | import android.webkit.WebView; |
| 22 | import android.widget.ImageView; |
| 23 | import android.widget.LinearLayout; |
| 24 | import android.widget.ProgressBar; |
| 25 | import android.widget.TextView; |
| 26 | import android.view.LayoutInflater; |
| 27 | import android.view.View; |
| 28 | |
| 29 | /* package */ class TitleBar extends LinearLayout { |
| 30 | private TextView mTitle; |
| 31 | private TextView mUrl; |
| 32 | private ImageView mZoomIn; |
| 33 | private View mZoomOut; |
| 34 | private View mDivider; |
| 35 | private ProgressBar mCircularProgress; |
| 36 | private ProgressBar mHorizontalProgress; |
| 37 | private ImageView mFavicon; |
| 38 | private ImageView mLockIcon; |
| 39 | private boolean mInLoad; |
| 40 | private CharSequence mTitleOnceLoaded; |
| 41 | private BrowserActivity mActivity; |
| 42 | |
| 43 | |
| 44 | /* package */ TitleBar(BrowserActivity context) { |
| 45 | super(context); |
| 46 | mActivity = context; |
| 47 | LayoutInflater factory = LayoutInflater.from(context); |
| 48 | factory.inflate(R.layout.title_bar, this); |
| 49 | |
| 50 | mTitle = (TextView) findViewById(R.id.title); |
| 51 | mUrl = (TextView) findViewById(R.id.url); |
| 52 | |
| 53 | mZoomIn = (ImageView) findViewById(R.id.zoom_in); |
| 54 | mZoomIn.setOnClickListener(new View.OnClickListener() { |
| 55 | public void onClick(View v) { |
| 56 | if (mInLoad) { |
| 57 | mActivity.getTopWindow().stopLoading(); |
| 58 | } else { |
| 59 | mActivity.getTopWindow().zoomIn(); |
| 60 | } |
| 61 | } |
| 62 | }); |
| 63 | mZoomOut = findViewById(R.id.zoom_out); |
| 64 | // Make zoom out disappear while loading |
| 65 | mZoomOut.setOnClickListener(new View.OnClickListener() { |
| 66 | public void onClick(View v) { |
| 67 | mActivity.getTopWindow().zoomOut(); |
| 68 | } |
| 69 | }); |
| 70 | |
| 71 | mCircularProgress = (ProgressBar) findViewById(R.id.progress_circular); |
| 72 | mHorizontalProgress = (ProgressBar) findViewById( |
| 73 | R.id.progress_horizontal); |
| 74 | mFavicon = (ImageView) findViewById(R.id.favicon); |
| 75 | mLockIcon = (ImageView) findViewById(R.id.lock_icon); |
| 76 | mDivider = findViewById(R.id.divider); |
| 77 | setOnClickListener(new View.OnClickListener() { |
| 78 | public void onClick(View v) { |
| 79 | mActivity.onSearchRequested(); |
| 80 | } |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | /* package */ void setFavicon(Drawable d) { |
| 85 | mFavicon.setImageDrawable(d); |
| 86 | } |
| 87 | |
| 88 | /* package */ void setLock(Drawable d) { |
| 89 | if (d == null) { |
| 90 | mLockIcon.setVisibility(View.GONE); |
| 91 | } else { |
| 92 | mLockIcon.setImageDrawable(d); |
| 93 | mLockIcon.setVisibility(View.VISIBLE); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* package */ void setProgress(int newProgress) { |
| 98 | if (newProgress == mCircularProgress.getMax()) { |
| 99 | mCircularProgress.setVisibility(View.GONE); |
| 100 | mHorizontalProgress.setVisibility(View.GONE); |
| 101 | mTitle.setText(mTitleOnceLoaded); |
| 102 | mDivider.setVisibility(View.VISIBLE); |
| 103 | mZoomOut.setVisibility(View.VISIBLE); |
| 104 | mZoomIn.setImageResource(R.drawable.ic_titlebar_zoom); |
| 105 | mInLoad = false; |
| 106 | } else { |
| 107 | mCircularProgress.setProgress(newProgress); |
| 108 | mHorizontalProgress.setProgress(newProgress); |
| 109 | mCircularProgress.setVisibility(View.VISIBLE); |
| 110 | mHorizontalProgress.setVisibility(View.VISIBLE); |
| 111 | mDivider.setVisibility(View.GONE); |
| 112 | mZoomOut.setVisibility(View.GONE); |
| 113 | mZoomIn.setImageResource(com.android.internal.R.drawable.ic_menu_stop); |
| 114 | mInLoad = true; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* package */ void setTitleAndUrl(CharSequence title, CharSequence url) { |
| 119 | mTitleOnceLoaded = title; |
| 120 | if (null == title || mHorizontalProgress.getProgress() < |
| 121 | mHorizontalProgress.getMax()) { |
| 122 | mTitle.setText(R.string.title_bar_loading); |
| 123 | } else { |
| 124 | mTitle.setText(title); |
| 125 | } |
| 126 | mUrl.setText(url); |
| 127 | } |
| 128 | |
| 129 | /* package */ void setToTabPicker() { |
| 130 | mTitle.setText(R.string.tab_picker_title); |
| 131 | setFavicon(null); |
| 132 | setLock(null); |
| 133 | mCircularProgress.setVisibility(View.GONE); |
| 134 | mHorizontalProgress.setVisibility(View.GONE); |
| 135 | } |
| 136 | } |