In order to familiarize myself with some open source frameworks, I decided to write an APP in my spare time to familiarize myself with the use of these frameworks. Step on the pit in advance for later use in company projects. The interface used is aggregation data and dry cargo concentration camp, thank you very much.




4.png




6.png




3.png

  • Home slider using DrawerLayout+NavigationView implementation

  • Local collections are implemented using a Realm database

  • Network requests are implemented using Retrofit+RxJava+RxAndroid, and the returned results are simply encapsulated

  • The RecyclerView Adapter and ViewHolder are encapsulated to realize the pull up loading

  • CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout created a cool slide animation

  • Glide is used to realize the loading of pictures

  • PhotoView is used to zoom the image

  • Use the open source Material – CalendarView

  • SwipeRefreshLayout is automatically refreshed for the first time

Download the APP




Qr code. PNG

The source code

Github.com/RaphetS/Tod…

NavigationView (DrawerLayout+NavigationView




    

       

        
    

    
    


Copy the code

Android :layout_gravity=”leftt” represents the left slide interface (or start). Android :layout_gravity=”right” code right slide interface (or end), without layout_gravity is the main interface. ActionBarDrawerToggle can be added to the code to control the slide bar show and hide.

ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.open, R.string.close);
mDrawerToggle.syncState();
mDrawer.addDrawerListener(mDrawerToggle);Copy the code

NavigationView is a NavigationView control, which is mainly used as a menu control. The upper part is headerLayout, which can be customized layout, and the lower part is Menu, which can be used as a navigation menu item



    
    
    
    


Copy the code
Get the internal controller of headerLayout:
View headView=navigationView.getHeaderView(0);Copy the code
Set the menu list icon color:

By default, the color of the menu icon is gray. You can set the color of the icon

app:itemIconTint=""Copy the code
Add a dividing line:

Simply divide the menu into groups, each with an Id, and there will be dividing lines between groups:












Copy the code

Glide loading pictures

Set the binding life cycle

Glide.with(Context context); // Bind Context Glide. With (Activity Activity); // Bind Activity Glide. With (FragmentActivity Activity); // Bind FragmentActivity Glide. With (Fragment Fragment); / / bind fragmentsCopy the code
General usage:
Green. With (context).load(imageUrl)// image path.placeholder (r.draable.ic_launcher)// Set the loading image .error(r.rawable.ic_launcher)// Sets the picture to load failed. SkipMemoryCache (true)// Sets the memory cache to skip DiskCacheStrategy (diskcacheStrategy. ALL)// Set the cache policy: ALL: cache source resources and converted resources/None: do not cache any disks /source: cache source resources /result: Priority (priority.normal)// Set download priority. Animate (r.anim.item_alpha_in)// Set loading animation. Thumbnail (0.1f)// Set thumbnail support (load thumbnail first, Override (400,400)// set the loading size. CenterCrop ()// set the dynamic transform. Into (imageView);Copy the code
Git image:
Glide.with(this).load(imageUrl).asGif().into(imageView);Copy the code
Dynamic cache cleanup:
Glide.get(this).clearDiskCache(); Glide.get(this).clearMemory(); // Clearing the memory cache can be done in the UI main threadCopy the code
Load rounded corners or rounded images:
Glide.with(this).load(imageUrl).transform(new GlideRoundTransform(this)).into(imageView);Copy the code

A custom Transform is required. Here we provide a rounded Transform and a rounded Transform:

Rounded corner conversion:
public class GlideRoundTransform extends BitmapTransformation { private static float radius = 0f; public GlideRoundTransform(Context context) { this(context, 4); } 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) { return 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_8888); } 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); }}Copy the code
Round picture conversion:
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; // TODO this could be acquired from the pool too 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(); }}Copy the code
Obtain Bitmap
Glide.with(this) .load(imageUrl) .asBitmap() .into(new SimpleTarget() { @Override public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { imageView.setImageBitmap(mBitmap); }});Copy the code