Android Open Source - RecyclerViewLib Card View Eclair Mr1






From Project

Back to project page RecyclerViewLib.

License

The source code is released under:

Apache License

If you think the Android project RecyclerViewLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 The Android Open Source Project
 */*from   w  ww .  j  ava2  s . com*/
 * 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.twotoasters.android.support.v7.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;

class CardViewEclairMr1 implements CardViewImpl {

    final RectF sCornerRect = new RectF();

    @Override
    public void initStatic() {
        // Draws a round rect using 7 draw operations. This is faster than using
        // canvas.drawRoundRect before JBMR1 because API 11-16 used alpha mask textures to draw
        // shapes.
        RoundRectDrawableWithShadow.sRoundRectHelper
                = new RoundRectDrawableWithShadow.RoundRectHelper() {
            @Override
            public void drawRoundRect(Canvas canvas, RectF bounds, float cornerRadius,
                    Paint paint) {
                final float twoRadius = cornerRadius * 2;
                final float innerWidth = bounds.width() - twoRadius;
                final float innerHeight = bounds.height() - twoRadius;
                sCornerRect.set(bounds.left, bounds.top,
                        bounds.left + cornerRadius * 2, bounds.top + cornerRadius * 2);

                canvas.drawArc(sCornerRect, 180, 90, true, paint);
                sCornerRect.offset(innerWidth, 0);
                canvas.drawArc(sCornerRect, 270, 90, true, paint);
                sCornerRect.offset(0, innerHeight);
                canvas.drawArc(sCornerRect, 0, 90, true, paint);
                sCornerRect.offset(-innerWidth, 0);
                canvas.drawArc(sCornerRect, 90, 90, true, paint);

                //draw top and bottom pieces
                canvas.drawRect(bounds.left + cornerRadius, bounds.top,
                        bounds.right - cornerRadius, bounds.top + cornerRadius,
                        paint);
                canvas.drawRect(bounds.left + cornerRadius,
                        bounds.bottom - cornerRadius, bounds.right - cornerRadius,
                        bounds.bottom, paint);

                //center
                canvas.drawRect(bounds.left, bounds.top + cornerRadius,
                        bounds.right, bounds.bottom - cornerRadius, paint);
            }
        };
    }

    @Override
    public void initialize(CardViewDelegate cardView, Context context, int backgroundColor,
            float radius) {
        RoundRectDrawableWithShadow background = new RoundRectDrawableWithShadow(
                context.getResources(), backgroundColor, radius);
        cardView.setBackgroundDrawable(background);
    }

    @Override
    public void setRadius(CardViewDelegate cardView, float radius) {
        ((RoundRectDrawableWithShadow) cardView.getBackground()).setCornerRadius(radius);
    }

    @Override
    public float getRadius(CardViewDelegate cardView) {
        return ((RoundRectDrawableWithShadow) cardView.getBackground()).getCornerRadius();
    }
}




Java Source Code List

com.twotoasters.android.support.v7.widget.CardViewDelegate.java
com.twotoasters.android.support.v7.widget.CardViewEclairMr1.java
com.twotoasters.android.support.v7.widget.CardViewImpl.java
com.twotoasters.android.support.v7.widget.CardViewJellybeanMr1.java
com.twotoasters.android.support.v7.widget.CardView.java
com.twotoasters.android.support.v7.widget.DefaultItemAnimator.java
com.twotoasters.android.support.v7.widget.LinearLayoutManager.java
com.twotoasters.android.support.v7.widget.LinearSmoothScroller.java
com.twotoasters.android.support.v7.widget.PositionMap.java
com.twotoasters.android.support.v7.widget.RecyclerView.java
com.twotoasters.android.support.v7.widget.RoundRectDrawableWithShadow.java
com.twotoasters.anim.FlipDownItemAnimator.java
com.twotoasters.anim.FromTopItemAnimator.java
com.twotoasters.anim.GarageDoorItemAnimator.java
com.twotoasters.anim.PendingItemAnimator.java
com.twotoasters.anim.SlideItemAnimator.java
com.twotoasters.layoutmanager.BaseLayoutManager.java
com.twotoasters.layoutmanager.GridLayoutManager.java
com.twotoasters.recycled.ApplicationTest.java
com.twotoasters.recycled.Item.java
com.twotoasters.recycled.NameAdapter.java
com.twotoasters.recycled.NameViewHolder.java
com.twotoasters.recycled.RecycleActivity.java
com.twotoasters.recycled.factory.ItemAnimationFactory.java
com.twotoasters.recycled.factory.NameFactory.java
com.twotoasters.utils.DisplayUtils.java