Skip to content

Commit ef8153a

Browse files
committed
add autoscroll
1 parent f011871 commit ef8153a

7 files changed

Lines changed: 268 additions & 93 deletions

File tree

demo/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ dependencies {
2929
implementation 'com.makeramen:roundedimageview:2.3.0'
3030
implementation 'com.google.code.gson:gson:2.8.5'
3131
implementation "androidx.viewpager:viewpager:${androidx}"
32+
implementation 'com.facebook.fresco:fresco:1.11.0'
3233
implementation project(':library')
3334
}

demo/src/main/java/com/uis/stackview/demo/activity/MainActivity.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Intent;
44
import android.net.Uri;
5+
import android.os.AsyncTask;
56
import android.os.Bundle;
67
import android.util.Log;
78
import android.view.LayoutInflater;
@@ -10,6 +11,16 @@
1011
import android.widget.Toast;
1112

1213
import com.bumptech.glide.Glide;
14+
import com.facebook.drawee.backends.pipeline.Fresco;
15+
import com.facebook.drawee.backends.pipeline.PipelineDraweeController;
16+
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
17+
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerFactory;
18+
import com.facebook.drawee.interfaces.DraweeController;
19+
import com.facebook.imagepipeline.core.ImagePipeline;
20+
import com.facebook.imagepipeline.core.ImagePipelineConfig;
21+
import com.facebook.imagepipeline.core.ImagePipelineFactory;
22+
import com.facebook.imagepipeline.request.ImageRequest;
23+
import com.facebook.imagepipeline.request.ImageRequestBuilder;
1324
import com.google.gson.Gson;
1425
import com.uis.stackview.StackLayout;
1526
import com.uis.stackview.demo.R;
@@ -35,6 +46,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
3546
protected void onCreate(Bundle savedInstanceState) {
3647
super.onCreate(savedInstanceState);
3748
setContentView(R.layout.activity_main);
49+
if(!Fresco.hasBeenInitialized()) {
50+
ImagePipelineConfig config = ImagePipelineConfig.newBuilder(getApplicationContext())
51+
.setDiskCacheEnabled(true)
52+
.setDownsampleEnabled(true)
53+
.build();
54+
Fresco.initialize(getApplicationContext(), config);
55+
}
3856
recyclerView = findViewById(R.id.recyclerView);
3957
stackViewLayout = findViewById(R.id.stacklayout);
4058
findViewById(R.id.bt_web).setOnClickListener(this);
@@ -43,24 +61,30 @@ protected void onCreate(Bundle savedInstanceState) {
4361
dataList = StackAdapter.initDataList(this);
4462

4563
recyclerView.setLayoutManager(new LinearLayoutManager(this));
46-
//recyclerView.setAdapter(new StackAdapter());
64+
recyclerView.setAdapter(new StackAdapter());
65+
stackViewLayout.setStackLooper(false);
4766
stackViewLayout.setAdapter(new StackLayout.StackAdapter() {
4867
@Override
4968
public View onCreateView(ViewGroup parent) {
50-
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,null);
69+
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fresco_layout,null);
5170
}
5271

5372
@Override
5473
public void onBindView(View view, int position) {
5574
StackAdapter.ViewHolder viewHolder = (StackAdapter.ViewHolder) view.getTag();
5675
if (viewHolder == null) {
5776
viewHolder = new StackAdapter.ViewHolder();
58-
viewHolder.imageView = view.findViewById(R.id.imageView);
77+
viewHolder.dv = view.findViewById(R.id.imageView);
5978
view.setTag(viewHolder);
6079
}
6180
Log.e("xx","binderVH: " + position + ",data: " + new Gson().toJson(dataList.get(position)));
62-
Glide.with(view.getContext())
63-
.load(dataList.get(position).getCoverImageUrl()).into(viewHolder.imageView);
81+
DraweeController controller = Fresco.newDraweeControllerBuilder()
82+
83+
.setUri(Uri.parse(dataList.get(position).getCoverImageUrl()))
84+
.setTapToRetryEnabled(true)
85+
.setOldController(viewHolder.dv.getController())
86+
.build();
87+
viewHolder.dv.setController(controller);
6488
}
6589

6690
@Override
@@ -70,7 +94,13 @@ public int getItemCount() {
7094

7195
@Override
7296
public void onItemDisplay(int position) {
97+
Log.e("xx","display = " + position);
98+
}
7399

100+
@Override
101+
public void onItemClicked(int position) {
102+
Log.e("xx","clicked = " + position);
103+
stackViewLayout.setStackLooper(false);
74104
}
75105
});
76106
}

demo/src/main/java/com/uis/stackview/demo/activity/StackAdapter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.widget.Toast;
99

1010
import com.bumptech.glide.Glide;
11+
import com.facebook.drawee.view.SimpleDraweeView;
1112
import com.uis.stackview.demo.R;
1213
import com.uis.stackview.demo.entity.ItemEntity;
1314
import com.uis.stackview.StackLayout;
@@ -46,7 +47,7 @@ public int getItemViewType(int position) {
4647

4748
@Override
4849
public int getItemCount() {
49-
return 1;
50+
return 10;
5051
}
5152

5253
public static ArrayList<ItemEntity> initDataList(Context context) {
@@ -77,6 +78,7 @@ public static ArrayList<ItemEntity> initDataList(Context context) {
7778

7879
public static class ViewHolder {
7980
ImageView imageView;
81+
SimpleDraweeView dv;
8082
}
8183

8284
static class StackVH extends RecyclerView.ViewHolder{
@@ -104,6 +106,7 @@ public void onBindView(View view, int position) {
104106
view.setTag(viewHolder);
105107
}
106108
//Log.e("xx","binderVH: " + position + ",data: " + new Gson().toJson(dataList.get(position)));
109+
if(itemView.getContext() != null)
107110
Glide.with(itemView.getContext())
108111
.load(dataList.get(position).getCoverImageUrl()).into(viewHolder.imageView);
109112
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:background="@drawable/default_back"
6+
android:layout_height="match_parent"
7+
>
8+
<com.facebook.drawee.view.SimpleDraweeView
9+
android:id="@+id/imageView"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
app:actualImageScaleType="focusCrop"
13+
app:roundedCornerRadius="5dp" />
14+
15+
<ImageView
16+
android:layout_width="22dp"
17+
android:layout_height="22dp"
18+
android:layout_gravity="center"
19+
android:src="@drawable/play"
20+
/>
21+
22+
</FrameLayout>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
android:id="@+id/stacklayout"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7-
stack:stackSpace="10dp"
7+
stack:stackSpace="5dp"
88
stack:stackEdge="20dp"
99
stack:stackZoom="0.08"
10-
stack:stackLooper = "true"
11-
stack:stackSize = "15"
10+
stack:stackLooper = "false"
11+
stack:stackSize = "5"
1212
stack:stackEdgeModel = "left">
1313
</com.uis.stackview.StackLayout>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
77
stack:stackSpace="10dp"
8-
stack:stackEdge="20dp"
9-
stack:stackZoom="0.08"
10-
stack:stackLooper = "true"
11-
stack:stackSize = "12"
8+
stack:stackEdge="10dp"
9+
stack:stackZoom="0.1"
10+
stack:stackLooper = "false"
11+
stack:stackSize = "3"
1212
stack:stackEdgeModel = "right">
1313
</com.uis.stackview.StackLayout>

0 commit comments

Comments
 (0)