Android Open Source - Pimp_my_Z1 Card U I






From Project

Back to project page Pimp_my_Z1.

License

The source code is released under:

GNU General Public License

If you think the Android project Pimp_my_Z1 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

package com.fima.cardsui.views;
/*w w w  . ja v a2s  .  c  om*/
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.FrameLayout;
import android.widget.Space;
import android.widget.TableLayout;
import android.widget.TableRow;

import com.fima.cardsui.R;
import com.fima.cardsui.StackAdapter;
import com.fima.cardsui.objects.AbstractCard;
import com.fima.cardsui.objects.Card;
import com.fima.cardsui.objects.CardStack;

import java.util.ArrayList;

public class CardUI extends FrameLayout {

    /**
     * Constants
     */

    private static final int STATE_ONSCREEN = 0;
    private static final int STATE_OFFSCREEN = 1;
    private static final int STATE_RETURNING = 2;
    protected int renderedCardsStacks = 0;
    protected int mScrollY;
    /**
     * *****************************
     * Fields
     * <p/>
     * ******************************
     */

    private ArrayList<AbstractCard> mStacks;
    private Context mContext;
    private ViewGroup mQuickReturnView;
    /**
     * The table layout to be used for multiple columns
     */
    private TableLayout mTableLayout;
    /**
     * The number of columns, 1 by default
     */
    private int mColumnNumber = 1;
    private View mPlaceholderView;
    private QuickReturnListView mListView;
    private int mMinRawY = 0;
    private int mState = STATE_ONSCREEN;
    private int mQuickReturnHeight;
    private int mCachedVerticalScrollRange;
    private boolean mSwipeable = false;
    private OnRenderedListener onRenderedListener;
    private StackAdapter mAdapter;
    private View mHeader;

    /**
     * Constructor
     */
    public CardUI(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        //read the number of columns from the attributes
        mColumnNumber = attrs.getAttributeIntValue(null, "columnCount", 1);
        initData(context);
    }

    /**
     * Constructor
     */
    public CardUI(Context context, AttributeSet attrs) {
        super(context, attrs);
        //read the number of columns from the attributes
        mColumnNumber = attrs.getAttributeIntValue(null, "columnCount", 1);
        initData(context);
    }

    /**
     * Constructor
     */
    public CardUI(Context context) {
        super(context);
        initData(context);
    }

    private void initData(Context context) {
        mContext = context;
        LayoutInflater inflater = LayoutInflater.from(context);
        mStacks = new ArrayList<AbstractCard>();
        //inflate a different layout, depending on the number of columns
        if (mColumnNumber == 1) {
            inflater.inflate(R.layout.cards_view, this);
            // init observable scrollview
            mListView = (QuickReturnListView) findViewById(R.id.listView);
        } else {
            //initialize the mulitcolumn view
            inflater.inflate(R.layout.cards_view_multicolumn, this);
            mTableLayout = (TableLayout) findViewById(R.id.tableLayout);
        }
        // mListView.setCallbacks(this);

        mHeader = inflater.inflate(R.layout.header, null);
        mQuickReturnView = (ViewGroup) findViewById(R.id.sticky);
        mPlaceholderView = mHeader.findViewById(R.id.placeholder);

    }

    public void setSwipeable(boolean b) {
        mSwipeable = b;
    }

    public void setHeader(View header) {

        mPlaceholderView.setVisibility(View.VISIBLE);

        mListView.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {

                        mQuickReturnHeight = mQuickReturnView.getHeight();
                        mListView.computeScrollY();
                        mCachedVerticalScrollRange = mListView.getListHeight();

                    }
                });

        mListView.setOnScrollListener(new OnScrollListener() {
            @SuppressLint("NewApi")
            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                                 int visibleItemCount, int totalItemCount) {

                mScrollY = 0;
                int translationY = 0;

                if (mListView.scrollYIsComputed()) {
                    mScrollY = mListView.getComputedScrollY();
                }

                int rawY = mPlaceholderView.getTop()
                        - Math.min(
                        mCachedVerticalScrollRange
                                - mListView.getHeight(), mScrollY);

                switch (mState) {
                    case STATE_OFFSCREEN:
                        if (rawY <= mMinRawY) {
                            mMinRawY = rawY;
                        } else {
                            mState = STATE_RETURNING;
                        }
                        translationY = rawY;
                        break;

                    case STATE_ONSCREEN:
                        if (rawY < -mQuickReturnHeight) {
                            mState = STATE_OFFSCREEN;
                            mMinRawY = rawY;
                        }
                        translationY = rawY;
                        break;

                    case STATE_RETURNING:
                        translationY = (rawY - mMinRawY) - mQuickReturnHeight;
                        if (translationY > 0) {
                            translationY = 0;
                            mMinRawY = rawY - mQuickReturnHeight;
                        }

                        if (rawY > 0) {
                            mState = STATE_ONSCREEN;
                            translationY = rawY;
                        }

                        if (translationY < -mQuickReturnHeight) {
                            mState = STATE_OFFSCREEN;
                            mMinRawY = rawY;
                        }
                        break;
                }

                /** this can be used if the build is below honeycomb **/
                if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
                    TranslateAnimation anim = new TranslateAnimation(0, 0,
                            translationY, translationY);
                    anim.setFillAfter(true);
                    anim.setDuration(0);
                    mQuickReturnView.startAnimation(anim);
                } else {
                    mQuickReturnView.setTranslationY(translationY);
                }

            }

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }
        });

        if (header != null) {
            try {
                mQuickReturnView.removeAllViews();
            } catch (Exception e) {
                e.printStackTrace();
            }
            mQuickReturnView.addView(header);
        }

    }

    public void scrollToCard(int pos) {
        // int y = 0;
        try {
            // y = getY(pos);

            mListView.smoothScrollToPosition(pos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void scrollToY(int y) {

        try {

            mListView.scrollTo(0, y);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public QuickReturnListView getScrollView() {
        return mListView;
    }

    public int getLastCardStackPosition() {

        return mStacks.size() - 1;
    }

    public void addSeparateCards(Card[] cards) {
        addSeparateCards(cards, false);
    }

    public void addSeparateCards(Card[] cards, boolean refresh) {

        for (int i = 0; i < cards.length; i++) {
            CardStack stack = new CardStack();
            stack.add(cards[i]);
            mStacks.add(stack);
        }

        if (refresh)
            refresh();
    }

    public void addCard(Card card) {
        addCard(card, false);
    }

    public void addCard(Card card, boolean refresh) {
        CardStack stack = new CardStack();
        stack.add(card);
        mStacks.add(stack);
        if (refresh)
            refresh();
    }

    public void addAsyncCard(Card card, boolean refresh, Context ctx) {
        final Card asyncCard = card;
        final Context context = ctx;

        new Thread(new Runnable() {
            @Override
            public void run() {
                asyncCard.getCardContent(context);
            }
        }).start();

        CardStack stack = new CardStack();
        stack.add(asyncCard);
        mStacks.add(stack);
        if (refresh) refresh();
    }

    public void addCardToLastStack(Card card) {
        addCardToLastStack(card, false);

    }

    public void addCardToLastStack(Card card, boolean refresh) {
        if (mStacks.isEmpty()) {
            addCard(card, refresh);
            return;
        }
        int lastItemPos = mStacks.size() - 1;
        CardStack cardStack = (CardStack) mStacks.get(lastItemPos);
        cardStack.add(card);
        mStacks.set(lastItemPos, cardStack);
        if (refresh) refresh();
    }

    public void addStack(CardStack stack) {
        addStack(stack, false);

    }

    public void addStack(CardStack stack, boolean refresh) {
        mStacks.add(stack);
        if (refresh)
            refresh();

    }

    //suppress this error message to be able to use spaces in higher api levels
    @SuppressLint("NewApi")
    public void refresh() {

        if (mAdapter == null) {
            mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
            if (mListView != null) {
                mListView.setAdapter(mAdapter);
            } else if (mTableLayout != null) {
                TableRow tr = null;
                for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
                    //add a new table row with the current context
                    tr = (TableRow) new TableRow(mTableLayout.getContext());
                    tr.setOrientation(TableRow.HORIZONTAL);
                    tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    //add as many cards as the number of columns indicates per row
                    for (int j = 0; j < mColumnNumber; j++) {
                        if (i + j < mAdapter.getCount()) {
                            View card = mAdapter.getView(i + j, null, tr);
                            if ((card != null ? card.getLayoutParams() : null) != null) {
                                card.setLayoutParams(new TableRow.LayoutParams(card.getLayoutParams().width, card.getLayoutParams().height, 1f));
                            } else {
                                if (card != null) {
                                    card.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
                                    tr.addView(card);
                                }
                            }
                        }
                    }
                    mTableLayout.addView(tr);
                }
                if (tr != null) {
                    //fill the empty space with spacers
                    for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
                        View space = null;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                            space = new Space(tr.getContext());
                        } else {
                            space = new View(tr.getContext());
                        }
                        space.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
                        tr.addView(space);
                    }
                }

            }
        } else {
            mAdapter.setSwipeable(mSwipeable); // in case swipeable changed;
            mAdapter.setItems(mStacks);

        }

    }

    public void clearCards() {
        mStacks = new ArrayList<AbstractCard>();
        renderedCardsStacks = 0;
        refresh();
    }

    public void setCurrentStackTitle(String title) {
        CardStack cardStack = (CardStack) mStacks
                .get(getLastCardStackPosition());
        cardStack.setTitle(title);

    }

    public CardStack getLastStack() {
        return (CardStack) mStacks.get(getLastCardStackPosition());
    }

    public OnRenderedListener getOnRenderedListener() {
        return onRenderedListener;
    }

    public void setOnRenderedListener(OnRenderedListener onRenderedListener) {
        this.onRenderedListener = onRenderedListener;
    }

    public interface OnRenderedListener {
        public void onRendered();
    }

}




Java Source Code List

com.androguide.honamicontrol.MainActivity.java
com.androguide.honamicontrol.PresentationActivity.java
com.androguide.honamicontrol.SettingsActivity.java
com.androguide.honamicontrol.bootservice.BootHelper.java
com.androguide.honamicontrol.bootservice.BootReceiver.java
com.androguide.honamicontrol.cards.CardDoubleSeekBarPA.java
com.androguide.honamicontrol.cards.CardDoubleSeekBar.java
com.androguide.honamicontrol.cards.CardImageLocal.java
com.androguide.honamicontrol.cards.CardSeekBarGeneric.java
com.androguide.honamicontrol.cards.CardSeekBarReadahead.java
com.androguide.honamicontrol.cards.CardSeekBarSC.java
com.androguide.honamicontrol.cards.CardSeekBarSysctl.java
com.androguide.honamicontrol.cards.CardSeekBarVibrator.java
com.androguide.honamicontrol.cards.CardSeekBar.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMCDisabled.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMC.java
com.androguide.honamicontrol.cards.CardSpinnerVoltage.java
com.androguide.honamicontrol.cards.CardSpinner.java
com.androguide.honamicontrol.cards.CardSwitchDisabled.java
com.androguide.honamicontrol.cards.CardSwitchPlugin.java
com.androguide.honamicontrol.cards.CardTopImageLocal.java
com.androguide.honamicontrol.fragments.CardsFragment.java
com.androguide.honamicontrol.fragments.HelpFragment.java
com.androguide.honamicontrol.fragments.WelcomeFragment.java
com.androguide.honamicontrol.helpers.CPUHelper.java
com.androguide.honamicontrol.helpers.FileHelper.java
com.androguide.honamicontrol.helpers.Helpers.java
com.androguide.honamicontrol.helpers.NegativeSeekBar.java
com.androguide.honamicontrol.helpers.ShellInterface.java
com.androguide.honamicontrol.helpers.SystemPropertiesReflection.java
com.androguide.honamicontrol.helpers.CMDProcessor.AbstractAsyncSuCMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.CMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.ChildProcess.java
com.androguide.honamicontrol.helpers.CMDProcessor.CommandResult.java
com.androguide.honamicontrol.helpers.CMDProcessor.Constants.java
com.androguide.honamicontrol.helpers.CMDProcessor.Shell.java
com.androguide.honamicontrol.kernel.KernelFragment.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlActivity.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUFragment.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.GovernorDialog.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUActivity.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUInterface.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksActivity.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksInterface.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementActivity.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementInterface.java
com.androguide.honamicontrol.kernel.misc.MiscActivity.java
com.androguide.honamicontrol.kernel.misc.MiscInterface.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementActivity.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementInterface.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageActivity.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageInterface.java
com.androguide.honamicontrol.profiles.BalancedProfile.java
com.androguide.honamicontrol.profiles.BatteryMaxProfile.java
com.androguide.honamicontrol.profiles.BatteryProfile.java
com.androguide.honamicontrol.profiles.BenchmarkProfile.java
com.androguide.honamicontrol.profiles.PerformanceProfile.java
com.androguide.honamicontrol.profiles.ProfileEnabler.java
com.androguide.honamicontrol.profiles.Profile.java
com.androguide.honamicontrol.soundcontrol.SoundControlActivity.java
com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java
com.androguide.honamicontrol.soundcontrol.SoundControlInterface.java
com.androguide.honamicontrol.soundcontrol.SoundFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenInterface.java
com.astuetz.viewpager.extensions.PagerSlidingTabStrip.java
com.echo.holographlibrary.BarGraph.java
com.echo.holographlibrary.Bar.java
com.echo.holographlibrary.LineGraph.java
com.echo.holographlibrary.LinePoint.java
com.echo.holographlibrary.Line.java
com.echo.holographlibrary.PieGraph.java
com.echo.holographlibrary.PieSlice.java
com.fima.cardsui.StackAdapter.java
com.fima.cardsui.SwipeDismissTouchListener.java
com.fima.cardsui.Utils.java
com.fima.cardsui.objects.AbstractCard.java
com.fima.cardsui.objects.CardStack.java
com.fima.cardsui.objects.Card.java
com.fima.cardsui.views.CardCategory.java
com.fima.cardsui.views.CardDownload.java
com.fima.cardsui.views.CardEditText.java
com.fima.cardsui.views.CardEdit.java
com.fima.cardsui.views.CardImage.java
com.fima.cardsui.views.CardPresentation.java
com.fima.cardsui.views.CardSeekBar.java
com.fima.cardsui.views.CardSpinner.java
com.fima.cardsui.views.CardTextStripe.java
com.fima.cardsui.views.CardText.java
com.fima.cardsui.views.CardTopImage.java
com.fima.cardsui.views.CardUI.java
com.fima.cardsui.views.QuickReturnListView.java