不积跬步无以至千里
“一花一世界,一树一乾坤,一草一天堂,一木一浮生”,这句话告诉我们通过一小部分可以知道整个整体,同样的Camera也一样,本文主要分析这个CameraActivity。
其实我发现AndroidMainfest.xml中,启动Activity就是CameraActivity的别名的CameraLauncher,如下图:

下面看一下这个CameraActivity的整个生命周期(代码的逻辑,我通过加注释给大家解释一下)。

onCreate方法

    public void onCreate(Bundle state) {super.onCreate(state);//检查权限,如果权限没检查过,或者没有批准的权限直接关闭。另说一嘴,大家都知道吗?android7.1又对权限做了新的处理。if (checkPermissions() || !mHasCriticalPermissions) {Log.v(TAG, "onCreate: Missing critical permissions.");//关闭本Activity,即跳出整个程序finish();return;}// Check if this is in the secure camera mode.检查是否为安全相机模式Intent intent = getIntent();String action = intent.getAction();if (INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)|| ACTION_IMAGE_CAPTURE_SECURE.equals(action)|| intent.getComponent().getClassName().equals(GESTURE_CAMERA_NAME)) {mSecureCamera = true;} else {mSecureCamera = intent.getBooleanExtra(SECURE_CAMERA_EXTRA, false);}//根据相机是不是安全相机模式做处理if (mSecureCamera) {// Change the window flags so that secure camera can show when locked 当被锁住时,为安全模式时,改变窗口。Window win = getWindow();WindowManager.LayoutParams params = win.getAttributes();params.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;if (intent.getComponent().getClassName().equals(GESTURE_CAMERA_NAME)) {params.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;//获取唤醒锁PowerManager pm = ((PowerManager) getSystemService(POWER_SERVICE));mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);mWakeLock.acquire();Log.d(TAG, "acquire wake lock");}win.setAttributes(params);}GcamHelper.init(getContentResolver());//设置actionBargetWindow().requestFeature(Window.FEATURE_ACTION_BAR);setContentView(R.layout.camera_filmstrip);//为ActionBa设置菜单可见监听mActionBar = getActionBar();mActionBar.addOnMenuVisibilityListener(this);//当大于4.3版本,设置窗口的旋转动画if (ApiHelper.HAS_ROTATION_ANIMATION) {setRotationAnimation();}//声明一个主线程的Handler,主要用于ActionBar的隐藏和显示mMainHandler = new MainHandler(getMainLooper());//关联控件mAboveFilmstripControlLayout =(FrameLayout) findViewById(R.id.camera_above_filmstrip_layout);mAboveFilmstripControlLayout。setFitsSystemWindows(true);
mAboveFilmstripControlLayout。setFitsSystemWindows(true);
this.setSystemBarsVisibility(false);mPanoramaManager = AppManagerFactory.getInstance(this)。getPanoramaStitchingManager();mPlaceholderManager = AppManagerFactory.getInstance(this)。getGcamProcessingManager();//添加图片加载监听mPanoramaManager。addTaskListener(mStitchingListener);mPlaceholderManager。addTaskListener(mPlaceholderListener);LayoutInflater inflater = getLayoutInflater();View rootLayout = inflater。inflate(R。layout。camera, null, false);mCameraRootFrame = (FrameLayout)rootLayout。findViewById(R。id。camera_root_frame);mCameraPhotoModuleRootView = rootLayout。findViewById(R。id。camera_photo_root);mCameraVideoModuleRootView = rootLayout。findViewById(R。id。camera_video_root);mCameraPanoModuleRootView = rootLayout。findViewById(R。id。camera_pano_root);mPanoStitchingPanel = findViewById(R。id。pano_stitching_progress_panel);mBottomProgress = (ProgressBar) findViewById(R。id。pano_stitching_progress_bar);mCameraPreviewData = new CameraPreviewData(rootLayout,FilmStripView。ImageData。SIZE_FULL,FilmStripView。ImageData。SIZE_FULL);// Put a CameraPreviewData at the first positionmWrappedDataAdapter = new FixedFirstDataAdapter(new CameraDataAdapter(new ColorDrawable(getResources()。getColor(R。color.photo_placeholder))),mCameraPreviewData);mFilmStripView = (FilmStripView) findViewById(R。id.filmstrip_view);mFilmStripView。setViewGap(getResources()。getDimensionPixelSize(R。dimen.camera_film_strip_gap));mPanoramaViewHelper = new PanoramaViewHelper(this);mPanoramaViewHelper。onCreate();mFilmStripView。setPanoramaViewHelper(mPanoramaViewHelper);// Set up the camera preview first so the preview shows up ASAPmFilmStripView。setListener(mFilmStripListener);//获取当前的拍照模式:视频、照相int moduleIndex = -1;if (MediaStore。INTENT_ACTION_VIDEO_CAMERA。equals(getIntent()。getAction())|| MediaStore。ACTION_VIDEO_CAPTURE。equals(getIntent()。getAction())) {moduleIndex = ModuleSwitcher。VIDEO_MODULE_INDEX;} else if (MediaStore。INTENT_ACTION_STILL_IMAGE_CAMERA.equals(getIntent()。getAction())|| MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE。equals(getIntent()。getAction())) {moduleIndex = ModuleSwitcher。PHOTO_MODULE_INDEX;SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);if (prefs.getInt(CameraSettings.KEY_STARTUP_MODULE_INDEX, -1)== ModuleSwitcher.GCAM_MODULE_INDEX && GcamHelper.hasGcamCapture()) {moduleIndex = ModuleSwitcher.GCAM_MODULE_INDEX;}} else if (MediaStore.ACTION_IMAGE_CAPTURE.equals(getIntent().getAction())|| MediaStore.ACTION_IMAGE_CAPTURE_SECURE.equals(getIntent().getAction())) {moduleIndex = ModuleSwitcher.PHOTO_MODULE_INDEX;} else {// If the activity has not been started using an explicit intent,// read the module index from the last time the user changed modesSharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);moduleIndex = prefs.getInt(CameraSettings.KEY_STARTUP_MODULE_INDEX, -1);if ((moduleIndex == ModuleSwitcher.GCAM_MODULE_INDEX &&!GcamHelper.hasGcamCapture()) || moduleIndex < 0) {moduleIndex = ModuleSwitcher.PHOTO_MODULE_INDEX;}}//设置重力感应监听mOrientationListener = new MyOrientationEventListener(this);//根据上面获取、判断的模式,去设置界面的显示等等。setModuleFromIndex(moduleIndex);//根据是不是安全相机来处理
if (!mSecureCamera) {mDataAdapter = mWrappedDataAdapter;mFilmStripView。setDataAdapter(mDataAdapter);if (!isCaptureIntent()) {mDataAdapter。requestLoad(getContentResolver());mDataRequested = true;}} else {// Put a lock placeholder as the last image by setting its date to// 0.//点击照片跳转意图ImageView v = (ImageView) getLayoutInflater().inflate(R.layout.secure_album_placeholder, null);v.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {try {UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA,UsageStatistics.ACTION_GALLERY, null);//跳转到相册        startActivity(IntentHelper.getGalleryIntent(CameraActivity.this));} catch (ActivityNotFoundException e) {Log.w(TAG, "Failed to launch gallery activity, closing");}finish();}});mDataAdapter = new FixedLastDataAdapter(mWrappedDataAdapter,new SimpleViewData(v,v.getDrawable().getIntrinsicWidth(),v.getDrawable().getIntrinsicHeight(),0, 0));// Flush out all the original data.mDataAdapter.flush();mFilmStripView.setDataAdapter(mDataAdapter);}//设置nfcsetupNfcBeamPush();//设置观察者,来分别观察图片的变化和视频资源的变化mLocalImagesObserver = new LocalMediaObserver();mLocalVideosObserver = new LocalMediaObserver();getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true,mLocalImagesObserver);getContentResolver().registerContentObserver(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true,mLocalVideosObserver);SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);mDeveloperMenuEnabled = prefs.getBoolean(CameraSettings.KEY_DEVELOPER_MENU, false);//设置窗口大小Display display = getWindowManager().getDefaultDisplay();Point size = new Point();display.getSize(size);int width = size.x;int height = size.y;int lower = Math.min(width, height);int offset = lower * 10 / 100;SETTING_LIST_WIDTH_1 = lower / 2 + offset;SETTING_LIST_WIDTH_2 = lower / 2 - offset;//注册关于sd的挂载的广播registerSDcardMountedReceiver();}

onStart方法:

@Overridepublic void onStart() {super.onStart();//开启添加图片、视频的servicebindMediaSaveService();mPanoramaViewHelper.onStart();}

onResume方法:

@Overridepublic void onResume() {//权限检测if (checkPermissions() || !mHasCriticalPermissions) {super。onResume();Log.v(TAG, "onResume: Missing critical permissions.");finish();return;}UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA,UsageStatistics.ACTION_FOREGROUNDED, this.getClass().getSimpleName());mOrientationListener.enable();mCurrentModule.onResumeBeforeSuper();super.onResume();mCurrentModule.onResumeAfterSuper();//设置预览画面能否滑动setSwipingEnabled(true);if (mResetToPreviewOnResume) {// Go to the preview on resume.mFilmStripView.getController().goToFirstItem();}// Default is showing the preview, unless disabled by explicitly// starting an activity we want to return from to the filmstrip rather// than the preview.mResetToPreviewOnResume = true;//查看图片和视频资源有无变化,有则重新加载if (mLocalVideosObserver.isMediaDataChangedDuringPause()|| mLocalImagesObserver.isMediaDataChangedDuringPause()) {if (!mSecureCamera) {// If it's secure camera, requestLoad() should not be called// as it will load all the data.mDataAdapter.requestLoad(getContentResolver());mThumbnailDrawable = null;}}//重置观察者标志位mLocalImagesObserver.setActivityPaused(false);mLocalVideosObserver.setActivityPaused(false);//This is a temporal solution to share LED resource//as Android doesn’t have any default intent to share the state.// if the led flash light is open, turn it offLog.d(TAG, "send the turn off Flashlight broadcast");//关闭闪光灯Intent intent = new Intent("org.codeaurora.snapcam.action.CLOSE_FLASHLIGHT");intent.putExtra("camera_led", true);sendBroadcast(intent);}

onPause方法:

    @Overridepublic void onPause() {// Delete photos that are pending deletion//删除照片时正好界面pause了的处理performDeletion();//关闭重力传感器监听mOrientationListener.disable();mCurrentModule.onPauseBeforeSuper();super.onPause();mCurrentModule.onPauseAfterSuper();//设置观察者的标志位mLocalImagesObserver.setActivityPaused(true);mLocalVideosObserver.setActivityPaused(true);}

onStop方法:

    @Overrideprotected void onStop() {super.onStop();mPanoramaViewHelper.onStop();//断开存储视频、图片的serviceunbindMediaSaveService();}

onDestory方法:

@Overridepublic void onDestroy() {//释放唤醒锁if (mWakeLock != null && mWakeLock.isHeld()) {mWakeLock.release();Log.d(TAG, "wake lock release");}//注销观察者和sd卡的挂载广播if (mLocalImagesObserver != null) {getContentResolver().unregisterContentObserver(mLocalImagesObserver);getContentResolver().unregisterContentObserver(mLocalVideosObserver);unregisterReceiver(mSDcardMountedReceiver);}super.onDestroy();}

先分析到这,接下在再补充。。。

android7.1的SnapdragonCamera之CameraActivity逻辑流程分析整体相关推荐

  1. 百度新闻后台逻辑流程分析

    /*版权声明:可以任意转载,转载时请务必标明文章原始出处和作者信息 .*/ 百度新闻后台逻辑流程分析 CopyMiddle:张俊林 TimeStamp:2008年1月9日 今天分析了一下百度新闻,琢磨 ...

  2. netts之 CTWSocket代码流程分析(整体是客户端请求式的)

    netts之 CTWSocket代码流程分析(整体是客户端请求式的) 1.外部程序载入调用 netts.dll 2.外部程序调用 netts实现的Stock_Init_Nodialog,(Stock_ ...

  3. HDFS追本溯源:HDFS操作的逻辑流程与源码解析

    转自:http://www.it165.net/admin/html/201404/2726.html 本文主要介绍5个典型的HDFS流程,这些流程充分体现了HDFS实体间IPC接口和stream接口 ...

  4. 数据库逻辑删除的sql语句_通过数据库的眼睛查询sql的逻辑流程

    数据库逻辑删除的sql语句 Structured Query Language (SQL) is famously known as the romance language of data. Eve ...

  5. MINA核心结构和处理消息的逻辑流程

    1.MINA 核心结构 IoService 最底层的是IOService,负责具体的IO相关工作.这一层的典型代表有IOSocketAcceptor和IOSocketChannel,分别对应TCP协议 ...

  6. 产品需求文档、需求结构图、数据字典、全局说明、用例描述、需求描述、逻辑流程、原型设计、页面交互、登录注册、词汇表、数据统计、用户表设计、接口需求、功能清单、业务流程图、Axure原型、prd、文档实例

    产品需求文档.需求结构图.数据字典.全局说明.用例描述.逻辑流程.原型设计.页面交互.登录注册.词汇表.数据统计.用户表设计.接口需求.功能清单.业务流程图.Axure原型.prd.产品需求文档实例 ...

  7. 【云贝学院】揭秘TDSQL分布式实例扩容的逻辑流程

    [云贝学院]云贝学院TDSQL TCP认证课程已上线,学院有不定期公开课 需要进讨论群的同学可以加老师微信:19941464235 作者:潘峰 [前言] 大家众所周知TDSQL for mysql 是 ...

  8. android7.0 进程管理,Android 7.0 ActivityManagerService(8) 进程管理相关流程分析(2) updateOomAdjLocked...

    前一篇博客进程管理相关流程分析(1)里, 我们介绍了AMS中updateLruProcessLocked函数相关的流程. updateLruProcessLocked只是按照进程中运行的组件,粗略地定 ...

  9. 在C++程序中添加逻辑流程控制

    在C++ 程序中添加逻辑流程控制          问题的引出 在计算机程序中,除了常见的执行流程控制,还有逻辑流程控制:有时,执行流程即为逻辑流程,但在大多数情况下还是有所区别的,例如,假定有一个W ...

最新文章

  1. 微型计算机使用环境,计算机的日常使用环境
  2. Network下方什么请求也没有_HTTP的响应与请求
  3. Gartner 组织世界BI大会,PowerBI 与 Tableau 同台竞技
  4. mysql主外键引用关系,关于mysql:数据主/外键关系
  5. 遇到一个打开文件方式“w+”和“a+”的问题
  6. 【mybatis】mybatis使用java实体中定义的常量,或静态方法
  7. [Beego模型] 五、构造查询
  8. 深入浅出ASP .NET Core学习记录
  9. oracle数据库教程ppt,Oracle 数据库入门教程 PPT
  10. Whitelabel Error Page 的原因
  11. Shell脚本学习-阶段二十七-命令解释二
  12. 浙江python改革_重大改革:Python 语言将被加入高考科目!
  13. linux中flac安装
  14. 1.单例模式_繁星漫天_新浪博客
  15. 机器学习初级算法之决策树
  16. 活动可视化怎么做?看京东乐高架构设计
  17. 读取SpringBoot(Spring)的配置信息,定义常量
  18. iOS - 广告标识符(IDFA IDFV)
  19. RK3399平台入门到精通系列讲解 - 总目录
  20. 网络管理员(初级桌面运维工程师)工作常用解决方法

热门文章

  1. 中外互免签证协定一览表(普通护照与公务普通护照)
  2. OpenCV中的基本图像操作
  3. 【移动光猫H2-2的完全破解心路历程及配置】
  4. 嘉和生物药业(开曼)控股有限公司于香港联交所主板成功上市
  5. 【C语言编程】如何整蛊你的损友,让他的电脑一直关机?
  6. JS,Jquery发起ajax的方式总结
  7. 软件测试证述职报告ppt,实验室检测员的述职报告ppt
  8. 【iOS】遍历相册照片
  9. python语言合法命名-python语言合法命名有哪些
  10. TCP的三次握手与四次挥手理解