List of usage examples for android.widget Button Button
public Button(Context context)
From source file:org.odk.collect.android.widgets.ImageWebViewWidget.java
public ImageWebViewWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent(); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5);/* w w w . j av a 2 s. c o m*/ mErrorTextView = new TextView(context); mErrorTextView.setId(QuestionWidget.newUniqueId()); mErrorTextView.setText("Selected file is not a valid image"); // setup capture button mCaptureButton = new Button(getContext()); mCaptureButton.setId(QuestionWidget.newUniqueId()); mCaptureButton.setText(getContext().getString(R.string.capture_image)); mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mCaptureButton.setPadding(20, 20, 20, 20); mCaptureButton.setEnabled(!prompt.isReadOnly()); mCaptureButton.setLayoutParams(params); // launch capture intent on click mCaptureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); // We give the camera an absolute filename/path where to put the // picture because of bug: // http://code.google.com/p/android/issues/detail?id=1480 // The bug appears to be fixed in Android 2.0+, but as of feb 2, // 2010, G1 phones only run 1.6. Without specifying the path the // images returned by the camera in 1.6 (and earlier) are ~1/4 // the size. boo. // if this gets modified, the onActivityResult in // FormEntyActivity will also need to be updated. Uri tempPath = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider", new File(Collect.TMPFILE_PATH)); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPath); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, "image capture"), Toast.LENGTH_SHORT).show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // setup chooser button mChooseButton = new Button(getContext()); mChooseButton.setId(QuestionWidget.newUniqueId()); mChooseButton.setText(getContext().getString(R.string.choose_image)); mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mChooseButton.setPadding(20, 20, 20, 20); mChooseButton.setEnabled(!prompt.isReadOnly()); mChooseButton.setLayoutParams(params); // launch capture intent on click mChooseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click", mPrompt.getIndex()); mErrorTextView.setVisibility(View.GONE); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER); } catch (ActivityNotFoundException e) { Toast.makeText(getContext(), getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT) .show(); Collect.getInstance().getFormController().setIndexWaitingForData(null); } } }); // finish complex layout LinearLayout answerLayout = new LinearLayout(getContext()); answerLayout.setOrientation(LinearLayout.VERTICAL); answerLayout.addView(mCaptureButton); answerLayout.addView(mChooseButton); answerLayout.addView(mErrorTextView); // and hide the capture and choose button if read-only if (prompt.isReadOnly()) { mCaptureButton.setVisibility(View.GONE); mChooseButton.setVisibility(View.GONE); } mErrorTextView.setVisibility(View.GONE); // retrieve answer from data model and update ui mBinaryName = prompt.getAnswerText(); // Only add the imageView if the user has taken a picture if (mBinaryName != null) { mImageDisplay = new WebView(getContext()); mImageDisplay.setId(QuestionWidget.newUniqueId()); mImageDisplay.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); mImageDisplay.getSettings().setBuiltInZoomControls(true); mImageDisplay.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR); mImageDisplay.setVisibility(View.VISIBLE); mImageDisplay.setLayoutParams(params); // HTML is used to display the image. String html = "<body>" + constructImageElement() + "</body>"; mImageDisplay.loadDataWithBaseURL("file:///" + mInstanceFolder + File.separator, html, "text/html", "utf-8", ""); answerLayout.addView(mImageDisplay); } addAnswerView(answerLayout); }
From source file:ovh.ice.icecons.MainActivity.java
private void createLayout() { // main centered layout LinearLayout.LayoutParams smallLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); float scale = IceScreenUtils.densityScale(getApplicationContext()); ViewGroup.LayoutParams buttonParams = new ViewGroup.LayoutParams(Math.round(48 * scale), Math.round(48 * scale)); LinearLayout frameLayout = new LinearLayout(this); frameLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); frameLayout.setBackgroundColor(0xffffffff); frameLayout.setGravity(Gravity.CENTER); setContentView(frameLayout);//from w w w . j av a2 s. c om LinearLayout baseLayout = new LinearLayout(this); baseLayout.setOrientation(LinearLayout.VERTICAL); baseLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); baseLayout.setGravity(Gravity.LEFT); frameLayout.addView(baseLayout); // wallpaper button LinearLayout wallpaperLayout = new LinearLayout(this); wallpaperLayout.setOrientation(LinearLayout.HORIZONTAL); wallpaperLayout.setLayoutParams(smallLayoutParams); wallpaperLayout.setGravity(Gravity.CENTER_VERTICAL); baseLayout.addView(wallpaperLayout); LinearLayout wallpaperClickLayout = new LinearLayout(this); wallpaperClickLayout.setOrientation(LinearLayout.HORIZONTAL); wallpaperClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); wallpaperClickLayout.setGravity(Gravity.CENTER); wallpaperLayout.addView(wallpaperClickLayout); wallpaperClickLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { wallpaperPicker(v); } }); Button wallpaperButton = new Button(this); wallpaperButton.setLayoutParams(buttonParams); wallpaperButton.setBackground( new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_wallpaper_button, Math.round(48 * scale), Math.round(48 * scale)))); wallpaperClickLayout.addView(wallpaperButton); TextView wallpaperText = new TextView(this); wallpaperText.setText("wallpapers"); wallpaperText.setTextSize(24); wallpaperText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); wallpaperText.setPadding(64, 64, 64, 64); wallpaperClickLayout.addView(wallpaperText); // icon view button LinearLayout iconLayout = new LinearLayout(this); iconLayout.setOrientation(LinearLayout.HORIZONTAL); iconLayout.setLayoutParams(smallLayoutParams); iconLayout.setGravity(Gravity.CENTER_VERTICAL); baseLayout.addView(iconLayout); LinearLayout iconClickLayout = new LinearLayout(this); iconClickLayout.setOrientation(LinearLayout.HORIZONTAL); iconClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); iconClickLayout.setGravity(Gravity.CENTER); iconLayout.addView(iconClickLayout); iconClickLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { iconView(v); } }); Button iconButton = new Button(this); iconButton.setLayoutParams(buttonParams); iconButton.setBackground( new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_icon_button, Math.round(48 * scale), Math.round(48 * scale)))); iconClickLayout.addView(iconButton); TextView iconText = new TextView(this); iconText.setText("view icons"); iconText.setTextSize(24); iconText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); iconText.setPadding(64, 64, 64, 64); iconClickLayout.addView(iconText); // source code button LinearLayout sourceLayout = new LinearLayout(this); sourceLayout.setOrientation(LinearLayout.HORIZONTAL); sourceLayout.setLayoutParams(smallLayoutParams); sourceLayout.setGravity(Gravity.CENTER_VERTICAL); baseLayout.addView(sourceLayout); LinearLayout sourceClickLayout = new LinearLayout(this); sourceClickLayout.setOrientation(LinearLayout.HORIZONTAL); sourceClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); sourceClickLayout.setGravity(Gravity.CENTER); sourceLayout.addView(sourceClickLayout); sourceClickLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gitLink(v); } }); Button sourceButton = new Button(this); sourceButton.setLayoutParams(buttonParams); sourceButton.setBackground( new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_source_button, Math.round(48 * scale), Math.round(48 * scale)))); sourceClickLayout.addView(sourceButton); TextView sourceText = new TextView(this); sourceText.setText("source code"); sourceText.setTextSize(24); sourceText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); sourceText.setPadding(64, 64, 64, 64); sourceClickLayout.addView(sourceText); // license button LinearLayout aboutLayout = new LinearLayout(this); aboutLayout.setOrientation(LinearLayout.HORIZONTAL); aboutLayout.setLayoutParams(smallLayoutParams); aboutLayout.setGravity(Gravity.CENTER_VERTICAL); baseLayout.addView(aboutLayout); LinearLayout aboutClickLayout = new LinearLayout(this); aboutClickLayout.setOrientation(LinearLayout.HORIZONTAL); aboutClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); aboutClickLayout.setGravity(Gravity.CENTER); aboutLayout.addView(aboutClickLayout); aboutClickLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { licenseShow(v); } }); Button aboutButton = new Button(this); aboutButton.setLayoutParams(buttonParams); aboutButton.setBackground( new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_license_button, Math.round(48 * scale), Math.round(48 * scale)))); aboutClickLayout.addView(aboutButton); TextView aboutText = new TextView(this); aboutText.setText("license"); aboutText.setTextSize(24); aboutText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)); aboutText.setPadding(64, 64, 64, 64); aboutClickLayout.addView(aboutText); }
From source file:org.chronotext.MobileTest.Bridge.java
Button addButton(int x, int y, int id) { final Button button = new Button(getActivity()); button.setId(id);// w w w . j av a 2 s . c o m RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.leftMargin = x; params.topMargin = y; overlayView.addView(button, params); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { buttonClicked(button); } }); return button; }
From source file:com.mikecorrigan.trainscorekeeper.ActivityNewGame.java
private void addContent() { Log.vc(VERBOSE, TAG, "addContent"); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear_layout); Resources res = getResources(); AssetManager am = res.getAssets();/*from w w w . j a va 2 s .c om*/ String files[]; try { files = am.list(ASSETS_BASE); if (files == null || files.length == 0) { Log.e(TAG, "addContent: empty asset list"); return; } for (final String file : files) { final String path = ASSETS_BASE + File.separator + file; JSONObject jsonRoot = JsonUtils.readFromAssets(this /* context */, path); if (jsonRoot == null) { Log.e(file, "addContent: failed to read read asset"); continue; } final String name = jsonRoot.optString(JsonSpec.ROOT_NAME); if (TextUtils.isEmpty(name)) { Log.e(file, "addContent: failed to read asset name"); continue; } final String description = jsonRoot.optString(JsonSpec.ROOT_DESCRIPTION, name); TextView textView = new TextView(this /* context */); textView.setText(name); linearLayout.addView(textView); Button button = new Button(this /* context */); button.setText(description); button.setOnClickListener(new OnRulesClickListener(path)); linearLayout.addView(button); } } catch (IOException e) { Log.th(TAG, e, "addContent: asset list failed"); } }
From source file:com.clov4r.moboplayer.android.nil.codec.activity.MoboThumbnailTestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); imageView = new ImageView(this); SubtitleJni h = new SubtitleJni(); String libpath = getFilesDir().getParent() + "/lib/"; String libname = "libffmpeg.so";// libffmpeg_armv7_neon.so h.loadFFmpegLibs(libpath, libname);/*from w w w. j a va 2 s . c om*/ Button button = new Button(this); layout.addView(button); layout.addView(imageView); button.setText(""); setContentView(layout); button.setOnClickListener(mOnClickListener); }
From source file:com.todoroo.astrid.notes.CommentsController.java
public void reloadView() { if (!preferences.getBoolean(R.string.p_show_task_edit_comments, true)) { return;//from w w w . j a v a2 s .co m } items.clear(); commentsContainer.removeAllViews(); metadataDao.byTaskAndKey(task.getId(), NoteMetadata.METADATA_KEY, metadata -> items.add(NoteOrUpdate.fromMetadata(metadata))); userActivityDao.getCommentsForTask(task.getUuid(), update -> items.add(NoteOrUpdate.fromUpdate(update))); Collections.sort(items, (a, b) -> { if (a.createdAt < b.createdAt) { return 1; } else if (a.createdAt == b.createdAt) { return 0; } else { return -1; } }); for (int i = 0; i < Math.min(items.size(), commentItems); i++) { View notesView = this.getUpdateNotes(items.get(i), commentsContainer); commentsContainer.addView(notesView); } if (items.size() > commentItems) { Button loadMore = new Button(activity); loadMore.setText(R.string.TEA_load_more); loadMore.setTextColor(getColor(activity, R.color.text_secondary)); loadMore.setBackgroundColor(Color.alpha(0)); loadMore.setOnClickListener(v -> { // Perform action on click commentItems += 10; reloadView(); }); commentsContainer.addView(loadMore); } }
From source file:com.normalexception.app.rx8club.fragment.thread.ThreadFilterFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { try {/*from w w w. j av a 2s .c o m*/ super.onCreate(savedInstanceState); MainApplication.setState(AppState.State.THREAD, this); Log.v(TAG, "Thread Filter Activity Started"); lv = (ListView) view.findViewById(R.id.mainlistview); Button bv = new Button(getActivity()); bv.setId(NEW_FILTER); bv.setOnClickListener(new ThreadFilterListener()); bv.setText("New Filter"); bv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10); lv.addFooterView(bv); updateList(); } catch (Exception e) { Log.e(TAG, "Fatal Error In Thread Activity! " + e.getMessage(), e); } }
From source file:com.pitchedapps.primenumbercalculator.CalculatorThemesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout v = (LinearLayout) super.onCreateView(inflater, container, savedInstanceState); Button btn = new Button(getActivity().getApplicationContext()); btn.setText("Reboot Now"); btn.setTextColor(PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()) .getInt("theme_advanced_numpad_text", 0xFF000000)); btn.setBackgroundColor(PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()) .getInt("theme_advanced_numpad", 0xFF1DE9B6)); v.addView(btn);//w w w.j a va2 s . c om btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = getActivity().getBaseContext().getPackageManager() .getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } }); return v; }
From source file:com.google.android.car.kitchensink.input.InputTestFragment.java
private Button createButton(@StringRes int textResId, int keyCode) { Button button = new Button(getContext()); button.setText(getContext().getString(textResId)); button.setTextSize(32f);//w w w. j a v a2s .co m // Single touch + key event does not work as touch is happening in other window // at the same time. But long press will work. button.setOnTouchListener((v, event) -> { handleTouchEvent(event, keyCode); return true; }); return button; }
From source file:com.publisnet.leydeinfogobierno.CapituloActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = (ScrollView) inflater.inflate(R.layout.fragment, container, false); final int i = getArguments().getInt(ARG_SECTION_NUMBER); ((TextView) rootView.findViewById(R.id.titulo)) .setText(getResources().getStringArray(R.array.leyes_titulos)[i]); //carga de articulos dentro de mismo titulo int articulos = getResources().getIdentifier("t" + i + "capitulo0", "array", getActivity().getApplicationContext().getPackageName()); //int articulosid = getResources().getIdentifier("t"+i+"arts","array",getActivity().getApplicationContext().getPackageName()); if (articulos != 0) { final String[] dropdownValues = getResources().getStringArray(articulos); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); int position = 0; for (String arts : dropdownValues) { Button art = new Button(getActivity().getApplicationContext()); art.setText(arts);/*from www . j av a2 s . c o m*/ final int pos = position; art.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Bundle sendBundle = new Bundle(); sendBundle.putInt(ArticuloActivity.ARG_ARTICULO_NUMBER, pos); sendBundle.putInt(ArticuloActivity.ARG_TIULO_NUMBER, i); sendBundle.putInt(ArticuloActivity.ARG_CAPITULO_NUMBER, 0); Intent intent = new Intent(getActivity().getApplicationContext(), ArticuloActivity.class); intent.putExtras(sendBundle); startActivity(intent); } }); ((LinearLayout) rootView.findViewById(R.id.ley)).addView(art, lp); position += 1; } } //carga de capitulos dentro del tituo int[] capitulos = ley.getCapitulos(i); if (capitulos != null) { int capitulosid = getResources().getIdentifier("titulo" + i, "array", getActivity().getApplicationContext().getPackageName()); for (int cap : capitulos) { Log.d("capitulo", "cap" + cap); View listview = (LinearLayout) inflater.inflate(R.layout.capitulo, container, false); int capituloid = getResources().getIdentifier("t" + i + "capitulo" + cap, "array", getActivity().getApplicationContext().getPackageName()); LinearLayout list = (LinearLayout) listview.findViewById(R.id.listart); String titulocapitulo = getResources().getStringArray(capitulosid)[cap - 1]; if (titulocapitulo.indexOf('-') > 0) { String[] c = titulocapitulo.split("-"); ((TextView) listview.findViewById(R.id.numeracioncapitulo)).setText(c[0]); if (c.length > 1) ((TextView) listview.findViewById(R.id.titulocapitulo)).setText(c[1]); } else { ((TextView) listview.findViewById(R.id.numeracioncapitulo)) .setText("CAP?TULO " + RomanNumerals(cap)); ((TextView) listview.findViewById(R.id.titulocapitulo)).setText(titulocapitulo); } final String[] dropdownValues = getResources().getStringArray(capituloid); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); final int capi = cap; int position = 0; for (String arts : dropdownValues) { Button art = new Button(getActivity().getApplicationContext()); art.setText(arts); final int pos = position; art.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Bundle sendBundle = new Bundle(); sendBundle.putInt(ArticuloActivity.ARG_ARTICULO_NUMBER, pos); sendBundle.putInt(ArticuloActivity.ARG_TIULO_NUMBER, i); sendBundle.putInt(ArticuloActivity.ARG_CAPITULO_NUMBER, capi); Intent intent = new Intent(getActivity().getApplicationContext(), ArticuloActivity.class); intent.putExtras(sendBundle); startActivity(intent); //Fragment fragment = new ArticuloFragment(); //Bundle args = new Bundle(); //args.putInt(ArticuloFragment.ARG_ARTICULO_NUMBER, pos); //fragment.setArguments(args); //args.putInt(ArticuloFragment.ARG_TIULO_NUMBER, i); //fragment.setArguments(args); ///args.putInt(ArticuloFragment.ARG_CAPITULO_NUMBER, capi); //fragment.setArguments(args); //FragmentTransaction f = getFragmentManager().beginTransaction(); //f.setCustomAnimations(android.R.anim.slide_out_right, android.R.anim.slide_in_left); //f.addToBackStack(null); //f.replace(R.id.container, fragment).addToBackStack(null); //f.commit(); } }); list.addView(art, lp); position += 1; } ((LinearLayout) rootView.findViewById(R.id.ley)).addView(listview); } //ArrayAdapter<String> adapter = new ArrayAdapter<String>( getActivity().getApplicationContext(), android.R.layout.simple_spinner_item, android.R.id.text1,dropdownValues); //list.setAdapter(adapter); //list.setOnItemClickListener(new AdapterView.OnItemClickListener() { //@Override //public void onItemClick(AdapterView<?> parent, View view, int position, //long id) { //} //}); } //LinearLayout l = new LinearLayout(getActivity().getApplicationContext()); return rootView; }