| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.appmenu; | 5 package org.chromium.chrome.browser.appmenu; |
| 6 | 6 |
| 7 import android.animation.Animator; |
| 8 import android.animation.AnimatorSet; |
| 7 import android.content.Context; | 9 import android.content.Context; |
| 8 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| 9 import android.graphics.Rect; | 11 import android.graphics.Rect; |
| 10 import android.view.KeyEvent; | 12 import android.view.KeyEvent; |
| 11 import android.view.LayoutInflater; | 13 import android.view.LayoutInflater; |
| 12 import android.view.Menu; | 14 import android.view.Menu; |
| 13 import android.view.MenuItem; | 15 import android.view.MenuItem; |
| 14 import android.view.Surface; | 16 import android.view.Surface; |
| 15 import android.view.View; | 17 import android.view.View; |
| 16 import android.view.View.OnKeyListener; | 18 import android.view.View.OnKeyListener; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 mPopup.show(); | 142 mPopup.show(); |
| 141 mPopup.getListView().setItemsCanFocus(true); | 143 mPopup.getListView().setItemsCanFocus(true); |
| 142 mPopup.getListView().setOnKeyListener(this); | 144 mPopup.getListView().setOnKeyListener(this); |
| 143 | 145 |
| 144 mHandler.onMenuVisibilityChanged(true); | 146 mHandler.onMenuVisibilityChanged(true); |
| 145 | 147 |
| 146 if (mVerticalFadeDistance > 0) { | 148 if (mVerticalFadeDistance > 0) { |
| 147 mPopup.getListView().setVerticalFadingEdgeEnabled(true); | 149 mPopup.getListView().setVerticalFadingEdgeEnabled(true); |
| 148 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance); | 150 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance); |
| 149 } | 151 } |
| 152 |
| 153 mPopup.getListView().addOnLayoutChangeListener(new View.OnLayoutChangeLi
stener() { |
| 154 @Override |
| 155 public void onLayoutChange(View v, int left, int top, int right, int
bottom, |
| 156 int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 157 mPopup.getListView().removeOnLayoutChangeListener(this); |
| 158 runMenuItemEnterAnimations(); |
| 159 } |
| 160 }); |
| 150 } | 161 } |
| 151 | 162 |
| 152 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect
appRect) { | 163 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect
appRect) { |
| 153 Rect paddingRect = new Rect(); | 164 Rect paddingRect = new Rect(); |
| 154 popup.getBackground().getPadding(paddingRect); | 165 popup.getBackground().getPadding(paddingRect); |
| 155 int[] anchorLocation = new int[2]; | 166 int[] anchorLocation = new int[2]; |
| 156 popup.getAnchorView().getLocationInWindow(anchorLocation); | 167 popup.getAnchorView().getLocationInWindow(anchorLocation); |
| 157 | 168 |
| 158 // If we have a hardware menu button, locate the app menu closer to the
estimated | 169 // If we have a hardware menu button, locate the app menu closer to the
estimated |
| 159 // hardware menu button location. | 170 // hardware menu button location. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 229 } |
| 219 } | 230 } |
| 220 return false; | 231 return false; |
| 221 } | 232 } |
| 222 | 233 |
| 223 /** | 234 /** |
| 224 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla
ce. | 235 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla
ce. |
| 225 */ | 236 */ |
| 226 void dismiss() { | 237 void dismiss() { |
| 227 mHandler.appMenuDismissed(); | 238 mHandler.appMenuDismissed(); |
| 228 if (isShowing()) mPopup.dismiss(); | 239 if (isShowing()) { |
| 240 mPopup.dismiss(); |
| 241 } |
| 229 } | 242 } |
| 230 | 243 |
| 231 /** | 244 /** |
| 232 * @return Whether the app menu is currently showing. | 245 * @return Whether the app menu is currently showing. |
| 233 */ | 246 */ |
| 234 boolean isShowing() { | 247 boolean isShowing() { |
| 235 if (mPopup == null) { | 248 if (mPopup == null) { |
| 236 return false; | 249 return false; |
| 237 } | 250 } |
| 238 return mPopup.isShowing(); | 251 return mPopup.isShowing(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 mPopup.setHeight(spaceForFullItems + spaceForPartialItem + | 283 mPopup.setHeight(spaceForFullItems + spaceForPartialItem + |
| 271 padding.top + padding.bottom); | 284 padding.top + padding.bottom); |
| 272 } else { | 285 } else { |
| 273 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa
rtialItem + | 286 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa
rtialItem + |
| 274 padding.top + padding.bottom); | 287 padding.top + padding.bottom); |
| 275 } | 288 } |
| 276 } else { | 289 } else { |
| 277 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | 290 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
| 278 } | 291 } |
| 279 } | 292 } |
| 293 |
| 294 private void runMenuItemEnterAnimations() { |
| 295 AnimatorSet animation = new AnimatorSet(); |
| 296 AnimatorSet.Builder builder = null; |
| 297 |
| 298 ViewGroup list = mPopup.getListView(); |
| 299 for (int i = 0; i < list.getChildCount(); i++) { |
| 300 View view = list.getChildAt(i); |
| 301 Object animatorObject = view.getTag(R.id.menu_item_enter_anim_id); |
| 302 if (animatorObject != null) { |
| 303 if (builder == null) { |
| 304 builder = animation.play((Animator) animatorObject); |
| 305 } else { |
| 306 builder.with((Animator) animatorObject); |
| 307 } |
| 308 } |
| 309 } |
| 310 |
| 311 animation.start(); |
| 312 } |
| 280 } | 313 } |
| OLD | NEW |