IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Camera 图标加载(flash) -> 正文阅读

[移动开发]Camera 图标加载(flash)

1.加载初始桌面布局camera_ui_root,对应 quick_switcher
2.加载quick_switcher相关布局QuickSwitcherManager? setVisibility
3.加载flash相关图标布局FlashViewController,mMainHandler.sendEmptyMessage(FLASH_VIEW_INIT);
4.初始化:initFlashEntryView,flash_icon.xml
5.通过mSettingController.addViewEntry();将其加入到 quick_switcher 中。
6.点击相应图标触发 mFlashEntryListener 事件,加载布局
7.触发 mFlashChoiceViewListener 点击事件重新加载布局


host/res/layout/camera_ui_root.xml
??????? <RelativeLayout
??????????? android:layout_width="match_parent"
??????????? android:layout_height="match_parent">

??????????? <LinearLayout
??????????????? android:id="@+id/top_bar"
??????????????? android:layoutDirection="ltr"
??????????????? android:clickable="true"
??????????????? android:layout_width="match_parent"
??????????????? android:layout_height="wrap_content"
??????????????? >

??????????????? <!-- 设置图标--!>
??????????????? <com.mediatek.camera.common.widget.RotateImageView
??????????????????? android:id="@+id/mode"
??????????????????? android:layout_width="35dp"
??????????????????? android:layout_height="35dp"
??????????????????? android:layout_alignParentLeft="true"
??????????????????? android:layout_alignParentTop="true"
??????????????????? android:layout_marginLeft="@dimen/settings_margin_left"
??????????????????? android:layout_marginTop="@dimen/settings_margin_top"
??????????????????? android:clickable="true"
??????????????????? android:contentDescription="@string/accessibility_mode"
??????????????????? android:focusable="false"
??????????????????? android:scaleType="fitCenter"
??????????????????? android:visibility="visible" />
??????????????? <!-- switch 图标--!>
??????????????? <LinearLayout
??????????????????? android:id="@+id/quick_switcher"
??????????????????? android:layout_width="match_parent"
??????????????????? android:layout_height="30dp"
??????????????????? android:layout_alignParentTop="true"
??????????????????? android:layout_marginRight="@dimen/quick_switcher_margin_right_dp"
??????????????????? android:layout_marginTop="@dimen/quick_switcher_margin_top"
??????????????????? android:layout_toRightOf="@+id/mode"
??????????????????? android:gravity="center_vertical"
??????????????????? android:layoutDirection="rtl"
??????????????????? android:orientation="horizontal" />

??????????? </LinearLayout>
??????? </RelativeLayout>


??? quick_switcher 加载
host/src/com/mediatek/camera/ui/CameraAppUI.java
??? mQuickSwitcherManager = new QuickSwitcherManager(mApp, parentView);
??? mQuickSwitcherManager.setVisibility(View.VISIBLE);//1111
??? mQuickSwitcherManager.setModeChangeListener(new OnQuickModeChangedListenerImpl());
??? mViewManagers.add(mQuickSwitcherManager);

host/src/com/mediatek/camera/ui/AbstractViewManager.java
??? protected abstract View getView();

??? @Override
??? public void setVisibility(int visibility) {
??????? if (visibility == View.VISIBLE) {
??????????? show();
??????? } else if (visibility == View.INVISIBLE) {
??????????? hide(View.INVISIBLE);
??????? } else if (visibility == View.GONE) {
??????????? hide(View.GONE);
??????? }
??? }


??? @Override
??? protected View getView() {

??????? LogHelper.d(TAG,"[getView]");
??????? RuntimeException e = new RuntimeException("print stacktrace");
??????? Stream.of(e.getStackTrace()).forEach(System.out::println);
?????? ?
??????? mQuickSwitcherLayout = (LinearLayout) mParentView.findViewById(R.id.quick_switcher);
??????? updateQuickItems();
??????? return mQuickSwitcherLayout;
??? }

feature/setting/flash/src/com/mediatek/camera/feature/setting/flash/Flash.java
??????? @Override
??????? public void init(IApp app,
??????????????????????? ICameraContext cameraContext,
??????????????????????? ISettingManager.SettingController settingController) {
??????????? super.init(app, cameraContext, settingController);
??????????? ...
??????????? mFlashViewController = new FlashViewController(this, app);
??????????? ...
??????? }
feature/setting/flash/src/com/mediatek/camera/feature/setting/flash/FlashViewController.java

??????? public FlashViewController(Flash flash, IApp app) {
??????????? mFlash = flash;
??????????? mApp = app;
??????????? mMainHandler = new MainHandler(app.getActivity().getMainLooper());
??????????? mMainHandler.sendEmptyMessage(FLASH_VIEW_INIT);
??????? }

??????? @Override
??????? public void handleMessage(Message msg) {
??????????? LogHelper.d(TAG, "view handleMessage: " + msg.what);
??????????? switch (msg.what) {
??????????????? case FLASH_VIEW_INIT:
??????????????????? mFlashEntryView = initFlashEntryView();
??????????????????? break;
??????????? }
??????? }

??????? private ImageView initFlashEntryView() {
??????????? Activity activity = mApp.getActivity();
?????????? ?
??????????? RotateImageView view = (RotateImageView) activity.getLayoutInflater().inflate(R.layout.flash_icon, null);

??????????? view.setOnClickListener(mFlashEntryListener);
??????????? mFlashIndicatorView = (RotateImageView) activity.getLayoutInflater().inflate(
??????????????????? R.layout.flash_indicator, null);
??????????? return view;
??????? }

以拍照模式为例:
??????? common/src/com/mediatek/camera/common/mode/photo/device/PhotoDevice2Controller.java
??????? mSettingController.addViewEntry();

??????? common/src/com/mediatek/camera/common/setting/SettingManager.java
??????? @Override
??????? public void addViewEntry() {
??????????? ...
??????????? List<ICameraSetting> settingsRelatedToMode = getSettingByModeType(mModeType);
??????????? for (ICameraSetting setting : settingsRelatedToMode) {
??????????????? if (!access.isValid()) {
??????????????????? break;
??????????????? }
??????????????? LogHelper.d(mTag, "zzj_[addViewEntry]? 111");
??????????????? setting.addViewEntry();
??????????? }
??????????? ...
??????????? mAppUi.registerQuickIconDone();
??????????? ...
??????? }

??????? feature/setting/flash/src/com/mediatek/camera/feature/setting/flash/Flash.java
??????? public void addQuickSwitchIcon() {
??????????? mMainHandler.sendEmptyMessage(FLASH_VIEW_ADD_QUICK_SWITCH);
??????? }

??????? public void handleMessage(Message msg) {
??????????? LogHelper.d(TAG, "view handleMessage: " + msg.what);
??????????????????? switch (msg.what) {
??????????????????????? case FLASH_VIEW_INIT:
??????????????????????????? mFlashEntryView = initFlashEntryView();
??????????????????????????? break;

??????????????????????? case FLASH_VIEW_ADD_QUICK_SWITCH:
??????????????????????????? mApp.getAppUi().addToQuickSwitcher(mFlashEntryView, FLASH_PRIORITY);
??????????????????????????? updateFlashEntryView(mFlash.getValue());
??????????????????????????? mApp.getAppUi().registerOnShutterButtonListener(mShutterListener,
??????????????????????????????????? FLASH_SHUTTER_PRIORITY);
??????????????????????????? break;
??????????????????? }
??????????? }

??????? host/src/com/mediatek/camera/ui/CameraAppUI.java
??????? @Override
??????? public void addToQuickSwitcher(View view, int priority) {
??????????? mQuickSwitcherManager.addToQuickSwitcher(view, priority);
??????? }
?????? ?
??????? host/src/com/mediatek/camera/ui/QuickSwitcherManager.java
??????? public void addToQuickSwitcher(View view, int priority) {
??????????? LogHelper.d(TAG, "[registerToQuickSwitcher] priority = " + priority);
??????????? if (mQuickItems.size() > ITEM_LIMIT) {
??????????????? LogHelper.w(TAG, "already reach to limit number : " + ITEM_LIMIT);
??????????????? return;
??????????? }
??????????? if (!mQuickItems.containsValue(view)) {
??????????????? mQuickItems.put(priority, view);
??????????? }
??????? }


??????? mFlashViewController.showQuickSwitchIcon(getEntryValues().size() > 1);
?????? ?
??????? feature/setting/flash/src/com/mediatek/camera/feature/setting/flash/FlashViewController.java
??????? public void showQuickSwitchIcon(boolean isShow) {
??????????? mMainHandler.obtainMessage(FLASH_VIEW_UPDATE_QUICK_SWITCH_ICON, isShow).sendToTarget();
??????? }

??????? public void handleMessage(Message msg) {
??????????? LogHelper.d(TAG, "view handleMessage: " + msg.what);
??????????????????? switch (msg.what) {
??????????????????????? case FLASH_VIEW_UPDATE_QUICK_SWITCH_ICON:
??????????????????????? if ((boolean) msg.obj) {
??????????????????????????? mFlashEntryView.setVisibility(View.VISIBLE);
??????????????????????????? updateFlashEntryView(mFlash.getValue());
??????????????????????? } else {
??????????????????????????? mFlashEntryView.setVisibility(View.GONE);
??????????????????????? }
??????????????????????? break;
??????????????????? }
??????? }

??????? public void updateFlashEntryView(final String value) {
??????????? LogHelper.d(TAG, "[updateFlashView] currentValue = " + mFlash.getValue());
??????????? if (FLASH_ON_VALUE.equals(value)) {
??????????????? mFlashEntryView.setImageResource(R.drawable.ic_flash_status_on);
??????????????? mFlashEntryView.setContentDescription(mApp.getActivity().getResources().getString(
??????????????????????? R.string.accessibility_flash_on));
??????????? } else if (FLASH_AUTO_VALUE.equals(value)) {
??????????????? mFlashEntryView.setImageResource(R.drawable.ic_flash_status_auto);
??????????????? mFlashEntryView.setContentDescription(mApp.getActivity().getResources().getString(
??????????????????????? R.string.accessibility_flash_auto));
??????????? } else {
??????????????? mFlashEntryView.setImageResource(R.drawable.ic_flash_status_off);
??????????????? mFlashEntryView.setContentDescription(mApp.getActivity().getResources().getString(
??????????????????????? R.string.accessibility_flash_off));
??????????? }
??????????? // Flash indicator no need to show now,would be enable later
??????????? // updateFlashIndicator(value);
??????? }


??????? mAppUi.registerQuickIconDone();
??????? host/src/com/mediatek/camera/ui/CameraAppUI.java
??????? @Override
??????? public void registerQuickIconDone() {
??????????? mApp.getActivity().runOnUiThread(new Runnable() {
??????????????? @Override
??????????????? public void run() {
??????????????????? mQuickSwitcherManager.registerQuickIconDone();
??????????????? }
??????????? });
??????? }

??????? host/src/com/mediatek/camera/ui/QuickSwitcherManager.java
??????? public void registerQuickIconDone() {
??????????? LogHelper.d(TAG,"[registerQuickIconDone]");
??????????? updateQuickItems();
??????? }

??????? //加载小图标
??????? private void updateQuickItems() {
??????????? LogHelper.d(TAG,"[updateQuickItems]");
??????????? float density = mApp.getActivity().getResources().getDisplayMetrics().density;
??????????? int marginInPix = (int) (MARGIN_IN_DP * density);
??????????? if (mQuickSwitcherLayout != null && mQuickSwitcherLayout.getChildCount() != 0) {
??????????????? mQuickSwitcherLayout.removeAllViews();
??????????? }
??????????? if (mQuickSwitcherLayout != null) {
??????????????? Iterator iterator = mQuickItems.entrySet().iterator();
??????????????? while (iterator.hasNext()) {
??????????????????? Map.Entry map = (Map.Entry) iterator.next();
??????????????????? View view = (View) map.getValue();
??????????????????? LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
??????????????????????????? ViewGroup.LayoutParams.WRAP_CONTENT,
??????????????????????????? ViewGroup.LayoutParams.WRAP_CONTENT);
??????????????????? params.setMargins(marginInPix, 0, 0, 0);
??????????????????? view.setLayoutParams(params);
??????????????????? mQuickSwitcherLayout.addView(view);
??????????????? }
??????????????? updateViewOrientation();
??????????? }
??????? }

??????? mQuickSwitcherLayout.addView(view);


//点击事件
feature/setting/flash/src/com/mediatek/camera/feature/setting/flash/FlashViewController.java

??? private final View.OnClickListener mFlashEntryListener = new View.OnClickListener() {
??????? public void onClick(View view) {
??????????? if (mFlash.getEntryValues().size() <= 1) {
??????????????? return;
??????????? }
??????????? if (mFlash.getEntryValues().size() > FLASH_ENTRY_LIST_SWITCH_SIZE) {
??????????????? initializeFlashChoiceView();
??????????????? updateChoiceView();
??????????????? mApp.getAppUi().showQuickSwitcherOption(mOptionLayout);
??????????? } else {
??????????????? String value = mFlash.getEntryValues().get(FLASH_ENTRY_LIST_INDEX_0);
??????????????? if (value.equals(mFlash.getValue())) {
??????????????????? value = mFlash.getEntryValues().get(FLASH_ENTRY_LIST_INDEX_1);
??????????????? }
??????????????? updateFlashEntryView(value);
??????????????? // Flash indicator no need to show now,would be enable later
??????????????? // updateFlashIndicator(value);
??????????????? mFlash.onFlashValueChanged(value);
??????????? }
??????? }
??? };


??? private void initializeFlashChoiceView() {
??????? if (mFlashChoiceView == null || mOptionLayout == null) {
??????????? ViewGroup viewGroup =? mApp.getAppUi().getModeRootView();
??????????? mOptionLayout = mApp.getActivity().getLayoutInflater().inflate(
??????????????????? R.layout.flash_option, viewGroup, false);
??????????? mFlashChoiceView = mOptionLayout.findViewById(R.id.flash_choice);
??????????? mFlashOnIcon = (ImageView) mOptionLayout.findViewById(R.id.flash_on);
??????????? mFlashOffIcon = (ImageView) mOptionLayout.findViewById(R.id.flash_off);
??????????? mFlashAutoIcon = (ImageView) mOptionLayout.findViewById(R.id.flash_auto);

??????????? mFlashOffIcon.setOnClickListener(mFlashChoiceViewListener);
??????????? mFlashOnIcon.setOnClickListener(mFlashChoiceViewListener);
??????????? mFlashAutoIcon.setOnClickListener(mFlashChoiceViewListener);
??????? }
??? }

??????? private void updateChoiceView() {
??????? if (FLASH_ON_VALUE.equals(mFlash.getValue())) {
??????????? mFlashOnIcon.setImageResource(R.drawable.ic_flash_status_on_selected);
??????????? mFlashOffIcon.setImageResource(R.drawable.ic_flash_status_off);
??????????? mFlashAutoIcon.setImageResource(R.drawable.ic_flash_status_auto);
??????? } else if (FLASH_OFF_VALUE.equals(mFlash.getValue())) {
??????????? mFlashOnIcon.setImageResource(R.drawable.ic_flash_status_on);
??????????? mFlashOffIcon.setImageResource(R.drawable.ic_flash_status_off_selected);
??????????? mFlashAutoIcon.setImageResource(R.drawable.ic_flash_status_auto);
??????? } else {
??????????? mFlashOnIcon.setImageResource(R.drawable.ic_flash_status_on);
??????????? mFlashOffIcon.setImageResource(R.drawable.ic_flash_status_off);
??????????? mFlashAutoIcon.setImageResource(R.drawable.ic_flash_status_auto_selected);
??????? }
??? }

host/src/com/mediatek/camera/ui/CameraAppUI.java
??? @Override
??? public void showQuickSwitcherOption(View optionView) {
??????? mApp.getActivity().runOnUiThread(new Runnable() {
??????????? @Override
??????????? public void run() {
??????????????? mQuickSwitcherManager.showQuickSwitcherOption(optionView);
??????????? }
??????? });
??? }
host/src/com/mediatek/camera/ui/QuickSwitcherManager.java
??? public void showQuickSwitcherOption(View optionView) {
??????? if (mOptionRoot.getChildCount() != 0) {
??????????? LogHelper.e(TAG, "[showQuickSwitcherOption] Already has options to be shown!");
??????????? return;
??????? }
??????? Animation inAnim = AnimationUtils.loadAnimation(mApp.getActivity(), R.anim.anim_top_in);
??????? mOptionRoot.addView(optionView);
??????? int orientation = mApp.getGSensorOrientation();
??????? CameraUtil.rotateRotateLayoutChildView(mApp.getActivity(), mOptionRoot, orientation, true);
??????? mOptionRoot.setVisibility(View.VISIBLE);
??????? mOptionRoot.setClickable(true);
??????? mOptionRoot.startAnimation(inAnim);
??????? mTopBar.setVisibility(View.GONE);
??????? mApp.registerOnOrientationChangeListener(mOrientationChangeListener);
??? }


??? private View.OnClickListener mFlashChoiceViewListener = new View.OnClickListener() {
??????? @Override
??????? public void onClick(View view) {
??????????? String value = "";
??????????? if (mFlashAutoIcon == view) {
??????????????? value = FLASH_AUTO_VALUE;
??????????? } else if (mFlashOnIcon == view) {
??????????????? value = FLASH_ON_VALUE;
??????????? //*/ hct.huangfei, 20201212.add torch mode for flash.
??????????? } else if (mFlash.isTorchModeSupport()&&mFlashTorchIcon == view) {
??????????????? value = FLASH_TORCH_VALUE;
??????????? //*/
??????????? } else {
??????????????? value = FLASH_OFF_VALUE;
??????????? }
??????????? mApp.getAppUi().hideQuickSwitcherOption();
??????????? updateFlashEntryView(value);
??????????? // Flash indicator no need to show now,would be enable later
??????????? // updateFlashIndicator(value);
??????????? mFlash.onFlashValueChanged(value);
??????? }

??? };

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-11-24 08:03:55  更:2021-11-24 08:06:15 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 4:50:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码