| 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 final float mDpToPx; | |
| 18 | |
| 19 private View mContentAreaView; | |
| 20 private long mNativeTabControlFeatureAndroidPtr; | |
| 21 | |
| 22 /** | |
| 23 * Creates an instance of a {@link TabControlFeature}. This will register w
ith | |
| 24 * {@code contentAreaView} as a {@link android.view.View.OnLayoutChangeListe
ner} and will | |
| 25 * unregister when {@link #destroy()} is called. | |
| 26 * @param blimpClientSession The {@link BlimpClientSession} that contains th
e content-lite | |
| 27 * features required by the native components of t
he | |
| 28 * {@link TabControlFeature}. | |
| 29 * @param contentAreaView A {@link View} that represents the content area
of the screen. | |
| 30 * This is used to notify the engine of the correc
t size of the web | |
| 31 * content area. | |
| 32 */ | |
| 33 public TabControlFeature(BlimpClientSession blimpClientSession, View content
AreaView) { | |
| 34 mContentAreaView = contentAreaView; | |
| 35 mContentAreaView.addOnLayoutChangeListener(this); | |
| 36 mDpToPx = mContentAreaView.getContext().getResources().getDisplayMetrics
().density; | |
| 37 mNativeTabControlFeatureAndroidPtr = nativeInit(blimpClientSession); | |
| 38 | |
| 39 // Push down the current size of the content area view. | |
| 40 nativeOnContentAreaSizeChanged(mNativeTabControlFeatureAndroidPtr, | |
| 41 mContentAreaView.getWidth(), mContentAreaView.getHeight(), mDpTo
Px); | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Tears down the native counterpart to this class and unregisters any {@lin
k View} listeners. | |
| 46 * This class should not be used after this. | |
| 47 */ | |
| 48 public void destroy() { | |
| 49 if (mContentAreaView != null) { | |
| 50 mContentAreaView.removeOnLayoutChangeListener(this); | |
| 51 mContentAreaView = null; | |
| 52 } | |
| 53 | |
| 54 if (mNativeTabControlFeatureAndroidPtr != 0) { | |
| 55 nativeDestroy(mNativeTabControlFeatureAndroidPtr); | |
| 56 mNativeTabControlFeatureAndroidPtr = 0; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 // View.OnLayoutChangeListener implementation. | |
| 61 @Override | |
| 62 public void onLayoutChange(View v, int left, int top, int right, int bottom, | |
| 63 int oldLeft, int oldTop, int oldRight, int oldBottom) { | |
| 64 if (mNativeTabControlFeatureAndroidPtr == 0) return; | |
| 65 nativeOnContentAreaSizeChanged(mNativeTabControlFeatureAndroidPtr, right
- left, | |
| 66 bottom - top, mDpToPx); | |
| 67 } | |
| 68 | |
| 69 private native long nativeInit(BlimpClientSession blimpClientSession); | |
| 70 private native void nativeDestroy(long nativeTabControlFeatureAndroid); | |
| 71 private native void nativeOnContentAreaSizeChanged( | |
| 72 long nativeTabControlFeatureAndroid, int width, int height, float dp
ToPx); | |
| 73 } | |
| OLD | NEW |