Skip to content

Instantly share code, notes, and snippets.

View vizhen's full-sized avatar

Jun Tan vizhen

View GitHub Profile
@vizhen
vizhen / FileUtils.java
Created February 10, 2014 12:58
格式化文件大小
/**
* 文件大小格式转换
* @param fileS 文件大小
* @return 文件大小
*/
public static String FormatFileSize(long fileS)
{
// 转换文件大小
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
@vizhen
vizhen / gbk2utf
Created February 21, 2014 05:51
Linux GBK to UTF-8
把 1.txt 从 gbk 转成 utf-8 并保存为 2.txt
iconv -f gbk -t utf-8 1.txt > 2.txt
@vizhen
vizhen / gist:9771906873508624cbba
Created May 13, 2014 08:31
APK广播监听设备挂载事件注意需要加上scheme
<receiver
android:name="com.talentstech.mediaboardusbupdate.DiskMountReceiver">
<intent-filter >
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<action android:name="android.intent.action.MEDIA_EJECT"/>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<data android:scheme="file"/>
</intent-filter>
</receiver>
package com.thoughtmonkeys.pitstop;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* 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
@vizhen
vizhen / 打开android wifi调试
Created January 4, 2013 02:21
需要系统能root,并在终端模拟器中执行
$su
#setprop service.adb.tcp.port 5555
#stop adbd
#start adbd
@vizhen
vizhen / 待机
Created January 19, 2013 06:53
Android设备sleep,好像学要系统权限
PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
pm.goToSleep(SystemClock.uptimeMillis());
@vizhen
vizhen / Android TextView渐变效果
Created April 12, 2013 01:48
Android中给TextView加渐变
Shader shader = new LinearGradient(0, 0, 0, 100, Color.BLUE, Color.GREEN, Shader.TileMode.REPEAT);
textView.getPaint().setShader(shader);
@vizhen
vizhen / convertToBlur.java
Created May 10, 2013 08:43
Android图片高斯效果
public static Bitmap convertToBlur(Bitmap bmp) {
// 高斯矩阵
int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1 };
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap newBmp = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
int pixR = 0;
@vizhen
vizhen / MusicLyrcUtil.java
Created January 16, 2014 05:59
获取文本文件编码格式
public String GetCharset(File file) {
String charset = "GBK";
byte[] first3Bytes = new byte[3];
try {
boolean checked = false;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
bis.mark(0);
int read = bis.read(first3Bytes, 0, 3);
if (read == -1)
return charset;