Search in sources :

Example 61 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android by JetBrains.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    // Find the Google+ sign in button.
    mPlusSignInButton = (SignInButton) findViewById(R.id.plus_sign_in_button);
    if (supportsGooglePlayServices()) {
        // Set a listener to connect the user when the G+ button is clicked.
        mPlusSignInButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                signIn();
            }
        });
    } else {
        // Don't offer G+ sign in if the app's version is too low to support Google Play
        // Services.
        mPlusSignInButton.setVisibility(View.GONE);
        return;
    }
    // Set up the login form.
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    populateAutoComplete();
    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });
    Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
    mEmailLoginFormView = findViewById(R.id.email_login_form);
    mSignOutButtons = findViewById(R.id.plus_sign_out_buttons);
}
Also used : KeyEvent(android.view.KeyEvent) Button(android.widget.Button) SignInButton(com.google.android.gms.common.SignInButton) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView)

Example 62 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project WordPress-Android by wordpress-mobile.

the class ReaderPostListFragment method setupRecyclerToolbar.

/*
     * adds a menu to the recycler's toolbar containing settings & search items - only called
     * for followed tags
     */
private void setupRecyclerToolbar() {
    Menu menu = mRecyclerView.addToolbarMenu(R.menu.reader_list);
    mSettingsMenuItem = menu.findItem(R.id.menu_reader_settings);
    mSearchMenuItem = menu.findItem(R.id.menu_reader_search);
    mSettingsMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ReaderActivityLauncher.showReaderSubs(getActivity());
            return true;
        }
    });
    mSearchView = (SearchView) mSearchMenuItem.getActionView();
    mSearchView.setQueryHint(getString(R.string.reader_hint_post_search));
    mSearchView.setSubmitButtonEnabled(false);
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setIconified(true);
    // force the search view to take up as much horizontal space as possible (without this
    // it looks truncated on landscape)
    int maxWidth = DisplayUtils.getDisplayPixelWidth(getActivity());
    mSearchView.setMaxWidth(maxWidth);
    // this is hacky, but we want to change the SearchView's autocomplete to show suggestions
    // after a single character is typed, and there's no less hacky way to do this...
    View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    if (view instanceof AutoCompleteTextView) {
        ((AutoCompleteTextView) view).setThreshold(1);
    }
    MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            if (getPostListType() != ReaderPostListType.SEARCH_RESULTS) {
                AnalyticsTracker.track(AnalyticsTracker.Stat.READER_SEARCH_LOADED);
            }
            resetPostAdapter(ReaderPostListType.SEARCH_RESULTS);
            showSearchMessage();
            mSettingsMenuItem.setVisible(false);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            hideSearchMessage();
            resetSearchSuggestionAdapter();
            mSettingsMenuItem.setVisible(true);
            mCurrentSearchQuery = null;
            // return to the followed tag that was showing prior to searching
            resetPostAdapter(ReaderPostListType.TAG_FOLLOWED);
            return true;
        }
    });
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            submitSearchQuery(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                showSearchMessage();
            } else {
                populateSearchSuggestionAdapter(newText);
            }
            return true;
        }
    });
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchView(android.support.v7.widget.SearchView) MenuItem(android.view.MenuItem) Menu(android.view.Menu) SearchView(android.support.v7.widget.SearchView) ReaderSiteHeaderView(org.wordpress.android.ui.reader.views.ReaderSiteHeaderView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FilteredRecyclerView(org.wordpress.android.ui.FilteredRecyclerView) AutoCompleteTextView(android.widget.AutoCompleteTextView) RecyclerView(android.support.v7.widget.RecyclerView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 63 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project SR-Tracker-for-Overwatch by Rexios80.

the class ActionBarHandler method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDbHelper = new DatabaseHelper(getApplicationContext());
    db = mDbHelper.getWritableDatabase();
    if (savedInstanceState != null) {
        Log.i("ActionBarHandler", "Saved instance restored - " + savedInstanceState.getString("season"));
        DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME = savedInstanceState.getString("season");
    }
    AlertDialog.Builder builder;
    View view;
    LayoutInflater inflater;
    String origin = getIntent().getStringExtra("origin");
    if (origin == null)
        origin = "";
    switch(item.getItemId()) {
        case R.id.action_add_record:
            if (origin.equals("Placements")) {
                builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
                // Get the layout inflater
                inflater = getLayoutInflater();
                view = inflater.inflate(R.layout.dialog_add_record_placement, null);
                final AutoCompleteTextView actvMap = (AutoCompleteTextView) view.findViewById(R.id.map_field);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.autocompletetextview_item, getResources().getStringArray(R.array.map_array));
                actvMap.setAdapter(adapter);
                actvMap.setThreshold(1);
                final AutoCompleteTextView actvHero1 = (AutoCompleteTextView) view.findViewById(R.id.hero1_field);
                ArrayAdapter<String> heroAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.autocompletetextview_item, getResources().getStringArray(R.array.hero_array));
                actvHero1.setAdapter(heroAdapter);
                actvHero1.setThreshold(1);
                final AutoCompleteTextView actvHero2 = (AutoCompleteTextView) view.findViewById(R.id.hero2_field);
                actvHero2.setAdapter(heroAdapter);
                actvHero2.setThreshold(1);
                final AutoCompleteTextView actvHero3 = (AutoCompleteTextView) view.findViewById(R.id.hero3_field);
                actvHero3.setAdapter(heroAdapter);
                actvHero3.setThreshold(1);
                final EditText etNote = (EditText) view.findViewById(R.id.note_field);
                if (DatabaseUtils.queryNumEntries(db, DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME) == 10) {
                    Intent returnIntent = new Intent();
                    returnIntent.putExtra("error", "You already completed your placements");
                    setResult(Activity.RESULT_OK, returnIntent);
                    finish();
                    return;
                }
                // Inflate and set the layout for the dialog
                // Pass null as the parent view because its going in the dialog layout
                final Dialog recordAddDialog = builder.setView(view).setPositiveButton("Win", null).setNeutralButton("Draw", null).setNegativeButton("Loss", null).create();
                recordAddDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                    @Override
                    public void onShow(DialogInterface dialog) {
                        Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                String newSR = "1";
                                String newMap = actvMap.getText().toString();
                                String newHero1 = actvHero1.getText().toString();
                                String newHero2 = actvHero2.getText().toString();
                                String newHero3 = actvHero3.getText().toString();
                                String newNote = etNote.getText().toString();
                                List<String> maps = Arrays.asList(getResources().getStringArray(R.array.map_array));
                                List<String> heroes = Arrays.asList(getResources().getStringArray(R.array.hero_array));
                                if (newMap.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Enter a map name", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!maps.contains(newMap)) {
                                    Snackbar snackbar = Snackbar.make(view, "Check map spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!heroes.contains(newHero1) && !newHero1.equals("") || !heroes.contains(newHero2) && !newHero2.equals("") || !heroes.contains(newHero3) && !newHero3.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Check hero spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                ContentValues values = new ContentValues();
                                values.put(DatabaseContract.Database.COLUMN_NAME_SR, newSR);
                                values.put(DatabaseContract.Database.COLUMN_NAME_MAP, newMap);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_1, newHero1);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_2, newHero2);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_3, newHero3);
                                values.put(DatabaseContract.Database.COLUMN_NAME_TIME, System.currentTimeMillis());
                                values.put(DatabaseContract.Database.COLUMN_NAME_NOTE, newNote);
                                db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                                //Dismiss once everything is OK.
                                recordAddDialog.dismiss();
                                finish();
                            }
                        });
                        button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                String newSR = "0";
                                String newMap = actvMap.getText().toString();
                                String newHero1 = actvHero1.getText().toString();
                                String newHero2 = actvHero2.getText().toString();
                                String newHero3 = actvHero3.getText().toString();
                                String newNote = etNote.getText().toString();
                                List<String> maps = Arrays.asList(getResources().getStringArray(R.array.map_array));
                                List<String> heroes = Arrays.asList(getResources().getStringArray(R.array.hero_array));
                                if (newMap.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Enter a map name", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!maps.contains(newMap)) {
                                    Snackbar snackbar = Snackbar.make(view, "Check map spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!heroes.contains(newHero1) && !newHero1.equals("") || !heroes.contains(newHero2) && !newHero2.equals("") || !heroes.contains(newHero3) && !newHero3.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Check hero spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                ContentValues values = new ContentValues();
                                values.put(DatabaseContract.Database.COLUMN_NAME_SR, newSR);
                                values.put(DatabaseContract.Database.COLUMN_NAME_MAP, newMap);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_1, newHero1);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_2, newHero2);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_3, newHero3);
                                values.put(DatabaseContract.Database.COLUMN_NAME_TIME, System.currentTimeMillis());
                                values.put(DatabaseContract.Database.COLUMN_NAME_NOTE, newNote);
                                db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                                //Dismiss once everything is OK.
                                recordAddDialog.dismiss();
                                finish();
                            }
                        });
                        button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                String newSR = "-1";
                                String newMap = actvMap.getText().toString();
                                String newHero1 = actvHero1.getText().toString();
                                String newHero2 = actvHero2.getText().toString();
                                String newHero3 = actvHero3.getText().toString();
                                String newNote = etNote.getText().toString();
                                List<String> maps = Arrays.asList(getResources().getStringArray(R.array.map_array));
                                List<String> heroes = Arrays.asList(getResources().getStringArray(R.array.hero_array));
                                if (newMap.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Enter a map name", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!maps.contains(newMap)) {
                                    Snackbar snackbar = Snackbar.make(view, "Check map spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                if (!heroes.contains(newHero1) && !newHero1.equals("") || !heroes.contains(newHero2) && !newHero2.equals("") || !heroes.contains(newHero3) && !newHero3.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Check hero spelling", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                ContentValues values = new ContentValues();
                                values.put(DatabaseContract.Database.COLUMN_NAME_SR, newSR);
                                values.put(DatabaseContract.Database.COLUMN_NAME_MAP, newMap);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_1, newHero1);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_2, newHero2);
                                values.put(DatabaseContract.Database.COLUMN_NAME_HERO_3, newHero3);
                                values.put(DatabaseContract.Database.COLUMN_NAME_TIME, System.currentTimeMillis());
                                values.put(DatabaseContract.Database.COLUMN_NAME_NOTE, newNote);
                                db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                                //Dismiss once everything is OK.
                                recordAddDialog.dismiss();
                                finish();
                            }
                        });
                    }
                });
                window = recordAddDialog.getWindow();
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
                window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                recordAddDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                    @Override
                    public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                            recordAddDialog.dismiss();
                            finish();
                        }
                        return false;
                    }
                });
                recordAddDialog.show();
                break;
            }
            builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
            // Get the layout inflater
            inflater = getLayoutInflater();
            view = inflater.inflate(R.layout.dialog_add_record, null);
            final EditText etSR = (EditText) view.findViewById(R.id.sr_field);
            final AutoCompleteTextView actvMap = (AutoCompleteTextView) view.findViewById(R.id.map_field);
            ArrayAdapter<String> mapAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.autocompletetextview_item, getResources().getStringArray(R.array.map_array));
            actvMap.setAdapter(mapAdapter);
            actvMap.setThreshold(1);
            final AutoCompleteTextView actvHero1 = (AutoCompleteTextView) view.findViewById(R.id.hero1_field);
            ArrayAdapter<String> heroAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.autocompletetextview_item, getResources().getStringArray(R.array.hero_array));
            actvHero1.setAdapter(heroAdapter);
            actvHero1.setThreshold(1);
            final AutoCompleteTextView actvHero2 = (AutoCompleteTextView) view.findViewById(R.id.hero2_field);
            actvHero2.setAdapter(heroAdapter);
            actvHero2.setThreshold(1);
            final AutoCompleteTextView actvHero3 = (AutoCompleteTextView) view.findViewById(R.id.hero3_field);
            actvHero3.setAdapter(heroAdapter);
            actvHero3.setThreshold(1);
            final EditText etNote = (EditText) view.findViewById(R.id.note_field);
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            final Dialog recordAddDialog = builder.setView(view).setPositiveButton("Add", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing
                    finish();
                }
            }).create();
            recordAddDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(DialogInterface dialog) {
                    Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                    button.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            String newSR = etSR.getText().toString();
                            String newMap = actvMap.getText().toString();
                            String newHero1 = actvHero1.getText().toString();
                            String newHero2 = actvHero2.getText().toString();
                            String newHero3 = actvHero3.getText().toString();
                            String newNote = etNote.getText().toString();
                            List<String> maps = Arrays.asList(getResources().getStringArray(R.array.map_array));
                            List<String> heroes = Arrays.asList(getResources().getStringArray(R.array.hero_array));
                            if (newSR.equals("") || newMap.equals("")) {
                                Snackbar snackbar = Snackbar.make(view, "Enter SR and Map", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            try {
                                Integer.parseInt(newSR);
                            } catch (NumberFormatException e) {
                                Snackbar snackbar = Snackbar.make(view, "That number is too big", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            if (!maps.contains(newMap)) {
                                Snackbar snackbar = Snackbar.make(view, "Check map spelling", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            if (!heroes.contains(newHero1) && !newHero1.equals("") || !heroes.contains(newHero2) && !newHero2.equals("") || !heroes.contains(newHero3) && !newHero3.equals("")) {
                                Snackbar snackbar = Snackbar.make(view, "Check hero spelling", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            ContentValues values = new ContentValues();
                            values.put(DatabaseContract.Database.COLUMN_NAME_SR, newSR);
                            values.put(DatabaseContract.Database.COLUMN_NAME_MAP, newMap);
                            values.put(DatabaseContract.Database.COLUMN_NAME_HERO_1, newHero1);
                            values.put(DatabaseContract.Database.COLUMN_NAME_HERO_2, newHero2);
                            values.put(DatabaseContract.Database.COLUMN_NAME_HERO_3, newHero3);
                            values.put(DatabaseContract.Database.COLUMN_NAME_TIME, System.currentTimeMillis());
                            values.put(DatabaseContract.Database.COLUMN_NAME_NOTE, newNote);
                            db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                            //Dismiss once everything is OK.
                            recordAddDialog.dismiss();
                            finish();
                        }
                    });
                }
            });
            window = recordAddDialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            recordAddDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        recordAddDialog.dismiss();
                        finish();
                    }
                    return false;
                }
            });
            recordAddDialog.show();
            break;
        case R.id.action_remove_record:
            // If last entry is the placement SR entry
            if (DatabaseUtils.queryNumEntries(db, DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME) == 11 && !origin.equals("Placements")) {
                builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
                // Get the layout inflater
                inflater = getLayoutInflater();
                view = inflater.inflate(R.layout.dialog_new_placement, null);
                final EditText etPlacement = (EditText) view.findViewById(R.id.placement_field);
                // Inflate and set the layout for the dialog
                // Pass null as the parent view because its going in the dialog layout
                final Dialog newPlacementDialog = builder.setView(view).setPositiveButton("Replace", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        // Do nothing
                        finish();
                    }
                }).create();
                newPlacementDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                    @Override
                    public void onShow(DialogInterface dialog) {
                        Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                        button.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                String newPlacement = etPlacement.getText().toString();
                                if (newPlacement.equals("")) {
                                    Snackbar snackbar = Snackbar.make(view, "Enter a placement SR", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                try {
                                    Integer.parseInt(newPlacement);
                                } catch (NumberFormatException e) {
                                    Snackbar snackbar = Snackbar.make(view, "That number is too big", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                                mDbHelper.deleteLast(db);
                                ContentValues values = new ContentValues();
                                values.put(DatabaseContract.Database.COLUMN_NAME_SR, newPlacement);
                                db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                                newPlacementDialog.dismiss();
                                finish();
                            }
                        });
                    }
                });
                window = newPlacementDialog.getWindow();
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
                window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                newPlacementDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                    @Override
                    public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                            newPlacementDialog.dismiss();
                            finish();
                            return true;
                        }
                        return false;
                    }
                });
                newPlacementDialog.show();
                break;
            }
            // If there are no entries to remove
            if (DatabaseUtils.queryNumEntries(db, DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME) == 0 && origin.equals("Placements")) {
                Intent returnIntent = new Intent();
                returnIntent.putExtra("error", "Nothing to remove");
                setResult(Activity.RESULT_OK, returnIntent);
                finish();
                break;
            }
            builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
            // Get the layout inflater
            inflater = getLayoutInflater();
            view = inflater.inflate(R.layout.dialog_remove_record, null);
            final Dialog recordRemoveDialog = builder.setView(view).setPositiveButton("Confirm", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    mDbHelper.deleteLast(db);
                    Intent returnIntent = new Intent();
                    returnIntent.putExtra("itemRemoved", "");
                    setResult(Activity.RESULT_OK, returnIntent);
                    finish();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing
                    finish();
                }
            }).create();
            window = recordRemoveDialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            recordRemoveDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        recordRemoveDialog.dismiss();
                        finish();
                    }
                    return false;
                }
            });
            recordRemoveDialog.show();
            break;
        case R.id.seasons:
            // Do nothing
            finish();
            break;
        case R.id.action_add_season:
            builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
            // Get the layout inflater
            inflater = getLayoutInflater();
            view = inflater.inflate(R.layout.dialog_add_season, null);
            final EditText etSeason = (EditText) view.findViewById(R.id.season_field);
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            final Dialog seasonAddDialog = builder.setView(view).setPositiveButton("Add", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing
                    finish();
                }
            }).create();
            seasonAddDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(DialogInterface dialog) {
                    Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                    button.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            String newSeason = etSeason.getText().toString();
                            if (newSeason.equals("")) {
                                Snackbar snackbar = Snackbar.make(view, "Enter a season number", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            try {
                                Integer.parseInt(newSeason);
                            } catch (NumberFormatException e) {
                                Snackbar snackbar = Snackbar.make(view, "That number is too big", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            DatabaseHelper mDbHelper = new DatabaseHelper(getApplicationContext());
                            SQLiteDatabase db = mDbHelper.getWritableDatabase();
                            String[] projection = { DatabaseContract.Database._ID, DatabaseContract.Database.COLUMN_NAME_SEASON };
                            Cursor cursor = db.query(DatabaseContract.Database.SEASONS_TABLE_NAME, projection, null, null, null, null, null);
                            while (cursor.moveToNext()) {
                                if (Integer.parseInt(newSeason) == cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseContract.Database.COLUMN_NAME_SEASON))) {
                                    Snackbar snackbar = Snackbar.make(view, "Season already exists", Snackbar.LENGTH_SHORT);
                                    snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                    snackbar.show();
                                    return;
                                }
                            }
                            cursor.close();
                            DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME = "Season" + Integer.parseInt(newSeason);
                            mDbHelper = new DatabaseHelper(getApplicationContext());
                            db = mDbHelper.getWritableDatabase();
                            mDbHelper.onCreateSeason(db);
                            // Put new season number in Seasons table
                            ContentValues values = new ContentValues();
                            values.put(DatabaseContract.Database.COLUMN_NAME_SEASON, newSeason);
                            db.insert(DatabaseContract.Database.SEASONS_TABLE_NAME, null, values);
                            intent = new Intent(getApplicationContext(), PlacementsActivity.class);
                            startActivity(intent);
                            // Tell parent activity to finish
                            Intent returnIntent = new Intent();
                            returnIntent.putExtra("exit", true);
                            setResult(Activity.RESULT_OK, returnIntent);
                            seasonAddDialog.dismiss();
                            finish();
                        }
                    });
                }
            });
            window = seasonAddDialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            seasonAddDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        seasonAddDialog.dismiss();
                        finish();
                        return true;
                    }
                    return false;
                }
            });
            seasonAddDialog.show();
            break;
        case R.id.action_delete_season:
            builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
            // Get the layout inflater
            inflater = getLayoutInflater();
            view = inflater.inflate(R.layout.dialog_delete_season, null);
            final Dialog seasonDeleteDialog = builder.setView(view).setPositiveButton("Confirm", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    mDbHelper.deleteSeason(db, DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME);
                    Intent returnIntent = new Intent();
                    returnIntent.putExtra("exit", true);
                    setResult(Activity.RESULT_OK, returnIntent);
                    intent = new Intent(getApplicationContext(), StartupActivity.class);
                    startActivity(intent);
                    finish();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing
                    finish();
                }
            }).create();
            window = seasonDeleteDialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            seasonDeleteDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        seasonDeleteDialog.dismiss();
                        finish();
                    }
                    return false;
                }
            });
            seasonDeleteDialog.show();
            break;
        case R.id.action_skip_placements:
            builder = new AlertDialog.Builder(this, R.style.AlertDialogCustom);
            // Get the layout inflater
            inflater = getLayoutInflater();
            view = inflater.inflate(R.layout.dialog_skip_placements, null);
            final EditText etSrInitial = (EditText) view.findViewById(R.id.initial_sr_entry);
            // Inflate and set the layout for the dialog
            // Pass null as the parent view because its going in the dialog layout
            final Dialog skipPlacementsDialog = builder.setView(view).setPositiveButton("Skip", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    // Do nothing
                    finish();
                }
            }).create();
            skipPlacementsDialog.setOnShowListener(new DialogInterface.OnShowListener() {

                @Override
                public void onShow(DialogInterface dialog) {
                    Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                    button.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            String newSR = etSrInitial.getText().toString();
                            if (newSR.equals("")) {
                                Snackbar snackbar = Snackbar.make(view, "Enter a SR", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            try {
                                Integer.parseInt(newSR);
                            } catch (NumberFormatException e) {
                                Snackbar snackbar = Snackbar.make(view, "That number is too big", Snackbar.LENGTH_SHORT);
                                snackbar.getView().findViewById(android.support.design.R.id.snackbar_text).setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.snackbarBackground));
                                snackbar.show();
                                return;
                            }
                            // Remove any already added placements to avoid conflicts
                            mDbHelper.onClearCurrentSeason(db);
                            ContentValues values = new ContentValues();
                            // Insert empty placement matches in database
                            for (int i = 0; i < 10; i++) {
                                values.put(DatabaseContract.Database.COLUMN_NAME_SR, -5);
                                db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                            }
                            // Insert placement sr in database
                            values = new ContentValues();
                            values.put(DatabaseContract.Database.COLUMN_NAME_SR, newSR);
                            db.insert(DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME, null, values);
                            Intent intent = new Intent(getApplicationContext(), InformationActivity.class);
                            skipPlacementsDialog.dismiss();
                            startActivity(intent);
                            finish();
                        }
                    });
                }
            });
            Window window = skipPlacementsDialog.getWindow();
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            skipPlacementsDialog.setOnKeyListener(new AlertDialog.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        skipPlacementsDialog.dismiss();
                        finish();
                        return true;
                    }
                    return false;
                }
            });
            skipPlacementsDialog.show();
            break;
        // Handle season list action (probably a bad idea to put it in default, but whatever)
        default:
            int seasonNumber = Integer.parseInt(item.getTitle().toString().substring(7));
            if (DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME.equals("Season" + seasonNumber)) {
                finish();
                return;
            }
            DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME = "Season" + seasonNumber;
            Intent returnIntent = new Intent();
            returnIntent.putExtra("exit", true);
            setResult(Activity.RESULT_OK, returnIntent);
            if (DatabaseUtils.queryNumEntries(db, DatabaseContract.Database.CURRENT_SEASON_TABLE_NAME) < 11) {
                intent = new Intent(this, PlacementsActivity.class);
                startActivity(intent);
                finish();
                return;
            }
            intent = new Intent(this, InformationActivity.class);
            startActivity(intent);
            finish();
            break;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) ContentValues(android.content.ContentValues) Window(android.view.Window) Intent(android.content.Intent) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LayoutInflater(android.view.LayoutInflater) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView) Snackbar(android.support.design.widget.Snackbar)

Example 64 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android_frameworks_base by ResurrectionRemix.

the class AutoCompleteTextViewActivityLandscape method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.auto_complete_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
    textView.setAdapter(adapter);
}
Also used : ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 65 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project android_frameworks_base by ResurrectionRemix.

the class AutoCompleteTextViewActivityPortrait method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.auto_complete_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
    textView.setAdapter(adapter);
}
Also used : ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

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