Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

In this page you can find the example usage for android.view View setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.arman.efficientqhalgoforch.SuperAwesomeCardFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (position == 2) {
        final View vv = inflater.inflate(R.layout.benchmark_lay, null);

        Button run = (Button) vv.findViewById(R.id.runAlgor);
        Button reset = (Button) vv.findViewById(R.id.cleardata);
        run.setOnClickListener(new View.OnClickListener() {
            @Override/*  w w  w . j a  v  a2s  . co  m*/
            public void onClick(View v) {
                EditText thrd;
                EditText points;
                EditText canvasY;
                EditText canvasX;
                thrd = (EditText) vv.findViewById(R.id.numberTreadstxt);
                points = (EditText) vv.findViewById(R.id.numberpoints);
                canvasX = (EditText) vv.findViewById(R.id.canvasWidth);
                canvasY = (EditText) vv.findViewById(R.id.canvasHeight);
                int threads = Integer.valueOf(thrd.getText().toString());
                int ponts = Integer.valueOf(points.getText().toString());
                int canvY = Integer.valueOf(canvasY.getText().toString());
                int canvX = Integer.valueOf(canvasX.getText().toString());

                if (threads < 1)
                    threads = 1;
                if (ponts <= 2)
                    ponts = 3;
                if (threads > ponts)
                    threads = ponts - 1;
                if (threads > 25)
                    threads = 25;
                if (canvX + 100 < ponts)
                    canvX = canvX + 100;
                if (canvY + 100 < ponts)
                    canvY = canvY + 100;

                final Point2DCloud point2DCloud = new Point2DCloud(getActivity(), ponts /* points */,
                        Utils.WIDTH = canvY, Utils.HEIGHT = canvX, true);

                int animTime = 10;
                final int finalThreads = threads;
                final int finalPonts = ponts;
                QuickHull qh = new QuickHull(point2DCloud, threads, true, animTime, new DoneListener() {
                    @Override
                    public void jobDone(int id, float time) {
                        mResults.add(new DataHolder(finalThreads, time, finalPonts));
                        updateChart(mResults);

                    }
                });
                qh.run();
                algorithmIndex = 2;

            }
        });

        reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (DataHolder hld : mResults) {
                    mResults.remove(hld);
                }

                updateChart(mResults);

            }
        });
        doHardcore(vv, inflater);

        return vv;
    } else if (position == 3) {

        final View vv = inflater.inflate(R.layout.benchmark_lay, null);

        ((TextView) vv.findViewById(R.id.nametxt)).setText("             GrahamScan\n Multithreaded Benchmark");

        Button run = (Button) vv.findViewById(R.id.runAlgor);
        Button resetgr = (Button) vv.findViewById(R.id.cleardata);
        run.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText thrd;
                EditText points;
                EditText canvasY;
                EditText canvasX;
                thrd = (EditText) vv.findViewById(R.id.numberTreadstxt);
                points = (EditText) vv.findViewById(R.id.numberpoints);
                canvasX = (EditText) vv.findViewById(R.id.canvasWidth);
                canvasY = (EditText) vv.findViewById(R.id.canvasHeight);
                int threads = Integer.valueOf(thrd.getText().toString());
                int ponts = Integer.valueOf(points.getText().toString());
                int canvY = Integer.valueOf(canvasY.getText().toString());
                int canvX = Integer.valueOf(canvasX.getText().toString());

                if (threads < 1)
                    threads = 1;
                if (ponts <= 2)
                    ponts = 3;
                if (threads > ponts)
                    threads = ponts - 1;
                if (threads > 25)
                    threads = 25;
                if (canvX + 100 < ponts)
                    canvX = canvX + 100;
                if (canvY + 100 < ponts)
                    canvY = canvY + 100;

                final Point2DCloud point2DCloud = new Point2DCloud(getActivity(), ponts /* points */,
                        Utils.WIDTH = canvY, Utils.HEIGHT = canvX, true);

                int animTime = 10;
                final int finalThreads = threads;
                final int finalPonts = ponts;
                GrahamScanParallel gh = new GrahamScanParallel(point2DCloud, threads, true, animTime,
                        new DoneListener() {
                            @Override
                            public void jobDone(int id, float time) {
                                mGResults.add(new DataHolder(finalThreads, time, finalPonts));
                                updateChart(mGResults);

                            }
                        });
                gh.run();
                algorithmIndex = 3;

            }
        });

        resetgr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (DataHolder hld : mGResults) {
                    mGResults.remove(hld);
                }
                updateChart(mGResults);
            }
        });
        doHardcore(vv, inflater);

        return vv;

    } else {

        if (position == 0) {

            LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

            FrameLayout fl = new FrameLayout(getActivity());
            fl.setLayoutParams(params);

            final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                    getResources().getDisplayMetrics());

            View v = (View) inflater.inflate(R.layout.intro, null);
            params.setMargins(margin, margin, margin, margin);
            v.setLayoutParams(params);
            v.setLayoutParams(params);
            //v.setBackgroundResource(R.drawable.background_card);

            fl.addView(v);
            //fl.addView(btn);
            return fl;
        } else if (position == 1) {
            LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

            FrameLayout fl = new FrameLayout(getActivity());
            fl.setLayoutParams(params);

            final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                    getResources().getDisplayMetrics());

            View v = (View) inflater.inflate(R.layout.algo, null);
            params.setMargins(margin, margin, margin, margin);
            v.setLayoutParams(params);
            v.setLayoutParams(params);
            //v.setBackgroundResource(R.drawable.background_card);

            fl.addView(v);

            return fl;
        }

    }
    return null;
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addFactoryObstacles(int screens) {
    int totalSlots = screens * SLOTS_PER_SCREEN;
    for (int i = 0; i < totalSlots;) {
        // Any given "slot" has a 1 in 3 chance of having an obstacle
        if (mRandom.nextInt(2) == 0) {
            View view = mInflater.inflate(R.layout.obstacle_layout, null);
            ImageView top = (ImageView) view.findViewById(R.id.top_view);
            ImageView bottom = (ImageView) view.findViewById(R.id.bottom_view);
            ImageView back = (ImageView) view.findViewById(R.id.back_view);

            // Which obstacle?
            int width = 0;
            //                int obstacle = mRandom.nextInt((FACTORY_OBSTACLES.length/2));
            if ((mFactoryObstacleIndex % 20) == 0) {
                ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES,
                        mFactoryObstacles, mFactoryObstacleList, mFactoryObstacleIndex + 20, 2, mScaleX,
                        mScaleY);// ww w  .  j ava2 s. c om
                task.execute();
            }
            int obstacle = mFactoryObstacleList.get(mFactoryObstacleIndex++);
            if (mFactoryObstacleIndex >= mFactoryObstacleList.size()) {
                mFactoryObstacleIndex = 0;
            }
            int topIndex = obstacle * 2;
            int bottomIndex = topIndex + 1;
            back.setVisibility(View.GONE);

            int currentObstacle = 0; // Same values as mLastObstacle
            if (FACTORY_OBSTACLES[topIndex] != -1) {
                currentObstacle |= 1;
                Bitmap bmp = null;
                synchronized (mFactoryObstacles) {
                    bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[topIndex]);
                }
                while (bmp == null) {
                    synchronized (mFactoryObstacles) {
                        bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[topIndex]);
                        if (bmp == null) {
                            try {
                                mFactoryObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                width = bmp.getWidth();
                top.setImageBitmap(bmp);
            } else {
                top.setVisibility(View.GONE);
            }

            if (FACTORY_OBSTACLES[bottomIndex] != -1) {
                currentObstacle |= 2;
                Bitmap bmp = null;
                synchronized (mFactoryObstacles) {
                    bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[bottomIndex]);
                }
                while (bmp == null) {
                    synchronized (mFactoryObstacles) {
                        bmp = mFactoryObstacles.get(FACTORY_OBSTACLES[bottomIndex]);
                        if (bmp == null) {
                            try {
                                mFactoryObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                if (bmp.getWidth() > width) {
                    width = bmp.getWidth();
                }
                bottom.setImageBitmap(bmp);
            } else {
                bottom.setVisibility(View.GONE);
            }
            int slots = (width / mSlotWidth);
            if ((width % mSlotWidth) != 0) {
                slots++;
            }

            // If last obstacle had a top and this is a bottom or vice versa, insert a space
            if ((mLastObstacle & 0x1) > 0) {
                if ((currentObstacle & 0x2) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            } else if ((mLastObstacle & 0x2) > 0) {
                if ((currentObstacle & 0x1) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            }

            // If the new obstacle is too wide for the remaining space, skip it and fill spacer instead
            if ((i + slots) > totalSlots) {
                addSpaceOrPresent(mSlotWidth * (totalSlots - i));
                i = totalSlots;
            } else {
                mLastObstacle = currentObstacle;
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(slots * mSlotWidth,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(lp);
                mObstacleLayout.addView(view);
                i += slots;
            }
        } else {
            addSpaceOrPresent(mSlotWidth);
            i++;
        }
    }

    // Account for rounding errors in mSlotWidth
    int extra = ((screens * mScreenWidth) - (totalSlots * mSlotWidth));
    if (extra > 0) {
        // Add filler to ensure sync with background/foreground scrolls!
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra,
                LinearLayout.LayoutParams.MATCH_PARENT);
        View view = new View(this);
        view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        mObstacleLayout.addView(view, lp);
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addCaveObstacles(int screens) {
    int totalSlots = screens * SLOTS_PER_SCREEN;
    for (int i = 0; i < totalSlots;) {
        // Any given "slot" has a 1 in 3 chance of having an obstacle
        if (mRandom.nextInt(2) == 0) {
            View view = mInflater.inflate(R.layout.obstacle_layout, null);
            ImageView top = (ImageView) view.findViewById(R.id.top_view);
            ImageView bottom = (ImageView) view.findViewById(R.id.bottom_view);
            ImageView back = (ImageView) view.findViewById(R.id.back_view);

            // Which obstacle?
            int width = 0;
            if ((mCaveObstacleIndex % 20) == 0) {
                ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles,
                        mCaveObstacleList, mCaveObstacleIndex + 20, 2, mScaleX, mScaleY);
                task.execute();/*w w w .ja v a 2 s  . c  om*/
            }
            int obstacle = mCaveObstacleList.get(mCaveObstacleIndex++);
            if (mCaveObstacleIndex >= mCaveObstacleList.size()) {
                mCaveObstacleIndex = 0;
            }
            //                int obstacle = mRandom.nextInt((CAVE_OBSTACLES.length/2));
            int topIndex = obstacle * 2;
            int bottomIndex = topIndex + 1;
            back.setVisibility(View.GONE);

            int currentObstacle = 0; // Same values as mLastObstacle
            if (CAVE_OBSTACLES[topIndex] != -1) {
                currentObstacle |= 1;
                Bitmap bmp = null;
                synchronized (mCaveObstacles) {
                    bmp = mCaveObstacles.get(CAVE_OBSTACLES[topIndex]);
                }
                while (bmp == null) {
                    synchronized (mCaveObstacles) {
                        bmp = mCaveObstacles.get(CAVE_OBSTACLES[topIndex]);
                        if (bmp == null) {
                            try {
                                mCaveObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                width = bmp.getWidth();
                top.setImageBitmap(bmp);
            } else {
                top.setVisibility(View.GONE);
            }

            if (CAVE_OBSTACLES[bottomIndex] != -1) {
                currentObstacle |= 2;
                Bitmap bmp = null;
                synchronized (mCaveObstacles) {
                    bmp = mCaveObstacles.get(CAVE_OBSTACLES[bottomIndex]);
                }
                while (bmp == null) {
                    synchronized (mCaveObstacles) {
                        bmp = mCaveObstacles.get(CAVE_OBSTACLES[bottomIndex]);
                        if (bmp == null) {
                            try {
                                mCaveObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                if (bmp.getWidth() > width) {
                    width = bmp.getWidth();
                }
                bottom.setImageBitmap(bmp);
                if (CAVE_OBSTACLES[bottomIndex] == R.drawable.img_mammoth) {
                    // Special case...
                    bottom.setTag(true);
                }
            } else {
                bottom.setVisibility(View.GONE);
            }
            int slots = (width / mSlotWidth);
            slots += 2;

            // If last obstacle had a top and this is a bottom or vice versa, insert a space
            if ((mLastObstacle & 0x1) > 0) {
                if ((currentObstacle & 0x2) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            } else if ((mLastObstacle & 0x2) > 0) {
                if ((currentObstacle & 0x1) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            }

            // If the new obstacle is too wide for the remaining space, skip it and fill spacer instead
            if ((i + slots) > totalSlots) {
                addSpaceOrPresent(mSlotWidth * (totalSlots - i));
                i = totalSlots;
            } else {
                mLastObstacle = currentObstacle;
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(slots * mSlotWidth,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(lp);
                mObstacleLayout.addView(view);
                i += slots;
            }
        } else {
            addSpaceOrPresent(mSlotWidth);
            i++;
        }
    }

    // Account for rounding errors in mSlotWidth
    int extra = ((screens * mScreenWidth) - (totalSlots * mSlotWidth));
    if (extra > 0) {
        // Add filler to ensure sync with background/foreground scrolls!
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra,
                LinearLayout.LayoutParams.MATCH_PARENT);
        View view = new View(this);
        mObstacleLayout.addView(view, lp);
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

@TargetApi(16)
private View obtainView(int position, boolean[] isScrap) {
    isScrap[0] = false;//  ww w .  j  a v  a2s . co m

    View scrapView = mRecycler.getTransientStateView(position);
    if (scrapView != null) {
        return scrapView;
    }

    scrapView = mRecycler.getScrapView(position);

    final View child;
    if (scrapView != null) {
        child = mAdapter.getView(position, scrapView, this);

        if (child != scrapView) {
            mRecycler.addScrapView(scrapView, position);
        } else {
            isScrap[0] = true;
        }
    } else {
        child = mAdapter.getView(position, null, this);
    }

    if (ViewCompat.getImportantForAccessibility(child) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    if (mHasStableIds) {
        LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }

        lp.id = mAdapter.getItemId(position);

        child.setLayoutParams(lp);
    }

    if (mAccessibilityDelegate == null) {
        mAccessibilityDelegate = new ListItemAccessibilityDelegate();
    }

    ViewCompat.setAccessibilityDelegate(child, mAccessibilityDelegate);

    return child;
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void addWoodObstacles(int screens) {
    int totalSlots = screens * SLOTS_PER_SCREEN;
    for (int i = 0; i < totalSlots;) {
        // Any given "slot" has a 1 in 3 chance of having an obstacle
        if (mRandom.nextInt(3) == 0) {
            View view = mInflater.inflate(R.layout.obstacle_layout, null);
            ImageView top = (ImageView) view.findViewById(R.id.top_view);
            ImageView bottom = (ImageView) view.findViewById(R.id.bottom_view);
            ImageView back = (ImageView) view.findViewById(R.id.back_view);

            // Which obstacle?
            int width = 0;
            //            int obstacle = mRandom.nextInt((WOOD_OBSTACLES.length/3));
            if ((mWoodObstacleIndex % 20) == 0) {
                ObstacleLoadTask task = new ObstacleLoadTask(getResources(), WOOD_OBSTACLES, mWoodObstacles,
                        mWoodObstacleList, mWoodObstacleIndex + 20, 3, mScaleX, mScaleY);
                task.execute();//from  w  w w .  ja  v  a2s.  c o  m
            }
            int obstacle = mWoodObstacleList.get(mWoodObstacleIndex++);
            if (mWoodObstacleIndex >= mWoodObstacleList.size()) {
                mWoodObstacleIndex = 0;
            }
            int topIndex = obstacle * 3;
            int bottomIndex = topIndex + 1;
            int backIndex = topIndex + 2;
            if (WOOD_OBSTACLES[backIndex] != -1) {
                Bitmap bmp = null;
                synchronized (mWoodObstacles) {
                    bmp = mWoodObstacles.get(WOOD_OBSTACLES[backIndex]);
                }
                while (bmp == null) {
                    synchronized (mWoodObstacles) {
                        bmp = mWoodObstacles.get(WOOD_OBSTACLES[backIndex]);
                        if (bmp == null) {
                            try {
                                mWoodObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                width = bmp.getWidth();
                back.setImageBitmap(bmp);
            } else {
                back.setVisibility(View.GONE);
            }

            int currentObstacle = 0; // Same values as mLastObstacle
            if (WOOD_OBSTACLES[topIndex] != -1) {
                currentObstacle |= 1;
                Bitmap bmp = null;
                synchronized (mWoodObstacles) {
                    bmp = mWoodObstacles.get(WOOD_OBSTACLES[topIndex]);
                }
                while (bmp == null) {
                    synchronized (mWoodObstacles) {
                        bmp = mWoodObstacles.get(WOOD_OBSTACLES[topIndex]);
                        if (bmp == null) {
                            try {
                                mWoodObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                width = bmp.getWidth();
                top.setImageBitmap(bmp);
            } else {
                top.setVisibility(View.GONE);
            }

            if (WOOD_OBSTACLES[bottomIndex] != -1) {
                currentObstacle |= 2;
                Bitmap bmp = null;
                synchronized (mWoodObstacles) {
                    bmp = mWoodObstacles.get(WOOD_OBSTACLES[bottomIndex]);
                }
                while (bmp == null) {
                    synchronized (mWoodObstacles) {
                        bmp = mWoodObstacles.get(WOOD_OBSTACLES[bottomIndex]);
                        if (bmp == null) {
                            try {
                                mWoodObstacles.wait();
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                }
                if (bmp.getWidth() > width) {
                    width = bmp.getWidth();
                }
                bottom.setImageBitmap(bmp);
            } else {
                bottom.setVisibility(View.GONE);
            }
            int slots = (width / mSlotWidth) + 2;

            // If last obstacle had a top and this is a bottom or vice versa, insert a space
            if ((mLastObstacle & 0x1) > 0) {
                if ((currentObstacle & 0x2) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            } else if ((mLastObstacle & 0x2) > 0) {
                if ((currentObstacle & 0x1) > 0) {
                    addSpaceOrPresent(mSlotWidth);
                    i++;
                }
            }

            // If the new obstacle is too wide for the remaining space, skip it and fill spacer instead
            if ((i + slots) > totalSlots) {
                addSpaceOrPresent(mSlotWidth * (totalSlots - i));
                i = totalSlots;
            } else {
                mLastObstacle = currentObstacle;
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(slots * mSlotWidth,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(lp);
                mObstacleLayout.addView(view);
                i += slots;
            }
        } else {
            addSpaceOrPresent(mSlotWidth);
            i++;
        }
    }

    // Account for rounding errors in mSlotWidth
    int extra = ((screens * mScreenWidth) - (totalSlots * mSlotWidth));
    if (extra > 0) {
        // Add filler to ensure sync with background/foreground scrolls!
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(extra,
                LinearLayout.LayoutParams.MATCH_PARENT);
        View view = new View(this);
        mObstacleLayout.addView(view, lp);
    }
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Get a view and have it show the data associated with the specified
 * position. This is called when we have already discovered that the view is
 * not available for reuse in the recycle bin. The only choices left are
 * converting an old view or making a new one.
 *
 * @param position The position to display
 * @param isScrap Array of at least 1 boolean, the first entry will become true if
 *                the returned view was taken from the scrap heap, false if otherwise.
 *
 * @return A view displaying the data associated with the specified position
 *///w w  w. ja va 2 s.c om
View obtainView(int position, boolean[] isScrap) {
    isScrap[0] = false;
    View scrapView;

    scrapView = mRecycler.getTransientStateView(position);
    if (scrapView != null) {
        return scrapView;
    }

    scrapView = mRecycler.getScrapView(position);

    View child;
    if (scrapView != null) {
        child = mAdapter.getView(position, scrapView, this);

        if (ViewCompat.getImportantForAccessibility(child) == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            ViewCompat.setImportantForAccessibility(child, IMPORTANT_FOR_ACCESSIBILITY_YES);
        }

        if (child != scrapView) {
            mRecycler.addScrapView(scrapView, position);
            if (mCacheColorHint != 0) {
                child.setDrawingCacheBackgroundColor(mCacheColorHint);
            }
        } else {
            isScrap[0] = true;
            AdapterView.dispatchStartTemporaryDetach(child);
        }
    } else {
        child = mAdapter.getView(position, null, this);

        if (ViewCompat.getImportantForAccessibility(child) == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            ViewCompat.setImportantForAccessibility(child, IMPORTANT_FOR_ACCESSIBILITY_YES);
        }

        if (mCacheColorHint != 0) {
            child.setDrawingCacheBackgroundColor(mCacheColorHint);
        }
    }

    if (mAdapterHasStableIds) {
        final ViewGroup.LayoutParams vlp = child.getLayoutParams();
        LayoutParams lp;
        if (vlp == null) {
            lp = (LayoutParams) generateDefaultLayoutParams();
        } else if (!checkLayoutParams(vlp)) {
            lp = (LayoutParams) generateLayoutParams(vlp);
        } else {
            lp = (LayoutParams) vlp;
        }
        lp.itemId = mAdapter.getItemId(position);
        child.setLayoutParams(lp);
    }

    if (getAccessibilityManager().isEnabled()) {
        if (mAccessibilityDelegate == null) {
            mAccessibilityDelegate = new ListItemAccessibilityDelegate();
        }
        ViewCompat.setAccessibilityDelegate(child, mAccessibilityDelegate);
    }

    return child;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

protected void editWidget(final View widget) {
    if (mWorkspace != null) {
        mIsWidgetEditMode = true;//w w  w .ja  v a2  s.co m
        final PersonaCellLayout screen = (PersonaCellLayout) mWorkspace
                .getChildAt(mWorkspace.getCurrentScreen());
        if (screen != null) {
            mlauncherAppWidgetInfo = (PersonaLauncherAppWidgetInfo) widget.getTag();

            final Intent motosize = new Intent("com.motorola.blur.home.ACTION_SET_WIDGET_SIZE");
            final int appWidgetId = ((AppWidgetHostView) widget).getAppWidgetId();
            final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
            if (appWidgetInfo != null) {
                motosize.setComponent(appWidgetInfo.provider);
            }
            motosize.putExtra("appWidgetId", appWidgetId);
            motosize.putExtra("com.motorola.blur.home.EXTRA_NEW_WIDGET", true);
            final int minw = (mWorkspace.getWidth() - screen.getLeftPadding() - screen.getRightPadding())
                    / screen.getCountX();
            final int minh = (mWorkspace.getHeight() - screen.getBottomPadding() - screen.getTopPadding())
                    / screen.getCountY();
            mScreensEditor = new PersonaResizeViewHandler(this);
            // Create a default HightlightView if we found no face in the
            // picture.
            int width = (mlauncherAppWidgetInfo.spanX * minw);
            int height = (mlauncherAppWidgetInfo.spanY * minh);

            final Rect screenRect = new Rect(0, 0, mWorkspace.getWidth() - screen.getRightPadding(),
                    mWorkspace.getHeight() - screen.getBottomPadding());
            final int x = mlauncherAppWidgetInfo.cellX * minw;
            final int y = mlauncherAppWidgetInfo.cellY * minh;
            final int[] spans = new int[] { 1, 1 };
            final int[] position = new int[] { 1, 1 };
            final PersonaCellLayout.LayoutParams lp = (PersonaCellLayout.LayoutParams) widget.getLayoutParams();
            RectF widgetRect = new RectF(x, y, x + width, y + height);
            ((PersonaResizeViewHandler) mScreensEditor).setup(null, screenRect, widgetRect, false, false,
                    minw - 10, minh - 10);
            mDragLayer.addView(mScreensEditor);
            ((PersonaResizeViewHandler) mScreensEditor)
                    .setOnValidateSizingRect(new PersonaResizeViewHandler.OnSizeChangedListener() {

                        @Override
                        public void onTrigger(RectF r) {
                            if (r != null) {
                                final float left = Math.round(r.left / minw) * minw;
                                final float top = Math.round(r.top / minh) * minh;
                                final float right = left + (Math.max(Math.round(r.width() / (minw)), 1) * minw);
                                final float bottom = top
                                        + (Math.max(Math.round(r.height() / (minh)), 1) * minh);

                                r.set(left, top, right, bottom);
                            }
                        }
                    });
            final Rect checkRect = new Rect();
            ((PersonaResizeViewHandler) mScreensEditor)
                    .setOnSizeChangedListener(new PersonaResizeViewHandler.OnSizeChangedListener() {
                        @Override
                        public void onTrigger(RectF r) {
                            int[] tmpspans = { Math.max(Math.round(r.width() / (minw)), 1),
                                    Math.max(Math.round(r.height() / (minh)), 1) };
                            int[] tmpposition = { Math.round(r.left / minw), Math.round(r.top / minh) };
                            checkRect.set(tmpposition[0], tmpposition[1], tmpposition[0] + tmpspans[0],
                                    tmpposition[1] + tmpspans[1]);
                            boolean ocupada = getModel().ocuppiedArea(screen.getScreen(), appWidgetId,
                                    checkRect);
                            if (!ocupada) {
                                ((PersonaResizeViewHandler) mScreensEditor).setColliding(false);
                            } else {
                                ((PersonaResizeViewHandler) mScreensEditor).setColliding(true);
                            }
                            if (tmpposition[0] != position[0] || tmpposition[1] != position[1]
                                    || tmpspans[0] != spans[0] || tmpspans[1] != spans[1]) {
                                if (!ocupada) {
                                    position[0] = tmpposition[0];
                                    position[1] = tmpposition[1];
                                    spans[0] = tmpspans[0];
                                    spans[1] = tmpspans[1];
                                    lp.cellX = position[0];
                                    lp.cellY = position[1];
                                    lp.cellHSpan = spans[0];
                                    lp.cellVSpan = spans[1];
                                    widget.setLayoutParams(lp);
                                    mlauncherAppWidgetInfo.cellX = lp.cellX;
                                    mlauncherAppWidgetInfo.cellY = lp.cellY;
                                    mlauncherAppWidgetInfo.spanX = lp.cellHSpan;
                                    mlauncherAppWidgetInfo.spanY = lp.cellVSpan;
                                    widget.setTag(mlauncherAppWidgetInfo);
                                    // send the broadcast
                                    motosize.putExtra("spanX", spans[0]);
                                    motosize.putExtra("spanY", spans[1]);
                                    PersonaLauncher.this.sendBroadcast(motosize);
                                    PersonaLog.d("RESIZEHANDLER", "sent resize broadcast");
                                }
                            }
                        }
                    });
        }
    }
}

From source file:de.j4velin.mapsmeasure.Map.java

@SuppressLint("NewApi")
@Override//from w w  w . j  av a 2  s  .com
public void onCreate(final Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
    } catch (final BadParcelableException bpe) {
        bpe.printStackTrace();
    }
    setContentView(R.layout.activity_map);

    formatter_no_dec.setMaximumFractionDigits(0);
    formatter_two_dec.setMaximumFractionDigits(2);

    final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE);

    // use metric a the default everywhere, except in the US
    metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US));

    final View topCenterOverlay = findViewById(R.id.topCenterOverlay);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    final View menuButton = findViewById(R.id.menu);
    if (menuButton != null) {
        menuButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        });
    }

    if (mDrawerLayout != null) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

            private boolean menuButtonVisible = true;

            @Override
            public void onDrawerStateChanged(int newState) {

            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onDrawerSlide(final View drawerView, final float slideOffset) {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setAlpha(1 - slideOffset);
                if (menuButtonVisible && menuButton != null && slideOffset > 0) {
                    menuButton.setVisibility(View.INVISIBLE);
                    menuButtonVisible = false;
                }
            }

            @Override
            public void onDrawerOpened(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onDrawerClosed(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.VISIBLE);
                if (menuButton != null) {
                    menuButton.setVisibility(View.VISIBLE);
                    menuButtonVisible = true;
                }
            }
        });
    }

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (mMap == null) {
        Dialog d = GooglePlayServicesUtil
                .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0);
        d.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
        d.show();
        return;
    }

    marker = BitmapDescriptorFactory.fromResource(R.drawable.marker);
    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(final Marker click) {
            addPoint(click.getPosition());
            return true;
        }
    });

    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            if (mMap.getMyLocation() != null) {
                LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(),
                        mMap.getMyLocation().getLongitude());
                double distance = SphericalUtil.computeDistanceBetween(myLocation,
                        mMap.getCameraPosition().target);

                // Only if the distance is less than 50cm we are on our location, add the marker
                if (distance < 0.5) {
                    Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show();
                    addPoint(myLocation);
                }
            }
            return false;
        }
    });

    // check if open with csv file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        try {
            Util.loadFromFile(getIntent().getData(), this);
            if (!trace.isEmpty())
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16));
        } catch (IOException e) {
            Toast.makeText(this,
                    getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(final Bundle bundle) {
                    Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
                    if (l != null && mMap.getCameraPosition().zoom <= 2) {
                        mMap.moveCamera(CameraUpdateFactory
                                .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16));
                    }
                    mGoogleApiClient.disconnect();
                }

                @Override
                public void onConnectionSuspended(int cause) {

                }
            }).build();
    mGoogleApiClient.connect();

    valueTv = (TextView) findViewById(R.id.distance);
    updateValueText();
    valueTv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (type == MeasureType.DISTANCE)
                changeType(MeasureType.AREA);
            // only switch to elevation mode is an internet connection is
            // available and user has access to this feature
            else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION)
                changeType(MeasureType.ELEVATION);
            else
                changeType(MeasureType.DISTANCE);
        }
    });

    View delete = findViewById(R.id.delete);
    delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            removeLast();
        }
    });
    delete.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Map.this);
            builder.setMessage(getString(R.string.delete_all, trace.size()));
            builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    clear();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show();
            return true;
        }
    });

    mMap.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(final LatLng center) {
            addPoint(center);
        }
    });

    // Drawer stuff
    ListView drawerList = (ListView) findViewById(R.id.left_drawer);
    drawerListAdapert = new DrawerListAdapter(this);
    drawerList.setAdapter(drawerListAdapert);
    drawerList.setDivider(null);
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) {
            switch (position) {
            case 0: // Search before Android 5.0
                Dialogs.getSearchDialog(Map.this).show();
                closeDrawer();
                break;
            case 2: // Units
                Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show();
                closeDrawer();
                break;
            case 3: // distance
                changeType(MeasureType.DISTANCE);
                break;
            case 4: // area
                changeType(MeasureType.AREA);
                break;
            case 5: // elevation
                if (PRO_VERSION) {
                    changeType(MeasureType.ELEVATION);
                } else {
                    Dialogs.getElevationAccessDialog(Map.this, mService).show();
                }
                break;
            case 7: // map
                changeView(GoogleMap.MAP_TYPE_NORMAL);
                break;
            case 8: // satellite
                changeView(GoogleMap.MAP_TYPE_HYBRID);
                break;
            case 9: // terrain
                changeView(GoogleMap.MAP_TYPE_TERRAIN);
                break;
            case 11: // save
                Dialogs.getSaveNShare(Map.this, trace).show();
                closeDrawer();
                break;
            case 12: // more apps
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin"))
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (ActivityNotFoundException anf) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/developer?id=j4velin"))
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
            case 13: // about
                Dialogs.getAbout(Map.this).show();
                closeDrawer();
                break;
            default:
                break;
            }
        }
    });

    changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL));
    changeType(MeasureType.DISTANCE);

    // KitKat translucent decor enabled? -> Add some margin/padding to the
    // drawer and the map
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {

        int statusbar = Util.getStatusBarHeight(this);

        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams();
        lp.setMargins(0, statusbar + 10, 0, 0);
        topCenterOverlay.setLayoutParams(lp);

        // on most devices and in most orientations, the navigation bar
        // should be at the bottom and therefore reduces the available
        // display height
        int navBarHeight = Util.getNavigationBarHeight(this);

        DisplayMetrics total, available;
        total = new DisplayMetrics();
        available = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(available);
        API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total);

        boolean navBarOnRight = getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE
                && (total.widthPixels - available.widthPixels > 0);

        if (navBarOnRight) {
            // in landscape on phones, the navigation bar might be at the
            // right side, reducing the available display width
            mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, 0);
        } else {
            mMap.setPadding(0, statusbar, 0, navBarHeight);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            drawerListAdapert.setMarginBottom(navBarHeight);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, navBarHeight);
        }
    }

    mMap.setMyLocationEnabled(true);

    PRO_VERSION |= prefs.getBoolean("pro", false);
    if (!PRO_VERSION) {
        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);
    }
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

@SuppressLint("NewApi")
private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) {
    if (viewRunnables == null)
        createViewRunnables();/* w  w  w  . j  a va2  s . co  m*/
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    int layoutRule;
    int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0,
            paddingTop = 0, paddingBottom = 0;
    boolean hasCornerRadius = false, hasCornerRadii = false;
    for (Map.Entry<String, String> entry : attrs.entrySet()) {
        String attr = entry.getKey();
        if (viewRunnables.containsKey(attr)) {
            viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs);
            continue;
        }
        if (attr.startsWith("cornerRadius")) {
            hasCornerRadius = true;
            hasCornerRadii = !attr.equals("cornerRadius");
            continue;
        }
        layoutRule = NO_LAYOUT_RULE;
        boolean layoutTarget = false;
        switch (attr) {
        case "id":
            String idValue = parseId(entry.getValue());
            if (parent != null) {
                DynamicLayoutInfo info = getDynamicLayoutInfo(parent);
                int newId = highestIdNumberUsed++;
                view.setId(newId);
                info.nameToIdNumber.put(idValue, newId);
            }
            break;
        case "width":
        case "layout_width":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, true);
                break;
            }
            break;
        case "height":
        case "layout_height":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, false);
                break;
            }
            break;
        case "layout_gravity":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            } else if (parent != null && parent instanceof FrameLayout) {
                ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            }
            break;
        case "layout_weight":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue());
            }
            break;
        case "layout_below":
            layoutRule = RelativeLayout.BELOW;
            layoutTarget = true;
            break;
        case "layout_above":
            layoutRule = RelativeLayout.ABOVE;
            layoutTarget = true;
            break;
        case "layout_toLeftOf":
            layoutRule = RelativeLayout.LEFT_OF;
            layoutTarget = true;
            break;
        case "layout_toRightOf":
            layoutRule = RelativeLayout.RIGHT_OF;
            layoutTarget = true;
            break;
        case "layout_alignBottom":
            layoutRule = RelativeLayout.ALIGN_BOTTOM;
            layoutTarget = true;
            break;
        case "layout_alignTop":
            layoutRule = RelativeLayout.ALIGN_TOP;
            layoutTarget = true;
            break;
        case "layout_alignLeft":
        case "layout_alignStart":
            layoutRule = RelativeLayout.ALIGN_LEFT;
            layoutTarget = true;
            break;
        case "layout_alignRight":
        case "layout_alignEnd":
            layoutRule = RelativeLayout.ALIGN_RIGHT;
            layoutTarget = true;
            break;
        case "layout_alignParentBottom":
            layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM;
            break;
        case "layout_alignParentTop":
            layoutRule = RelativeLayout.ALIGN_PARENT_TOP;
            break;
        case "layout_alignParentLeft":
        case "layout_alignParentStart":
            layoutRule = RelativeLayout.ALIGN_PARENT_LEFT;
            break;
        case "layout_alignParentRight":
        case "layout_alignParentEnd":
            layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT;
            break;
        case "layout_centerHorizontal":
            layoutRule = RelativeLayout.CENTER_HORIZONTAL;
            break;
        case "layout_centerVertical":
            layoutRule = RelativeLayout.CENTER_VERTICAL;
            break;
        case "layout_centerInParent":
            layoutRule = RelativeLayout.CENTER_IN_PARENT;
            break;
        case "layout_margin":
            marginLeft = marginRight = marginTop = marginBottom = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "layout_marginLeft":
            marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginTop":
            marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "layout_marginRight":
            marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginBottom":
            marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "padding":
            paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "paddingLeft":
            paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingTop":
            paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingRight":
            paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingBottom":
            paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;

        }
        if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) {
            if (layoutTarget) {
                int anchor = idNumFromIdString(parent, parseId(entry.getValue()));
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor);
            } else if (entry.getValue().equals("true")) {
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule);
            }
        }
    }
    // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background
    if (attrs.containsKey("background") || attrs.containsKey("borderColor")) {
        String bgValue = attrs.containsKey("background") ? attrs.get("background") : null;
        if (bgValue != null && bgValue.startsWith("@drawable/")) {
            view.setBackground(getDrawableByName(view, bgValue));
        } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) {
            if (view instanceof Button || attrs.containsKey("pressedColor")) {
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                int pressedColor;
                if (attrs.containsKey("pressedColor")) {
                    pressedColor = parseColor(view, attrs.get("pressedColor"));
                } else {
                    pressedColor = adjustBrightness(bgColor, 0.9f);
                }
                GradientDrawable gd = new GradientDrawable();
                gd.setColor(bgColor);
                GradientDrawable pressedGd = new GradientDrawable();
                pressedGd.setColor(pressedColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                        pressedGd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                    pressedGd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth,
                            view.getResources().getDisplayMetrics());
                    gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                    pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                }
                StateListDrawable selector = new StateListDrawable();
                selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd);
                selector.addState(new int[] {}, gd);
                view.setBackground(selector);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else if (hasCornerRadius || attrs.containsKey("borderColor")) {
                GradientDrawable gd = new GradientDrawable();
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                gd.setColor(bgColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    gd.setStroke(
                            DimensionConverter.stringToDimensionPixelSize(borderWidth,
                                    view.getResources().getDisplayMetrics()),
                            parseColor(view, attrs.get("borderColor")));
                }
                view.setBackground(gd);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else {
                view.setBackgroundColor(parseColor(view, bgValue));
            }
        }
    }

    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight,
                marginBottom);
    }
    view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    view.setLayoutParams(layoutParams);
}