4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1
以下内容为反编译后的 LoadingView.java 源代码,内容仅作参考
package com.m4399.support.widget;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.airbnb.lottie.LottieAnimationView;
import com.framework.helpers.SystemIntentHelper;
import com.framework.manager.network.NetworkStatusManager;
import com.framework.utils.DensityUtils;
import com.m4399.support.R;
import com.m4399.support.utils.DevicesUtils;
import com.m4399.support.utils.ToastUtils;
import java.lang.ref.WeakReference;
public class LoadingView extends RelativeLayout implements View.OnClickListener {
public static final int LOADING = 0;
public static final int NET_ERROR = 259;
public static final int RELOAD = 257;
public static final int UNLOGIN = 258;
protected int mButtonStatus;
protected LoadingHandler mLoadingHandler;
protected PageReloadClickListener mReloadListener;
public interface PageReloadClickListener {
void onViewClick(int i);
}
public LoadingView(Context context) {
super(context);
this.mButtonStatus = 0;
initView(context);
}
public LoadingView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.mButtonStatus = 0;
initView(context);
}
public void initView(Context context) {
View.inflate(context, getLayoutId(), this);
View findViewById = findViewById(R.id.btn_result_execute);
View findViewById2 = findViewById(R.id.layout_loading);
if (findViewById != null) {
findViewById.setOnClickListener(this);
}
if (findViewById2 != null) {
findViewById2.setOnClickListener(this);
if (findViewById2.getParent() instanceof NestedScrollView) {
((NestedScrollView) findViewById2.getParent()).setNestedScrollingEnabled(true);
}
}
View refreshButton = getRefreshButton();
if (refreshButton != null) {
refreshButton.setVisibility(8);
refreshButton.setOnClickListener(this);
}
this.mLoadingHandler = new LoadingHandler(getAnimView());
}
protected View getNetErrorView() {
View findViewById = findViewById(R.id.btn_error_1);
if (findViewById != null) {
findViewById.setOnClickListener(this);
}
View findViewById2 = findViewById(R.id.btn_error_2);
if (findViewById2 != null) {
findViewById2.setOnClickListener(this);
}
return findViewById(R.id.layout_network_error);
}
protected int getLayoutId() {
return R.layout.m4399_view_request_loading;
}
public void onViewClickListener(PageReloadClickListener pageReloadClickListener) {
this.mReloadListener = pageReloadClickListener;
}
public ImageView getAnimView() {
return (ImageView) findViewById(R.id.iv_loading);
}
public TextView getTipView() {
return (TextView) findViewById(R.id.tv_load_tip);
}
public Button getHandleButton() {
return (Button) findViewById(R.id.btn_result_execute);
}
protected View getRefreshButton() {
return findViewById(R.id.btn_result_refresh);
}
protected String getLoadingTip() {
return getResources().getString(R.string.loading);
}
protected String getOfflineTip() {
return getResources().getString(R.string.network_error_page_loading);
}
protected String getUnloginTip() {
return getResources().getString(R.string.unlogin);
}
protected int getDefaultBtnRes() {
return R.drawable.m4399_xml_selector_btn_green;
}
public void setLoadingStyle() {
Resources resources = getResources();
View findViewById = findViewById(R.id.layout_loading);
if (findViewById != null) {
findViewById.setBackgroundColor(resources.getColor(R.color.bai_ffffff));
}
if (getAnimView() != null) {
getAnimView().setVisibility(0);
}
if (getTipView() != null) {
getTipView().setVisibility(0);
((LinearLayout.LayoutParams) getTipView().getLayoutParams()).setMargins(0, DensityUtils.dip2px(getContext(), 8.0f), 0, 0);
getTipView().setText(getLoadingTip());
getTipView().setTextColor(resources.getColor(R.color.hui_8a000000));
getTipView().setTextSize(14.0f);
}
if (getHandleButton() != null) {
getHandleButton().setVisibility(8);
}
if (getNetErrorView() != null) {
getNetErrorView().setVisibility(8);
}
View refreshButton = getRefreshButton();
if (refreshButton != null) {
refreshButton.setVisibility(8);
}
this.mLoadingHandler.removeMessages(1);
this.mLoadingHandler.sendEmptyMessage(1);
this.mButtonStatus = 0;
}
public void dismiss() {
if (getParent() != null) {
((ViewGroup) getParent()).removeView(this);
}
releaseResourse();
}
public void setErrorStyle(Throwable th, int i, String str) {
setErrorStyle(th, i, str, true);
}
public void setErrorStyle(Throwable th, int i, String str, boolean z) {
if (getTipView() != null) {
((LinearLayout.LayoutParams) getTipView().getLayoutParams()).setMargins(0, DensityUtils.dip2px(getContext(), 8.0f), 0, 0);
}
this.mLoadingHandler.sendEmptyMessage(2);
if (th == null) {
if (i == 799) {
showNoLoginError(z);
return;
} else if (i == 403007) {
showServiceMaintain(str);
return;
} else {
showOtherError(str);
return;
}
}
if (i != -104) {
if (i == 0) {
showNetworkError();
return;
} else {
showOtherError(str);
return;
}
}
if (!NetworkStatusManager.checkIsAvalible()) {
showNetworkError();
} else {
showOtherError(str);
}
}
public void showNetworkError() {
this.mButtonStatus = NET_ERROR;
this.mLoadingHandler.sendEmptyMessage(4);
if (getTipView() != null) {
getTipView().setVisibility(0);
getTipView().setText(getOfflineTip());
}
if (getHandleButton() != null) {
getHandleButton().setVisibility(8);
}
if (getNetErrorView() != null) {
getNetErrorView().setVisibility(0);
}
if (getRefreshButton() != null) {
getRefreshButton().setVisibility(8);
}
}
protected void showNoLoginError(boolean z) {
this.mButtonStatus = 258;
Message obtain = Message.obtain();
obtain.arg1 = R.mipmap.m4399_webp_like;
obtain.what = 3;
this.mLoadingHandler.sendMessage(obtain);
if (getTipView() != null) {
getTipView().setVisibility(0);
getTipView().setText(getUnloginTip());
}
if (getHandleButton() != null) {
getHandleButton().setText(R.string.login_or_register);
getHandleButton().setVisibility(z ? 8 : 0);
}
if (getNetErrorView() != null) {
getNetErrorView().setVisibility(8);
}
}
public void showOtherError(String str) {
this.mButtonStatus = 257;
this.mLoadingHandler.sendEmptyMessage(3);
if (getTipView() != null) {
getTipView().setVisibility(0);
getTipView().setText(str);
}
if (getHandleButton() != null) {
getHandleButton().setBackgroundResource(getDefaultBtnRes());
getHandleButton().setVisibility(0);
getHandleButton().setText(R.string.refresh);
}
if (getNetErrorView() != null) {
getNetErrorView().setVisibility(8);
}
}
protected void showServiceMaintain(String str) {
View findViewById = findViewById(R.id.layout_loading);
if (findViewById != null) {
findViewById.setBackgroundColor(getResources().getColor(R.color.bai_ffffff));
}
this.mButtonStatus = 257;
this.mLoadingHandler.sendEmptyMessage(5);
Resources resources = getResources();
TextView tipView = getTipView();
if (tipView != null) {
tipView.setVisibility(0);
tipView.setText(str);
tipView.setIncludeFontPadding(false);
tipView.setTextColor(resources.getColor(R.color.hui_8a000000));
tipView.setTextSize(15.0f);
((LinearLayout.LayoutParams) tipView.getLayoutParams()).setMargins(0, DensityUtils.dip2px(getContext(), 11.0f), 0, 0);
}
if (getHandleButton() != null) {
getHandleButton().setVisibility(8);
}
if (getNetErrorView() != null) {
getNetErrorView().setVisibility(8);
}
if (getRefreshButton() != null) {
getRefreshButton().setVisibility(0);
}
}
public void onClick(View view) {
PageReloadClickListener pageReloadClickListener;
if (view.getId() == R.id.btn_result_execute || view.getId() == R.id.btn_result_refresh) {
PageReloadClickListener pageReloadClickListener2 = this.mReloadListener;
if (pageReloadClickListener2 != null) {
pageReloadClickListener2.onViewClick(this.mButtonStatus);
return;
}
return;
}
if (view.getId() == R.id.layout_loading) {
int i = this.mButtonStatus;
if ((i == 257 || i == 259) && (pageReloadClickListener = this.mReloadListener) != null) {
pageReloadClickListener.onViewClick(257);
return;
}
return;
}
if (view.getId() == R.id.btn_error_1) {
try {
((Activity) getContext()).startActivityForResult(new Intent("android.settings.WIFI_SETTINGS"), 0);
} catch (Exception unused) {
getContext().startActivity(SystemIntentHelper.createNetworkSetting());
}
} else if (view.getId() == R.id.btn_error_2) {
openBrowser(DevicesUtils.isMiui() ? "https://www.4399.cn/help/abox_guide_miui.html" : "https://www.4399.cn/help/abox_guide_common.html");
}
}
private void openBrowser(String str) {
try {
getContext().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
} catch (Exception unused) {
ToastUtils.showToast(getContext(), getContext().getString(R.string.open_error));
}
}
public void releaseResourse() {
LoadingHandler loadingHandler = this.mLoadingHandler;
if (loadingHandler != null) {
loadingHandler.sendEmptyMessage(2);
}
}
public static class LoadingHandler extends Handler {
private final WeakReference<ImageView> eDh;
private WeakReference<LottieAnimationView> geN;
public LoadingHandler(ImageView imageView) {
this.eDh = new WeakReference<>(imageView);
}
@Override
public void handleMessage(Message message) {
ImageView imageView;
int i = message.what;
try {
if (i == 1) {
ImageView imageView2 = this.eDh.get();
if (imageView2 == null) {
return;
}
ViewGroup viewGroup = (ViewGroup) imageView2.getParent();
LottieAnimationView bO = bO(viewGroup.getContext());
if (viewGroup.getChildAt(0) != bO) {
viewGroup.addView(bO, 0, imageView2.getLayoutParams());
}
bO.setVisibility(0);
imageView2.setVisibility(8);
bO.setImageAssetsFolder("animation/loading");
bO.setAnimation("animation/loading/data.json");
bO.loop(true);
bO.playAnimation();
return;
}
if (i == 2) {
removeMessages(1);
ImageView imageView3 = this.eDh.get();
if (imageView3 == null) {
return;
}
ViewGroup viewGroup2 = (ViewGroup) imageView3.getParent();
LottieAnimationView MW = MW();
if (viewGroup2.getChildAt(0) == MW) {
MW.cancelAnimation();
viewGroup2.removeView(MW);
}
imageView3.setVisibility(0);
return;
}
if (i == 3) {
ImageView imageView4 = this.eDh.get();
if (imageView4 != null) {
if (message.arg1 == 0) {
imageView4.setImageResource(R.mipmap.m4399_webp_marvel);
return;
} else {
imageView4.setImageResource(message.arg1);
return;
}
}
return;
}
if (i != 4) {
if (i == 5 && (imageView = this.eDh.get()) != null) {
imageView.setImageResource(R.mipmap.m4399_png_default_pic_breakdown);
return;
}
return;
}
ImageView imageView5 = this.eDh.get();
if (imageView5 != null) {
imageView5.setImageResource(R.mipmap.m4399_png_request_error);
}
} catch (Exception unused) {
}
}
private LottieAnimationView MW() {
WeakReference<LottieAnimationView> weakReference = this.geN;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
private LottieAnimationView bO(Context context) {
LottieAnimationView MW = MW();
if (MW != null) {
return MW;
}
LottieAnimationView lottieAnimationView = new LottieAnimationView(context);
this.geN = new WeakReference<>(lottieAnimationView);
return lottieAnimationView;
}
}
}