Example usage for android.text InputFilter InputFilter

List of usage examples for android.text InputFilter InputFilter

Introduction

In this page you can find the example usage for android.text InputFilter InputFilter.

Prototype

InputFilter

Source Link

Usage

From source file:org.odk.collect.android.activities.FormEntryActivity.java

/**
 * Creates a view given the View type and an event
 *
 * @param advancingPage -- true if this results from advancing through the form
 * @return newly created View//from w w  w . ja  v a2 s.  c o m
 */
private View createView(int event, boolean advancingPage) {
    FormController formController = Collect.getInstance().getFormController();

    if (hasHardwareMenu) {
        toolbar.setTitle(formController.getFormTitle());
    } else {
        setTitle(formController.getFormTitle());
    }

    switch (event) {
    case FormEntryController.EVENT_BEGINNING_OF_FORM:
        return createViewForFormBeginning(event, true, formController);

    case FormEntryController.EVENT_END_OF_FORM:
        View endView = View.inflate(this, R.layout.form_entry_end, null);
        ((TextView) endView.findViewById(R.id.description))
                .setText(getString(R.string.save_enter_data_description, formController.getFormTitle()));

        // checkbox for if finished or ready to send
        final CheckBox instanceComplete = ((CheckBox) endView.findViewById(R.id.mark_finished));
        instanceComplete.setChecked(isInstanceComplete(true));

        if (!adminPreferences.getBoolean(AdminKeys.KEY_MARK_AS_FINALIZED, true)) {
            instanceComplete.setVisibility(View.GONE);
        }

        // edittext to change the displayed name of the instance
        final EditText saveAs = (EditText) endView.findViewById(R.id.save_name);

        // disallow carriage returns in the name
        InputFilter returnFilter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    if (Character.getType((source.charAt(i))) == Character.CONTROL) {
                        return "";
                    }
                }
                return null;
            }
        };
        saveAs.setFilters(new InputFilter[] { returnFilter });

        String saveName = formController.getSubmissionMetadata().instanceName;
        if (saveName == null) {
            // no meta/instanceName field in the form -- see if we have a
            // name for this instance from a previous save attempt...
            if (getContentResolver().getType(getIntent().getData()) == InstanceColumns.CONTENT_ITEM_TYPE) {
                Uri instanceUri = getIntent().getData();
                Cursor instance = null;
                try {
                    instance = getContentResolver().query(instanceUri, null, null, null, null);
                    if (instance.getCount() == 1) {
                        instance.moveToFirst();
                        saveName = instance.getString(instance.getColumnIndex(InstanceColumns.DISPLAY_NAME));
                    }
                } finally {
                    if (instance != null) {
                        instance.close();
                    }
                }
            }
            if (saveName == null) {
                // last resort, default to the form title
                saveName = formController.getFormTitle();
            }
            // present the prompt to allow user to name the form
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.VISIBLE);
            saveAs.setText(saveName);
            saveAs.setEnabled(true);
            saveAs.setVisibility(View.VISIBLE);
        } else {
            // if instanceName is defined in form, this is the name -- no
            // revisions
            // display only the name, not the prompt, and disable edits
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
            saveAs.setText(saveName);
            saveAs.setEnabled(false);
            saveAs.setVisibility(View.VISIBLE);
        }

        // override the visibility settings based upon admin preferences
        if (!adminPreferences.getBoolean(AdminKeys.KEY_SAVE_AS, true)) {
            saveAs.setVisibility(View.GONE);
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
        }

        // Create 'save' button
        endView.findViewById(R.id.save_exit_button).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "createView.saveAndExit",
                        instanceComplete.isChecked() ? "saveAsComplete" : "saveIncomplete");
                // Form is marked as 'saved' here.
                if (saveAs.getText().length() < 1) {
                    ToastUtils.showShortToast(R.string.save_as_error);
                } else {
                    saveDataToDisk(EXIT, instanceComplete.isChecked(), saveAs.getText().toString());
                }
            }
        });

        if (showNavigationButtons) {
            backButton.setEnabled(true);
            nextButton.setEnabled(false);
        }

        return endView;
    case FormEntryController.EVENT_QUESTION:
    case FormEntryController.EVENT_GROUP:
    case FormEntryController.EVENT_REPEAT:
        ODKView odkv = null;
        // should only be a group here if the event_group is a field-list
        try {
            FormEntryPrompt[] prompts = formController.getQuestionPrompts();
            FormEntryCaption[] groups = formController.getGroupsForCurrentIndex();
            odkv = new ODKView(this, formController.getQuestionPrompts(), groups, advancingPage);
            Timber.i("Created view for group %s %s",
                    (groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]"),
                    (prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]"));
        } catch (RuntimeException e) {
            Timber.e(e);
            // this is badness to avoid a crash.
            try {
                event = formController.stepToNextScreenEvent();
                createErrorDialog(e.getMessage(), DO_NOT_EXIT);
            } catch (JavaRosaException e1) {
                Timber.e(e1);
                createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), DO_NOT_EXIT);
            }
            return createView(event, advancingPage);
        }

        // Makes a "clear answer" menu pop up on long-click
        for (QuestionWidget qw : odkv.getWidgets()) {
            if (!qw.getPrompt().isReadOnly()) {
                // If it's a StringWidget register all its elements apart from EditText as
                // we want to enable paste option after long click on the EditText
                if (qw instanceof StringWidget) {
                    for (int i = 0; i < qw.getChildCount(); i++) {
                        if (!(qw.getChildAt(i) instanceof EditText)) {
                            registerForContextMenu(qw.getChildAt(i));
                        }
                    }
                } else {
                    registerForContextMenu(qw);
                }
            }
        }

        if (showNavigationButtons) {
            adjustBackNavigationButtonVisibility();
            nextButton.setEnabled(true);
        }
        return odkv;

    case FormEntryController.EVENT_PROMPT_NEW_REPEAT:
        createRepeatDialog();
        return new EmptyView(this);

    default:
        Timber.e("Attempted to create a view that does not exist.");
        // this is badness to avoid a crash.
        try {
            event = formController.stepToNextScreenEvent();
            createErrorDialog(getString(R.string.survey_internal_error), EXIT);
        } catch (JavaRosaException e) {
            Timber.e(e);
            createErrorDialog(e.getCause().getMessage(), EXIT);
        }
        return createView(event, advancingPage);
    }
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Filter space EditText//from   www. ja v a  2s .  c  o m
 *
 * @return
 */
@NonNull
public static InputFilter inputFilter() {
    return new InputFilter() {
        @Override
        public CharSequence filter(CharSequence charSequence, int start, int end, Spanned spanned, int i2,
                int i3) {
            String filter = "";
            for (int k = start; k < end; k++) {
                char chz = charSequence.charAt(k);
                if (!Character.isWhitespace(chz)) {
                    filter += chz;
                }
            }
            return filter;
        }
    };
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void dynExport() {
    localfinished = false;/*from w  w  w  .  j a  v  a  2 s  .  c  o  m*/
    if (Globals.isMidi(currSongName) && Globals.isPlaying == 0) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(getResources().getString(R.string.dynex_alert1));
        alert.setMessage(getResources().getString(R.string.dynex_alert1_msg));
        InputFilter filter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                    if (IC.contains("*" + source.charAt(i) + "*")) {
                        return "";
                    }
                }
                return null;
            }
        };
        final EditText input = new EditText(this);
        input.setFilters(new InputFilter[] { filter });
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                if (!value.toLowerCase(Locale.US).endsWith(".wav"))
                    value += ".wav";
                String parent = currSongName.substring(0, currSongName.lastIndexOf('/') + 1);
                boolean alreadyExists = new File(parent + value).exists();
                boolean aWrite = true;
                String needRename = null;
                String probablyTheRoot = "";
                String probablyTheDirectory = "";
                try {
                    new FileOutputStream(parent + value, true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if (aWrite && !alreadyExists)
                    new File(parent + value).delete();

                if (aWrite && new File(parent).canWrite()) {
                    value = parent + value;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                    String[] tmp = Globals.getDocFilePaths(TimidityActivity.this, parent);
                    probablyTheDirectory = tmp[0];
                    probablyTheRoot = tmp[1];
                    if (probablyTheDirectory.length() > 1) {
                        needRename = parent
                                .substring(parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value;
                        value = probablyTheDirectory + '/' + value;
                    } else {
                        value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                    }
                } else {
                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                }
                final String finalval = value;
                final boolean canWrite = aWrite;
                final String needToRename = needRename;
                final String probRoot = probablyTheRoot;
                if (new File(finalval).exists()
                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                    AlertDialog dialog2 = new AlertDialog.Builder(TimidityActivity.this).create();
                    dialog2.setTitle(getResources().getString(R.string.warning));
                    dialog2.setMessage(getResources().getString(R.string.dynex_alert2_msg));
                    dialog2.setCancelable(false);
                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.yes),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {
                                    if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        if (needToRename != null) {
                                            Globals.tryToDeleteFile(TimidityActivity.this,
                                                    probRoot + needToRename);
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        } else {
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        }
                                    } else {
                                        new File(finalval).delete();
                                    }
                                    saveWavPart2(finalval, needToRename);
                                }
                            });
                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.no),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {

                                }
                            });
                    dialog2.show();
                } else {
                    saveWavPart2(finalval, needToRename);
                }

            }
        });

        alert.setNegativeButton(getResources().getString(R.string.cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        alerty = alert.show();

    }
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/**
 * Creates a view given the View type and an event
 *
 * @param event//w w w  .jav  a2s . c o m
 * @param advancingPage
 *            -- true if this results from advancing through the form
 * @return newly created View
 */
private View createView(int event, boolean advancingPage, int swipeCase) {
    FormController formController = Collect.getInstance().getFormController();
    /*   setTitle(getString(R.string.app_name) + " > "
    + formController.getFormTitle());*/
    int questioncount = formController.getFormDef().getDeepChildCount();

    switch (event) {
    case FormEntryController.EVENT_BEGINNING_OF_FORM:
        progressValue = 0.0;
        progressUpdate(progressValue, questioncount);
        View startView = View.inflate(this, R.layout.form_entry_start, null);
        /*setTitle(getString(R.string.app_name) + " > "
              + formController.getFormTitle());*/

        Drawable image = null;
        File mediaFolder = formController.getMediaFolder();
        String mediaDir = mediaFolder.getAbsolutePath();
        BitmapDrawable bitImage = null;
        // attempt to load the form-specific logo...
        // this is arbitrarily silly
        bitImage = new BitmapDrawable(getResources(), mediaDir + File.separator + "form_logo.png");

        if (bitImage != null && bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0
                && bitImage.getIntrinsicWidth() > 0) {
            image = bitImage;
        }

        if (image == null) {
            // show the opendatakit zig...
            // image =
            // getResources().getDrawable(R.drawable.opendatakit_zig);
            ((ImageView) startView.findViewById(R.id.form_start_bling)).setVisibility(View.GONE);
        } else {
            ImageView v = ((ImageView) startView.findViewById(R.id.form_start_bling));
            v.setImageDrawable(image);
            v.setContentDescription(formController.getFormTitle());
        }

        // change start screen based on navigation prefs
        String navigationChoice = PreferenceManager.getDefaultSharedPreferences(this)
                .getString(PreferencesActivity.KEY_NAVIGATION, PreferencesActivity.KEY_NAVIGATION);
        Boolean useSwipe = false;
        Boolean useButtons = false;
        ImageView ia = ((ImageView) startView.findViewById(R.id.image_advance));
        ImageView ib = ((ImageView) startView.findViewById(R.id.image_backup));
        TextView ta = ((TextView) startView.findViewById(R.id.text_advance));
        TextView tb = ((TextView) startView.findViewById(R.id.text_backup));
        TextView d = ((TextView) startView.findViewById(R.id.description));

        if (navigationChoice != null) {
            if (navigationChoice.contains(PreferencesActivity.NAVIGATION_SWIPE)) {
                useSwipe = true;
            }
            if (navigationChoice.contains(PreferencesActivity.NAVIGATION_BUTTONS)) {
                useButtons = true;
            }
        }
        if (useSwipe && !useButtons) {
            d.setText(getString(R.string.swipe_instructions, formController.getFormTitle()));
        } else if (useButtons && !useSwipe) {
            ia.setVisibility(View.GONE);
            ib.setVisibility(View.GONE);
            ta.setVisibility(View.GONE);
            tb.setVisibility(View.GONE);
            d.setText(getString(R.string.buttons_instructions, formController.getFormTitle()));
        } else {
            d.setText(getString(R.string.swipe_buttons_instructions, formController.getFormTitle()));
        }

        if (mBackButton.isShown()) {
            mBackButton.setEnabled(false);
        }
        if (mNextButton.isShown()) {
            mNextButton.setEnabled(true);
        }

        return startView;
    case FormEntryController.EVENT_END_OF_FORM:
        progressValue = questioncount;
        progressUpdate(progressValue, questioncount);
        View endView = View.inflate(this, R.layout.form_entry_end, null);

        ((ImageView) endView.findViewById(R.id.completed))
                .setImageDrawable(getResources().getDrawable(R.drawable.complete_tick));
        ((TextView) endView.findViewById(R.id.description))
                .setText(getString(R.string.save_enter_data_description, formController.getFormTitle()));

        // checkbox for if finished or ready to send
        final CheckBox instanceComplete = ((CheckBox) endView.findViewById(R.id.mark_finished));
        instanceComplete.setChecked(isInstanceComplete(true));

        if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_MARK_AS_FINALIZED, true)) {
            instanceComplete.setVisibility(View.GONE);
        }

        // edittext to change the displayed name of the instance
        final EditText saveAs = (EditText) endView.findViewById(R.id.save_name);

        // disallow carriage returns in the name
        InputFilter returnFilter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    if (Character.getType((source.charAt(i))) == Character.CONTROL) {
                        return "";
                    }
                }
                return null;
            }
        };
        saveAs.setFilters(new InputFilter[] { returnFilter });
        String saveName = getSaveName();

        if (saveName == null) {
            // no meta/instanceName field in the form -- see if we have a
            // name for this instance from a previous save attempt...
            if (getContentResolver().getType(getIntent().getData()) == InstanceColumns.CONTENT_ITEM_TYPE) {
                Uri instanceUri = getIntent().getData();
                Cursor instance = null;
                try {
                    instance = getContentResolver().query(instanceUri, null, null, null, null);
                    if (instance.getCount() == 1) {
                        instance.moveToFirst();
                        saveName = instance.getString(instance.getColumnIndex(InstanceColumns.DISPLAY_NAME));
                    }
                } finally {
                    if (instance != null) {
                        instance.close();
                    }
                }
            }
            if (saveName == null) {
                // last resort, default to the form title
                saveName = formController.getFormTitle();
            }
            // present the prompt to allow user to name the form
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.VISIBLE);
            saveAs.setText(saveName);
            saveAs.setEnabled(true);
            saveAs.setVisibility(View.VISIBLE);
        } else {
            // if instanceName is defined in form, this is the name -- no
            // revisions
            // display only the name, not the prompt, and disable edits
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
            saveAs.setText(saveName);
            saveAs.setEnabled(false);
            saveAs.setBackgroundColor(Color.WHITE);
            saveAs.setVisibility(View.VISIBLE);
        }

        // override the visibility settings based upon admin preferences
        if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_SAVE_AS, true)) {
            saveAs.setVisibility(View.GONE);
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
        }

        // Create 'save' button
        ((Button) endView.findViewById(R.id.save_exit_button)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "createView.saveAndExit",
                        instanceComplete.isChecked() ? "saveAsComplete" : "saveIncomplete");
                // Form is marked as 'saved' here.
                if (saveAs.getText().length() < 1) {
                    Toast.makeText(FormEntryActivity.this, R.string.save_as_error, Toast.LENGTH_SHORT).show();
                } else {
                    saveDataToDisk(EXIT, instanceComplete.isChecked(), saveAs.getText().toString());
                }
            }
        });

        if (mBackButton.isShown()) {
            mBackButton.setEnabled(true);
        }
        if (mNextButton.isShown()) {
            mNextButton.setEnabled(false);
        }

        return endView;
    case FormEntryController.EVENT_QUESTION:
    case FormEntryController.EVENT_GROUP:
    case FormEntryController.EVENT_REPEAT:
        ODKView odkv = null;
        // should only be a group here if the event_group is a field-list
        try {
            double depth = (double) formController.getFormIndex().getDepth();
            double local_index = (double) formController.getFormIndex().getLocalIndex();
            double instance_index = (double) formController.getFormIndex().getInstanceIndex();
            Log.i("Question coint", Integer.toString(questioncount));

            Log.i("Depth", Integer.toString(formController.getFormIndex().getDepth()));
            Log.i("Local Index", Integer.toString(formController.getFormIndex().getLocalIndex()));
            Log.i("Instance Index", Integer.toString(formController.getFormIndex().getInstanceIndex()));

            if (swipeCase == NEXT) {

                Log.i("progressValue", Double.toString(progressValue));

            }
            if (swipeCase == PREVIOUS) {
                progressValue = progressValue - (1 - (instance_index * local_index / questioncount * depth));

                Log.i("progressValue", Double.toString(progressValue));
            }
            Log.i("progressValue", Double.toString(progressValue));
            progressUpdate(progressValue, questioncount);
            FormEntryPrompt[] prompts = formController.getQuestionPrompts();
            FormEntryCaption[] groups = formController.getGroupsForCurrentIndex();
            odkv = new ODKView(this, formController.getQuestionPrompts(), groups, advancingPage);
            Log.i(t, "created view for group "
                    + (groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]") + " "
                    + (prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]"));
        } catch (RuntimeException e) {
            Log.e(t, e.getMessage(), e);
            // this is badness to avoid a crash.
            try {
                event = formController.stepToNextScreenEvent();
                createErrorDialog(e.getMessage(), DO_NOT_EXIT);
            } catch (JavaRosaException e1) {
                Log.e(t, e1.getMessage(), e1);
                createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), DO_NOT_EXIT);
            }
            return createView(event, advancingPage, swipeCase);
        }

        // Makes a "clear answer" menu pop up on long-click
        for (QuestionWidget qw : odkv.getWidgets()) {
            if (!qw.getPrompt().isReadOnly()) {
                registerForContextMenu(qw);
            }
        }

        if (mBackButton.isShown() && mNextButton.isShown()) {
            mBackButton.setEnabled(true);
            mNextButton.setEnabled(true);
        }
        return odkv;
    default:
        Log.e(t, "Attempted to create a view that does not exist.");
        // this is badness to avoid a crash.
        try {
            event = formController.stepToNextScreenEvent();
            createErrorDialog(getString(R.string.survey_internal_error), EXIT);
        } catch (JavaRosaException e) {
            Log.e(t, e.getMessage(), e);
            createErrorDialog(e.getCause().getMessage(), EXIT);
        }
        return createView(event, advancingPage, swipeCase);
    }

}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveCfg() {
    localfinished = false;// ww w . j  a va2 s . c  o  m
    if (Globals.isMidi(currSongName) && Globals.isPlaying == 0) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Save Cfg");
        alert.setMessage("Save a MIDI configuration file");
        InputFilter filter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                    if (IC.contains("*" + source.charAt(i) + "*")) {
                        return "";
                    }
                }
                return null;
            }
        };
        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        input.setFilters(new InputFilter[] { filter });
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                if (!value.toLowerCase(Locale.US).endsWith(Globals.compressCfg ? ".tzf" : ".tcf"))
                    value += (Globals.compressCfg ? ".tzf" : ".tcf");
                String parent = currSongName.substring(0, currSongName.lastIndexOf('/') + 1);
                boolean aWrite = true;
                boolean alreadyExists = new File(parent + value).exists();
                String needRename = null;
                String probablyTheRoot = "";
                String probablyTheDirectory = "";
                try {
                    new FileOutputStream(parent + value, true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (!alreadyExists && aWrite)
                    new File(parent + value).delete();
                if (aWrite && new File(parent).canWrite()) {
                    value = parent + value;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                    //TODO
                    // Write the file to getExternalFilesDir, then move it with the Uri
                    // We need to tell JNIHandler that movement is needed.

                    String[] tmp = Globals.getDocFilePaths(TimidityActivity.this, parent);
                    probablyTheDirectory = tmp[0];
                    probablyTheRoot = tmp[1];
                    if (probablyTheDirectory.length() > 1) {
                        needRename = parent
                                .substring(parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value;
                        value = probablyTheDirectory + '/' + value;
                    } else {
                        value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                        return;
                    }
                } else {
                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value;
                }
                final String finalval = value;
                final boolean canWrite = aWrite;
                final String needToRename = needRename;
                final String probRoot = probablyTheRoot;
                if (new File(finalval).exists()
                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                    AlertDialog dialog2 = new AlertDialog.Builder(TimidityActivity.this).create();
                    dialog2.setTitle("Warning");
                    dialog2.setMessage("Overwrite config file?");
                    dialog2.setCancelable(false);
                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                            getResources().getString(android.R.string.yes),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {
                                    if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        if (needToRename != null) {
                                            Globals.tryToDeleteFile(TimidityActivity.this,
                                                    probRoot + needToRename);
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        } else {
                                            Globals.tryToDeleteFile(TimidityActivity.this, finalval);
                                        }
                                    } else {
                                        new File(finalval).delete();
                                    }
                                    saveCfgPart2(finalval, needToRename);
                                }
                            });
                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                            getResources().getString(android.R.string.no),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int buttonId) {

                                }
                            });
                    dialog2.show();
                } else {
                    saveCfgPart2(finalval, needToRename);
                }
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                // Canceled.
            }
        });

        alerty = alert.show();
    }
}