Search in sources :

Example 31 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Osmand by osmandapp.

the class FavoriteDialogs method prepareAddFavouriteDialog.

public static void prepareAddFavouriteDialog(Activity activity, Dialog dialog, Bundle args, double lat, double lon, PointDescription desc) {
    final Resources resources = activity.getResources();
    String name = desc == null ? "" : desc.getName();
    if (name.length() == 0) {
        name = resources.getString(R.string.add_favorite_dialog_default_favourite_name);
    }
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    final FavouritePoint point = new FavouritePoint(lat, lon, name, app.getSettings().LAST_FAV_CATEGORY_ENTERED.get());
    args.putSerializable(KEY_FAVORITE, point);
    final EditText editText = (EditText) dialog.findViewById(R.id.Name);
    editText.setText(point.getName());
    editText.selectAll();
    editText.requestFocus();
    final AutoCompleteTextView cat = (AutoCompleteTextView) dialog.findViewById(R.id.Category);
    cat.setText(point.getCategory());
    AndroidUtils.softKeyboardDelayed(editText);
}
Also used : EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) Resources(android.content.res.Resources) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 32 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Osmand by osmandapp.

the class AddPOIAction method setUpAdapterForPoiTypeEditText.

private void setUpAdapterForPoiTypeEditText(final MapActivity activity, final Map<String, PoiType> allTranslatedNames, final AutoCompleteTextView poiTypeEditText) {
    final Map<String, PoiType> subCategories = new LinkedHashMap<>();
    // }
    for (Map.Entry<String, PoiType> s : allTranslatedNames.entrySet()) {
        addMapEntryAdapter(subCategories, s.getKey(), s.getValue());
    }
    final ArrayAdapter<Object> adapter;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        adapter = new ArrayAdapter<>(activity, R.layout.list_textview, subCategories.keySet().toArray());
    } else {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = activity.getTheme();
        theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
        final int textColor = typedValue.data;
        adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.keySet().toArray()) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                final View view = super.getView(position, convertView, parent);
                ((TextView) view.findViewById(R.id.textView)).setTextColor(textColor);
                return view;
            }
        };
    }
    adapter.sort(new Comparator<Object>() {

        @Override
        public int compare(Object lhs, Object rhs) {
            return lhs.toString().compareTo(rhs.toString());
        }
    });
    poiTypeEditText.setAdapter(adapter);
    poiTypeEditText.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Object item = parent.getAdapter().getItem(position);
            poiTypeEditText.setText(item.toString());
            setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint) LinkedHashMap(java.util.LinkedHashMap) CallbackWithObject(net.osmand.CallbackWithObject) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TypedValue(android.util.TypedValue)

Example 33 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Osmand by osmandapp.

the class AddPOIAction method drawUI.

@Override
public void drawUI(final ViewGroup parent, final MapActivity activity) {
    final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_poi_layout, parent, false);
    final OsmandApplication application = activity.getMyApplication();
    Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark, activity.getResources().getColor(R.color.dash_search_icon_dark));
    final LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
    final MapPoiTypes poiTypes = application.getPoiTypes();
    final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(true);
    final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
    // It is possible to not restart initialization every time, and probably move initialization to appInit
    Map<String, PoiType> translatedTypes = poiTypes.getAllTranslatedNames(true);
    HashSet<String> tagKeys = new HashSet<>();
    HashSet<String> valueKeys = new HashSet<>();
    for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
        addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
    }
    addPoiToStringSet(poiTypes.getOtherMapCategory(), tagKeys, valueKeys);
    tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS);
    mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
    mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
    Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
    addTagButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            for (int i = 0; i < editTagsLineaLayout.getChildCount(); i++) {
                View item = editTagsLineaLayout.getChildAt(i);
                if (((EditText) item.findViewById(R.id.tagEditText)).getText().toString().isEmpty() && ((EditText) item.findViewById(R.id.valueEditText)).getText().toString().isEmpty())
                    return;
            }
            mAdapter.addTagView("", "");
        }
    });
    mAdapter.updateViews();
    final TextInputLayout poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
    final AutoCompleteTextView poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
    final SwitchCompat showDialog = (SwitchCompat) view.findViewById(R.id.saveButton);
    // showDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    // @Override
    // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // getParams().put(KEY_DIALOG, Boolean.toString(isChecked));
    // }
    // });
    showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
    final String text = getTagsFromParams().get(POI_TYPE_TAG);
    poiTypeEditText.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) {
            String tp = s.toString();
            putTagIntoParams(POI_TYPE_TAG, tp);
            PoiCategory category = getCategory(allTranslatedNames);
            if (category != null) {
                poiTypeTextInputLayout.setHint(category.getTranslation());
            }
            String add = application.getString(R.string.shared_string_add);
            if (title != null) {
                if (prevType.equals(title.getText().toString()) || title.getText().toString().equals(activity.getString(getNameRes())) || title.getText().toString().equals((add + " "))) {
                    if (!tp.isEmpty()) {
                        title.setText(add + " " + tp);
                        prevType = title.getText().toString();
                    }
                }
            }
        }
    });
    poiTypeEditText.setText(text != null ? text : "");
    poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(final View v, MotionEvent event) {
            final EditText editText = (EditText) v;
            final int DRAWABLE_RIGHT = 2;
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getX() >= (editText.getRight() - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - editText.getPaddingRight())) {
                    PoiCategory category = getCategory(allTranslatedNames);
                    PoiCategory tempPoiCategory = (category != null) ? category : poiTypes.getOtherPoiCategory();
                    PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(tempPoiCategory);
                    f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {

                        @Override
                        public void select(String category) {
                            poiTypeEditText.setText(category);
                        }
                    });
                    CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
                    f.show(activity.getSupportFragmentManager(), "PoiSubTypeDialogFragment");
                    return true;
                }
            }
            return false;
        }
    });
    setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
    ImageButton onlineDocumentationButton = (ImageButton) view.findViewById(R.id.onlineDocumentationButton);
    onlineDocumentationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
        }
    });
    boolean isLightTheme = activity.getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
    final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
    final int color = activity.getResources().getColor(colorId);
    onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_help, color));
    // poiTypeEditText.setCompoundDrawables(null, null, activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_arrow_drop_down, color), null);
    // Button addTypeButton = (Button) view.findViewById(R.id.addTypeButton);
    // addTypeButton.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(poiTypes.getOtherPoiCategory());
    // f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
    // @Override
    // public void select(String category) {
    // putTagIntoParams(POI_TYPE_TAG, category);
    // }
    // });
    // 
    // CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
    // f.show(parentFragment.getChildFragmentManager(), "PoiSubTypeDialogFragment");
    // }
    // });
    parent.addView(view);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) PoiSubTypeDialogFragment(net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) HashSet(java.util.HashSet) EditText(android.widget.EditText) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AbstractPoiType(net.osmand.osm.AbstractPoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapPoiTypes(net.osmand.osm.MapPoiTypes) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint) MotionEvent(android.view.MotionEvent) CreateEditActionDialog(net.osmand.plus.quickaction.CreateEditActionDialog) PoiCategory(net.osmand.osm.PoiCategory) LinearLayout(android.widget.LinearLayout) AutoCompleteTextView(android.widget.AutoCompleteTextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 34 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project BloodHub by kazijehangir.

the class OrganizationRegistrationActivity method registerNewOrg.

private void registerNewOrg() {
    AutoCompleteTextView mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    EditText mPasswordView = (EditText) findViewById(R.id.password);
    CheckBox mTermsAgree = (CheckBox) findViewById(R.id.agreeTerms);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();
    if (!email.contains("@")) {
        Toast.makeText(this, "Not a valid email address", Toast.LENGTH_SHORT).show();
    } else {
        if (password.length() < 4) {
            Toast.makeText(this, "Password is too short, minimum length is 4.", Toast.LENGTH_SHORT).show();
        } else {
            if (email.contains(":") || password.contains(":")) {
                Toast.makeText(this, "Email address and Password cannot contain ':'", Toast.LENGTH_SHORT).show();
            } else {
                if (!mTermsAgree.isChecked()) {
                    Toast.makeText(this, "You need to agree to share your details.", Toast.LENGTH_SHORT).show();
                } else {
                    progressBar.setVisibility(View.VISIBLE);
                    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Context context = getApplicationContext();
                            progressBar.setVisibility(View.GONE);
                            if (task.isSuccessful()) {
                                FirebaseUser user = mAuth.getCurrentUser();
                                sendVerificationEmail();
                                // take user to main screen
                                progressBar.setVisibility(View.GONE);
                                Intent intent = new Intent(context, LoginActivity.class);
                                startActivity(intent);
                            } else {
                                if (task.getException() instanceof FirebaseAuthUserCollisionException) {
                                    Toast.makeText(context, "User with this email already exists.", Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(context, "Error creating user", Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                    });
                }
            }
        }
    }
}
Also used : EditText(android.widget.EditText) Context(android.content.Context) AuthResult(com.google.firebase.auth.AuthResult) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) CheckBox(android.widget.CheckBox) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) ProgressBar(android.widget.ProgressBar) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 35 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project BloodHub by kazijehangir.

the class OrganizationRegistrationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_organization_registration);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    mAuth = FirebaseAuth.getInstance();
    username = (AutoCompleteTextView) findViewById(R.id.name);
    String[] hospitals = getResources().getStringArray(R.array.organizations_array);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, hospitals);
    username.setAdapter(adapter);
    // Set OnClick Listeners for buttons
    Button mRegisterButton = (Button) findViewById(R.id.register_button);
    mRegisterButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            registerNewOrg();
        }
    });
}
Also used : Button(android.widget.Button) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) ActionBar(android.support.v7.app.ActionBar) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

AutoCompleteTextView (android.widget.AutoCompleteTextView)106 View (android.view.View)62 TextView (android.widget.TextView)44 ArrayAdapter (android.widget.ArrayAdapter)38 Button (android.widget.Button)27 EditText (android.widget.EditText)21 OnClickListener (android.view.View.OnClickListener)20 KeyEvent (android.view.KeyEvent)19 AdapterView (android.widget.AdapterView)17 Intent (android.content.Intent)16 ImageView (android.widget.ImageView)14 Editable (android.text.Editable)10 TextWatcher (android.text.TextWatcher)10 ArrayList (java.util.ArrayList)9 Dialog (android.app.Dialog)8 ListView (android.widget.ListView)8 Spinner (android.widget.Spinner)8 DialogInterface (android.content.DialogInterface)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 SuppressLint (android.annotation.SuppressLint)6