Example usage for android.widget AutoCompleteTextView setThreshold

List of usage examples for android.widget AutoCompleteTextView setThreshold

Introduction

In this page you can find the example usage for android.widget AutoCompleteTextView setThreshold.

Prototype

public void setThreshold(int threshold) 

Source Link

Document

Specifies the minimum number of characters the user has to type in the edit box before the drop down list is shown.

When threshold is less than or equals 0, a threshold of 1 is applied.

Usage

From source file:ru.orangesoftware.financisto.activity.CategorySelector.java

private void initAutoCompleteFilter(final AutoCompleteTextView filterTxt) { // init only after it's toggled
    autoCompleteAdapter = TransactionUtils.createCategoryFilterAdapter(activity, db);
    filterTxt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS
            | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_FILTER);
    filterTxt.setThreshold(1);
    filterTxt.setOnFocusChangeListener((view, hasFocus) -> {
        if (hasFocus) {
            filterTxt.setAdapter(requireNonNull(autoCompleteAdapter));
            filterTxt.selectAll();/*from w w w . j  a v  a  2s  . c  om*/
        }
    });
    filterTxt.setOnItemClickListener((parent, view, position, id) -> {
        activity.onSelectedId(R.id.category, id);
        ToggleButton toggleBtn = (ToggleButton) filterTxt.getTag();
        toggleBtn.performClick();
    });
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_agent_autocomplete(int id) {
    ArrayAdapter<String> agents = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
    Cursor c = mDbHelper.fetch_agents();
    if (c.moveToFirst())
        do {//from  w w  w  .j  ava 2s .  c o  m
            agents.add(c.getString(c.getColumnIndex(DbAdapter.KEY_AGENT)));
        } while (c.moveToNext());
    c.close();
    AutoCompleteTextView agents_entry = (AutoCompleteTextView) findViewById(id);
    agents_entry.setThreshold(1);
    agents_entry.setAdapter(agents);
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_station_autocomplete(int id) {
    ArrayAdapter<String> stations = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
    Cursor c = mDbHelper.fetch_stations();
    if (c.moveToFirst())
        do {/*from w  w  w  .  j  a v  a 2 s.co  m*/
            stations.add(c.getString(c.getColumnIndex(DbAdapter.KEY_STN)));
        } while (c.moveToNext());
    c.close();
    AutoCompleteTextView stations_entry = (AutoCompleteTextView) findViewById(id);
    stations_entry.setThreshold(1);
    stations_entry.setAdapter(stations);
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_operator_autocomplete(int id) {
    ArrayAdapter<String> operators = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line);
    Cursor c = mDbHelper.fetch_operators();
    if (c.moveToFirst())
        do {/* w w w.  j av  a  2  s .  c o m*/
            operators.add(c.getString(c.getColumnIndex(DbAdapter.KEY_OPERATOR)));
        } while (c.moveToNext());
    c.close();
    AutoCompleteTextView operators_entry = (AutoCompleteTextView) findViewById(id);
    operators_entry.setThreshold(1);
    operators_entry.setAdapter(operators);
}

From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseFragment.java

@Nullable
@Override//  w  w w.ja v a  2 s  .co  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view);
    emptyTV = (TextView) root.findViewById(R.id.empty);
    arrow = (ImageView) root.findViewById(R.id.arrow);
    setRecyclerViewAdapter();

    FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab);
    addPurchaseFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            List<String> nseList = ShareUtils.getNseList(getContext());
            FilterWithSpaceAdapter<String> arrayAdapter = new FilterWithSpaceAdapter<>(getContext(),
                    android.R.layout.simple_dropdown_item_1line, nseList);
            name.setThreshold(1);
            name.setAdapter(arrayAdapter);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);

            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            if (shares.size() == 0)
                existingRB.setVisibility(View.GONE);
            (newRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.VISIBLE);
                    spinner.setVisibility(View.GONE);
                }
            });

            (existingRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.GONE);
                    spinner.setVisibility(View.VISIBLE);
                }
            });

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start,
                            month_start - 1, day_start);
                    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            selectDate.setText(new StringBuilder().append(day_start).append("/")
                                    .append(month_start).append("/").append(year_start));
                        }
                    });
                    dialog.show();
                }
            });

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Share share = new Share();
                    share.setId(databaseHandler.getNextKey("share"));
                    share.setPurchases(new RealmList<Purchase>());
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));

                    if (newRB.isChecked()) {
                        String sName = name.getText().toString().trim();
                        if (sName.equals("")) {
                            Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            share.setName(sName);
                            purchase.setName(sName);
                        }
                    }

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        share.setDateOfInitialPurchase(date);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.buying_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("buy");
                    if (newRB.isChecked()) {
                        if (!databaseHandler.addShare(share, purchase)) {
                            Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        purchase.setName(spinner.getSelectedItem().toString());
                        databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    }
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}

From source file:com.mobicage.rogerthat.plugins.friends.RecommendServiceActivity.java

private void configureMailView() {
    T.UI();//from  w  w  w  . ja  v a  2  s  .  c  om
    final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.recommend_email_text_field);
    emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>()));
    emailText.setThreshold(1);

    if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) {
        mService.postAtFrontOfBIZZHandler(new SafeRunnable() {

            @SuppressWarnings("unchecked")
            @Override
            protected void safeRun() throws Exception {
                L.d("RecommendServiceActivity getEmailAddresses");
                List<String> emailList = ContactListHelper.getEmailAddresses(RecommendServiceActivity.this);
                ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter();
                for (int i = 0; i < emailList.size(); i++) {
                    a.add(emailList.get(i));
                }
                a.notifyDataSetChanged();
                L.d("RecommendServiceActivity gotEmailAddresses");
            }
        });
    }

    final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            String email = emailText.getText().toString().trim();
            if (RegexPatterns.EMAIL.matcher(email).matches()) {
                mFriendsPlugin.shareService(mServiceEmail, email);
                emailText.setText(null);
                UIUtils.hideKeyboard(RecommendServiceActivity.this, emailText);

                AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this);
                builder.setMessage(R.string.service_recommendation_sent);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(RecommendServiceActivity.this);
                builder.setMessage(R.string.registration_email_not_valid);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            }
        }
    };

    ((Button) findViewById(R.id.recommend_email_button)).setOnClickListener(onClickListener);

    emailText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                onClickListener.onClick(view);
                return true;
            }
            return false;
        }
    });
}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;/*w  w  w.  j ava2  s .  c om*/
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}

From source file:com.vaquerosisd.projectmanager.TaskList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.task_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
    Button clearSearchTask = (Button) searchItem.getActionView().findViewById(R.id.actionBar_ClearSearch);
    final AutoCompleteTextView searchTask = (AutoCompleteTextView) searchItem.getActionView()
            .findViewById(R.id.actionBar_SearchItemEditText);

    //Get all tasks names and add them to an adapter for the AutoCompleteTextView
    List<Task> allTasks = db.getAllTasks(projectId);
    String[] tasksNames = new String[allTasks.size()];
    for (int i = 0; i < allTasks.size(); i++)
        tasksNames[i] = allTasks.get(i).getTaskName();

    ArrayAdapter<String> tasksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            tasksNames);//from  ww  w  .j  ava 2s. com
    searchTask.setAdapter(tasksAdapter);
    searchTask.setThreshold(1);

    //Clear text of search AutoCompleteTextView
    clearSearchTask.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            searchTask.setText("");
        }
    });

    searchTask.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
            } else {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            }
        }
    });

    //Search task
    searchTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //When the user press "DONE" key, select the task
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                String project = searchTask.getText().toString();
                searchTask(project);
                //Hide keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchTask.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                return true;
            }
            return false;
        }
    });
    return true;
}

From source file:com.mobicage.rogerthat.AddFriendsActivity.java

private void configureMailView() {
    T.UI();//from   ww  w . ja  va 2  s .  c  om
    final AutoCompleteTextView emailText = (AutoCompleteTextView) findViewById(R.id.add_via_email_text_field);
    emailText.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, new ArrayList<String>()));
    emailText.setThreshold(1);

    if (mService.isPermitted(Manifest.permission.READ_CONTACTS)) {
        mService.postAtFrontOfBIZZHandler(new SafeRunnable() {

            @SuppressWarnings("unchecked")
            @Override
            protected void safeRun() throws Exception {
                L.d("AddFriendsActivity getEmailAddresses");
                List<String> emailList = ContactListHelper.getEmailAddresses(AddFriendsActivity.this);
                ArrayAdapter<String> a = (ArrayAdapter<String>) emailText.getAdapter();
                for (int i = 0; i < emailList.size(); i++) {
                    a.add(emailList.get(i));
                }
                a.notifyDataSetChanged();
                L.d("AddFriendsActivity gotEmailAddresses");
            }
        });
    }

    final SafeViewOnClickListener onClickListener = new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            String email = emailText.getText().toString().trim();
            if (RegexPatterns.EMAIL.matcher(email).matches()) {
                if (mFriendsPlugin.inviteFriend(email, null, null, true)) {
                    emailText.setText(null);
                    UIUtils.hideKeyboard(AddFriendsActivity.this, emailText);
                } else {
                    UIUtils.showLongToast(AddFriendsActivity.this, getString(R.string.friend_invite_failed));
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(AddFriendsActivity.this);
                builder.setMessage(R.string.registration_email_not_valid);
                builder.setPositiveButton(R.string.rogerthat, null);
                builder.create().show();
            }
        }
    };
    ((Button) findViewById(R.id.add_via_email_button)).setOnClickListener(onClickListener);

    emailText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                onClickListener.onClick(view);
                return true;
            }
            return false;
        }
    });
}

From source file:com.terraremote.terrafieldreport.OpenGroundReport.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.open_ground_layout);
    ButterKnife.bind(this);

    loadSharedPreferences();/*from   w ww .  j a v a2  s . co m*/

    Typeface customTypeface = Typeface.createFromAsset(getAssets(), "Raleway-Medium.ttf");
    TextView open_ground_text_font = findViewById(R.id.open_ground_text);
    open_ground_text_font.setTypeface(customTypeface);

    //        final DecimalFormat df = new DecimalFormat("0.00000");
    // Grab the current date and update the string variable 'userSelectedDateGround' with its value.
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    showDate.setText(sdf.format(new Date()));
    submissionDate = sdf.format(new Date());

    // get the defined string array of field team names
    ArrayAdapter<String> enterNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.TerraFieldTeamNames));
    AutoCompleteTextView enterNameTextView = (AutoCompleteTextView) mName;
    //set adapter for the auto complete fields
    enterNameTextView.setAdapter(enterNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    enterNameTextView.setThreshold(1);
    // comma to separate the different names
    enterNameTextView.setAdapter(enterNameAdapter);

    // get the defined string array of field team names
    ArrayAdapter<String> fieldTeamNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.TerraFieldTeamNames));
    MultiAutoCompleteTextView fieldTeamNameTextView = mColleagues;
    //set adapter for the auto complete fields
    fieldTeamNameTextView.setAdapter(fieldTeamNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    fieldTeamNameTextView.setThreshold(1);
    // comma to separate the different names
    fieldTeamNameTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    // get the defined string array of helicopter color names
    ArrayAdapter<String> vehicleColorAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.vehicle_colors));
    AutoCompleteTextView vehicleColorsTextView = (AutoCompleteTextView) mVehicleColour;
    //set adapter for the auto complete fields
    vehicleColorsTextView.setAdapter(vehicleColorAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleColorsTextView.setThreshold(1);
    // set adapter
    vehicleColorsTextView.setAdapter(vehicleColorAdapter);

    // get the defined string array of vehicle makes
    ArrayAdapter<String> vehicleMakeAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line, getResources().getStringArray(R.array.vehicle_make));
    AutoCompleteTextView vehicleMakeTextView = (AutoCompleteTextView) mVehicleMake;
    //set adapter for the auto complete fields
    vehicleMakeTextView.setAdapter(vehicleMakeAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleMakeTextView.setThreshold(1);
    // set adapter
    vehicleMakeTextView.setAdapter(vehicleMakeAdapter);

    // get the defined string array of car rental agencies
    ArrayAdapter<String> rentalAgencyAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.rental_agencies));
    AutoCompleteTextView rentalAgencyTv = (AutoCompleteTextView) mRentalAgency;
    //set adapter for the auto complete fields
    rentalAgencyTv.setAdapter(rentalAgencyAdapter);
    // specify the minimum type of characters before drop-down list is shown
    rentalAgencyTv.setThreshold(1);
    // set adapter
    rentalAgencyTv.setAdapter(rentalAgencyAdapter);

    // get the defined string array of vehicle operator names
    ArrayAdapter<String> vehicleOperatorNameAdapter = new ArrayAdapter<>(this,
            android.R.layout.simple_dropdown_item_1line,
            getResources().getStringArray(R.array.check_in_contact_data_checker_names));
    AutoCompleteTextView vehicleOperatorNameTextView = (AutoCompleteTextView) mVehicleOperatorName;
    //set adapter for the auto complete fields
    vehicleOperatorNameTextView.setAdapter(vehicleOperatorNameAdapter);
    // specify the minimum type of characters before drop-down list is shown
    vehicleOperatorNameTextView.setThreshold(1);
    // set adapter
    vehicleOperatorNameTextView.setAdapter(vehicleOperatorNameAdapter);

}