This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); | |
// current UNIX time millsecond to yyyy-MM-dd HH:mm:ss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 判斷 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |