Open, download and cancel operations linked to contextual menu for files
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / dialog / EditNameDialog.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19
20 package com.owncloud.android.ui.dialog;
21
22 import android.os.Bundle;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.view.View.OnClickListener;
27 import android.view.WindowManager.LayoutParams;
28 import android.widget.Button;
29 import android.widget.TextView;
30
31 import com.actionbarsherlock.app.SherlockDialogFragment;
32 import com.owncloud.android.R;
33
34
35 /**
36 * Dialog to request the user about a certificate that could not be validated with the certificates store in the system.
37 *
38 * @author Bartek Przybylski
39 */
40 public class EditNameDialog extends SherlockDialogFragment implements OnClickListener {
41
42 private String mNewFilename;
43 private boolean mResult;
44 private EditNameDialogListener mListener;
45
46 static public EditNameDialog newInstance(String filename) {
47 EditNameDialog f = new EditNameDialog();
48 Bundle args = new Bundle();
49 args.putString("filename", filename);
50 f.setArguments(args);
51 return f;
52 }
53
54 @Override
55 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
56 View v = inflater.inflate(R.layout.edit_box_dialog, container, false);
57
58 String currentName = getArguments().getString("filename");
59 if (currentName == null)
60 currentName = "";
61
62 ((Button)v.findViewById(R.id.cancel)).setOnClickListener(this);
63 ((Button)v.findViewById(R.id.ok)).setOnClickListener(this);
64 ((TextView)v.findViewById(R.id.user_input)).setText(currentName);
65 ((TextView)v.findViewById(R.id.user_input)).requestFocus();
66 getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
67
68 mResult = false;
69 return v;
70 }
71
72 @Override
73 public void onClick(View view) {
74 switch (view.getId()) {
75 case R.id.ok: {
76 mNewFilename = ((TextView)getView().findViewById(R.id.user_input)).getText().toString();
77 mResult = true;
78 }
79 case R.id.cancel: { // fallthought
80 dismiss();
81 if (mListener != null)
82 mListener.onDismiss(this);
83 }
84 }
85 }
86
87 public void setOnDismissListener(EditNameDialogListener listener) {
88 mListener = listener;
89 }
90
91 public String getNewFilename() {
92 return mNewFilename;
93 }
94
95 // true if user clicked ok
96 public boolean getResult() {
97 return mResult;
98 }
99
100
101 public interface EditNameDialogListener {
102 public void onDismiss(EditNameDialog dialog);
103 }
104
105 }
106