Example usage for android.widget GridLayout getColumnCount

List of usage examples for android.widget GridLayout getColumnCount

Introduction

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

Prototype

public int getColumnCount() 

Source Link

Document

Returns the current number of columns.

Usage

From source file:com.syncedsynapse.kore2.utils.UIUtils.java

/**
 * Fills the standard cast info list, consisting of a {@link android.widget.GridLayout}
 * with actor images and a Textview with the name and the role of the additional cast.
 * The number of actor presented on the {@link android.widget.GridLayout} is controlled
 * through the global setting, and only actors with images are presented.
 * The rest are presented in the additionalCastView TextView
 *
 * @param context Activity//from w w  w  . j a v  a2 s. c om
 * @param castList Cast list
 * @param castListView GridLayout on which too show actors that have images
 * @param additionalCastTitleView View with additional cast title
 * @param additionalCastView Additional cast
 */
public static void setupCastInfo(final Context context, List<VideoType.Cast> castList, GridLayout castListView,
        TextView additionalCastTitleView, TextView additionalCastView) {
    HostManager hostManager = HostManager.getInstance(context);
    Resources resources = context.getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);

    View.OnClickListener castListClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openImdbForPerson(context, (String) v.getTag());
        }
    };

    castListView.removeAllViews();
    int numColumns = castListView.getColumnCount();

    int layoutMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.remote_content_hmargin);
    int imageMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin);
    int imageWidth = (displayMetrics.widthPixels - layoutMarginPx - numColumns * imageMarginPx) / numColumns;
    int imageHeight = (int) (imageWidth * 1.2);

    List<VideoType.Cast> noPicturesCastList = new ArrayList<VideoType.Cast>();
    int maxCastPictures = Settings.DEFAULT_MAX_CAST_PICTURES;
    int currentPictureNumber = 0;
    for (int i = 0; i < castList.size(); i++) {
        VideoType.Cast actor = castList.get(i);

        if (((maxCastPictures == -1) || (currentPictureNumber < maxCastPictures))
                && (actor.thumbnail != null)) {
            // Present the picture
            currentPictureNumber++;
            View castView = LayoutInflater.from(context).inflate(R.layout.grid_item_cast, castListView, false);
            ImageView castPicture = (ImageView) castView.findViewById(R.id.picture);
            TextView castName = (TextView) castView.findViewById(R.id.name);
            TextView castRole = (TextView) castView.findViewById(R.id.role);

            castView.getLayoutParams().width = imageWidth;
            castView.getLayoutParams().height = (int) (imageHeight * 1.2);
            castView.setTag(actor.name);
            castView.setOnClickListener(castListClickListener);

            castName.setText(actor.name);
            castRole.setText(actor.role);
            UIUtils.loadImageWithCharacterAvatar(context, hostManager, actor.thumbnail, actor.name, castPicture,
                    imageWidth, imageHeight);
            castListView.addView(castView);
        } else {
            noPicturesCastList.add(actor);
        }
    }

    // Additional cast
    if (noPicturesCastList.size() > 0) {
        additionalCastTitleView.setVisibility(View.VISIBLE);
        additionalCastView.setVisibility(View.VISIBLE);
        StringBuilder castListText = new StringBuilder();
        boolean first = true;
        for (VideoType.Cast cast : noPicturesCastList) {
            if (!first)
                castListText.append("\n");
            first = false;
            if (!TextUtils.isEmpty(cast.role)) {
                castListText.append(
                        String.format(context.getString(R.string.cast_list_text), cast.name, cast.role));
            } else {
                castListText.append(cast.name);
            }
        }
        additionalCastView.setText(castListText);
    } else {
        additionalCastTitleView.setVisibility(View.GONE);
        additionalCastView.setVisibility(View.GONE);
    }
}

From source file:org.xbmc.kore.utils.UIUtils.java

/**
 * Fills the standard cast info list, consisting of a {@link android.widget.GridLayout}
 * with actor images and a Textview with the name and the role of the additional cast.
 * The number of actor presented on the {@link android.widget.GridLayout} is controlled
 * through the global setting, and only actors with images are presented.
 * The rest are presented in the additionalCastView TextView
 *
 * @param activity Activity//from   ww w  . j  av a 2  s  . c om
 * @param castList Cast list
 * @param castListView GridLayout on which too show actors that have images
 */
public static void setupCastInfo(final Activity activity, List<VideoType.Cast> castList,
        GridLayout castListView, final Intent allCastActivityLaunchIntent) {
    HostManager hostManager = HostManager.getInstance(activity);
    Resources resources = activity.getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);

    View.OnClickListener castListClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openImdbForPerson(activity, (String) v.getTag());
        }
    };

    castListView.removeAllViews();
    int numColumns = castListView.getColumnCount();
    int numRows = resources.getInteger(R.integer.cast_grid_view_rows);
    int maxCastPictures = numColumns * numRows;

    int layoutMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.remote_content_hmargin);
    int imageMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin);
    int imageWidth = (displayMetrics.widthPixels - layoutMarginPx - numColumns * imageMarginPx) / numColumns;
    int imageHeight = (int) (imageWidth * 1.5);

    for (int i = 0; i < Math.min(castList.size(), maxCastPictures); i++) {
        VideoType.Cast actor = castList.get(i);

        View castView = LayoutInflater.from(activity).inflate(R.layout.grid_item_cast, castListView, false);
        ImageView castPicture = (ImageView) castView.findViewById(R.id.picture);
        TextView castName = (TextView) castView.findViewById(R.id.name);
        TextView castRole = (TextView) castView.findViewById(R.id.role);

        castView.getLayoutParams().width = imageWidth;
        castView.getLayoutParams().height = imageHeight;
        castView.setTag(actor.name);

        UIUtils.loadImageWithCharacterAvatar(activity, hostManager, actor.thumbnail, actor.name, castPicture,
                imageWidth, imageHeight);

        if ((i == maxCastPictures - 1) && (castList.size() > i + 1)) {
            View castNameGroup = castView.findViewById(R.id.cast_name_group);
            View allCastGroup = castView.findViewById(R.id.all_cast_group);
            TextView remainingCastCount = (TextView) castView.findViewById(R.id.remaining_cast_count);

            castNameGroup.setVisibility(View.GONE);
            allCastGroup.setVisibility(View.VISIBLE);
            remainingCastCount.setText(String.format(activity.getString(R.string.remaining_cast_count),
                    castList.size() - maxCastPictures + 1));
            castView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.startActivity(allCastActivityLaunchIntent);
                    activity.overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
                }
            });
        } else {
            castName.setText(actor.name);
            castRole.setText(actor.role);
            castView.setOnClickListener(castListClickListener);
        }

        castListView.addView(castView);
    }
}

From source file:io.palaima.debugdrawer.DebugWidgetsFrame.java

@NonNull
private GridLayout.LayoutParams getSpanColParams(GridLayout gl) {
    // http://bbs.csdn.net/topics/391853628
    // ?????/* ww w.  j av  a2  s .  c o m*/
    GridLayout.Spec row = GridLayout.spec(GridLayout.UNDEFINED);
    // ?????
    GridLayout.Spec col = GridLayout.spec(GridLayout.UNDEFINED, gl.getColumnCount());
    GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
    params.width = GridLayout.LayoutParams.MATCH_PARENT;
    return params;
}