blob: 9242f99a031f5c7d9b236f012582cc4d0b6442e1 [file] [log] [blame]
Michael Kolb11d19782011-03-20 10:17:40 -07001/*
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 com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
Michael Kolb11d19782011-03-20 10:17:40 -070020
21import android.app.Activity;
22import android.content.Context;
23import android.view.ContextMenu;
24import android.view.MenuInflater;
25import android.view.View;
26import android.view.View.OnClickListener;
27import android.view.View.OnFocusChangeListener;
Michael Kolbfdb70242011-03-24 09:41:11 -070028import android.widget.FrameLayout;
Michael Kolb11d19782011-03-20 10:17:40 -070029import android.widget.ImageView;
30
31import java.util.List;
32
33/**
34 * This class represents a title bar for a particular "tab" or "window" in the
35 * browser.
36 */
37public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener,
38 OnClickListener, TextChangeWatcher {
39
40 private Activity mActivity;
Michael Kolbc16c5952011-03-29 15:37:03 -070041 private ImageView mStopButton;
Michael Kolb11d19782011-03-20 10:17:40 -070042 private ImageView mVoiceButton;
Michael Kolb11d19782011-03-20 10:17:40 -070043 private boolean mHasLockIcon;
44
Michael Kolb46f987e2011-04-05 10:39:10 -070045 public TitleBarPhone(Activity activity, UiController controller, PhoneUi ui,
46 FrameLayout parent) {
47 super(activity, controller, ui, parent);
Michael Kolb11d19782011-03-20 10:17:40 -070048 mActivity = activity;
49 initLayout(activity, R.layout.title_bar);
50 }
51
52 @Override
53 protected void initLayout(Context context, int layoutId) {
54 super.initLayout(context, layoutId);
Michael Kolb11d19782011-03-20 10:17:40 -070055 mLockIcon = (ImageView) findViewById(R.id.lock);
56 mFavicon = (ImageView) findViewById(R.id.favicon);
Michael Kolbc16c5952011-03-29 15:37:03 -070057 mStopButton = (ImageView) findViewById(R.id.stop);
Michael Kolb11d19782011-03-20 10:17:40 -070058 mStopButton.setOnClickListener(this);
59 mVoiceButton = (ImageView) findViewById(R.id.voice);
60 mVoiceButton.setOnClickListener(this);
61 setFocusState(false);
62 }
63
64 @Override
Michael Kolb11d19782011-03-20 10:17:40 -070065 public void createContextMenu(ContextMenu menu) {
66 MenuInflater inflater = mActivity.getMenuInflater();
67 inflater.inflate(R.menu.title_context, menu);
68 mActivity.onCreateContextMenu(menu, this, null);
69 }
70
71 @Override
72 public void setInVoiceMode(boolean voicemode, List<String> voiceResults) {
73 super.setInVoiceMode(voicemode, voiceResults);
74 }
75
76 @Override
77 protected void setSearchMode(boolean voiceSearchEnabled) {
78 boolean showvoicebutton = voiceSearchEnabled &&
79 mUiController.supportsVoiceSearch();
80 mVoiceButton.setVisibility(showvoicebutton ? View.VISIBLE :
81 View.GONE);
82 }
83
84 @Override
85 protected void setFocusState(boolean focus) {
86 super.setFocusState(focus);
87 if (focus) {
88 mHasLockIcon = (mLockIcon.getVisibility() == View.VISIBLE);
Michael Kolb11d19782011-03-20 10:17:40 -070089 mLockIcon.setVisibility(View.GONE);
90 mStopButton.setVisibility(View.GONE);
91 mVoiceButton.setVisibility(View.VISIBLE);
92 } else {
Michael Kolb11d19782011-03-20 10:17:40 -070093 mLockIcon.setVisibility(mHasLockIcon ? View.VISIBLE : View.GONE);
94 if (mInLoad) {
95 mStopButton.setVisibility(View.VISIBLE);
96 } else {
97 mStopButton.setVisibility(View.GONE);
98 }
99 mVoiceButton.setVisibility(View.GONE);
100 }
101 }
102
Michael Kolb11d19782011-03-20 10:17:40 -0700103 @Override
Michael Kolb46f987e2011-04-05 10:39:10 -0700104 protected void onProgressStarted() {
105 setFocusState(mUrlInput.hasFocus());
106 }
107
108 @Override
109 protected void onProgressStopped() {
110 setFocusState(mUrlInput.hasFocus());
Michael Kolb11d19782011-03-20 10:17:40 -0700111 }
112
113 /**
114 * Update the text displayed in the title bar.
115 * @param title String to display. If null, the new tab string will be
116 * shown.
117 */
118 @Override
119 void setDisplayTitle(String title) {
120 if (title == null) {
121 mUrlInput.setText(R.string.new_tab);
122 } else {
123 mUrlInput.setText(title);
124 }
125 }
126
127 @Override
128 public void onFocusChange(View v, boolean hasFocus) {
129 if (v == mUrlInput) {
130 if (hasFocus) {
131 mActivity.closeOptionsMenu();
132 }
133 }
134 super.onFocusChange(v, hasFocus);
Michael Kolbf2055602011-04-09 17:20:03 -0700135 if (!hasFocus) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700136 mBaseUi.hideTitleBar();
137 }
Michael Kolb11d19782011-03-20 10:17:40 -0700138 }
139
140 @Override
141 public void onClick(View v) {
142 if (v == mStopButton) {
143 mUiController.stopLoading();
144 } else if (v == mVoiceButton) {
145 mUiController.startVoiceSearch();
146 } else {
147 super.onClick(v);
148 }
149 }
150
Michael Kolb11d19782011-03-20 10:17:40 -0700151}