Skip to content

Instantly share code, notes, and snippets.

View johnkil's full-sized avatar

Evgenii Shishkin johnkil

View GitHub Profile
@johnkil
johnkil / HttpClientProvider.java
Created April 23, 2012 13:06
HttpClientProvider Source from Pro Android 4
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
@johnkil
johnkil / ViewHoldingAdapter.java
Created April 26, 2012 18:31 — forked from JakeWharton/ViewHoldingAdapter.java
Template for a list adapter which uses a view holder to cache lookups.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh = ViewHolder.get(convertView, parent);
Item item = getItem(position);
vh.title.setText(item.title);
vh.subtitle.setText(item.subtitle);
return vh.root;
}
@johnkil
johnkil / FileExtFilter.java
Created May 18, 2012 09:58
Class for filtering File objects based on specific extension.
package com.mtgclient.util;
import java.io.File;
import java.io.FilenameFilter;
/**
* Class for filtering File objects based on specific extension.
*
* @author e.shishkin
*
@johnkil
johnkil / CheckHeapActivity.java
Created May 29, 2012 09:36
Check heap size on the android device
package com.miz.heapsize;
import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;
public class CheckHeapActivity extends Activity {
private TextView text;
@johnkil
johnkil / AspectRatioImageView.java
Created June 2, 2012 05:13 — forked from JakeWharton/AspectRatioImageView.java
ImageView that respects an aspect ratio applied to a specific measurement.
// Copyright 2012 Square, Inc.
package com.squareup.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
/** Maintains an aspect ratio based on either width or height. Disabled by default. */
public class AspectRatioImageView extends ImageView {
@johnkil
johnkil / AndroidTip.txt
Created June 3, 2012 17:35
30 helpful Android development Tips/Tricks
1) ListView=>Use android:cacheColorHint=”@android:color/transparent” to avoid black highlighting while Scrolling.
2) To resolve this issue “Failed to install *.apk on device timeout Launch canceled! , increase ADB connection timeout
3) use setError() to display error message for your EditText
4) To Block the default animation for startActivity() For ex: myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
5) Android Action Bar Style Generator http://jgilfelt.github.com/android-actionbarstylegenerator
6) create library with reusable code and reference it in future projects.
7) Don’t use right-pointing carets on line items http://developer.android.com/design/media/migrating_ios_settings.png
8) 10 amazing Android development tips http://www.netmagazine.com/features/10-amazing-android-development-tips
9) Define these attributes for displaying multiline EditText => android:singleLine=”false”, android:lines=”5″
10) Follow Dashboard design pattern. Easy to implement and handle Navigation.
/**
* Execute an {@link AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
public <T> void execute(AsyncTask<T, ?, ?> task, T... args) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
@johnkil
johnkil / ScreenShot.java
Created June 19, 2012 16:21
ScreenShot Android Util
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.view.View;
public class ScreenShot {
private final View view;
/** Create snapshots based on the view and its children. */
@johnkil
johnkil / gist:3145466
Created July 19, 2012 17:23
The methods that opens and closes the keyboard
/**
* Shows the keyboard.
*
* @param view
*/
public void showKeyboard(View view) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
@johnkil
johnkil / FileUtils.java
Created August 11, 2012 10:40
Getting external files/cache dir [compatibility]
/**
* Getting external files/cache dir [compatibility].
*
* @author johnkil
*
*/
public class FileUtils {
private static final String LOG_TAG = FileUtils.class.getSimpleName();
/**