1 /* 2 * Copyright (C) 2022 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.example.android.apis.app; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.content.res.Configuration; 22 import android.graphics.Rect; 23 import android.os.Bundle; 24 import android.os.RemoteException; 25 import android.util.Log; 26 import android.view.View; 27 import android.widget.CompoundButton; 28 import android.widget.RelativeLayout; 29 import android.widget.Switch; 30 31 import com.example.android.apis.R; 32 33 import java.util.Arrays; 34 import java.util.List; 35 36 public class KeepClearRects extends Activity { 37 private static final String EXTRA_SET_PREFER_KEEP_CLEAR = "prefer_keep_clear"; 38 private static final String EXTRA_SET_PREFER_KEEP_CLEAR_RECTS = "prefer_keep_clear_rects"; 39 40 private RelativeLayout mRootView; 41 private View mKeepClearView; 42 private Switch mViewAsRestrictedKeepClearAreaToggle; 43 private Switch mBottomRightCornerKeepClearAreaToggle; 44 45 @Override onCreate(Bundle savedInstanceState)46 protected void onCreate(Bundle savedInstanceState) { 47 super.onCreate(savedInstanceState); 48 setContentView(R.layout.keep_clear_rects_activity); 49 50 // Find views 51 mRootView = findViewById(R.id.container); 52 mKeepClearView = findViewById(R.id.keep_clear_view_bottom_right); 53 mViewAsRestrictedKeepClearAreaToggle = findViewById(R.id.set_prefer_keep_clear_toggle); 54 mBottomRightCornerKeepClearAreaToggle = findViewById( 55 R.id.set_bottom_right_rectangle_keep_clear_toggle); 56 57 // Add listeners 58 mViewAsRestrictedKeepClearAreaToggle.setOnCheckedChangeListener(mOnToggleChangedListener); 59 mBottomRightCornerKeepClearAreaToggle.setOnCheckedChangeListener( 60 mBottomRightCornerToggleChangedListener); 61 62 // Get defaults 63 final Intent intent = getIntent(); 64 mViewAsRestrictedKeepClearAreaToggle.setChecked( 65 intent.getBooleanExtra(EXTRA_SET_PREFER_KEEP_CLEAR, false)); 66 mBottomRightCornerKeepClearAreaToggle.setChecked( 67 intent.getBooleanExtra(EXTRA_SET_PREFER_KEEP_CLEAR_RECTS, false)); 68 } 69 70 private final CompoundButton.OnCheckedChangeListener mOnToggleChangedListener = 71 (v, isChecked) -> mKeepClearView.setPreferKeepClear(isChecked); 72 73 private final CompoundButton.OnCheckedChangeListener mBottomRightCornerToggleChangedListener = 74 (v, isChecked) -> { 75 if (isChecked) { 76 mRootView.setPreferKeepClearRects( 77 Arrays.asList(new Rect( 78 mKeepClearView.getLeft(), 79 mKeepClearView.getTop(), 80 mKeepClearView.getRight(), 81 mKeepClearView.getBottom()))); 82 } else { 83 mRootView.setPreferKeepClearRects(List.of()); 84 } 85 }; 86 } 87