loading迁移common
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.mogo.module.common.animation;
|
||||
|
||||
interface Animation {
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.mogo.module.common.animation;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
public class AnimationManager implements Animation {
|
||||
|
||||
private static final String TAG = "V2XAnimationManager";
|
||||
private ProgressBar targetImageView;
|
||||
private boolean isStarted = false;
|
||||
|
||||
private int mStartIndex = 0;
|
||||
|
||||
private final static int MSG_LOOP = 3004;
|
||||
private long INTERVAL = 100L;
|
||||
|
||||
private Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case MSG_LOOP:
|
||||
if (isStarted) {
|
||||
// targetImageView.setImageResource( AnimationResources.loadingRes[mStartIndex++ % AnimationResources.loadingRes.length] );
|
||||
mHandler.sendEmptyMessageDelayed(MSG_LOOP, INTERVAL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void animationWithTarget(ProgressBar imageView, int[] resources, int duration) {
|
||||
targetImageView = imageView;
|
||||
INTERVAL = duration;
|
||||
start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void start() {
|
||||
isStarted = true;
|
||||
mHandler.sendEmptyMessage(MSG_LOOP);
|
||||
if (targetImageView != null) {
|
||||
targetImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void stop() {
|
||||
isStarted = false;
|
||||
mHandler.removeMessages(MSG_LOOP);
|
||||
if (targetImageView != null) {
|
||||
targetImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void soptWithError() {
|
||||
stop();
|
||||
if (targetImageView != null) {
|
||||
targetImageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void release() {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.module.common.animation;
|
||||
|
||||
|
||||
import com.mogo.module.common.R;
|
||||
|
||||
public class AnimationResources {
|
||||
public static final int loadingRes[] = {
|
||||
// R.drawable.v_to_x_loading_car0000,
|
||||
// R.drawable.v_to_x_loading_car0002,
|
||||
// R.drawable.v_to_x_loading_car0004,
|
||||
// R.drawable.v_to_x_loading_car0006,
|
||||
// R.drawable.v_to_x_loading_car0008,
|
||||
// R.drawable.v_to_x_loading_car0010,
|
||||
// R.drawable.v_to_x_loading_car0012,
|
||||
// R.drawable.v_to_x_loading_car0014,
|
||||
// R.drawable.v_to_x_loading_car0016,
|
||||
// R.drawable.v_to_x_loading_car0018,
|
||||
// R.drawable.v_to_x_loading_car0020,
|
||||
// R.drawable.v_to_x_loading_car0022,
|
||||
// R.drawable.v_to_x_loading_car0024,
|
||||
// R.drawable.v_to_x_loading_car0025,
|
||||
// R.drawable.v_to_x_loading_car0027,
|
||||
// R.drawable.v_to_x_loading_car0029,
|
||||
// R.drawable.v_to_x_loading_car0031,
|
||||
// R.drawable.v_to_x_loading_car0033,
|
||||
// R.drawable.v_to_x_loading_car0035,
|
||||
// R.drawable.v_to_x_loading_car0037,
|
||||
// R.drawable.v_to_x_loading_car0039,
|
||||
// R.drawable.v_to_x_loading_car0041,
|
||||
// R.drawable.v_to_x_loading_car0043,
|
||||
// R.drawable.v_to_x_loading_car0045,
|
||||
// R.drawable.v_to_x_loading_car0047,
|
||||
// R.drawable.v_to_x_loading_car0048,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.module.common.animation;
|
||||
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
|
||||
public class DelegateDrawable implements Animation {
|
||||
|
||||
private AnimationDrawable drawable;
|
||||
|
||||
public DelegateDrawable(AnimationDrawable drawable) {
|
||||
this.drawable = drawable;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (drawable != null) {
|
||||
drawable.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (drawable != null) {
|
||||
drawable.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.mogo.module.common.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.module.common.R;
|
||||
import com.mogo.module.common.animation.AnimationResources;
|
||||
import com.mogo.module.common.animation.AnimationManager;
|
||||
|
||||
public class NetworkLoadingView extends RelativeLayout {
|
||||
|
||||
private ProgressBar loadView;
|
||||
private TextView textView;
|
||||
private AnimationManager mAnimationManager;
|
||||
public Button refresButton;
|
||||
private String loadingText = "正在获取信息…";
|
||||
|
||||
public NetworkLoadingView(Context context) {
|
||||
|
||||
super(context);
|
||||
}
|
||||
|
||||
public NetworkLoadingView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LayoutInflater.from(context).inflate(R.layout.network_loading_item, this);
|
||||
initView();
|
||||
/*
|
||||
添加动画图片资源
|
||||
* */
|
||||
setLoadingImage(AnimationResources.loadingRes);
|
||||
}
|
||||
|
||||
public NetworkLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
mAnimationManager = new AnimationManager();
|
||||
loadView = findViewById(R.id.loading_imageview);
|
||||
textView = findViewById(R.id.loading_text);
|
||||
refresButton = findViewById(R.id.refresh_button);
|
||||
}
|
||||
|
||||
public void setLoadingText(String text) {
|
||||
if (textView != null) {
|
||||
textView.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLoadingImage(int[] resources) {
|
||||
mAnimationManager.animationWithTarget(loadView, resources, 100);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (mAnimationManager != null) {
|
||||
mAnimationManager.start();
|
||||
this.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (refresButton != null) {
|
||||
refresButton.setVisibility(GONE);
|
||||
}
|
||||
if (textView != null) {
|
||||
textView.setText(loadingText);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (mAnimationManager != null) {
|
||||
mAnimationManager.stop();
|
||||
this.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopWithError(String errormsg, int showRefreshButton) {
|
||||
if (mAnimationManager != null) {
|
||||
mAnimationManager.soptWithError();
|
||||
}
|
||||
if (textView != null) {
|
||||
textView.setText(errormsg);
|
||||
}
|
||||
if (refresButton != null) {
|
||||
refresButton.setVisibility(showRefreshButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user