Merge "Improve keyboard control of "create folder" action."
This commit is contained in:
@@ -180,7 +180,7 @@ abstract class BaseActivity extends Activity {
|
||||
onBackPressed();
|
||||
return true;
|
||||
} else if (id == R.id.menu_create_dir) {
|
||||
CreateDirectoryFragment.show(getFragmentManager());
|
||||
showCreateDirectoryDialog();
|
||||
return true;
|
||||
} else if (id == R.id.menu_search) {
|
||||
return false;
|
||||
@@ -217,6 +217,23 @@ abstract class BaseActivity extends Activity {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
void showCreateDirectoryDialog() {
|
||||
CreateDirectoryFragment.show(getFragmentManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a directory can be created in the current location.
|
||||
* @return
|
||||
*/
|
||||
boolean canCreateDirectory() {
|
||||
final RootInfo root = getCurrentRoot();
|
||||
final DocumentInfo cwd = getCurrentDirectory();
|
||||
return cwd != null
|
||||
&& cwd.isCreateSupported()
|
||||
&& !mSearchManager.isSearching()
|
||||
&& !root.isDownloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this when directory changes. Prior to root fragment update
|
||||
* the (abstract) directoryChanged method will be called.
|
||||
|
||||
@@ -33,9 +33,13 @@ import android.os.Bundle;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsContract.Document;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
@@ -64,26 +68,47 @@ public class CreateDirectoryFragment extends DialogFragment {
|
||||
final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
|
||||
|
||||
final View view = dialogInflater.inflate(R.layout.dialog_create_dir, null, false);
|
||||
final EditText text1 = (EditText) view.findViewById(android.R.id.text1);
|
||||
final EditText editText = (EditText) view.findViewById(android.R.id.text1);
|
||||
|
||||
builder.setTitle(R.string.menu_create_dir);
|
||||
builder.setView(view);
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final String displayName = text1.getText().toString();
|
||||
builder.setPositiveButton(
|
||||
android.R.string.ok,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
createDirectory(editText.getText().toString());
|
||||
}
|
||||
});
|
||||
|
||||
final BaseActivity activity = (BaseActivity) getActivity();
|
||||
final DocumentInfo cwd = activity.getCurrentDirectory();
|
||||
|
||||
new CreateDirectoryTask(activity, cwd, displayName).executeOnExecutor(
|
||||
ProviderExecutor.forAuthority(cwd.authority));
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
final AlertDialog dialog = builder.create();
|
||||
|
||||
return builder.create();
|
||||
editText.setOnEditorActionListener(
|
||||
new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|
||||
&& event.hasNoModifiers()) {
|
||||
createDirectory(editText.getText().toString());
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void createDirectory(String name) {
|
||||
final BaseActivity activity = (BaseActivity) getActivity();
|
||||
final DocumentInfo cwd = activity.getCurrentDirectory();
|
||||
|
||||
new CreateDirectoryTask(activity, cwd, name).executeOnExecutor(
|
||||
ProviderExecutor.forAuthority(cwd.authority));
|
||||
}
|
||||
|
||||
private class CreateDirectoryTask extends AsyncTask<Void, Void, DocumentInfo> {
|
||||
|
||||
@@ -195,23 +195,19 @@ public class StandaloneActivity extends BaseActivity {
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
boolean shown = super.onPrepareOptionsMenu(menu);
|
||||
|
||||
final RootInfo root = getCurrentRoot();
|
||||
final DocumentInfo cwd = getCurrentDirectory();
|
||||
|
||||
final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
|
||||
final MenuItem advanced = menu.findItem(R.id.menu_advanced);
|
||||
final MenuItem fileSize = menu.findItem(R.id.menu_file_size);
|
||||
final MenuItem settings = menu.findItem(R.id.menu_settings);
|
||||
|
||||
createDir.setVisible(cwd != null
|
||||
&& cwd.isCreateSupported()
|
||||
&& !mSearchManager.isSearching()
|
||||
&& !root.isDownloads());
|
||||
boolean canCreateDir = canCreateDirectory();
|
||||
|
||||
createDir.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
createDir.setVisible(canCreateDir);
|
||||
|
||||
fileSize.setVisible(true);
|
||||
advanced.setVisible(true);
|
||||
settings.setVisible((root.flags & Root.FLAG_HAS_SETTINGS) != 0);
|
||||
settings.setVisible((getCurrentRoot().flags & Root.FLAG_HAS_SETTINGS) != 0);
|
||||
|
||||
return shown;
|
||||
}
|
||||
@@ -301,13 +297,18 @@ public class StandaloneActivity extends BaseActivity {
|
||||
dir = DirectoryFragment.get(getFragmentManager());
|
||||
dir.copyToClipboard();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_N:
|
||||
if (event.isShiftPressed() && canCreateDirectory()) {
|
||||
showCreateDirectoryDialog();
|
||||
return true;
|
||||
}
|
||||
case KeyEvent.KEYCODE_V:
|
||||
dir = DirectoryFragment.get(getFragmentManager());
|
||||
dir.pasteFromClipboard();
|
||||
return true;
|
||||
default:
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user