Skip to content

Instantly share code, notes, and snippets.

View miva2's full-sized avatar

Michael Vandendriessche miva2

  • Oncomfort
  • Belgium
View GitHub Profile
@miva2
miva2 / BaseActvity.java
Created September 23, 2015 09:28
Snippet of a BaseActivity class extended by child Activities. Makes it simpler to switch fragments in the same Activity if the setup is always the same. Removes repetition.
protected void switchToFragment(Fragment fragment) {
switchToFragment(fragment, false, null);
}
protected void switchToFragment(Fragment fragment, boolean addToBackStack, String tag) {
if (fragment != null) {
FragmentTransaction transaction = getFragmentManager().beginTransaction().replace(R.id.container, fragment);
if (addToBackStack) { transaction.addToBackStack(tag); }
@miva2
miva2 / onBackPressed.java
Created September 8, 2015 13:35
onBackPressed in FragmentActivity
/**
* Take care of popping the fragment back stack or finishing the activity
* as appropriate.
*/
public void onBackPressed() {
if (!mFragments.popBackStackImmediate()) {
supportFinishAfterTransition();
}
}
@miva2
miva2 / gist:a0cf8b7f50d5132df1d2
Created August 14, 2015 10:25
toolbar bullshit
android.support.v7.app.ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
Toolbar toolBar = (Toolbar) getActivity().findViewById(R.id.toolbar);
Log.d("DEBUG VERSIONFRAGMENT", "Actionbar: " + actionBar);
if (toolBar != null) {
toolBar.setBackgroundColor(getResources().getColor(R.color.red_background));
toolBar.setTitle("TEMPORARY TITLE");
toolBar.setTitleTextColor(R.color.white);
Log.d("DEBUGG VERSIONFRAGMENT", (String) toolBar.getTitle());
}
@miva2
miva2 / cson.js
Created December 23, 2014 10:52
Atom files for fixing startup issue - https://github.com/atom/atom-keymap/issues/62
(function() {
var CoffeeScript, crypto, csonCache, fs, getCachePath, multiplyString, parseContents, parseContentsSync, parseObject, path, stringifyArray, stringifyBoolean, stringifyIndent, stringifyNull, stringifyNumber, stringifyObject, stringifyString, writeCacheFile, writeCacheFileSync, _;
crypto = require('crypto');
path = require('path');
_ = require('underscore-plus');
fs = require('fs-plus');