Skip to content

Commit

Permalink
feat(0.9.7): 添加动画Demo演示
Browse files Browse the repository at this point in the history
Signed-off-by: free46000 <[email protected]>
  • Loading branch information
free46000 committed May 25, 2017
1 parent 167c5cd commit 3cb9bf3
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 2 deletions.
4 changes: 2 additions & 2 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<activity android:name=".DataBindActivity_"/>
<activity android:name=".InputActivity_"/>
<activity android:name=".UserInfoActivity_"/>
<activity android:name=".EmptyAndErrorActivity_">
</activity>
<activity android:name=".EmptyAndErrorActivity_"/>
<activity android:name=".AnimationActivity_"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.freelib.multiitem.demo;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;

import com.freelib.multiitem.adapter.BaseItemAdapter;
import com.freelib.multiitem.animation.AlphaInAnimation;
import com.freelib.multiitem.animation.BaseAnimation;
import com.freelib.multiitem.animation.ScaleInAnimation;
import com.freelib.multiitem.animation.SlideInBottomAnimation;
import com.freelib.multiitem.animation.SlideInLeftAnimation;
import com.freelib.multiitem.animation.SlideInRightAnimation;
import com.freelib.multiitem.demo.bean.ImageBean;
import com.freelib.multiitem.demo.bean.ImageTextBean;
import com.freelib.multiitem.demo.bean.TextBean;
import com.freelib.multiitem.demo.viewholder.ImageAndTextManager;
import com.freelib.multiitem.demo.viewholder.ImageViewManager;
import com.freelib.multiitem.demo.viewholder.TextViewManager;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.CheckedChange;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

@EActivity(R.layout.activity_animation)
public class AnimationActivity extends AppCompatActivity {
@ViewById(R.id.recyclerView)
protected RecyclerView recyclerView;

private BaseItemAdapter adapter;

public static void startActivity(Context context) {
AnimationActivity_.intent(context).start();
}

@AfterViews
protected void initViews() {
setTitle(R.string.animation_title);

recyclerView.setLayoutManager(new LinearLayoutManager(this));
//初始化adapter
adapter = new BaseItemAdapter();
//为XXBean数据源注册XXManager管理类
adapter.register(ImageTextBean.class, new ImageAndTextManager());
recyclerView.setAdapter(adapter);
List<Object> list = new ArrayList<>();
for (int i = 0; i < 20; i++) {
list.add(new ImageTextBean(R.drawable.img2, "BBB" + i));
}

adapter.setDataItems(list);
}

@CheckedChange({R.id.leftCheck, R.id.rightCheck, R.id.bottomCheck, R.id.scaleCheck, R.id.alphaCheck})
protected void checkedChanged(CompoundButton compoundButton, boolean isChecked) {
if (!isChecked) {
return;
}
BaseAnimation baseAnimation;
switch (compoundButton.getId()) {
case R.id.leftCheck:
baseAnimation = new SlideInLeftAnimation();
break;
case R.id.rightCheck:
baseAnimation = new SlideInRightAnimation();
break;
case R.id.bottomCheck:
baseAnimation = new SlideInBottomAnimation();
break;
case R.id.alphaCheck:
baseAnimation = new AlphaInAnimation();
break;
default:
baseAnimation = new ScaleInAnimation();
break;
}
//开启动画,并取消动画只在第一次加载时展示
adapter.enableAnimation(baseAnimation, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected void initViews() {
() -> UserInfoActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.empty_error_title),
() -> EmptyAndErrorActivity.startActivity(this)));
adapter.addDataItem(new MainBean(getString(R.string.animation_title),
() -> AnimationActivity.startActivity(this)));

adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
Expand Down
56 changes: 56 additions & 0 deletions demo/src/main/res/layout/activity_animation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:orientation="vertical">

<RadioGroup android:id="@+id/animationGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<RadioButton
android:id="@+id/scaleCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scale"
/>

<RadioButton
android:id="@+id/alphaCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="alpha"
/>

<RadioButton
android:id="@+id/bottomCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bottom"
/>

<RadioButton
android:id="@+id/leftCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="left"
/>

<RadioButton
android:id="@+id/rightCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="right"
/>

</RadioGroup>

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="8dp"/>
</LinearLayout>
1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="input_title">录入表单演示</string>
<string name="user_info_title">用户详情演示</string>
<string name="empty_error_title">空白错误页演示</string>
<string name="animation_title">动画页演示</string>

<string name="loading_more">加载中...</string>
<string name="load_all">加载完成</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;

import com.freelib.multiitem.adapter.holder.BaseViewHolder;
import com.freelib.multiitem.adapter.holder.HeadFootHolderManager;
Expand Down Expand Up @@ -285,6 +286,14 @@ public void enableAnimation(BaseAnimation animation, boolean isShowAnimWhenFirst
animationLoader.enableLoadAnimation(animation, isShowAnimWhenFirstLoad);
}

public void setInterpolator(@NonNull Interpolator interpolator) {
animationLoader.setInterpolator(interpolator);
}

public void setAnimDuration(long animDuration) {
animationLoader.setAnimDuration(animDuration);
}

/**
* @return 获取当前数据源List,不包含head和foot
*/
Expand Down

0 comments on commit 3cb9bf3

Please sign in to comment.