Skip to content

Instantly share code, notes, and snippets.

@VAdaihiep
VAdaihiep / image.php
Created April 20, 2018 08:14
PHP Controller view file or download file. Use to check permission before return file like attach file in topic forum, private message,etc. Avoid user public file url. Ex: To view image: localhost/image.php?mode=view. To download image: localhost/image.php?mode=download.
// Check permission,...
// View image or download
$filePath = '/data/.../demo-image.jpg';
$name = basename($filePath);
if($params['mode'] == 'view'){
header("Content-Type: " . mime_content_type($filePath));
header('Content-disposition: inline; filename="' . $name . '"');
} else {
header("Content-Type: application/octet-stream");
@VAdaihiep
VAdaihiep / Util.java
Created January 17, 2017 09:31
Copy Android Database to SDCard
final static String DATABASE_NAME = "your-database-name";
final static String FOLDER_EXTERNAL_DIRECTORY = Environment.getExternalStorageDirectory() + "/folder";
//______________________________________________________________________________________________
/**
* Call this method from any activity in your app (
* for example -> DatabaseUtil.copyDatabaseToExtStg(MainActivity.this);
* this method will copy the database of your application into SDCard folder "shanraisshan/MyDatabase.sqlite" (DATABASE_NAME)
*/
@VAdaihiep
VAdaihiep / MoneyFormatEditText.java
Created July 2, 2016 04:01
Format money. For an example: 10000 -> 10.000
public class MoneyFormatEditText extends EditText {
public MoneyFormatEditText(Context context) {
super(context);
setupTextWatcher();
}
public MoneyFormatEditText(Context context, AttributeSet attrs) {
super(context, attrs);
setupTextWatcher();
}
@VAdaihiep
VAdaihiep / ImagePickerHelper.java
Last active June 17, 2016 10:59
Pick image or capture simplest way by custom 'com.kbeanie:image-chooser-library:1.5.8@aar'
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import com.kbeanie.imagechooser.api.ChooserType;
import com.kbeanie.imagechooser.api.ChosenImage;
import com.kbeanie.imagechooser.api.ChosenImages;
import com.kbeanie.imagechooser.api.ImageChooserListener;
import com.kbeanie.imagechooser.api.ImageChooserManager;
@VAdaihiep
VAdaihiep / LoadMoreListView.java
Last active March 29, 2016 14:15
Load more (paging) ListView in simplest way
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.HeaderViewListAdapter;
import android.widget.ListView;
public class LoadMoreListView extends ListView implements AbsListView.OnScrollListener {
private OnLoadMorListener onLoadMorListener;
@VAdaihiep
VAdaihiep / PhoneNumberEditText.java
Created March 22, 2016 03:54
EditText auto add space when input phone number (phone number in Vietnam). Example: 01234567890 -> 0123 456 7890
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
@VAdaihiep
VAdaihiep / OneSignalRestClient.java
Created March 18, 2016 04:04
Demo Custom Http Client from OneSignal SDK Android
/**
* Modified MIT License
*
* Copyright 2015 OneSignal
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@VAdaihiep
VAdaihiep / TimeAgo.java
Created March 17, 2016 07:22
Calculate and return time ago
import java.util.Date;
import android.content.res.Resources;
public class TimeAgo {
public static String timeAgo(Date date) {
return timeAgo(date.getTime());
}
@VAdaihiep
VAdaihiep / MyLog.java
Created November 11, 2015 04:37
Log auto turn off when build release
import android.util.Log;
import vn.mog.mygimi.BuildConfig;
/**
* Created by VAdaihiep on 11/11/2015.
*/
public class MyLog {
public static String DEFAULT_TAG = "VAdaihiep";
@VAdaihiep
VAdaihiep / MyListFragment.java
Created November 6, 2015 03:19
Keep state (data) in Fragment when replace fragment and go back
package vn.vadaihiep.keepstatefragment;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;