blob: 6348148fdafe935581641a11d9baa0a92e4d711a [file] [log] [blame]
Ben Kwa1bb3abe2015-08-20 13:10:33 -07001/*
2 * Copyright (C) 2015 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
17package com.android.documentsui;
18
19import android.content.Context;
Bill Lin6b771722018-08-16 19:56:56 +080020import android.content.res.ColorStateList;
21import android.content.res.TypedArray;
Ben Kwa1bb3abe2015-08-20 13:10:33 -070022import android.util.AttributeSet;
Ben Kwa3e4db1a2015-11-06 11:07:22 -080023import android.widget.ImageView;
Ben Kwa1bb3abe2015-08-20 13:10:33 -070024
25/**
Ben Kwa3e4db1a2015-11-06 11:07:22 -080026 * Ensures that grid thumbnails are always square.
Ben Kwa1bb3abe2015-08-20 13:10:33 -070027 */
Ben Kwa3e4db1a2015-11-06 11:07:22 -080028public class GridItemThumbnail extends ImageView {
29 public GridItemThumbnail(Context context) {
Ben Kwa1bb3abe2015-08-20 13:10:33 -070030 super(context);
31 }
32
Ben Kwa3e4db1a2015-11-06 11:07:22 -080033 public GridItemThumbnail(Context context, AttributeSet attrs) {
Ben Kwa1bb3abe2015-08-20 13:10:33 -070034 super(context, attrs);
35 }
36
Ben Kwa3e4db1a2015-11-06 11:07:22 -080037 public GridItemThumbnail(Context context, AttributeSet attrs, int defStyle) {
Ben Kwa1bb3abe2015-08-20 13:10:33 -070038 super(context, attrs, defStyle);
Bill Lin6b771722018-08-16 19:56:56 +080039 TypedArray ta = context.obtainStyledAttributes(R.styleable.GridItem);
40 ColorStateList color = ta.getColorStateList(R.styleable.GridItem_gridItemTint);
41 ta.recycle();
42 setImageTintList(color);
Ben Kwa1bb3abe2015-08-20 13:10:33 -070043 }
44
45 @Override
46 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
47 // Grid layout uses item width to figure out the number of columns, then dynamically fits
48 // rows into the view. The upshot of this is that changing the item width will mess up the
49 // grid layout - so to make the items square, throw out the height and use the width for
50 // both dimensions. The grid layout will correctly adjust the row height.
51 //
52 // Note that this code will need to be changed if the layout manager's orientation is
53 // changed from VERTICAL to HORIZONTAL.
54 super.onMeasure(widthMeasureSpec, widthMeasureSpec);
55 }
56}