Example usage for android.widget GridLayout VERTICAL

List of usage examples for android.widget GridLayout VERTICAL

Introduction

In this page you can find the example usage for android.widget GridLayout VERTICAL.

Prototype

int VERTICAL

To view the source code for android.widget GridLayout VERTICAL.

Click Source Link

Document

The vertical orientation.

Usage

From source file:com.gelakinetic.mtgfam.fragments.LifeCounterFragment.java

/**
 * Updates the display mode based on the current value of mDisplayMode. This updates the GridLayout's parameters
 * and draws the player's views in the fragment. It also shows and hides buttons and views relating to
 * commander mode./*from ww w .j a  va 2s.  co m*/
 */
public void changeDisplayMode(boolean shouldDefaultLives) {
    /* update the preference */
    PreferenceAdapter.setDisplayMode(getContext(), String.valueOf(mDisplayMode));

    mGridLayout.removeAllViews();

    if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        switch (mDisplayMode) {
        case DISPLAY_NORMAL:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(1);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        case DISPLAY_COMPACT:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(2);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        case DISPLAY_COMMANDER:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(2);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        }
    } else {
        switch (mDisplayMode) {
        case DISPLAY_NORMAL:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            mGridLayout.setRowCount(1);
            break;
        case DISPLAY_COMPACT:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            mGridLayout.setRowCount(1);
            break;
        case DISPLAY_COMMANDER:
            mGridLayout.setOrientation(GridLayout.VERTICAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            if (mListSizeHeight != -1) {
                float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48,
                        getActivity().getResources().getDisplayMetrics());
                mGridLayout.setRowCount((int) (mListSizeHeight / height));
            } else {
                mGridLayout.setRowCount(GridLayout.UNDEFINED);
            }
            break;
        }
    }

    boolean areLivesDefault = true;
    for (LcPlayer player : mPlayers) {
        /* Only reset a player's default life / life if that player is unaltered and doesn't have a noticeably
         * custom default life */
        if (!(player.mLifeHistory.size() == 0 && player.mPoisonHistory.size() == 0
                && player.mLife == player.mDefaultLifeTotal && (player.mDefaultLifeTotal == DEFAULT_LIFE
                        || player.mDefaultLifeTotal == DEFAULT_LIFE_COMMANDER))) {
            areLivesDefault = false;
        }
    }

    if (areLivesDefault && shouldDefaultLives) {
        for (LcPlayer player : mPlayers) {
            player.mDefaultLifeTotal = getDefaultLife();
            player.mLife = player.mDefaultLifeTotal;
        }
    }

    for (LcPlayer player : mPlayers) {
        /* Draw the player's view */
        addPlayerView(player);
    }

    if (mDisplayMode == DISPLAY_COMMANDER) {
        mCommanderButton.setVisibility(View.VISIBLE);
        mCommanderPlayerView.setVisibility(View.VISIBLE);
        mCommanderPlayerView.removeAllViews();
        if (mPlayers.size() > 0 && null != mPlayers.get(0).mView) {
            mCommanderPlayerView.addView(mPlayers.get(0).mView);
            mPlayers.get(0).setSize(mListSizeWidth, mListSizeHeight, mDisplayMode, getActivity().getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
        }
    } else {
        mCommanderPlayerView.setVisibility(View.GONE);
        mCommanderButton.setVisibility(View.GONE);
        if (mStatDisplaying == STAT_COMMANDER) {
            setStatDisplaying(STAT_LIFE);
        }
    }
}