1 /* 2 * Copyright (C) 2020 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 package com.android.quickstep.interaction; 17 18 import android.content.Context; 19 import android.content.res.TypedArray; 20 import android.graphics.Color; 21 import android.graphics.Insets; 22 import android.util.AttributeSet; 23 import android.view.MotionEvent; 24 import android.view.WindowInsets; 25 import android.widget.RelativeLayout; 26 27 import androidx.annotation.ColorInt; 28 import androidx.annotation.NonNull; 29 import androidx.annotation.Nullable; 30 import androidx.fragment.app.FragmentManager; 31 32 import com.android.launcher3.R; 33 import com.android.launcher3.Utilities; 34 35 /** Root layout that TutorialFragment uses to intercept motion events. */ 36 public class RootSandboxLayout extends RelativeLayout { 37 38 @ColorInt final int mColorSurfaceContainer; 39 @ColorInt final int mColorOnSurfaceHome; 40 @ColorInt final int mColorSurfaceHome; 41 @ColorInt final int mColorSecondaryHome; 42 @ColorInt final int mColorOnSurfaceBack; 43 @ColorInt final int mColorSurfaceBack; 44 @ColorInt final int mColorSecondaryBack; 45 @ColorInt final int mColorOnSurfaceOverview; 46 @ColorInt final int mColorSurfaceOverview; 47 @ColorInt final int mColorSecondaryOverview; 48 RootSandboxLayout(Context context)49 public RootSandboxLayout(Context context) { 50 this(context, null); 51 } 52 RootSandboxLayout(Context context, AttributeSet attrs)53 public RootSandboxLayout(Context context, AttributeSet attrs) { 54 this(context, attrs, 0); 55 } 56 RootSandboxLayout(Context context, AttributeSet attrs, int defStyleAttr)57 public RootSandboxLayout(Context context, AttributeSet attrs, int defStyleAttr) { 58 this(context, attrs, defStyleAttr, 0); 59 } 60 RootSandboxLayout( @onNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)61 public RootSandboxLayout( 62 @NonNull Context context, 63 @Nullable AttributeSet attrs, 64 int defStyleAttr, 65 int defStyleRes) { 66 super(context, attrs, defStyleAttr, defStyleRes); 67 TypedArray ta = context.obtainStyledAttributes( 68 attrs, 69 R.styleable.RootSandboxLayout, 70 defStyleAttr, 71 defStyleRes); 72 boolean isDarkTheme = Utilities.isDarkTheme(context); 73 int colorSurface = isDarkTheme ? Color.BLACK : Color.WHITE; 74 int colorOnSurface = isDarkTheme ? Color.WHITE : Color.BLACK; 75 int colorSecondary = Color.GRAY; 76 77 mColorSurfaceContainer = ta.getColor( 78 R.styleable.RootSandboxLayout_surfaceContainer, colorSurface); 79 mColorOnSurfaceHome = ta.getColor( 80 R.styleable.RootSandboxLayout_onSurfaceHome, colorOnSurface); 81 mColorSurfaceHome = ta.getColor(R.styleable.RootSandboxLayout_surfaceHome, colorSurface); 82 mColorSecondaryHome = ta.getColor( 83 R.styleable.RootSandboxLayout_secondaryHome, colorSecondary); 84 mColorOnSurfaceBack = ta.getColor( 85 R.styleable.RootSandboxLayout_onSurfaceBack, colorOnSurface); 86 mColorSurfaceBack = ta.getColor(R.styleable.RootSandboxLayout_surfaceBack, colorSurface); 87 mColorSecondaryBack = ta.getColor( 88 R.styleable.RootSandboxLayout_secondaryBack, colorSecondary); 89 mColorOnSurfaceOverview = ta.getColor( 90 R.styleable.RootSandboxLayout_onSurfaceOverview, colorOnSurface); 91 mColorSurfaceOverview = ta.getColor( 92 R.styleable.RootSandboxLayout_surfaceOverview, colorSurface); 93 mColorSecondaryOverview = ta.getColor( 94 R.styleable.RootSandboxLayout_secondaryOverview, colorSecondary); 95 96 ta.recycle(); 97 } 98 99 @Override onInterceptTouchEvent(MotionEvent motionEvent)100 public boolean onInterceptTouchEvent(MotionEvent motionEvent) { 101 return ((TutorialFragment) FragmentManager.findFragment(this)) 102 .onInterceptTouch(motionEvent); 103 } 104 105 /** 106 * Returns this view's fullscreen height. This method is agnostic of this view's actual height. 107 */ getFullscreenHeight()108 public int getFullscreenHeight() { 109 Insets insets = getRootWindowInsets().getInsets(WindowInsets.Type.systemBars()); 110 111 return getHeight() + insets.top + insets.bottom; 112 } 113 } 114