| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.animation.Animator; | 7 import android.animation.Animator; |
| 8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
| 9 import android.annotation.SuppressLint; | 9 import android.annotation.SuppressLint; |
| 10 import android.annotation.TargetApi; | 10 import android.annotation.TargetApi; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 private final VSyncMonitor mVSyncMonitor; | 70 private final VSyncMonitor mVSyncMonitor; |
| 71 | 71 |
| 72 // A string used as a key to store intent errors in a bundle | 72 // A string used as a key to store intent errors in a bundle |
| 73 static final String WINDOW_CALLBACK_ERRORS = "window_callback_errors"; | 73 static final String WINDOW_CALLBACK_ERRORS = "window_callback_errors"; |
| 74 | 74 |
| 75 // Error code returned when an Intent fails to start an Activity. | 75 // Error code returned when an Intent fails to start an Activity. |
| 76 public static final int START_INTENT_FAILURE = -1; | 76 public static final int START_INTENT_FAILURE = -1; |
| 77 | 77 |
| 78 protected Context mApplicationContext; | 78 protected Context mApplicationContext; |
| 79 protected SparseArray<IntentCallback> mOutstandingIntents; | 79 protected SparseArray<IntentCallback> mOutstandingIntents; |
| 80 // To render properly on an external display through a Presentation we need
to fetch |
| 81 // display metrics from the context provided by the Presentation. This conte
xt is not the same |
| 82 // as the application context since the application context targets the prim
ary display. |
| 83 // We use a weak reference here to prevent this from leaking in WebView. |
| 84 private WeakReference<Context> mDisplayContextRef; |
| 80 | 85 |
| 81 // Ideally, this would be a SparseArray<String>, but there's no easy way to
store a | 86 // Ideally, this would be a SparseArray<String>, but there's no easy way to
store a |
| 82 // SparseArray<String> in a bundle during saveInstanceState(). So we use a H
ashMap and suppress | 87 // SparseArray<String> in a bundle during saveInstanceState(). So we use a H
ashMap and suppress |
| 83 // the Android lint warning "UseSparseArrays". | 88 // the Android lint warning "UseSparseArrays". |
| 84 protected HashMap<Integer, String> mIntentErrors; | 89 protected HashMap<Integer, String> mIntentErrors; |
| 85 | 90 |
| 86 // We track all animations over content and provide a drawing placeholder fo
r them. | 91 // We track all animations over content and provide a drawing placeholder fo
r them. |
| 87 private HashSet<Animator> mAnimationsOverContent = new HashSet<Animator>(); | 92 private HashSet<Animator> mAnimationsOverContent = new HashSet<Animator>(); |
| 88 private View mAnimationPlaceholderView; | 93 private View mAnimationPlaceholderView; |
| 89 | 94 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 */ | 134 */ |
| 130 public boolean isInsideVSync() { | 135 public boolean isInsideVSync() { |
| 131 return mVSyncMonitor.isInsideVSync(); | 136 return mVSyncMonitor.isInsideVSync(); |
| 132 } | 137 } |
| 133 | 138 |
| 134 /** | 139 /** |
| 135 * @param context The application context. | 140 * @param context The application context. |
| 136 */ | 141 */ |
| 137 @SuppressLint("UseSparseArrays") | 142 @SuppressLint("UseSparseArrays") |
| 138 public WindowAndroid(Context context) { | 143 public WindowAndroid(Context context) { |
| 139 assert context == context.getApplicationContext(); | 144 mApplicationContext = context.getApplicationContext(); |
| 140 mApplicationContext = context; | 145 // context could be an Activity Context so we can't hold a strong refere
nce to it. |
| 146 mDisplayContextRef = new WeakReference<Context>(context); |
| 141 mOutstandingIntents = new SparseArray<IntentCallback>(); | 147 mOutstandingIntents = new SparseArray<IntentCallback>(); |
| 142 mIntentErrors = new HashMap<Integer, String>(); | 148 mIntentErrors = new HashMap<Integer, String>(); |
| 143 mVSyncMonitor = new VSyncMonitor(context, mVSyncListener); | 149 mVSyncMonitor = new VSyncMonitor(context, mVSyncListener); |
| 144 mAccessibilityManager = (AccessibilityManager) | 150 mAccessibilityManager = (AccessibilityManager) mApplicationContext.getSy
stemService( |
| 145 context.getSystemService(Context.ACCESSIBILITY_SERVICE); | 151 Context.ACCESSIBILITY_SERVICE); |
| 146 } | 152 } |
| 147 | 153 |
| 148 /** | 154 /** |
| 149 * Set the delegate that will handle android permissions requests. | 155 * Set the delegate that will handle android permissions requests. |
| 150 */ | 156 */ |
| 151 @VisibleForTesting | 157 @VisibleForTesting |
| 152 public void setAndroidPermissionDelegate(AndroidPermissionDelegate delegate)
{ | 158 public void setAndroidPermissionDelegate(AndroidPermissionDelegate delegate)
{ |
| 153 mPermissionDelegate = delegate; | 159 mPermissionDelegate = delegate; |
| 154 } | 160 } |
| 155 | 161 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 animation.addListener(new AnimatorListenerAdapter() { | 582 animation.addListener(new AnimatorListenerAdapter() { |
| 577 @Override | 583 @Override |
| 578 public void onAnimationEnd(Animator animation) { | 584 public void onAnimationEnd(Animator animation) { |
| 579 animation.removeListener(this); | 585 animation.removeListener(this); |
| 580 mAnimationsOverContent.remove(animation); | 586 mAnimationsOverContent.remove(animation); |
| 581 refreshWillNotDraw(); | 587 refreshWillNotDraw(); |
| 582 } | 588 } |
| 583 }); | 589 }); |
| 584 } | 590 } |
| 585 | 591 |
| 592 @CalledByNative |
| 593 private Context getDisplayContext() { |
| 594 return mDisplayContextRef.get(); |
| 595 } |
| 596 |
| 586 /** | 597 /** |
| 587 * Update whether the placeholder is 'drawn' based on whether an animation i
s running | 598 * Update whether the placeholder is 'drawn' based on whether an animation i
s running |
| 588 * or touch exploration is enabled - if either of those are true, we call | 599 * or touch exploration is enabled - if either of those are true, we call |
| 589 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf
aceView, | 600 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf
aceView, |
| 590 * and otherwise we call setWillNotDraw(true). | 601 * and otherwise we call setWillNotDraw(true). |
| 591 */ | 602 */ |
| 592 private void refreshWillNotDraw() { | 603 private void refreshWillNotDraw() { |
| 593 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont
ent.isEmpty(); | 604 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont
ent.isEmpty(); |
| 594 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) { | 605 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) { |
| 595 mAnimationPlaceholderView.setWillNotDraw(willNotDraw); | 606 mAnimationPlaceholderView.setWillNotDraw(willNotDraw); |
| 596 } | 607 } |
| 597 } | 608 } |
| 598 | 609 |
| 599 private native long nativeInit(); | 610 private native long nativeInit(); |
| 600 private native void nativeOnVSync(long nativeWindowAndroid, | 611 private native void nativeOnVSync(long nativeWindowAndroid, |
| 601 long vsyncTimeMicros, | 612 long vsyncTimeMicros, |
| 602 long vsyncPeriodMicros); | 613 long vsyncPeriodMicros); |
| 603 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool
ean visible); | 614 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool
ean visible); |
| 604 private native void nativeOnActivityStopped(long nativeWindowAndroid); | 615 private native void nativeOnActivityStopped(long nativeWindowAndroid); |
| 605 private native void nativeOnActivityStarted(long nativeWindowAndroid); | 616 private native void nativeOnActivityStarted(long nativeWindowAndroid); |
| 606 private native void nativeDestroy(long nativeWindowAndroid); | 617 private native void nativeDestroy(long nativeWindowAndroid); |
| 607 | 618 |
| 608 } | 619 } |
| OLD | NEW |