Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenu.java

Issue 388803006: Add per-item animations to the menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 mPopup.show(); 129 mPopup.show();
128 mPopup.getListView().setItemsCanFocus(true); 130 mPopup.getListView().setItemsCanFocus(true);
129 mPopup.getListView().setOnKeyListener(this); 131 mPopup.getListView().setOnKeyListener(this);
130 132
131 mHandler.onMenuVisibilityChanged(true); 133 mHandler.onMenuVisibilityChanged(true);
132 134
133 if (mVerticalFadeDistance > 0) { 135 if (mVerticalFadeDistance > 0) {
134 mPopup.getListView().setVerticalFadingEdgeEnabled(true); 136 mPopup.getListView().setVerticalFadingEdgeEnabled(true);
135 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance); 137 mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance);
136 } 138 }
139
140 mPopup.getListView().addOnLayoutChangeListener(new View.OnLayoutChangeLi stener() {
141 @Override
142 public void onLayoutChange(View v, int left, int top, int right, int bottom,
143 int oldLeft, int oldTop, int oldRight, int oldBottom) {
144 mPopup.getListView().removeOnLayoutChangeListener(this);
145 runMenuItemEnterAnimations();
146 }
147 });
137 } 148 }
138 149
139 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) { 150 private void setPopupOffset(ListPopupWindow popup, int screenRotation, Rect appRect) {
140 Rect paddingRect = new Rect(); 151 Rect paddingRect = new Rect();
141 popup.getBackground().getPadding(paddingRect); 152 popup.getBackground().getPadding(paddingRect);
142 int[] anchorLocation = new int[2]; 153 int[] anchorLocation = new int[2];
143 popup.getAnchorView().getLocationInWindow(anchorLocation); 154 popup.getAnchorView().getLocationInWindow(anchorLocation);
144 155
145 // If we have a hardware menu button, locate the app menu closer to the estimated 156 // If we have a hardware menu button, locate the app menu closer to the estimated
146 // hardware menu button location. 157 // hardware menu button location.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 216 }
206 } 217 }
207 return false; 218 return false;
208 } 219 }
209 220
210 /** 221 /**
211 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla ce. 222 * Dismisses the app menu and cancels the drag-to-scroll if it is taking pla ce.
212 */ 223 */
213 void dismiss() { 224 void dismiss() {
214 mHandler.appMenuDismissed(); 225 mHandler.appMenuDismissed();
215 if (isShowing()) mPopup.dismiss(); 226 if (isShowing()) {
227 runMenuItemExitAnimations();
228 mPopup.dismiss();
229 }
216 } 230 }
217 231
218 /** 232 /**
219 * @return Whether the app menu is currently showing. 233 * @return Whether the app menu is currently showing.
220 */ 234 */
221 boolean isShowing() { 235 boolean isShowing() {
222 if (mPopup == null) { 236 if (mPopup == null) {
223 return false; 237 return false;
224 } 238 }
225 return mPopup.isShowing(); 239 return mPopup.isShowing();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 mPopup.setHeight(spaceForFullItems + spaceForPartialItem + 271 mPopup.setHeight(spaceForFullItems + spaceForPartialItem +
258 padding.top + padding.bottom); 272 padding.top + padding.bottom);
259 } else { 273 } else {
260 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa rtialItem + 274 mPopup.setHeight(spaceForFullItems - mItemRowHeight + spaceForPa rtialItem +
261 padding.top + padding.bottom); 275 padding.top + padding.bottom);
262 } 276 }
263 } else { 277 } else {
264 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 278 mPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
265 } 279 }
266 } 280 }
281
282 private void runMenuItemEnterAnimations() {
283 runMenuItemAnimators(R.id.menu_item_enter_anim_id);
284 }
285
286 private void runMenuItemExitAnimations() {
287 runMenuItemAnimators(R.id.menu_item_exit_anim_id);
288 }
289
290 private void runMenuItemAnimators(int animationTagId) {
291 AnimatorSet animation = new AnimatorSet();
292 AnimatorSet.Builder builder = null;
293
294 ViewGroup list = mPopup.getListView();
aurimas (slooooooooow) 2014/07/15 01:37:25 Should we be animating the views that are currentl
David Trainor- moved to gerrit 2014/07/15 20:53:38 This will animate all the views that are currently
295 for (int i = 0; i < list.getChildCount(); i++) {
296 View view = list.getChildAt(i);
297 Object animatorObject = view.getTag(animationTagId);
298 if (animatorObject != null) {
299 if (builder == null) {
300 builder = animation.play((Animator) animatorObject);
301 } else {
302 builder.with((Animator) animatorObject);
303 }
304 }
305 }
306
307 animation.start();
308 }
267 } 309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698