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