blob: f43058b0f93dc3886df47d8fa596c481c3d60588 [file] [log] [blame]
Leon Scroggins81db3662009-06-04 17:45:11 -04001/*
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
17package com.android.browser;
18
19import android.content.Context;
20import android.graphics.drawable.Drawable;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040021import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.View;
Leon Scroggins81db3662009-06-04 17:45:11 -040024import android.webkit.WebView;
25import android.widget.ImageView;
26import android.widget.LinearLayout;
27import android.widget.ProgressBar;
28import android.widget.TextView;
Leon Scroggins81db3662009-06-04 17:45:11 -040029
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040030public class TitleBar extends LinearLayout {
Leon Scroggins81db3662009-06-04 17:45:11 -040031 private TextView mTitle;
32 private TextView mUrl;
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040033 private ImageView mLftButton;
34 private Drawable mBookmarkDrawable;
35 private View mRtButton;
Leon Scroggins81db3662009-06-04 17:45:11 -040036 private View mDivider;
37 private ProgressBar mCircularProgress;
38 private ProgressBar mHorizontalProgress;
39 private ImageView mFavicon;
40 private ImageView mLockIcon;
41 private boolean mInLoad;
Leon Scroggins81db3662009-06-04 17:45:11 -040042
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040043 public TitleBar(Context context) {
44 this(context, null);
45 }
Leon Scroggins81db3662009-06-04 17:45:11 -040046
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040047 public TitleBar(Context context, AttributeSet attrs) {
48 super(context, attrs);
Leon Scroggins81db3662009-06-04 17:45:11 -040049 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 Scrogginse4b3bda2009-06-09 15:46:41 -040055 mLftButton = (ImageView) findViewById(R.id.lft_button);
56 mRtButton = findViewById(R.id.rt_button);
Leon Scroggins81db3662009-06-04 17:45:11 -040057
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 Scrogginse4b3bda2009-06-09 15:46:41 -040064 }
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 Scroggins81db3662009-06-04 17:45:11 -040087 setOnClickListener(new View.OnClickListener() {
88 public void onClick(View v) {
Leon Scrogginse4b3bda2009-06-09 15:46:41 -040089 activity.onSearchRequested();
Leon Scroggins81db3662009-06-04 17:45:11 -040090 }
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 Scroggins81db3662009-06-04 17:45:11 -0400111 mDivider.setVisibility(View.VISIBLE);
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400112 mRtButton.setVisibility(View.VISIBLE);
113 mLftButton.setImageDrawable(mBookmarkDrawable);
Leon Scroggins81db3662009-06-04 17:45:11 -0400114 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 Scrogginse4b3bda2009-06-09 15:46:41 -0400121 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 Scroggins81db3662009-06-04 17:45:11 -0400130 mInLoad = true;
131 }
132 }
133
134 /* package */ void setTitleAndUrl(CharSequence title, CharSequence url) {
Leon Scrogginse4b3bda2009-06-09 15:46:41 -0400135 if (null == title) {
Leon Scroggins81db3662009-06-04 17:45:11 -0400136 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}