1b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan/*
2b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * Copyright (C) 2013 The Android Open Source Project
3b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan *
4b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * Licensed under the Apache License, Version 2.0 (the "License");
5b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * you may not use this file except in compliance with the License.
6b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * You may obtain a copy of the License at
7b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan *
8b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan *      http://www.apache.org/licenses/LICENSE-2.0
9b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan *
10b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * Unless required by applicable law or agreed to in writing, software
11b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * distributed under the License is distributed on an "AS IS" BASIS,
12b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * See the License for the specific language governing permissions and
14b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan * limitations under the License.
15b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan */
16b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
17b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chanpackage com.android.calendar.recurrencepicker;
18b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
19b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chanimport android.content.Context;
20b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chanimport android.util.AttributeSet;
21b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chanimport android.view.View;
22b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
23b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chanpublic class WeekButton extends android.widget.ToggleButton {
24b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
25b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    private static int mWidth;
26b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
27b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    public WeekButton(Context context) {
28b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        super(context);
29b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    }
30b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
31b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    public WeekButton(Context context, AttributeSet attrs) {
32b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        super(context, attrs);
33b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    }
34b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
35b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    public WeekButton(Context context, AttributeSet attrs, int defStyle) {
36b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        super(context, attrs, defStyle);
37b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    }
38b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
39b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    public static void setSuggestedWidth(int w) {
40b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        mWidth = w;
41b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    }
42b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan
43b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    @Override
44b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
45b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
46b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan        int h = getMeasuredHeight();
47b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        int w = getMeasuredWidth();
48b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan        if (h > 0 && w > 0) {
49b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan            if (w < h) {
50b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                if (View.MeasureSpec.getMode(getMeasuredHeightAndState()) != MeasureSpec.EXACTLY) {
51b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                    h = w;
52b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                }
53b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan            } else if (h < w) {
54b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                if (View.MeasureSpec.getMode(getMeasuredWidthAndState()) != MeasureSpec.EXACTLY) {
55b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                    w = h;
56b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan                }
57b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan            }
58b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan        }
59b39a2e929a98ab329ce0f4e40b7b0fc617dc6575Michael Chan        setMeasuredDimension(w, h);
60b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan    }
61b21c638ca11d9be3a3d9e7d28223bb4a3dab5f15Michael Chan}
62