Skip to content

Instantly share code, notes, and snippets.

View chemouna's full-sized avatar

Mouna Cheikhna chemouna

  • San Francisco, CA
View GitHub Profile
@astachelek
astachelek / SoManyWaysToGetScreenSizeInAndroid.java
Created May 8, 2013 18:59
In case you ever wanted to see a list of the various approaches to get the size of the screen in Android, here are a bunch. Many of these return slightly different values.
// This causes some IPC to the WindowManager, so use with caution as its slow
Rect displayArea = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(displayArea);
Log.d(TAG, "Visible Display Frame Method: " + displayArea.width() + "x" + displayArea.height());
// This is not immediately available as the full view layout needs to happen
View root = window.getDecorView().findViewById(android.R.id.content);
Log.d(TAG, "Root Content View Method: " + root.getMeasuredWidth() + "x" + root.getMeasuredHeight());
@andreynovikov
andreynovikov / OnItemSelectedListener.java
Last active June 14, 2020 17:43
Complete working solution for Android action bar tabs with fragments having separate back stack for each tab.
// Custom interface that enables communication between Fragment and its Activity
public interface OnItemSelectedListener
{
public void onItemSelected(String item);
}
anonymous
anonymous / Consumer.java
Created January 7, 2013 22:23
Simple of example of how to use injection with objects that require things which cannot always be injected.
public class Consumer {
@Inject ExampleClass.Factory exampleClassFactory;
public void fireZeMissles() {
ExampleClass ex = exampleClassFactory.createForUser(42);
ex.doThings();
}
}
@heynemann
heynemann / gist:3341234
Created August 13, 2012 14:30
nginx conf for thumbor
upstream thumborbe {
server thumbor.myhost.com:8090 ;
server thumbor.myhost.com:8091 ;
server thumbor.myhost.com:8092 ;
server thumbor.myhost.com:8093 ;
server thumbor.myhost.com:8094 ;
server thumbor.myhost.com:8095 ;
}
location ~* "^/.{28}/.*(jpg|jpeg|gif|png)(#.*)?$" {
@JakeWharton
JakeWharton / BaseActivity.java
Created July 6, 2012 01:17
Scoped event bus which automatically registers and unregisters with the lifecycle.
package com.squareup.example;
public abstract BaseActivity extends SherlockActivity {
private final ScopedBus scopedBus = new ScopedBus();
protected ScopedBus getBus() {
return scopedBus;
}
@Override public void onPause() {
/**
* Execute an {@link AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
public static <T> void execute(AsyncTask<T, ?, ?> task, T... args) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");