package dev.oneuiproject.oneui.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.appcompat.animation.SeslAnimationUtils;
import androidx.reflect.content.res.SeslConfigurationReflector;
import androidx.reflect.widget.SeslTextViewReflector;

import dev.oneuiproject.oneui.design.R;

public class TipPopup {
    private static final int ANIMATION_DURATION_BOUNCE_SCALE1 = 167;
    private static final int ANIMATION_DURATION_BOUNCE_SCALE2 = 250;
    private static final int ANIMATION_DURATION_DISMISS_ALPHA = 166;
    private static final int ANIMATION_DURATION_DISMISS_SCALE = 166;
    private static final int ANIMATION_DURATION_EXPAND_ALPHA = 83;
    private static final int ANIMATION_DURATION_EXPAND_SCALE = 500;
    private static final int ANIMATION_DURATION_EXPAND_TEXT = 167;
    private static final int ANIMATION_DURATION_SHOW_SCALE = 500;
    private static final int ANIMATION_OFFSET_BOUNCE_SCALE = 3000;
    private static final int ANIMATION_OFFSET_EXPAND_TEXT = 100;
    public static final int DIRECTION_BOTTOM_LEFT = 2;
    public static final int DIRECTION_BOTTOM_RIGHT = 3;
    public static final int DIRECTION_DEFAULT = -1;
    public static final int DIRECTION_TOP_LEFT = 0;
    public static final int DIRECTION_TOP_RIGHT = 1;
    public static final int MODE_NORMAL = 0;
    public static final int MODE_TRANSLUCENT = 1;
    private static final int MSG_DISMISS = 1;
    private static final int MSG_SCALE_UP = 2;
    private static final int MSG_TIMEOUT = 0;
    public static final int STATE_DISMISSED = 0;
    public static final int STATE_EXPANDED = 2;
    public static final int STATE_HINT = 1;
    private static final String TAG = "TipPopup";
    private static final int TIMEOUT_DURATION_MS = 7100;
    private static final int TYPE_BALLOON_ACTION = 1;
    private static final int TYPE_BALLOON_CUSTOM = 2;
    private static final int TYPE_BALLOON_SIMPLE = 0;
    private static final boolean localLOGD = true;
    private static Handler mHandler;
    private View.OnClickListener mActionClickListener;
    private CharSequence mActionText;
    private Integer mActionTextColor;
    private final Button mActionView;
    private int mArrowDirection;
    private final int mArrowHeight;
    private int mArrowPositionX;
    private int mArrowPositionY;
    private final int mArrowWidth;
    private int mBackgroundColor;
    private ImageView mBalloonBg1;
    private ImageView mBalloonBg2;
    private FrameLayout mBalloonBubble;
    private ImageView mBalloonBubbleHint;
    private ImageView mBalloonBubbleIcon;
    private FrameLayout mBalloonContent;
    private int mBalloonHeight;
    private FrameLayout mBalloonPanel;
    private TipWindow mBalloonPopup;
    private int mBalloonPopupX;
    private int mBalloonPopupY;
    private final View mBalloonView;
    private int mBalloonWidth;
    private int mBalloonX;
    private int mBalloonY;
    private Integer mBorderColor;
    private ImageView mBubbleBackground;
    private int mBubbleHeight;
    private ImageView mBubbleIcon;
    private TipWindow mBubblePopup;
    private int mBubblePopupX;
    private int mBubblePopupY;
    private final View mBubbleView;
    private int mBubbleWidth;
    private int mBubbleX;
    private int mBubbleY;
    private final Context mContext;
    private final Rect mDisplayFrame;
    private DisplayMetrics mDisplayMetrics;
    private boolean mForceRealDisplay;
    private CharSequence mHintDescription;
    private final int mHorizontalTextMargin;
    private int mInitialmMessageViewWidth;
    private boolean mIsDefaultPosition;
    private boolean mIsMessageViewMeasured;
    private CharSequence mMessageText;
    private Integer mMessageTextColor;
    private final TextView mMessageView;
    private final int mMode;
    private boolean mNeedToCallParentViewsOnClick;
    private OnDismissListener mOnDismissListener;
    private OnStateChangeListener mOnStateChangeListener;
    private final View mParentView;
    private final Resources mResources;
    private int mScaleMargin;
    private int mSideMargin;
    private int mState;
    private int mType;
    private final int mVerticalTextMargin;
    private final WindowManager mWindowManager;
    private static Interpolator INTERPOLATOR_SINE_IN_OUT_33 = null;
    private static Interpolator INTERPOLATOR_SINE_IN_OUT_70 = null;
    private static Interpolator INTERPOLATOR_ELASTIC_50 = null;
    private static Interpolator INTERPOLATOR_ELASTIC_CUSTOM = null;

    public interface OnDismissListener {
        void onDismiss();
    }

    public interface OnStateChangeListener {
        void onStateChanged(int i);
    }

    public void setOnStateChangeListener(OnStateChangeListener changeListener) {
        this.mOnStateChangeListener = changeListener;
    }

    public TipPopup(View parentView) {
        this(parentView, MODE_NORMAL);
    }

    public TipPopup(View parentView, int mode) {
        this.mIsDefaultPosition = true;
        this.mMessageText = null;
        this.mActionText = null;
        this.mHintDescription = null;
        this.mActionClickListener = null;
        this.mMessageTextColor = null;
        this.mActionTextColor = null;
        this.mBorderColor = null;
        this.mInitialmMessageViewWidth = 0;
        this.mIsMessageViewMeasured = false;
        this.mForceRealDisplay = false;
        this.mNeedToCallParentViewsOnClick = false;
        if (mode < MODE_NORMAL || mode > MODE_TRANSLUCENT) {
            throw new IllegalArgumentException("Invalid SmartTip mode : " + mode + " ,mode can either be 0 (MODE_NORMAL) or 1 (MODE_TRANSLUCENT)");
        }
        Context context = parentView.getContext();
        this.mContext = context;
        Resources resources = context.getResources();
        this.mResources = resources;
        this.mParentView = parentView;
        this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        this.mDisplayMetrics = resources.getDisplayMetrics();
        debugLog("mDisplayMetrics = " + this.mDisplayMetrics);
        this.mState = STATE_HINT;
        this.mType = TYPE_BALLOON_SIMPLE;
        this.mMode = mode;
        this.mBackgroundColor = context.getColor(R.color.sem_tip_popup_background_color);
        initInterpolator();
        LayoutInflater inflater = LayoutInflater.from(context);
        this.mBubbleView = inflater.inflate(R.layout.sem_tip_popup_bubble, (ViewGroup) null);
        View inflate = inflater.inflate(R.layout.sem_tip_popup_balloon, (ViewGroup) null);
        this.mBalloonView = inflate;
        initBubblePopup(mode);
        initBalloonPopup(mode);
        TextView textView = (TextView) inflate.findViewById(R.id.sem_tip_popup_message);
        this.mMessageView = textView;
        Button button = (Button) inflate.findViewById(R.id.sem_tip_popup_action);
        this.mActionView = button;
        textView.setVisibility(View.GONE);
        button.setVisibility(View.GONE);
        this.mArrowPositionX = -1;
        this.mArrowPositionY = -1;
        this.mArrowDirection = DIRECTION_DEFAULT;
        this.mBalloonX = -1;
        if (mode == MODE_TRANSLUCENT) {
            textView.setTextColor(resources.getColor(R.color.sem_tip_popup_text_color_translucent, null));
            button.setTextColor(resources.getColor(R.color.sem_tip_popup_text_color_translucent, null));
        }
        this.mScaleMargin = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_scale_margin);
        this.mSideMargin = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_side_margin);
        this.mArrowHeight = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_balloon_arrow_height);
        this.mArrowWidth = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_balloon_arrow_width);
        this.mHorizontalTextMargin = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_balloon_message_margin_horizontal);
        this.mVerticalTextMargin = resources.getDimensionPixelSize(R.dimen.sem_tip_popup_balloon_message_margin_vertical);
        this.mDisplayFrame = new Rect();
        this.mBubblePopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (TipPopup.this.mState == STATE_HINT) {
                    TipPopup.this.mState = STATE_DISMISSED;
                    if (TipPopup.this.mOnStateChangeListener != null) {
                        TipPopup.this.mOnStateChangeListener.onStateChanged(TipPopup.this.mState);
                        TipPopup.this.debugLog("mIsShowing : " + TipPopup.this.isShowing());
                    }
                    if (TipPopup.mHandler != null) {
                        TipPopup.mHandler.removeCallbacksAndMessages(null);
                        TipPopup.mHandler = null;
                    }
                    TipPopup.this.debugLog("onDismiss - BubblePopup");
                }
            }
        });
        this.mBalloonPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                TipPopup.this.mState = STATE_DISMISSED;
                if (TipPopup.this.mOnStateChangeListener != null) {
                    TipPopup.this.mOnStateChangeListener.onStateChanged(TipPopup.this.mState);
                    TipPopup.this.debugLog("mIsShowing : " + TipPopup.this.isShowing());
                }
                TipPopup.this.debugLog("onDismiss - BalloonPopup");
                TipPopup.this.dismissBubble(false);
                if (TipPopup.mHandler != null) {
                    TipPopup.mHandler.removeCallbacksAndMessages(null);
                    TipPopup.mHandler = null;
                }
            }
        });
        inflate.setAccessibilityDelegate(new View.AccessibilityDelegate() {
            @Override
            public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(host, info);
                info.addAction(new AccessibilityNodeInfo.AccessibilityAction(16, TipPopup.this.mContext.getString(R.string.oui_common_close)));
            }
        });
    }

    @SuppressLint("RestrictedApi")
    private void initInterpolator() {
        if (INTERPOLATOR_SINE_IN_OUT_33 == null) {
            INTERPOLATOR_SINE_IN_OUT_33 = AnimationUtils.loadInterpolator(this.mContext, R.interpolator.sine_in_out_33);
        }
        if (INTERPOLATOR_SINE_IN_OUT_70 == null) {
            INTERPOLATOR_SINE_IN_OUT_70 = AnimationUtils.loadInterpolator(this.mContext, R.interpolator.sine_in_out_70);
        }
        if (INTERPOLATOR_ELASTIC_50 == null) {
            INTERPOLATOR_ELASTIC_50 = SeslAnimationUtils.ELASTIC_50;
        }
        if (INTERPOLATOR_ELASTIC_CUSTOM == null) {
            INTERPOLATOR_ELASTIC_CUSTOM = SeslAnimationUtils.ELASTIC_40; //TODO: new SeslElasticInterpolator(1.0f, 1.3f);
        }
    }

    private void initBubblePopup(int mode) {
        this.mBubbleBackground = (ImageView) this.mBubbleView.findViewById(R.id.sem_tip_popup_bubble_bg);
        this.mBubbleIcon = (ImageView) this.mBubbleView.findViewById(R.id.sem_tip_popup_bubble_icon);
        if (mode == MODE_TRANSLUCENT) {
            this.mBubbleBackground.setImageResource(R.drawable.sem_tip_popup_hint_background_translucent);
            this.mBubbleBackground.setImageTintList(null);
            if (isRTL()) {
                this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_translucent_rtl);
            } else {
                this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_translucent);
            }
            this.mBubbleIcon.setImageTintList(null);
            this.mBubbleWidth = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_width_translucent);
            this.mBubbleHeight = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_height_translucent);
        } else {
            this.mBubbleWidth = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_width);
            this.mBubbleHeight = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_height);
        }
        TipWindow tipWindow = new TipWindow(this.mBubbleView, this.mBubbleWidth, this.mBubbleHeight, false);
        this.mBubblePopup = tipWindow;
        tipWindow.setTouchable(true);
        this.mBubblePopup.setOutsideTouchable(true);
        this.mBubblePopup.setAttachedInDecor(false);
    }

    private void initBalloonPopup(int mode) {
        this.mBalloonBubble = (FrameLayout) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_bubble);
        this.mBalloonBubbleHint = (ImageView) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_bubble_hint);
        this.mBalloonBubbleIcon = (ImageView) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_bubble_icon);
        this.mBalloonPanel = (FrameLayout) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_panel);
        this.mBalloonContent = (FrameLayout) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_content);
        this.mBalloonBg1 = (ImageView) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_bg_01);
        this.mBalloonBg2 = (ImageView) this.mBalloonView.findViewById(R.id.sem_tip_popup_balloon_bg_02);
        if (mode == MODE_TRANSLUCENT) {
            this.mBalloonBg1.setBackgroundResource(R.drawable.sem_tip_popup_balloon_background_left_translucent);
            this.mBalloonBg1.setBackgroundTintList(null);
            this.mBalloonBg2.setBackgroundResource(R.drawable.sem_tip_popup_balloon_background_right_translucent);
            this.mBalloonBg2.setBackgroundTintList(null);
        }
        this.mBalloonBubble.setVisibility(View.VISIBLE);
        this.mBalloonPanel.setVisibility(View.GONE);
        TipWindow tipWindow = new TipWindow(this.mBalloonView, this.mBalloonWidth, this.mBalloonHeight, true);
        this.mBalloonPopup = tipWindow;
        tipWindow.setFocusable(true);
        this.mBalloonPopup.setTouchable(true);
        this.mBalloonPopup.setOutsideTouchable(true);
        this.mBalloonPopup.setAttachedInDecor(false);
        this.mBalloonPopup.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (TipPopup.this.mNeedToCallParentViewsOnClick && TipPopup.this.mParentView.hasOnClickListeners() && (event.getAction() == 0 || event.getAction() == 4)) {
                    Rect parentViewBounds = new Rect();
                    int[] outLocation = new int[2];
                    TipPopup.this.mParentView.getLocationOnScreen(outLocation);
                    parentViewBounds.set(outLocation[0], outLocation[1], outLocation[0] + TipPopup.this.mParentView.getWidth(), outLocation[1] + TipPopup.this.mParentView.getHeight());
                    boolean isTouchContainedInParentView = parentViewBounds.contains((int) event.getRawX(), (int) event.getRawY());
                    if (isTouchContainedInParentView) {
                        TipPopup.this.debugLog("callOnClick for parent view");
                        TipPopup.this.mParentView.callOnClick();
                    }
                }
                return false;
            }
        });
    }

    public void show(int direction) {
        setInternal();
        if (this.mArrowPositionX == -1 || this.mArrowPositionY == -1) {
            calculateArrowPosition();
        }
        if (direction == -1) {
            calculateArrowDirection(this.mArrowPositionX, this.mArrowPositionY);
        } else {
            this.mArrowDirection = direction;
        }
        calculatePopupSize();
        calculatePopupPosition();
        setBubblePanel();
        setBalloonPanel();
        showInternal();
    }

    public void setMessage(CharSequence message) {
        this.mMessageText = message;
    }

    public void setAction(CharSequence actionText, View.OnClickListener listener) {
        this.mActionText = actionText;
        this.mActionClickListener = listener;
    }

    public void semCallParentViewsOnClick(boolean needToCall) {
        this.mNeedToCallParentViewsOnClick = needToCall;
    }

    public boolean isShowing() {
        boolean isBubbleShowing = false;
        boolean isBalloonShowing = false;
        TipWindow tipWindow = this.mBubblePopup;
        if (tipWindow != null) {
            isBubbleShowing = tipWindow.isShowing();
        }
        TipWindow tipWindow2 = this.mBalloonPopup;
        if (tipWindow2 != null) {
            isBalloonShowing = tipWindow2.isShowing();
        }
        return isBubbleShowing || isBalloonShowing;
    }

    public void dismiss(boolean withAnimation) {
        TipWindow tipWindow = this.mBubblePopup;
        if (tipWindow != null) {
            tipWindow.setUseDismissAnimation(withAnimation);
            debugLog("mBubblePopup.mIsDismissing = " + this.mBubblePopup.mIsDismissing);
            this.mBubblePopup.dismiss();
        }
        TipWindow tipWindow2 = this.mBalloonPopup;
        if (tipWindow2 != null) {
            tipWindow2.setUseDismissAnimation(withAnimation);
            debugLog("mBalloonPopup.mIsDismissing = " + this.mBalloonPopup.mIsDismissing);
            this.mBalloonPopup.dismiss();
        }
        OnDismissListener onDismissListener = this.mOnDismissListener;
        if (onDismissListener != null) {
            onDismissListener.onDismiss();
        }
        Handler handler = mHandler;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
    }

    public void setExpanded(boolean expanded) {
        if (expanded) {
            this.mState = STATE_EXPANDED;
            this.mScaleMargin = 0;
            return;
        }
        this.mScaleMargin = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_scale_margin);
    }

    public void setTargetPosition(int x, int y) {
        if (x < 0 || y < 0) {
            return;
        }
        this.mIsDefaultPosition = false;
        this.mArrowPositionX = x;
        this.mArrowPositionY = y;
    }

    public void setHintDescription(CharSequence hintDescription) {
        this.mHintDescription = hintDescription;
    }

    public void update() {
        update(this.mArrowDirection, false);
    }

    public void update(int direction, boolean resetHintTimer) {
        TipWindow tipWindow;
        TipWindow tipWindow2;
        if (!isShowing() || this.mParentView == null) {
            return;
        }
        setInternal();
        this.mBalloonX = -1;
        this.mBalloonY = -1;
        if (this.mIsDefaultPosition) {
            debugLog("update - default position");
            calculateArrowPosition();
        }
        if (direction == DIRECTION_DEFAULT) {
            calculateArrowDirection(this.mArrowPositionX, this.mArrowPositionY);
        } else {
            this.mArrowDirection = direction;
        }
        calculatePopupSize();
        calculatePopupPosition();
        setBubblePanel();
        setBalloonPanel();
        int i = this.mState;
        if (i == STATE_HINT && (tipWindow2 = this.mBubblePopup) != null) {
            tipWindow2.update(this.mBubblePopupX, this.mBubblePopupY, tipWindow2.getWidth(), this.mBubblePopup.getHeight());
            if (resetHintTimer) {
                debugLog("Timer Reset!");
                scheduleTimeout();
            }
        } else if (i == STATE_EXPANDED && (tipWindow = this.mBalloonPopup) != null) {
            tipWindow.update(this.mBalloonPopupX, this.mBalloonPopupY, tipWindow.getWidth(), this.mBalloonPopup.getHeight());
        }
    }

    public void setMessageTextColor(int color) {
        this.mMessageTextColor = Integer.valueOf((-16777216) | color);
    }

    public void setActionTextColor(int color) {
        this.mActionTextColor = Integer.valueOf((-16777216) | color);
    }

    public void setBackgroundColor(int color) {
        this.mBackgroundColor = (-16777216) | color;
    }

    public void setBackgroundColorWithAlpha(int color) {
        this.mBackgroundColor = color;
    }

    public void setBorderColor(int color) {
        this.mBorderColor = Integer.valueOf((-16777216) | color);
    }

    public void setOutsideTouchEnabled(boolean enabled) {
        this.mBubblePopup.setFocusable(enabled);
        this.mBubblePopup.setOutsideTouchable(enabled);
        this.mBalloonPopup.setFocusable(enabled);
        this.mBalloonPopup.setOutsideTouchable(enabled);
        debugLog("outside enabled : " + enabled);
    }

    public void setPopupWindowClippingEnabled(boolean enabled) {
        this.mBubblePopup.setClippingEnabled(enabled);
        this.mBalloonPopup.setClippingEnabled(enabled);
        this.mForceRealDisplay = !enabled;
        this.mSideMargin = enabled ? this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_side_margin) : 0;
        debugLog("clipping enabled : " + enabled);
    }

    private void setInternal() {
        CharSequence charSequence;
        if (mHandler == null) {
            mHandler = new Handler(Looper.getMainLooper()) {
                @Override
                public void handleMessage(Message message) {
                    switch (message.what) {
                        case MSG_TIMEOUT:
                            TipPopup.this.dismissBubble(true);
                            return;
                        case MSG_DISMISS:
                            TipPopup.this.dismissBubble(false);
                            return;
                        case MSG_SCALE_UP:
                            TipPopup.this.animateScaleUp();
                            return;
                        default:
                            return;
                    }
                }
            };
        }
        if (this.mMessageView == null || this.mActionView == null) {
            return;
        }
        float currentFontScale = this.mResources.getConfiguration().fontScale;
        int messageTextSize = this.mResources.getDimensionPixelOffset(R.dimen.sem_tip_popup_balloon_message_text_size);
        int actionTextSize = this.mResources.getDimensionPixelOffset(R.dimen.sem_tip_popup_balloon_action_text_size);
        if (currentFontScale > 1.2f) {
            this.mMessageView.setTextSize(0, (float) Math.floor(Math.ceil(messageTextSize / currentFontScale) * 1.2f));
            this.mActionView.setTextSize(0, (float) Math.floor(Math.ceil(actionTextSize / currentFontScale) * 1.2f));
        }
        this.mMessageView.setText(this.mMessageText);
        if (TextUtils.isEmpty(this.mActionText) || this.mActionClickListener == null) {
            this.mActionView.setVisibility(View.GONE);
            this.mActionView.setOnClickListener(null);
            this.mType = TYPE_BALLOON_SIMPLE;
        } else {
            this.mActionView.setVisibility(View.VISIBLE);
            SeslTextViewReflector.semSetButtonShapeEnabled(mActionView, true, mBackgroundColor);
            this.mActionView.setText(this.mActionText);
            this.mActionView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (TipPopup.this.mActionClickListener != null) {
                        TipPopup.this.mActionClickListener.onClick(view);
                    }
                    TipPopup.this.dismiss(true);
                }
            });
            this.mType = TYPE_BALLOON_ACTION;
        }
        ImageView imageView = this.mBubbleIcon;
        if (imageView != null && (charSequence = this.mHintDescription) != null) {
            imageView.setContentDescription(charSequence);
        }
        if (this.mMode == MODE_TRANSLUCENT || this.mBubbleIcon == null || this.mBubbleBackground == null || this.mBalloonBubble == null || this.mBalloonBg1 == null || this.mBalloonBg2 == null) {
            return;
        }
        Integer num = this.mMessageTextColor;
        if (num != null) {
            this.mMessageView.setTextColor(num.intValue());
        }
        Integer num2 = this.mActionTextColor;
        if (num2 != null) {
            this.mActionView.setTextColor(num2.intValue());
        }
        this.mBubbleBackground.setColorFilter(this.mBackgroundColor);
        this.mBalloonBubbleHint.setColorFilter(this.mBackgroundColor);
        this.mBalloonBg1.setBackgroundTintList(ColorStateList.valueOf(this.mBackgroundColor));
        this.mBalloonBg2.setBackgroundTintList(ColorStateList.valueOf(this.mBackgroundColor));
        Integer num3 = this.mBorderColor;
        if (num3 != null) {
            this.mBubbleIcon.setColorFilter(num3.intValue());
            this.mBalloonBubbleIcon.setColorFilter(this.mBorderColor.intValue());
        }
    }

    private void showInternal() {
        if (this.mState != STATE_EXPANDED) {
            this.mState = STATE_HINT;
            OnStateChangeListener onStateChangeListener = this.mOnStateChangeListener;
            if (onStateChangeListener != null) {
                onStateChangeListener.onStateChanged(STATE_HINT);
                debugLog("mIsShowing : " + isShowing());
            }
            TipWindow tipWindow = this.mBubblePopup;
            if (tipWindow != null) {
                tipWindow.showAtLocation(this.mParentView, 0, this.mBubblePopupX, this.mBubblePopupY);
                animateViewIn();
            }
            this.mBubbleView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    TipPopup.this.mState = STATE_EXPANDED;
                    if (TipPopup.this.mOnStateChangeListener != null) {
                        TipPopup.this.mOnStateChangeListener.onStateChanged(TipPopup.this.mState);
                    }
                    if (TipPopup.this.mBalloonPopup != null) {
                        TipPopup.this.mBalloonPopup.showAtLocation(TipPopup.this.mParentView, 0, TipPopup.this.mBalloonPopupX, TipPopup.this.mBalloonPopupY);
                    }
                    if (TipPopup.mHandler != null) {
                        TipPopup.mHandler.removeMessages(0);
                        TipPopup.mHandler.sendMessageDelayed(Message.obtain(TipPopup.mHandler, MSG_DISMISS), 10L);
                        TipPopup.mHandler.sendMessageDelayed(Message.obtain(TipPopup.mHandler, MSG_SCALE_UP), 20L);
                    }
                    return false;
                }
            });
        } else {
            this.mBalloonBubble.setVisibility(View.GONE);
            this.mBalloonPanel.setVisibility(View.VISIBLE);
            this.mMessageView.setVisibility(View.VISIBLE);
            OnStateChangeListener onStateChangeListener2 = this.mOnStateChangeListener;
            if (onStateChangeListener2 != null) {
                onStateChangeListener2.onStateChanged(this.mState);
            }
            TipWindow tipWindow2 = this.mBalloonPopup;
            if (tipWindow2 != null) {
                tipWindow2.showAtLocation(this.mParentView, 0, this.mBalloonPopupX, this.mBalloonPopupY);
            }
        }
        this.mBalloonView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (TipPopup.this.mType == TYPE_BALLOON_SIMPLE) {
                    TipPopup.this.dismiss(true);
                    return false;
                }
                return false;
            }
        });
    }

    private void setBubblePanel() {
        if (this.mBubblePopup == null) {
            return;
        }
        FrameLayout.LayoutParams paramBubblePanel = (FrameLayout.LayoutParams) this.mBubbleBackground.getLayoutParams();
        if (this.mMode == MODE_TRANSLUCENT) {
            paramBubblePanel.width = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_width_translucent);
            paramBubblePanel.height = this.mResources.getDimensionPixelSize(R.dimen.sem_tip_popup_bubble_height_translucent);
        }
        switch (this.mArrowDirection) {
            case DIRECTION_TOP_LEFT:
                TipWindow tipWindow = this.mBubblePopup;
                tipWindow.setPivot(tipWindow.getWidth(), this.mBubblePopup.getHeight());
                paramBubblePanel.gravity = 85;
                int i = this.mBubbleX;
                int i2 = this.mScaleMargin;
                this.mBubblePopupX = i - (i2 * 2);
                this.mBubblePopupY = this.mBubbleY - (i2 * 2);
                if (this.mMode == MODE_NORMAL) {
                    this.mBubbleBackground.setImageResource(R.drawable.sem_tip_popup_hint_background_03);
                    if (isRTL()) {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_rtl);
                    } else {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon);
                    }
                } else {
                    this.mBubbleBackground.setRotationX(180.0f);
                }
                break;
            case DIRECTION_TOP_RIGHT:
                TipWindow tipWindow2 = this.mBubblePopup;
                tipWindow2.setPivot(0.0f, tipWindow2.getHeight());
                paramBubblePanel.gravity = 83;
                this.mBubblePopupX = this.mBubbleX;
                this.mBubblePopupY = this.mBubbleY - (this.mScaleMargin * 2);
                if (this.mMode == MODE_NORMAL) {
                    this.mBubbleBackground.setImageResource(R.drawable.sem_tip_popup_hint_background_04);
                    if (isRTL()) {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_rtl);
                    } else {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon);
                    }
                } else {
                    this.mBubbleBackground.setRotation(180.0f);
                }
                break;
            case DIRECTION_BOTTOM_LEFT:
                TipWindow tipWindow3 = this.mBubblePopup;
                tipWindow3.setPivot(tipWindow3.getWidth(), 0.0f);
                paramBubblePanel.gravity = 53;
                this.mBubblePopupX = this.mBubbleX - (this.mScaleMargin * 2);
                this.mBubblePopupY = this.mBubbleY;
                if (this.mMode == MODE_NORMAL) {
                    this.mBubbleBackground.setImageResource(R.drawable.sem_tip_popup_hint_background_01);
                    if (isRTL()) {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_rtl);
                    } else {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon);
                    }
                }
                break;
            case DIRECTION_BOTTOM_RIGHT:
                this.mBubblePopup.setPivot(0.0f, 0.0f);
                paramBubblePanel.gravity = 51;
                this.mBubblePopupX = this.mBubbleX;
                this.mBubblePopupY = this.mBubbleY;
                if (this.mMode == MODE_NORMAL) {
                    this.mBubbleBackground.setImageResource(R.drawable.sem_tip_popup_hint_background_02);
                    if (isRTL()) {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon_rtl);
                    } else {
                        this.mBubbleIcon.setImageResource(R.drawable.sem_tip_popup_hint_icon);
