Skip to content

Instantly share code, notes, and snippets.

View moondroid's full-sized avatar

Marco Granatiero moondroid

View GitHub Profile
public class TextViewWithImages extends TextView {
private static final String DRAWABLE = "drawable";
/**
* Regex pattern that looks for embedded images of the format: [img src=imageName/]
*/
public static final String PATTERN = "\\Q[img src=\\E([a-zA-Z0-9_]+?)\\Q/]\\E";
public TextViewWithImages(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@moondroid
moondroid / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@moondroid
moondroid / GrayScale.java
Created March 12, 2015 09:15
Transform Bitmap to grayscale
public static Bitmap toGrayScale(Bitmap bmpOriginal) {
int width, height;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>
<color name="red_300">#f36c60</color>
<color name="red_400">#e84e40</color>
<color name="red_500">#e51c23</color>
@moondroid
moondroid / MyApplication.java
Last active October 13, 2015 21:58
Overriding the Application Lifecycle Handlers
public class MyApplication extends Application {
private static MyApplication singleton;
// Returns the application instance
public static MyApplication getInstance() {
return singleton;
}
//Called when the application is created. Override this method to initialize your
@moondroid
moondroid / MyStateChangeActivity.java
Last active October 13, 2015 21:57
Activity state event handlers
public class MyStateChangeActivity extends Activity {
// Called at the start of the full lifetime.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize Activity and inflate the UI.
}
// Called after onCreate has finished, use to restore UI state
@moondroid
moondroid / MySkeletonFragment.java
Last active October 13, 2015 21:57
Skeleton Fragment
public class MySkeletonFragment extends Fragment {
// Called when the Fragment is attached to its parent Activity.
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Get a reference to the parent Activity.
}
// Called to do the initial creation of the Fragment.
@moondroid
moondroid / gist:4261389
Created December 11, 2012 19:37
Simple ArrayAdapter
// Create the Array List of to do items
final ArrayList<String> todoItems = new ArrayList<String>();
// Create the Array Adapter to bind the array to the List View
// ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoItems);
// Bind the Array Adapter to the List View
myListView.setAdapter(aa);