Search in sources :

Example 1 with LocalFileProvider

use of group.pals.android.lib.ui.filechooser.services.LocalFileProvider in project FBReaderJ by geometer.

the class FileChooserActivity method doCreateNewDir.

// doSwitchViewType()
/**
     * Confirms user to create new directory.
     */
private void doCreateNewDir() {
    if (mFileProvider instanceof LocalFileProvider && !Utils.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        Dlg.toast(this, R.string.afc_msg_app_doesnot_have_permission_to_create_files, Dlg._LengthShort);
        return;
    }
    if ((getLocation() instanceof File)) {
        if (!((File) getLocation()).canWrite()) {
            Dlg.toast(this, R.string.afc_msg_app_cant_create_folder, Dlg._LengthShort);
            return;
        }
    }
    final AlertDialog _dlg = Dlg.newDlg(this);
    View view = getLayoutInflater().inflate(R.layout.afc_simple_text_input_view, null);
    final EditText _textFile = (EditText) view.findViewById(R.id.afc_simple_text_input_view_text1);
    _textFile.setHint(mTextResources.get("folderNameHint"));
    _textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.hideSoftKeyboard(FileChooserActivity.this, _textFile.getWindowToken());
                _dlg.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });
    _dlg.setView(view);
    _dlg.setTitle(mTextResources.get("newFolder"));
    _dlg.setIcon(android.R.drawable.ic_menu_add);
    _dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String name = _textFile.getText().toString().trim();
            if (!FileUtils.isFilenameValid(name)) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_filename_is_invalid, name), Dlg._LengthShort);
                return;
            }
            final IFileProvider fileProvider = mFileProvider;
            final IFile location = getLocation();
            if (fileProvider == null || location == null) {
                return;
            }
            IFile dir = fileProvider.fromPath(String.format("%s/%s", location.getAbsolutePath(), name));
            if (dir.mkdir()) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_msg_done), Dlg._LengthShort);
                setLocation(getLocation(), null);
            } else
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_cannot_create_folder, name), Dlg._LengthShort);
        }
    });
    _dlg.show();
    final Button _btnOk = _dlg.getButton(DialogInterface.BUTTON_POSITIVE);
    _btnOk.setEnabled(false);
    _textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            _btnOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) IFileProvider(group.pals.android.lib.ui.filechooser.services.IFileProvider) IFile(group.pals.android.lib.ui.filechooser.io.IFile) DialogInterface(android.content.DialogInterface) LocalFileProvider(group.pals.android.lib.ui.filechooser.services.LocalFileProvider) GridView(android.widget.GridView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) IFile(group.pals.android.lib.ui.filechooser.io.IFile) File(java.io.File)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 GridView (android.widget.GridView)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 IFile (group.pals.android.lib.ui.filechooser.io.IFile)1 IFileProvider (group.pals.android.lib.ui.filechooser.services.IFileProvider)1 LocalFileProvider (group.pals.android.lib.ui.filechooser.services.LocalFileProvider)1 File (java.io.File)1