Skip to content

Instantly share code, notes, and snippets.

View yyunikov's full-sized avatar

Yuriy Yunikov yyunikov

View GitHub Profile
@yyunikov
yyunikov / HttpClientUtils.java
Created January 15, 2015 14:59
Usage of Apache Http Client
public final class HttpClientUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientUtils.class);
private static final int CONNECTION_TIMEOUT = 10000;
private HttpClientUtils() {
}
/**
@yyunikov
yyunikov / Hostname.java
Created January 15, 2015 14:52
Getting machine's hostname
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() {}
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 / SearchViewFormatter.java
Last active August 29, 2015 14:12
Android: formatting search view and it's icons
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;
@yyunikov
yyunikov / FontsOverride.java
Last active March 2, 2017 14:39
Android: overriding default fonts
/*
* 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 / AsyncGenericLoader.java
Created October 26, 2014 17:09
Android: example implementation of Loader for generics
/**
* 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 / DaoMaster.java
Last active January 2, 2024 02:27
Android: example of working with SQLite database from /assets folder
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 / KeyboardUtils.java
Last active August 29, 2015 14:08
Android: some utilities for working with keyboard
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 / .gitignore
Created October 26, 2014 16:32
Android: .gitignore
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@yyunikov
yyunikov / UncaughtExceptionFilter.java
Last active August 29, 2015 14:08
Java: filter for handling and logging uncaught exceptions
/**
* 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,