Skip to content

Instantly share code, notes, and snippets.

View agramian's full-sized avatar

Abtin Gramian agramian

View GitHub Profile
@agramian
agramian / gist:bbce114bae063a048dd6c585f019bc64
Last active April 19, 2018 22:22
RxJava2 exponential backoff sequence generator
public static final Observable<Long> getExponentialBackoffSequence(@Nullable Long startValue,
@Nullable Long maxValue,
@Nullable Long multiplier,
@Nullable Long sequenceLength,
@Nullable Long maxValueRepeatCount) {
// set defaults if necessary
if (startValue == null) {
startValue = 1L;
}
final long start = startValue;
@agramian
agramian / ShowLastCharsPasswordTransformationMethod.java
Last active July 10, 2017 00:15
An implementation of PasswordTransformationMethod which shows the last n characters
import android.graphics.Rect;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
import android.text.GetChars;
import android.text.NoCopySpan;
import android.text.Spannable;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
@agramian
agramian / gist:c1297c8fd09d88b6039833a8fc643233
Created March 30, 2017 18:07
Android media scanner example to make file available in downloads app
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(context.getApplicationContext(),
new String[] { file.toString() }, null, (path, uri) -> {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
// make the file visible in the downloads app
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(file.getName(), file.getName(), true, "application/gpx+xml", file.getAbsolutePath(), file.length(), true);
});