1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.ui; 18 19 import android.content.Context; 20 import android.graphics.RectF; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.FrameLayout; 24 25 import com.android.camera.CaptureLayoutHelper; 26 import com.android.camera.debug.Log; 27 import com.android.camera2.R; 28 29 /** 30 * The goal of this class is to ensure mode options is always laid out to 31 * the left of or above bottom bar in landscape or portrait respectively. 32 * All the other children in this view group can be expected to be laid out 33 * the same way as they are in a normal FrameLayout. 34 */ 35 public class BottomBarModeOptionsWrapper extends FrameLayout { 36 37 private final static Log.Tag TAG = new Log.Tag("BottomBarWrapper"); 38 private View mModeOptionsOverlay; 39 private View mBottomBar; 40 private CaptureLayoutHelper mCaptureLayoutHelper = null; 41 BottomBarModeOptionsWrapper(Context context, AttributeSet attrs)42 public BottomBarModeOptionsWrapper(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 } 45 46 @Override onFinishInflate()47 public void onFinishInflate() { 48 mModeOptionsOverlay = findViewById(R.id.mode_options_overlay); 49 mBottomBar = findViewById(R.id.bottom_bar); 50 } 51 52 /** 53 * Sets a capture layout helper to query layout rect from. 54 */ setCaptureLayoutHelper(CaptureLayoutHelper helper)55 public void setCaptureLayoutHelper(CaptureLayoutHelper helper) { 56 mCaptureLayoutHelper = helper; 57 } 58 59 @Override onLayout(boolean changed, int left, int top, int right, int bottom)60 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 61 if (mCaptureLayoutHelper == null) { 62 Log.e(TAG, "Capture layout helper needs to be set first."); 63 return; 64 } 65 RectF uncoveredPreviewRect = mCaptureLayoutHelper.getUncoveredPreviewRect(); 66 RectF bottomBarRect = mCaptureLayoutHelper.getBottomBarRect(); 67 68 mModeOptionsOverlay.layout((int) uncoveredPreviewRect.left, (int) uncoveredPreviewRect.top, 69 (int) uncoveredPreviewRect.right, (int) uncoveredPreviewRect.bottom); 70 mBottomBar.layout((int) bottomBarRect.left, (int) bottomBarRect.top, 71 (int) bottomBarRect.right, (int) bottomBarRect.bottom); 72 } 73 }