List of usage examples for android.widget Button Button
public Button(Context context)
From source file:com.skytree.epubtest.BookViewActivity.java
public void fillBookmarkList() { this.listView.removeAllViews(); ArrayList<PageInformation> pis = sd.fetchBookmarks(this.bookCode); for (int i = 0; i < pis.size(); i++) { int textColor = Color.BLACK; Theme theme = getCurrentTheme(); textColor = theme.foregroundColor; PageInformation pi = pis.get(i); SkyLayout item = new SkyLayout(this); setFrame(item, 0, 0, listBox.getWidth(), ps(80)); ImageButton mark = this.makeImageButton(9898, R.drawable.bookmarked2x, ps(50), ps(90)); item.addView(mark);/*from w ww .ja v a 2 s . c o m*/ setFrame(mark, ps(10), ps(5), ps(60), ps(120)); int ci = pi.chapterIndex; if (rv.isRTL()) { ci = rv.getNumberOfChapters() - ci - 1; } String chapterTitle = rv.getChapterTitle(ci); if (chapterTitle == null || chapterTitle.isEmpty()) chapterTitle = "Chapter " + ci; TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor); setFrame(chapterLabel, ps(80), ps(5), this.listBox.getWidth() - ps(80), ps(40)); item.addView(chapterLabel); TextView dateLabel = this.makeLabel(9899, pi.datetime, Gravity.LEFT, 12, textColor); setFrame(dateLabel, this.listBox.getWidth() - ps(50 + 250), ps(48), this.listBox.getWidth() - ps(40), ps(40)); View lineView = new View(this); lineView.setBackgroundColor(Color.LTGRAY); setFrame(lineView, 0, ps(79), this.listBox.getWidth(), ps(1)); item.addView(dateLabel); item.addView(lineView); item.setSkyLayoutListener(bookmarkListDelegate); item.setId(pi.code); item.data = pi; Button deleteButton = new Button(this); GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xffcf666e, 0xff671521 }); grad.setStroke(ps(2), 0xff282828); deleteButton.setBackgroundDrawable(grad); deleteButton.setText(getString(R.string.delete)); deleteButton.setTextSize(12); deleteButton.setTypeface(null, Typeface.BOLD); deleteButton.setTextColor(Color.WHITE); deleteButton.setId(pi.code); deleteButton.setVisibility(View.INVISIBLE); deleteButton.setVisibility(View.GONE); deleteButton.setOnClickListener(deleteBookmarkDelegate); int dw = ps(120); int dh = ps(50); setFrame(deleteButton, this.listView.getWidth() - dw, (ps(80) - dh) / 2, dw, dh); item.deleteControl = deleteButton; item.addView(deleteButton); this.listView.addView(item); } }
From source file:com.mplayer_remote.ServerList.java
private void createConnectButtons(int i) { Button button_connect_to = new Button(ServerList.this); button_connect_to.setPadding(5, 5, 5, 5); button_connect_to.setText(serverListArrayList.get(i).getServerName()); button_connect_to.setId(i);//from w w w. j av a 2 s . c om //custom look of button button_connect_to .setBackgroundDrawable(getResources().getDrawable(R.drawable.buttontheme_btn_default_holo_light)); //enabling menu item menu_item_edit_server and menu_item_delete_server invalidateOptionsMenu(); final Intent intent_start_ConnectAndPlayService = new Intent(getApplicationContext(), ConnectAndPlayService.class); intent_start_ConnectAndPlayService.putExtra("server_name", serverListArrayList.get(i).getServerName()); intent_start_ConnectAndPlayService.putExtra("IP_address", serverListArrayList.get(i).getIPAddress()); intent_start_ConnectAndPlayService.putExtra("username", serverListArrayList.get(i).getUsername()); intent_start_ConnectAndPlayService.putExtra("password", serverListArrayList.get(i).getPassword()); button_connect_to.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startService(intent_start_ConnectAndPlayService); connectingToSshProgressDialog = ProgressDialog.show(ServerList.this, "", getString(R.string.text_for_progressdialog_from_connecttoserver), true, true); } }); ll.addView(button_connect_to); }
From source file:com.skytree.epubtest.BookViewActivity.java
public void fillHighlightList() { Theme theme = getCurrentTheme();/*w w w . jav a 2 s.com*/ int textColor = theme.foregroundColor; this.listView.removeAllViews(); Highlights highlights = sd.fetchAllHighlights(this.bookCode); for (int i = 0; i < highlights.getSize(); i++) { Highlight highlight = highlights.getHighlight(i); SkyLayout item = new SkyLayout(this); int ci = highlight.chapterIndex; if (rv.isRTL()) { ci = rv.getNumberOfChapters() - ci - 1; } String chapterTitle = rv.getChapterTitle(ci); if (chapterTitle == null || chapterTitle.isEmpty()) chapterTitle = "Chapter " + ci; TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor); setFrame(chapterLabel, ps(20), ps(5), this.listView.getWidth() - ps(20), ps(40)); item.addView(chapterLabel); GradientDrawable textGrad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { getBrighterColor(highlight.color), getDarkerColor(highlight.color) }); TextView textLabel = this.makeLabel(9899, highlight.text, Gravity.LEFT, 16, Color.BLACK); setFrame(textLabel, ps(20), ps(5 + 40 + 5), this.listView.getWidth() - ps(20), ps(70)); textLabel.setBackgroundDrawable(textGrad); textLabel.getBackground().setAlpha(180); item.addView(textLabel); int noteHeight = 0; if (highlight.isNote && highlight.note != null && highlight.note.length() != 0 && !highlight.note.equalsIgnoreCase("null")) { TextView noteLabel = this.makeLabel(9899, highlight.note, Gravity.LEFT, 16, Color.BLACK); noteLabel.setTextColor(getDarkerColor(highlight.color)); noteHeight = 70; setFrame(noteLabel, ps(20), ps(5 + 40 + 5 + 70 + 5), this.listView.getWidth() - ps(20), ps(noteHeight)); item.addView(noteLabel); } TextView dateLabel = this.makeLabel(9899, highlight.datetime, Gravity.RIGHT, 12, textColor); int lw = this.listView.getWidth(); setFrame(dateLabel, 0, ps(5 + 40 + 5 + 70 + 5 + noteHeight + 5), lw, ps(40)); item.addView(dateLabel); int itemHeight = ps(5 + 40 + 5 + 90 + 5 + noteHeight + 5 + 15 + 5); View lineView = new View(this); lineView.setBackgroundColor(Color.LTGRAY); setFrame(lineView, 0, itemHeight - ps(1), this.listView.getWidth(), ps(1)); item.addView(lineView); setFrame(item, 0, 0, listView.getWidth(), itemHeight); item.setSkyLayoutListener(highlightListDelegate); item.setId(highlight.code); item.data = highlight; Button deleteButton = new Button(this); GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xffcf666e, 0xff671521 }); grad.setStroke(ps(2), 0xff282828); deleteButton.setBackgroundDrawable(grad); deleteButton.setText(getString(R.string.delete)); deleteButton.setTypeface(null, Typeface.BOLD); deleteButton.setTextColor(Color.WHITE); deleteButton.setTextSize(12); deleteButton.setId(highlight.code); deleteButton.setVisibility(View.INVISIBLE); deleteButton.setVisibility(View.GONE); deleteButton.setOnClickListener(deleteHighlightDelegate); int dw = ps(120); int dh = ps(50); setFrame(deleteButton, this.listView.getWidth() - dw, (itemHeight - dh) / 2, dw, dh); item.deleteControl = deleteButton; item.addView(deleteButton); this.listView.addView(item); } }
From source file:com.mplayer_remote.ServerList.java
private void createConnectButtonsThatAskForServerPassword(int i) { //TODO Correct DIALOG_GIVE_ME_A_SERVER_PASSWORD final Button button_connect_to = new Button(ServerList.this); button_connect_to.setPadding(5, 5, 5, 5); button_connect_to.setText(serverListArrayList.get(i).getServerName()); button_connect_to.setId(i);/* w w w. ja va 2s .co m*/ //custom look of button button_connect_to .setBackgroundDrawable(getResources().getDrawable(R.drawable.buttontheme_btn_default_holo_light)); //enabling menu item menu_item_edit_server and menu_item_delete_server invalidateOptionsMenu(); button_connect_to.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Bundle bundleWithClickedButtonID = new Bundle(); bundleWithClickedButtonID.putInt("clicked_button", button_connect_to.getId()); Log.v(TAG, "button_connect_to.getId():" + button_connect_to.getId()); showDialog(DIALOG_GIVE_ME_A_SERVER_PASSWORD, bundleWithClickedButtonID); } }); ll.addView(button_connect_to); }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
@SuppressLint("InlinedApi") private void openGridGallery() { final int tnSize = resources.getDimensionPixelSize(R.dimen.post_thumbnail_size); class GridGalleryAdapter extends ArrayAdapter<Triple<AttachmentModel, String, String>> implements View.OnClickListener, AbsListView.OnScrollListener { private final GridView view; private boolean selectingMode = false; private boolean[] isSelected = null; private volatile boolean isBusy = false; public GridGalleryAdapter(GridView view, List<Triple<AttachmentModel, String, String>> list) { super(activity, 0, list); this.view = view; this.isSelected = new boolean[list.size()]; }/* ww w . ja v a 2s. c om*/ @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { if (isBusy) setNonBusy(); isBusy = false; } else isBusy = true; } private void setNonBusy() { if (!downloadThumbnails()) return; for (int i = 0; i < view.getChildCount(); ++i) { View v = view.getChildAt(i); Object tnTag = v.findViewById(R.id.post_thumbnail_image).getTag(); if (tnTag == null || tnTag == Boolean.FALSE) fill(view.getPositionForView(v), v, false); } } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = new FrameLayout(activity); convertView.setLayoutParams(new AbsListView.LayoutParams(tnSize, tnSize)); ImageView tnImage = new ImageView(activity); tnImage.setLayoutParams(new FrameLayout.LayoutParams(tnSize, tnSize, Gravity.CENTER)); tnImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE); tnImage.setId(R.id.post_thumbnail_image); ((FrameLayout) convertView).addView(tnImage); } convertView.setTag(getItem(position).getLeft()); safeRegisterForContextMenu(convertView); convertView.setOnClickListener(this); fill(position, convertView, isBusy); if (isSelected[position]) { /*ImageView overlay = new ImageView(activity); overlay.setImageResource(android.R.drawable.checkbox_on_background);*/ FrameLayout overlay = new FrameLayout(activity); overlay.setBackgroundColor(Color.argb(128, 0, 255, 0)); if (((FrameLayout) convertView).getChildCount() < 2) ((FrameLayout) convertView).addView(overlay); } else { if (((FrameLayout) convertView).getChildCount() > 1) ((FrameLayout) convertView).removeViewAt(1); } return convertView; } private void safeRegisterForContextMenu(View view) { try { view.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (presentationModel == null) { Fragment currentFragment = MainApplication .getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { currentFragment.onCreateContextMenu(menu, v, menuInfo); } } else { BoardFragment.this.onCreateContextMenu(menu, v, menuInfo); } } }); } catch (Exception e) { Logger.e(TAG, e); } } @Override public void onClick(View v) { if (selectingMode) { int position = view.getPositionForView(v); isSelected[position] = !isSelected[position]; notifyDataSetChanged(); } else { BoardFragment fragment = BoardFragment.this; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } fragment.openAttachment((AttachmentModel) v.getTag()); } } private void fill(int position, View view, boolean isBusy) { AttachmentModel attachment = getItem(position).getLeft(); String attachmentHash = getItem(position).getMiddle(); ImageView tnImage = (ImageView) view.findViewById(R.id.post_thumbnail_image); if (attachment.thumbnail == null || attachment.thumbnail.length() == 0) { tnImage.setTag(Boolean.TRUE); tnImage.setImageResource(Attachments.getDefaultThumbnailResId(attachment.type)); return; } tnImage.setTag(Boolean.FALSE); CancellableTask imagesDownloadTask = BoardFragment.this.imagesDownloadTask; ExecutorService imagesDownloadExecutor = BoardFragment.this.imagesDownloadExecutor; if (presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) { imagesDownloadTask = ((BoardFragment) currentFragment).imagesDownloadTask; imagesDownloadExecutor = ((BoardFragment) currentFragment).imagesDownloadExecutor; } } bitmapCache.asyncGet(attachmentHash, attachment.thumbnail, tnSize, chan, localFile, imagesDownloadTask, tnImage, imagesDownloadExecutor, Async.UI_HANDLER, downloadThumbnails() && !isBusy, downloadThumbnails() ? (isBusy ? 0 : R.drawable.thumbnail_error) : Attachments.getDefaultThumbnailResId(attachment.type)); } public void setSelectingMode(boolean selectingMode) { this.selectingMode = selectingMode; if (!selectingMode) { Arrays.fill(isSelected, false); notifyDataSetChanged(); } } public void selectAll() { if (selectingMode) { Arrays.fill(isSelected, true); notifyDataSetChanged(); } } public void downloadSelected(final Runnable onFinish) { final Dialog progressDialog = ProgressDialog.show(activity, resources.getString(R.string.grid_gallery_dlg_title), resources.getString(R.string.grid_gallery_dlg_message), true, false); Async.runAsync(new Runnable() { @Override public void run() { BoardFragment fragment = BoardFragment.this; if (fragment.presentationModel == null) { Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment; if (currentFragment instanceof BoardFragment) fragment = (BoardFragment) currentFragment; } boolean flag = false; for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) if (!fragment.downloadFile(getItem(i).getLeft(), true)) flag = true; final boolean toast = flag; activity.runOnUiThread(new Runnable() { @Override public void run() { if (toast) Toast.makeText(activity, R.string.notification_download_exists_or_in_queue, Toast.LENGTH_LONG).show(); progressDialog.dismiss(); onFinish.run(); } }); } }); } } try { List<Triple<AttachmentModel, String, String>> list = presentationModel.getAttachments(); if (list == null) { Toast.makeText(activity, R.string.notifacation_updating_now, Toast.LENGTH_LONG).show(); return; } GridView grid = new GridView(activity); final GridGalleryAdapter gridAdapter = new GridGalleryAdapter(grid, list); grid.setNumColumns(GridView.AUTO_FIT); grid.setColumnWidth(tnSize); int spacing = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); grid.setVerticalSpacing(spacing); grid.setHorizontalSpacing(spacing); grid.setPadding(spacing, spacing, spacing, spacing); grid.setAdapter(gridAdapter); grid.setOnScrollListener(gridAdapter); grid.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); final Button btnToSelecting = new Button(activity); btnToSelecting.setText(R.string.grid_gallery_select); CompatibilityUtils.setTextAppearance(btnToSelecting, android.R.style.TextAppearance_Small); btnToSelecting.setSingleLine(); btnToSelecting.setVisibility(View.VISIBLE); btnToSelecting.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutSelectingButtons = new LinearLayout(activity); layoutSelectingButtons.setOrientation(LinearLayout.HORIZONTAL); layoutSelectingButtons.setWeightSum(10f); Button btnDownload = new Button(activity); btnDownload.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.25f)); btnDownload.setText(R.string.grid_gallery_download); CompatibilityUtils.setTextAppearance(btnDownload, android.R.style.TextAppearance_Small); btnDownload.setSingleLine(); Button btnSelectAll = new Button(activity); btnSelectAll.setLayoutParams( new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3.75f)); btnSelectAll.setText(android.R.string.selectAll); CompatibilityUtils.setTextAppearance(btnSelectAll, android.R.style.TextAppearance_Small); btnSelectAll.setSingleLine(); Button btnCancel = new Button(activity); btnCancel.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 3f)); btnCancel.setText(android.R.string.cancel); CompatibilityUtils.setTextAppearance(btnCancel, android.R.style.TextAppearance_Small); btnCancel.setSingleLine(); layoutSelectingButtons.addView(btnDownload); layoutSelectingButtons.addView(btnSelectAll); layoutSelectingButtons.addView(btnCancel); layoutSelectingButtons.setVisibility(View.GONE); layoutSelectingButtons.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); btnToSelecting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.GONE); layoutSelectingButtons.setVisibility(View.VISIBLE); gridAdapter.setSelectingMode(true); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); btnSelectAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.selectAll(); } }); btnDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gridAdapter.downloadSelected(new Runnable() { @Override public void run() { btnToSelecting.setVisibility(View.VISIBLE); layoutSelectingButtons.setVisibility(View.GONE); gridAdapter.setSelectingMode(false); } }); } }); LinearLayout dlgLayout = new LinearLayout(activity); dlgLayout.setOrientation(LinearLayout.VERTICAL); dlgLayout.addView(btnToSelecting); dlgLayout.addView(layoutSelectingButtons); dlgLayout.addView(grid); Dialog gridDialog = new Dialog(activity); gridDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); gridDialog.setContentView(dlgLayout); gridDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); gridDialog.show(); } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); Toast.makeText(activity, R.string.error_out_of_memory, Toast.LENGTH_LONG).show(); } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showInAppDonations(final Inventory inv, boolean showIfAlreadyDonated) { updateProgressIcon(false);/*from ww w . ja v a 2s . c o m*/ AlertDialog.Builder alert = new AlertDialog.Builder(TvBrowser.this); alert.setTitle(R.string.donation); View view = getLayoutInflater().inflate(R.layout.in_app_donations, getParentViewGroup(), false); LinearLayout layout = (LinearLayout) view.findViewById(R.id.donation_in_app_layout); alert.setView(view); alert.setNegativeButton(getString(R.string.not_now).replace("{0}", ""), null); if (Locale.getDefault().getCountry().equals("DE")) { alert.setPositiveButton(R.string.donation_info_website, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://android.tvbrowser.org/index.php?id=donations"))); } }); } final AlertDialog d = alert.create(); View.OnClickListener onDonationClick = new View.OnClickListener() { @Override public void onClick(View v) { d.dismiss(); openDonation((SkuDetails) v.getTag()); } }; Purchase donated = null; SkuDetails donatedDetails = null; for (String sku : SettingConstants.SKU_LIST) { SkuDetails details = inv.getSkuDetails(sku); Purchase donatedTest = inv.getPurchase(sku); if (donatedTest != null && details != null) { donated = donatedTest; donatedDetails = details; } if (details != null) { if (!details.getSku().equals(SettingConstants.SKU_EPG_DONATE_ONCE) || hasEpgDonateChannelsSubscribed()) { String title = details.getTitle().substring(0, details.getTitle().indexOf("(") - 1); Button donation = new Button(this); donation.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); donation.setText(title + ": " + details.getPrice()); donation.setTag(details); donation.setOnClickListener(onDonationClick); layout.addView(donation); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) donation.getLayoutParams(); params.setMargins(5, 0, 5, 5); //left, top, right, bottom donation.setLayoutParams(params); } } } if (donated == null || showIfAlreadyDonated) { d.show(); } else if (donated != null) { AlertDialog.Builder alert2 = new AlertDialog.Builder(TvBrowser.this); alert2.setTitle(R.string.donation); String message = getString(R.string.already_donated) .replace("{1}", DateFormat.getLongDateFormat(this).format(new Date(donated.getPurchaseTime()))) .replace("{0}", donatedDetails.getPrice()); alert2.setMessage(message); final Purchase toConsume = donated; alert2.setPositiveButton(R.string.donate_again, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { updateProgressIcon(true); mHelper.consumeAsync(toConsume, new IabHelper.OnConsumeFinishedListener() { @Override public void onConsumeFinished(Purchase purchase, IabResult result) { updateProgressIcon(false); if (result.isSuccess()) { d.show(); } else { handler.post(new Runnable() { @Override public void run() { Toast.makeText(TvBrowser.this, "", Toast.LENGTH_LONG).show(); } }); } } }); } }); alert2.setNegativeButton(R.string.stop_donation, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert2.show(); } }