
Android
文章平均质量分 60
代码_李
这个作者很懒,什么都没留下…
展开
-
Image Gauss blur
public static Bitmap getBlurBitmap(Bitmap bitmap, Context context, float blurDepth) { // Create a smaller bitmap and blur this smaller bitmap to get better result. Bitmap resampledBitmap = resampleBit原创 2017-03-07 21:47:02 · 337 阅读 · 0 评论 -
Define enum in xml and use it in another xml
1. 定义enum_shape_type.xml <enum n定义enum_shape_type.xml ame="Circle" value="2"/> 2. 在attr_shaped_image.xml中使用原创 2017-03-14 19:45:18 · 225 阅读 · 0 评论 -
Set a customized attr in style file
225dp 154dp centerCrop @color/light_gray Rectangle //直接通过名字,不要加namespace 3dp原创 2017-03-14 19:50:47 · 229 阅读 · 0 评论 -
layout中使用自定义的view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="m原创 2017-03-14 19:52:12 · 302 阅读 · 0 评论 -
Canvas & Paint & Shader & Bitmap
Bitmap bitmap = Bitmap.create(...) // 画框的布 Canvas canvas = new Canvas(bitmap) // 整个画框,包含画布 Paint paint = new Paint(); // 画笔 BitmapShader shader = new BitmapShader(); // 颜料 paint.setShader(shader)原创 2017-03-14 20:50:22 · 552 阅读 · 0 评论 -
Activity life cycle
1. Key life cyle: onCreate(Bundle savedBundleInstance) -> onStart()-> onResume() -> onPause() -> onStop() -> onDestory() 2. Save status: there are two methods you can use to save state: * onSaveI原创 2017-03-14 20:52:17 · 441 阅读 · 0 评论 -
Activity launch mode
Standard: start a activity and add to the top of task stack.Single Top: If start an activity with this mode, and system find the top of task stack is this kind acvivity, system will reuse the top acti原创 2017-03-14 20:55:34 · 282 阅读 · 0 评论 -
Plug-in(1) 动态加载机制研究学习笔记
原文:http://blog.youkuaiyun.com/singwhatiwanna/article/details/22597587 要解决的问题:不安装APK,但希望加载APK当中的activity,service等组件,或者其中的resource 背景知识:Dex可以被Dalvik直接加载,APK包含Dex,所以也可以被Dalvik加载 主要用到的API: Dex原创 2017-03-23 22:39:49 · 284 阅读 · 0 评论 -
AIDL
AIDL文件主要的作用是帮助我们生成Binder类。Binder类是进程间通信的核心,在Android开发中,Binder主要用在service中,包括AIDL和Messenger。(普通的service并不涉及进程间通信的问题) 在AIDL文件中,并不使所有的数据类型可以使用,支持数据类型如下: 基础数据类型String和CahrsequenceParcelable类型ArrayLi原创 2017-03-14 22:37:43 · 224 阅读 · 0 评论 -
Messenger
Messenger is based on AIDL. There are several key elements: IMessenger, this interface is same as the interface generated by specific AIDL. It has an inner class of Stub. and contains a member fu原创 2017-03-15 22:25:58 · 326 阅读 · 0 评论 -
Inflate layout file in customized view
// Use inflater to infalte in the constructor. public CategoryIconView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.view_category原创 2017-03-16 20:40:03 · 305 阅读 · 0 评论 -
Define and use ripple
// Define a xml in drawable folder ripple_gray.xml: <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/gray"> --> // 如果不要这个行, 则ripple效果溢出原创 2017-03-16 20:40:53 · 193 阅读 · 0 评论 -
Intent filter
只用于隐式匹配,显示调用和filter没关系 Action: intent必须要添加至少一个Action,intent中有任意一个Action和filter中的Action匹配(全字符匹配),那么就能匹配 Category: intent中所有的category和filter匹配,那么才可以匹配。系统给所有的intent添加一个default category,所以一个activity想被隐原创 2017-03-16 20:42:32 · 411 阅读 · 0 评论 -
Service
Service的几个比较重要的生命周期函数 onCreateonStartCommandonBindonUnbindonRebindonDestory Start service: 必须以显式的方式调用 context.startService(intent) bind service 实现一个继承Binder的类, the binder should be able to原创 2017-03-16 20:43:38 · 517 阅读 · 0 评论 -
Process of Starting an Activity
startActivityForResult() ----Instrumentation.execStartActivity ----mainThread.sendActivityResult Instrumentation.exeStartActivity ----ActiveManagerNative.getDefault().StartActiv原创 2017-04-05 21:15:58 · 240 阅读 · 0 评论 -
Drawable to bitmap
// There are two kinds of drawable: BitmapDrawable and ColorDrawable, so we need to deal with them seperately private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) {原创 2017-03-14 19:44:08 · 391 阅读 · 0 评论 -
Utilities about screen/view size
/*** Get screen size in pixel.* @param context Context.* @return Screen size in pixel*/public static Point getScreenSizeInPixel(Context context) { WindowManager windowManager = (WindowManager)context.原创 2017-03-07 20:36:31 · 282 阅读 · 0 评论 -
Adapter of page viewer (how to reuse view)
a. 在写PagerAdapter的时候,需要重写instantiateItem(ViewGroup container ,int position),此方法中,将需要加载的View,添加到container中。 b. PagerAdapter不能直接使用像ListView那样的ViewHolder,来实现View的复用。所以,如果每次加载,都要新建一个View出来就会很占用内存。 c. 如原创 2017-03-08 09:40:52 · 216 阅读 · 0 评论 -
Image scale type
matrix:将图片显示到定义好的宽度和高度描述的矩形中,不做任何缩放(图形的左上角对齐矩形的左上角)。意味着,如果矩形比图形大,则图片显示在左上角,如果矩形比图形小,则只会显示图形矩形部分的大小。fitXY:将图片不按等比例扩大/缩小到View的大小显示(确保图片会完整显示,并充满View)fitStart:将图片按照等比例进行缩放,并显示在矩形的左上方(确保图片会完整显示,矩形的短边会充满)f原创 2017-03-08 09:41:52 · 435 阅读 · 0 评论 -
Set layout parameter in Java code
// Get layout param first ViewGroup.LayoutParams photoViewLayoutParameter = mPhotoView.getLayoutParams(); // Set height photoViewLayoutParameter.height = LayoutUtils.getNPercentOfScreenHeightInPixel(I原创 2017-03-08 09:44:49 · 234 阅读 · 0 评论 -
Make status bar the same color as activity's top color
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo); getWindow().addFlags(WindowManager.LayoutParams.原创 2017-03-08 12:01:50 · 204 阅读 · 0 评论 -
Create a parcelable
public interface IArticleLoader extends Parcelable { /** * Load article. * @param loadListener Load complete listener. */ void load(IArticleLoadListener loadListener); } public cl原创 2017-03-08 12:02:59 · 218 阅读 · 0 评论 -
Resize a bitmap
/** * Resample bitmap. * 这个方法有两个缺陷: * 1、我们先要从磁盘上先将图片加载到内存,然后才能对图片进行缩放,在移动设备上对内存的要求比较高,这在一定程度上降级了性能。 * 2、我们使用Bitmap.createBitmap这个方法进行缩放,使用的是Java层面的方法来缩放,我们知道Java层面对图片,视频等进行处理是有性能损失的。 * @param bitmap B原创 2017-03-08 21:54:08 · 813 阅读 · 0 评论 -
DisplayMatrix.density & DisplayMatrix.densityDpi & pixel
windowManager.getDisplayMatrix().densityDpi 每英寸的像素数(就是DPI值)windowManager.getDisplayMatrix().density= DPI/160, 所以DPI == 160设备的DisplayMatrix.density = 1DIP:长度单位, 等于pixel/DisplayMatrix.density, 所以DPI==16原创 2017-03-08 21:59:26 · 265 阅读 · 0 评论 -
WindowManager & DisplayMatrix
// get window manager WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); // get display matrix of window dm = new DisplayMetrics(); getWindowManager().getD原创 2017-03-08 22:00:24 · 301 阅读 · 0 评论 -
Remote view API
具体的知识点可以参考http://blog.youkuaiyun.com/u014628886/article/details/51930762什么是remoteview: Remoteview不是当前进程的View,是属于SystemServer进程.应用程序与RemoteViews之间依赖Binder实现了进程间通信.从实现上来看,removeview是一个Parcelable.常见usecase: no原创 2017-03-09 21:44:24 · 259 阅读 · 0 评论 -
Application Context 和 Activity Context
两者的区别可能还有很多,我目前看到的是关于内存泄漏的问题。Activity的Context和Activity同生命周期,而Application的Context和Application同周期。假如我们让Activity中的某个View保存了Activity的Context,而且又让这个view变成了static的成员,那么这个activity就不能在该销毁的时候销毁,因为static变量引用了这个原创 2017-03-09 21:45:43 · 245 阅读 · 0 评论 -
override onMeasure()
// widthMeasureSpec是一个int值,前两位代表模式,后面30位代表数值,有三种mode: // EXACTLY: 当layout_width = 100dp 或 layout_width = match_parent时 // AT_MOST:当layout_width = wrap_content时 // UNSPECIFIED:一般自定义的时候才会用,要多大有多大 // 如果不原创 2017-03-09 21:46:42 · 284 阅读 · 0 评论 -
BitmapFactory.Options
在Android中,BitmapFactory相信大家都很熟悉了,这个类里面的所有方法都是用来解码创建一个Bitmap,其中有一个重要的类是Options,此类用于解码Bitmap时的各种参数控制,那这里面的各种参数都是什么含义呢?今天我们就来重点解读几个参数。 inJustDecodeBounds: 如果将这个值置为true,那么在解码的时候将不会返回bitmap,只会返回这个bit原创 2017-03-08 21:50:09 · 264 阅读 · 0 评论 -
Update layout parameters of view
// suppose we want to update layout_height parameter of following layout // <LinearLayout // android:id="@+id/categorySelectorBar" // android:orientation="horizontal" // android:layout_width=原创 2017-03-07 20:39:45 · 362 阅读 · 0 评论 -
Set shadow in Android 5+
<LinearLayout android:id="@+id/tool_bar" android:layout_width="match_parent" android:layout_height="@dimen/detail_toolbar_height" android:background="@color/main_color" android:ori原创 2017-03-07 20:41:00 · 349 阅读 · 0 评论 -
Multi view adapter
Implement the following interface: public static abstract class Adapter { public abstract VH onCreateViewHolder(ViewGroup parent, int viewType); public abstract void onBindViewHolder(VH holde原创 2017-03-07 20:42:07 · 280 阅读 · 0 评论 -
Convert image resource to drawable
// 我们在布局文件里面写android:background和android:src这些属性,// 实际上解析之后执行的是view.setBackgroundResource和view.setImageResource方法,// 这两个方法实际上是拿到资源ID再去获取资源的drawable。// 他们会decode图片后,最终都是通过java层的createBitmap来完成的,需要消耗更多内存原创 2017-03-07 20:34:00 · 267 阅读 · 0 评论 -
DiskLruCache
Key Elements: 1. DisLruCache a. Created by static method DisLruCache.open() b. Need to close when you finished write in one piece of cache c. If you want to calculate the size of al原创 2017-04-22 21:38:19 · 215 阅读 · 0 评论