Example usage for android.widget Button Button

List of usage examples for android.widget Button Button

Introduction

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

Prototype

public Button(Context context) 

Source Link

Document

Simple constructor to use when creating a button from code.

Usage

From source file:com.acceleratedio.pac_n_zoom.FindTagsActivity.java

private void dsply_tags() {

    TableLayout tbl_tag_lo = (TableLayout) findViewById(R.id.tl_tag);
    int tag_mbr = 0;
    int tag_nmbr = fil_tags.length;
    String lst_str = "";
    int row_mbr;// w  ww  .  j a v a2 s.  c om

    tbl_tag_lo.setAlpha(185);

    // - Find the search string
    srch_str = srch_str.trim();
    boolean flg_srch_tags = !srch_str.equals("");

    if (flg_srch_tags) {

        String[] srch_ary = srch_str.split("\\s* \\s*");
        srch_str = srch_ary[srch_ary.length - 1].toLowerCase();
    }

    // - Remove any current rows
    int row_nmbr = tbl_tag_lo.getChildCount();

    if (row_nmbr > 0)
        tbl_tag_lo.removeAllViews();

    for (row_mbr = 0; row_mbr < 4 && tag_mbr < tag_nmbr; row_mbr++) {

        TableRow tableRow = new TableRow(this);
        tableRow.setGravity(Gravity.CENTER);

        tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT, 1.0f));

        for (int clm_mbr = 0; clm_mbr < 3; clm_mbr++) {

            Button btnTag = new Button(this);

            while (tag_mbr < tag_nmbr
                    && (fil_tags[tag_mbr].equals("") || fil_tags[tag_mbr].equalsIgnoreCase(lst_str)
                            || flg_srch_tags && !fil_tags[tag_mbr].toLowerCase().startsWith(srch_str))) {

                lst_str = fil_tags[tag_mbr];
                tag_mbr++;
            }

            if (tag_mbr >= tag_nmbr)
                break;

            lst_str = fil_tags[tag_mbr];
            btnTag.setText(fil_tags[tag_mbr++]);
            btnTag.setOnClickListener(this);

            btnTag.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                    TableRow.LayoutParams.MATCH_PARENT));

            tableRow.addView(btnTag);
        }

        tbl_tag_lo.addView(tableRow);
    }
}

From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestPageLock.java

/**
 * @return creates a Button which navigates to the next page
 *///  w w  w .  ja va  2s  .  c o  m
private Button createGoToNextPageButton() {
    final Button button = new Button(this);
    button.setText("Go to next page");

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final int startIndex = getIndexOfCurrentPage();
            goToNextPage();
            validateCommandPageChange(startIndex,
                    (startIndex == NUMBER_OF_PAGES - 1) ? NUMBER_OF_PAGES - 1 : startIndex + 1);
        }
    });

    return button;
}

From source file:org.odk.collect.android.views.ODKView.java

public ODKView(Context context, final FormEntryPrompt[] questionPrompts, FormEntryCaption[] groups,
        boolean advancingPage) {
    super(context);

    inflate(getContext(), R.layout.nested_scroll_view, this); // keep in an xml file to enable the vertical scrollbar

    widgets = new ArrayList<>();

    view = new LinearLayout(getContext());
    view.setOrientation(LinearLayout.VERTICAL);
    view.setGravity(Gravity.TOP);//from   w ww  .j a v  a2s.co  m
    view.setPadding(0, 7, 0, 0);

    layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setMargins(10, 0, 10, 0);

    // display which group you are in as well as the question

    addGroupText(groups);

    // when the grouped fields are populated by an external app, this will get true.
    boolean readOnlyOverride = false;

    // get the group we are showing -- it will be the last of the groups in the groups list
    if (groups != null && groups.length > 0) {
        final FormEntryCaption c = groups[groups.length - 1];
        final String intentString = c.getFormElement().getAdditionalAttribute(null, "intent");
        if (intentString != null && intentString.length() != 0) {

            readOnlyOverride = true;

            final String buttonText;
            final String errorString;
            String v = c.getSpecialFormQuestionText("buttonText");
            buttonText = (v != null) ? v : context.getString(R.string.launch_app);
            v = c.getSpecialFormQuestionText("noAppErrorString");
            errorString = (v != null) ? v : context.getString(R.string.no_app);

            TableLayout.LayoutParams params = new TableLayout.LayoutParams();
            params.setMargins(7, 5, 7, 5);

            // set button formatting
            Button launchIntentButton = new Button(getContext());
            launchIntentButton.setId(ViewIds.generateViewId());
            launchIntentButton.setText(buttonText);
            launchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Collect.getQuestionFontsize() + 2);
            launchIntentButton.setPadding(20, 20, 20, 20);
            launchIntentButton.setLayoutParams(params);

            launchIntentButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String intentName = ExternalAppsUtils.extractIntentName(intentString);
                    Map<String, String> parameters = ExternalAppsUtils.extractParameters(intentString);

                    Intent i = new Intent(intentName);
                    try {
                        ExternalAppsUtils.populateParameters(i, parameters, c.getIndex().getReference());

                        for (FormEntryPrompt p : questionPrompts) {
                            IFormElement formElement = p.getFormElement();
                            if (formElement instanceof QuestionDef) {
                                TreeReference reference = (TreeReference) formElement.getBind().getReference();
                                IAnswerData answerValue = p.getAnswerValue();
                                Object value = answerValue == null ? null : answerValue.getValue();
                                switch (p.getDataType()) {
                                case Constants.DATATYPE_TEXT:
                                case Constants.DATATYPE_INTEGER:
                                case Constants.DATATYPE_DECIMAL:
                                    i.putExtra(reference.getNameLast(), (Serializable) value);
                                    break;
                                }
                            }
                        }

                        ((Activity) getContext()).startActivityForResult(i, RequestCodes.EX_GROUP_CAPTURE);
                    } catch (ExternalParamsException e) {
                        Timber.e(e, "ExternalParamsException");

                        ToastUtils.showShortToast(e.getMessage());
                    } catch (ActivityNotFoundException e) {
                        Timber.d(e, "ActivityNotFoundExcept");

                        ToastUtils.showShortToast(errorString);
                    }
                }
            });

            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);

            view.addView(launchIntentButton, layout);
        }
    }

    boolean first = true;
    for (FormEntryPrompt p : questionPrompts) {
        if (!first) {
            View divider = new View(getContext());
            divider.setBackgroundResource(new ThemeUtils(getContext()).getDivider());
            divider.setMinimumHeight(3);
            view.addView(divider);
        } else {
            first = false;
        }

        // if question or answer type is not supported, use text widget
        QuestionWidget qw = WidgetFactory.createWidgetFromPrompt(p, getContext(), readOnlyOverride);
        qw.setLongClickable(true);
        qw.setOnLongClickListener(this);
        qw.setId(ViewIds.generateViewId());

        widgets.add(qw);
        view.addView(qw, layout);
    }

    ((NestedScrollView) findViewById(R.id.odk_view_container)).addView(view);

    // see if there is an autoplay option.
    // Only execute it during forward swipes through the form
    if (advancingPage && widgets.size() == 1) {
        final String playOption = widgets.get(0).getFormEntryPrompt().getFormElement()
                .getAdditionalAttribute(null, "autoplay");
        if (playOption != null) {
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (playOption.equalsIgnoreCase("audio")) {
                        widgets.get(0).playAudio();
                    } else if (playOption.equalsIgnoreCase("video")) {
                        widgets.get(0).playVideo();
                    }
                }
            }, 150);
        }
    }
}

From source file:com.launcher.silverfish.TabFragmentHandler.java

/**
 * Loads all tabs from the database./*from  w w w .j a v a 2 s.  c  o m*/
 */
public void loadTabs() {
    arrButton = new ArrayList<Button>();
    arrTabs = new ArrayList<TabInfo>();

    LinearLayout tabWidget = (LinearLayout) rootView.findViewById(R.id.custom_tabwidget);

    LauncherSQLiteHelper sql = new LauncherSQLiteHelper(mActivity.getApplicationContext());
    List<TabTable> tabTables = sql.getAllTabs();

    for (TabTable tabEntry : tabTables) {
        TabInfo tab = new TabInfo(tabEntry);
        arrTabs.add(tab);

        // Create a button for each tab
        Button btn = new Button(mActivity.getApplicationContext());
        btn.setText(tab.getLabel());
        arrButton.add(btn);

        // Set the style of the button
        btn.setBackgroundResource(R.drawable.tab_style);
        btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        btn.setTextColor(Color.WHITE);

        // Add the button to the tab widget.
        tabWidget.addView(btn);

        // And create a new tab
        TabHost.TabSpec tSpecFragmentId = tHost.newTabSpec(tab.getTag());
        tSpecFragmentId.setIndicator(tab.getLabel());
        tSpecFragmentId.setContent(new DummyTabContent(mActivity.getBaseContext()));
        tHost.addTab(tSpecFragmentId);
    }

}

From source file:org.mklab.mikity.android.editor.AbstractObjectEditor.java

private void createColorBoxes(TableLayout parameters) {
    final ColorModel color = this.object.getColor();
    this.colorValue = Color.argb(color.getAlpha(), color.getR(), color.getG(), color.getB());

    final TableRow colorParameter = new TableRow(getContext());
    parameters.addView(colorParameter);/*w  w w . j  a v  a2  s  .  c  om*/

    final TextView colorLabel = new TextView(getContext());
    colorLabel.setText(getString(R.string.color));
    colorLabel.setTextColor(Color.BLACK);
    colorParameter.addView(colorLabel);

    this.colorButton = new Button(getContext());
    updateColorButton();
    colorParameter.addView(this.colorButton);

    this.colorButton.setOnClickListener(new OnClickListener() {

        /**
         * {@inheritDoc}
         */
        public void onClick(View v) {
            openColorPicker(AbstractObjectEditor.this.colorValue);
        }
    });

    this.colorAlpha = new ParameterInputBox(getContext(), this, this);
    parameters.addView(this.colorAlpha);
    this.colorAlpha.setName(R.string.color_alpha);
    this.colorAlpha.setValue("" + color.getAlpha()); //$NON-NLS-1$
    this.colorAlpha.setUnit(""); //$NON-NLS-1$
}

From source file:com.gokuai.yunkuandroidsdk.compat.v2.UrlTouchImageView.java

@SuppressWarnings("deprecation")
protected void init() {

    mImageView = new TouchImageView(mContext);

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.FILL_PARENT);
    mImageView.setLayoutParams(params);//www .  j av  a2 s. c  o m
    this.addView(mImageView);

    mImageView.setVisibility(GONE);

    mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleInverse);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(params);
    mProgressBar.setIndeterminate(false);
    this.addView(mProgressBar);

    mTextView = new TextView(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mTextView.setLayoutParams(params);
    int left = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_left);
    int top = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_top);
    int right = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_right);
    int bottom = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_bottom);
    mTextView.setPadding(left, top, right, bottom);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setTextColor(Color.WHITE);
    mTextView.setText(R.string.tip_is_preparing_for_data);
    mTextView.setVisibility(View.GONE);
    this.addView(mTextView);

    mButton = new Button(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mButton.setLayoutParams(params);
    mButton.setGravity(Gravity.CENTER);
    mButton.setText(R.string.tip_image_button);
    mButton.setTextColor(Color.WHITE);
    mButton.setBackgroundResource(R.drawable.btn_check_image);
    mButton.setVisibility(View.GONE);
    this.addView(mButton);

    mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mImageUrlTask = new AsyncTask<Void, Integer, Bitmap>() {

                @Override
                protected Bitmap doInBackground(Void... voids) {
                    if (mFileData != null) {
                        FileData fileData = FileDataManager.getInstance()
                                .getFileInfoSync(mFileData.getFullpath());

                        return getOriImage(fileData, new ParamsCallBack() {
                            @Override
                            public void callBack(Object obj) {
                                publishProgress((int) obj);
                            }
                        });

                    } else {
                        return null;
                    }

                }

                @Override
                protected void onProgressUpdate(Integer... values) {
                    super.onProgressUpdate(values);
                    mButton.setVisibility(GONE);
                    mTextView.setVisibility(VISIBLE);
                    mProgressBar.setVisibility(VISIBLE);
                    if (values[0] == -1) {
                        mTextView.setText(mContext.getString(R.string.tip_is_loading));
                    } else {
                        mTextView.setText(values[0] + " %");
                    }
                }

                @Override
                protected void onPostExecute(Bitmap bitmap) {
                    super.onPostExecute(bitmap);

                    if (mImageView != null && mProgressBar != null) {
                        if (bitmap != null) {
                            mButton.setVisibility(GONE);
                            mImageView.setScaleType(ScaleType.MATRIX);
                            mImageView.setImageBitmap(bitmap);

                            mTextView.setVisibility(View.GONE);
                            mImageView.setVisibility(VISIBLE);
                            mProgressBar.setVisibility(GONE);

                        } else {
                            mButton.setVisibility(GONE);
                            mTextView.setVisibility(VISIBLE);
                            mTextView.setText(R.string.tip_open_image_failed);
                            mProgressBar.setVisibility(View.VISIBLE);
                        }
                    }

                }
            }.execute();
        }
    });

}

From source file:com.owncloud.android.ui.adapter.NotificationListAdapter.java

@Override
public void onBindViewHolder(@NonNull NotificationViewHolder holder, int position) {
    Notification notification = notificationsList.get(position);
    holder.dateTime.setText(// w  w  w .  ja va  2  s  .  c o  m
            DisplayUtils.getRelativeTimestamp(notificationsActivity, notification.getDatetime().getTime()));

    String subject = notification.getSubject();
    if (!TextUtils.isEmpty(notification.getLink())) {
        subject = subject + " ";
        holder.subject.setTypeface(holder.subject.getTypeface(), Typeface.BOLD);
        holder.subject.setOnClickListener(v -> openLink(notification.getLink()));
        holder.subject.setText(subject);
    } else {
        if (!TextUtils.isEmpty(notification.subjectRich)) {
            holder.subject.setText(makeSpecialPartsBold(notification));
        } else {
            holder.subject.setText(subject);
        }
    }

    holder.message.setText(notification.getMessage());

    // Todo set proper action icon (to be clarified how to pick)
    if (!TextUtils.isEmpty(notification.getIcon())) {
        downloadIcon(notification.getIcon(), holder.icon);
    }

    // add action buttons
    holder.buttons.removeAllViews();
    Button button;
    ExecuteActionTask executeActionTask = new ExecuteActionTask(holder);

    for (Action action : notification.getActions()) {
        button = new Button(notificationsActivity);
        button.setText(action.label);
        if (action.primary) {
            button.getBackground().setColorFilter(ThemeUtils.primaryColor(notificationsActivity, true),
                    PorterDuff.Mode.SRC_ATOP);
            button.setTextColor(ThemeUtils.fontColor(notificationsActivity));
        }

        button.setOnClickListener(v -> executeActionTask.execute(action));

        holder.buttons.addView(button);
    }
}

From source file:com.launcher.silverfish.launcher.appdrawer.TabFragmentHandler.java

/**
 * Loads all tabs from the database./*from  w  w w. j  a v a2  s.  c o m*/
 */
public void loadTabs() {
    arrButton = new ArrayList<>();
    arrTabs = new ArrayList<>();

    LinearLayout tabWidget = (LinearLayout) rootView.findViewById(R.id.custom_tabwidget);

    LauncherSQLiteHelper sql = new LauncherSQLiteHelper((App) mActivity.getApplication());
    List<TabTable> tabTables = sql.getAllTabs();

    for (TabTable tabEntry : tabTables) {
        TabInfo tab = new TabInfo(tabEntry);
        arrTabs.add(tab);

        // Create a button for each tab
        Button btn = new Button(mActivity.getApplicationContext());
        btn.setText(tab.getLabel());
        btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_TEXT_SIZE);
        arrButton.add(btn);

        // Set the style of the button
        btn.setBackground(settings.getTabButtonStyle());
        btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        btn.setTextColor(settings.getFontFgColor());

        // Add the button to the tab widget.
        tabWidget.addView(btn);

        // And create a new tab
        TabHost.TabSpec tSpecFragmentId = tHost.newTabSpec(tab.getTag());
        tSpecFragmentId.setIndicator(tab.getLabel());
        tSpecFragmentId.setContent(new DummyTabContent(mActivity.getBaseContext()));
        tHost.addTab(tSpecFragmentId);
    }

}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

public void createMessage(ViewGroup l, String text, String button, View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(getActivity());
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    LinearLayout l2 = new LinearLayout(getActivity());
    l2.setOrientation(LinearLayout.VERTICAL);
    RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutparams.addRule(RelativeLayout.CENTER_VERTICAL);
    l2.setLayoutParams(layoutparams);//www  . j  a v  a  2s .  c om
    l2.setGravity(Gravity.CENTER_HORIZONTAL);

    TextView tv = new TextView(getActivity());
    LinearLayout.LayoutParams tvparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv.setLayoutParams(tvparams);
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    l2.addView(tv);

    if (button != null) {
        Button b = new Button(getActivity());
        LinearLayout.LayoutParams bparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        bparams.setMargins(toPixels(4), toPixels(0), toPixels(4), toPixels(4));
        b.setLayoutParams(bparams);
        b.setId(R.id.reload_button);
        b.setText(button);
        b.setTextSize(23);
        b.setAllCaps(false);
        b.setTypeface(null, Typeface.NORMAL);
        b.setOnClickListener(onclick);
        l2.addView(b);
    }

    r.addView(l2);
    l.addView(r);
}

From source file:org.spinsuite.fta.view.V_AddSuggestedProduct.java

/**
 * Load Config/*from  w  w  w .  ja  va  2s .c o  m*/
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 18/03/2014, 22:07:43
 * @return void
 */
private void loadConfig() {
    viewList = new ArrayList<GridField>();
    //   Set Parameter
    v_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, WEIGHT);
    //   Add Fields
    //   Add View to Layout
    InfoField field = new InfoField();
    field.DisplayType = DisplayType.YES_NO;

    addView(field);
    //   Add Button
    Button btn_Search = new Button(this);
    btn_Search.setText(getResources().getString(R.string.msg_Search));
    //   Action
    btn_Search.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            m_criteria = new FilterValue();
            if (m_oldCriteria != null)
                m_criteria = m_oldCriteria;
            //   Add Criteria
            addCriteriaQuery();
            new LoadViewTask().execute();
        }
    });
    //   Add Button
    ll_ConfigSearch.addView(btn_Search, v_param);
    //   Hide
    ll_ConfigSearch.setVisibility(LinearLayout.GONE);
}