12fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki/* 22fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Copyright (C) 2011 The Android Open Source Project 32fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * 42fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Licensed under the Apache License, Version 2.0 (the "License"); 52fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * you may not use this file except in compliance with the License. 62fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * You may obtain a copy of the License at 72fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * 82fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * http://www.apache.org/licenses/LICENSE-2.0 92fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * 102fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Unless required by applicable law or agreed to in writing, software 112fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * distributed under the License is distributed on an "AS IS" BASIS, 122fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * See the License for the specific language governing permissions and 142fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * limitations under the License. 152fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki */ 162fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 172fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukipackage com.android.email.activity; 182fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 192fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukiimport android.app.Activity; 202fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukiimport android.content.Context; 212fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukiimport android.content.res.Resources; 222fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukiimport android.view.View; 232fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 24f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blankimport com.android.email.R; 25f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank 262fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onukipublic class UiUtilities { 272fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki private UiUtilities() { 282fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 292fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 302fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki /** 312fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Same as {@link View#findViewById}, but crashes if there's no view. 322fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki */ 33256652050c8c047d1879621805f028454e83b677Ben Komalo @SuppressWarnings("unchecked") 34256652050c8c047d1879621805f028454e83b677Ben Komalo public static <T extends View> T getView(View parent, int viewId) { 35256652050c8c047d1879621805f028454e83b677Ben Komalo return (T) checkView(parent.findViewById(viewId)); 362fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 372fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 382fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki private static View checkView(View v) { 392fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki if (v == null) { 402fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki throw new IllegalArgumentException("View doesn't exist"); 412fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 422fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki return v; 432fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 442fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 452fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki /** 462fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Same as {@link View#setVisibility(int)}, but doesn't crash even if {@code view} is null. 472fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki */ 482fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki public static void setVisibilitySafe(View v, int visibility) { 492fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki if (v != null) { 502fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki v.setVisibility(visibility); 512fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 522fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 532fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki 542fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki /** 552fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki * Same as {@link View#setVisibility(int)}, but doesn't crash even if {@code view} is null. 562fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki */ 572fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki public static void setVisibilitySafe(View parent, int viewId, int visibility) { 582fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki setVisibilitySafe(parent.findViewById(viewId), visibility); 592fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki } 602fbb3db5d86210d03175ce77ff08c989a96c5864Makoto Onuki} 61