Skip to content

Instantly share code, notes, and snippets.

import java.util.ArrayList;
import java.util.Collection;
import java.util.*;
public class ArrayList_LinkedList {
public static final String filePath = "D:/MP";
public static void main(String[] args) {
Collection collection = new ArrayList();
@easternHong
easternHong / producer_consumer.java
Last active August 29, 2015 14:07
生产者,消费者模型,主要考虑线程同步(syncrhonized wait notify的使用
//1.消费者,生产者都要实现Runnable接口
//2.要有一个消费的对象,如:面包
//3.模拟一个栈的操作方式,先进后出
//4.线程同步,synchronized,notify,wait
public class AJava {
@easternHong
easternHong / ServiceRunning?
Created October 6, 2014 02:37
checkService running or not
/**
* 判断服务是否启动
*
* @param className
* @return
*/
private boolean checkServiceRunning(String className) {
boolean isRunning = false;
ActivityManager am = (ActivityManager) this
.getSystemService(Context.ACTIVITY_SERVICE);
@easternHong
easternHong / startService self
Created October 6, 2014 03:05
protect Service
private void startSelfService() {
// 获得系统级别服务
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent in = new Intent(this, this.getClass());
PendingIntent pin = PendingIntent.getService(this, 0, in,
PendingIntent.FLAG_UPDATE_CURRENT);
// 返回系统开机到现在的时间差
long timePeriod = SystemClock.elapsedRealtime();
// ELAPSED_REALTIME =3s
am.setRepeating(AlarmManager.ELAPSED_REALTIME, timePeriod, 3 * 1000,
@easternHong
easternHong / styleprogressbar
Created October 7, 2014 07:44
beautiful progressbar
package net.canking.myanimtest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@easternHong
easternHong / DoubleTap.java
Created October 7, 2014 16:36
onTouch_DoubleTap
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (MotionEvent.ACTION_DOWN == event.getAction()) {
if (mCurrentDownEvent != null
&& mPreviousUpEvent != null
&& isConsiderAsDoubleTap(mCurrentDownEvent,
mPreviousUpEvent, event)) {
}
mCurrentDownEvent = MotionEvent.obtain(event);
@easternHong
easternHong / LRU_test.java
Created October 14, 2014 14:57
LRU——使用
private final BitmapCache mMemoryCache;
//一般在构造函数实现
mMemoryCache = new BitmapCache();
private Bitmap getBitmapFromMemCache(final int key) {
return mMemoryCache.get(key);
}
private void addBitmapToMemoryCache(final int key, final Bitmap bitmap) {
@easternHong
easternHong / test.java
Created October 16, 2014 12:22
get_package_info
@Override
protected List<AppInfo> doInBackground(Void... params) {
// TODO Auto-generated method stub
List<AppInfo> list = new ArrayList<AppInfo>();
// 获取系统所有的应用
List<PackageInfo> appList = mContext.getPackageManager()
.getInstalledPackages(PackageManager.GET_META_DATA);
// 获取应用主activity
for (PackageInfo p : appList) {
// user app
@easternHong
easternHong / test.java
Created October 16, 2014 15:56
update_listview_item
public void updateItemView(final int index, Object o) {
int visibleposition = mlist.getFirstVisiblePosition();
View view = mlist.getChildAt(index - visibleposition);
TextView tView = (TextView) view.findViewById(R.id.item_define_word);
tView.setText((String) o);
}
@easternHong
easternHong / test.java
Created October 21, 2014 11:15
使用IMAGE_CACHE,大幅度提升ListView GridView性能
package com.hunt.listviewdemo;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.LayoutInflater;