*/
@Override
public void onTextChanged(String newValue, List<String> currentFilterData) {
+ String value = newValue;
+
//Check if directory is valid
- if (newValue.length() == 0) {
+ if (value.length() == 0) {
if (this.mOnValidationListener != null) {
this.mOnValidationListener.onVoidValue();
}
} else {
- boolean relative = FileHelper.isRelativePath(newValue);
+ boolean relative = FileHelper.isRelativePath(value);
if (relative) {
if (this.mOnValidationListener != null) {
this.mOnValidationListener.onInvalidValue();
}
//Ensure data
- if (!newValue.startsWith(File.separator)) {
+ if (!value.startsWith(File.separator)) {
currentFilterData.clear();
this.mLastParent = ""; //$NON-NLS-1$
return;
}
- //Get the new parent, or exits if not is the parent
- String newParent = new File(newValue).getParent();
- if (newValue.compareTo(FileHelper.ROOT_DIRECTORY) == 0) {
+ //Get the new parent
+ String newParent = new File(value).getParent();
+ if (newParent == null) {
+ newParent = FileHelper.ROOT_DIRECTORY;
+ }
+ if (!newParent.endsWith(FileHelper.ROOT_DIRECTORY)) {
+ newParent += FileHelper.ROOT_DIRECTORY;
+ }
+ if (value.compareTo(FileHelper.ROOT_DIRECTORY) == 0) {
newParent = FileHelper.ROOT_DIRECTORY;
currentFilterData.clear();
- } else if (newValue.endsWith(FileHelper.ROOT_DIRECTORY)) {
+ } else if (value.endsWith(FileHelper.ROOT_DIRECTORY)) {
//Force the change of parent
- newParent = new File(newValue, "a").getParent(); //$NON-NLS-1$
+ newParent = new File(value, "a").getParent(); //$NON-NLS-1$
+ if (!newParent.endsWith(FileHelper.ROOT_DIRECTORY)) {
+ newParent += FileHelper.ROOT_DIRECTORY;
+ }
currentFilterData.clear();
+ } else {
+ value = newParent;
}
//If a new path is detected, then load the new data
- if (newParent != null
- && (newParent.compareTo(this.mLastParent) != 0 || currentFilterData.isEmpty())) {
+ if (newParent.compareTo(this.mLastParent) != 0 || currentFilterData.isEmpty()) {
this.mLastParent = newParent;
currentFilterData.clear();
try {
List<String> newData =
- CommandHelper.quickFolderSearch(getContext(), newValue, null);
+ CommandHelper.quickFolderSearch(getContext(), value, null);
currentFilterData.addAll(newData);
} catch (Throwable ex) {
Log.e(TAG, "Quick folder search failed", ex); //$NON-NLS-1$
private void doTab() {
//Complete with current text
String current = this.mForegroundText.getText().toString();
- String filter = this.mBackgroundText.getText().toString();
if (current.length() == 0) {
return;
}
- if (this.mCompletionString != null
- && current.endsWith(this.mCompletionString)) {
- if (this.mData.size() <= this.mFilter) {
- this.mFilter = 0;
- }
- if (this.mData.size() == 1 && this.mFilter == 0) {
- //Autocomplete with the only autocomplete option
- setText(this.mData.get(this.mFilter));
- } else {
- //Show the autocomplete options
- if (this.mData.size() > 0) {
- this.mBackgroundText.setText(this.mData.get(this.mFilter));
- this.mBackgroundText.setVisibility(View.VISIBLE);
- this.mFilter++;
- }
- }
+
+ //Get the data
+ List<String> filteredData = filter(this.mData, current);
+ if (filteredData.size() <= this.mFilter) {
+ this.mFilter = 0;
+ }
+ if (filteredData.size() == 1 && this.mFilter == 0) {
+ //Autocomplete with the only autocomplete option
+ setText(filteredData.get(this.mFilter));
} else {
- //Autocomplete
- if (filter != null && filter.length() > 0) {
- //Ensure that filter wraps the current text
- if (filter.startsWith(current)) {
- setText(filter);
- }
+ //Show the autocomplete options
+ if (filteredData.size() > 0) {
+ this.mBackgroundText.setText(filteredData.get(this.mFilter));
+ this.mBackgroundText.setVisibility(View.VISIBLE);
+ this.mFilter++;
+ }
+ }
+ }
+
+ /**
+ * Method that creates a temporary filter based in the current text
+ *
+ * @param data The global data array
+ * @param current The current text
+ * @return The filtered data array
+ */
+ private static List<String> filter(List<String> data, String current) {
+ List<String> filter = new ArrayList<String>(data);
+ int size = filter.size();
+ for (int i=size-1; i>=0; i--) {
+ String s = filter.get(i);
+ if (!s.startsWith(current)) {
+ filter.remove(i);
}
}
+ return filter;
}
/**