Skip to content

Instantly share code, notes, and snippets.

@Joisar
Joisar / Code.java
Created October 26, 2017 15:57 — forked from Dogesmith/Code.java
Android Multi-line EditText which prevents newline characters from being added
mContent = (EditText) v.findViewById(R.id.dialog_item_content_EditText);
mContent.setText(mContentInit);
mContent.setRawInputType(InputType.TYPE_CLASS_TEXT);
mContent.setImeActionLabel(getResources().getString(R.string.done), EditorInfo.IME_ACTION_DONE);
mContent.setImeOptions(EditorInfo.IME_ACTION_DONE);
mContent.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event == null) {
@Joisar
Joisar / DataParser
Last active January 13, 2019 00:22
Realm, GSON and primitive JSON arrays
//parsing with help of gson without storing via realm
UserInfo userInfo = (UserInfo)Utils.deserialize(userInfoJsonObject.toString(),new TypeToken<UserInfo>(){}.getType());
//save data using realm
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
realm.createOrUpdateObjectFromJson(UserInfo.class, userInfoJsonObject);
realm.commitTransaction();
realm.close();
@Joisar
Joisar / CountingFileRequestBody.java
Last active August 29, 2015 14:27 — forked from eduardb/CountingFileRequestBody.java
Uploading a file with a progress displayed using OkHttp
public class CountingFileRequestBody extends RequestBody {
private static final int SEGMENT_SIZE = 2048; // okio.Segment.SIZE
private final File file;
private final ProgressListener listener;
private final String contentType;
public CountingFileRequestBody(File file, String contentType, ProgressListener listener) {
this.file = file;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
public class AspectImageView extends ImageView {
private static final int DEFAULT_XRATIO = 1;
private static final int DEFAULT_YRATIO = 1;
package no.nsb.ombord;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.http.util.ExceptionUtils;
public class SplashActivity extends Activity{
private static final String TAG = "SplashActivity";
private Handler mHandler;
private Runnable mRunnable = new Runnable() {
@Override
public void run() {
loadHomeScreen();
public class PrefsManager {
// Shared Preferences
private SharedPreferences pref;
// Editor for Shared preferences
private Editor editor;
// Shared pref mode
private int PRIVATE_MODE = 0;
@Joisar
Joisar / EncryptionUtils.java
Created September 12, 2014 13:56
128 bit AES Encryption-Decryption
public class EncryptionUtils {
private Cipher mCipher;
private SecretKeySpec mSpecSecretKey;
private IvParameterSpec mSpecIV;
/* private String iv = "4957414F6B524147";//Dummy iv (CHANGE IT!)
private String secret_key = "764164673344344D55624A6C486E4168";//Dummy secretKey (CHANGE IT!)
*/
public EncryptionUtils(String secret_key,String iv) {
@Joisar
Joisar / UTILS.java
Last active April 9, 2017 08:59
Common UTILS pattern
public class UTILS {
public static boolean LOG_ENABLED = true;
public static class Log {
public static void e(String tag, String message) {
if (LOG_ENABLED) {
android.util.Log.e(tag, message);
}
}
@Joisar
Joisar / URLS.java
Created September 12, 2014 13:52
Server config pattern :
public class URLS {
public static final SERVER_CONFIGS.Server CURRENT_SERVER = SERVER_CONFIGS.Server.QA;
private static class SERVER_CONFIGS
{
private static final String LIVE_URL = "http://services.joisar.com/svc/";
private static final String QA_URL = "http://qaservices.joisar.com/svc/";
private static enum Server {
LIVE(LIVE_URL), QA(QA_URL);