Skip to content

Instantly share code, notes, and snippets.

View mttkay's full-sized avatar

Matthias Käppler mttkay

  • GitLab
  • Berlin, Germany
View GitHub Profile
@mttkay
mttkay / gist:3851440
Created October 8, 2012 08:40
Testing if an Android app is installed on the SD card
private boolean isAppInstalledToSDCard(Context context) {
PackageManager pm = context.getPackageManager();
try {
int extStorage = ApplicationInfo.FLAG_EXTERNAL_STORAGE;
String package = context.getPackageName();
ApplicationInfo appInfo = pm.getApplicationInfo(package, extStorage);
return extStorage == (extStorage & appInfo.flags);
} catch (NameNotFoundException e) {
e.printStackTrace();
return false;
<TextView android:id="@+id/my_text" ...>
TextView text = (TextView) findViewById(R.id.my_text);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="my_text" type="id" />
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="my_textview_style" parent="@android:style/Widget.TextView">
<item name="android:id">@+id/my_text</item>
...
</style>
</resources>
<TextView style="@style/my_textview_style" .../>
@mttkay
mttkay / gist:6050054
Created July 21, 2013 21:25
Note that you must setRetainInstance(true); otherwise the Observable and all associated state will get destroyed of course. So make sure you don't create strong references to views/context in onCreate or onActivityCreated, or they will leak. The nice thing about this is that there apart from splitting up the code for creating the observable from…
package com.github.super8.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import com.github.super8.R;
@mttkay
mttkay / DownloadTask.java
Last active December 21, 2015 16:19
An AsyncTask.
class DownloadTask extends AsyncTask<String, Void, File> {
protected File doInBackground(String... args) {
final String url = args[0];
try {
byte[] fileContent = downloadFile(url);
File file = writeToFile(fileContent);
return file;
} catch (Exception e) {
// ???
@mttkay
mttkay / Pager.java
Created November 4, 2015 15:46
A simple Rx based pager
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
@mttkay
mttkay / report.txt
Created June 15, 2016 07:12
Mix 1.0.5 crash
Process: Mix-ide [31034]
Path: /Applications/Mix-ide.app/Contents/MacOS/Mix-ide
Identifier: .
Version: ??? (mix )
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Mix-ide [31034]
User ID: 502
Date/Time: 2016-06-15 09:09:57.574 +0200