/*
 * Copyright 2013 Christian Grach
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cmgapps.android.util;

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;

/**
 * Helper class for retrieving a View from a layout
 */
public class UiUtilities
{
  public static final int ANIMATION_FADE_IN_TIME = 250;

  private UiUtilities()
  {
    // Utility class
  }

  /**
   * <p>
   * Gets a view from a {@link ViewGroup}
   * </p>
   * 
   * @param parent
   *          the view to look in
   * @param resourceId
   *          the id of the view to look for
   * @return the view
   * @throws IllegalArgumentException
   *           if view with the givven id does not exist
   */
  @SuppressWarnings("unchecked")
  public static <T extends View> T getView(View parent, int resourceId)
  {
    return (T) checkView(parent.findViewById(resourceId));
  }

  /**
   * <p>
   * Gets a view from a {@link Activity}
   * </p>
   * 
   * @param parent
   *          the Activity to look in
   * @param resourceId
   *          the id of the view to look for
   * @return the view
   * @throws IllegalArgumentException
   *           if view with the givven id does not exist
   */
  @SuppressWarnings("unchecked")
  public static <T extends View> T getView(Activity parent, int resourceId)
  {
    return (T) checkView(parent.findViewById(resourceId));
  }

  /**
   * <p>
   * Gets a view from a {@link ViewGroup}
   * </p>
   * 
   * @param parent
   *          the view to look in
   * @param resourceId
   *          the id of the view to look for
   * @return the view or null if the view does not exist
   */
  @SuppressWarnings("unchecked")
  public static <T extends View> T getViewOrNull(View parent, int resourceId)
  {
    return (T) parent.findViewById(resourceId);
  }

  /**
   * <p>
   * Gets a view from a {@link Activity}
   * </p>
   * 
   * @param parent
   *          the Activity to look in
   * @param resourceId
   *          the id of the view to look for
   * @return the view or null if the view does not exist
   */
  @SuppressWarnings("unchecked")
  public static <T extends View> T getViewOrNull(Activity parent, int resourceId)
  {
    return (T) parent.findViewById(resourceId);
  }

  private static View checkView(View v)
  {
    if (v == null)
      throw new IllegalArgumentException("View does not exist");

    return v;
  }

  /**
   * Checks if build version is Honeycomb MR1
   * 
   * @return true if build version is >= API 12
   */
  public static boolean hasHoneycombMR1()
  {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
  }

}

@@ -658,16 +658,90 @@
 tivity;%0A
+import android.content.Context;%0Aimport android.content.res.Configuration;%0A
 import a
@@ -757,16 +757,16 @@
 .Build;%0A
-
 import a
@@ -1076,33 +1076,32 @@
 %7D%0A   * %3C/p%3E%0A   *
- 
 %0A   * @param par
@@ -1564,33 +1564,32 @@
 %7D%0A   * %3C/p%3E%0A   *
- 
 %0A   * @param par
@@ -2061,33 +2061,32 @@
 %7D%0A   * %3C/p%3E%0A   *
- 
 %0A   * @param par
@@ -2488,25 +2488,24 @@
  * %3C/p%3E%0A   *
- 
 %0A   * @param
@@ -3057,17 +3057,16 @@
 MR1%0A   *
- 
 %0A   * @r
@@ -3154,24 +3154,24 @@
 mbMR1()%0A  %7B%0A
-
     return B
@@ -3234,10 +3234,218 @@
 1;%0A  %7D%0A%0A
+  public static boolean isTablet(Context context)%0A  %7B%0A    return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) %3E= Configuration.SCREENLAYOUT_SIZE_LARGE;%0A  %7D%0A%0A
 %7D%0A

add tablet check method