Skip to content

Instantly share code, notes, and snippets.

[way_1]:
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
hhmmss = dateFormat.format(new Date(millis));
[way_2]:
Calendar c = Calendar.getInstance();
c.setTimeInMillis(millis);
int hour = c.get(Calendar.HOUR);
int minute = c.get(Calendar.MINUTE);
@tedzyc
tedzyc / Util.java
Created April 19, 2015 10:40
android上的Util,不依赖第三方库(精心收藏)
package zyc.ta.util;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.RectF;
@tedzyc
tedzyc / TestFragment.java
Created April 5, 2015 13:35
generate Random-Color
Random r = new Random();
v.setBackgroundColor(Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
@tedzyc
tedzyc / CheckForUpdateUtil.java
Created March 18, 2015 06:36
ProgressDialog不显示右边的类似"2/3"的分数
mProgressDialog = new ProgressDialog(mContext, AlertDialog.THEME_HOLO_LIGHT) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Field field = ProgressDialog.class.getDeclaredField("mProgressNumber");
field.setAccessible(true);
TextView.class.getMethod("setVisibility", Integer.TYPE).invoke(field.get(this), View.GONE);
} catch (Exception e) {
@tedzyc
tedzyc / gist:431b4225d602432cd8b3
Last active August 29, 2015 14:17
javah生成函数名(引用android.jar的路径)
javah -d jni\header\ -bootclasspath D:\adt_bundle\sdk\platforms\android-16\android.jar -cp bin\classes\ zyc.as.DemoGLSurfaceView zyc.as.DemoRenderer
@tedzyc
tedzyc / gist:847f6ef6b703d1b83cb2
Last active August 29, 2015 14:17
照片的uri转换为file-path
public staitc String getMediaFilePath(Context context, Uri contentUri) {
Cursor cursor = context.getContentResolver().query(contentUri, null, null, null, null);
cursor.moveToFirst();
String mediaFilePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
cursor.close();
return mediaFilePath;
}
@tedzyc
tedzyc / TSimulateActivity.java
Created January 27, 2015 09:19
手机上原生的图片的uri转换成文件路径
public String getMediaFilePath(Context context, Uri contentUri) {
Cursor cursor = context.getContentResolver().query(contentUri, null, null, null, null);
cursor.moveToFirst();
String mediaFilePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
cursor.close();
return mediaFilePath;
}
@tedzyc
tedzyc / Main.java
Created January 22, 2015 14:14
生成2个维度的随机数(从给定的范围里取值)
import java.util.*;
public class Main {
public static void main(String[] args) {
// final String[] SUBJECTS = {"语文", "数学", "英语", "体育", "物理", "化学", "政治", "地理", "历史", "生物"};
// final String[] TEACHING_MATERIAL_VERSIONS = {"人教版", "苏教版", "北师大版", "湖北教育出版社", "a出版社", "b出版社", "c出版社", "d出版社", "e出版社", "f出版社", "g出版社", "h出版社", "i出版社", "j出版社"};
final String[] SUBJECTS = {"a", "b", "c", "d", "e"};
final String[] TEACHING_MATERIAL_VERSIONS = {"1", "2", "3", "4", "5", "6"};
final Random r = new Random();