package com.vkcoffeelite.android.stickers;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.KeyCharacterMap;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnApplyWindowInsetsListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowInsets;
import android.view.inputmethod.InputMethodManager;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import com.vkcoffeelite.android.Global;
import com.vkcoffeelite.android.Manifest.permission;
import com.vkcoffeelite.android.ViewUtils;
import com.vkcoffeelite.android.api.VKAPIRequestCoffee;
import com.vkcoffeelite.android.photopicker.view.ImageViewerImageView;
import org.apache.http.HttpStatus;
public class KeyboardPopup {
public static final String ACTION_HIDE_POPUP = "com.vkcoffeelite.andoroid.HIDE_EMOJI_POPUP";
public static final int TABLET_HEIGHT;
public static final int TABLE_WIDTH;
private static IntentFilter sIntentFilter;
private static final boolean sUseFlymeHack;
private boolean keyboardVisible;
private final Activity mActivity;
private View mAnchor;
private final Rect mContentResizeRect;
private final View mContentView;
private int mDisplayHeight;
private int mDisplayWidth;
private final InputMethodManager mImm;
private int mKeyboardHeight;
private final Rect mKeyboardRect;
private OnVisibilityChangedListener mListener;
private int mPopupBgColor;
private PopupWindow mPopupWindow;
private final boolean mTablet;
private final View mView;
private final BroadcastReceiver receiver;
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.1 */
class C22751 extends BroadcastReceiver {
C22751() {
}
public void onReceive(Context context, Intent intent) {
if (KeyboardPopup.ACTION_HIDE_POPUP.equals(intent.getAction())) {
KeyboardPopup.this.hide();
}
}
}
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.2 */
static class C22762 extends IntentFilter {
C22762() {
addAction(KeyboardPopup.ACTION_HIDE_POPUP);
}
}
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.3 */
class C22773 implements OnDismissListener {
C22773() {
}
public void onDismiss() {
KeyboardPopup.this.unregisterReceiver();
}
}
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.4 */
class C22784 implements Runnable {
C22784() {
}
public void run() {
KeyboardPopup.this.mContentView.setPadding(0, 0, 0, 0);
}
}
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.5 */
class C22795 implements OnPreDrawListener {
final /* synthetic */ int[] val$aloc;
final /* synthetic */ PopupArrowDrawable val$bd;
final /* synthetic */ int[] val$eloc;
C22795(int[] iArr, PopupArrowDrawable popupArrowDrawable, int[] iArr2) {
this.val$eloc = iArr;
this.val$bd = popupArrowDrawable;
this.val$aloc = iArr2;
}
public boolean onPreDraw() {
KeyboardPopup.this.mView.getViewTreeObserver().removeOnPreDrawListener(this);
KeyboardPopup.this.mView.getLocationOnScreen(this.val$eloc);
this.val$bd.setArrowX((this.val$aloc[0] - this.val$eloc[0]) + (KeyboardPopup.this.mAnchor.getWidth() / 2));
return true;
}
}
/* renamed from: com.vkcoffeelite.android.stickers.KeyboardPopup.6 */
class C22806 implements OnApplyWindowInsetsListener {
C22806() {
}
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
return windowInsets.replaceSystemWindowInsets(0, 0, 0, windowInsets.getSystemWindowInsetBottom());
}
}
public interface OnVisibilityChangedListener {
void showDefaultIcon();
void showHideIcon();
void showKeyboardIcon();
}
private static class PopupArrowDrawable extends Drawable {
private static final int ARROW_SIZE;
private static final int PADDING;
private int arrowX;
private Bitmap bitmap;
private final Rect boundRect;
private Paint paint;
static {
PADDING = Global.scale(5.0f);
ARROW_SIZE = Global.scale(7.0f);
}
public PopupArrowDrawable(int color) {
this.bitmap = null;
this.arrowX = HttpStatus.SC_OK;
this.boundRect = new Rect();
this.paint = new Paint();
this.paint.setColor(color);
this.paint.setShadowLayer((float) Global.scale(4.0f), 0.0f, (float) Global.scale(ImageViewerImageView.DEFAULT_MIN_ZOOM), 1426063360);
this.paint.setAntiAlias(true);
}
public void draw(Canvas canvas) {
copyBounds(this.boundRect);
if (!(this.bitmap != null && this.boundRect.width() == this.bitmap.getWidth() && this.boundRect.height() == this.bitmap.getHeight())) {
this.bitmap = Bitmap.createBitmap(this.boundRect.width(), this.boundRect.height(), Config.ARGB_8888);
Canvas c = new Canvas(this.bitmap);
Rect r = new Rect(this.boundRect);
r.offsetTo(0, 0);
r.inset(PADDING, PADDING);
r.bottom -= ARROW_SIZE;
Path path = new Path();
path.addRect(new RectF(r), Direction.CW);
path.moveTo((float) (this.arrowX - ARROW_SIZE), (float) r.bottom);
path.lineTo((float) this.arrowX, (float) (r.bottom + ARROW_SIZE));
path.lineTo((float) (this.arrowX + ARROW_SIZE), (float) r.bottom);
path.close();
c.drawPath(path, this.paint);
}
canvas.drawBitmap(this.bitmap, new Rect(0, 0, this.boundRect.width(), PADDING), new Rect(this.boundRect.left, this.boundRect.top, this.boundRect.right, this.boundRect.top + PADDING), this.paint);
canvas.drawBitmap(this.bitmap, new Rect(0, (this.boundRect.height() - PADDING) - ARROW_SIZE, this.boundRect.width(), this.boundRect.height()), new Rect(this.boundRect.left, (this.boundRect.bottom - PADDING) - ARROW_SIZE, this.boundRect.right, this.boundRect.bottom), this.paint);
canvas.drawBitmap(this.bitmap, new Rect(0, PADDING, PADDING, (this.boundRect.bottom - PADDING) - ARROW_SIZE), new Rect(this.boundRect.left, this.boundRect.top + PADDING, this.boundRect.left + PADDING, (this.boundRect.bottom - PADDING) - ARROW_SIZE), this.paint);
canvas.drawBitmap(this.bitmap, new Rect(this.boundRect.width() - PADDING, PADDING, this.boundRect.width(), (this.boundRect.bottom - PADDING) - ARROW_SIZE), new Rect(this.boundRect.right - PADDING, this.boundRect.top + PADDING, this.boundRect.right, (this.boundRect.bottom - PADDING) - ARROW_SIZE), this.paint);
}
public void setArrowX(int x) {
this.arrowX = Global.scale(5.0f) + x;
this.bitmap = null;
}
public int getOpacity() {
return -3;
}
public void setAlpha(int alpha) {
}
public void setColorFilter(ColorFilter cf) {
}
public boolean getPadding(Rect out) {
out.set(PADDING, PADDING, PADDING, PADDING + ARROW_SIZE);
return true;
}
}
static {
boolean z;
TABLE_WIDTH = Global.scale(350.0f);
TABLET_HEIGHT = Global.scale(260.0f);
if (Build.DISPLAY.contains("Flyme OS") && Build.DISPLAY.contains("4")) {
z = true;
} else {
z = false;
}
sUseFlymeHack = z;
sIntentFilter = new C22762();
}
public KeyboardPopup(@NonNull Activity activity, @NonNull View contentView, @NonNull View view) {
this.receiver = new C22751();
this.mContentResizeRect = new Rect();
this.mKeyboardRect = new Rect();
this.mActivity = activity;
this.mView = view;
this.mContentView = contentView;
this.mImm = (InputMethodManager) this.mActivity.getSystemService("input_method");
this.mTablet = (this.mActivity.getResources().getConfiguration().screenLayout & 15) >= 3;
}
public void attachToAnchor(@Nullable View anchor, int popupBgColor) {
this.mAnchor = anchor;
this.mPopupBgColor = popupBgColor;
}
public void toggle() {
show(!isShowing());
}
public void show(boolean show) {
if (show != isShowing()) {
if (this.mPopupWindow == null) {
this.mPopupWindow = new PopupWindow(this.mView);
this.mPopupWindow.setOnDismissListener(new C22773());
}
if (show) {
unregisterReceiver();
this.mActivity.registerReceiver(this.receiver, sIntentFilter, permission.ACCESS_DATA, null);
}
if (this.mTablet) {
if (show) {
this.mPopupWindow.setWidth(TABLE_WIDTH);
this.mPopupWindow.setHeight(TABLET_HEIGHT);
PopupArrowDrawable bd = new PopupArrowDrawable(this.mPopupBgColor);
this.mPopupWindow.setBackgroundDrawable(bd);
this.mPopupWindow.setOutsideTouchable(true);
this.mPopupWindow.showAsDropDown(this.mAnchor, -((this.mPopupWindow.getWidth() / 2) - (this.mAnchor.getWidth() / 2)), 0);
int[] eloc = new int[]{0, 0};
int[] aloc = new int[]{0, 0};
this.mAnchor.getLocationOnScreen(aloc);
this.mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(this.mKeyboardRect);
if (this.mPopupWindow.getHeight() > this.mKeyboardRect.height()) {
View focus = this.mActivity.getCurrentFocus();
if (focus != null) {
this.mImm.hideSoftInputFromWindow(focus.getWindowToken(), 0);
}
}
this.mView.getViewTreeObserver().addOnPreDrawListener(new C22795(eloc, bd, aloc));
return;
}
this.mPopupWindow.dismiss();
} else if (show) {
if (this.mKeyboardHeight <= Global.scale(100.0f)) {
this.mKeyboardHeight = this.mActivity.getSharedPreferences("emoji", 0).getInt("kbd_height" + this.mDisplayWidth + '_' + this.mDisplayHeight, Global.scale(200.0f));
}
if (this.mKeyboardHeight < Global.scale(200.0f)) {
this.mKeyboardHeight = Global.scale(200.0f);
}
if (!this.keyboardVisible && this.mKeyboardHeight > (this.mContentView.getHeight() / 3) * 2) {
this.mKeyboardHeight = (this.mContentView.getHeight() / 3) * 2;
}
int keyboardHeight = (!sUseFlymeHack || this.mContentView.getHeight() <= this.mContentView.getWidth()) ? this.mKeyboardHeight : this.mKeyboardHeight - ViewUtils.getNavigationBarHeight(this.mActivity);
this.mPopupWindow.setHeight(MeasureSpec.makeMeasureSpec(keyboardHeight, VKAPIRequestCoffee.ERROR_FLAG_LOCALIZED));
this.mPopupWindow.setWidth(MeasureSpec.makeMeasureSpec(this.mDisplayWidth, VKAPIRequestCoffee.ERROR_FLAG_LOCALIZED));
int bottom = 0;
if ((VERSION.SDK_INT >= 20 || sUseFlymeHack) && this.mContentView.getHeight() > this.mContentView.getWidth() && (!KeyCharacterMap.deviceHasKey(3) || sUseFlymeHack)) {
bottom = ViewUtils.getNavigationBarHeight(this.mActivity);
}
this.mPopupWindow.showAtLocation(this.mActivity.getWindow().getDecorView(), 83, 0, bottom);
if (!this.keyboardVisible) {
this.mContentView.setPadding(0, 0, 0, keyboardHeight);
if (this.mListener != null) {
this.mListener.showHideIcon();
}
} else if (this.mListener != null) {
this.mListener.showKeyboardIcon();
}
} else {
if (this.mListener != null) {
this.mListener.showDefaultIcon();
}
this.mPopupWindow.dismiss();
this.mContentView.post(new C22784());
}
}
}
private void unregisterReceiver() {
try {
this.mActivity.unregisterReceiver(this.receiver);
} catch (Exception e) {
e.printStackTrace();
}
}
public void notifyLayoutHasChanged() {
DisplayMetrics displayMetrics = this.mActivity.getResources().getDisplayMetrics();
this.mDisplayWidth = displayMetrics.widthPixels;
this.mDisplayHeight = displayMetrics.heightPixels;
this.mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(this.mContentResizeRect);
int scrH = this.mActivity.getWindow().getDecorView().getHeight();
if (VERSION.SDK_INT >= 20 && !KeyCharacterMap.deviceHasKey(3)) {
scrH -= ViewUtils.getNavigationBarHeight(this.mActivity);
}
if (!this.mTablet) {
this.mKeyboardHeight = scrH - this.mContentResizeRect.bottom;
this.keyboardVisible = this.mKeyboardHeight > Global.scale(100.0f);
if (this.mKeyboardHeight > Global.scale(100.0f)) {
this.mActivity.getSharedPreferences("emoji", 0).edit().putInt("kbd_height" + this.mDisplayWidth + '_' + this.mDisplayHeight, this.mKeyboardHeight).commit();
}
if (this.keyboardVisible && this.mContentView.getPaddingBottom() == 0 && this.mPopupWindow != null && this.mPopupWindow.isShowing()) {
this.mPopupWindow.setHeight(this.mKeyboardHeight);
this.mPopupWindow.dismiss();
this.mPopupWindow.showAtLocation(this.mActivity.getWindow().getDecorView(), 83, 0, 0);
}
if (this.keyboardVisible && this.mContentView.getPaddingBottom() > 0) {
show(false);
}
if (!(this.keyboardVisible || this.mPopupWindow == null || !this.mPopupWindow.isShowing())) {
show(false);
}
if (this.mDisplayWidth > this.mDisplayHeight) {
if (this.keyboardVisible) {
if (VERSION.SDK_INT >= 21) {
}
if (VERSION.SDK_INT >= 21) {
}
if (VERSION.SDK_INT < 21) {
}
} else if (VERSION.SDK_INT < 21) {
}
} else if (VERSION.SDK_INT < 21) {
}
}
}
public boolean isShowing() {
return this.mPopupWindow != null && this.mPopupWindow.isShowing();
}
public void hide() {
if (this.mPopupWindow != null && this.mPopupWindow.isShowing()) {
try {
show(false);
} catch (Exception e) {
unregisterReceiver();
}
}
}
public OnVisibilityChangedListener getOnVisibilityChangedListener() {
return this.mListener;
}
public void setOnVisibilityChangedListener(OnVisibilityChangedListener mListener) {
this.mListener = mListener;
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.