package com.mm.android.deviceaddmodule.mobilecommon.utils; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; public class UIHelper { /** * 设置按钮选ä¸ä¸Žå¦ * <p> * @param selected * @param views */ public static void setSelected(boolean selected, View... views) { for (View view : views) { view.setSelected(selected); } } /** * 设置空间是å¦å¯ç”¨ï¼ˆä¸ç½®ç°ï¼‰ * <p> * </p> * @param enabled * @param views */ public static void setEnabled(boolean enabled, View... views) { for (View view : views) { view.setEnabled(enabled); } } /** * å¯ç”¨/ç¦ç”¨æŽ§ä»¶ï¼ŒåŒ…æ‹¬æ‰€æœ‰åæŽ§ä»¶ * <p> * </p> * @param enabled */ public static void setEnabledSub(boolean enabled, ViewGroup... viewGroups) { for (ViewGroup viewGroup : viewGroups) { viewGroup.setEnabled(enabled); for (int i = 0; i < viewGroup.getChildCount(); i++) { View v = viewGroup.getChildAt(i); if (v instanceof ViewGroup) { setEnabledSub(enabled, (ViewGroup) v); } else { setEnabled(enabled, v); } } } } /** * 设置控件å¯ç”¨ä¸Žå¦ (ç½®ç°) * * @param enabled * 是å¦å¯ç”¨ */ public static void setEnabledEX(boolean enabled, View... views) { for (View view : views) { if (enabled) { view.setEnabled(enabled); view.clearAnimation(); } else { Animation aniAlp = new AlphaAnimation(1f, 0.5f); aniAlp.setDuration(0); aniAlp.setInterpolator(new AccelerateDecelerateInterpolator()); aniAlp.setFillEnabled(true); aniAlp.setFillAfter(true); view.startAnimation(aniAlp); view.setEnabled(enabled); } } } /** * é历布局,ç¦ç”¨/å¯ç”¨æ‰€æœ‰å控件 * <p> * </p> * @param enabled */ public static void setEnabledSubEX(boolean enabled, ViewGroup... viewGroups) { for (ViewGroup viewGroup : viewGroups) { setEnabledEX(enabled, viewGroup); for (int i = 0; i < viewGroup.getChildCount(); i++) { View v = viewGroup.getChildAt(i); if (v instanceof ViewGroup) { setEnabledSubEX(enabled, (ViewGroup) v); } else { setEnabledEX(enabled, v); } } } } /** * éšè—/显示 * <p> * </p> * @param visibility * @param views */ public static void setVisibility(int visibility, View... views) { for (View view : views) { view.setVisibility(visibility); } } }