Skip to content

Instantly share code, notes, and snippets.

@john990
john990 / SelectImage.java
Created March 27, 2015 06:54
android select image from gallery or camera, and crop
private String cameraFileName;
@Override
public void choiceAvatarFromCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraFileName = Constants.DOWNLOAD_IMAGE_PATH + System.currentTimeMillis();
File file = new File(Constants.DOWNLOAD_IMAGE_PATH);
if(!file.exists()){
file.mkdirs();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(cameraFileName)));
/**
* Attempts to get the ViewHolder for the given position, either from the Recycler scrap,
* cache, the RecycledViewPool, or creating it directly.
* <p>
* If a deadlineNs other than {@link #FOREVER_NS} is passed, this method early return
* rather than constructing or binding a ViewHolder if it doesn't think it has time.
* If a ViewHolder must be constructed and not enough time remains, null is returned. If a
* ViewHolder is aquired and must be bound but not enough time remains, an unbound holder is
* returned. Use {@link ViewHolder#isBound()} on the returned object to check for this.
*
@john990
john990 / update_language.java
Created March 19, 2014 08:58
android change app language.
// 设置时调用一次,程序启动时调用一次
private static void updateActivity(String locate, Context context) {
// 本地语言设置
Locale myLocale = new Locale(locate);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
// 更新全局Configuration
res.updateConfiguration(conf, dm);
@john990
john990 / PrintChar.java
Last active March 20, 2018 06:57
线程间通信,wait、notify的使用
package com.java.test.thread;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by John on 18/3/19.
* 使用三个线程使得ABC 循环输出十次
*/
public class PrintABC {
@john990
john990 / FlipAnimation.java
Created November 24, 2014 09:24
rotate 3d animation
package com.dianxinos.wifimgr.widget;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.Transformation;
@john990
john990 / Upload.java
Created February 19, 2016 06:42
android upload file
public String commonUpload(Context cxt, String url, Map<String, String> params,
List<UploadFile> uploadFiles, Map<String, String> properties, String encoding) throws IOException {
// 定义POST体中分割线
String BOUNDARY = "124324471239807512395795";
String PREFIX = "--";
String ENDLINE = "\r\n";
String CONTENT_TYPE = "multipart/form-data";
// long contentLen = 0;
// 1. 拼接HTTP 请求头
HttpURLConnection httpConn = NetworkUtils.openHttpURLConnection(cxt, url);
@john990
john990 / flaskwithcron.py
Created January 24, 2016 03:25 — forked from chadselph/flaskwithcron.py
flask with "cron"-like loop
from flask import Flask, render_template, jsonify, request
from threading import Timer, Thread
from time import sleep
app = Flask(__name__)
@app.route("/api/<method>")
def api(method):
data = {
@john990
john990 / BeanUtil.java
Last active January 3, 2016 02:39
从cursor中提取bean 列表(反射的使用)
package com.android.orm;
import android.database.Cursor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
package com.demo.view;
import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
public class AutoLoadAdapter<T> extends BaseAdapter {
java.util.Timer timer = new java.util.Timer(true);
// true 说明这个timer以daemon方式运行(优先级低,
// 程序结束timer也自动结束),注意,javax.swing
// 包中也有一个Timer类,如果import中用到swing包,
// 要注意名字的冲突。
TimerTask task = new TimerTask() {
public void run() {
... //每次需要执行的代码放到这里面。
}