Search in sources :

Example 86 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project LibreraReader by foobnix.

the class DialogTranslateFromTo method show.

public static AlertDialog show(final Activity a, final Runnable runnable) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(a);
    alertDialog.setTitle(R.string.remember_dictionary);
    View body = LayoutInflater.from(a).inflate(R.layout.dialog_translate_from_to, null, false);
    final Spinner spinnerFrom = (Spinner) body.findViewById(R.id.spinnerFrom);
    final Spinner spinnerTo = (Spinner) body.findViewById(R.id.spinnerTo);
    ImageView imageOk = (ImageView) body.findViewById(R.id.imageOK);
    final List<String> langNames = new ArrayList<String>(langs.keySet());
    final List<String> langCodes = new ArrayList<String>(langs.values());
    spinnerFrom.setAdapter(new BaseItemLayoutAdapter<String>(a, android.R.layout.simple_spinner_dropdown_item, langNames) {

        @Override
        public void populateView(View inflate, int arg1, String value) {
            Views.text(inflate, android.R.id.text1, "" + value);
        }
    });
    spinnerFrom.setSelection(langCodes.indexOf(AppState.get().fromLang));
    spinnerTo.setAdapter(new BaseItemLayoutAdapter<String>(a, android.R.layout.simple_spinner_dropdown_item, langNames) {

        @Override
        public void populateView(View inflate, int arg1, String value) {
            Views.text(inflate, android.R.id.text1, "" + value);
        }
    });
    spinnerTo.setSelection(langCodes.indexOf(AppState.get().toLang));
    final ListView dictSpinner = (ListView) body.findViewById(R.id.dictionaries);
    final List<DictItem> list = DictsHelper.getAllResolveInfoAsDictItem1(a, "");
    list.addAll(DictsHelper.getOnlineDicts(a, ""));
    dictSpinner.setAdapter(new BaseItemLayoutAdapter<DictItem>(a, R.layout.item_dict_line, list) {

        @Override
        public void populateView(View layout, int position, DictItem item) {
            ((TextView) layout.findViewById(R.id.text1)).setText(item.name);
            ((TextView) layout.findViewById(R.id.type1)).setText(item.type);
            if (item.image == null) {
                ((ImageView) layout.findViewById(R.id.image1)).setImageResource(R.drawable.web);
            } else {
                ((ImageView) layout.findViewById(R.id.image1)).setImageDrawable(item.image);
            }
        }
    });
    body.findViewById(R.id.onReverse).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int p1 = spinnerFrom.getSelectedItemPosition();
            int p2 = spinnerTo.getSelectedItemPosition();
            spinnerTo.setSelection(p1);
            spinnerFrom.setSelection(p2);
        }
    });
    alertDialog.setView(body);
    alertDialog.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    final AlertDialog show = alertDialog.show();
    dictSpinner.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AppState.get().rememberDict = list.get(position).toString();
            AppState.get().fromLang = langCodes.get(spinnerFrom.getSelectedItemPosition());
            AppState.get().toLang = langCodes.get(spinnerTo.getSelectedItemPosition());
            try {
                show.dismiss();
            } catch (Exception e) {
            }
            runnable.run();
        }
    });
    imageOk.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AppState.get().fromLang = langCodes.get(spinnerFrom.getSelectedItemPosition());
            AppState.get().toLang = langCodes.get(spinnerTo.getSelectedItemPosition());
            try {
                show.dismiss();
            } catch (Exception e) {
            }
        }
    });
    return show;
}
Also used : AlertDialog(android.app.AlertDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) 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) DictItem(com.foobnix.pdf.info.DictsHelper.DictItem) ImageView(android.widget.ImageView)

Example 87 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project LibreraReader by foobnix.

the class ZipDialog method getDialogContent.

public static View getDialogContent(final Activity a, final Uri uri, final Runnable onDismiss) {
    final List<String> items = new ArrayList<String>();
    BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(a, R.layout.zip_item, items) {

        @Override
        public void populateView(View layout, int position, String item) {
            TextView text = (TextView) layout.findViewById(R.id.text1);
            text.setText(item);
        }
    };
    ListView list = new ListView(a);
    try {
        InputStream openInputStream = getStream(a, uri);
        ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(openInputStream, CP1251, true);
        ZipArchiveEntry nextEntry = null;
        while ((nextEntry = zipInputStream.getNextZipEntry()) != null) {
            String nameFull = nextEntry.getName();
            LOG.d(nameFull);
            if (!nextEntry.isDirectory()) {
                items.add(nameFull);
            }
        }
        zipInputStream.close();
        openInputStream.close();
    } catch (Exception e) {
        LOG.e(e);
    }
    list.setAdapter(adapter);
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            String name = items.get(position);
            extractAsyncProccess(a, name, uri, onDismiss, false);
        }
    });
    adapter.notifyDataSetChanged();
    return list;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) FileInputStream(java.io.FileInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) TextView(android.widget.TextView) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 88 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project PhoneProfilesPlus by henrichg.

the class LocationGeofencePreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    if (onlyEdit == 0) {
        String value = "";
        value = getPersistedString(value);
        DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence(value, 1);
    }
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_location_pref_dialog, false).dividerColor(0);
    if (onlyEdit == 0) {
        mBuilder.positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText());
        mBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                persistGeofence(false);
                mDialog.dismiss();
            }
        });
        mBuilder.onNegative(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                mDialog.dismiss();
            }
        });
    } else {
        mBuilder.positiveText(getPositiveButtonText());
        mBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                mDialog.dismiss();
            }
        });
    }
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // progressLinearLayout = layout.findViewById(R.id.location_pref_dlg_linla_progress);
    // dataRelativeLayout = layout.findViewById(R.id.location_pref_dlg_rella_data);
    // geofenceName = layout.findViewById(R.id.location_pref_dlg_geofence_name);
    // updateGUIWithGeofence(dataWrapper.getDatabaseHandler().getCheckedGeofences());
    // noinspection ConstantConditions
    AppCompatImageButton addButton = layout.findViewById(R.id.location_pref_dlg_add);
    // noinspection ConstantConditions
    ListView geofencesListView = layout.findViewById(R.id.location_pref_dlg_listview);
    listAdapter = new LocationGeofencesPreferenceAdapter(context, DatabaseHandler.getInstance(context.getApplicationContext()).getGeofencesCursor(), this);
    geofencesListView.setAdapter(listAdapter);
    refreshListView();
    geofencesListView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            LocationGeofencesPreferenceAdapter.ViewHolder viewHolder = (LocationGeofencesPreferenceAdapter.ViewHolder) v.getTag();
            /*
                if (listAdapter.selectedRB != null){
                    long gid = (long)listAdapter.selectedRB.getTag();
                    Log.d("LocationGeofencePreference.onItemClick", "checked id="+gid);
                    listAdapter.selectedRB.setChecked(false);
                }
                */
            // listAdapter.selectedRB = viewHolder.radioButton;
            long gid = viewHolder.geofenceId;
            if (onlyEdit == 0) {
                DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence(String.valueOf(gid), 2);
                // viewHolder.radioButton.setChecked(true);
                // updateGUIWithGeofence(gid);
                refreshListView();
            } else {
                startEditor(gid);
            }
        }
    });
    /*
        final TextView helpText = layout.findViewById(R.id.wifi_ssid_pref_dlg_helpText);
        String helpString = context.getString(R.string.pref_dlg_info_about_wildcards_1) + " " +
                            context.getString(R.string.pref_dlg_info_about_wildcards_2) + " " +
                            context.getString(R.string.wifi_ssid_pref_dlg_info_about_wildcards) + " " +
                            context.getString(R.string.pref_dlg_info_about_wildcards_3);
        helpText.setText(helpString);

        ImageView helpIcon = layout.findViewById(R.id.wifi_ssid_pref_dlg_helpIcon);
        helpIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int visibility = helpText.getVisibility();
                if (visibility == View.VISIBLE)
                    visibility = View.GONE;
                else
                    visibility = View.VISIBLE;
                helpText.setVisibility(visibility);
            }
        });
        */
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startEditor(0);
        }
    });
    final Button unselectAllButton = layout.findViewById(R.id.location_pref_dlg_uselectAll);
    unselectAllButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence("", 0);
            refreshListView();
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) AppCompatImageButton(android.support.v7.widget.AppCompatImageButton) Button(android.widget.Button) DialogAction(com.afollestad.materialdialogs.DialogAction)

Example 89 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project PhoneProfilesPlus by henrichg.

the class NFCTagPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    value = getPersistedString(value);
    MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_nfc_tag_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            if (shouldPersist()) {
                if (callChangeListener(value)) {
                    persistString(value);
                }
            }
            mDialog.dismiss();
        }
    }).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
            mDialog.dismiss();
        }
    });
    mDialog = mBuilder.build();
    View layout = mDialog.getCustomView();
    // progressLinearLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_linla_progress);
    // dataRelativeLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_rella_data);
    // noinspection ConstantConditions
    addIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_addIcon);
    addIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = nfcTagName.getText().toString();
            addNfcTag(tag);
            DatabaseHandler.getInstance(context).addNFCTag(tag);
            refreshListView(tag);
        }
    });
    // noinspection ConstantConditions
    nfcTagName = layout.findViewById(R.id.nfc_tag_pref_dlg_bt_name);
    nfcTagName.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
        }
    });
    GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
    nfcTagListView = layout.findViewById(R.id.nfc_tag_pref_dlg_listview);
    listAdapter = new NFCTagPreferenceAdapter(context, this);
    nfcTagListView.setAdapter(listAdapter);
    refreshListView("");
    nfcTagListView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // NFCTagPreferenceAdapter.ViewHolder viewHolder =
            // (NFCTagPreferenceAdapter.ViewHolder) v.getTag();
            String nfcTag = nfcTagList.get(position).name;
            nfcTagName.setText(nfcTag);
        }
    });
    /*
        final TextView helpText = layout.findViewById(R.id.nfc_tag_pref_dlg_helpText);
        final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
        ApplicationPreferences.getSharedPreferences(context);
        if (ApplicationPreferences.preferences.getBoolean(PREF_SHOW_HELP, true)) {
            helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
            helpText.setVisibility(View.VISIBLE);
        }
        else {
            helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
            helpText.setVisibility(View.GONE);
        }
        helpIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ApplicationPreferences.getSharedPreferences(context);
                SharedPreferences.Editor editor = ApplicationPreferences.preferences.edit();
                int visibility = helpText.getVisibility();
                if (visibility == View.VISIBLE) {
                    helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
                    visibility = View.GONE;
                    editor.putBoolean(PREF_SHOW_HELP, false);
                }
                else {
                    helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
                    visibility = View.VISIBLE;
                    editor.putBoolean(PREF_SHOW_HELP, true);
                }
                helpText.setVisibility(visibility);
                editor.apply();
            }
        });
        */
    final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
    helpIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogHelpPopupWindow.showPopup(helpIcon, context, R.string.nfc_tag_pref_dlg_help);
        }
    });
    ImageView changeSelectionIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_changeSelection);
    changeSelectionIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSelectorDialog = new MaterialDialog.Builder(context).title(R.string.pref_dlg_change_selection_title).items(R.array.nfcTagsChangeSelectionArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    switch(which) {
                        case 0:
                            value = "";
                            break;
                        case 1:
                            for (NFCTagData nfcTag : nfcTagList) {
                                if (nfcTag.name.equals(nfcTagName.getText().toString()))
                                    addNfcTag(nfcTag.name);
                            }
                            break;
                        default:
                    }
                    refreshListView("");
                    return true;
                }
            }).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
        }
    });
    GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.setOnDismissListener(this);
    mDialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ImageView(android.widget.ImageView)

Example 90 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project PhoneProfilesPlus by henrichg.

the class ActivateProfileListFragment method doOnViewCreated.

private void doOnViewCreated(View view) /*, Bundle savedInstanceState*/
{
    activeProfileName = view.findViewById(R.id.act_prof_activated_profile_name);
    activeProfileIcon = view.findViewById(R.id.act_prof_activated_profile_icon);
    if (!ApplicationPreferences.applicationActivatorGridLayout(activityDataWrapper.context))
        listView = view.findViewById(R.id.act_prof_profiles_list);
    else
        gridView = view.findViewById(R.id.act_prof_profiles_grid);
    textViewNoData = view.findViewById(R.id.act_prof_list_empty);
    progressBar = view.findViewById(R.id.act_prof_list_linla_progress);
    AbsListView absListView;
    if (!ApplicationPreferences.applicationActivatorGridLayout(activityDataWrapper.context))
        absListView = listView;
    else
        absListView = gridView;
    // absListView.setLongClickable(false);
    absListView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!ApplicationPreferences.applicationLongClickActivation(activityDataWrapper.context))
                // activateProfileWithAlert(position);
                activateProfile((Profile) profileListAdapter.getItem(position));
        }
    });
    absListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (ApplicationPreferences.applicationLongClickActivation(activityDataWrapper.context))
                // activateProfileWithAlert(position);
                activateProfile((Profile) profileListAdapter.getItem(position));
            return false;
        }
    });
    if (!activityDataWrapper.profileListFilled) {
        LoadProfileListAsyncTask asyncTask = new LoadProfileListAsyncTask(this);
        this.asyncTaskContext = new WeakReference<>(asyncTask);
        asyncTask.execute();
    } else {
        absListView.setAdapter(profileListAdapter);
        doOnStart();
    }
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener)

Aggregations

OnItemClickListener (android.widget.AdapterView.OnItemClickListener)241 AdapterView (android.widget.AdapterView)238 View (android.view.View)237 ListView (android.widget.ListView)188 TextView (android.widget.TextView)135 ImageView (android.widget.ImageView)86 Intent (android.content.Intent)68 OnClickListener (android.view.View.OnClickListener)44 SuppressLint (android.annotation.SuppressLint)32 LayoutInflater (android.view.LayoutInflater)32 AlertDialog (android.app.AlertDialog)27 DialogInterface (android.content.DialogInterface)27 GridView (android.widget.GridView)26 ArrayAdapter (android.widget.ArrayAdapter)24 Bundle (android.os.Bundle)23 Dialog (android.app.Dialog)22 ArrayList (java.util.ArrayList)21 Paint (android.graphics.Paint)17 File (java.io.File)17 AbsListView (android.widget.AbsListView)16