Java Code Examples for android.widget.GridLayout#LayoutParams

The following examples show how to use android.widget.GridLayout#LayoutParams . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainViewer.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
private void initializeTextView(
        TextView view,
        GridLayout layout,
        int columnId){

    layout.addView(view);

    GridLayout.LayoutParams param = new GridLayout.LayoutParams();
    param.height = GridLayout.LayoutParams.WRAP_CONTENT;
    param.width = GridLayout.LayoutParams.WRAP_CONTENT;
    param.rightMargin = 5;
    param.topMargin = 5;
    view.setTextSize(11);
    view.setWidth(TEXT_FIELD_WIDTH[columnId]);
    view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    param.setGravity(Gravity.CENTER);
    param.columnSpec = GridLayout.spec(columnId);
    param.rowSpec = GridLayout.spec(rowId);
    view.setLayoutParams (param);
}
 
Example 2
Source File: MainActivity.java    From CourseScheduleDemo with MIT License 6 votes vote down vote up
private void setUpClsTitle(){
    for (int i=0; i<TITLE_DATA.length; ++i){
        String content = TITLE_DATA[i];
        GridLayout.LayoutParams params = new GridLayout.LayoutParams();
        //第一列的时候
        if (i == 0){
            params.width = mTableDistance;
        }
        else {
            //添加分割线
            View divider = getLayoutInflater().inflate(R.layout.grid_title_form,mGlClsTitle,false);
            mGlClsTitle.addView(divider);

            params.width = mTableDistance * 2;
        }
        params.height = GridLayout.LayoutParams.MATCH_PARENT;
        TextView textView = new TextView(this);
        textView.setTextColor(getResources().getColor(R.color.blue));
        textView.setText(content);
        textView.setGravity(Gravity.CENTER);
        mGlClsTitle.addView(textView,params);
    }
}
 
Example 3
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private View createOptionIcon(GridLayout parent, int rowIndex, boolean editIconExists) {
    // The icon has a pre-defined width.
    ImageView optionIcon = new ImageView(parent.getContext());
    optionIcon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    optionIcon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
    optionIcon.setImageDrawable(mOption.getDrawableIcon());
    optionIcon.setMaxWidth(mIconMaxWidth);

    // Place option icon at column three if no edit icon.
    int columnStart = editIconExists ? 2 : 3;
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, 1));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(optionIcon, iconParams);

    optionIcon.setOnClickListener(OptionSection.this);
    return optionIcon;
}
 
Example 4
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 6 votes vote down vote up
private View createIcon(GridLayout parent, int rowIndex) {
    // The icon has a pre-defined width.
    ImageView icon = new ImageView(parent.getContext());
    icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    icon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
    icon.setImageResource(mOption.getDrawableIconId());
    icon.setMaxWidth(mIconMaxWidth);

    // The icon floats to the right of everything.
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(2, 1));
    iconParams.topMargin = mVerticalMargin;
    ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing);
    parent.addView(icon, iconParams);

    icon.setOnClickListener(OptionSection.this);
    return icon;
}
 
Example 5
Source File: MainViewer.java    From GNSS_Compare with Apache License 2.0 6 votes vote down vote up
/**
 * Factory method to initialize each text view and add it to the layout
 * @param view text view to be initialized
 * @param layout layout to which the view is to be added
 * @param columnId column of the layout to which the view is to be added
 */
private void initializeTextView(
        TextView view,
        GridLayout layout,
        int columnId){

    layout.addView(view);

    GridLayout.LayoutParams param = new GridLayout.LayoutParams();
    param.height = GridLayout.LayoutParams.WRAP_CONTENT;
    param.width = GridLayout.LayoutParams.WRAP_CONTENT;
    param.rightMargin = 5;
    param.topMargin = 5;
    view.setTextSize(11);
    view.setWidth(TEXT_FIELD_WIDTH[columnId]);
    view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    param.setGravity(Gravity.CENTER);
    param.columnSpec = GridLayout.spec(columnId);
    param.rowSpec = GridLayout.spec(rowId);
    view.setLayoutParams (param);
}
 
Example 6
Source File: ColorChooser.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void makeColorPresetButton(int color) {
        FrameLayout outframe = new FrameLayout(getContext());
        outframe.setBackgroundColor(Color.BLACK);
        outframe.setPadding(6,6,6,6);

        FrameLayout frame = new FrameLayout(getContext());
        //frame.setPadding(6,6,6,6);
        //frame.setBackgroundColor(Color.BLACK);
        frame.setBackgroundResource(R.drawable.bwg);

        TextView c = new TextView(getContext());
        c.setText("   ");
        c.setTextSize(22);
        c.setBackgroundColor(color);
//        if (color==Color.TRANSPARENT) {
//            c.setBackgroundResource(R.drawable.transparentgrid);
//        }
        c.setTag(color);
        c.setClickable(true);
        c.setOnClickListener(setColorListener);
        frame.addView(c);
        GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
        lp.setMargins(24, 16, 24, 16);
        outframe.setPadding(6,6,6,6);
        outframe.addView(frame);
        colorPresets.addView(outframe, lp);
    }
 
Example 7
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 5 votes vote down vote up
private void addAppToIconSheet(GridLayout iconSheet, AppLauncher app, int pos, boolean reuse) {
    if (app != null) {
        try {
            if (((app.isWidget() || app.isLink()) && isAppInstalled(app.getPackageName())) || mLaunchApp.isValidActivity(app)) {
                ViewGroup item = getLauncherView(app, false, reuse);
                if (item != null) {
                    if (!app.iconLoaded()) {
                        app.loadAppIconAsync(this);
                    }
                    item.setTranslationX(0);
                    ViewGroup parent = (ViewGroup) item.getParent();
                    if (parent != null) parent.removeView(item);
                    GridLayout.LayoutParams lp = getAppLauncherLayoutParams(iconSheet, app);
                    iconSheet.addView(item, pos, lp);
                }
            } else {
                db().deleteApp(app.getComponentName());
                Log.d(TAG, "removed " + app.getPackageName() + " " + app.getActivityName() + ": activity not valid.");
            }
        } catch (Exception e) {
            Log.e(TAG, "exception adding icon to sheet", e);
            Toast.makeText(this,"Couldn't place icon: " + e.getMessage(), Toast.LENGTH_LONG).show();
        }
    } else {
        Log.d(TAG, "Not showing recent: Null.");
    }

}
 
Example 8
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private View createEditIcon(GridLayout parent, int rowIndex) {
    View editorIcon = LayoutInflater.from(parent.getContext())
                              .inflate(R.layout.payment_option_edit_icon, null);

    // The icon floats to the right of everything.
    GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLayout.spec(3, 1));
    iconParams.topMargin = mVerticalMargin;
    parent.addView(editorIcon, iconParams);

    editorIcon.setOnClickListener(OptionSection.this);
    return editorIcon;
}
 
Example 9
Source File: NotificationPeekActivity.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
/**
 * Update small notification icons when there is new notification coming, and the
 * Activity is in foreground.
 */
private void updateNotificationIcons() {

    if (mNotificationsContainer.getVisibility() != View.VISIBLE) {
        mNotificationsContainer.setVisibility(View.VISIBLE);
    }

    NotificationHub notificationHub = NotificationHub.getInstance();

    int iconSize = getResources().getDimensionPixelSize(R.dimen.small_notification_icon_size);
    int padding = getResources().getDimensionPixelSize(R.dimen.small_notification_icon_padding);

    final StatusBarNotification n = notificationHub.getCurrentNotification();
    ImageView icon = new ImageView(this);
    icon.setAlpha(NotificationPeek.ICON_LOW_OPACITY);

    icon.setPadding(padding, 0, padding, 0);
    icon.setImageDrawable(NotificationPeekViewUtils.getIconFromResource(this, n));
    icon.setTag(n);

    restoreFirstIconVisibility();

    int oldIndex = getOldIconViewIndex(notificationHub);

    if (oldIndex >= 0) {
        mNotificationsContainer.removeViewAt(oldIndex);
    }

    mNotificationsContainer.addView(icon);
    LinearLayout.LayoutParams linearLayoutParams =
            new LinearLayout.LayoutParams(iconSize, iconSize);

    // Wrap LayoutParams to GridLayout.LayoutParams.
    GridLayout.LayoutParams gridLayoutParams = new GridLayout.LayoutParams(linearLayoutParams);
    icon.setLayoutParams(gridLayoutParams);
}
 
Example 10
Source File: MainActivity.java    From LaunchTime with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
    private GridLayout.LayoutParams getAppLauncherLayoutParams(GridLayout grid, AppLauncher app) {

        GridLayout.LayoutParams lp = new GridLayout.LayoutParams();

        final int wDp = getLauncherWidth(app);
        final int hDp = getLauncherHeight(app);
        float w = dipToPx(wDp);
        float h = dipToPx(hDp);

        int wcells = getWidgetWCells(app);
        int hcells = getWidgetHCells(app);

        float sw = mStyle.getLauncherSize();

        float cellwidth = sw * 1f;
        float cellheight = cellwidth *1.1f;  // ~square cells


        if (w>0 || wcells>0) {

            if (wcells == 0) wcells = (int) Math.round(Math.max(w / cellwidth * .75, 1));

            if (wcells > 1) {
                int start = GridLayout.UNDEFINED;
                if (wcells > grid.getColumnCount()) {
                    wcells = grid.getColumnCount();
                }
                if (wcells > mStyle.getMaxWCells()) {
                    wcells = mStyle.getMaxWCells();
                }

                lp.columnSpec = GridLayout.spec(start, wcells, GridLayout.FILL);

                //Log.d("widcol", "w=" + w + " wcells=" + wcells + " start=" + start + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
            } else {
                lp.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
            }
        }
        if (h>0 || hcells>0) {

            if (hcells == 0) {
                hcells = (int) Math.round(Math.max(h / cellheight * .75, 1));
                if (hcells > mStyle.getMaxWCells()) {
                    hcells = mStyle.getMaxWCells();
                }
            }

            if (hcells > 1) {
                lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, hcells, GridLayout.FILL);
            } else {
                lp.rowSpec = GridLayout.spec(GridLayout.UNDEFINED, 1, GridLayout.FILL);
            }

        }

        final AppWidgetHostView appwid = mWidgetHelper.getAppWidgetHostView(app);

        if (appwid != null) {

            lp.width = (int)(cellwidth*wcells*1.16);

            int calcHeight = (int)(cellheight*hcells*(hcells/(hcells-.2)));
            lp.height = calcHeight;
//            if (h > cellheight*hcells*1.3) {
//                lp.height = calcHeight;
//            } else {
//                lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;//(int)(cellheight*hcells*1.2);
//            }

            storeWidgetWCells(app, wcells);
            storeWidgetHCells(app, hcells);
            //lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;//(int)(cellheight*hcells*1.2);

            final int hDpf;
            if (h<calcHeight) {
                hDpf = pxToDip(calcHeight);
            } else {
                hDpf = hDp;
            }
            //Log.d("widcol2", "wDp=" + wDp + " w=" + w + " wcells=" + wcells  + " cellwidth=" + cellwidth + " r=" + cellwidth * wcells);
            //Log.d("widcol2", "hDp=" + hDp + " hDpf=" + hDpf + " h=" + h + " hcells=" + hcells  + " cellheight=" + cellheight + " r=" + cellheight * hcells);
            iconHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    appwid.updateAppWidgetSize(null, wDp, hDpf, wDp, hDpf);
                    if (appwid.getParent()!=null) {
                        appwid.getParent().requestLayout();
                    }
                    appwid.requestLayout();
                    appwid.postInvalidate();
                }
            }, 1000);


        }

        return lp;
    }
 
Example 11
Source File: ClusterMapContributeEditActivity.java    From intra42 with Apache License 2.0 4 votes vote down vote up
private View inflateClusterMapItem(int x, int y) {
    @Nullable
    Location location = cluster.map.get(x, y);

    View view;
    ImageView imageViewContent;
    TextView textView;
    GridLayout.LayoutParams paramsGridLayout;

    if (vi == null)
        return null;

    view = vi.inflate(R.layout.grid_layout_cluster_map_edit, gridLayout, false);
    view.setTag(new LocationWrapper(x, y, location));
    imageViewContent = view.findViewById(R.id.imageView);
    textView = view.findViewById(R.id.textView);
    view.setOnClickListener(this);

    textView.setVisibility(View.GONE);
    if (location != null)
        if (location.kind == Location.Kind.USER) {
            if (location.host == null ||
                    location.host.isEmpty() ||
                    location.host.contentEquals("null") ||
                    location.host.contentEquals("TBD")) {
                imageViewContent.setImageResource(R.drawable.ic_missing_black_25dp);
                view.setBackgroundColor(getResources().getColor(R.color.color_warning));
            } else {
                textView.setVisibility(View.VISIBLE);
                textView.setText(location.host);
                imageViewContent.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_desktop_mac_black_custom));
                if (cluster.hostPrefix != null && location.host.startsWith(cluster.hostPrefix)) // set warning flag because host contain cluster prefix
                    view.setBackgroundColor(getResources().getColor(R.color.color_warning));
                else
                    imageViewContent.setColorFilter(ContextCompat.getColor(this, R.color.colorClusterMapComputerColor), android.graphics.PorterDuff.Mode.SRC_IN);
            }

        } else if (location.kind == Location.Kind.WALL)
            imageViewContent.setImageResource(R.color.colorClusterMapWall);
        else {
            imageViewContent.setImageResource(R.drawable.ic_add_black_24dp);
            imageViewContent.setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.CLEAR);
        }

    paramsGridLayout = (GridLayout.LayoutParams) view.getLayoutParams();
    paramsGridLayout.columnSpec = GridLayout.spec(x);
    paramsGridLayout.rowSpec = GridLayout.spec(y);
    paramsGridLayout.setGravity(Gravity.FILL);
    paramsGridLayout.height = GridLayout.LayoutParams.WRAP_CONTENT;
    paramsGridLayout.width = GridLayout.LayoutParams.WRAP_CONTENT;
    float sizeX = 1;
    float sizeY = 1;
    if (location != null) {
        sizeX = location.sizeX;
        sizeY = location.sizeY;
    }
    paramsGridLayout.height = (int) (baseItemHeight * sizeY);
    paramsGridLayout.width = (int) (baseItemWidth * sizeX);
    imageViewContent.setPadding(paddingItem2dp, paddingItem2dp, paddingItem2dp, paddingItem2dp);
    view.setLayoutParams(paramsGridLayout);

    return view;
}
 
Example 12
Source File: ClusterMapContributeEditActivity.java    From intra42 with Apache License 2.0 4 votes vote down vote up
private View inflateClusterMapController(int x, int y) {
        GridLayout.LayoutParams paramsGridLayout;
        Location location = null;
        boolean isCorner = false;

        View view = vi.inflate(R.layout.grid_layout_cluster_map_edit_controller, gridLayout, false);

        if (x == cluster.width && y == cluster.height) {
            isCorner = true;
        } else if (x == cluster.width)
            location = cluster.map.get(0, y);
        else if (y == cluster.height)
            location = cluster.map.get(x, 0);

        float sizeX = 1;
        float sizeY = 1;
        if (!isCorner) {
            if (location != null) {
                sizeX = location.sizeX;
                sizeY = location.sizeY;
            }

            final LocationWrapper wrapper = new LocationWrapper(x, y, location);
            view.setTag(wrapper);
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickController(wrapper);
                }
            });
        }

        paramsGridLayout = (GridLayout.LayoutParams) view.getLayoutParams();
        paramsGridLayout.columnSpec = GridLayout.spec(x);
        paramsGridLayout.rowSpec = GridLayout.spec(y);
        paramsGridLayout.setGravity(Gravity.FILL);
        paramsGridLayout.height = GridLayout.LayoutParams.WRAP_CONTENT;
        paramsGridLayout.width = GridLayout.LayoutParams.WRAP_CONTENT;
        paramsGridLayout.height = (int) (baseItemHeight * sizeY);
        paramsGridLayout.width = (int) (baseItemWidth * sizeX);

        ImageView imageView = view.findViewById(R.id.imageView);
        if (isCorner)
            imageView.setImageDrawable(null);
//            imageView.setImageResource(R.drawable.ic_add_black_24dp);

        view.setLayoutParams(paramsGridLayout);
        return view;
    }
 
Example 13
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the total and how it's broken down.
 *
 * @param cart The shopping cart contents and the total.
 */
public void update(ShoppingCart cart) {
    Context context = mBreakdownLayout.getContext();

    // Update the summary to display information about the total.
    setSummaryText(cart.getTotal().getLabel(), createValueString(
            cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true));

    mBreakdownLayout.removeAllViews();
    if (cart.getContents() == null) return;

    // Update the breakdown, using one row per {@link LineItem}.
    int numItems = cart.getContents().size();
    mBreakdownLayout.setRowCount(numItems);
    for (int i = 0; i < numItems; i++) {
        LineItem item = cart.getContents().get(i);

        TextView description = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                description, R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        description.setText(item.getLabel());

        TextView amount = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                amount, R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));

        // Each item is represented by a row in the GridLayout.
        GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(0, 1, GridLayout.END));
        GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(1, 1, GridLayout.END));
        ApiCompatibilityUtils.setMarginStart(amountParams,
                context.getResources().getDimensionPixelSize(
                        R.dimen.payments_section_descriptive_item_spacing));

        mBreakdownLayout.addView(description, descriptionParams);
        mBreakdownLayout.addView(amount, amountParams);
    }
}
 
Example 14
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 4 votes vote down vote up
private TextView createLabel(
        GridLayout parent, int rowIndex, boolean iconExists, boolean isEnabled) {
    Context context = parent.getContext();
    Resources resources = context.getResources();

    // By default, the label appears to the right of the "button" in the second column.
    // + If there is no button and no icon, the label spans the whole row.
    // + If there is no icon, the label spans two columns.
    // + Otherwise, the label occupies only its own column.
    int columnStart = 1;
    int columnSpan = iconExists ? 1 : 2;

    TextView labelView = new TextView(context);
    if (mRowType == OPTION_ROW_TYPE_OPTION) {
        // Show the string representing the PaymentOption.
        ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
                ? R.style.PaymentsUiSectionDefaultText
                : R.style.PaymentsUiSectionDisabledText);
        labelView.setText(convertOptionToString(mOption));
        labelView.setEnabled(isEnabled);
    } else if (mRowType == OPTION_ROW_TYPE_ADD) {
        // Shows string saying that the user can add a new option, e.g. credit card no.
        String typeface = resources.getString(R.string.roboto_medium_typeface);
        int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle);
        int buttonHeight = resources.getDimensionPixelSize(
                R.dimen.payments_section_add_button_height);

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionAddButtonLabel);
        labelView.setMinimumHeight(buttonHeight);
        labelView.setGravity(Gravity.CENTER_VERTICAL);
        labelView.setTypeface(Typeface.create(typeface, textStyle));
    } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) {
        // The description spans all the columns.
        columnStart = 0;
        columnSpan = 3;

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionDescriptiveText);
    } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
        // Warnings use two columns.
        columnSpan = 2;
        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionWarningText);
    }

    // The label spans two columns if no icon exists.  Setting the view width to 0
    // forces it to stretch.
    GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, columnSpan, GridLayout.FILL));
    labelParams.topMargin = mVerticalMargin;
    labelParams.width = 0;
    parent.addView(labelView, labelParams);

    labelView.setOnClickListener(OptionSection.this);
    return labelView;
}
 
Example 15
Source File: SortingActivity.java    From Primary with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onShowProbImpl() {
        GridLayout sortArea = findViewById(R.id.sort_area);
        sortArea.removeAllViews();

        sortArea.setOnDragListener(this);

        Set<Integer> nums = new TreeSet<>();
        SortingLevel level = ((SortingLevel) getLevel());

        String numliststr = getSavedLevelValue("numlist", (String) null);
        if (numliststr == null || numliststr.length() == 0) {
            int tries = 0;
            do {
                nums.add(getRand(level.getMaxNum()));
            } while (tries++ < 100 && nums.size() < level.getNumItems());

            numlist = new ArrayList<>(nums);

            do {
                Collections.shuffle(numlist);
            } while (isSorted(numlist));

        } else {
            numlist = splitInts(",", numliststr);
            deleteSavedLevelValue("numlist");
        }

        int mlen = (level.getMaxNum() + "").length();
//        int xsize = getScreenSize().x;
//
//        int tsize = xsize*2/3 / numcolumns / 4 - 5;
//        if (tsize>30) tsize = 30;
        int tsize = 30 - mlen;

        for (int num : numlist) {
            String spaces = "";
            for (int i = 0; i < Math.max(3, mlen) - (num + "").length(); i++) {
                spaces += " ";
            }

            final String numstr = spaces + num;

            TextView item = new TextView(this);
            item.setText(numstr);
            item.setTag(num);
            item.setOnTouchListener(this);
            item.setOnDragListener(this);


            item.setMaxLines(1);
            item.setTextSize(tsize);
            item.setTypeface(Typeface.MONOSPACE);
            //item.setWidth(xsize*2/3 / numcolumns -10);
            //item.setEms(mlen);

            item.setGravity(Gravity.END);

            GridLayout.LayoutParams lp = new GridLayout.LayoutParams();

            lp.setMargins(1, 1, 1, 1);
            lp.setGravity(Gravity.CENTER);
            item.setLayoutParams(lp);
            item.setBackgroundColor(BACKGROUND_COLOR);
            item.setPadding(16, 12, 16, 12);

            sortArea.addView(item);
        }
        problemDone = false;
        moves = 0;

        setFasttimes(level.getNumItems()*300, level.getNumItems()*500, level.getNumItems()*750);

        startHint(level.getNumItems());
    }
 
Example 16
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the total and how it's broken down.
 *
 * @param cart The shopping cart contents and the total.
 */
public void update(ShoppingCart cart) {
    Context context = mBreakdownLayout.getContext();

    CharSequence totalPrice = createValueString(
            cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);

    // Show the updated text view if the total changed.
    showUpdateIfTextChanged(totalPrice);

    // Update the summary to display information about the total.
    setSummaryText(cart.getTotal().getLabel(), totalPrice);

    mBreakdownLayout.removeAllViews();
    if (cart.getContents() == null) return;

    int maximumDescriptionWidthPx =
            ((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;

    // Update the breakdown, using one row per {@link LineItem}.
    int numItems = cart.getContents().size();
    mBreakdownLayout.setRowCount(numItems);
    for (int i = 0; i < numItems; i++) {
        LineItem item = cart.getContents().get(i);

        TextView description = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        description.setText(item.getLabel());
        description.setEllipsize(TruncateAt.END);
        description.setMaxLines(2);
        if (maximumDescriptionWidthPx > 0) {
            description.setMaxWidth(maximumDescriptionWidthPx);
        }

        TextView amount = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));

        // Each item is represented by a row in the GridLayout.
        GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(0, 1, GridLayout.END));
        GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(1, 1, GridLayout.END));
        ApiCompatibilityUtils.setMarginStart(amountParams,
                context.getResources().getDimensionPixelSize(
                        R.dimen.payments_section_descriptive_item_spacing));

        mBreakdownLayout.addView(description, descriptionParams);
        mBreakdownLayout.addView(amount, amountParams);
    }
}
 
Example 17
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private TextView createLabel(GridLayout parent, int rowIndex, boolean optionIconExists,
        boolean editIconExists, boolean isEnabled) {
    Context context = parent.getContext();
    Resources resources = context.getResources();

    // By default, the label appears to the right of the "button" in the second column.
    // + If there is no button, no option and edit icon, the label spans the whole row.
    // + If there is no option and edit icon, the label spans three columns.
    // + If there is no edit icon or option icon, the label spans two columns.
    // + Otherwise, the label occupies only its own column.
    int columnStart = 1;
    int columnSpan = 1;
    if (!optionIconExists) columnSpan++;
    if (!editIconExists) columnSpan++;

    TextView labelView = new TextView(context);
    if (mRowType == OPTION_ROW_TYPE_OPTION) {
        // Show the string representing the PaymentOption.
        ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
                ? R.style.PaymentsUiSectionDefaultText
                : R.style.PaymentsUiSectionDisabledText);
        labelView.setText(convertOptionToString(
                mOption, mDelegate.isBoldLabelNeeded(OptionSection.this)));
        labelView.setEnabled(isEnabled);
    } else if (mRowType == OPTION_ROW_TYPE_ADD) {
        // Shows string saying that the user can add a new option, e.g. credit card no.
        String typeface = resources.getString(R.string.roboto_medium_typeface);
        int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle);
        int buttonHeight = resources.getDimensionPixelSize(
                R.dimen.payments_section_add_button_height);

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionAddButtonLabel);
        labelView.setMinimumHeight(buttonHeight);
        labelView.setGravity(Gravity.CENTER_VERTICAL);
        labelView.setTypeface(Typeface.create(typeface, textStyle));
    } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) {
        // The description spans all the columns.
        columnStart = 0;
        columnSpan = 4;

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionDescriptiveText);
    } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
        // Warnings use three columns.
        columnSpan = 3;
        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionWarningText);
    }

    // The label spans two columns if no option or edit icon, or spans three columns if
    // no option and edit icons. Setting the view width to 0 forces it to stretch.
    GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, columnSpan, GridLayout.FILL));
    labelParams.topMargin = mVerticalMargin;
    labelParams.width = 0;
    if (optionIconExists) {
        // Margin at the end of the label instead of the start of the option icon to
        // allow option icon in the the next row align with the end of label (include
        // end margin) when edit icon exits in that row, like below:
        // ---Label---------------------[label margin]|---option icon---|
        // ---Label---[label margin]|---option icon---|----edit icon----|
        ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing);
    }
    parent.addView(labelView, labelParams);

    labelView.setOnClickListener(OptionSection.this);
    return labelView;
}
 
Example 18
Source File: ChannelView.java    From ChannelView with Apache License 2.0 4 votes vote down vote up
public ChannelLayoutParams(GridLayout.LayoutParams source) {
    super(source);
}
 
Example 19
Source File: ZoomHoverGridView.java    From CustomViewSets with Apache License 2.0 4 votes vote down vote up
/**
 * 将view添加进GridLayout
 */
private void addItem() {
    for (int i = 0; i < mItemList.size(); i++) {
        View childView = mViewList.get(i);
        ZoomHoverItem item = mItemList.get(i);
        GridLayout.LayoutParams childViewLp = (LayoutParams) childView.getLayoutParams();
        if (childViewLp == null) {
            childViewLp = new GridLayout.LayoutParams();
        }
        //设置子view的宽高
        if (mUseBaseWH) {
            childViewLp.width = mBaseWidth * item.getColumnSpan() + (item.getColumnSpan() > 1 ? (item.getColumnSpan() - 1) * mDivider : 0);
            childViewLp.height = mBaseHeight * item.getRowSpan() + (item.getRowSpan() > 1 ? (item.getRowSpan() - 1) * mDivider : 0);
        } else {
            if (childViewLp.width > 0) {
                childViewLp.width = childViewLp.width * item.getColumnSpan() + (item.getColumnSpan() > 1 ? (item.getColumnSpan() - 1) * mDivider : 0);
            } else {
                childViewLp.width = LayoutParams.WRAP_CONTENT;
            }

            if (childViewLp.height > 0) {
                childViewLp.height = childViewLp.height * item.getRowSpan() + (item.getRowSpan() > 1 ? (item.getRowSpan() - 1) * mDivider : 0);
            } else {
                childViewLp.height = LayoutParams.WRAP_CONTENT;
            }
        }
        //确定子view的行列位置
        childViewLp.rowSpec = GridLayout.spec(item.getRow(), item.getRowSpan());
        childViewLp.columnSpec = GridLayout.spec(item.getColumn(), item.getColumnSpan());
        int right = 0;
        int top = 0;
        int bottom = 0;
        int left = 0;
        if (item.getColumn() > 0) {
            //除了第一列左边距为分割线的宽度
            left = mDivider;
        } else if (item.getColumn() == 0) {
            //第一列的左边距=距离父布局的边距
            left = mMarginParent;
        }

        if (item.getRow() > 0) {
            //不是第一行上边距为分割线的宽度
            top = mDivider;
        } else if (item.getRow() == 0) {
            //第一行的上边距=距离父布局的边距
            top = mMarginParent;
        }

        //最后一列的右边距=距离父布局的边距
        if (item.getColumn() + item.getColumnSpan() >= mColumnNum) {
            right = mMarginParent;
        }

        //最后一行的下边距=距离父布局的边距
        if (item.getRow() + item.getRowSpan() >= mRowNum) {
            bottom = mMarginParent;
        }
        //设置margin
        childViewLp.setMargins(left, top, right, bottom);
        addView(childView, childViewLp);
        childView.setOnClickListener(this);
    }
}
 
Example 20
Source File: NotificationPeek.java    From NotificationPeekPort with Apache License 2.0 4 votes vote down vote up
private void updateNotificationIcons() {
    mNotificationsContainer.removeAllViews();
    int iconSize =
            mContext.getResources().getDimensionPixelSize(R.dimen.small_notification_icon_size);
    int padding = mContext.getResources()
            .getDimensionPixelSize(R.dimen.small_notification_icon_padding);
    Object tag = mNotificationView.getTag();
    String currentNotification = tag != null ? tag.toString() : null;
    boolean foundCurrentNotification = false;
    int notificationCount = mNotificationHub.getNotificationCount();
    mNotificationsContainer.setVisibility(View.VISIBLE);
    if (notificationCount <= 1) {
        mNotificationsContainer.setVisibility(View.GONE);
    }

    StatusBarNotification lastNotification = null;
    for (StatusBarNotification notification : mNotificationHub.getNotifications()) {
        final StatusBarNotification n = notification;
        ImageView icon = new ImageView(mContext);
        if (n.toString().equals(currentNotification)) {
            foundCurrentNotification = true;
        } else {
            icon.setAlpha(ICON_LOW_OPACITY);
        }
        icon.setPadding(padding, 0, padding, 0);
        icon.setImageDrawable(NotificationPeekViewUtils.getIconFromResource(mContext, n));
        icon.setTag(n);
        mNotificationsContainer.addView(icon);
        LinearLayout.LayoutParams linearLayoutParams =
                new LinearLayout.LayoutParams(iconSize, iconSize);

        // Wrap LayoutParams to GridLayout.LayoutParams.
        GridLayout.LayoutParams gridLayoutParams =
                new GridLayout.LayoutParams(linearLayoutParams);
        icon.setLayoutParams(gridLayoutParams);

        if (lastNotification == null) {
            lastNotification = n;
        }
    }


    if (!foundCurrentNotification) {
        if (notificationCount > 0) {
            updateSelection(lastNotification);
        } else {
            dismissNotification();
        }
    }
}