Search in sources :

Example 1 with DialogAdapter

use of de.baumann.browser.View.DialogAdapter in project browser by scoute-dich.

the class HolderActivity method showHolderDialog.

private void showHolderDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(new NinjaContextWrapper(this));
    builder.setCancelable(true);
    @SuppressLint("InflateParams") NinjaRelativeLayout linearLayout = (NinjaRelativeLayout) getLayoutInflater().inflate(R.layout.main_home, null, false);
    builder.setView(linearLayout);
    String[] strings = getResources().getStringArray(R.array.holder_menu);
    List<String> list = new ArrayList<>();
    list.addAll(Arrays.asList(strings));
    ListView listView = linearLayout.findViewById(R.id.home_list);
    DialogAdapter adapter = new DialogAdapter(this, list);
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    final AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            HolderActivity.this.finish();
        }
    });
    dialog.show();
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch(position) {
                case 0:
                    Intent toActivity = new Intent(HolderActivity.this, BrowserActivity.class);
                    toActivity.putExtra(IntentUnit.OPEN, first.getURL());
                    startActivity(toActivity);
                    break;
                case 1:
                    BrowserUnit.copyURL(HolderActivity.this, first.getURL());
                    break;
                case 2:
                    IntentUnit.share(HolderActivity.this, first.getTitle(), first.getURL());
                    break;
                default:
                    break;
            }
            dialog.hide();
            dialog.dismiss();
            finish();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) NinjaContextWrapper(de.baumann.browser.View.NinjaContextWrapper) ListView(android.widget.ListView) NinjaRelativeLayout(de.baumann.browser.View.NinjaRelativeLayout) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView) DialogAdapter(de.baumann.browser.View.DialogAdapter)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 DialogAdapter (de.baumann.browser.View.DialogAdapter)1 NinjaContextWrapper (de.baumann.browser.View.NinjaContextWrapper)1 NinjaRelativeLayout (de.baumann.browser.View.NinjaRelativeLayout)1 ArrayList (java.util.ArrayList)1