[Java] 纯文本查看 复制代码
package com.cyjh.elfin.floatview;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.Point;
import android.os.Build.VERSION;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.cyjh.elfin.AppContext;
import com.cyjh.elfin.dialog.HideFWDialog;
import com.cyjh.elfin.dialog.HideFWDialog.OnHideCancelClickListener;
import com.cyjh.elfin.dialog.HideFWDialog.OnHideOKClickListener;
import com.cyjh.elfin.dialog.ScriptRTDDialog;
import com.cyjh.elfin.dialog.ScriptUIDialog;
import com.cyjh.elfin.log.CommonLog;
import com.cyjh.elfin.util.AppDeviceUtils;
import com.cyjh.elfin.util.NetworkUtils;
import com.cyjh.mq.sdk.MqRunner;
import com.cyjh.share.bean.response.ScriptStartRunResponse;
import com.cyjh.share.mvp.presenter.AppStatisticsPresenter;
import com.cyjh.share.mvp.presenter.AppStatisticsPresenter.OnClickScriptRunCallback;
import com.cyjh.share.util.GsonExUtil;
import com.cyjh.share.util.ToastUtils;
public class ElfinFloatView
extends LinearLayout
implements View.OnClickListener
{
private static final int ELFIN_ORIENTATION_DOWN = 3;
private static final int ELFIN_ORIENTATION_LEFT = 4;
private static final int ELFIN_ORIENTATION_RIGHT = 2;
private static final int ELFIN_ORIENTATION_UP = 1;
private static final int LIMIT_ANGLE = 60;
private static final int LIMIT_COUNT = 2;
private static final int TIME_ADSORPTION = 2000;
private static final int TIME_INTERVAL = 1000;
private static final int TIME_TRANSLUCENT = 5000;
private CommonLog commonLog = new CommonLog();
private boolean isPreventRepeatedClick = false;
private AppContext mAppContext;
private Context mContext;
private CountDownTimer mCountDownTimer = new CountDownTimer(7000L, 1000L)
{
public void onFinish()
{
int[] arrayOfInt = new int[2];
ElfinFloatView.this.mImageViewElfin.getLocationOnScreen(arrayOfInt);
if (arrayOfInt[0] >= (AppDeviceUtils.getResolution(ElfinFloatView.this.getContext()).x - ElfinFloatView.this.mDownX) / 2.0F)
{
if (ElfinFloatView.this.mAppContext.STATE_SCRIPT == 2)
{
ElfinFloatView.this.mImageViewElfin.setImageResource(2130837667);
return;
}
ElfinFloatView.this.mImageViewElfin.setImageResource(2130837656);
return;
}
if (ElfinFloatView.this.mAppContext.STATE_SCRIPT == 2)
{
ElfinFloatView.this.mImageViewElfin.setImageResource(2130837669);
return;
}
ElfinFloatView.this.mImageViewElfin.setImageResource(2130837660);
}
public void onTick(long paramAnonymousLong)
{
if ((paramAnonymousLong <= 3000L) && (paramAnonymousLong > 2000L))
{
ElfinFloatView.this.mImageViewElfin.setAlpha(0.5F);
ElfinFloatView.this.changeToolBarState(false);
}
}
};
private DeleteFloatView mDeleteFloatView;
private float mDownX;
private float mDownY;
private MyHandler mHandler;
private ImageView mImageViewElfin;
public ImageView mImgRunAndStop;
private float mLastX;
private float mLastY;
private LinearLayout mLinearLayoutElfin;
private LinearLayout mLinearLayoutInfo;
private LinearLayout mLinearLayoutRun;
private LinearLayout mLinearLayoutSetting;
private LinearLayout mLinearLayoutTools;
private int mLockState;
private float mRawCurrentX;
private float mRawCurrentY;
private ScriptRTDDialog mScriptRTDDialog;
private ScriptUIDialog mScriptUIDialog;
public TextView mTvRunScript;
private WindowManager mWindowManager;
private WindowManager.LayoutParams mWindowManagerParams;
private HideFWDialog.OnHideCancelClickListener onHideCancelClickListener = new HideFWDialog.OnHideCancelClickListener()
{
public void onClick(View paramAnonymousView)
{
ElfinFloatView.this.moveToEdge();
}
};
private HideFWDialog.OnHideOKClickListener onHideOKClickListener = new HideFWDialog.OnHideOKClickListener()
{
public void onClick(View paramAnonymousView)
{
ElfinFloatView.this.toggleElfinVisbility();
}
};
private final View.OnTouchListener onTouchListener = new View.OnTouchListener()
{
private static final int MIN_MOVEMENT = 5;
private GestureDetector gestureDetector = new GestureDetector(ElfinFloatView.this.getContext(), this.gestureListener);
private ElfinFloatView.ElfinGestureListener gestureListener = new ElfinFloatView.ElfinGestureListener(ElfinFloatView.this, null);
public float getDistance(float paramAnonymousFloat1, float paramAnonymousFloat2, float paramAnonymousFloat3, float paramAnonymousFloat4)
{
return (float)Math.sqrt(Math.pow(paramAnonymousFloat1 - paramAnonymousFloat3, 2.0D) + Math.pow(paramAnonymousFloat2 - paramAnonymousFloat4, 2.0D));
}
public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
{
if (this.gestureDetector.onTouchEvent(paramAnonymousMotionEvent)) {
return true;
}
switch (paramAnonymousMotionEvent.getAction())
{
default:
return false;
case 2:
if (ElfinFloatView.this.mLinearLayoutTools.getVisibility() == 0) {
return true;
}
ElfinFloatView.access$1102(ElfinFloatView.this, ElfinFloatView.this.mRawCurrentX);
ElfinFloatView.access$1202(ElfinFloatView.this, ElfinFloatView.this.mRawCurrentY);
ElfinFloatView.access$702(ElfinFloatView.this, paramAnonymousMotionEvent.getRawX());
ElfinFloatView.access$802(ElfinFloatView.this, paramAnonymousMotionEvent.getRawY() - AppDeviceUtils.getStatusBarHeight(ElfinFloatView.this.getContext()));
if (getDistance(ElfinFloatView.this.mLastX, ElfinFloatView.this.mLastY, ElfinFloatView.this.mRawCurrentX, ElfinFloatView.this.mRawCurrentY) <= 5.0F) {
return true;
}
double d = Math.toDegrees(Math.atan2(ElfinFloatView.this.mRawCurrentY - ElfinFloatView.this.mLastY, ElfinFloatView.this.mRawCurrentX - ElfinFloatView.this.mLastX));
if ((d < -60.0D) && (d > -120.0D)) {}
do
{
i = 1;
break;
if ((d >= -60.0D) && (d <= 60.0D))
{
i = 2;
break;
}
if ((d > 60.0D) && (d < 120.0D))
{
i = 3;
break;
}
} while ((d < 120.0D) && (d > -120.0D));
int i = 4;
ElfinFloatView.this.updateFloatViewDirection(i);
ElfinFloatView.this.updateFloatViewPosition((int)(ElfinFloatView.this.mRawCurrentX - ElfinFloatView.this.mDownX), (int)(ElfinFloatView.this.mRawCurrentY - ElfinFloatView.this.mDownY));
if (ElfinFloatView.this.mDeleteFloatView.getVisibility() == 8) {
ElfinFloatView.this.mDeleteFloatView.setVisibility(0);
}
if (ElfinFloatView.this.isHide())
{
ElfinFloatView.this.mDeleteFloatView.setHide();
return true;
}
ElfinFloatView.this.mDeleteFloatView.setNormal();
return true;
case 1:
ElfinFloatView.access$702(ElfinFloatView.this, paramAnonymousMotionEvent.getRawX());
ElfinFloatView.access$802(ElfinFloatView.this, paramAnonymousMotionEvent.getRawY() - AppDeviceUtils.getStatusBarHeight(ElfinFloatView.this.getContext()));
if (ElfinFloatView.this.isHide())
{
paramAnonymousView = new HideFWDialog(ElfinFloatView.this.getContext());
paramAnonymousView.setOnHideOKClickListener(ElfinFloatView.this.onHideOKClickListener);
paramAnonymousView.setOnHideCancelClickListener(ElfinFloatView.this.onHideCancelClickListener);
paramAnonymousView.setOnCancelListener(new DialogInterface.OnCancelListener()
{
public void onCancel(DialogInterface paramAnonymous2DialogInterface)
{
ElfinFloatView.this.moveToEdge();
}
});
paramAnonymousView.show();
return false;
}
if (ElfinFloatView.this.mLinearLayoutTools.getVisibility() == 8) {
ElfinFloatView.this.moveToEdge();
}
ElfinFloatView.this.mDeleteFloatView.setVisibility(8);
ElfinFloatView.this.mCountDownTimer.start();
return false;
}
ElfinFloatView.this.resetElfinState();
ElfinFloatView.access$702(ElfinFloatView.this, paramAnonymousMotionEvent.getRawX());
ElfinFloatView.access$802(ElfinFloatView.this, paramAnonymousMotionEvent.getRawY() - AppDeviceUtils.getStatusBarHeight(ElfinFloatView.this.getContext()));
ElfinFloatView.access$102(ElfinFloatView.this, paramAnonymousMotionEvent.getX());
ElfinFloatView.access$902(ElfinFloatView.this, paramAnonymousMotionEvent.getY());
return false;
}
};
public ElfinFloatView(Context paramContext, DeleteFloatView paramDeleteFloatView)
{
super(paramContext);
this.mAppContext = ((AppContext)paramContext);
initView();
initWindow();
this.mDeleteFloatView = paramDeleteFloatView;
this.mCountDownTimer.start();
}
private void initElfinImageView()
{
this.mImageViewElfin = ((ImageView)findViewById(2131755300));
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837662);
this.mTvRunScript.setText(getContext().getString(2131296412));
this.mImgRunAndStop.setImageResource(2130837678);
}
else
{
this.mImageViewElfin.setImageResource(2130837649);
this.mTvRunScript.setText(getContext().getString(2131296410));
this.mImgRunAndStop.setImageResource(2130837676);
}
this.mImageViewElfin.setOnClickListener(null);
this.mImageViewElfin.setOnTouchListener(this.onTouchListener);
}
private void initView()
{
LayoutInflater.from(getContext()).inflate(2130968659, this);
this.mLinearLayoutElfin = ((LinearLayout)findViewById(2131755291));
this.mLinearLayoutTools = ((LinearLayout)findViewById(2131755292));
this.mLinearLayoutRun = ((LinearLayout)findViewById(2131755293));
this.mLinearLayoutInfo = ((LinearLayout)findViewById(2131755296));
this.mLinearLayoutSetting = ((LinearLayout)findViewById(2131755298));
this.mTvRunScript = ((TextView)findViewById(2131755295));
this.mImgRunAndStop = ((ImageView)findViewById(2131755294));
this.mLinearLayoutRun.setOnClickListener(this);
this.mLinearLayoutInfo.setOnClickListener(this);
this.mLinearLayoutSetting.setOnClickListener(this);
initElfinImageView();
}
private void initWindow()
{
this.mWindowManager = ((WindowManager)getContext().getSystemService("window"));
this.mWindowManagerParams = new WindowManager.LayoutParams();
if (Build.VERSION.SDK_INT >= 26) {
this.mWindowManagerParams.type = 2038;
} else if ((Build.VERSION.SDK_INT >= 19) && (Build.VERSION.SDK_INT < 24)) {
this.mWindowManagerParams.type = 2005;
} else {
this.mWindowManagerParams.type = 2002;
}
this.mWindowManagerParams.format = 1;
this.mWindowManagerParams.flags = 40;
this.mWindowManagerParams.gravity = 51;
this.mWindowManagerParams.x = (AppDeviceUtils.getResolution(getContext()).x - this.mLinearLayoutElfin.getLayoutParams().width);
this.mWindowManagerParams.y = (AppDeviceUtils.getResolution(getContext()).y / 4);
this.mRawCurrentY = (AppDeviceUtils.getResolution(getContext()).y / 4);
this.mWindowManagerParams.width = this.mLinearLayoutElfin.getLayoutParams().width;
this.mWindowManagerParams.height = this.mLinearLayoutElfin.getLayoutParams().height;
}
private boolean isHide()
{
int[] arrayOfInt1 = new int[2];
this.mImageViewElfin.getLocationOnScreen(arrayOfInt1);
int[] arrayOfInt2 = new int[2];
this.mDeleteFloatView.getLocationOnScreen(arrayOfInt2);
return (arrayOfInt1[0] > arrayOfInt2[0]) && (arrayOfInt1[0] < arrayOfInt2[0] + this.mDeleteFloatView.geTextViewtWidth()) && (arrayOfInt1[1] > arrayOfInt2[1]);
}
private void moveToEdge()
{
if (this.mDeleteFloatView.getVisibility() == 0)
{
this.mDeleteFloatView.setVisibility(8);
this.mDeleteFloatView.setNormal();
}
int[] arrayOfInt = new int[2];
this.mImageViewElfin.getLocationOnScreen(arrayOfInt);
if (arrayOfInt[0] >= (AppDeviceUtils.getResolution(getContext()).x - this.mDownX) / 2.0F)
{
updateFloatViewPosition(AppDeviceUtils.getResolution(getContext()).x, (int)(this.mRawCurrentY - this.mDownY));
this.mLinearLayoutElfin.removeView(this.mLinearLayoutTools);
this.mLinearLayoutElfin.addView(this.mLinearLayoutTools, 0);
}
else
{
updateFloatViewPosition(0, (int)(this.mRawCurrentY - this.mDownY));
this.mLinearLayoutElfin.removeView(this.mLinearLayoutTools);
this.mLinearLayoutElfin.addView(this.mLinearLayoutTools, 1);
}
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837662);
return;
}
this.mImageViewElfin.setImageResource(2130837649);
}
private void resetElfinState()
{
this.mCountDownTimer.cancel();
this.mImageViewElfin.setAlpha(1.0F);
}
private void updateFloatViewDirection(int paramInt)
{
switch (paramInt)
{
default:
return;
case 4:
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837668);
return;
}
this.mImageViewElfin.setImageResource(2130837657);
return;
case 3:
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837666);
return;
}
this.mImageViewElfin.setImageResource(2130837653);
return;
case 2:
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837670);
return;
}
this.mImageViewElfin.setImageResource(2130837661);
return;
}
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837662);
return;
}
this.mImageViewElfin.setImageResource(2130837649);
}
public void changeToolBarState(boolean paramBoolean)
{
updateFloatViewDirection(1);
if (paramBoolean)
{
if (this.mLinearLayoutTools.getVisibility() == 8) {
this.mLinearLayoutTools.setVisibility(0);
}
}
else if (this.mLinearLayoutTools.getVisibility() == 0) {
this.mLinearLayoutTools.setVisibility(8);
}
}
public WindowManager.LayoutParams getLayoutParams()
{
return this.mWindowManagerParams;
}
public Context getmContext()
{
return this.mContext;
}
public void onClick(View paramView)
{
resetElfinState();
int i = paramView.getId();
if (i != 2131755293)
{
if (i != 2131755296)
{
if (i == 2131755298)
{
this.mScriptUIDialog = new ScriptUIDialog(getContext());
this.mScriptUIDialog.mContext = this.mContext;
this.mScriptUIDialog.show();
}
}
else
{
this.mScriptRTDDialog = new ScriptRTDDialog(getContext());
this.mScriptRTDDialog.show();
}
}
else
{
if (this.isPreventRepeatedClick) {
return;
}
this.isPreventRepeatedClick = true;
if (MqRunner.getInstance().isScriptStarted())
{
MqRunner.getInstance().stop();
this.isPreventRepeatedClick = false;
}
else
{
if (!NetworkUtils.isAvailable(paramView.getContext()))
{
ToastUtils.showToastLong(getContext(), getContext().getString(2131296450));
this.isPreventRepeatedClick = false;
return;
}
AppStatisticsPresenter.getStatisticsPresenter().setClickScriptRunCallback(new AppStatisticsPresenter.OnClickScriptRunCallback()
{
public void onCallbackFail()
{
ElfinFloatView.access$302(ElfinFloatView.this, false);
}
public void onCallbackSuc(Object paramAnonymousObject)
{
paramAnonymousObject = (String)paramAnonymousObject;
if (!TextUtils.isEmpty(paramAnonymousObject))
{
paramAnonymousObject = (ScriptStartRunResponse)GsonExUtil.parsData(paramAnonymousObject, ScriptStartRunResponse.class);
if ((paramAnonymousObject != null) && (paramAnonymousObject.Code == 200))
{
if (ElfinFloatView.this.mAppContext.STATE_SCRIPT == 1) {
ElfinFloatView.this.mAppContext.runScript();
}
}
else if (paramAnonymousObject != null) {
ToastUtils.showToastLong(AppContext.getInstance(), paramAnonymousObject.Message);
} else {
ToastUtils.showToastLong(AppContext.getInstance(), 2131296429);
}
}
else
{
ToastUtils.showToastLong(AppContext.getInstance(), 2131296428);
}
AppStatisticsPresenter.getStatisticsPresenter().cleanCallback();
ElfinFloatView.access$302(ElfinFloatView.this, false);
}
}).loadScriptStartRunStatistics(AppContext.getInstance(), "", "PreStart");
}
if (this.mHandler == null) {
this.mHandler = new MyHandler(null);
}
this.mHandler.removeCallbacksAndMessages(null);
this.mHandler.postDelayed(new Runnable()
{
public void run()
{
ElfinFloatView.access$302(ElfinFloatView.this, false);
}
}, 3000L);
}
this.mCountDownTimer.start();
}
protected void onDetachedFromWindow()
{
if (this.mHandler != null) {
this.mHandler.removeCallbacksAndMessages(null);
}
super.onDetachedFromWindow();
}
public void posContorlbar(float paramFloat, int paramInt)
{
CommonLog localCommonLog = this.commonLog;
StringBuilder localStringBuilder = new StringBuilder();
localStringBuilder.append("postion>>>");
localStringBuilder.append(paramFloat);
localCommonLog.e(localStringBuilder.toString());
this.mLockState = paramInt;
if (this.mLockState != 0) {
this.mImageViewElfin.setOnTouchListener(null);
}
if (this.mDeleteFloatView.getVisibility() == 0)
{
this.mDeleteFloatView.setVisibility(8);
this.mDeleteFloatView.setNormal();
}
updateFloatViewPosition(AppDeviceUtils.getResolution(getContext()).x, (int)(AppDeviceUtils.getResolution(getContext()).y * paramFloat - getHeight()));
this.mLinearLayoutElfin.removeView(this.mLinearLayoutTools);
this.mLinearLayoutElfin.addView(this.mLinearLayoutTools, 0);
if (this.mAppContext.STATE_SCRIPT == 2)
{
this.mImageViewElfin.setImageResource(2130837662);
return;
}
this.mImageViewElfin.setImageResource(2130837649);
}
public void rotateScreen()
{
resetElfinState();
this.mCountDownTimer.start();
updateFloatViewDirection(1);
this.mWindowManagerParams.x = (AppDeviceUtils.getResolution(getContext()).x - this.mLinearLayoutElfin.getLayoutParams().width);
this.mWindowManagerParams.y = (AppDeviceUtils.getResolution(getContext()).y / 4);
this.mWindowManager.updateViewLayout(this, this.mWindowManagerParams);
this.mDeleteFloatView.rotateScreen();
}
public void setImageViewElfinTouchListener()
{
this.mImageViewElfin.setOnTouchListener(this.onTouchListener);
}
public void setmContext(Context paramContext)
{
this.mContext = paramContext;
}
public void toggleElfinVisbility()
{
resetElfinState();
if (getVisibility() == 0)
{
changeToolBarState(false);
this.mDeleteFloatView.setVisibility(8);
setVisibility(8);
return;
}
this.mCountDownTimer.start();
updateFloatViewPosition(AppDeviceUtils.getResolution(getContext()).x, AppDeviceUtils.getResolution(getContext()).y / 4);
setVisibility(0);
}
public void upadateElfinImages()
{
if (this.mAppContext.STATE_SCRIPT == 2) {
this.mImageViewElfin.setImageResource(2130837662);
} else {
this.mImageViewElfin.setImageResource(2130837649);
}
resetElfinState();
this.mCountDownTimer.start();
}
public void updateFloatViewPosition(int paramInt1, int paramInt2)
{
this.mWindowManagerParams.x = paramInt1;
this.mWindowManagerParams.y = paramInt2;
this.mWindowManager.updateViewLayout(this, this.mWindowManagerParams);
}
private class ElfinGestureListener
implements GestureDetector.OnGestureListener
{
private ElfinGestureListener() {}
public boolean onDown(MotionEvent paramMotionEvent)
{
return false;
}
public boolean onFling(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)
{
return false;
}
public void onLongPress(MotionEvent paramMotionEvent) {}
public boolean onScroll(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)
{
return false;
}
public void onShowPress(MotionEvent paramMotionEvent) {}
public boolean onSingleTapUp(MotionEvent paramMotionEvent)
{
if (ElfinFloatView.this.mDeleteFloatView.getVisibility() == 0) {
ElfinFloatView.this.mDeleteFloatView.setVisibility(8);
}
if (ElfinFloatView.this.mLinearLayoutTools.getVisibility() == 0) {
ElfinFloatView.this.changeToolBarState(false);
} else {
ElfinFloatView.this.changeToolBarState(true);
}
ElfinFloatView.this.mCountDownTimer.start();
return true;
}
}
private static class MyHandler
extends Handler
{
public void handleMessage(Message paramMessage)
{
super.handleMessage(paramMessage);
}
}
}