Search in sources :

Example 1 with ExtFilter

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();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) BrowserAdapter(com.foobnix.pdf.info.presentation.BrowserAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) ExtFilter(com.foobnix.pdf.info.ExtFilter) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) TextView(android.widget.TextView) File(java.io.File) TableLayout(android.widget.TableLayout) LinearLayout(android.widget.LinearLayout)

Example 2 with ExtFilter

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();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) BrowserAdapter(com.foobnix.pdf.info.presentation.BrowserAdapter) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) ExtFilter(com.foobnix.pdf.info.ExtFilter) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) File(java.io.File) TableLayout(android.widget.TableLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 AdapterView (android.widget.AdapterView)2 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)2 EditText (android.widget.EditText)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 ListView (android.widget.ListView)2 TableLayout (android.widget.TableLayout)2 TextView (android.widget.TextView)2 ExtFilter (com.foobnix.pdf.info.ExtFilter)2 BrowserAdapter (com.foobnix.pdf.info.presentation.BrowserAdapter)2 File (java.io.File)2