Skip to content

Instantly share code, notes, and snippets.

Avatar

Mindaugas Kuprionis mkuprionis

View GitHub Profile
@mkuprionis
mkuprionis / EnumPreference.java
Last active Aug 29, 2015
EnumPreference for Android following u2020 path
View EnumPreference.java
public class EnumPreference<E extends Enum<E>> {
private final SharedPreferences preferences;
private final Class<E> clazz;
private final String key;
private final E defaultValue;
public EnumPreference(SharedPreferences preferences, Class<E> clazz, String key) {
this(preferences, clazz, key, null);
}
@mkuprionis
mkuprionis / BrandListFragment.java
Created Oct 10, 2014
List view with sticky headers and filtering
View BrandListFragment.java
public class BrandListFragment extends BaseFragment {
private static final String ARGS_LOCATION_SPEC = "location_spec";
private LocationSpec location;
@InjectView(R.id.progress) View progress;
@InjectView(R.id.brand_list) StickyListHeadersListView brandList;
@mkuprionis
mkuprionis / README.md
Created May 14, 2014
Embeded ActionBar tabs
View README.md

Copied from Cyril Mottier's post on G+

His comments:

In order to implement tabs I decided to go for an entirely custom solution. I created the tab bar from scratch and added it as a custom ActionBar View. The tabs container is called TabBarView and extends LinearLayout. TabBarView actually handles the "selection strip".

The TabBarView is then filled with several TabView (one for each tab). The main purpose of TabView is to provide a nice API to deal with icon and the optional text (only visible in landscape) and handle the long press gesture (long pressing a tab displays a hint).

Once the TabBarView is initialized with a bunch of TabView, it is added as a custom View to the ActionBar:

@mkuprionis
mkuprionis / DebugApiModule.java
Last active Feb 3, 2016
Retrofit API wrapper to be used when testing with Espresso
View DebugApiModule.java
@Module(
complete = false,
library = true,
overrides = true
)
public final class DebugApiModule {
@Provides @Singleton ApiEndpoint provideApiEndpoint(Locale locale, @ApiEndpointMarker StringPreference apiEndpoint,
@NetworkIgnoreLocale BooleanPreference ignoreLocale) {
return (ignoreLocale.get())
View gist:4084888
# Print file names with line numbers sorted ascending
for f in $(find . -iname "*.java"); do echo $f `(cat $f | wc -l)`; done | sort -k2 -n
# Total line count in directory
for f in $(find . -iname "*.java"); do cat $f; done | wc -l
# Copy files from multiple directories to a single one (filenames contain whitespace)
SAVEIFS=$IFS; IFS=$(echo -en "\n\b"); for f in $(find . -iname "*_new.png"); do cp $f ~/tmp/md/; done; IFS=$SAVEIFS;
# Total changed lines since some date from Git log
@mkuprionis
mkuprionis / Misc.java
Created Aug 30, 2012
Android snippets, tips & tricks
View Misc.java
// Hide keyboard
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(editText.getWindowToken(), 0);
@mkuprionis
mkuprionis / _app.scss
Created Jul 21, 2012
Compass/SASS sprites for different density displays
View _app.scss
@import "_mixins.scss";
@mixin app($dpi) {
header {
position: relative;
header .logo {
// Center in header
@include sprt-box-centered($dpi, logo);
@mkuprionis
mkuprionis / gist:3155322
Created Jul 21, 2012
Flask-Restless with URL rules example
View gist:3155322
# flask-restless.views.API
class API(ModelView):
def get(self, instid, **kwargs):
<...>
self._search(**kwargs)
<...>
def _search(self, **kwargs):
<...>
self._before_search(data, **kwargs)
@mkuprionis
mkuprionis / gist:3155303
Created Jul 21, 2012
Flask-Restless extension example
View gist:3155303
class ProductAPI(API):
def _before_search(self, data):
if not current_user.isAdmin():
if not data.has_key('filters'):
data['filters'] = []
data['filters'].append({
'name': 'sysUserId',
'op': 'equals',
'val': current_user.id
})