List of usage examples for android.widget LinearLayout LinearLayout
public LinearLayout(Context context)
From source file:info.semanticsoftware.semassist.android.activity.SemanticAssistantsActivity.java
/** Presents additional information about a specific assistant. * @return a dynamically generated linear layout */// w w w . j a va2 s . c o m private LinearLayout getServiceDescLayout() { final LinearLayout output = new LinearLayout(this); final RelativeLayout topButtonsLayout = new RelativeLayout(this); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); final Button btnBack = new Button(this); btnBack.setText(R.string.btnAllServices); btnBack.setId(5); btnBack.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { output.setVisibility(View.GONE); getListView().setVisibility(View.VISIBLE); lblAvAssist.setVisibility(View.VISIBLE); } }); topButtonsLayout.addView(btnBack); final Button btnInvoke = new Button(this); btnInvoke.setText(R.string.btnInvokeLabel); btnInvoke.setId(6); btnInvoke.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new InvocationTask().execute(); } }); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, btnInvoke.getId()); btnInvoke.setLayoutParams(layoutParams); topButtonsLayout.addView(btnInvoke); output.addView(topButtonsLayout); TableLayout serviceInfoTbl = new TableLayout(this); output.addView(serviceInfoTbl); serviceInfoTbl.setColumnShrinkable(1, true); /* FIRST ROW */ TableRow rowServiceName = new TableRow(this); TextView lblServiceName = new TextView(this); lblServiceName.setText(R.string.lblServiceName); lblServiceName.setTextAppearance(getApplicationContext(), R.style.titleText); TextView txtServiceName = new TextView(this); txtServiceName.setText(selectedService); txtServiceName.setTextAppearance(getApplicationContext(), R.style.normalText); txtServiceName.setPadding(10, 0, 0, 0); rowServiceName.addView(lblServiceName); rowServiceName.addView(txtServiceName); /* SECOND ROW */ TableRow rowServiceDesc = new TableRow(this); TextView lblServiceDesc = new TextView(this); lblServiceDesc.setText(R.string.lblServiceDesc); lblServiceDesc.setTextAppearance(getApplicationContext(), R.style.titleText); TextView txtServiceDesc = new TextView(this); txtServiceDesc.setTextAppearance(getApplicationContext(), R.style.normalText); txtServiceDesc.setPadding(10, 0, 0, 0); List<GateRuntimeParameter> params = null; ServiceInfoForClientArray list = getServices(); for (int i = 0; i < list.getItem().size(); i++) { if (list.getItem().get(i).getServiceName().equals(selectedService)) { txtServiceDesc.setText(list.getItem().get(i).getServiceDescription()); params = list.getItem().get(i).getParams(); break; } } TextView lblParams = new TextView(this); lblParams.setText(R.string.lblServiceParams); lblParams.setTextAppearance(getApplicationContext(), R.style.titleText); output.addView(lblParams); LayoutParams txtParamsAttrbs = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout paramsLayout = new LinearLayout(this); paramsLayout.setId(0); if (params.size() > 0) { ScrollView scroll = new ScrollView(this); scroll.setLayoutParams(txtParamsAttrbs); paramsLayout.setOrientation(LinearLayout.VERTICAL); scroll.addView(paramsLayout); for (int j = 0; j < params.size(); j++) { TextView lblParamName = new TextView(this); lblParamName.setText(params.get(j).getParamName()); EditText tview = new EditText(this); tview.setId(1); tview.setText(params.get(j).getDefaultValueString()); LayoutParams txtViewLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); tview.setLayoutParams(txtViewLayoutParams); paramsLayout.addView(lblParamName); paramsLayout.addView(tview); } output.addView(scroll); } else { TextView lblParamName = new TextView(this); lblParamName.setText(R.string.lblRTParams); output.addView(lblParamName); } rowServiceDesc.addView(lblServiceDesc); rowServiceDesc.addView(txtServiceDesc); serviceInfoTbl.addView(rowServiceName); serviceInfoTbl.addView(rowServiceDesc); output.setOrientation(LinearLayout.VERTICAL); output.setGravity(Gravity.TOP); return output; }
From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java
private void addWarningTab(final int position, String title, int resId) { LinearLayout tabLayout = new LinearLayout(getContext()); tabLayout.setOrientation(LinearLayout.HORIZONTAL); tabLayout.setGravity(Gravity.CENTER); ImageView tabImg = new ImageView(getContext()); int width = DimenUtils.dp2px(getContext(), 18); LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width); tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0); tabImgParams.gravity = Gravity.CENTER; tabImg.setLayoutParams(tabImgParams); if (resId != -1) { tabImg.setBackgroundResource(resId); tabImg.setVisibility(View.VISIBLE); } else {// w w w . j a v a 2s . c o m tabImg.setVisibility(View.GONE); } tabLayout.addView(tabImg, 0); TextView tab = new TextView(getContext()); tab.setText(title); tab.setFocusable(true); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTextColor(getResources().getColorStateList( mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector)); tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f); tabLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (null != mOnPageClickedLisener) { mOnPageClickedLisener.onPageClicked(position); } pager.setCurrentItem(position); } }); tabLayout.addView(tab, 1); tabsContainer.addView(tabLayout); }
From source file:com.android.calendar.event.EditEventFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // mContext.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); View view;/*w w w . j a v a 2s. c o m*/ if (mIsReadOnly) { view = inflater.inflate(R.layout.edit_event_single_column, null); } else { view = inflater.inflate(R.layout.edit_event, null); } mView = new EditEventView(mContext, view, mOnDone, mTimeSelectedWasStartTime, mDateSelectedWasStartDate); if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { //If permission is not granted Toast.makeText(mContext, R.string.calendar_permission_not_granted, Toast.LENGTH_LONG).show(); } else { startQuery(); } if (mUseCustomActionBar) { View actionBarButtons = inflater.inflate(R.layout.edit_event_custom_actionbar, new LinearLayout(mContext), false); View cancelActionView = actionBarButtons.findViewById(R.id.action_cancel); cancelActionView.setOnClickListener(mActionBarListener); View doneActionView = actionBarButtons.findViewById(R.id.action_done); doneActionView.setOnClickListener(mActionBarListener); mContext.getSupportActionBar().setCustomView(actionBarButtons); } return view; }
From source file:com.facebook.widget.LikeView.java
private void initialize(Context context) { edgePadding = getResources().getDimensionPixelSize(R.dimen.com_facebook_likeview_edge_padding); internalPadding = getResources().getDimensionPixelSize(R.dimen.com_facebook_likeview_internal_padding); if (foregroundColor == NO_FOREGROUND_COLOR) { foregroundColor = getResources().getColor(R.color.com_facebook_likeview_text_color); }/*from ww w . ja v a 2 s . co m*/ setBackgroundColor(Color.TRANSPARENT); containerView = new LinearLayout(context); LayoutParams containerViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); containerView.setLayoutParams(containerViewLayoutParams); initializeLikeButton(context); initializeSocialSentenceView(context); initializeLikeCountView(context); containerView.addView(likeButton); containerView.addView(socialSentenceView); containerView.addView(likeBoxCountView); addView(containerView); setObjectIdForced(this.objectId); updateLikeStateAndLayout(); }
From source file:cm.aptoide.pt.MainActivity.java
private void loadRecommended() { if (Login.isLoggedIn(mContext)) { ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.GONE); } else {/*from w w w . java 2 s . c o m*/ ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.VISIBLE); } new Thread(new Runnable() { private ArrayList<HashMap<String, String>> valuesRecommended; public void run() { loadUIRecommendedApps(); File f = null; try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); NetworkUtils utils = new NetworkUtils(); BufferedInputStream bis = new BufferedInputStream( utils.getInputStream("http://webservices.aptoide.com/webservices/listUserBasedApks/" + Login.getToken(mContext) + "/10/xml", null, null, mContext), 8 * 1024); f = File.createTempFile("abc", "abc"); OutputStream out = new FileOutputStream(f); byte buf[] = new byte[1024]; int len; while ((len = bis.read(buf)) > 0) out.write(buf, 0, len); out.close(); bis.close(); String hash = Md5Handler.md5Calc(f); ViewApk parent_apk = new ViewApk(); parent_apk.setApkid("recommended"); if (!hash.equals(db.getItemBasedApksHash(parent_apk.getApkid()))) { // Database.database.beginTransaction(); db.deleteItemBasedApks(parent_apk); sp.parse(f, new HandlerItemBased(parent_apk)); db.insertItemBasedApkHash(hash, parent_apk.getApkid()); // Database.database.setTransactionSuccessful(); // Database.database.endTransaction(); loadUIRecommendedApps(); } } catch (Exception e) { e.printStackTrace(); } if (f != null) f.delete(); } private void loadUIRecommendedApps() { valuesRecommended = db.getItemBasedApksRecommended("recommended"); runOnUiThread(new Runnable() { public void run() { LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.recommended_container); ll.removeAllViews(); LinearLayout llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); llAlso.setOrientation(LinearLayout.HORIZONTAL); if (valuesRecommended.isEmpty()) { if (Login.isLoggedIn(mContext)) { TextView tv = new TextView(mContext); tv.setText(R.string.no_recommended_apps); tv.setTextAppearance(mContext, android.R.attr.textAppearanceMedium); tv.setPadding(10, 10, 10, 10); ll.addView(tv); } } else { for (int i = 0; i != valuesRecommended.size(); i++) { LinearLayout txtSamItem = (LinearLayout) getLayoutInflater() .inflate(R.layout.row_grid_item, null); ((TextView) txtSamItem.findViewById(R.id.name)) .setText(valuesRecommended.get(i).get("name")); ImageLoader.getInstance().displayImage(valuesRecommended.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon)); float stars = 0f; try { stars = Float.parseFloat(valuesRecommended.get(i).get("rating")); } catch (Exception e) { stars = 0f; } ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true); ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars); txtSamItem.setPadding(10, 0, 0, 0); // ((TextView) // txtSamItem.findViewById(R.id.version)) // .setText(getString(R.string.version) +" "+ // valuesRecommended.get(i).get("vername")); ((TextView) txtSamItem.findViewById(R.id.downloads)) .setText("(" + valuesRecommended.get(i).get("downloads") + " " + getString(R.string.downloads) + ")"); txtSamItem.setTag(valuesRecommended.get(i).get("_id")); txtSamItem.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100, 1)); // txtSamItem.setOnClickListener(featuredListener); txtSamItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ApkInfo.class); long id = Long.parseLong((String) arg0.getTag()); i.putExtra("_id", id); i.putExtra("top", true); i.putExtra("category", Category.ITEMBASED.ordinal()); startActivity(i); } }); txtSamItem.measure(0, 0); if (i % 2 == 0) { ll.addView(llAlso); llAlso = new LinearLayout(MainActivity.this); llAlso.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 100)); llAlso.setOrientation(LinearLayout.HORIZONTAL); llAlso.addView(txtSamItem); } else { llAlso.addView(txtSamItem); } } ll.addView(llAlso); } } }); } }).start(); }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java
private void displayViewsForMode(int mode) { taskControls.removeAllViews();//from w w w . j a v a2 s. com descriptionControls.removeAllViews(); if (row == null) { row = new LinearLayout(this); row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); row.setOrientation(LinearLayout.HORIZONTAL); } else { row.removeAllViews(); } if (menuTitle != null) { menuTitle.setText(getResources().getStringArray(R.array.tr_preset_types)[mode]); } int[] presetValues = getPresetValues(mode); TypedArray keys = getResources().obtainTypedArray(R.array.tr_default_set_key); JSONObject parameters = defaultValuesToJSON(keys, presetValues); for (int i = 0; i < controls.size(); i++) { if (presetValues[i] == -1) continue; TaskRabbitSetListener set = controls.get(i); int arrayID = keys.getResourceId(i, 0); if (arrayID == R.string.tr_set_key_cost_in_cents || arrayID == R.string.tr_set_key_named_price) { if (row.getParent() == null) taskControls.addView(row); else { // View separator = getLayoutInflater().inflate(R.layout.tea_separator, row); // separator.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT)); } LinearLayout displayRow = (LinearLayout) ((TaskEditControlSet) set).getDisplayView(); LinearLayout.LayoutParams layoutParams = null; if (arrayID == R.string.tr_set_key_named_price) { layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1); displayRow.findViewById(R.id.display_row_body).setPadding(5, 0, 10, 0); displayRow.setMinimumWidth(130); } else { layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1); displayRow.findViewById(R.id.display_row_body).setPadding(10, 0, 5, 0); } row.addView(displayRow, layoutParams); } else if (arrayID == R.string.tr_set_key_description) { descriptionControls.addView(((TaskEditControlSet) set).getDisplayView()); } else { taskControls.addView(((TaskEditControlSet) set).getDisplayView()); } ((TaskRabbitSetListener) set).readFromModel(parameters, getString(arrayID), currentSelectedItem); } }
From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java
private void editPasswordDialog(final String oldPass) { mOldPassword = oldPass;/*from w w w . j ava 2 s .co m*/ LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER); int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding)); linearLayout.setPadding(padding, padding, padding, padding); final AppCompatEditText oldPassword = new AppCompatEditText(getActivity()); if (!oldPass.isEmpty()) { oldPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); oldPassword.setHint(getString(R.string.old_password)); linearLayout.addView(oldPassword); } final AppCompatEditText newPassword = new AppCompatEditText(getActivity()); newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); newPassword.setHint(getString(R.string.new_password)); linearLayout.addView(newPassword); final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity()); confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); confirmNewPassword.setHint(getString(R.string.confirm_new_password)); linearLayout.addView(confirmNewPassword); new Dialog(getActivity()).setView(linearLayout) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (!oldPass.isEmpty() && !oldPassword.getText().toString().equals(Utils.decodeString(oldPass))) { Utils.toast(getString(R.string.old_password_wrong), getActivity()); return; } if (newPassword.getText().toString().isEmpty()) { Utils.toast(getString(R.string.password_empty), getActivity()); return; } if (!newPassword.getText().toString().equals(confirmNewPassword.getText().toString())) { Utils.toast(getString(R.string.password_not_match), getActivity()); return; } if (newPassword.getText().toString().length() > 32) { Utils.toast(getString(R.string.password_too_long), getActivity()); return; } Prefs.saveString("password", Utils.encodeString(newPassword.getText().toString()), getActivity()); if (mFingerprint != null) { mFingerprint.setEnabled(true); } } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mOldPassword = null; } }).show(); }
From source file:com.facebook.android.friendsmash.ScoreboardFragment.java
private void populateScoreboard() { // Ensure all components are firstly removed from scoreboardContainer scoreboardContainer.removeAllViews(); // Ensure the progress spinner is hidden progressContainer.setVisibility(View.INVISIBLE); // Ensure scoreboardEntriesList is not null and not empty first if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) { closeAndShowError(getResources().getString(R.string.error_no_scores)); } else {// w w w . ja v a2 s .c o m // Iterate through scoreboardEntriesList, creating new UI elements for each entry int index = 0; Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator(); while (scoreboardEntriesIterator.hasNext()) { // Get the current scoreboard entry final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next(); // FrameLayout Container for the currentScoreboardEntry ... // Create and add a new FrameLayout to display the details of this entry FrameLayout frameLayout = new FrameLayout(getActivity()); scoreboardContainer.addView(frameLayout); // Set the attributes for this frameLayout int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin); frameLayout.setPadding(0, topPadding, 0, 0); // ImageView background image ... { // Create and add an ImageView for the background image to this entry ImageView backgroundImageView = new ImageView(getActivity()); frameLayout.addView(backgroundImageView); // Set the image of the backgroundImageView String uri = "drawable/scores_stub_even"; if (index % 2 != 0) { // Odd entry uri = "drawable/scores_stub_odd"; } int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName()); Drawable image = getResources().getDrawable(imageResource); backgroundImageView.setImageDrawable(image); // Other attributes of backgroundImageView to modify FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int backgroundImageViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top); backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0); backgroundImageViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry backgroundImageViewLayoutParams.gravity = Gravity.RIGHT; } backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams); } // ProfilePictureView of the current user ... { // Create and add a ProfilePictureView for the current user entry's profile picture ProfilePictureView profilePictureView = new ProfilePictureView(getActivity()); frameLayout.addView(profilePictureView); // Set the attributes of the profilePictureView int profilePictureViewWidth = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width); FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams( profilePictureViewWidth, profilePictureViewWidth); int profilePictureViewMarginLeft = 0; int profilePictureViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top); int profilePictureViewMarginRight = 0; int profilePictureViewMarginBottom = 0; if (index % 2 == 0) { profilePictureViewMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left); } else { profilePictureViewMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right); } profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft, profilePictureViewMarginTop, profilePictureViewMarginRight, profilePictureViewMarginBottom); profilePictureViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry profilePictureViewLayoutParams.gravity = Gravity.RIGHT; } profilePictureView.setLayoutParams(profilePictureViewLayoutParams); // Finally set the id of the user to show their profile pic profilePictureView.setProfileId(currentScoreboardEntry.getId()); } // LinearLayout to hold the text in this entry // Create and add a LinearLayout to hold the TextViews LinearLayout textViewsLinearLayout = new LinearLayout(getActivity()); frameLayout.addView(textViewsLinearLayout); // Set the attributes for this textViewsLinearLayout FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int textViewsLinearLayoutMarginLeft = 0; int textViewsLinearLayoutMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top); int textViewsLinearLayoutMarginRight = 0; int textViewsLinearLayoutMarginBottom = 0; if (index % 2 == 0) { textViewsLinearLayoutMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left); } else { textViewsLinearLayoutMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right); } textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft, textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight, textViewsLinearLayoutMarginBottom); textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT; } textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams); textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL); // TextView with the position and name of the current user { // Set the text that should go in this TextView first int position = index + 1; String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName(); // Create and add a TextView for the current user position and first name TextView titleTextView = new TextView(getActivity()); textViewsLinearLayout.addView(titleTextView); // Set the text and other attributes for this TextView titleTextView.setText(currentScoreboardEntryTitle); titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont); } // TextView with the score of the current user { // Create and add a TextView for the current user score TextView scoreTextView = new TextView(getActivity()); textViewsLinearLayout.addView(scoreTextView); // Set the text and other attributes for this TextView scoreTextView.setText("Score: " + currentScoreboardEntry.getScore()); scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont); } // Finally make this frameLayout clickable so that a game starts with the user smashing // the user represented by this frameLayout in the scoreContainer frameLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { Bundle bundle = new Bundle(); bundle.putString("user_id", currentScoreboardEntry.getId()); Intent i = new Intent(); i.putExtras(bundle); getActivity().setResult(Activity.RESULT_FIRST_USER, i); getActivity().finish(); return false; } else { return true; } } }); // Increment the index before looping back index++; } } }
From source file:com.citrus.sample.WalletPaymentFragment.java
private void showPrompt(final Utils.PaymentType paymentType) { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); String message = null;/*from w w w .ja v a 2 s . c o m*/ String positiveButtonText = null; switch (paymentType) { case LOAD_MONEY: case AUTO_LOAD_MONEY: message = "Please enter the amount to load."; positiveButtonText = "Load Money"; break; case CITRUS_CASH: case NEW_CITRUS_CASH: message = "Please enter the transaction amount."; positiveButtonText = "Pay"; break; case PG_PAYMENT: case NEW_PG_PAYMENT: case WALLET_PG_PAYMENT: message = "Please enter the transaction amount."; positiveButtonText = "Make Payment"; break; } LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); alert.setTitle("Transaction Amount?"); alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(getActivity()); input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); alert.setView(input); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); mListener.onPaymentTypeSelected(paymentType, new Amount(value)); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); input.requestFocus(); alert.show(); }
From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java
private void populateLayoutBlocks() { List<BlockContainerEntry> entries; try {// w w w . j av a 2s .co m Repository repository = Repository.getDefaultRepository(this); BlockContainer blocks = repository.getBlocks(); entries = blocks.getEntries(true); } catch (RepositoryException ex) { return; } LinearLayout layoutRow = null; for (BlockContainerEntry entry : entries) { View view = QuiltEditActivity.this.getLayoutInflater().inflate(R.layout.listentry_block_selector, null); ImageView image_thumbnail = (ImageView) view.findViewById(R.id.image_thumbnail); image_thumbnail.setImageBitmap(entry.getThumbnail()); view.setTag(entry.getBlockName()); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String blockName = (String) v.getTag(); try { getQuiltEditFragment().setBlock(blockName); } catch (Exception e) { Handle.asRuntimeError(e); } } }); if (m_layout_blocks.getOrientation() == LinearLayout.HORIZONTAL) { m_layout_blocks.addView(view); } else { if (layoutRow != null && layoutRow.getChildCount() == m_layout_blocks.getNumColumns()) { layoutRow = null; } if (layoutRow == null) { layoutRow = new LinearLayout(this); layoutRow.setOrientation(LinearLayout.HORIZONTAL); m_layout_blocks.addView(layoutRow); } layoutRow.addView(view); } } }