| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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.blimp.session; | |
| 6 | |
| 7 import android.view.View; | |
| 8 | |
| 9 import org.chromium.base.annotations.JNINamespace; | |
| 10 | |
| 11 /** | |
| 12 * A Java representation of the native ControlFeature class. Provides easy acce
ss for Java control | |
| 13 * UI to interact with the native content-lite feature proxy and talk to the eng
ine. | |
| 14 */ | |
| 15 @JNINamespace("blimp::client") | |
| 16 public class TabControlFeature implements View.OnLayoutChangeListener { | |
| 17 private View mContentAreaView; | |
| 18 private long mNativeTabControlFeatureAndroidPtr; | |
| 19 | |
| 20 /** | |
| 21 * Creates an instance of a {@link TabControlFeature}. This will register w
ith | |
| 22 * {@code contentAreaView} as a {@link android.view.View.OnLayoutChangeListe
ner} and will | |
| 23 * unregister when {@link #destroy()} is called. | |
| 24 * @param blimpClientSession The {@link BlimpClientSession} that contains th
e content-lite | |
| 25 * features required by the native components of t
he | |
| 26 * {@link TabControlFeature}. | |
| 27 * @param contentAreaView A {@link View} that represents the content area
of the screen. | |
| 28 * This is used to notify the engine of the correc
t size of the web | |
| 29 * content area. | |
| 30 */ | |
| 31 public TabControlFeature(BlimpClientSession blimpClientSession, View content
AreaView) { | |
| 32 mContentAreaView = contentAreaView; | |
| 33 mContentAreaView.addOnLayoutChangeListener(this); | |
| 34 mNativeTabControlFeatureAndroidPtr = nativeInit(blimpClientSession); | |
| 35 } | |
| 36 | |
| 37 /** | |
| 38 * Tears down the native counterpart to this class and unregisters any {@lin
k View} listeners. | |
| 39 * This class should not be used after this. | |
| 40 */ | |
| 41 public void destroy() { | |
| 42 if (mContentAreaView != null) { | |
| 43 mContentAreaView.removeOnLayoutChangeListener(this); | |
| 44 mContentAreaView = null; | |
| 45 } | |
| 46 | |
| 47 if (mNativeTabControlFeatureAndroidPtr != 0) { | |
| 48 nativeDestroy(mNativeTabControlFeatureAndroidPtr); | |
| 49 mNativeTabControlFeatureAndroidPtr = 0; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 // View.OnLayoutChangeListener implementation. | |
| 54 @Override | |
| 55 public void onLayoutChange(View v, int left, int top, int right, int bottom, | |
| 56 int oldLeft, int oldTop, int oldRight, int oldBottom) { | |
| 57 if (mNativeTabControlFeatureAndroidPtr == 0) return; | |
| 58 nativeOnContentAreaSizeChanged(mNativeTabControlFeatureAndroidPtr, right
- left, | |
| 59 bottom - top, | |
| 60 mContentAreaView.getContext().getResources().getDisplayMetrics()
.density); | |
| 61 } | |
| 62 | |
| 63 private native long nativeInit(BlimpClientSession blimpClientSession); | |
| 64 private native void nativeDestroy(long nativeTabControlFeatureAndroid); | |
| 65 private native void nativeOnContentAreaSizeChanged( | |
| 66 long nativeTabControlFeatureAndroid, int width, int height, float dp
ToPx); | |
| 67 } | |
| OLD | NEW |