• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.wallpaper.picker;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.view.ViewGroup;
21 
22 import androidx.cardview.widget.CardView;
23 
24 import com.android.wallpaper.R;
25 import com.android.wallpaper.util.ScreenSizeCalculator;
26 
27 /** The wallpaper section view in the customization picker fragment. */
28 public final class WallpaperSectionView extends SectionView {
29 
30     private CardView mHomePreviewCard;
31     private CardView mLockscreenPreviewCard;
32 
WallpaperSectionView(Context context, AttributeSet attrs)33     public WallpaperSectionView(Context context, AttributeSet attrs) {
34         super(context, attrs);
35     }
36 
37     @Override
onMeasure(int widthMeasureSpec, int heightMeasureSpec)38     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
39         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
40         matchDeviceShape(mHomePreviewCard);
41         matchDeviceShape(mLockscreenPreviewCard);
42     }
43 
44     @Override
onFinishInflate()45     protected void onFinishInflate() {
46         super.onFinishInflate();
47         mHomePreviewCard = findViewById(R.id.home_preview);
48         mLockscreenPreviewCard = findViewById(R.id.lock_preview);
49 
50         // Disable the shadows of these card views.
51         mHomePreviewCard.setCardElevation(0);
52         mLockscreenPreviewCard.setCardElevation(0);
53     }
54 
matchDeviceShape(CardView cardView)55     private void matchDeviceShape(CardView cardView) {
56         // Match device aspect ratio
57         float screenAspectRatio =
58                 ScreenSizeCalculator.getInstance().getScreenAspectRatio(getContext());
59         int cardWidth = cardView.getMeasuredWidth();
60         int cardHeight = (int) (cardWidth * screenAspectRatio);
61         ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams();
62         layoutParams.height = cardHeight;
63 
64         // TODO(b/218951518): Make corner radius proportional to the card's
65         cardView.setRadius(
66                 getResources().getDimension(R.dimen.wallpaper_picker_entry_card_corner_radius));
67     }
68 }
69