Skip to content

Instantly share code, notes, and snippets.

/**
* Copyright 2013 Bo Wang
*
* 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
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 / gist:05a0177ddcee3fd44500
Last active January 30, 2023 09:48
Android Read Assets file as string
private String loadAssetTextAsString(Context context, String name) {
BufferedReader in = null;
try {
StringBuilder buf = new StringBuilder();
InputStream is = context.getAssets().open(name);
in = new BufferedReader(new InputStreamReader(is));
String str;
boolean isFirst = true;
while ( (str = in.readLine()) != null ) {
@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 / 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 / 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 {