If you think the Android project turbo-editor listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014 Vlad Mihalachi/*www.java2s.com*/
*
* This file is part of Turbo Editor.
*
* Turbo Editor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Turbo Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package sharedcode.turboeditor.dialogfragment;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import sharedcode.turboeditor.R;
import sharedcode.turboeditor.views.DialogHelper;
// ...
publicclass EditTextDialog extends DialogFragment implements TextView.OnEditorActionListener {
private EditText mEditText;
publicstatic EditTextDialog newInstance(final Actions action) {
return EditTextDialog.newInstance(action, "");
}
publicstatic EditTextDialog newInstance(final Actions action, final String hint) {
final EditTextDialog f = new EditTextDialog();
final Bundle args = new Bundle();
args.putSerializable("action", action);
args.putString("hint", hint);
f.setArguments(args);
return f;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Actions action = (Actions) getArguments().getSerializable("action");
final String title;
switch (action) {
case NewFile:
title = getString(R.string.file);
break;
case NewFolder:
title = getString(R.string.folder);
break;
default:
title = null;
break;
}
View view = new DialogHelper.Builder(getActivity())
.setTitle(title)
.setView(R.layout.dialog_fragment_edittext)
.createSkeletonView();
this.mEditText = (EditText) view.findViewById(android.R.id.edit);
this.mEditText.setHint(R.string.name);
// Show soft keyboard automatically
this.mEditText.setText(getArguments().getString("hint"));
this.mEditText.requestFocus();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
this.mEditText.setOnEditorActionListener(this);
returnnew AlertDialog.Builder(getActivity())
.setView(view)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
publicvoid onClick(DialogInterface dialog, int which) {
returnData();
}
}
)
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
publicvoid onClick(DialogInterface dialog, int which) {
}
}
)
.create();
}
void returnData() {
EditDialogListener target = (EditDialogListener) getTargetFragment();
if (target == null) {
target = (EditDialogListener) getActivity();
}
target.onFinishEditDialog(this.mEditText.getText().toString(), getArguments().getString("hint"),
(Actions) getArguments().getSerializable("action"));
this.dismiss();
}
@Override
publicboolean onEditorAction(final TextView v, finalint actionId, final KeyEvent event) {
if (EditorInfo.IME_ACTION_DONE == actionId) {
returnData();
return true;
}
return false;
}
publicenum Actions {
NewFile, NewFolder
}
publicinterface EditDialogListener {
void onFinishEditDialog(String result, String hint, Actions action);
}
}