/*
 * *
 *  * ViewUtil.java
 *  * as part of mkcommons-android
 *  *
 *  * Created by michaelkuck, last updated on 7/24/14 9:02 PM
 *  * Unless otherwise stated in a separate LICENSE file for this project
 *  * or agreed via contract, all rights reserved by the author.
 *
 */

package com.michael_kuck.android.mkcommons;

import android.graphics.Point;
import android.view.View;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by michaelkuck on 7/24/14.
 */
public class ViewUtil {

    private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);

    /**
     * Generate a value suitable for use in setId(int).
     * This value will not collide with ID values generated at build time by aapt for R.id.
     * <p/>
     * Note: This method is copied over from later API 17 View.java
     *
     * @return a generated ID value
     */
    public static int generateViewId() {
        for (; ; ) {
            final int result = sNextGeneratedId.get();
            // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
            int newValue = result + 1;
            if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
            if (sNextGeneratedId.compareAndSet(result, newValue)) {
                return result;
            }
        }
    }

    /**
     * Get the absolute screen position of the top left corner of the view in x,y coordinates.
     *
     * @param view
     * @return
     */
    public static Point getAbsoluteOrigin(final View view) {
        final int origin[] = new int[2];
        view.getLocationOnScreen(origin);
        final Point originAsPoint = new Point(origin[0], origin[1]);
        return originAsPoint;
    }

}

@@ -344,39 +344,262 @@
 ics.
-Point;%0Aimport android.view.View
+Bitmap;%0Aimport android.graphics.Canvas;%0Aimport android.graphics.Point;%0Aimport android.graphics.drawable.BitmapDrawable;%0Aimport android.graphics.drawable.Drawable;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.LinearLayout
 ;%0A%0Ai
@@ -1947,10 +1947,1505 @@
 %0A    %7D%0A%0A
+    /**%0A     * View parent holder for inflation, required for rendering some layouts (e.g. RelativeLayouts) before rendering%0A     * with @see renderToTDrawable%0A     * @return%0A     */%0A    public static LinearLayout parentHolderForRendering() %7B%0A%0A        final LinearLayout viewHolder = new LinearLayout(Android.getApplication().getApplicationContext());%0A        viewHolder.setOrientation(LinearLayout.VERTICAL);%0A        final LinearLayout.LayoutParams holderLayoutParams =%0A                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,%0A                                              ViewGroup.LayoutParams.MATCH_PARENT);%0A        viewHolder.setLayoutParams(holderLayoutParams);%0A        return viewHolder;%0A    %7D%0A%0A    public static Drawable renderToDrawable(final View view) %7B%0A        // Measure view size%0A        view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec%0A                .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));%0A        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());%0A%0A        // Render%0A        final Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),%0A                                                  Bitmap.Config.ARGB_8888);%0A        final Canvas canvas = new Canvas(bitmap);%0A        view.draw(canvas);%0A        final Drawable renderedDrawable = new BitmapDrawable(Android.getApplication().getResources(), bitmap);%0A        return renderedDrawable;%0A    %7D%0A%0A
 %7D%0A

Add utility method for rendering views to drawables