Skip to content

Commit

Permalink
添加MultiImageView
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfusheng committed Jun 19, 2018
1 parent da857de commit 6f87684
Show file tree
Hide file tree
Showing 33 changed files with 630 additions and 716 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
26 changes: 6 additions & 20 deletions GlideImageView/src/main/java/com/sunfusheng/GlideImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.sunfusheng.progress.GlideApp;
import com.sunfusheng.progress.GlideRequest;
import com.sunfusheng.progress.OnProgressListener;
Expand Down Expand Up @@ -68,12 +63,15 @@ public GlideImageLoader load(@DrawableRes int resId, @DrawableRes int placeholde
return loadImage(resId2Uri(resId), placeholder, transformation);
}

protected GlideImageLoader loadImage(Object obj, @DrawableRes int placeholder, Transformation<Bitmap> transformation) {
protected GlideRequest<Drawable> loadImage(Object obj) {
if (obj instanceof String) {
url = (String) obj;
}
return GlideApp.with(getContext()).load(obj);
}

GlideRequest<Drawable> glideRequest = GlideApp.with(getContext()).load(obj);
protected GlideImageLoader loadImage(Object obj, @DrawableRes int placeholder, Transformation<Bitmap> transformation) {
GlideRequest<Drawable> glideRequest = loadImage(obj);
if (placeholder != 0) {
glideRequest = glideRequest.placeholder(placeholder).error(placeholder);
}
Expand All @@ -82,19 +80,7 @@ protected GlideImageLoader loadImage(Object obj, @DrawableRes int placeholder, T
glideRequest = glideRequest.transform(transformation);
}

// glideRequest = glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true);

glideRequest.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(getImageView());
glideRequest.into(getImageView());
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion Sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:name=".about.AboutActivity"
android:theme="@style/AboutTheme"/>

<activity android:name=".NineImageViewActivity"/>
<activity android:name=".MultiImageViewActivity"/>

<activity android:name=".RecyclerViewActivity"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {
draggableView1 = findViewById(R.id.draggableView1);
draggableView2 = findViewById(R.id.draggableView2);
draggableView1.setOnClickListener(v -> startActivity(new Intent(mContext, RecyclerViewActivity.class)));
draggableView2.setOnClickListener(v -> startActivity(new Intent(mContext, NineImageViewActivity.class)));
draggableView2.setOnClickListener(v -> startActivity(new Intent(mContext, MultiImageViewActivity.class)));

image31.setOnClickListener(v -> {
Intent intent = new Intent(MainActivity.this, SingleImageActivity.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.sunfusheng.glideimageview.sample;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunfusheng.glideimageview.sample.model.ImageModel;
import com.sunfusheng.glideimageview.sample.model.ModelUtil;
import com.sunfusheng.glideimageview.sample.widget.MultiImageView.GridLayoutHelper;
import com.sunfusheng.glideimageview.sample.widget.MultiImageView.ImageData;
import com.sunfusheng.glideimageview.sample.widget.MultiImageView.MultiImageView;
import com.sunfusheng.util.DisplayUtil;

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

public class MultiImageViewActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_recyclerview);

RecyclerView recyclerView = findViewById(R.id.recycleView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, ModelUtil.getImages());
recyclerView.setAdapter(adapter);
}

class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

private List<ImageModel> list;

private int margin;
private int maxImgWidth;
private int maxImgHeight;
private int cellWidth;
private int cellHeight;
private int minImgWidth;
private int minImgHeight;

RecyclerViewAdapter(Context context, List<ImageModel> list) {
this.list = list;
margin = DisplayUtil.dp2px(context, 3);
maxImgHeight = maxImgWidth = DisplayUtil.getWindowWidth(context) - DisplayUtil.dp2px(context, 16) * 2;
cellHeight = cellWidth = (maxImgWidth - margin * 3) / 3;
minImgHeight = minImgWidth = cellWidth;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_multiimageview, viewGroup, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
ImageModel model = list.get(position);

viewHolder.vDesc.setText(model.desc);

List<ImageData> list = new ArrayList<>();
int size = 0;
for (String url : model.images) {
list.add(new ImageData(url));
size++;
if (size >= 9) break;
}

viewHolder.multiImageView.setData(list, getLayoutHelper(list));
}

private GridLayoutHelper getLayoutHelper(List<ImageData> list) {
int imageCount = list != null ? list.size() : 0;
if (imageCount > 3) {
imageCount = (int) Math.ceil(Math.sqrt(imageCount));
}
return new GridLayoutHelper(imageCount, cellWidth, cellHeight, margin);
}

@Override
public int getItemCount() {
return list.size();
}

class ViewHolder extends RecyclerView.ViewHolder {
TextView vDesc;
MultiImageView multiImageView;

ViewHolder(View view) {
super(view);
vDesc = view.findViewById(R.id.desc);
multiImageView = view.findViewById(R.id.multiImageView);
}
}
}
}

This file was deleted.

Loading

0 comments on commit 6f87684

Please sign in to comment.