Skip to content

Instantly share code, notes, and snippets.

import android.os.Bundle
import android.support.annotation.LayoutRes
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.arellomobile.mvp.MvpDelegate
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.OnMapReadyCallback
@iserbin
iserbin / MediaDecoder.java
Created March 15, 2017 08:33 — forked from a-m-s/MediaDecoder.java
Android code to extract raw audio from arbitrary media files.
/* MediaDecoder
Author: Andrew Stubbs (based on some examples from the docs)
This class opens a file, reads the first audio channel it finds, and returns raw audio data.
Usage:
MediaDecoder decoder = new MediaDecoder("myfile.m4a");
short[] data;
while ((data = decoder.readShortData()) != null) {
Genymotion emulators are already rooted and with SU installed
To fix "adb server version (<server-version>) doesn't match this client (<client-version>); killing...":
Change SDK location https://stackoverflow.com/questions/30757191/adb-and-genymotion-error-adb-server-is-out-of-date-killing-cannot-bind-tc
To find current SDK location:
https://stackoverflow.com/questions/34532063/finding-android-sdk-on-mac-and-adding-to-path
System apps reside in:
/system/app/<AppName>/<AppName>.apk
@iserbin
iserbin / DownloadTransformImagesAndPutThemAsMarkersOnMapWithGlide.java
Created November 21, 2016 12:05 — forked from lsurvila/DownloadTransformImagesAndPutThemAsMarkersOnMapWithGlide.java
Downloads/transforms images with Glide and puts them on Google Map as markers (images will be cached automatically).
private Bitmap defaultPin;
private GoogleMap googleMap;
private List<MapItem> items;
private void putItemsOnMap() {
for (MapItem item : items) {
// wrap google map marker with target, also set marker's pin with default pin bitmap, coordinates, etc, so it still be shown on map while real one is downloaded/transformed
MarkerTarget marker = new MarkerTarget(googleMap.addMarker(new MarkerOptions().position(new LatLng(item.getLatitude(), item.getLongitude())).title(item.getName()).icon(BitmapDescriptorFactory.fromBitmap(defaultPin))));
Glide.with(this)
.load(item.getPinImageUrl())
@iserbin
iserbin / FilterListInsideResponse.java
Created November 21, 2016 12:04 — forked from lsurvila/FilterListInsideResponse.java
An example how to iterate and filter through list which is inside object, retrieved from server/etc with RxJava
public Observable<SomeResponse> downloadAndFilterListInResponse() {
return mSomeRetrofitApi.downloadSomeData() // get response from server/etc
// start iterating through list in response object
.flatMap(response -> Observable.from(response.getListWeWantToFilterOut())
// NOTE: this is inner sequence, gets result from Observable.from
.filter(item -> item != null) // filters out items that are null
.toList() // all items combined into list again
.take(100) // take only first 100 items, rest will be ignored
.map(items -> { // now we need to 'map' list into response
response.setListWeWantToFilterOut(items); // overwrite list in object with filtered list
public static void setActionDoneListener(EditText editText, final ActionDoneListener editTextActionDoneListener) {
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
editTextActionDoneListener.onActionDone();
return false;
}
return false;
}
@iserbin
iserbin / Interceptor.java
Created November 21, 2016 10:25 — forked from alex-shpak/Interceptor.java
Refreshing OAuth token with okhttp interceptors. All requests will wait until token refresh finished, and then will continue with the new token.
private class HttpInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//Build new request
Request.Builder builder = request.newBuilder();
builder.header("Accept", "application/json"); //if necessary, say to consume JSON
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')