Skip to content

Commit 2709e13

Browse files
Merge pull request bingoogolapple#75 from bingoogolapple/develop
「fix」v2.1.5:修复 setAutoPlayAble 空指针异常,增加 Fresco Demo
2 parents 5602f66 + aa7a30c commit 2709e13

File tree

12 files changed

+187
-7
lines changed

12 files changed

+187
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
* [功能介绍](#功能介绍)
77
* [效果图与示例 apk](#效果图与示例-apk)
8+
* [常见问题](#常见问题)
89
* [使用](#使用)
910
* [自定义属性说明](#自定义属性说明)
1011
* [关于我](#关于我)
@@ -32,6 +33,11 @@
3233

3334
![BGABannerDemo apk文件二维](http://7xk9dj.com1.z0.glb.clouddn.com/banner/BGABannerDemo.png)
3435

36+
## 常见问题
37+
38+
1. 结合 Fresco 加载图片请参考 [FrescoDemoActivity](https://github.com/bingoogolapple/BGABanner-Android/blob/master/demo/src/main/java/cn/bingoogolapple/bgabanner/demo/ui/activity/FrescoDemoActivity.java)
39+
2. 自定义 item 布局文件请参考 [FrescoDemoActivity](https://github.com/bingoogolapple/BGABanner-Android/blob/master/demo/src/main/java/cn/bingoogolapple/bgabanner/demo/ui/activity/FrescoDemoActivity.java)
40+
3541
## 使用
3642

3743
### 1.添加 Gradle 依赖

demo/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies {
1616
// compile project(':library')
1717

1818
// -------------------- 以下两个库是必须依赖的 ----------------------------
19-
compile 'cn.bingoogolapple:bga-banner:2.1.4@aar'
19+
compile 'cn.bingoogolapple:bga-banner:2.1.5@aar'
2020
compile 'com.android.support:support-v4:25.0.1'
2121
// -------------------- 以上两个库是必须依赖的 ----------------------------
2222

@@ -27,4 +27,6 @@ dependencies {
2727
compile 'com.squareup.retrofit2:retrofit:2.1.0'
2828
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
2929
compile 'cn.bingoogolapple:bga-adapter:1.1.5@aar'
30+
31+
compile 'com.facebook.fresco:fresco:0.14.1'
3032
}

demo/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
android:name=".ui.activity.RecyclerViewDemoActivity"
3434
android:screenOrientation="portrait"/>
3535

36+
<activity
37+
android:name=".ui.activity.FrescoDemoActivity"
38+
android:screenOrientation="portrait"/>
3639
</application>
3740

3841
</manifest>

demo/src/main/java/cn/bingoogolapple/bgabanner/demo/App.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.app.Application;
44

5+
import com.facebook.drawee.backends.pipeline.Fresco;
6+
57
import cn.bingoogolapple.bgabanner.demo.engine.Engine;
68
import retrofit2.Retrofit;
79
import retrofit2.converter.gson.GsonConverterFactory;
@@ -24,6 +26,8 @@ public void onCreate() {
2426
.baseUrl("http://7xk9dj.com1.z0.glb.clouddn.com/banner/api/")
2527
.addConverterFactory(GsonConverterFactory.create())
2628
.build().create(Engine.class);
29+
30+
Fresco.initialize(this);
2731
}
2832

2933

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package cn.bingoogolapple.bgabanner.demo.ui.activity;
2+
3+
import android.net.Uri;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.widget.Toast;
8+
9+
import com.facebook.drawee.view.SimpleDraweeView;
10+
11+
import cn.bingoogolapple.bgabanner.BGABanner;
12+
import cn.bingoogolapple.bgabanner.demo.App;
13+
import cn.bingoogolapple.bgabanner.demo.R;
14+
import cn.bingoogolapple.bgabanner.demo.model.BannerModel;
15+
import retrofit2.Call;
16+
import retrofit2.Callback;
17+
import retrofit2.Response;
18+
19+
/**
20+
* 作者:王浩 邮件:bingoogolapple@gmail.com
21+
* 创建时间:16/12/12 下午10:37
22+
* 描述:
23+
*/
24+
public class FrescoDemoActivity extends AppCompatActivity {
25+
private BGABanner mContentBanner;
26+
27+
@Override
28+
protected void onCreate(@Nullable Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_fresco_demo);
31+
32+
mContentBanner = (BGABanner) findViewById(R.id.banner_fresco_demo_content);
33+
mContentBanner.setDelegate(new BGABanner.Delegate<SimpleDraweeView, String>() {
34+
@Override
35+
public void onBannerItemClick(BGABanner banner, SimpleDraweeView itemView, String model, int position) {
36+
Toast.makeText(banner.getContext(), "点击了第" + (position + 1) + "页", Toast.LENGTH_SHORT).show();
37+
}
38+
});
39+
mContentBanner.setAdapter(new BGABanner.Adapter<SimpleDraweeView, String>() {
40+
@Override
41+
public void fillBannerItem(BGABanner banner, SimpleDraweeView itemView, String model, int position) {
42+
itemView.setImageURI(Uri.parse(model));
43+
}
44+
});
45+
46+
App.getInstance().getEngine().fetchItemsWithItemCount(5).enqueue(new Callback<BannerModel>() {
47+
@Override
48+
public void onResponse(Call<BannerModel> call, Response<BannerModel> response) {
49+
BannerModel bannerModel = response.body();
50+
mContentBanner.setData(R.layout.item_fresco, bannerModel.imgs, bannerModel.tips);
51+
}
52+
53+
@Override
54+
public void onFailure(Call<BannerModel> call, Throwable t) {
55+
Toast.makeText(App.getInstance(), "网络数据加载失败", Toast.LENGTH_SHORT).show();
56+
}
57+
});
58+
}
59+
60+
}

demo/src/main/java/cn/bingoogolapple/bgabanner/demo/ui/activity/MainActivity.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ private void loadData() {
8686
loadData(mDepthBanner, 5);
8787
}
8888

89-
private void loadData(final BGABanner banner, int count) {
89+
private void loadData(final BGABanner banner, final int count) {
9090
mEngine.fetchItemsWithItemCount(count).enqueue(new Callback<BannerModel>() {
9191
@Override
9292
public void onResponse(Call<BannerModel> call, Response<BannerModel> response) {
9393
BannerModel bannerModel = response.body();
9494

95+
/**
96+
* 设置是否开启自动轮播,需要在 setData 方法之前调用,并且调了该方法后必须再调用一次 setData 方法
97+
* 例如根据图片当图片数量大于 1 时开启自动轮播,等于 1 时不开启自动轮播
98+
*/
99+
// banner.setAutoPlayAble(bannerModel.imgs.size() > 1);
100+
95101
banner.setAdapter(MainActivity.this);
96102
banner.setData(bannerModel.imgs, bannerModel.tips);
97103
}
@@ -130,6 +136,28 @@ public void onClick(View v) {
130136
case R.id.tv_main_gone:
131137
mDefaultBanner.setVisibility(View.GONE);
132138
break;
139+
case R.id.tv_main_enable_auto_play:
140+
/**
141+
* 设置是否开启自动轮播,需要在 setData 方法之前调用,并且调了该方法后必须再调用一次 setData 方法
142+
* 例如根据图片当图片数量大于 1 时开启自动轮播,等于 1 时不开启自动轮播
143+
*/
144+
mDefaultBanner.setAutoPlayAble(true);
145+
break;
146+
case R.id.tv_main_disable_auto_play:
147+
/**
148+
* 设置是否开启自动轮播,需要在 setData 方法之前调用,并且调了该方法后必须再调用一次 setData 方法
149+
* 例如根据图片当图片数量大于 1 时开启自动轮播,等于 1 时不开启自动轮播
150+
*/
151+
mDefaultBanner.setAutoPlayAble(false);
152+
break;
153+
case R.id.tv_main_start_auto_play:
154+
// 仅在 autoPlayAble 为 true 时才会生效「开发者使用该库时不用调用该方法,这里只是为了演示而已,界面可见时在 BGABanner 内部已经帮开发者调用了该方方法」
155+
mDefaultBanner.startAutoPlay();
156+
break;
157+
case R.id.tv_main_stop_auto_play:
158+
// 仅在 autoPlayAble 为 true 时才会生效「开发者使用该库时不用调用该方法,这里只是为了演示而已,界面不可见时在 BGABanner 内部已经帮开发者调用了该方方法」
159+
mDefaultBanner.stopAutoPlay();
160+
break;
133161
case R.id.tv_main_select_page_one:
134162
mDefaultBanner.setCurrentItem(0);
135163
break;
@@ -184,6 +212,10 @@ public void onClick(View v) {
184212
case R.id.tv_main_recyclerview_demo:
185213
startActivity(new Intent(this, RecyclerViewDemoActivity.class));
186214
break;
215+
case R.id.tv_main_fresco:
216+
startActivity(new Intent(this, FrescoDemoActivity.class));
217+
break;
218+
187219
default:
188220
break;
189221
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
style="@style/MatchMatch.Vertical">
5+
6+
<cn.bingoogolapple.bgabanner.BGABanner
7+
android:id="@+id/banner_fresco_demo_content"
8+
style="@style/BannerDefaultStyle"
9+
app:banner_indicatorGravity="bottom|right"
10+
app:banner_isNeedShowIndicatorOnOnlyOnePage="true"
11+
app:banner_isNumberIndicator="true"
12+
app:banner_numberIndicatorBackground="@drawable/shape_number_indicator_background"
13+
app:banner_numberIndicatorTextColor="@android:color/white"
14+
app:banner_numberIndicatorTextSize="10sp"
15+
app:banner_pointAutoPlayAble="true"
16+
app:banner_pointContainerBackground="@android:color/transparent"
17+
app:banner_transitionEffect="defaultEffect"/>
18+
</LinearLayout>

demo/src/main/res/layout/activity_main.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
android:textColor="@android:color/white"
3535
android:textSize="14dp"/>
3636

37+
<TextView
38+
android:id="@+id/tv_main_fresco"
39+
android:layout_width="match_parent"
40+
android:layout_height="wrap_content"
41+
android:layout_margin="10dp"
42+
android:background="@drawable/selector_btn_test"
43+
android:clickable="true"
44+
android:gravity="center"
45+
android:onClick="onClick"
46+
android:padding="10dp"
47+
android:text="Fresco Demo"
48+
android:textColor="@android:color/white"
49+
android:textSize="14dp"/>
50+
3751
<LinearLayout style="@style/MatchWrap.Horizontal">
3852

3953
<TextView
@@ -52,6 +66,29 @@
5266
android:text="gone"/>
5367
</LinearLayout>
5468

69+
<LinearLayout style="@style/MatchWrap.Horizontal">
70+
71+
<TextView
72+
android:id="@+id/tv_main_enable_auto_play"
73+
style="@style/AutoWrapTv"
74+
android:text="EnableAutoPlay"/>
75+
76+
<TextView
77+
android:id="@+id/tv_main_disable_auto_play"
78+
style="@style/AutoWrapTv"
79+
android:text="DisableAutoPlay"/>
80+
81+
<TextView
82+
android:id="@+id/tv_main_start_auto_play"
83+
style="@style/AutoWrapTv"
84+
android:text="StartAutoPlay"/>
85+
86+
<TextView
87+
android:id="@+id/tv_main_stop_auto_play"
88+
style="@style/AutoWrapTv"
89+
android:text="StopAutoPlay"/>
90+
</LinearLayout>
91+
5592
<LinearLayout style="@style/MatchWrap.Horizontal">
5693

5794
<TextView
@@ -150,6 +187,7 @@
150187
app:banner_numberIndicatorBackground="@drawable/shape_number_indicator_background"
151188
app:banner_numberIndicatorTextColor="@android:color/white"
152189
app:banner_numberIndicatorTextSize="10sp"
190+
app:banner_pointAutoPlayAble="true"
153191
app:banner_pointContainerBackground="@android:color/transparent"
154192
app:banner_transitionEffect="defaultEffect"/>
155193

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.facebook.drawee.view.SimpleDraweeView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="match_parent"
6+
android:layout_height="100dp"
7+
app:placeholderImage="@drawable/holder"/>

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ ANDROID_BUILD_TARGET_SDK_VERSION=25
33
ANDROID_BUILD_SDK_VERSION=25
44
ANDROID_BUILD_TOOLS_VERSION=25.0.0
55

6-
VERSION_NAME=2.1.4
7-
VERSION_CODE=214
6+
VERSION_NAME=2.1.5
7+
VERSION_CODE=215

0 commit comments

Comments
 (0)