blob: 0eb2d1a39b98ab5acc3e3da8d66bfb7c1c7eba39 [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);
89 mFavicon.setVisibility(View.GONE);
90 mLockIcon.setVisibility(View.GONE);
91 mStopButton.setVisibility(View.GONE);
92 mVoiceButton.setVisibility(View.VISIBLE);
93 } else {
94 mFavicon.setVisibility(View.VISIBLE);
95 mLockIcon.setVisibility(mHasLockIcon ? View.VISIBLE : View.GONE);
96 if (mInLoad) {
97 mStopButton.setVisibility(View.VISIBLE);
98 } else {
99 mStopButton.setVisibility(View.GONE);
100 }
101 mVoiceButton.setVisibility(View.GONE);
102 }
103 }
104
Michael Kolb11d19782011-03-20 10:17:40 -0700105 @Override
Michael Kolb46f987e2011-04-05 10:39:10 -0700106 protected void onProgressStarted() {
107 setFocusState(mUrlInput.hasFocus());
108 }
109
110 @Override
111 protected void onProgressStopped() {
112 setFocusState(mUrlInput.hasFocus());
Michael Kolb11d19782011-03-20 10:17:40 -0700113 }
114
115 /**
116 * Update the text displayed in the title bar.
117 * @param title String to display. If null, the new tab string will be
118 * shown.
119 */
120 @Override
121 void setDisplayTitle(String title) {
122 if (title == null) {
123 mUrlInput.setText(R.string.new_tab);
124 } else {
125 mUrlInput.setText(title);
126 }
127 }
128
129 @Override
130 public void onFocusChange(View v, boolean hasFocus) {
131 if (v == mUrlInput) {
132 if (hasFocus) {
133 mActivity.closeOptionsMenu();
134 }
135 }
136 super.onFocusChange(v, hasFocus);
Michael Kolbf2055602011-04-09 17:20:03 -0700137 if (!hasFocus) {
Michael Kolbfdb70242011-03-24 09:41:11 -0700138 mBaseUi.hideTitleBar();
139 }
Michael Kolb11d19782011-03-20 10:17:40 -0700140 }
141
142 @Override
143 public void onClick(View v) {
144 if (v == mStopButton) {
145 mUiController.stopLoading();
146 } else if (v == mVoiceButton) {
147 mUiController.startVoiceSearch();
148 } else {
149 super.onClick(v);
150 }
151 }
152
Michael Kolb11d19782011-03-20 10:17:40 -0700153}