Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
vuhung3990 / Fullscreen
Created August 19, 2014 09:08
đặt trước setcontentview
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
@vuhung3990
vuhung3990 / orientation change event
Created August 19, 2014 09:10
AndroidManifest.xml <activity......... android:configChanges="orientation|screenSize" /> </activity>
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// todo
}else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
// todo
}
}
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 / Checkbox State in custom list.java
Last active February 2, 2016 02:19
solved issui checkbox state in listview scroll
// Contructor ()
// StaticVar.java contain 'Expand_State' var
private List<ItemObject> list;
private int current_size;
StaticVar.Expand_State = new boolean[list.size()];
current_size = list.size();
// end Contructor--------------------------------
// @override Getview()
// String result;
JsonParser parser = new JsonParser();
JsonElement elem = parser.parse(result);
JsonArray jsonArray = elem.getAsJsonArray();
@vuhung3990
vuhung3990 / get language
Last active August 29, 2015 14:06
get current language on device
Locale.getDefault().getLanguage();
// ja, vi, en...
@vuhung3990
vuhung3990 / delayed a second for search
Last active February 29, 2016 12:24
Search delay idea
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);