Skip to content

Instantly share code, notes, and snippets.

private void setNavigationItemSelectedListener(final BottomNavigationView.OnNavigationItemSelectedListener listener) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) mBinding.bottomNavi.getChildAt(0);
for (int i = 0; i < menuView.getChildCount(); i++) {
final BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(i);
// Labels are re-used from a pool, if you have global freeze text enabled, this causes state problems
((TextView) itemView.findViewById(android.support.design.R.id.smallLabel)).setFreezesText(false);
((TextView) itemView.findViewById(android.support.design.R.id.largeLabel)).setFreezesText(false);
// Workaround for BottomNavigationMenu bug where it selects the item even if the listener returns false
@haunguyen
haunguyen / getDefaultUserAgent.java
Created June 21, 2018 10:20
Android getDefaultUserAgent
// http://matsuhilog.blogspot.jp/2013/05/performance-analytics-in-android.html
// https://code.google.com/p/codenameone/issues/detail?id=294
public static String getDefaultUserAgent(Context context) {
String ua;
if (Build.VERSION.SDK_INT >= 17) {
ua = Util.getDefaultUserAgent(context);
} else if (Build.VERSION.SDK_INT >= 16) {
ua = Util.getUserAgent(context);
} else {
try {
@haunguyen
haunguyen / LocaleManager.java
Created April 11, 2018 10:56
Change local language App
package vn.mclab.babyoto.utils;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import java.util.Locale;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
@haunguyen
haunguyen / EllipsizingTextView.java
Last active February 7, 2018 09:54
EllipsizingTextView
package jp.co.permission.movielike.custom.view;
import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.widget.TextView;
@haunguyen
haunguyen / zip_upzip.txt
Created January 19, 2018 04:02
[Android-java] zip and unzip multiple file in folder
public static boolean rajDhaniSuperFastUnzip(String inputZipFile, String destinationDirectory)
{
try {
int BUFFER = 2048;
List<String> zipFiles = new ArrayList<String>();
File sourceZipFile = new File(inputZipFile);
File unzipDestinationDirectory = new File(destinationDirectory);
unzipDestinationDirectory.mkdir();
ZipFile zipFile;
zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
@haunguyen
haunguyen / read_kernel_android.txt
Last active January 19, 2018 03:59
[Android-java] Read kernel version of device
public static String readKernelVersion() {
try {
Process p = Runtime.getRuntime().exec("uname -s -m", null, null);
InputStream is = null;
if (p.waitFor() == 0) {
is = p.getInputStream();
} else {
is = p.getErrorStream();
}