Skip to content

Commit

Permalink
修改demo,增加一些使用例子!
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Dec 9, 2016
1 parent cf3909a commit 92ff61a
Show file tree
Hide file tree
Showing 28 changed files with 566 additions and 325 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
/**
常用的图片加载库:
Universal Image Loader:一个强大的图片加载库,包含各种各样的配置,最老牌,使用也最广泛。
Picasso: Square出品,必属精品。和OkHttp搭配起来更配呦!
Volley ImageLoader:Google官方出品,可惜不能加载本地图片~
Fresco:Facebook出的,天生骄傲!不是一般的强大。
Glide:Google推荐的图片加载库,专注于流畅的滚动。
注意:
1.图片加载器由自己选择,这里不限制,只是提供几种使用方法
2.返回的图片路径为Object类型,由于不能确定你到底使用的那种图片加载器,
传输的到的是什么格式,那么这种就使用Object接收和返回,你只需要强转成你传输的类型就行,
切记不要胡乱强转!
*/

eg:

//Glide 加载图片简单用法
Glide.with(context).load(path).into(imageView);

Expand All @@ -162,6 +162,7 @@ public class GlideImageLoader extends ImageLoader {
Uri uri = Uri.parse((String) path);
imageView.setImageURI(uri);
}

//提供createImageView 方法,如果不用可以不重写这个方法,方便fresco自定义ImageView
@Override
public ImageView createImageView(Context context) {
Expand Down
32 changes: 23 additions & 9 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,22 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/drawee/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/fbcore/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/fresco/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline-base/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.zxy.android/recovery/0.0.8/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
Expand All @@ -110,22 +116,30 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-media-compat-24.2.0" level="project" />
<orderEntry type="library" exported="" name="imagepipeline-0.12.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="support-compat-24.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-24.2.0" level="project" />
<orderEntry type="library" exported="" name="recovery-0.0.8" level="project" />
<orderEntry type="library" exported="" name="imagepipeline-base-0.12.0" level="project" />
<orderEntry type="library" exported="" name="drawee-0.12.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-24.2.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-24.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-24.2.0" level="project" />
<orderEntry type="library" exported="" name="fresco-0.12.0" level="project" />
<orderEntry type="library" exported="" name="support-fragment-24.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-24.2.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-24.2.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-24.2.0" level="project" />
<orderEntry type="library" exported="" name="bolts-tasks-1.4.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.7.0" level="project" />
<orderEntry type="library" exported="" name="fbcore-0.12.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
<orderEntry type="module" module-name="banner-banner" exported="" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
compile 'com.android.support:recyclerview-v7:23+'
compile "com.github.bumptech.glide:glide:3.7.0"
compile 'com.facebook.fresco:fresco:0.12.0'
compile 'com.zxy.android:recovery:0.0.8'
compile project(':banner')
// compile 'com.youth.banner:banner:+'
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.test.banner">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_TASKS" />

<application
android:name=".App"
Expand All @@ -19,7 +20,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".demo.BannerAnimationActivity" />
<activity android:name=".demo.BannerStyleActivity" />
<activity android:name=".demo.IndicatorPositionActivity" />
<activity android:name=".demo.CustomBannerActivity"></activity>
</application>

</manifest>
26 changes: 25 additions & 1 deletion app/src/main/java/com/test/banner/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.zxy.recovery.core.Recovery;

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


public class App extends Application {
public static List<?> images=new ArrayList<>();
public static List<String> titles=new ArrayList<>();
public static int H;
@Override
public void onCreate() {
super.onCreate();
H=getScreenH(this);
Fresco.initialize(this);

Recovery.getInstance()
.debug(true)
.recoverInBackground(false)
.recoverStack(true)
.mainPage(MainActivity.class)
.init(this);
String[] urls = getResources().getStringArray(R.array.url4);
String[] tips = getResources().getStringArray(R.array.title);
List list = Arrays.asList(urls);
images = new ArrayList(list);
titles= Arrays.asList(tips);
}
public int getScreenH(Context aty) {
DisplayMetrics dm = aty.getResources().getDisplayMetrics();
return dm.heightPixels;
}
}
112 changes: 44 additions & 68 deletions app/src/main/java/com/test/banner/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package com.test.banner;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.test.banner.common.BaseRecyclerAdapter;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;

import com.test.banner.demo.BannerAnimationActivity;
import com.test.banner.demo.BannerStyleActivity;
import com.test.banner.demo.CustomBannerActivity;
import com.test.banner.demo.IndicatorPositionActivity;
import com.test.banner.loader.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerClickListener;

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


public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, OnBannerClickListener {
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener {
static final int REFRESH_COMPLETE = 0X1112;
SwipeRefreshLayout mSwipeLayout;
RecyclerView recyclerView;
ListView listView;
Banner banner;
String[] images, titles;

private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case REFRESH_COMPLETE:
images = getResources().getStringArray(R.array.url4);
List list = Arrays.asList(images);
String[] urls = getResources().getStringArray(R.array.url);
List list = Arrays.asList(urls);
List arrayList = new ArrayList(list);
banner.update(arrayList);
mSwipeLayout.setRefreshing(false);
Expand All @@ -49,64 +49,27 @@ public void handleMessage(android.os.Message msg) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
images = getResources().getStringArray(R.array.url);
titles = getResources().getStringArray(R.array.title);
List list = Arrays.asList(images);
List arrayList = new ArrayList(list);

mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
mSwipeLayout.setOnRefreshListener(this);

recyclerView= (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
BaseRecyclerAdapter adapter = new BaseRecyclerAdapter<>(new SampleAdapter());

/**
* 将banner添加到recyclerView头部
*/
listView= (ListView) findViewById(R.id.list);
View header= LayoutInflater.from(this).inflate(R.layout.header,null);

banner = (Banner) header.findViewById(R.id.banner);
//如果你不需要用xml的属性,那么也可以直接创建对象来实现
// banner=new Banner(this);

//设置轮播图宽度和高度,建议最好按照图片的比例设置,效果更好
banner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,getScreenH(this)/3));
adapter.addHeader(banner);
recyclerView.setAdapter(adapter);
banner.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,App.H/4));
listView.addHeaderView(banner);
String[] data=getResources().getStringArray(R.array.demo_list);
listView.setAdapter(new SampleAdapter(this,data));
listView.setOnItemClickListener(this);

//简单使用
// banner.setImages(arrayList).setImageLoader(new FrescoImageLoader()).start();

//设置banner样式
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//设置图片加载器
banner.setImageLoader(new GlideImageLoader());
//设置图片集合
banner.setImages(arrayList);
//设置banner动画效果
banner.setBannerAnimation(Transformer.ZoomOut);
//设置标题集合(当banner样式有显示title时)
banner.setBannerTitles(Arrays.asList(titles));
//设置自动轮播,默认为true
banner.isAutoPlay(true);
//设置轮播时间
banner.setDelayTime(3000);
//设置指示器位置(当banner模式中有指示器时)
banner.setIndicatorGravity(BannerConfig.CENTER);
//设置点击事件
banner.setOnBannerClickListener(this);
//banner设置方法全部调用完毕时最后调用
banner.start();
banner.setImages(App.images)
.setImageLoader(new GlideImageLoader())
.start();

}

@Override
public void OnBannerClick(int position) {
Toast.makeText(getApplicationContext(), "点击:" + position, Toast.LENGTH_SHORT).show();
Log.e("--",position+"");
}



//如果你需要考虑更好的体验,可以这么操作
@Override
protected void onStart() {
Expand All @@ -122,14 +85,27 @@ protected void onStop() {
banner.stopAutoPlay();
}


@Override
public void onRefresh() {
mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000);
}
public int getScreenH(Context aty) {
DisplayMetrics dm = aty.getResources().getDisplayMetrics();
return dm.heightPixels;
}


@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 1:
startActivity(new Intent(this, BannerAnimationActivity.class));
break;
case 2:
startActivity(new Intent(this, BannerStyleActivity.class));
break;
case 3:
startActivity(new Intent(this, IndicatorPositionActivity.class));
break;
case 4:
startActivity(new Intent(this, CustomBannerActivity.class));
break;
}
}
}
Loading

0 comments on commit 92ff61a

Please sign in to comment.