The
Glide usage (tool Class) summarized in the project.
public class Glides {public static glides instance = new glides ();
Public glides () {} public static glides getinstance () {return instance; }//load network picture public void load (context context, String URL, ImageView ImageView, Glidedrawableimageviewtarget targe
T) {Glide.with (context). Load (URL). Diskcachestrategy (Diskcachestrategy.all)
. Placeholder (r.color.abc_tab_text_normal). Error (R.color.abc_tab_text_normal)
. Crossfade (). into (target); }//load network picture public void load (context context, Uri Uri, ImageView ImageView, Glidedrawableimageviewtarget target)
{Glide.with (context). Load (URI). Diskcachestrategy (Diskcachestrategy.all) . Placeholder (r.color.abc_tab_text_normal). Error (R.color.abc_tab_text_normal). C
Rossfade (). into (target);}//load network picture public void load (context context, String URL, ImageView ImageView) {glide.with (context) . Load (URL). Placeholder (r.color.abc_tab_text_normal). Error (R.color.abc_tab_te
Xt_normal). Crossfade (). into (ImageView); }//Load network or Local picture public void load (context context, Uri Uri, ImageView ImageView, int defaultimg) {Glide.wi
Th (context). Load (URI). Placeholder (defaultimg). Error (DEFAULTIMG)
. Crossfade (). Centercrop (). into (ImageView); }//load network picture public void load (context context, String URL, ImageView ImageView, int defaultimg) {Glide.wi
Th (context). Load (URL). Placeholder (defaultimg). Error (DEFAULTIMG)
. Crossfade (). Centercrop (). into (ImageView); }
//Load network picture public void Loadfitcenter (context context, String URL, ImageView ImageView, int defaultimg, int width, int Heig HT) {Glide.with (context). Load (URL). Thumbnail (0.8f). Override (WI
DTH, height). Dontanimate (). Placeholder (defaultimg). Error (DEFAULTIMG)
. Fitcenter (). into (ImageView); }//load network picture public void Loadshade (context context, String URL, ImageView ImageView, int defaultimg) {Gli
De.with (context). Load (URL). Placeholder (defaultimg). Error (DEFAULTIMG) . Crossfade (). Bitmaptransform (New Shadetransformation (context)). into (Imagev
Iew); }//load local boot picture public void Loadguide (context context, int resId, ImageView ImageView, int defaultimg) {Gl Ide.with (context). Load (resId). DontaniMate (). Bitmaptransform (New Croptoptransformation (context)). into (ImageView); }//load local boot picture public void Loadguide (context context, int resId, ImageView ImageView, Transformation transformatio N) {glide.with (context). Load (resId). Dontanimate (). bitmaptransf
ORM (Transformation). into (ImageView);
}//Load circular network picture public void loadcircle (context context, String URL, ImageView ImageView, int defaultimg) {
Glide.with (context). Load (URL). Placeholder (defaultimg). Error (DEFAULTIMG) . Crossfade (). Bitmaptransform (New Cropcircletransformation (context)). int
O (ImageView);
} public void Loadcircledefault (context context, ImageView ImageView, int defaultimg) {Glide.with (context)
. Load (defaultimg). Placeholder (defaultimg) . Error (DEFAULTIMG). Crossfade (). Bitmaptransform (New Cropcircletransformation (
context). into (ImageView);
} public void Loadcircle (context context, Uri Uri, ImageView ImageView, int defaultimg) {Glide.with (context) . Load (URI). Placeholder (defaultimg). Error (DEFAULTIMG). b
Itmaptransform (new Cropcircletransformation (context)). Crossfade (). into (ImageView);
}/** * Fillet picture * * @param context * @param URL * @param imageView * @param defaultimg */public void Loadround (context context, String URL, ImageView ImageView, int defaultimg) {Glide.with (cont
EXT). Load (URL). Placeholder (defaultimg). Error (DEFAULTIMG) . Transform (new Centercrop (context), new Glideroundtransform (context)). CROSSFAde (). into (ImageView);
}//Load fillet network picture public void Loadroundcorner (context context, String URL, ImageView ImageView, int radius) { Glide.with (context). Load (URL). Transform (new Centercrop (context), new glideroundtransfor m (context, RADIUS)). Placeholder (R.color.common_image_default). Error (R.color.common_image
_default)//. Crossfade (). into (ImageView); }//Load fillet network picture public void Loadround (context context, String URL, ImageView ImageView, int radius, int defaultimg) {Glide.with (context). Load (URL). Placeholder (defaultimg). Error (
DEFAULTIMG). Transform (new Centercrop (context), new glideroundtransform (context, RADIUS))
. Crossfade (). into (ImageView); }//Load fillet local picture public void Loadroundcorner (context context, int resId, ImageView imageView, int radius) {glide.with (context). Load (resId). Transform (new Centercrop (con
Text), new Glideroundtransform (context, RADIUS)). into (ImageView);
}//load local picture public void load (context context, int resid, ImageView ImageView) {glide.with (context) . Load (RESID). Placeholder (r.color.abc_tab_text_normal). Error (R.color.abc_tab_
Text_normal). Crossfade (). into (ImageView); }//load local picture public void Loaddecor (context context, String URL, ImageView ImageView, int errresid, int width, int Height) {glide.with (context). Load (URL). Asbitmap (). Format (decod eformat.prefer_rgb_565). Diskcachestrategy (Diskcachestrategy.result). Priority (priority.im Mediate). Dontanimate (). Thumbnail (0.1f). Override (WIDTH, height). into (ImageView);
}//Load Sky network picture without setting high public void Loaddecor (context context, String URL, ImageView ImageView, int errresid) { Glide.with (context). Load (URL). Asbitmap (). Format (decodeformat.prefer_r
gb_565). Diskcachestrategy (Diskcachestrategy.result). Priority (Priority.immediate)
. Dontanimate (). into (ImageView); }//load local picture, error or placeholder with transparent public void Loaddecor (context context, int resid, ImageView ImageView, int errresid, int wi DTH, int height) {glide.with (context). Load (resid). Asbitmap (). f Ormat (decodeformat.prefer_rgb_565). Diskcachestrategy (Diskcachestrategy.result). Priority ( priority.immediate). Dontanimate (). Thumbnail (0.1f). Override (width, heigh T). into (ImagevieW);
}//Load Sky picture, error or placeholder with transparent public void Loaddecor (context context, int resid, ImageView ImageView, int errresid) { Glide.with (context). Load (resid). Asbitmap (). Format (decodeformat.pref
er_rgb_565). Diskcachestrategy (Diskcachestrategy.result). Priority (Priority.immediate)
. Dontanimate (). into (ImageView); } public void Loadnoanim (context context, String URI, ImageView ImageView, int placeholder) {Glide.with (con
Text). Load (Uri.parse (Uri)). Placeholder (placeholder). Error (Placeholder)
. Dontanimate ()//color filter error. into (ImageView); }//Load circular local picture public void loadcircle (context context, int resId, ImageView ImageView) {Glide.with (Contex T). Load (resId). Placeholder (R.color.trans). Error (R.coloR.trans). Transform (new Glidecircletransform (context)). Crossfade (). into (
ImageView); }//Load circular network picture public void loadcircle (context context, String URL, ImageView ImageView) {Glide.with (conte
XT). Load (URL). Placeholder (R.color.trans). Error (R.color.trans)
. Transform (new Glidecircletransform (context)). Crossfade (). into (ImageView);
}//Load network picture animation public void Loadanima (context context, String URL, Animation Animation, ImageView ImageView) {
Glide.with (context). Load (URL). Placeholder (r.color.abc_tab_text_normal) . Error (R.color.abc_tab_text_normal). Animate (animation). Crossfade (). I
Nto (ImageView); }//Load network picture animation public void Loadanima (context context, String URL, int animationid, ImageView ImageView){Glide.with (context). Load (URL). Placeholder (r.color.abc_tab_text_normal)
. Error (R.color.abc_tab_text_normal). Animate (Animationid). Crossfade ()
. into (ImageView);
}//load local picture animation public void Loadanima (context context, int resId, Animation Animation, ImageView ImageView) {
Glide.with (context). Load (resId). Placeholder (r.color.abc_tab_text_normal) . Error (R.color.abc_tab_text_normal). Animate (animation). Crossfade ().
Into (ImageView);
}//load drawable picture public void Loadanima (context context, int resId, int animationid, ImageView ImageView) {
Glide.with (context). Load (resId). Placeholder (r.color.abc_tab_text_normal) . Error (R.color.abc_tab_text_normal). Animate (Animationid). CRossfade (). into (ImageView);
}
}
public class Glideroundtransform extends Bitmaptransformation {private static float radius = 0f;
Public Glideroundtransform (Context context) {This (context, 6);
} public Glideroundtransform (context context, int dp) {super (context);
This.radius = Resources.getsystem (). Getdisplaymetrics (). density * DP; } @Override protected Bitmap transform (Bitmappool pool, Bitmap totransform, int outwidth, int outheight) {RE
Turn roundcrop (pool, totransform);
} private static Bitmap Roundcrop (Bitmappool pool, Bitmap source) {if (source = = null) return null;
Bitmap result = Pool.get (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8888); if (result = = null) {result = Bitmap.createbitmap (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8
888);
Canvas canvas = new canvas (result);
Paint paint = new paint (); Paint.setshader (new Bitmapshader (source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
Paint.setantialias (TRUE);
RECTF RECTF = new RECTF (0f, 0f, Source.getwidth (), Source.getheight ());
Canvas.drawroundrect (RECTF, radius, radius, paint);
return result;
} @Override Public String getId () {return getclass (). GetName () + math.round (RADIUS);
}
}
public class Croptoptransformation implements transformation<bitmap> {private Context mcontext;
Private Bitmappool Mbitmappool;
private int mwidth;
private int mheight;
Private Croptransformation.croptype mcroptype = CropTransformation.CropType.CENTER;
Public Croptoptransformation (Context context) {This (Glide.get (context). Getbitmappool ());
Mcontext = context;
} public croptoptransformation (Bitmappool pool) {this.mbitmappool = pool; } @Override Public resource<bitmap> transform (resource<bitmap> Resource, int outwidth, int outheight)
{Bitmap Source = Resource.get ();
float swidth = (float) source.getwidth ();
float sheight = (float) source.getheight ();
float Wscale = outwidth/swidth;
float calculateheight = Wscale * sheight + 0.5f;
Bitmap Fitbitmap = transformationutils.fitcenter (source, Mbitmappool, outwidth, (int) calculateheight); int fwidth = Fitbitmap.getwidth ();
int fheight = Fitbitmap.getheight ();
Bitmap Bitmap = Mbitmappool.get (Outwidth, Outheight, Bitmap.Config.ARGB_8888);
if (bitmap = = null) {bitmap = Bitmap.createbitmap (Outwidth, Outheight, Bitmap.Config.ARGB_8888);
} Matrix Matrix = new Matrix ();
if (Fheight > Outheight) {matrix.settranslate (0, fheight-outheight);
} else {matrix.settranslate (0, outheight-fheight);
Canvas canvas = new canvas (bitmap);
Paint paint = new paint ();
Paint.setantialias (TRUE);
Paint.setdither (TRUE);
Canvas.drawbitmap (Fitbitmap, Matrix, paint);
Return Bitmapresource.obtain (bitmap, Mbitmappool);
} @Override Public String getId () {return ' cropcircletransformation () '; } private float GetTop (float scaledheight) {switch (mcroptype) {case Top:retur
n 0; Case Center:return (mheight-scaledheight)/2;
Case Bottom:return Mheight-scaledheight;
Default:return 0;
}
}
}
public class Glidecircletransform extends Bitmaptransformation {public Glidecircletransform (context context) {
Super (context);
} @Override protected Bitmap transform (Bitmappool pool, Bitmap totransform, int outwidth, int outheight) {
Return Circlecrop (pool, totransform);
} private static Bitmap Circlecrop (Bitmappool pool, Bitmap source) {if (source = = null) return null;
int size = Math.min (Source.getwidth (), Source.getheight ());
int x = (Source.getwidth ()-size)/2;
int y = (source.getheight ()-size)/2;
Bitmap squared = Bitmap.createbitmap (source, x, y, size, size);
Bitmap result = pool.get (size, size, Bitmap.Config.ARGB_8888);
if (result = = null) {result = Bitmap.createbitmap (size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new canvas (result);
Paint paint = new paint (); Paint.setshader (New Bitmapshader (Squared, bitmapshader.tIlemode.clamp, BitmapShader.TileMode.CLAMP));
Paint.setantialias (TRUE);
float r = size/2f;
Canvas.drawcircle (R, R, R, paint);
return result;
} @Override Public String getId () {return getclass (). GetName ();
}
}
public class Shadetransformation implements transformation<bitmap> {