[add] 动画

This commit is contained in:
liujing
2020-07-31 19:53:29 +08:00
parent 39b4684263
commit 8cba259002
6 changed files with 132 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -29,6 +30,8 @@ import com.zhidao.mogo.module.event.panel.network.HostConstant;
import com.zhidao.mogo.module.event.panel.network.EventApiService;
import com.zhidao.mogo.module.event.panel.network.ShareEventParameter;
import com.zhidao.mogo.module.event.panel.presenter.ShareEventsPresenter;
import com.zhidao.mogo.module.event.panel.util.animation.AnimationManager;
import com.zhidao.mogo.module.event.panel.util.animation.AnimationResources;
import java.util.ArrayList;
import java.util.HashMap;
@@ -47,6 +50,11 @@ public class ShareEventsFragment extends MvpFragment implements AdapterCallback
private EventApiService eventApiService;
private int pageNum = 1;
final CountDownLatch countDownLatch = new CountDownLatch(2);
private IMogoNetwork network;
//动画
private ImageView loadingImageView;
private AnimationManager animationHandler;
@Override
protected int getLayoutId() {
@@ -55,6 +63,9 @@ public class ShareEventsFragment extends MvpFragment implements AdapterCallback
@Override
protected void initViews() {
network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(getContext());
eventApiService = network.create(EventApiService.class, HostConstant.getNetHost());
animationHandler = new AnimationManager();
initRecyclerView();
initData();
}
@@ -76,9 +87,8 @@ public class ShareEventsFragment extends MvpFragment implements AdapterCallback
}
private void initData() {
IMogoNetwork network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(getContext());
this.eventApiService = network.create(EventApiService.class, HostConstant.getNetHost());
loadingImageView = mRootView.findViewById(R.id.loading_imageview);
animationHandler.animationWithTarget(loadingImageView, AnimationResources.loadingRes,300);
getShareEventDescription();
getShareEventList(pageNum, 10);
}
@@ -101,7 +111,6 @@ public class ShareEventsFragment extends MvpFragment implements AdapterCallback
if (resultData != null && resultData.getResult() != null
&& resultData.getResult().getEnthusiasmIndex() != null) {
dataArrayList.add(resultData.getResult().getEnthusiasmIndex());
adapter.notifyDataSetChanged();
Log.d(TAG, "热心指数---:" + resultData.getResult().getEnthusiasmIndex());
}
countDownLatch.countDown();
@@ -162,11 +171,11 @@ public class ShareEventsFragment extends MvpFragment implements AdapterCallback
} else {
//空白
item.setViewType(ShareEventItemEnum.ITEM_TYPE_SHARE_EMPTY);
dataArrayList.add(item);
}
adapter.notifyDataSetChanged();
countDownLatch.countDown();
animationHandler.stop();
}
@Override

View File

@@ -0,0 +1,9 @@
package com.zhidao.mogo.module.event.panel.util.animation;
interface Animation {
void start();
void stop();
}

View File

@@ -0,0 +1,47 @@
package com.zhidao.mogo.module.event.panel.util.animation;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.UiThreadHandler;
public class AnimationManager implements Animation {
private ImageView targetImageView;
private Animation delegate;
private boolean isStarted = false;
public void animationWithTarget(ImageView imageView, int[] resources, int duration) {
targetImageView = imageView;
ThreadPoolService.execute(() -> {
final AnimationDrawable drawable = new AnimationDrawable();
for (int i = 0; i < resources.length; i++) {
drawable.addFrame(targetImageView.getResources().getDrawable(resources[i]), duration);
}
UiThreadHandler.post(() -> {
targetImageView.setBackground(drawable);
delegate = new DelegateDrawable(drawable);
});
});
}
synchronized public void start() {
if (delegate != null && !isStarted) {
isStarted = true;
delegate.start();
}
}
synchronized public void stop() {
if (delegate != null && isStarted) {
isStarted = false;
delegate.stop();
}
}
public void release() {
delegate = null;
}
}

View File

@@ -0,0 +1,11 @@
package com.zhidao.mogo.module.event.panel.util.animation;
import com.zhidao.mogo.module.event.panel.R;
public class AnimationResources {
public static final int loadingRes[] = {
R.drawable.icon_enthusiasm_choose,
R.drawable.icon_enthusiasm_unchoose,
};
}

View File

@@ -0,0 +1,27 @@
package com.zhidao.mogo.module.event.panel.util.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();
}
}
}

View File

@@ -1,14 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/road_case_share_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:overScrollMode="never"
android:background="#000000"
tools:itemCount="1"
tools:listitem="@layout/module_event_panel_share_description"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
android:layout_height="match_parent" >
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/road_case_share_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:overScrollMode="never"
android:background="#000000"
tools:itemCount="1"
tools:listitem="@layout/module_event_panel_share_description"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" >
</androidx.recyclerview.widget.RecyclerView>
<ImageView
android:layout_height="50dp"
android:layout_width="50dp"
android:id="@+id/loading_imageview"
android:background="#fff889"
android:layout_centerInParent="true" >
</ImageView>
</RelativeLayout>