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
TextView text = (TextView) findViewById(R.id.my_text);
<TextView android:id="@+id/my_text" ...>
@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;
@mttkay
mttkay / gist:2995057
Created June 26, 2012 10:50
Android obtainStyledAttributes
public MyWidget(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyWidget, defStyle);
// read attribute values
boolean userBoolAttr = a.getBoolean(R.styleable.bool_attr, false);
int userIntAttr = a.getInteger(R.styleable.int_attr, 0);
// do something with these values
// ...
}
@mttkay
mttkay / gist:2994987
Created June 26, 2012 10:45
Android use custom attribute
<com.example.MyWidget
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bool_attr="true"
int_attr="1" />
@mttkay
mttkay / gist:2994973
Created June 26, 2012 10:43
Android declare-styleable sample
<resources>
<declare-styleable name="MyWidget">
<attr name="bool_attr" format="boolean" />
<attr name="int_attr" format="integer" />
</declare-styleable>
</resources>
class Base
def m
puts "Base::m"
end
end
module MixinA
def m
puts "MixinA::m"
end
@mttkay
mttkay / gist:1868951
Created February 20, 2012 12:08
Inserting a StreamItemPhoto
private void addStreamItemPhoto(String photoUrl, long streamItemId, String accountName) {
byte[] photoData = downloadPhoto(photoUrl);
ContentValues values = new ContentValues();
values.put(StreamItems.ACCOUNT_NAME, accountName);
values.put(StreamItems.ACCOUNT_TYPE, "com.yourapp.account");
values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
values.put(StreamItemPhotos.PHOTO, photoData);
resolver.insert(StreamItems.CONTENT_PHOTO_URI, values);
}
@mttkay
mttkay / gist:1868888
Created February 20, 2012 11:43
Android social stream view item Activity
<activity android:name=".social.ViewStreamItemActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<data android:host="com.android.contacts" android:scheme="content" android:pathPattern="/stream_items/*"/>
</intent-filter>
</activity>
@mttkay
mttkay / gist:1393552
Created November 25, 2011 13:39
IgnitedAsyncTask sample
import com.github.ignition.core.tasks.IgnitedAsyncTask;
public class IgnitedAsyncTaskActivity extends Activity {
private SampleTask task;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);