List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:com.wit.and.dialog.LoginDialog.java
/** * //w ww . j a v a 2 s . c om */ @Override protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = inflater.getContext(); RelativeLayout layout = new RelativeLayout(context); // Apply neutral layout params. layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Do not allow to apply style to body view. // layout.setId(R.id.Dialog_Layout_Body); // Create layout for loading view. LinearLayout loadingLayout = new LinearLayout(context); loadingLayout.setOrientation(LinearLayout.HORIZONTAL); loadingLayout.setGravity(Gravity.CENTER_VERTICAL); // Allow styling of loading layout as body layout. loadingLayout.setId(R.id.And_Dialog_Layout_Body); // Create text view for message. TextView msgTextView = new TextView(context); msgTextView.setId(R.id.And_Dialog_TextView_Message); // Create circle progress bar. ProgressBar circleProgressBar = new ProgressBar(context); circleProgressBar.setId(R.id.And_Dialog_ProgressBar); // Build loading view. loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.setVisibility(View.GONE); // Insert loading layout into main body layout. RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(loadingLayout, loadingLayoutParams); // Create layout for edit texts. LinearLayout editLayout = new LinearLayout(context); editLayout.setOrientation(LinearLayout.VERTICAL); editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView); // Create edit texts for username and password. EditText userEdit = new EditText(context); userEdit.setId(R.id.And_Dialog_EditText_Username); userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); EditText passEdit = new EditText(context); passEdit.setId(R.id.And_Dialog_EditText_Password); passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // Create edit texts divider. DialogDivider divider = new DialogDivider(context); divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts); // Build edit layout. editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); // Add custom layout. View customView = onCreateCustomView(inflater, editLayout, savedInstanceState); if (customView != null) { editLayout.addView(this.mCustomView = customView); } // Insert edit layout into main body layout. RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(editLayout, editLayoutParams); return layout; }
From source file:com.brq.wallet.activity.modern.AccountsFragment.java
private LinearLayout createActiveAccountBalanceSumView(CurrencySum spendableBalance) { LinearLayout outer = new LinearLayout(getActivity()); outer.setOrientation(LinearLayout.VERTICAL); outer.setLayoutParams(_outerLayoutParameters); LinearLayout inner = new LinearLayout(getActivity()); inner.setOrientation(LinearLayout.VERTICAL); inner.setLayoutParams(_innerLayoutParameters); inner.requestLayout();/*from ww w .j a va 2s . c o m*/ // Add records RecordRowBuilder builder = new RecordRowBuilder(_mbwManager, getResources(), _layoutInflater); // Add item View item = builder.buildTotalView(outer, spendableBalance); inner.addView(item); // Add separator inner.addView(createSeparator()); outer.addView(inner); return outer; }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override protected Dialog onCreateDialog(int id) { // Scan NFC Tag dialog, inflate image LayoutInflater factory = LayoutInflater.from(MainActivity.this); final View view = factory.inflate(R.layout.scan_tag_image, null); // Ask for tagTitle (tagName) in dialog final EditText tagTitle = new EditText(this); tagTitle.setHint(getResources().getString(R.string.set_tag_name_dialog_hint)); tagTitle.setSingleLine(true);//from w w w . j av a 2s .co m tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); // Set tagTitle maxLength int maxLength = 50; InputFilter[] array = new InputFilter[1]; array[0] = new InputFilter.LengthFilter(maxLength); tagTitle.setFilters(array); final LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); l.addView(tagTitle); // Dialog that shows scan tag image if (id == DIALOG_READ) { return new AlertDialog.Builder(this).setTitle(R.string.scan_tag_dialog_title).setView(view) .setCancelable(false) .setNeutralButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialogCancelled = true; killForegroundDispatch(); dialog.cancel(); } }).create(); } // Dialog that asks for tagName and stores it after 'Ok' pressed else if (id == DIALOG_SET_TAGNAME) { tagTitle.requestFocus(); return new AlertDialog.Builder(this).setTitle(R.string.set_tag_name_dialog_title).setView(l) .setCancelable(false) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONObject newTag = new JSONObject(); try { newTag.put("tagName", tagTitle.getText()); newTag.put("tagID", tagID); } catch (JSONException e) { e.printStackTrace(); } tags.put(newTag); writeToJSON(); adapter.notifyDataSetChanged(); updateListViewHeight(listView); if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_added, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); tagID = ""; tagTitle.setText(""); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { tagID = ""; tagTitle.setText(""); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); dialog.cancel(); } }).create(); } return null; }
From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java
/** * Called when the device configuration changes. *///from w w w .j a va 2 s .c o m @Override public void onConfigurationChanged(Configuration newConfig) { Log.d(LOG, LOG + ".onConfigurationChanged"); super.onConfigurationChanged(newConfig); // Signal to the Governor that a runtime change has occurred. governor.onRuntimeChange(); // Change the orientation of the PanelsLayout accordingly. LinearLayout panelsLayout = (LinearLayout) findViewById(R.id.PanelsLayout); if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { panelsLayout.setOrientation(LinearLayout.VERTICAL); } else { panelsLayout.setOrientation(LinearLayout.HORIZONTAL); } // Set the divider again, because it needs to be redrawn due to the orientation change. panelsLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_panels)); // Inform ActionBar Drawer Toggle of the change. actionBarDrawerToggle.onConfigurationChanged(newConfig); }
From source file:com.brq.wallet.activity.modern.AccountsFragment.java
private LinearLayout createAccountViewList(String title, List<WalletAccount> accounts, WalletAccount selectedAccount, CurrencySum spendableBalance) { LinearLayout outer = new LinearLayout(getActivity()); outer.setOrientation(LinearLayout.VERTICAL); outer.setLayoutParams(_outerLayoutParameters); // Add title//from w w w .ja v a 2s . c o m createTitle(outer, title, spendableBalance); if (accounts.isEmpty()) { return outer; } LinearLayout inner = new LinearLayout(getActivity()); inner.setOrientation(LinearLayout.VERTICAL); inner.setLayoutParams(_innerLayoutParameters); inner.requestLayout(); // // Add records RecordRowBuilder builder = new RecordRowBuilder(_mbwManager, getResources(), _layoutInflater); for (WalletAccount account : accounts) { // Add separator inner.addView(createSeparator()); // Add item boolean isSelected = account.equals(selectedAccount); View item = createAccountView(outer, account, isSelected, builder); inner.addView(item); } if (accounts.size() > 0) { // Add separator inner.addView(createSeparator()); } outer.addView(inner); return outer; }
From source file:com.example.drugsformarinemammals.Dose_Information.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dose_information); Bundle parameters = this.getIntent().getExtras(); if (parameters != null) { TextView textViewDrug = (TextView) findViewById(R.id.textView_drug_name); textViewDrug.setTypeface(Typeface.SANS_SERIF); textViewDrug.setText(parameters.getString("drugName")); TextView textViewGroupName = (TextView) findViewById(R.id.textView_group_name); textViewGroupName.setTypeface(Typeface.SANS_SERIF); textViewGroupName.setText("(" + parameters.getString("groupName") + ")"); layoutDose = (LinearLayout) findViewById(R.id.layout_dose); helper = new Handler_Sqlite(this); SQLiteDatabase db = helper.open(); ArrayList<String> notes_index = new ArrayList<String>(); ArrayList<String> references = new ArrayList<String>(); ArrayList<Article_Reference> references_index = new ArrayList<Article_Reference>(); reference_index = 'a'; ArrayList<String> families = new ArrayList<String>(); if (db != null) families = helper.read_animals_family(parameters.getString("drugName"), parameters.getString("groupName")); for (int l = 0; l < families.size(); l++) { //if exists animals family TextView textView_family = new TextView(this); textView_family.setText(families.get(l)); textView_family.setTextSize(20); textView_family.setTextColor(getResources().getColor(R.color.darkGray)); textView_family.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.leftMargin = 30;//from w w w. j a v a2s . c o m params.topMargin = 20; layoutDose.addView(textView_family, layoutDose.getChildCount(), params); //dose information LinearLayout layout_dose_information = new LinearLayout(this); layout_dose_information.setOrientation(LinearLayout.VERTICAL); layout_dose_information .setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); layout_dose_information.setBackgroundResource(R.drawable.layout_border); ArrayList<Dose_Data> dose = new ArrayList<Dose_Data>(); if (db != null) { dose = helper.read_dose_information(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "", ""); } TableLayout doseTable = new TableLayout(this); doseTable.setStretchAllColumns(true); screenWidth = Integer.parseInt(getString(R.string.display)); TableRow header = new TableRow(this); //Amount TextView textView_dose_amount = new TextView(this); textView_dose_amount.setText("Dose"); textView_dose_amount.setSingleLine(true); textView_dose_amount.setTextColor(getResources().getColor(R.color.darkGray)); textView_dose_amount.setTextSize(17); textView_dose_amount.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); TableRow.LayoutParams paramsAmount = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsAmount.gravity = Gravity.CENTER; header.addView(textView_dose_amount, paramsAmount); //Posology TextView textView_posology = new TextView(this); if (screenWidth >= 720) textView_posology.setText("Posology"); else textView_posology.setText("Pos"); textView_posology.setSingleLine(true); textView_posology.setTextColor(getResources().getColor(R.color.darkGray)); textView_posology.setTextSize(17); textView_posology.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); TableRow.LayoutParams paramsPosology = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsPosology.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology")) || screenWidth >= 600) header.addView(textView_posology, paramsPosology); //Route TextView textView_route = new TextView(this); textView_route.setText("Route"); textView_route.setSingleLine(true); textView_route.setTextColor(getResources().getColor(R.color.darkGray)); textView_route.setTextSize(17); textView_route.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); TableRow.LayoutParams paramsRoute = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsRoute.gravity = Gravity.CENTER; header.addView(textView_route, paramsRoute); //Reference TextView textView_reference = new TextView(this); textView_reference.setText("Ref"); textView_reference.setSingleLine(true); textView_reference.setTextColor(getResources().getColor(R.color.darkGray)); textView_reference.setTextSize(17); textView_reference.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); TableRow.LayoutParams paramsReference = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsReference.gravity = Gravity.CENTER; header.addView(textView_reference, paramsReference); //Specific Note TextView textView_specific_note = new TextView(this); textView_specific_note.setText("Note"); textView_specific_note.setSingleLine(true); textView_specific_note.setTextColor(getResources().getColor(R.color.darkGray)); textView_specific_note.setTextSize(17); textView_specific_note.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); TableRow.LayoutParams paramsSpecificNote = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsSpecificNote.gravity = Gravity.CENTER; if ((screenWidth < 600 && !isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note")) || screenWidth >= 600) header.addView(textView_specific_note, paramsSpecificNote); TableRow doseData = new TableRow(this); doseTable.addView(header); //General Dose if (dose.size() > 0) { show_dose(dose, doseTable, doseData, parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "", "", notes_index, references, references_index); } HashMap<String, ArrayList<String>> animal_information = new HashMap<String, ArrayList<String>>(); if (db != null) animal_information = helper.read_animal_information(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l)); String animalName; Object[] animalsName = animal_information.keySet().toArray(); for (int i = 0; i < animalsName.length; i++) { doseData = new TableRow(this); //if exists animal name animalName = (String) animalsName[i]; TextView textView_animal_name = new TextView(this); if (!animalName.equals("")) { //Animal name textView_animal_name.setText(animalName); textView_animal_name.setSingleLine(false); textView_animal_name.setTextColor(getResources().getColor(R.color.darkGray)); textView_animal_name.setTextSize(15); textView_animal_name.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); } //if exists category ArrayList<String> categories = animal_information.get(animalName); String animalCategory; for (int j = 0; j < categories.size(); j++) { animalCategory = categories.get(j); if (!animalCategory.equals("")) { //Animal category TextView textView_animal_category = new TextView(this); textView_animal_category.setText(animalCategory); textView_animal_category.setSingleLine(false); textView_animal_category.setTextColor(Color.BLACK); textView_animal_category.setTextSize(15); textView_animal_category.setTypeface(Typeface.SANS_SERIF); if (!animalName.equals("")) { if (j == 0) { TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); if (screenWidth < 600 && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note")) paramsAnimalName.span = 3; else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") || isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note"))) paramsAnimalName.span = 4; else paramsAnimalName.span = 5; doseData.addView(textView_animal_name, paramsAnimalName); doseTable.addView(doseData); } if (db != null) dose = helper.read_dose_information(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory); doseData = new TableRow(this); textView_animal_category.setTypeface(Typeface.SANS_SERIF, Typeface.ITALIC); TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); if (screenWidth < 600 && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note")) paramsCategoryName.span = 3; else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") || isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note"))) paramsCategoryName.span = 4; else paramsCategoryName.span = 5; if (screenWidth < 600) paramsCategoryName.leftMargin = 15; else if (screenWidth >= 600 && screenWidth < 720) paramsCategoryName.leftMargin = 20; else paramsCategoryName.leftMargin = 30; doseData.addView(textView_animal_category, paramsCategoryName); doseTable.addView(doseData); doseData = new TableRow(this); show_dose(dose, doseTable, doseData, parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory, notes_index, references, references_index); doseData = new TableRow(this); } else { if (db != null) dose = helper.read_dose_information(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory); textView_animal_category.setTypeface(Typeface.SANS_SERIF, Typeface.DEFAULT_BOLD.getStyle()); textView_animal_category.setTextColor(getResources().getColor(R.color.darkGray)); TableRow.LayoutParams paramsCategoryName = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); if (screenWidth < 600 && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note")) paramsCategoryName.span = 3; else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") || isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note"))) paramsCategoryName.span = 4; else paramsCategoryName.span = 5; doseData.addView(textView_animal_category, paramsCategoryName); doseTable.addView(doseData); doseData = new TableRow(this); show_dose(dose, doseTable, doseData, parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory, notes_index, references, references_index); doseData = new TableRow(this); } } if (!animalName.equals("") && animalCategory.equals("")) { if (db != null) dose = helper.read_dose_information(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory); TableRow.LayoutParams paramsAnimalName = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); if (screenWidth < 600 && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") && isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note")) paramsAnimalName.span = 3; else if (screenWidth < 600 && (isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Posology") || isCollapsed(parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), "Note"))) paramsAnimalName.span = 4; else paramsAnimalName.span = 5; doseData.addView(textView_animal_name, paramsAnimalName); doseTable.addView(doseData); doseData = new TableRow(this); show_dose(dose, doseTable, doseData, parameters.getString("drugName"), parameters.getString("groupName"), families.get(l), animalName, animalCategory, notes_index, references, references_index); doseData = new TableRow(this); } } } LinearLayout.LayoutParams paramsDoseTable = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (screenWidth >= 600) { paramsDoseTable.topMargin = 5; paramsDoseTable.leftMargin = 50; paramsDoseTable.rightMargin = 50; } else { paramsDoseTable.topMargin = 5; paramsDoseTable.leftMargin = 60; paramsDoseTable.rightMargin = 30; } layout_dose_information.addView(doseTable, paramsDoseTable); layoutDose.addView(layout_dose_information, layoutDose.getChildCount()); } helper.close(); //Notes additionalInformationInterface("GENERAL NOTES", parameters.getString("drugName"), parameters.getString("groupName"), notes_index, references_index); additionalInformationInterface("SPECIFIC NOTES", parameters.getString("drugName"), parameters.getString("groupName"), notes_index, references_index); //References additionalInformationInterface("REFERENCES", parameters.getString("drugName"), parameters.getString("groupName"), notes_index, references_index); } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_sort: return true; case R.id.menuSortNewest: sort = "New"; refreshComments();/*from w w w .j a v a 2 s . c o m*/ activity.invalidateOptionsMenu(); return true; case R.id.menuSortTop: sort = "Top"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.menuSortBest: sort = "Best"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.action_refresh: refreshComments(); return true; case R.id.action_submit: final EditText newGalleryTitle = new EditText(activity); newGalleryTitle.setHint("Title"); newGalleryTitle.setSingleLine(); new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove") .setView(newGalleryTitle) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newGalleryTitle.getText() == null) return; HashMap<String, Object> galleryMap = new HashMap<String, Object>(); galleryMap.put("terms", "1"); galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newGalleryTitle.getText().toString()); newGalleryString = newGalleryTitle.getText().toString(); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET, galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY); fetcher.execute(); } catch (Exception e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_edit: try { final EditText newTitle = new EditText(activity); newTitle.setSingleLine(); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_description); newTitle.setHint(R.string.body_hint_title); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newTitle); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView imageTitle = (TextView) imageLayoutView .findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView .findViewById(R.id.single_image_description); if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) { imageTitle.setText(newTitle.getText().toString()); imageTitle.setVisibility(View.VISIBLE); } else imageTitle.setVisibility(View.GONE); if (newBody.getText() != null && !newBody.getText().toString().equals("")) { imageDescription.setText(newBody.getText().toString()); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); HashMap<String, Object> editImageMap = new HashMap<String, Object>(); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString()); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION, newBody.getText().toString()); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST, editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(), EDITIMAGE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } catch (JSONException e) { Log.e("Error!", "oops, some image fields missing values" + e.toString()); } return true; case R.id.action_download: ImageUtils.downloadImage(this, imageData); return true; case R.id.action_delete: new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title) .setMessage(R.string.dialog_delete_confirmation_summary) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE, null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_copy: ImageUtils.copyImageURL(this, imageData); return true; case R.id.action_share: ImageUtils.shareImage(this, imageData); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.moonpi.tapunlock.MainActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { // Get pressed item information final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // If Rename Tag pressed if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) { // Create new EdiText and configure final EditText tagTitle = new EditText(this); tagTitle.setSingleLine(true);//from w ww .j a v a 2s .c o m tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); // Set tagTitle maxLength int maxLength = 50; InputFilter[] array = new InputFilter[1]; array[0] = new InputFilter.LengthFilter(maxLength); tagTitle.setFilters(array); // Get tagName text into EditText try { assert info != null; tagTitle.setText(tags.getJSONObject(info.position).getString("tagName")); } catch (JSONException e) { e.printStackTrace(); } final LinearLayout l = new LinearLayout(this); l.setOrientation(LinearLayout.VERTICAL); l.addView(tagTitle); // Show rename dialog new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l) .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 'Rename' pressed, change tagName and store try { JSONObject newTagName = tags.getJSONObject(info.position); newTagName.put("tagName", tagTitle.getText()); tags.put(info.position, newTagName); adapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed, Toast.LENGTH_SHORT); toast.show(); imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0); } }).show(); tagTitle.requestFocus(); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); return true; } // If Delete Tag pressed else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) { // Construct dialog message String dialogMessage = ""; assert info != null; try { dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '" + tags.getJSONObject(info.position).getString("tagName") + "'?"; } catch (JSONException e) { e.printStackTrace(); dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2); } // Show delete dialog new AlertDialog.Builder(this).setMessage(dialogMessage) .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONArray newArray = new JSONArray(); // Copy contents to new array, without the deleted item for (int i = 0; i < tags.length(); i++) { if (i != info.position) { try { newArray.put(tags.get(i)); } catch (JSONException e) { e.printStackTrace(); } } } // Equal original array to new array tags = newArray; // Write to file try { settings.put("tags", tags); root.put("settings", settings); } catch (JSONException e) { e.printStackTrace(); } writeToJSON(); adapter.adapterData = tags; adapter.notifyDataSetChanged(); updateListViewHeight(listView); // If no tags, show 'Press + to add Tags' textView if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted, Toast.LENGTH_SHORT); toast.show(); } }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing, close dialog } }).show(); return true; } return super.onContextItemSelected(item); }
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. j a v a 2s .c om 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.citrus.sample.WalletPaymentFragment.java
@OnClick(R.id.btnMasterpass) public void testMasterPass() { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); String message = null;/* w w w .j a va 2 s . c om*/ String positiveButtonText = null; message = "Please enter the transaction amount."; positiveButtonText = "Make Payment"; 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(); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); try { MasterPassOption masterPassOption = new MasterPassOption(); PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(new Amount(value), Constants.BILL_URL, masterPassOption, null); mCitrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() { @Override public void success(TransactionResponse transactionResponse) { Toast.makeText(getActivity(), transactionResponse.getMessage(), Toast.LENGTH_SHORT) .show(); } @Override public void error(CitrusError error) { Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); } catch (CitrusException e) { e.printStackTrace(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); input.requestFocus(); alert.show(); }