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;
}
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;
}
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();
}
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();
}
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();
}
}
Aggregations