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. 高效批量更新 sql 字段的值(从一个表向另一个表更新)

    里给出一种更高效.简洁的做法,批量更新SQL ,一句SQL就可以替代麻烦的循环过程,有MS SQLServer.Oracle.DB2下的写法--关键点:t4和t1是同一个table,primary k ...

  2. 【转载】Xcode6中添加pch文件

    //原文地址:http://www.cnblogs.com/YouXianMing/p/3989155.html 1. 新建工程: 2. 创建pch文件:cmd+n->other->PCH ...

  3. [转载]Matlab中fft与fftshift命令的小结与分析

    http://blog.sina.com.cn/s/blog_68f3a4510100qvp1.html 注:转载请注明出处——by author. 我们知道Fourier分析是信号处理里很重要的技术 ...

  4. ASP.NET,Razor语句中@符号的意义

    比较下面两段代码的区别: <td> @if (item.ModifyTime.HasValue) { @item.ModifyTime.GetValueOrDefault().ToStri ...

  5. 统计字符 比如aaabbcca----3a2b1c1a

    package Demo; import java.util.Scanner; /** * Created by chengpeng on 16/11/3. */ /* idea command+al ...

  6. illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: text/html; charset=utf-8)

    问题描述: 在a.jsp通过<%@ include file="b.jsp" %> 的方式引入b.jsp,但是报了标题的中的错误, 问题原因: 在a.jsp的头部: & ...

  7. 复习篇(一)Activity的生命周期和启动模式

    (一)关于<intent-filter>中的<data> 当设置<data>过滤器的时候,使用intent的时候必须要设置响应的匹配,否则无法匹配成功.不过不设置则 ...

  8. StringBuilder[] 作为数组如何使用

    在工作中突然要用到这个就记录下来. 不知为何我这里的StringBuilder[] 数组必须要指明几个(les)才给用,否则就会报错. int les = 5; StringBuilder[] sb_ ...

  9. python学习day3

    目录: 1.集合set 2.计数器 3.有序字典 4.默认字典 5.可命名元组 6.队列 7.深浅拷贝 8.函数 9.lambda表达式 10.内置函数 一.集合set set是一个无序且不重复的元素 ...

  10. 一个.java文件中可以有几个同级类

    1.在一个.java文件中可以有几个类.修饰符只可以public abstract final和无修饰符,不能是其他的private等修饰符.2.public修饰的只能有一个,且要与文件名相同 若没有 ...