12f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann/*
22f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * Copyright (C) 2012 The Android Open Source Project
32f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann *
42f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * Licensed under the Apache License, Version 2.0 (the "License");
52f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * you may not use this file except in compliance with the License.
62f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * You may obtain a copy of the License at
72f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann *
82f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann *      http://www.apache.org/licenses/LICENSE-2.0
92f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann *
102f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * Unless required by applicable law or agreed to in writing, software
112f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * distributed under the License is distributed on an "AS IS" BASIS,
122f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * See the License for the specific language governing permissions and
142f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * limitations under the License.
152f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann */
162f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann
172f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmannpackage com.android.contacts.util;
182f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann
192f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmannimport android.view.View;
202f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmannimport android.view.ViewGroup;
212f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann
222f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann/**
232f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann * Provides static functions to work with views
242f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann */
252f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmannpublic class ViewUtil {
262f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann    private ViewUtil() {}
272f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann
282f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann    /**
292f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann     * Returns the width as specified in the LayoutParams
302f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann     * @throws IllegalStateException Thrown if the view's width is unknown before a layout pass
312f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann     * s
322f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann     */
332f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann    public static int getConstantPreLayoutWidth(View view) {
342f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann        // We haven't been layed out yet, so get the size from the LayoutParams
352f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann        final ViewGroup.LayoutParams p = view.getLayoutParams();
362f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann        if (p.width < 0) {
372f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann            throw new IllegalStateException("Expecting view's width to be a constant rather " +
382f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann                    "than a result of the layout pass");
392f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann        }
402f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann        return p.width;
412f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann    }
422f77c85543e6c497e63cd0e216b70e58c1d13ec3Daniel Lehmann}
43