首先我們來看下源碼中源於Activity的定義:
- public class Activity extends ContextThemeWrapper
- implements LayoutInflater.Factory2,
- Window.Callback, KeyEvent.Callback,
- OnCreateContextMenuListener, ComponentCallbacks2 {
- ...
- }
下面我們來詳細分析每一部分的具體意義:
extends ContextThemeWrapper表示Activity本質上是一個ContextThemeWrapper,而ContextThemeWrapper具體是什么呢?看ContextThemeWrapper在源碼中的定義:
- public class ContextThemeWrapper extends ContextWrapper {
- ...
- }
可見ContextThemeWrapper是一個ContextWrapper,繼續往下看:
- public class ContextWrapper extends Context {
- Context mBase;
- ...
- }
ContextWrapper本質上是一個Context,context 的定義如下:
- public abstract class Context {
- ...
- }
整體結構如下圖所示(圖引用自:http://blog.csdn.net/qinjuning/article/details/7310620):
Context是一個抽象類,因此可以知道Activity其實就是一個Context,並實現了一些接口,如何理解Context呢?
Context 俗稱上下文,在很多對象定義中我們都用到了Context,例如ImageViewimageView = new ImageView(this); 這里的this就是當前Activity所在的Context,源碼中對Context的解釋如下:
Interface to global information about anapplication environment. This is an abstract class whose implementation isprovided by the Android system. It allows access to application-specificresources and classes, as well as up-calls for application-level operationssuch as launching activities, broadcasting and receiving intents, etc.
Context只是一個接口,真正實現Context功能的是ContexImpl類,為了了解Context具體有什么作用,我們先來了解下Context中定義了哪些接口:
- public abstract ComponentNamestartService(Intent service);
- public abstract boolean stopService(Intentservice);
- public abstract void startActivity(Intentintent);
- public abstract void sendBroadcast(Intentintent);
- public abstract Intent registerReceiver(BroadcastReceiverreceiver, IntentFilter filter);
- public abstract Resources getResources();
以上是Context眾多接口中的一個片段,看着接口是不是很熟悉?其實我們經常用到的一些函數其實都是在Context中定義的,因此Context可以被認為是用來封裝一下通用功能的一個類,當然這個類不僅僅是針對Activity,最常見的service也是繼承自Context,以及一大堆類都繼承自Context,具體可參考:http://developer.android.com/reference/android/content/Context.html,關於Context的具體介紹可參考:http://blog.csdn.net/qinjuning/article/details/7310620
ContextWrapper僅僅是對Context的簡單封裝,如果要對Context修改,我們只需要修改ContextWrapper,而不需要對通用的Context進行修改,ContextWrapper的目的僅此而已。而ContextThemeWrapper只是在ContextWrapper的基礎上加入了Theme相關的一些內容,對於Activity來說需要處理一些Theme相關的東西,但是對於Service來說只需繼承ContextWrapper,因為Service不需要處理Theme相關的內容。
分析完extends部分,我們再來看下implements部分,extends決定了Activity的本質,implements部分可以認為是對Activity的擴展。
- LayoutInflater.Factory:通過LayoutInflater來inflate一個layout時的回調接口
- Window.Callback: Activity 靠這個接口才有機會對消息進行處理,這部分涉及到消息的傳遞,以后將專門介紹。
- ComponentCallbacks2:定義了內存管理的接口,內存過低時的回調和處理處理接口
- KeyEvent.Callback:鍵盤事件響應的回調接口,例如onKeyDown()等
- OnCreateContextMenuListener:上下文菜單顯示事件的監聽接口,通過實現該方法來處理上下文菜單顯示時的一些操作
通過以上分析,我們大概了解了Activity具體是什么了,這對以后理解Activity應該能帶來一定的幫助。
Examples of android:scaleType attribute.
Top row (l-r) center, centerCrop,centerInside.
Bottom row (l-r): fitCenter, fitStart, fitEnd, fitXY.
- VuDroid (Based on MuPDF) Review on Open-App
- APV (based on MuPDF)
- PDF-Annotation (Based on APV, MuPDF) appears to be the only OS app with annotation abilities, and they're not confirmed to work.
- Android PDF Viewer (Based on Sun's pdf-renderer)
- eBookDroid (Based on VuDroid, MuPDF))
- DroidReader (Based on MuPDF)
- APDFViewer (Based on Poppler, xpdf)
- iPDF View (Based on APV, MuPDF)
- Perfect Viewer plugin
ActionBar