SharePasswordDialogFragment.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * ownCloud Android client application
  3. * @author masensio
  4. * Copyright (C) 2015 ownCloud Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2,
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package com.owncloud.android.ui.dialog;
  20. import android.app.AlertDialog;
  21. import android.app.Dialog;
  22. import android.app.DialogFragment;
  23. import android.content.DialogInterface;
  24. import android.os.Bundle;
  25. import android.view.LayoutInflater;
  26. import android.view.View;
  27. import android.view.WindowManager;
  28. import android.widget.EditText;
  29. import android.widget.TextView;
  30. import android.widget.Toast;
  31. import com.actionbarsherlock.app.SherlockDialogFragment;
  32. import com.owncloud.android.R;
  33. import com.owncloud.android.datamodel.OCFile;
  34. /**
  35. * Dialog to input the password for sharing a file/folder.
  36. *
  37. * Triggers the share when the password is introduced.
  38. */
  39. public class SharePasswordDialogFragment extends SherlockDialogFragment
  40. implements DialogInterface.OnClickListener {
  41. public static final String PASSWORD_FRAGMENT = "PASSWORD_FRAGMENT";
  42. /**
  43. * Public factory method to create new SharePasswordDialogFragment instances.
  44. *
  45. * @param file File to share
  46. * @return Dialog ready to show.
  47. */
  48. public static SharePasswordDialogFragment newInstance(OCFile file) {
  49. SharePasswordDialogFragment frag = new SharePasswordDialogFragment();
  50. Bundle args = new Bundle();
  51. frag.setArguments(args);
  52. return frag;
  53. }
  54. @Override
  55. public Dialog onCreateDialog(Bundle savedInstanceState) {
  56. // Inflate the layout for the dialog
  57. LayoutInflater inflater = getActivity().getLayoutInflater();
  58. View v = inflater.inflate(R.layout.password_dialog, null);
  59. // Setup layout
  60. EditText inputText = ((EditText)v.findViewById(R.id.share_password));
  61. inputText.setText("");
  62. inputText.requestFocus();
  63. // Build the dialog
  64. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  65. builder.setView(v)
  66. .setPositiveButton(R.string.common_ok, this)
  67. .setNegativeButton(R.string.common_cancel, this)
  68. .setTitle(R.string.share_link_password_title);
  69. Dialog d = builder.create();
  70. d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
  71. return d;
  72. }
  73. @Override
  74. public void onClick(DialogInterface dialog, int which) {
  75. if (which == AlertDialog.BUTTON_POSITIVE) {
  76. String password =
  77. ((TextView)(getDialog().findViewById(R.id.share_password)))
  78. .getText().toString();
  79. if (password.length() <= 0) {
  80. Toast.makeText(
  81. getActivity(),
  82. R.string.share_link_empty_password,
  83. Toast.LENGTH_LONG).show();
  84. return;
  85. }
  86. // TODO
  87. // Share the file
  88. }
  89. }
  90. }