1、使用TransitionDrawable实现渐变效果 

  

private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
// Use TransitionDrawable to fade in.
final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) });
//noinspection deprecation
imageView.setBackgroundDrawable(imageView.getDrawable());
imageView.setImageDrawable(td);
td.startTransition(200);
} 比使用AlphaAnimation效果要好,可避免出现闪烁问题。

2、 扫描指定的文件 

  

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));

    用途:从本软件新增、修改、删除图片、文件某一个文件(音频、视频)需要更新系统媒体库时使用,不必扫描整个SD卡。

3、Dip转px

  

 public static int dipToPX(final Context ctx, float dip) {
return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, ctx.getResources().getDisplayMetrics());
} 用途:难免在Activity代码中设置位置、大小等,本方法就很有用了! 

4、获取已经安装APK的路径

  

PackageManager pm = getPackageManager();

    for (ApplicationInfo app : pm.getInstalledApplications()) {
Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
}
输出如下:
     package: com.tmobile.thememanager, sourceDir: /system/app/ThemeManager.apk
package: com.touchtype.swiftkey, sourceDir: /data/app/com.touchtype.swiftkey-1.apk

5、 多进程Preferences数据共享

  

public static void putStringProcess(Context ctx, String key, String value) {
SharedPreferences sharedPreferences = ctx.getSharedPreferences("preference_mu", Context.MODE_MULTI_PROCESS);
Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
} public static String getStringProcess(Context ctx, String key, String defValue) {
SharedPreferences sharedPreferences = ctx.getSharedPreferences("preference_mu", Context.MODE_MULTI_PROCESS);
return sharedPreferences.getString(key, defValue);
}

相关文章:

http://zengrong.net/post/1687.htm

6、泛型ArrayList转数组

  

  @SuppressWarnings("unchecked")
public static <T> T[] toArray(Class<?> cls, ArrayList<T> items) {
if (items == null || items.size() == 0) {
return (T[]) Array.newInstance(cls, 0);
}
return items.toArray((T[]) Array.newInstance(cls, items.size()));
}

7、 保存恢复ListView当前位置

private void saveCurrentPosition() {
if (mListView != null) {
int position = mListView.getFirstVisiblePosition();
View v = mListView.getChildAt(0);
int top = (v == null) ? 0 : v.getTop();
//保存position和top
}
} private void restorePosition() {
if (mFolder != null && mListView != null) {
int position = 0;//取出保存的数据
int top = 0;//取出保存的数据
mListView.setSelectionFromTop(position, top);
}
} 可以保存在Preference中或者是数据库中,数据加载完后再设置。

8、调用 便携式热点和数据共享 设置

  

public static Intent getHotspotSetting() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
ComponentName com = new ComponentName("com.android.settings", "com.android.settings.TetherSettings");
intent.setComponent(com);
return intent;
}

9、 格式化输出IP地址

 public static String getIp(Context ctx) {
return Formatter.formatIpAddress((WifiManager) ctx.getSystemService(Context.WIFI_SERVICE).getConnectionInfo().getIpAddress());
}

10、 文件夹排序(先文件夹排序,后文件排序)

public static void sortFiles(File[] files) {
Arrays.sort(files, new Comparator<File>() { @Override
public int compare(File lhs, File rhs) {
//返回负数表示o1 小于o2,返回0 表示o1和o2相等,返回正数表示o1大于o2。
boolean l1 = lhs.isDirectory();
boolean l2 = rhs.isDirectory();
if (l1 && !l2)
return -1;
else if (!l1 && l2)
return 1;
else {
return lhs.getName().compareTo(rhs.getName());
}
}
});
}

参考:http://www.cnblogs.com/over140/archive/2013/05/20/2948239.html

Android_CodeWiki_02的更多相关文章

随机推荐

  1. S - stl 的mapⅠ

    先来介绍一下stl中的map这个功能 头文件#include<map> map是STL的一个关联容器,它提供一对一的数据处理能力 就像一个人对应一个编号一样 定义 为  map<in ...

  2. linux学习笔记之硬盘分区

    引用:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/03/2997098.html PS:本文仅对知识点作总结.详情请参考原文. 首先 ...

  3. SSM三大框架整合详细教程

    使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没有记录SSM整合 ...

  4. BottomSheetBehavior 之 java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior

    AndroidRuntime: FATAL EXCEPTION: main Process: me.chunsheng.uberdriver, PID: 13674 java.lang.Runtime ...

  5. Moodle的qq登录版块的使用

    在这篇Moodle的qq登录(QQ登陆)版块的使用教程中,我们假定你已经有了一个有域名,外网能访问的Moodle2.4+网站,并且数据库使用的是mysql. 我们将提供Moodle的QQ登录版块的下载 ...

  6. Max Num---hdu2071

    Max Num Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. 回文数猜想(hd1282)

    回文数猜想 Problem Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数.任取一个正整数,如果不是回文数,将该数与他的倒序 ...

  8. docker 镜像管理

    docker:/root# docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official bui ...

  9. c++优先级

    蒟蒻连c++的运算优先级都搞不清楚QAQ 转载自http://www.cnblogs.com/chenglei/archive/2009/08/03/1537822.html C++优先级列表 Pre ...

  10. HDU1181 变形课 (回溯法)

    变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submis ...