Skip to content

Instantly share code, notes, and snippets.

The basic definition of how a View is sized goes like this:
MeasureSpec.EXACTLY - A view should be exactly this many pixels regardless of how big it actually wants to be.
MeasureSpec.AT_MOST - A view can be this size or smaller if it measures out to be smaller.
MeasureSpec.UNSPECIFIED - A view can be whatever size it needs to be in order to show the content it needs to show.
MeasureSpec.AT_MOST will be applied to views that have been set to WRAP_CONTENT if the parent view is bound in size. For example, your parent View might be bound to the screen size. It's children will be also bound to this size, but it might not be that big. Thus, the parent view will set the MeasureSpec to be AT_MOST which tells the child that it can be anywhere between 0 and screen size. The child will have to make adjustments to ensure that it fits within the bounds that was provided.
package com.amb.counter2counter.service.ocr;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import timber.log.Timber;
/**
Picasso v/s Imageloader v/s Fresco vs Glide
There are many different libraries available out there to load images when you develop Android applications. Picasso has been my favorite which is light weight, but functions provided are more or less similar to Imageloader and Glide. Most libs have callbacks but Fresco does not, which seems to have the best performance compared to all other libraries. So I thought, a simple comparison of these different libraries would help fellow developers when they want to select the best image download library for a specific requirement.
Fresco
(Cons)
- Huge size of library
- No Callback with View, Bitmap parameters
- SimpleDraweeView doesn't support wrap_content
@vtthach
vtthach / ProductAdapter.java
Created June 27, 2017 04:26
Sampel using DiffUtil when update product list
/*
* Copyright 2017, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vtthach
vtthach / GridDividerDecoration.java
Created June 27, 2017 06:24
GridDividerDecoration
package com.example.android.recyclerplayground;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
@vtthach
vtthach / DialogChoosePhotoMethodFragment.java
Created June 30, 2017 09:36
Bottom dialog select phooto
package com.piing.fragment.dialog;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@vtthach
vtthach / PhotoUtils.java
Created June 30, 2017 09:37
Select photo camera intent utils
package com.piing.util;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import com.piing.AppConstant;
import com.piing.R;
@vtthach
vtthach / ImageBrowsePresenter.java
Created July 20, 2017 04:21
Notify gallery insert an image with path
// 其次把文件插入到系统图库
try {
MediaStore.Images.Media.insertImage(view.getMyContext().getContentResolver(), file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 最后通知图库更新
view.getMyContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getPath())));
@vtthach
vtthach / Android Design Support Library
Last active August 14, 2017 09:44
Android Design Support Library - Style, Thems, Colors and Typography
app_themes.xml https://codelabs.developers.google.com/codelabs/material-design-style/img/5ffbda8697aa2b0f.png