use of com.foobnix.pdf.info.ExtFilter in project LibreraReader by foobnix.
the class PrefDialogs method selectFileDialog.
public static void selectFileDialog(final Context a, List<String> browseexts, File path, final com.foobnix.android.utils.ResultResponse<String> onChoose) {
final BrowserAdapter adapter = new BrowserAdapter(a, new ExtFilter(browseexts));
if (path.isFile()) {
String absolutePath = path.getAbsolutePath();
String filePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
adapter.setCurrentDirectory(new File(filePath));
} else {
adapter.setCurrentDirectory(path);
}
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.choose_);
final EditText text = new EditText(a);
text.setText(path.getName());
int p = Dips.dpToPx(5);
text.setPadding(p, p, p, p);
text.setSingleLine();
text.setEllipsize(TruncateAt.END);
text.setEnabled(true);
final TextView pathText = new TextView(a);
pathText.setText(path.getPath());
pathText.setPadding(p, p, p, p);
pathText.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
pathText.setTextSize(16);
pathText.setSingleLine();
pathText.setEllipsize(TruncateAt.END);
final ListView list = new ListView(a);
list.setMinimumHeight(1000);
list.setMinimumWidth(600);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final File file = new File(adapter.getItem(position).getPath());
if (file.isDirectory()) {
adapter.setCurrentDirectory(file);
pathText.setText(file.getPath());
list.setSelection(0);
} else {
text.setText(file.getName());
}
}
});
LinearLayout inflate = (LinearLayout) LayoutInflater.from(a).inflate(R.layout.frame_layout, null, false);
list.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
pathText.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f));
inflate.addView(pathText);
inflate.addView(list);
inflate.addView(text);
builder.setView(inflate);
builder.setPositiveButton(R.string.select, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
final AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = text.getText().toString();
if (name == null || name.trim().length() == 0) {
Toast.makeText(a, "Invalid File name", Toast.LENGTH_SHORT).show();
return;
}
File toFile = new File(adapter.getCurrentDirectory(), name);
onChoose.onResultRecive(toFile.getAbsolutePath());
dialog.dismiss();
}
});
}
use of com.foobnix.pdf.info.ExtFilter in project LibreraReader by foobnix.
the class PrefDialogs method imExDialog.
private void imExDialog(final Activity a, final int resSelectId, final String sampleName, final ResultResponse<File> onResult) {
List<String> browseexts = Arrays.asList(".json", ".txt", ".ttf", ".otf");
final BrowserAdapter adapter = new BrowserAdapter(a, new ExtFilter(browseexts));
adapter.setCurrentDirectory(new File(getLastPath()));
final AlertDialog.Builder builder = new AlertDialog.Builder(a);
builder.setTitle(R.string.choose_);
final EditText text = new EditText(a);
text.setText(sampleName);
int p = Dips.dpToPx(5);
text.setPadding(p, p, p, p);
text.setSingleLine();
text.setEllipsize(TruncateAt.END);
if (resSelectId == R.string.export_) {
text.setEnabled(true);
} else {
text.setEnabled(false);
}
final TextView pathText = new TextView(a);
pathText.setText(new File(getLastPath()).toString());
pathText.setPadding(p, p, p, p);
pathText.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
pathText.setTextSize(16);
pathText.setSingleLine();
pathText.setEllipsize(TruncateAt.END);
final ListView list = new ListView(a);
list.setMinimumHeight(1000);
list.setMinimumWidth(600);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final File file = new File(adapter.getItem(position).getPath());
if (file.isDirectory()) {
lastPaht = file.getPath();
adapter.setCurrentDirectory(file);
pathText.setText(file.getPath());
list.setSelection(0);
} else {
pathText.setText(file.getName());
}
}
});
LinearLayout inflate = (LinearLayout) LayoutInflater.from(a).inflate(R.layout.frame_layout, null, false);
list.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
pathText.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f));
ImageView home = new ImageView(a);
home.setImageResource(R.drawable.glyphicons_21_home);
TintUtil.setTintImageWithAlpha(home);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final File file = Environment.getExternalStorageDirectory();
if (file.isDirectory()) {
lastPaht = file.getPath();
adapter.setCurrentDirectory(file);
pathText.setText(file.getPath());
list.setSelection(0);
} else {
pathText.setText(file.getName());
}
}
});
inflate.addView(home);
inflate.addView(pathText);
inflate.addView(list);
inflate.addView(text);
builder.setView(inflate);
builder.setPositiveButton(resSelectId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
File toFile = null;
if (resSelectId == R.string.export_) {
toFile = new File(lastPaht, text.getText().toString());
} else {
toFile = new File(lastPaht, pathText.getText().toString());
}
onResult.onResultRecive(toFile);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
Aggregations