• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.systemui.util;
18 
19 import android.content.Context;
20 import android.content.res.Configuration;
21 import android.content.res.Resources;
22 import android.view.Gravity;
23 import android.widget.FrameLayout;
24 import android.widget.ImageView;
25 
26 import com.android.systemui.R;
27 
28 /**
29  * Circular view with a semitransparent, circular background with an 'X' inside it.
30  *
31  * This is used by both Bubbles and PIP as the dismiss target.
32  */
33 public class DismissCircleView extends FrameLayout {
34 
35     private final ImageView mIconView = new ImageView(getContext());
36 
DismissCircleView(Context context)37     public DismissCircleView(Context context) {
38         super(context);
39         final Resources res = getResources();
40 
41         setBackground(res.getDrawable(R.drawable.dismiss_circle_background));
42 
43         mIconView.setImageDrawable(res.getDrawable(R.drawable.ic_close_white));
44         addView(mIconView);
45 
46         setViewSizes();
47     }
48 
49     @Override
onConfigurationChanged(Configuration newConfig)50     protected void onConfigurationChanged(Configuration newConfig) {
51         super.onConfigurationChanged(newConfig);
52         setViewSizes();
53     }
54 
55     /** Retrieves the current dimensions for the icon and circle and applies them. */
setViewSizes()56     private void setViewSizes() {
57         final Resources res = getResources();
58         final int iconSize = res.getDimensionPixelSize(R.dimen.dismiss_target_x_size);
59         mIconView.setLayoutParams(
60                 new FrameLayout.LayoutParams(iconSize, iconSize, Gravity.CENTER));
61     }
62 }
63