Skip to content

Commit

Permalink
测试
Browse files Browse the repository at this point in the history
  • Loading branch information
hss committed Nov 7, 2019
1 parent 184975c commit b94973c
Show file tree
Hide file tree
Showing 12 changed files with 435 additions and 52 deletions.
12 changes: 8 additions & 4 deletions app/src/main/java/com/hss01248/imageloaderdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.RequestListener;
Expand All @@ -38,6 +39,7 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifDrawable;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -150,11 +152,13 @@ public void onFail(Throwable e) {


Glide.with(MainActivity.this)
.load("https://img.zcool.cn/community/01f1bc58413d49a8012060c80de125.gif")
.asGif()
// .load("http://img3.ynet.com/2018/03/22/071135542b5deabc409e36af01290c89_600x-_90.jpg")
.load("https://c-ssl.duitang.com/uploads/blog/201407/04/20140704234425_j5zHS.thumb.700_0.gif")
// .asGif()
//.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE);
//.into(ivUrl);
.bitmapTransform(new RoundedCornersTransformation(this,30,0))
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(ivUrl);
/* .listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.hss01248.adapter.SuperRvAdapter;
import com.hss01248.adapter.SuperRvHolder;
import com.hss01248.dialog.adapter.SuperRcvAdapter;
import com.hss01248.dialog.adapter.SuperRcvHolder;
import com.hss01248.image.ImageLoader;
import com.hss01248.image.config.ScaleMode;
import com.hss01248.imageloaderdemo.multi.RcvHolder;

import java.util.ArrayList;
Expand All @@ -32,12 +34,19 @@ public class RecycleViewActy extends Activity {
List<String> datas ;
int oldScrollState;

ImageView iv1,iv2,iv3,iv4;

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

recyclerView = (RecyclerView) findViewById(R.id.recy);
iv1 = findViewById(R.id.iv_1);
iv2 = findViewById(R.id.iv_2);
iv3 = findViewById(R.id.iv_3);
iv4 = findViewById(R.id.iv_4);

datas = new ArrayList<>();
addDatas();

Expand Down Expand Up @@ -71,10 +80,14 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
}
});

setIv();
}




private void setIv() {
ImageLoader.with(this)
.url("http://www.cingjing.gov.tw/upload/grass_b/0898a3792067e612b0a87f3c5058dae6.jpg")
.scale(ScaleMode.CENTER_CROP)
.into(iv1);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RcvHolder extends SuperRvHolder<String,Activity> {
private int columnNumber;
//private RoundedImageView roundedImageView2;
private ImageLoaderRoundImageView roundImageView;
private RoundImageView roundImageView3;
private ImageView roundImageView3;
public RcvHolder(View itemView) {
super(itemView);
this.rootView = itemView;
Expand Down Expand Up @@ -91,19 +91,25 @@ public void assignDatasAndEvents(Activity context, final String data, int positi

//loadByGlide(context,data,position);

roundImageView.setCornerRadius(20,20,0,0);
//roundImageView.setCornerRadius(20,20,0,0);
//roundImageView.setBorderWidth(2);
//roundImageView.setBorderColor(Color.BLUE);
if(position == 3){
//Debug.startMethodTracing("imageloader");
}
ImageLoader.with(context)
//.widthHeightByPx(360,360)
.url(data)
//.scale(ScaleMode.CENTER_CROP)
//.rectRoundCorner(10,Color.WHITE)
//.blur(2)
.defaultErrorRes(true)
//.loading(R.drawable.iv_loading_trans)
.placeHolder(R.color.colorAccent)
.into(roundImageView);

.into(roundImageView3);
if(position == 3){
//Debug.stopMethodTracing();
}
/* ImageLoader.with(context)
//.widthHeightByPx(360,360)
.url(data+"?t=4")
Expand All @@ -113,14 +119,14 @@ public void assignDatasAndEvents(Activity context, final String data, int positi
.loading(R.drawable.iv_loading_trans)
.into(roundedImageView2);*/

ImageLoader.with(context)
/*ImageLoader.with(context)
//.widthHeightByPx(360,360)
.url(data+"?t=5")
//.scale(ScaleMode.CENTER_CROP)
//.blur(2)
.defaultErrorRes(true)
.loading(R.drawable.iv_loading_trans)
.into(roundImageView3);
.into(roundImageView);*/

/*.asBitmap(new SingleConfig.BitmapListener() {
@Override
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@

<ImageView
android:id="@+id/iv_url"
android:layout_width="250dp"
android:layout_width="50dp"
android:layout_marginBottom="20dp"
android:layout_height="150dp" />
android:background="@drawable/shape_main_list_bg"
android:layout_height="50dp" />
<ImageView
android:id="@+id/iv_file"
android:layout_width="250dp"
Expand Down
38 changes: 37 additions & 1 deletion app/src/main/res/layout/acty_recycle_list.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="gone"
android:layout_height="0dp">
<LinearLayout
android:orientation="vertical"
android:padding="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_1"
android:background="@drawable/shape_main_list_bg"
android:layout_width="150dp"
android:layout_height="150dp" />
<ImageView
android:id="@+id/iv_2"
android:background="@drawable/shape_main_list_bg"
android:layout_width="match_parent"
android:layout_height="150dp" />
<ImageView
android:id="@+id/iv_3"
android:background="@drawable/shape_main_list_bg"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:layout_height="150dp" />
<ImageView
android:id="@+id/iv_4"
android:background="@drawable/shape_main_list_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

<android.support.v7.widget.RecyclerView
android:id="@+id/recy"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_weight="2"
android:layout_height="0dp"/>

</LinearLayout>
11 changes: 9 additions & 2 deletions app/src/main/res/layout/item_iv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
android:background="@drawable/shape_main_list_bg"
android:layout_marginBottom="5dp"
android:adjustViewBounds="true"
android:visibility="gone"
android:layout_height="wrap_content">

</com.hss01248.glideloader.ImageLoaderRoundImageView>
<ImageView
android:id="@+id/iv_round3"
android:background="@drawable/shape_main_list_bg"
android:layout_width="match_parent"
android:adjustViewBounds="true"
android:layout_height="wrap_content" />

<!--<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/iv_round2"
Expand All @@ -27,7 +34,7 @@ app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true" />-->

<org.raphets.roundimageview.RoundImageView
<!--<org.raphets.roundimageview.RoundImageView
android:layout_width="match_parent"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
Expand All @@ -39,5 +46,5 @@ app:riv_mutate_background="true" />-->
app:leftTop_corner_radius="30dp"
app:rightBottom_corner_radius="30dp"
app:rightTop_corner_radius="0dp"
app:type="round" />
app:type="round" />-->
</LinearLayout>
Binary file modified glide/src/main/java/com/.DS_Store
Binary file not shown.
40 changes: 24 additions & 16 deletions glide/src/main/java/com/hss01248/glideloader/GlideLoader.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.hss01248.glideloader;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.IntentUtils;
import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.disklrucache.DiskLruCache;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.cache.DiskCache;
import com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
Expand All @@ -26,6 +23,8 @@
import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.view.BigImageView;
import com.hss01248.glideloader.big.GlideBigLoader;
import com.hss01248.glideloader.transform.BlurTransform;
import com.hss01248.glideloader.transform.RoundCornerTransForm;
import com.hss01248.image.ImageLoader;
import com.hss01248.image.MyUtil;
import com.hss01248.image.config.GlobalConfig;
Expand Down Expand Up @@ -68,9 +67,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import jp.wasabeef.glide.transformations.internal.FastBlur;
Expand Down Expand Up @@ -207,14 +204,15 @@ public void onLoadFailed(Exception e, Drawable errorDrawable) {
builder.override(config.getWidth(),config.getHeight());
}
builder = setShapeModeAndBlur(config, builder);

if(config.getErrorResId() >0){
builder.error(config.getErrorResId());
}

if(config.getScaleMode() == ScaleMode.CENTER_CROP){
builder.centerCrop();
}else{
builder.fitCenter();
//builder.fitCenter();
}


Expand Down Expand Up @@ -504,6 +502,22 @@ private void showPop(ImageView v, final SingleConfig config) {

desc += "\n" + MyUtil.printImageView(v);

getFileFromDiskCache(config.getUrl(), new FileGetter() {
@Override
public void onSuccess(File file, int width, int height) {
String text = textView.getText().toString();
text += "\n\ncache file:\n" + file.getAbsolutePath() +"\nsize:"+ MyUtil.formatFileSize(file.length());
text += "\nwh:"+width+"x"+height;
text += "\nexif: todo";
textView.setText(text);
}

@Override
public void onFail(Throwable e) {

}
});



textView.setText(desc);
Expand Down Expand Up @@ -600,7 +614,7 @@ private DrawableRequestBuilder setShapeModeAndBlur(SingleConfig config, Drawable
}

if(config.isNeedBlur()){
transformations.add(new BlurTransform(config.getContext(), config.getBlurRadius()));
transformations.add(new BlurTransform(config.getContext(), config.getBlurRadius(),shapeMode > 0 ? 1: 2));
}


Expand All @@ -613,22 +627,16 @@ private DrawableRequestBuilder setShapeModeAndBlur(SingleConfig config, Drawable
break;
case ShapeMode.RECT_ROUND:
case ShapeMode.RECT_ROUND_ONLY_TOP:
/*if(config.getScaleMode() == ScaleMode.CENTER_CROP){
if(config.getScaleMode() == ScaleMode.CENTER_CROP){
transformations.add(new CenterCrop(config.getContext()));
}*/
}
RoundedCornersTransformation.CornerType cornerType = RoundedCornersTransformation.CornerType.ALL;
if(shapeMode == ShapeMode.RECT_ROUND_ONLY_TOP){
cornerType = RoundedCornersTransformation.CornerType.TOP;
}
transformations.add(new RoundedCornersTransformation(config.getContext(),
config.getRectRoundRadius(), 0, cornerType));

if(config.getBorderWidth()>0){

}
if(config.isGif() && config.getRoundOverlayColor()>0){

}
break;
case ShapeMode.OVAL:
transformations.add( new CropCircleTransformation(config.getContext()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.hss01248.glideloader.transform;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.hss01248.image.MyUtil;
import com.hss01248.image.config.GlobalConfig;

import java.security.PublicKey;

public class BaseTransForm {


public static Bitmap scale(Resource<Bitmap> resource, int outWidth, int outHeight){
Bitmap source = resource.get();

int width = source.getWidth();
int height = source.getHeight();

int samplesize = MyUtil.calculateScaleRatio(width,height,outWidth,outHeight,1);



int scaledWidth = width / samplesize;
int scaledHeight = height / samplesize;

Bitmap bitmap = Glide.get(GlobalConfig.context).getBitmapPool().get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
}

Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) samplesize, 1 / (float) samplesize);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(source, 0, 0, paint);
return bitmap;
}


}
Loading

0 comments on commit b94973c

Please sign in to comment.