Skip to content

Instantly share code, notes, and snippets.

@coreform
coreform / gist:36ed98f98668f2e90c6a
Last active August 29, 2015 14:13
An AppCompat (i.e. uses startSupportActionMode method) solution for modifying the Contextual Action Bar (CAB) done button image, while reinstating it so that Text Selection behaviour remains as per normal. This example will replace the normal back/up icon for a tick icon when an ActionMode is created by the app and reinstate the back/up icon whe…
Drawable mDefaultActionModeDoneDrawable; //used to cache the original doneButton drawable so it can be reinstated to provide TextSelection as per normal
void customiseActionModeDoneButton(boolean showTick) {
//updated for AppCompat, based on http://stackoverflow.com/questions/6556116/how-can-i-customize-the-action-modes-color-and-text
if(showTick) {
mHandler.post(new Runnable() {
@Override
public void run() {
int doneButtonId = R.id.action_mode_close_button;
View v = findViewById(doneButtonId);
@coreform
coreform / ExtrinsicData
Created December 4, 2014 04:57
An interface providing lifecycle callbacks useful for Cupboard POJOs that are populated from external JSON data
public interface ExtrinsicData {
public void onParse(Context context, JSONObject jsonObject, Bundle relatingData);
public void onPostPopulated(Context context);
public void onPreSaved(Context context);
public void onPostSaved(Context context);
public void onPreRead(Context context);
public void onPostRead(Context context);
}
@coreform
coreform / getDayOfMonthSuffix
Last active December 28, 2015 13:08
Get the day of month suffix in Android, e.g. "1st September, 2013", "1er Septembre 2013", "13th Jan".
public static String getDayOfMonthSuffix(final int n) {
if(n < 1 || n > 31) {
//invalid day of month
return "";
}
String language = Locale.getDefault().getLanguage();
if ("en".equals(language)) {
if (n >= 11 && n <= 13) {
return "th";
}
@coreform
coreform / gist:4357728
Last active December 10, 2015 01:18
Android YouTube API with ActionBarSherlock (via SherlockFragmentActivity). Because the existence of youTubeBaseActivity would have you think the API is missing a YouTubeBaseFragmentActivity and youTubeBaseSupportFragmentActivity.
public class YouTubeExampleFragmentActivity extends SherlockFragmentActivity implements YouTubePlayer.OnInitializedListener {
private static final String mDeveloperKey = null; //make sure to change this to your project's API key
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_console);