| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.ui.base; | |
| 6 | |
| 7 import android.view.View; | |
| 8 | |
| 9 /** | |
| 10 * From the Chromium architecture point of view, ViewAndroid and its native coun
terpart | |
| 11 * serve purpose of representing Android view where Chrome expects to have a cro
ss platform | |
| 12 * handle to the system view type. As Views are Java object on Android, this Vie
wAndroid | |
| 13 * and its native counterpart provide the expected abstractions on the C++ side
and allow | |
| 14 * it to be flexibly glued to an actual Android Java View at runtime. | |
| 15 * | |
| 16 * It should only be used where access to Android Views is needed from the C++ c
ode. | |
| 17 */ | |
| 18 public class ViewAndroid { | |
| 19 // Native pointer to the c++ ViewAndroid object. | |
| 20 private final ViewAndroidDelegate mViewAndroidDelegate; | |
| 21 private int mKeepScreenOnCount; | |
| 22 private View mKeepScreenOnView; | |
| 23 | |
| 24 /** | |
| 25 * Constructs a View object. | |
| 26 */ | |
| 27 public ViewAndroid(ViewAndroidDelegate viewAndroidDelegate) { | |
| 28 mViewAndroidDelegate = viewAndroidDelegate; | |
| 29 } | |
| 30 | |
| 31 public ViewAndroidDelegate getViewAndroidDelegate() { | |
| 32 return mViewAndroidDelegate; | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * Set KeepScreenOn flag. If the flag already set, increase mKeepScreenOnCou
nt. | |
| 37 */ | |
| 38 public void incrementKeepScreenOnCount() { | |
| 39 mKeepScreenOnCount++; | |
| 40 if (mKeepScreenOnCount == 1) { | |
| 41 mKeepScreenOnView = mViewAndroidDelegate.acquireAnchorView(); | |
| 42 mViewAndroidDelegate.setAnchorViewPosition(mKeepScreenOnView, 0, 0,
0, 0); | |
| 43 mKeepScreenOnView.setKeepScreenOn(true); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * Decrease mKeepScreenOnCount, if it is decreased to 0, remove the flag. | |
| 49 */ | |
| 50 public void decrementKeepScreenOnCount() { | |
| 51 assert mKeepScreenOnCount > 0; | |
| 52 mKeepScreenOnCount--; | |
| 53 if (mKeepScreenOnCount == 0) { | |
| 54 mViewAndroidDelegate.releaseAnchorView(mKeepScreenOnView); | |
| 55 mKeepScreenOnView = null; | |
| 56 } | |
| 57 } | |
| 58 } | |
| OLD | NEW |