Skip to content

Instantly share code, notes, and snippets.

View nguyenlinhnttu's full-sized avatar
🎯
Focusing

Nguyen Linh nguyenlinhnttu

🎯
Focusing
View GitHub Profile
class InfiniteViewPager2 @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyle, defStyleRes) {
private val viewPager2: ViewPager2 by lazy {
findViewById(R.id.view_pager_infinite)
}
@nguyenlinhnttu
nguyenlinhnttu / CustomTextWatcher.java
Created January 25, 2022 08:45
CustomTextWatcher format value
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import java.text.NumberFormat;
public class CustomTextWatcher implements TextWatcher {
@nguyenlinhnttu
nguyenlinhnttu / android-restore-password-keystore-jks.md
Created August 6, 2020 02:01 — forked from ptkdev/android-restore-password-keystore-jks.md
Android: Recovery lost keystore jks file or keystore password

Sign android app with new keystore file if you missing password or lost jks file.

  1. Create new keystore.jks file with comand line (not android studio build menu)

    Linux: keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks

    Windows: "C:\Program Files\Android\Android Studio\jre\bin\keytool.exe" -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore "C:\keystore_new.jks"

  2. Generate a .pem file from new keystore

@nguyenlinhnttu
nguyenlinhnttu / SwipeView
Created June 17, 2020 04:45
SwipeView detect swipe left, right, top, bottom
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
/**
* Created by NguyenLinh on 17,June,2020
*/
@nguyenlinhnttu
nguyenlinhnttu / AES256Cipher.java
Created August 29, 2019 06:59
AES256Cipher Android
public class AES256Cipher {
public static byte[] ivBytes = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
public static String AES_Encode(String str, String str2) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
byte[] bytes = str.getBytes("UTF-8");
IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes);
SecretKeySpec secretKeySpec = new SecretKeySpec(str2.getBytes("UTF-8"), "AES");
Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding");
instance.init(1, secretKeySpec, ivParameterSpec);
return Base64.encodeToString(instance.doFinal(bytes), 0);
@nguyenlinhnttu
nguyenlinhnttu / ZipManager.java
Created August 22, 2019 06:25
ZipManager android code.
package com.android.disastersdk.feature;
import com.android.disastersdk.utils.Logger;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@nguyenlinhnttu
nguyenlinhnttu / convertlist<>to int[].txt
Created April 12, 2019 04:10
Convert List<Integer> top Int[]
private int[] toIntArray(List<Integer> list) {
int[] ret = new int[list.size()];
for (int i = 0; i < ret.length; i++)
ret[i] = list.get(i);
Log.d("ret", Arrays.toString(ret));
return ret;
}
private String[] toStringArray(List<String> list) {
return list.toArray(new String[list.size()]);
//file local.properties
tmdb_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
//file build.gradle (Module: app)
buildTypes.each {
Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())
def tmdbApiKey = properties.getProperty("tmdb_api_key", "")
it.buildConfigField 'String', "TMDB_API_KEY", tmdbApiKey
@nguyenlinhnttu
nguyenlinhnttu / PingIP.java
Created December 26, 2018 04:14 — forked from madan712/PingIP.java
Java program to ping an IP address
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class PingIP {
public static void runSystemCommand(String command) {
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReader inputStream = new BufferedReader(
@nguyenlinhnttu
nguyenlinhnttu / Dialog Full LayoutParram
Created July 25, 2018 09:57
use dialog full screen, with set layout param, and gravity.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, R.style.AppTheme);
}
@Override
public void onStart() {
super.onStart();
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();