摘要: Bundle传递数据的时候,我们会发现传递Serializable集合会抛出IO异常。这个时候我们就必须使用Parcelable包裹类。Message.java:public class Message implements Parcelable{ @DatabaseField(generatedId = true,unique=true) int id; @DatabaseField private String Mid;//消息ID private MessageContent Content;//消息内容 @DatabaseField priva... 阅读全文
posted @ 2013-03-09 17:30 暗殇 阅读(382) 评论(0) 推荐(0) 编辑
摘要: 项目中我们经常会碰到这种情况,开启一个后台Service进行网络请求。当满足我们的条件发送一个广播,通过广播来改变UI。首先:我们应该注册Service和广播:mainfest.xml: <!--Service服务--> <service android:enabled="true" android:name=".service.MyService"> <intent-filter> <action android:name="org.allin.android.musicService" / 阅读全文
posted @ 2013-03-09 17:25 暗殇 阅读(392) 评论(0) 推荐(0) 编辑
摘要: public class PullToRefreshView extends LinearLayout { private static final String TAG = "PullToRefreshView"; // refresh states private static final int PULL_TO_REFRESH = 2; private static final int RELEASE_TO_REFRESH = 3; private static final int REFRESHING = 4; // pull state pr... 阅读全文
posted @ 2013-03-09 17:11 暗殇 阅读(530) 评论(0) 推荐(0) 编辑
摘要: Android系统API Demos提供了伪3D旋转的例子,实现原理都是通过Camera API来进行处理.先附上源码:动画类Rotate3dAnimation:/** * An animation that rotates the view on the Y axis between two specified angles. * This animation also adds a translation on the Z axis (depth) to improve the effect. */public class Rotate3dAnimation extends Animati 阅读全文
posted @ 2013-02-04 13:38 暗殇 阅读(543) 评论(0) 推荐(0) 编辑
摘要: 1.调用系统发短信界面: Intent intent = new Intent(); intent.setAction(Intent.ACTION_SENDTO); intent.setData(Uri.parse("smsto:xxxxxxxxx"));//设置收件人号码 intent.putExtra("sms_body", "reset");//设置短信内容 startActivity(intent);2.调用系统的分享功能: String content ... 阅读全文
posted @ 2013-02-01 12:20 暗殇 阅读(167) 评论(0) 推荐(0) 编辑
摘要: public class ContactPhotoLoader implements Callback { private static final String LOADER_THREAD_NAME = "ContactPhotoLoader"; /** * Type of message sent by the UI thread to itself to indicate that some photos * need to be loaded. */ private static final int MESSAGE_REQUEST_LOADIN... 阅读全文
posted @ 2013-01-30 16:30 暗殇 阅读(1211) 评论(0) 推荐(0) 编辑
摘要: 短信信息都储存在系统的数据库中,如果我们想获取相关信息需要根据URI进行查找操作.定义一个实体接收类SmsInfo.java:public class SmsInfo { private String smsbody;//短信内容 private String phoneNumber;//发送短信的电话号码 private String date;//发送短信的日期和时间 private String name;//发送者的名字 private String type;//短信类型 1 接收到的 2 已发出的 public SmsInfo... 阅读全文
posted @ 2013-01-26 10:36 暗殇 阅读(440) 评论(0) 推荐(0) 编辑
摘要: 1.Canvas上以一定收缩比例贴一张图 headBgBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.class_bg_sha1); headBmp = Bitmap.createBitmap(view.getWidth(),headBgBmp.getHeight(),Config.ARGB_8888); Canvas canvas2 = new Canvas(headBmp); Matrix matrix = new Matrix(); float xScale = (f... 阅读全文
posted @ 2013-01-23 14:00 暗殇 阅读(882) 评论(0) 推荐(0) 编辑
摘要: GestureDetector是系统提供的一个监听手势在屏幕操作的类.使用方法也挺简单,首先我们应该初始化GestureDetector对象: mGesture = new GestureDetector(this, new GestureListener());GestureListener类: class GestureListener extends SimpleOnGestureListener { //滑动的监听 @Override public boolean onFling(MotionEvent e1, MotionEvent e... 阅读全文
posted @ 2013-01-14 14:55 暗殇 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 有的时候,当我们项目中使用到WebView载入一些网页信息并对它做了一个记忆处理的话。我们点注销,就需要清空WebView的缓存。 private void clearWebView(){ File file = CacheManager.getCacheFileBaseDir(); if (file != null && file.exists() && file.isDirectory()) { for(File item : file.listFiles()) { item.delete(); ... 阅读全文
posted @ 2013-01-11 17:11 暗殇 阅读(2761) 评论(0) 推荐(0) 编辑
摘要: /** 创建MENU */ public boolean onCreateOptionsMenu(Menu menu) { menu.add("menu");// 必须创建一项 return super.onCreateOptionsMenu(menu); } /** 拦截MENU */ public boolean onMenuOpened(int featureId, Menu menu) { initPopuWindow(); return false;// 返回为tru... 阅读全文
posted @ 2012-12-08 10:47 暗殇 阅读(251) 评论(0) 推荐(0) 编辑
摘要: /** * @author gongchaobin * * 圆 * @version 2012-12-5 */public class RingView extends View { private Paint paint; private Context context; private int radius;//半径 private int color;//颜色值 public RingView(Context context) { // TODO Auto-generated constructor stub ... 阅读全文
posted @ 2012-12-05 16:42 暗殇 阅读(1475) 评论(0) 推荐(0) 编辑
摘要: /** * @author gongchaobin * * LruCache缓存Bitmap * (基于内存的缓存,读取时间比较快) */public class LruCacheUtil { private static final String TAG = LruCacheUtil.class.getSimpleName(); private int memClass; private LruCache<String,Bitmap> mMemoryCache;//高速缓存(系统) public static final String BITMAP = "bitma.. 阅读全文
posted @ 2012-12-04 10:51 暗殇 阅读(247) 评论(0) 推荐(0) 编辑
摘要: public class FileUtil { /** * 删除某个目录 * * @param srcDir 目录地址 * @throws IOException */ public static void deleteDir(String srcDir) throws IOException{ File file = new File(srcDir); if (!file.exists()) return; File files[] = file.listFiles(); ... 阅读全文
posted @ 2012-12-04 10:33 暗殇 阅读(429) 评论(0) 推荐(0) 编辑
摘要: CrashHandler.java:public class CrashHandler implements UncaughtExceptionHandler { public static final String TAG = "CrashHandler"; //系统默认的UncaughtException处理类 private Thread.UncaughtExceptionHandler mDefaultHandler; //CrashHandler实例 private static CrashHandler INSTANCE = new ... 阅读全文
posted @ 2012-12-03 17:28 暗殇 阅读(378) 评论(0) 推荐(0) 编辑
摘要: /** * @author gongchaobin * * Bitmap工具类 */public class BitmapUtil { /** * 以最省内存的方式读取本地资源的图片 或者SDCard中的图片 * * @param imagePath 图片在SDCard中的路径 * @return */ public static Bitmap getSDCardImg(String imagePath){ BitmapFactory.Options opt = new BitmapFactory.Options(); ... 阅读全文
posted @ 2012-11-30 17:56 暗殇 阅读(517) 评论(0) 推荐(0) 编辑
摘要: Hello.java:public class Hello{ @DatabaseField(generatedId = true,unique=true) int id; @DatabaseField String word; //这是必须加的,否则会出错 public Hello(){} public int getId() { return id; } public Hello(String word) { super(); this.word = word; } pub... 阅读全文
posted @ 2012-11-12 11:08 暗殇 阅读(282) 评论(0) 推荐(0) 编辑
摘要: AsyncDataLoader.java:/** * 异步加载后台数据 * @author gongchaobin * * @version 2011-12-19 */public class AsyncDataLoader extends AsyncTask<Object, Void, Object> { private Dialog loadingDialog; private Context mContext; private List<Object> paramsList = null; private String urlFlag; private i... 阅读全文
posted @ 2012-11-07 15:05 暗殇 阅读(359) 评论(0) 推荐(0) 编辑
摘要: /** * @author gongchaobin * * 日志管理 * [统一管理日志,包括各种级别的日志] */public class Log { /** * 控制日志开关 */ private static boolean LogSwitch = true; /** * 打印verbose级别的日志 * * @param tag 标记 * @param text 日志内容 */ public static void verbose(String tag, String text) ... 阅读全文
posted @ 2012-11-07 10:30 暗殇 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 异步下载类: class DownloadTask extends Thread{ private int blockSize, downloadSizeMore; private int threadNum = 5; String urlStr, threadNo, fileName; /** * @param urlStr 下载的URL * @param threadNum 下载的线程数 * @param fileName 文件名 */ public... 阅读全文
posted @ 2012-11-05 14:26 暗殇 阅读(317) 评论(0) 推荐(0) 编辑