Fixed update of right fragment when actions in the context menu of the left fragment...
[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 public static final String TAG = EditNameDialog.class.getSimpleName();
43
44 private String mNewFilename;
45 private boolean mResult;
46 private EditNameDialogListener mListener;
47
48 static public EditNameDialog newInstance(String filename) {
49 EditNameDialog f = new EditNameDialog();
50 Bundle args = new Bundle();
51 args.putString("filename", filename);
52 f.setArguments(args);
53 return f;
54 }
55
56 @Override
57 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
58 View v = inflater.inflate(R.layout.edit_box_dialog, container, false);
59
60 String currentName = getArguments().getString("filename");
61 if (currentName == null)
62 currentName = "";
63
64 ((Button)v.findViewById(R.id.cancel)).setOnClickListener(this);
65 ((Button)v.findViewById(R.id.ok)).setOnClickListener(this);
66 ((TextView)v.findViewById(R.id.user_input)).setText(currentName);
67 ((TextView)v.findViewById(R.id.user_input)).requestFocus();
68 getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
69
70 mResult = false;
71 return v;
72 }
73
74 @Override
75 public void onClick(View view) {
76 switch (view.getId()) {
77 case R.id.ok: {
78 mNewFilename = ((TextView)getView().findViewById(R.id.user_input)).getText().toString();
79 mResult = true;
80 }
81 case R.id.cancel: { // fallthought
82 dismiss();
83 if (mListener != null)
84 mListener.onDismiss(this);
85 }
86 }
87 }
88
89 public void setOnDismissListener(EditNameDialogListener listener) {
90 mListener = listener;
91 }
92
93 public String getNewFilename() {
94 return mNewFilename;
95 }
96
97 // true if user clicked ok
98 public boolean getResult() {
99 return mResult;
100 }
101
102
103 public interface EditNameDialogListener {
104 public void onDismiss(EditNameDialog dialog);
105 }
106
107 }
108