Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
vuhung3990 / .gitignore
Created August 28, 2015 08:14
Android gitignore
# Created by https://www.gitignore.io/api/windows,linux,osx,intellij,android,gradle,java,eclipse,jetbrains
### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
@vuhung3990
vuhung3990 / checkCameraHardware.java
Created August 29, 2015 02:45
Check if this device has a camera
/** Check if this device has a camera */
private boolean checkCameraHardware(Context context) {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
@vuhung3990
vuhung3990 / AndroidManifest.xml
Created August 29, 2015 02:49
Sample intent camera
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hungvu.testpack">
<uses-permission android:name="ANDROID.PERMISSION.CAMERA" />
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
public class DatabaseHelper {
private Context context;
private SqliteHelper sqlite;
private String TB_NAME;
private String TB_STRUCT;
public DatabaseHelper(Context context, String DbName, String TB_NAME, String TB_STRUCT) {
this.context = context;
this.TB_NAME = TB_NAME;
this.TB_STRUCT = TB_STRUCT;
@vuhung3990
vuhung3990 / get language
Last active August 29, 2015 14:06
get current language on device
Locale.getDefault().getLanguage();
// ja, vi, en...
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
@vuhung3990
vuhung3990 / Folder utils
Created October 3, 2014 09:16
PERMISSION: READ_EXTERNAL , WRITE_EXTERNAL
public static String formatSize(long bytes, int place) {
int level = 0;
float number = bytes;
String[] unit = { "bytes", "KB", "MB", "GB", "TB", "PB" };
while (number >= 1024f) {
number /= 1024f;
level++;
}
public static void setDefaultPreference(Context context,String share_Pref_Name) {
SharedPreferences getpref = context.getSharedPreferences(share_Pref_Name, Context.MODE_PRIVATE);
Map<String, ?> tempPreference = getpref.getAll();
if(tempPreference.size() <= 0){
// set default (fist time)
Editor edit = getpref.edit();
edit.putString(context.getString(R.string.pref_key_cache_capacity), StaticVar.PREF_DEFAULT_CACHE);
edit.putString(context.getString(R.string.pref_key_cache_mode), StaticVar.PREF_DEFAULT_CACHE_MODE);
edit.putBoolean(context.getString(R.string.pref_key_notification), StaticVar.PREF_DEFAULT_NOTIFICATION);
edit.putString(context.getString(R.string.pref_key_orientation_mode), StaticVar.PREF_DEFAULT_ORIENTATION_MODE);
@vuhung3990
vuhung3990 / default timestamp
Created October 14, 2014 03:00
Laravel default timestamp issui
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'));
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%d' // get day after convert
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%m' // get month
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%Y' // get year
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%H' // 24h format
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%M' // get minutes
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%S' // get second
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%u' // get day of week
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%U' // get week of year
date --date='TZ="Asia/Ho_Chi_Minh" 16:33' +'%Z' // alphabetic time zone