Skip to content

Instantly share code, notes, and snippets.

@demixdn
demixdn / EditTextDebounce.java
Created April 24, 2017 09:58
Get text from EditText with debounce without RxJava
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import java.lang.ref.WeakReference;
@pcevikogullari
pcevikogullari / WebViewActivity.java
Created January 13, 2017 21:30
Execute Javascript in webview
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://xxx.xxx.xxx.xxx:yyyy/form");
@mbunyard
mbunyard / MockResponseInterceptor.java
Created November 18, 2016 21:11
OkHttp3 interceptor which provides a mock response from local resource file.
package com.rogerthat.network.util;
import android.content.Context;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import okhttp3.Interceptor;
@shaik2many
shaik2many / javascript-localstorage-expiry.js
Created July 20, 2016 14:07
set timeout for localStorage or sessionStorage
http://apassant.net/2012/01/16/timeout-for-html5-localstorage/
var hours = 24; // Reset when storage is more than 24hours
var now = new Date().getTime();
var setupTime = localStorage.getItem('setupTime');
if (setupTime == null) {
localStorage.setItem('setupTime', now)
} else {
if(now-setupTime > hours*60*60*1000) {
localStorage.clear()
@alphamu
alphamu / KeyStoreHelper.java
Last active December 28, 2023 18:22
Using Android KeyStore to generate a password. The code create a public/private key pair and uses the base64 encoded form of the certificate to as the password. The code modified the KeystoreHelper class from AOSP demo projects.
/*
* Copyright 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.security.KeyPairGeneratorSpec;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import java.io.ByteArrayInputStream;
@metaphore
metaphore / RoundCornerFrameLayout.java
Created December 9, 2015 18:32
[Android] Frame layout with rounded corners
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* Frame layout that has rounded corners (it clips content too).
@rakawestu
rakawestu / ParsePushBroadcastReceiver.java
Last active April 20, 2018 20:50
Get json payload from Parse push notification
public class ParsePushBroadcasReceiver extends ParsePushBroadcastReceiver{
/**
* Provide resource identifier of the small icon for each
* push notification in the notification bar.
* @param context application context
* @param intent intent
* @return the icon resource id.
*/
@Override
@cyrixmorten
cyrixmorten / FucedLocationTracker.java
Created October 23, 2015 13:37
ReactiveLocation in Service
public class FusedLocationTrackerService extends InjectingService {
private static final String TAG = FusedLocationTrackerService.class.getSimpleName();
public FusedLocationTrackerService() {
}
public static void start(Context context) {
Log.e(TAG, "startGPSTrackerService");
@curioustechizen
curioustechizen / UseApiKey.java
Created April 6, 2015 07:37
Android: Loading API Keys and other secrets from properties file using gradle
String apiKey = BuildConfig.API_KEY