Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.app.Activity; |
| 20 | import android.content.Context; |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 22 | import android.view.LayoutInflater; |
| 23 | import android.view.Menu; |
| 24 | import android.view.MenuItem; |
| 25 | import android.view.View; |
| 26 | import android.view.View.OnClickListener; |
| 27 | import android.view.ViewGroup; |
| 28 | import android.webkit.WebView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 29 | import android.widget.BaseAdapter; |
| 30 | import android.widget.FrameLayout; |
| 31 | import android.widget.Gallery; |
| 32 | import android.widget.ImageButton; |
| 33 | import android.widget.ImageView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 34 | import android.widget.ListPopupWindow; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 35 | import android.widget.RelativeLayout; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 36 | import android.widget.TextView; |
| 37 | |
| 38 | import java.util.ArrayList; |
| 39 | import java.util.List; |
| 40 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 41 | public class NavScreen extends RelativeLayout implements OnClickListener { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 42 | |
| 43 | UiController mUiController; |
| 44 | PhoneUi mUi; |
| 45 | Tab mTab; |
| 46 | Activity mActivity; |
| 47 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 48 | ImageButton mRefresh; |
| 49 | ImageButton mForward; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 50 | ImageButton mBookmarks; |
| 51 | ImageButton mMore; |
| 52 | ImageButton mNewTab; |
| 53 | ImageButton mNewIncognito; |
| 54 | FrameLayout mHolder; |
| 55 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 56 | TextView mTitle; |
| 57 | ImageView mFavicon; |
| 58 | ImageButton mCloseTab; |
| 59 | |
| 60 | NavTabScroller mScroller; |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 61 | float mTabAspect = 0.66f; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 62 | int mTabWidth; |
| 63 | int mTabHeight; |
| 64 | TabAdapter mAdapter; |
| 65 | ListPopupWindow mPopup; |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 66 | int mOrientation; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 67 | |
| 68 | public NavScreen(Activity activity, UiController ctl, PhoneUi ui) { |
| 69 | super(activity); |
| 70 | mActivity = activity; |
| 71 | mUiController = ctl; |
| 72 | mUi = ui; |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 73 | mOrientation = activity.getResources().getConfiguration().orientation; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 74 | init(); |
| 75 | } |
| 76 | |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 77 | @Override |
| 78 | public void onMeasure(int wspec, int hspec) { |
| 79 | super.onMeasure(wspec, hspec); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void onAttachedToWindow() { |
| 84 | mAdapter.notifyDataSetChanged(); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 87 | protected Tab getSelectedTab() { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 88 | return (Tab) mScroller.getSelectedItem(); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 91 | protected void showMenu() { |
| 92 | Menu menu = mUi.getMenu(); |
| 93 | menu.setGroupVisible(R.id.NAV_MENU, false); |
| 94 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 95 | MenuAdapter menuAdapter = new MenuAdapter(mContext); |
| 96 | menuAdapter.setMenu(menu); |
| 97 | ListPopupWindow popup = new ListPopupWindow(mContext); |
| 98 | popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); |
| 99 | popup.setAdapter(menuAdapter); |
| 100 | popup.setModal(true); |
| 101 | popup.setAnchorView(mMore); |
| 102 | popup.setWidth((int) mContext.getResources().getDimension( |
| 103 | R.dimen.menu_width)); |
| 104 | popup.show(); |
| 105 | mPopup = popup; |
| 106 | } |
| 107 | |
John Reck | adc921f | 2011-04-27 10:11:03 -0700 | [diff] [blame] | 108 | protected float getToolbarHeight() { |
| 109 | return mActivity.getResources().getDimension(R.dimen.toolbar_height); |
| 110 | } |
| 111 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 112 | protected void dismissMenu() { |
| 113 | if (mPopup != null) { |
| 114 | mPopup.dismiss(); |
| 115 | } |
| 116 | } |
| 117 | |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 118 | // for configuration changes |
| 119 | @Override |
| 120 | protected void onConfigurationChanged(Configuration newconfig) { |
| 121 | if (newconfig.orientation != mOrientation) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 122 | int selIx = mScroller.getSelectionIndex(); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 123 | removeAllViews(); |
| 124 | init(); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 125 | mScroller.setSelection(selIx); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 126 | mOrientation = newconfig.orientation; |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 127 | mAdapter.notifyDataSetChanged(); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 131 | private void init() { |
| 132 | LayoutInflater.from(mContext).inflate(R.layout.nav_screen, this); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 133 | mBookmarks = (ImageButton) findViewById(R.id.bookmarks); |
| 134 | mNewTab = (ImageButton) findViewById(R.id.newtab); |
| 135 | mNewIncognito = (ImageButton) findViewById(R.id.newincognito); |
| 136 | mMore = (ImageButton) findViewById(R.id.more); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 137 | mBookmarks.setOnClickListener(this); |
| 138 | mNewTab.setOnClickListener(this); |
| 139 | mNewIncognito.setOnClickListener(this); |
| 140 | mMore.setOnClickListener(this); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 141 | mScroller = (NavTabScroller) findViewById(R.id.scroller); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 142 | mAdapter = new TabAdapter(mContext, mUiController.getTabControl()); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 143 | mScroller.setAdapter(mAdapter); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 144 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 145 | // update state for active tab |
| 146 | mScroller.setSelection(mUiController.getTabControl().getTabPosition(mUi.getActiveTab())); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onClick(View v) { |
| 151 | WebView web = (mTab != null) ? mTab.getWebView() : null; |
| 152 | if (web != null) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 153 | if (mForward == v) { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 154 | mUi.hideNavScreen(true); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 155 | web.goForward(); |
| 156 | } else if (mRefresh == v) { |
| 157 | mUi.hideNavScreen(true); |
| 158 | web.reload(); |
| 159 | } |
| 160 | } |
| 161 | if (mBookmarks == v) { |
| 162 | mUi.hideNavScreen(false); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 163 | switchToSelected(); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 164 | mUiController.bookmarksOrHistoryPicker(false); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 165 | } else if (mNewTab == v) { |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 166 | openNewTab(); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 167 | } else if (mMore == v) { |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 168 | showMenu(); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 169 | } else if (mNewIncognito == v) { |
| 170 | mUi.hideNavScreen(true); |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 171 | mUiController.openIncognitoTab(); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 172 | } else if (mTitle == v) { |
| 173 | mUi.getTitleBar().setSkipTitleBarAnimations(true); |
| 174 | close(false); |
| 175 | mUi.editUrl(false); |
| 176 | mUi.getTitleBar().setSkipTitleBarAnimations(false); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 180 | private void onCloseTab(Tab tab) { |
| 181 | if (tab != null) { |
| 182 | mUiController.closeTab(tab); |
| 183 | if (mUiController.getTabControl().getTabCount() == 0) { |
| 184 | openNewTab(); |
| 185 | } else { |
| 186 | mAdapter.notifyDataSetChanged(); |
| 187 | } |
| 188 | } |
| 189 | } |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 190 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 191 | |
| 192 | private void openNewTab() { |
| 193 | // need to call openTab explicitely with setactive false |
| 194 | Tab tab = mUiController.openTab(BrowserSettings.getInstance().getHomePage(), |
| 195 | false, false, false); |
| 196 | mAdapter.notifyDataSetChanged(); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 197 | if (tab != null) { |
| 198 | // set tab as the selected in flipper, then hide |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 199 | final int tix = mUi.mTabControl.getTabPosition(tab); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 200 | mScroller.setSelection(tix); |
| 201 | postDelayed(new Runnable() { |
| 202 | @Override |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 203 | public void run() { |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 204 | mUi.hideNavScreen(true); |
| 205 | switchToSelected(); |
| 206 | } |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 207 | }, 100); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | private void switchToSelected() { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 212 | Tab tab = (Tab) mScroller.getSelectedItem(); |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 213 | if (tab != mUi.getActiveTab()) { |
| 214 | mUiController.setActiveTab(tab); |
| 215 | } |
| 216 | } |
| 217 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 218 | protected void close() { |
| 219 | close(true); |
| 220 | } |
| 221 | |
| 222 | protected void close(boolean animate) { |
| 223 | mUi.hideNavScreen(animate); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | class TabGallery extends Gallery { |
| 227 | |
| 228 | public TabGallery(Context ctx) { |
| 229 | super(ctx); |
| 230 | setUnselectedAlpha(0.3f); |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | protected ViewGroup.LayoutParams generateDefaultLayoutParams() { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 235 | return new Gallery.LayoutParams(mTabWidth, mTabHeight); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) { |
| 240 | return generateDefaultLayoutParams(); |
| 241 | } |
| 242 | |
| 243 | } |
| 244 | |
| 245 | class TabAdapter extends BaseAdapter { |
| 246 | |
| 247 | Context context; |
| 248 | TabControl tabControl; |
| 249 | |
| 250 | public TabAdapter(Context ctx, TabControl tc) { |
| 251 | context = ctx; |
| 252 | tabControl = tc; |
| 253 | } |
| 254 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 255 | @Override |
| 256 | public int getCount() { |
| 257 | return tabControl.getTabCount(); |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public Tab getItem(int position) { |
| 262 | return tabControl.getTab(position); |
| 263 | } |
| 264 | |
| 265 | public long getItemId(int position) { |
| 266 | return position; |
| 267 | } |
| 268 | |
| 269 | @Override |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 270 | public View getView(final int position, View convertView, ViewGroup parent) { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 271 | if (convertView == null) { |
| 272 | convertView = LayoutInflater.from(context).inflate(R.layout.nav_tab_view, |
| 273 | null); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 274 | } |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 275 | final Tab tab = getItem(position); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 276 | final BrowserWebView web = (BrowserWebView) tab.getWebView(); |
| 277 | removeFromParent(web); |
| 278 | FrameLayout mview = (FrameLayout) convertView.findViewById(R.id.tab_view); |
| 279 | mview.addView(web, 0); |
| 280 | ImageButton close = (ImageButton) convertView.findViewById(R.id.closetab); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 281 | close.setOnClickListener(new OnClickListener() { |
| 282 | @Override |
| 283 | public void onClick(View v) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 284 | onCloseTab((Tab) (mScroller.getSelectedItem())); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 285 | } |
| 286 | }); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 287 | web.setNavMode(true); |
| 288 | web.setOnClickListener(new OnClickListener() { |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 289 | @Override |
| 290 | public void onClick(View v) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 291 | mScroller.setSelection(position); |
| 292 | close(); |
| 293 | } |
| 294 | }); |
| 295 | ImageButton forward = (ImageButton) convertView.findViewById(R.id.forward); |
| 296 | ImageButton refresh = (ImageButton) convertView.findViewById(R.id.refresh); |
| 297 | TextView title = (TextView) convertView.findViewById(R.id.title); |
| 298 | ImageView favicon = (ImageView) convertView.findViewById(R.id.favicon); |
| 299 | if (web != null) { |
| 300 | forward.setVisibility(web.canGoForward() |
| 301 | ? View.VISIBLE : View.GONE); |
| 302 | } |
| 303 | // refresh titlebar |
| 304 | favicon.setImageDrawable(mUi.getFaviconDrawable(tab.getFavicon())); |
| 305 | title.setText(tab.getUrl()); |
| 306 | title.setOnClickListener(new OnClickListener() { |
| 307 | @Override |
| 308 | public void onClick(View v) { |
Michael Kolb | ff6c36b | 2011-05-04 14:21:34 -0700 | [diff] [blame] | 309 | mUi.getTitleBar().setSkipTitleBarAnimations(true); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 310 | close(false); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 311 | mUi.editUrl(false); |
Michael Kolb | ff6c36b | 2011-05-04 14:21:34 -0700 | [diff] [blame] | 312 | mUi.getTitleBar().setSkipTitleBarAnimations(false); |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 313 | } |
| 314 | }); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 315 | forward.setOnClickListener(new OnClickListener() { |
| 316 | @Override |
| 317 | public void onClick(View v) { |
| 318 | mUi.hideNavScreen(true); |
| 319 | web.goForward(); |
| 320 | } |
| 321 | }); |
| 322 | refresh.setOnClickListener(new OnClickListener() { |
| 323 | @Override |
| 324 | public void onClick(View v) { |
| 325 | mUi.hideNavScreen(true); |
| 326 | web.reload(); |
| 327 | } |
| 328 | }); |
| 329 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 330 | return convertView; |
| 331 | } |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 332 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | private class MenuAdapter extends BaseAdapter implements OnClickListener { |
| 336 | |
| 337 | List<MenuItem> mItems; |
| 338 | LayoutInflater mInflater; |
| 339 | |
| 340 | public MenuAdapter(Context ctx) { |
| 341 | mInflater = LayoutInflater.from(ctx); |
| 342 | mItems = new ArrayList<MenuItem>(); |
| 343 | } |
| 344 | |
| 345 | public void setMenu(Menu menu) { |
| 346 | mItems.clear(); |
| 347 | for (int i = 0; i < menu.size(); i++) { |
| 348 | MenuItem item = menu.getItem(i); |
| 349 | if (item.isEnabled() && item.isVisible()) { |
| 350 | mItems.add(item); |
| 351 | } |
| 352 | } |
| 353 | notifyDataSetChanged(); |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public int getCount() { |
| 358 | return mItems.size(); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public MenuItem getItem(int position) { |
| 363 | return mItems.get(position); |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public long getItemId(int position) { |
| 368 | return position; |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void onClick(View v) { |
| 373 | if (v.getTag() != null) { |
| 374 | dismissMenu(); |
| 375 | mActivity.closeOptionsMenu(); |
| 376 | mUi.hideNavScreen(false); |
| 377 | mUiController.onOptionsItemSelected((MenuItem) v.getTag()); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public View getView(int position, View convertView, ViewGroup parent) { |
| 383 | final MenuItem item = mItems.get(position); |
| 384 | View view = mInflater.inflate(R.layout.qc_menu_item, null); |
| 385 | TextView label = (TextView) view.findViewById(R.id.title); |
| 386 | label.setText(item.getTitle()); |
| 387 | label.setTag(item); |
| 388 | label.setOnClickListener(this); |
| 389 | return label; |
| 390 | } |
| 391 | |
| 392 | } |
| 393 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame^] | 394 | private static void removeFromParent(View v) { |
| 395 | if (v.getParent() != null) { |
| 396 | ((ViewGroup) v.getParent()).removeView(v); |
| 397 | } |
| 398 | } |
| 399 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 400 | } |