AndroidGaller2源码分析.docx
文本预览下载声明
图库Gallery2Gallery2主要功能是实现本地存储器、MTP存储器和网络存储器中媒体(图像和视频)的浏览、显示和更多操作(删除、分享、选择和缩放等)。下面用一张简单的用例图描述了Gallery2的功能和职责。Gallery 主要是4个页面的跳转:????AlbumSetPage.Java(相册缩略图);??? AlbumPage.java(单个相册照片缩略图);??? PhotoPage.java(单张照片);??? SlideShowPage.java(幻灯片界面);跳转过程:AlbumSetPage.Java→AlbumPage.java→PhotoPage.javaSlideShowPage.java是单独的。这些界面类父类为ActivityState.java;这些界面的切换由StateManager.java负责。1 界面跳转过程:在Galley2模块,我们先从程序的入口看起,在androidManifest.xml中注册Application标签(Android 系统会为每个程序运行时创建一个Application的类对象且仅创建一个,他的生命周期等于这个程序的生命周期,它是全局的单实例的,一般做一些全局的初始化操作),应用创建时就会被初始化,维护应用内部全局数据,主要看几个函数:initializeAsyncTask(), GalleryUtils.initialize(this), GalleryUtil是Gallery的工具类,获得了屏幕参数,WindowManager,Resource等Gallery 从launcher进入Gallery,进入GalleryActivity.ava@Overrideprotected void onCreate(Bundle savedInstanceState) {? ? …...? ? setContentView(R.layout.main);?? ? if (savedInstanceState != null) {? ? ? ?getStateManager().restoreFromState(savedInstanceState);? ? } else {? ? ? ? initializeByIntent();? ? }}? ? private void initializeByIntent() {? ? ? ? Intent intent = getIntent();? ? ? ? String action = intent.getAction();?? ? ? ? if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)){? ? ? ? ? ? startGetContent(intent);? ? ? ? } else if(Intent.ACTION_PICK.equalsIgnoreCase(action)) {? ? ? ? ? ? // We do NOT really support the PICKintent. Handle it as? ? ? ? ? ? // the GET_CONTENT. However, we needto translate the type? ? ? ? ? ? // in the intent here.? ? ? ? ? ? Log.w(TAG, action PICK is notsupported);? ? ? ? ? ? String type =Utils.ensureNotNull(intent.getType());? ? ? ? ? ? if(type.startsWith(vnd.android.cursor.dir/)) {? ? ? ? ? ? ? ? if(type.endsWith(/image)) intent.setType(image/*);? ? ? ? ? ? ? ? if(type.endsWith(/video)) intent.setType(video/*);? ? ? ? ? ? }? ? ? ? ? ? startGetContent(intent);? ? ? ? } else if(Intent.ACTION_VIEW.equalsIgnoreCase(action)? ? ? ? ? ? ? ? ||ACTION_REVIEW.equalsIgnoreCase(action)){? ? ? ? ? ? startViewAction(intent);? ? ? ? } else {? ? ? ? ? ? startDefaultPage();? ? ? ? }}从这个函数看,如果从相册应用
显示全部