Skip to content

Instantly share code, notes, and snippets.

View talenguyen's full-sized avatar
🎯
Focusing

Nguyen Truong Giang talenguyen

🎯
Focusing
View GitHub Profile
@talenguyen
talenguyen / Coding Conventions
Created April 6, 2015 08:13
Android coding convention.
# Naming
## 1. File
### 1.1. Layout
* Activity -> prefix **activity_**
* Fragment -> prefix **fragment_**
* Custom View -> prefix **view_**
* List Item View -> prefix **item_**
@talenguyen
talenguyen / CustomViewGroup
Created May 15, 2015 02:59
Expert - CustomView group to get high performance
public class ProfilePhotoLayout extends ViewGroup {
private ProfilePhoto mProfilePhoto;
private Menu mMenu;
private Title mTitle;
private Subtitle mSubtitle;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 1. Setup initial constraints.
int mTextWidth, mTextHeight; // Our calculated text bounds
Paint mTextPaint = new Paint();
// Now lets calculate the size of the text
Rect textBounds = new Rect();
mTextPaint.getTextBounds(mText, 0, mText.length(), textBounds);
mTextWidth = mTextPaint.measureText(mText); // Use measureText to calculate width
mTextHeight = textBounds.height(); // Use height from getTextBounds()
// Later when you draw...
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
#parse("File Header.java")
public class ${NAME} extends Fragment {
private static final String FRAG_TAG = ${NAME}.class.getCanonicalName();
@talenguyen
talenguyen / AdMob.cs
Last active August 29, 2015 14:26
AdMob implement for display Google Admob in Unity project. NOTE: MonoSingleton is open source file on Github. and IAd is my interface for ad provider
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using System;
using GoogleMobileAds;
public class AdMob : MonoSingleton<AdMob>, IAd
{
[Header("Config ad id")]
@talenguyen
talenguyen / Logger.cs
Created August 6, 2015 15:42
Log wrapper help to easy to debug on Android or iOS build
using UnityEngine;
using System.Collections;
public class Logger : MonoSingleton<Logger>
{
[SerializeField]
private string
tag = "Logger";
@talenguyen
talenguyen / Useful stub in Android Development
Created August 27, 2015 08:50
Useful stub in Android Development
public void captureView(View view, File outputFile) {
//Create a Bitmap with the same dimensions
Bitmap image = Bitmap.createBitmap(
avatarSize,
avatarSize,
Bitmap.Config.RGB_565);
//Draw the view inside the Bitmap
view.draw(new Canvas(image));
//Store to sdcard
@talenguyen
talenguyen / ContentLayout.java
Last active September 28, 2015 07:16
Android ContentLayout. The utility class to switch showing content/loading/error/empty efficient way
/**
* Umbala
*
* Created by Giang Nguyen on 9/26/15.
* Copyright (c) 2015 Umbala. All rights reserved.
*/
package co.umbala.umbala.ui.widget;
import android.animation.Animator;
public class DetectViewPagerOverscroll extend OnPageChangeListener {
boolean hasSelection;
boolean userRelease;
private long lastScrollTimeStamp = 0;
@Override public void onPageSelected(int position) {
//hasSelection = true;
radioGroupController.selectItem(position);
Timber.d("onPageSelected =====> position: %d", position);
}
@talenguyen
talenguyen / LoadMoreAdapter.java
Last active June 14, 2019 10:16
Implementation of Load More feature for RecyclerView
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
public abstract class LoadMoreAdapter<T>
extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int VIEW_TYPE_LOAD_MORE = 1;