Skip to content

Instantly share code, notes, and snippets.

Avatar

Yuriy Yunikov yyunikov

View GitHub Profile
@yyunikov
yyunikov / UncaughtExceptionFilter.java
Last active Aug 29, 2015
Java: filter for handling and logging uncaught exceptions
View UncaughtExceptionFilter.java
/**
* Filter for handling and logging uncaught exceptions.
*/
@WebFilter(filterName="UncaughtExceptionFilter", urlPatterns = {"/*"})
public class UncaughtExceptionFilter implements Filter {
private static final Logger LOGGER = Logger.getLogger(UncaughtExceptionFilter.class);
@Override
public void doFilter(ServletRequest request, ServletResponse response,
@yyunikov
yyunikov / .gitignore
Created Oct 26, 2014
Android: .gitignore
View .gitignore
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@yyunikov
yyunikov / KeyboardUtils.java
Last active Aug 29, 2015
Android: some utilities for working with keyboard
View KeyboardUtils.java
public final class KeyboardUtils {
private KeyboardUtils(){}
public static void hideSoftKeyboard(final Activity activity)
{
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (activity.getWindow() != null && activity.getWindow().getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(activity.getWindow().getCurrentFocus().getWindowToken(), 0);
@yyunikov
yyunikov / DaoMaster.java
Last active Aug 29, 2015
Android: example of working with SQLite database from /assets folder
View DaoMaster.java
public abstract class DaoMaster<T extends Entity> {
protected SQLiteDatabase mSQLiteDatabase;
protected Context mContext;
public DaoMaster(final Context context, final SQLiteDatabase sqLiteDatabase) {
mSQLiteDatabase = sqLiteDatabase;
mContext = context;
}
@yyunikov
yyunikov / AsyncGenericLoader.java
Created Oct 26, 2014
Android: example implementation of Loader for generics
View AsyncGenericLoader.java
/**
* An {@link AsyncTaskLoader} implementation for loading objects like entities, cursors, etc.
* which takes care of delivering and reseting results. For Cursors you need to override
* onReleaseResources and perform all kind there, e.g. call close() method.
*/
public abstract class AsyncGenericLoader<T> extends AsyncTaskLoader<T> {
protected T mItems;
public AsyncGenericLoader(final Context context) {
@yyunikov
yyunikov / FontsOverride.java
Last active Mar 2, 2017
Android: overriding default fonts
View FontsOverride.java
/*
* Copyright 2014 Yuriy Yunikov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@yyunikov
yyunikov / SearchViewFormatter.java
Last active Aug 29, 2015
Android: formatting search view and it's icons
View SearchViewFormatter.java
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.TextView;
View Android Lollipop Widget Tinting Guide
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21. To use the support version of these attributes, remove the android namespace. For instance, "android:colorControlNormal" becomes "colorControlNormal". These attributes will be propagated to their corresponding attributes within the android namespace for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
* ripple effect (Lollipop only) -- "colorControlHighlight"
Status Bar:
------------
* background (Lollipop only) - "colorPrimaryDark"
@yyunikov
yyunikov / Hostname.java
Created Jan 15, 2015
Getting machine's hostname
View Hostname.java
public class SystemUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(SystemUtils.class);
private static final String HOSTNAME_VARIABLE = "HOSTNAME";
private static final String HOSTNAME_COMMAND = "hostname";
private SystemUtils() {}
@yyunikov
yyunikov / HttpClientUtils.java
Created Jan 15, 2015
Usage of Apache Http Client
View HttpClientUtils.java
public final class HttpClientUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtils.class);
private static final int CONNECTION_TIMEOUT = 10000;
private HttpClientUtils() {
}
/**