Skip to content

Instantly share code, notes, and snippets.

package com.feizan.android.snowball.ui.imageview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
/**
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class DynamicImageView extends ImageView {
public DynamicImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
public class JsonHelper {
public static Object toJSON(Object object) throws JSONException {
if (object instanceof Map) {
JSONObject json = new JSONObject();
@brandhill
brandhill / ScrimUtil.java
Created November 26, 2014 10:37
Better gradient scrims
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.util.FloatMath;
import android.view.Gravity;
@brandhill
brandhill / gist:6587d02bd88b95b44668
Created February 3, 2015 09:08
Android 的 Bitmap 轉成 Base64 並存入 SQLite 資料庫的方法
//Android的Bitmap轉成Base64並存入資料庫的方法
// 先把 bitmpa 轉成 byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream );
byte bytes[] = stream.toByteArray();
// Android 2.2以上才有內建Base64,其他要自已找Libary或是用Blob存入SQLite
String base64 = Base64.encodeToString(bytes, Base64.DEFAULT); // 把byte變成base64
// 再來是轉回來, 把Base64變回bytes
@brandhill
brandhill / TimeFormatConverter.java
Last active August 29, 2015 14:16
Time Format Converter
String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
// current UNIX time millsecond to yyyy-MM-dd HH:mm:ss
@brandhill
brandhill / SymmetricTreeQueue.java
Created December 6, 2015 16:35 — forked from b27lu/SymmetricTreeQueue.java
iteratively solution of Symmetric Tree at LeetCode
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@brandhill
brandhill / Utils.java
Last active February 1, 2016 10:19
常用的 utility functions
// 判斷 app 是否有安裝
private static boolean isPkgInstalled(Context context, String pkgName) {
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(pkgName, 0);
} catch (PackageManager.NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
@brandhill
brandhill / EachDirectoryPath.md
Created March 21, 2016 04:15 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@brandhill
brandhill / debug_push.py
Created November 16, 2016 06:56
Test APN push notification certificates (PEM key)
# How do I test my APN push notification certificates (PEM key)?
# https://www.pubnub.com/knowledge-base/discussion/234/how-do-i-test-my-pem-key
# You can test your PEM key using the following command, which should hang if successful until you press enter:
# openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert pnpush.pem -key pnpush.pem
# The above tests the PEM Key in sandbox mode. For production mode, use the following command:
# openssl s_client -connect gateway.push.apple.com:2195 -cert pnpush.pem -key pnpush.pem
# You can also test your PEM Key by running the Python script below using the script below. The usage would be:
# python push_debug.py <CERT_PATH> <DEVICE_TOKEN>