Gallery3d 学习笔记(10)

上次我们了解了一些层在做什么,对应是什么,也看了对应的图片,也知道他们是一层层放着的,也知道触摸消息是怎么分发处理的。


但这些都在哪里组织的呢?又是怎么切换的呢?


我们还是一个控件(我估且叫他们控件吧,应该是一个层里面的一部分东西),先看HudLayer里面的代码。


    // Camera button - launches the camera intent when pressed.
    private static final int CAMERA_BUTTON_ICON = Res.drawable.btn_camera;
    private static final int CAMERA_BUTTON_ICON_PRESSED = Res.drawable.btn_camera_pressed;
    private static final int ZOOM_IN_ICON = Res.drawable.gallery_zoom_in;
    private static final int ZOOM_IN_ICON_PRESSED = Res.drawable.gallery_zoom_in_touch;
    private static final int ZOOM_OUT_ICON = Res.drawable.gallery_zoom_out;
    private static final int ZOOM_OUT_ICON_PRESSED = Res.drawable.gallery_zoom_out_touch;

    private final Runnable mCameraButtonAction = new Runnable() {
        public void run() {
            // Launch the camera intent.
            Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mContext.startActivity(intent);
        }
    };

    // Grid mode button - switches the media browser to grid mode.
    private static final int GRID_MODE_ICON = Res.drawable.mode_stack;
    private static final int GRID_MODE_PRESSED_ICON = Res.drawable.mode_stack;

    private final Runnable mZoomInButtonAction = new Runnable() {
        public void run() {
            mGridLayer.zoomInToSelectedItem();
            mGridLayer.markDirty(1);
        }
    };

    private final Runnable mZoomOutButtonAction = new Runnable() {
        public void run() {
            mGridLayer.zoomOutFromSelectedItem();
            mGridLayer.markDirty(1);
        }
    };

    private final Runnable mGridModeButtonAction = new Runnable() {
        public void run() {
            mGridLayer.setState(GridLayer.STATE_GRID_VIEW);
        }
    };
    /**
     * Stack mode button - switches the media browser to grid mode.
     */
    private static final int STACK_MODE_ICON = Res.drawable.mode_grid;
    private static final int STACK_MODE_PRESSED_ICON = Res.drawable.mode_grid;
    private final Runnable mStackModeButtonAction = new Runnable() {
        public void run() {
            mGridLayer.setState(GridLayer.STATE_TIMELINE);
        }
    };

我们找到了摄像头按钮的处理和放大按钮和缩小按钮,以及切换按钮的处理。


有没有发现问题?


这些控件不在同一个界面上的,怎么都写在一起了?特别是摄像头和切换按钮是不同时出现的,怎么都写在一起?


让我们来看一个函数,这个函数是每次切换状态的时候就会调用的。


    private void updateViews() {
        if (mGridLayer == null)
            return;
        final int state = mGridLayer.getState();
        // Show the selection menu in selection mode.
        final boolean selectionMode = mMode == MODE_SELECT;
        final boolean fullscreenMode = state == GridLayer.STATE_FULL_SCREEN;
        final boolean stackMode = state == GridLayer.STATE_MEDIA_SETS || state == GridLayer.STATE_TIMELINE;
        mSelectionMenuTop.setHidden(!selectionMode || fullscreenMode);
        mSelectionMenuBottom.setHidden(!selectionMode);
        mFullscreenMenu.setHidden(!fullscreenMode || selectionMode);
        mZoomInButton.setHidden(mFullscreenMenu.isHidden());
        mZoomOutButton.setHidden(mFullscreenMenu.isHidden());

        // Show the time bar in stack and grid states, except in selection mode.
        mTimeBar.setHidden(fullscreenMode || selectionMode || stackMode);
        // mTimeBar.setHidden(selectionMode || (state !=
        // GridLayer.STATE_TIMELINE && state != GridLayer.STATE_GRID_VIEW));

        // Hide the path bar and top-right button in selection mode.
        mPathBar.setHidden(selectionMode);
        mTopRightButton.setHidden(selectionMode || fullscreenMode);
        computeSizeForPathbar();

        // Configure the top-right button.
        int image = 0;
        int pressedImage = 0;
        Runnable action = null;
        final ImageButton topRightButton = mTopRightButton;
        int height = (int) (94 * App.PIXEL_DENSITY);
        switch (state) {
        case GridLayer.STATE_MEDIA_SETS:
            image = CAMERA_BUTTON_ICON;
            pressedImage = CAMERA_BUTTON_ICON_PRESSED;
            action = mCameraButtonAction;
            break;
        case GridLayer.STATE_GRID_VIEW:
            height /= 2;
            image = STACK_MODE_ICON;
            pressedImage = STACK_MODE_PRESSED_ICON;
            action = mStackModeButtonAction;
            break;
        case GridLayer.STATE_TIMELINE:
            image = GRID_MODE_ICON;
            pressedImage = GRID_MODE_PRESSED_ICON;
            action = mGridModeButtonAction;
            break;
        case GridLayer.STATE_FULL_SCREEN:
            if (getGridLayer() != null && getGridLayer().getFeed() != null
                    && getGridLayer().getFeed().getExpandedMediaSet() != null) {
                if (getGridLayer().getFeed().getExpandedMediaSet().mId == LocalDataSource.CAMERA_BUCKET_ID) {
                    image = CAMERA_BUTTON_ICON;
                    pressedImage = CAMERA_BUTTON_ICON_PRESSED;
                    action = mCameraButtonAction;
                    topRightButton.setHidden(false);
                }
            }
            break;
        default:
            break;
        }
        topRightButton.setSize((int) (100 * App.PIXEL_DENSITY), height);
        topRightButton.setImages(image, pressedImage);
        topRightButton.setAction(action);
    }


一共又多少种状态呢?写在GridLayer中

    public static final int STATE_MEDIA_SETS = 0;
    public static final int STATE_GRID_VIEW = 1;
    public static final int STATE_FULL_SCREEN = 2;
    public static final int STATE_TIMELINE = 3;

四种 1 相册集 2 Grid视图 3全屏 4 时间线 

这下明白了吧,控件都在HudLayer中,但是状态是在GridLayer中定义和设置的,刷新是在HudLayer中的UpdateView中处理的,通过对不同状态下,对不同的控件进行隐藏和显示实现了切换。刷新还是在RenderView对各个层的刷新实现对界面的刷新。


通过10次博客,讲了Gallery3d的消息流程 数据流  刷新流程 和 切换流程。


我在问一个问题,看大家理解透彻没有,如果我要添加一个功能,在放大和缩小按钮的左边加上两个按钮左旋转90度 和右旋转90度的按钮,应该怎么做呢?


下节课交作业之后才能听课。下节课讲视频

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值