Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import android.view.View; | |
| 8 | |
| 7 import org.chromium.base.JNINamespace; | 9 import org.chromium.base.JNINamespace; |
| 8 import org.chromium.ui.ViewAndroidDelegate; | 10 import org.chromium.ui.ViewAndroidDelegate; |
| 9 import org.chromium.ui.WindowAndroid; | 11 import org.chromium.ui.WindowAndroid; |
| 10 | 12 |
| 11 /** | 13 /** |
| 12 * From the Chromium architecture point of view, ViewAndroid and its native coun terpart | 14 * From the Chromium architecture point of view, ViewAndroid and its native coun terpart |
| 13 * serve purpose of representing Android view where Chrome expects to have a cro ss platform | 15 * serve purpose of representing Android view where Chrome expects to have a cro ss platform |
| 14 * handle to the system view type. As Views are Java object on Android, this Vie wAndroid | 16 * handle to the system view type. As Views are Java object on Android, this Vie wAndroid |
| 15 * and its native counterpart provide the expected abstractions on the C++ side and allow | 17 * and its native counterpart provide the expected abstractions on the C++ side and allow |
| 16 * it to be flexibly glued to an actual Android Java View at runtime. | 18 * it to be flexibly glued to an actual Android Java View at runtime. |
| 17 * | 19 * |
| 18 * It should only be used where access to Android Views is needed from the C++ c ode. | 20 * It should only be used where access to Android Views is needed from the C++ c ode. |
| 19 */ | 21 */ |
| 20 @JNINamespace("ui") | 22 @JNINamespace("ui") |
| 21 public class ViewAndroid { | 23 public class ViewAndroid { |
| 22 // Native pointer to the c++ ViewAndroid object. | 24 // Native pointer to the c++ ViewAndroid object. |
| 23 private int mNativeViewAndroid = 0; | 25 private int mNativeViewAndroid = 0; |
| 24 private final ViewAndroidDelegate mViewAndroidDelegate; | 26 private final ViewAndroidDelegate mViewAndroidDelegate; |
| 25 private final WindowAndroid mWindowAndroid; | 27 private final WindowAndroid mWindowAndroid; |
| 28 private int mKeepScreenOnCount; | |
| 29 private View mKeepScreenOnView; | |
| 26 | 30 |
| 27 /** | 31 /** |
| 28 * Constructs a View object. | 32 * Constructs a View object. |
| 29 */ | 33 */ |
| 30 public ViewAndroid(WindowAndroid nativeWindow, ViewAndroidDelegate viewAndro idDelegate) { | 34 public ViewAndroid(WindowAndroid nativeWindow, ViewAndroidDelegate viewAndro idDelegate) { |
| 31 mWindowAndroid = nativeWindow; | 35 mWindowAndroid = nativeWindow; |
| 32 mViewAndroidDelegate = viewAndroidDelegate; | 36 mViewAndroidDelegate = viewAndroidDelegate; |
| 33 mNativeViewAndroid = nativeInit(mWindowAndroid.getNativePointer()); | 37 mNativeViewAndroid = nativeInit(mWindowAndroid.getNativePointer()); |
| 34 } | 38 } |
| 35 | 39 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 48 } | 52 } |
| 49 | 53 |
| 50 /** | 54 /** |
| 51 * Returns a pointer to the c++ AndroidWindow object. | 55 * Returns a pointer to the c++ AndroidWindow object. |
| 52 * @return A pointer to the c++ AndroidWindow. | 56 * @return A pointer to the c++ AndroidWindow. |
| 53 */ | 57 */ |
| 54 public int getNativePointer() { | 58 public int getNativePointer() { |
| 55 return mNativeViewAndroid; | 59 return mNativeViewAndroid; |
| 56 } | 60 } |
| 57 | 61 |
| 62 /** | |
| 63 * Set whether to keep screen on when this view is in foreground. | |
| 64 * @param keepScreenOn true if the screen needs to keep on. | |
| 65 */ | |
| 66 public void setKeepScreenOn(boolean keepScreenOn) { | |
|
newt (away)
2013/08/09 20:57:21
I think it should be more clear that this method i
michaelbai
2013/08/09 23:06:50
It was named by Android's convention, but yes, the
| |
| 67 if (keepScreenOn) { | |
| 68 mKeepScreenOnCount++; | |
| 69 if (mKeepScreenOnCount == 1) { | |
| 70 mKeepScreenOnView = mViewAndroidDelegate.acquireAnchorView(); | |
| 71 mKeepScreenOnView.setKeepScreenOn(true); | |
| 72 } | |
| 73 } else { | |
| 74 assert mKeepScreenOnCount > 0; | |
| 75 mKeepScreenOnCount--; | |
| 76 if (mKeepScreenOnCount == 0) { | |
| 77 mViewAndroidDelegate.releaseAnchorView(mKeepScreenOnView); | |
| 78 mKeepScreenOnView = null; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 58 private native int nativeInit(int windowPtr); | 83 private native int nativeInit(int windowPtr); |
| 59 private native void nativeDestroy(int nativeViewAndroid); | 84 private native void nativeDestroy(int nativeViewAndroid); |
| 60 } | 85 } |
| OLD | NEW |