Search in sources :

Example 71 with AutoCompleteTextView

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

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 72 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Slide by ccrama.

the class MainActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SETTINGS_RESULT) {
        int current = pager.getCurrentItem();
        if (commentPager && current == currentComment) {
            current = current - 1;
        }
        if (current < 0)
            current = 0;
        adapter = new OverviewPagerAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);
        pager.setCurrentItem(current);
        if (mTabLayout != null) {
            mTabLayout.setupWithViewPager(pager);
            scrollToTabAfterLayout(current);
        }
        setToolbarClick();
    } else if ((requestCode == 2001 || requestCode == 2002) && resultCode == RESULT_OK) {
        if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_DRAWER || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
            drawerLayout.closeDrawers();
            drawerSearch.setText("");
        }
        // clear the text from the toolbar search field
        if (findViewById(R.id.toolbar_search) != null) {
            ((AutoCompleteTextView) findViewById(R.id.toolbar_search)).setText("");
        }
        View view = MainActivity.this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    } else if (requestCode == 2002 && resultCode != RESULT_OK) {
        // search was init from the toolbar, so return focus to the toolbar
        mToolbar.performLongClick();
    } else if (requestCode == 423 && resultCode == RESULT_OK) {
        ((OverviewPagerAdapterComment) adapter).mCurrentComments.doResult(data);
    } else if (requestCode == 940) {
        if (adapter != null && adapter.getCurrentFragment() != null) {
            if (resultCode == RESULT_OK) {
                ArrayList<Integer> posts = data.getIntegerArrayListExtra("seen");
                ((SubmissionsView) adapter.getCurrentFragment()).adapter.refreshView(posts);
                if (data.hasExtra("lastPage") && data.getIntExtra("lastPage", 0) != 0 && ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager) {
                    ((LinearLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).scrollToPositionWithOffset(data.getIntExtra("lastPage", 0) + 1, mToolbar.getHeight());
                }
            } else {
                ((SubmissionsView) adapter.getCurrentFragment()).adapter.refreshView();
            }
        }
    } else if (requestCode == RESET_ADAPTER_RESULT) {
        resetAdapter();
        setDrawerSubList();
    } else if (requestCode == TUTORIAL_RESULT) {
        UserSubscriptions.doMainActivitySubs(this);
    } else if (requestCode == INBOX_RESULT) {
        // update notification badge
        new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (requestCode == 3333) {
        this.data = data;
        if (doImage != null) {
            Handler handler = new Handler();
            handler.post(doImage);
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
/* todo  if(resultCode == 4 && UserSubscriptions.hasChanged){
            UserSubscriptions.hasChanged = false;
            sideArrayAdapter.setSideItems(UserSubscriptions.getAllSubreddits(this));
            sideArrayAdapter.notifyDataSetChanged();
        }*/
}
Also used : Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point)

Example 73 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Slide by ccrama.

the class MainActivity method setupSubredditSearchToolbar.

/**
 * If the user has the Subreddit Search method set to "long press on toolbar title", an
 * OnLongClickListener needs to be set for the toolbar as well as handling all of the relevant
 * onClicks for the views of the search bar.
 */
private void setupSubredditSearchToolbar() {
    if (!NetworkUtil.isConnected(this)) {
        findViewById(R.id.drawer_divider).setVisibility(View.GONE);
    } else {
        if ((SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && usedArray != null && !usedArray.isEmpty()) {
            if (findViewById(R.id.drawer_divider) != null) {
                if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
                    findViewById(R.id.drawer_divider).setVisibility(View.GONE);
                } else {
                    findViewById(R.id.drawer_divider).setVisibility(View.VISIBLE);
                }
            }
            final ListView TOOLBAR_SEARCH_SUGGEST_LIST = (ListView) findViewById(R.id.toolbar_search_suggestions_list);
            final ArrayList<String> subs_copy = new ArrayList<>(usedArray);
            final SideArrayAdapter TOOLBAR_SEARCH_SUGGEST_ADAPTER = new SideArrayAdapter(this, subs_copy, UserSubscriptions.getAllSubreddits(this), TOOLBAR_SEARCH_SUGGEST_LIST);
            if (TOOLBAR_SEARCH_SUGGEST_LIST != null) {
                TOOLBAR_SEARCH_SUGGEST_LIST.setAdapter(TOOLBAR_SEARCH_SUGGEST_ADAPTER);
            }
            if (mToolbar != null) {
                mToolbar.setOnLongClickListener(new View.OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View v) {
                        final AutoCompleteTextView GO_TO_SUB_FIELD = (AutoCompleteTextView) findViewById(R.id.toolbar_search);
                        final ImageView CLOSE_BUTTON = (ImageView) findViewById(R.id.close_search_toolbar);
                        final CardView SUGGESTIONS_BACKGROUND = (CardView) findViewById(R.id.toolbar_search_suggestions);
                        // if the view mode is set to Subreddit Tabs, save the title ("Slide" or "Slide (debug)")
                        tabViewModeTitle = (!SettingValues.single) ? getSupportActionBar().getTitle().toString() : null;
                        getSupportActionBar().setTitle(// clear title to make room for search field
                        "");
                        if (GO_TO_SUB_FIELD != null && CLOSE_BUTTON != null && SUGGESTIONS_BACKGROUND != null) {
                            GO_TO_SUB_FIELD.setVisibility(View.VISIBLE);
                            CLOSE_BUTTON.setVisibility(View.VISIBLE);
                            SUGGESTIONS_BACKGROUND.setVisibility(View.VISIBLE);
                            // run enter animations
                            enterAnimationsForToolbarSearch(ANIMATE_DURATION, SUGGESTIONS_BACKGROUND, GO_TO_SUB_FIELD, CLOSE_BUTTON);
                            // Get focus of the search field and show the keyboard
                            GO_TO_SUB_FIELD.requestFocus();
                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                            // Close the search UI and keyboard when clicking the close button
                            CLOSE_BUTTON.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    final View view = MainActivity.this.getCurrentFocus();
                                    if (view != null) {
                                        // Hide the keyboard
                                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                                    }
                                    // run the exit animations
                                    exitAnimationsForToolbarSearch(ANIMATE_DURATION, SUGGESTIONS_BACKGROUND, GO_TO_SUB_FIELD, CLOSE_BUTTON);
                                    // clear sub text when close button is clicked
                                    GO_TO_SUB_FIELD.setText("");
                                }
                            });
                            GO_TO_SUB_FIELD.setOnEditorActionListener(new TextView.OnEditorActionListener() {

                                @Override
                                public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
                                    if (arg1 == EditorInfo.IME_ACTION_SEARCH) {
                                        // If it the input text doesn't match a subreddit from the list exactly, openInSubView is true
                                        if (sideArrayAdapter.fitems == null || sideArrayAdapter.openInSubView || !usedArray.contains(GO_TO_SUB_FIELD.getText().toString().toLowerCase(Locale.ENGLISH))) {
                                            Intent intent = new Intent(MainActivity.this, SubredditView.class);
                                            intent.putExtra(SubredditView.EXTRA_SUBREDDIT, GO_TO_SUB_FIELD.getText().toString());
                                            MainActivity.this.startActivityForResult(intent, 2002);
                                        } else {
                                            if (commentPager && adapter instanceof OverviewPagerAdapterComment) {
                                                openingComments = null;
                                                toOpenComments = -1;
                                                ((OverviewPagerAdapterComment) adapter).size = (usedArray.size() + 1);
                                                adapter.notifyDataSetChanged();
                                                if (usedArray.contains(GO_TO_SUB_FIELD.getText().toString().toLowerCase(Locale.ENGLISH))) {
                                                    doPageSelectedComments(usedArray.indexOf(GO_TO_SUB_FIELD.getText().toString().toLowerCase(Locale.ENGLISH)));
                                                } else {
                                                    doPageSelectedComments(usedArray.indexOf(sideArrayAdapter.fitems.get(0)));
                                                }
                                            }
                                            if (usedArray.contains(GO_TO_SUB_FIELD.getText().toString().toLowerCase(Locale.ENGLISH))) {
                                                pager.setCurrentItem(usedArray.indexOf(GO_TO_SUB_FIELD.getText().toString().toLowerCase(Locale.ENGLISH)));
                                            } else {
                                                pager.setCurrentItem(usedArray.indexOf(sideArrayAdapter.fitems.get(0)));
                                            }
                                        }
                                        View view = MainActivity.this.getCurrentFocus();
                                        if (view != null) {
                                            // Hide the keyboard
                                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                                        }
                                        SUGGESTIONS_BACKGROUND.setVisibility(View.GONE);
                                        GO_TO_SUB_FIELD.setVisibility(View.GONE);
                                        CLOSE_BUTTON.setVisibility(View.GONE);
                                        if (SettingValues.single) {
                                            getSupportActionBar().setTitle(selectedSub);
                                        } else {
                                            // Set the title back to "Slide" or "Slide (debug)"
                                            getSupportActionBar().setTitle(tabViewModeTitle);
                                        }
                                    }
                                    return false;
                                }
                            });
                            GO_TO_SUB_FIELD.addTextChangedListener(new TextWatcher() {

                                @Override
                                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                                }

                                @Override
                                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                                }

                                @Override
                                public void afterTextChanged(Editable editable) {
                                    final String RESULT = GO_TO_SUB_FIELD.getText().toString().replaceAll(" ", "");
                                    TOOLBAR_SEARCH_SUGGEST_ADAPTER.getFilter().filter(RESULT);
                                }
                            });
                        }
                        return true;
                    }
                });
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) CardView(android.support.v7.widget.CardView) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) SideArrayAdapter(me.ccrama.redditslide.Adapters.SideArrayAdapter) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 74 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project Slide by ccrama.

the class SideArrayAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (position < fitems.size()) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.subforsublist, parent, false);
        final String sub;
        final String base = fitems.get(position);
        if (multiToMatch.containsKey(fitems.get(position)) && !fitems.get(position).contains("/m/")) {
            sub = multiToMatch.get(fitems.get(position));
        } else {
            sub = fitems.get(position);
        }
        final TextView t = ((TextView) convertView.findViewById(R.id.name));
        t.setText(sub);
        if (height == 0) {
            final View finalConvertView = convertView;
            convertView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    height = finalConvertView.getHeight();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        finalConvertView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        finalConvertView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            });
        }
        final String subreddit = (sub.contains("+") || sub.contains("/m/")) ? sub : SantitizeField.sanitizeString(sub.replace(getContext().getString(R.string.search_goto) + " ", ""));
        convertView.findViewById(R.id.color).setBackgroundResource(R.drawable.circle);
        convertView.findViewById(R.id.color).getBackground().setColorFilter(Palette.getColor(subreddit), PorterDuff.Mode.MULTIPLY);
        convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (base.startsWith(getContext().getString(R.string.search_goto) + " ") || !((MainActivity) getContext()).usedArray.contains(base)) {
                    try {
                        // Hide the toolbar search UI without an animation because we're starting a new activity
                        if ((SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                            ((MainActivity) getContext()).findViewById(R.id.toolbar_search_suggestions).setVisibility(View.GONE);
                            ((MainActivity) getContext()).findViewById(R.id.toolbar_search).setVisibility(View.GONE);
                            ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).setVisibility(View.GONE);
                            // Play the exit animations of the search toolbar UI to avoid the animations failing to animate upon the next time
                            // the search toolbar UI is called. Set animation to 0 because the UI is already hidden.
                            ((MainActivity) getContext()).exitAnimationsForToolbarSearch(0, ((CardView) ((MainActivity) getContext()).findViewById(R.id.toolbar_search_suggestions)), ((AutoCompleteTextView) ((MainActivity) getContext()).findViewById(R.id.toolbar_search)), ((ImageView) ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar)));
                            if (SettingValues.single) {
                                ((MainActivity) getContext()).getSupportActionBar().setTitle(((MainActivity) getContext()).selectedSub);
                            } else {
                                ((MainActivity) getContext()).getSupportActionBar().setTitle(((MainActivity) getContext()).tabViewModeTitle);
                            }
                        }
                    } catch (NullPointerException npe) {
                        Log.e(getClass().getName(), npe.getMessage());
                    }
                    Intent inte = new Intent(getContext(), SubredditView.class);
                    inte.putExtra(SubredditView.EXTRA_SUBREDDIT, subreddit);
                    ((Activity) getContext()).startActivityForResult(inte, 2001);
                } else {
                    if (((MainActivity) getContext()).commentPager && ((MainActivity) getContext()).adapter instanceof MainActivity.OverviewPagerAdapterComment) {
                        ((MainActivity) getContext()).openingComments = null;
                        ((MainActivity) getContext()).toOpenComments = -1;
                        ((MainActivity.OverviewPagerAdapterComment) ((MainActivity) getContext()).adapter).size = (((MainActivity) getContext()).usedArray.size() + 1);
                        ((MainActivity) getContext()).reloadItemNumber = ((MainActivity) getContext()).usedArray.indexOf(base);
                        ((MainActivity) getContext()).adapter.notifyDataSetChanged();
                        ((MainActivity) getContext()).doPageSelectedComments(((MainActivity) getContext()).usedArray.indexOf(base));
                        ((MainActivity) getContext()).reloadItemNumber = -2;
                    }
                    try {
                        // Hide the toolbar search UI with an animation because we're just changing tabs
                        if ((SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                            ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
                        }
                    } catch (NullPointerException npe) {
                        Log.e(getClass().getName(), npe.getMessage());
                    }
                    ((MainActivity) getContext()).pager.setCurrentItem(((MainActivity) getContext()).usedArray.indexOf(base));
                    ((MainActivity) getContext()).drawerLayout.closeDrawers();
                    if (((MainActivity) getContext()).drawerSearch != null) {
                        ((MainActivity) getContext()).drawerSearch.setText("");
                    }
                }
                InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        });
        convertView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                try {
                    // Hide the toolbar search UI without an animation because we're starting a new activity
                    if ((SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                        ((MainActivity) getContext()).findViewById(R.id.toolbar_search_suggestions).setVisibility(View.GONE);
                        ((MainActivity) getContext()).findViewById(R.id.toolbar_search).setVisibility(View.GONE);
                        ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).setVisibility(View.GONE);
                        // Play the exit animations of the search toolbar UI to avoid the animations failing to animate upon the next time
                        // the search toolbar UI is called. Set animation to 0 because the UI is already hidden.
                        ((MainActivity) getContext()).exitAnimationsForToolbarSearch(0, ((CardView) ((MainActivity) getContext()).findViewById(R.id.toolbar_search_suggestions)), ((AutoCompleteTextView) ((MainActivity) getContext()).findViewById(R.id.toolbar_search)), ((ImageView) ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar)));
                        if (SettingValues.single) {
                            ((MainActivity) getContext()).getSupportActionBar().setTitle(((MainActivity) getContext()).selectedSub);
                        } else {
                            ((MainActivity) getContext()).getSupportActionBar().setTitle(((MainActivity) getContext()).tabViewModeTitle);
                        }
                    }
                } catch (NullPointerException npe) {
                    Log.e(getClass().getName(), npe.getMessage());
                }
                Intent inte = new Intent(getContext(), SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, subreddit);
                ((Activity) getContext()).startActivityForResult(inte, 2001);
                InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                return true;
            }
        });
    } else {
        if ((fitems.size() * height) < parentL.getHeight() && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_DRAWER || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH)) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.spacer, parent, false);
            ViewGroup.LayoutParams params = convertView.findViewById(R.id.height).getLayoutParams();
            params.height = (parentL.getHeight() - (getCount() - 1) * height);
            convertView.setLayoutParams(params);
        } else {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.spacer, parent, false);
            ViewGroup.LayoutParams params = convertView.findViewById(R.id.height).getLayoutParams();
            params.height = 0;
            convertView.setLayoutParams(params);
        }
    }
    return convertView;
}
Also used : ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) SubredditView(me.ccrama.redditslide.Activities.SubredditView) InputMethodManager(android.view.inputmethod.InputMethodManager) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ImageView(android.widget.ImageView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) CardView(android.support.v7.widget.CardView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 75 with AutoCompleteTextView

use of android.widget.AutoCompleteTextView in project MGit by maks.

the class CommitAction method commit.

private void commit() {
    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    LayoutInflater inflater = mActivity.getLayoutInflater();
    View layout = inflater.inflate(R.layout.dialog_commit, null);
    final EditText commitMsg = (EditText) layout.findViewById(R.id.commitMsg);
    final AutoCompleteTextView commitAuthor = (AutoCompleteTextView) layout.findViewById(R.id.commitAuthor);
    final CheckBox isAmend = (CheckBox) layout.findViewById(R.id.isAmend);
    final CheckBox autoStage = (CheckBox) layout.findViewById(R.id.autoStage);
    HashSet<Author> authors = new HashSet<Author>();
    try {
        Iterable<RevCommit> commits = mRepo.getGit().log().setMaxCount(500).call();
        for (RevCommit commit : commits) {
            authors.add(new Author(commit.getAuthorIdent()));
        }
    } catch (Exception e) {
    }
    String profileUsername = Profile.getUsername(mActivity.getApplicationContext());
    String profileEmail = Profile.getEmail(mActivity.getApplicationContext());
    if (profileUsername != null && !profileUsername.equals("") && profileEmail != null && !profileEmail.equals("")) {
        authors.add(new Author(profileUsername, profileEmail));
    }
    ArrayList<Author> authorList = new ArrayList<Author>(authors);
    Collections.sort(authorList);
    AuthorsAdapter adapter = new AuthorsAdapter(mActivity, authorList);
    commitAuthor.setAdapter(adapter);
    isAmend.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                commitMsg.setText(mRepo.getLastCommitFullMsg());
            } else {
                commitMsg.setText("");
            }
        }
    });
    final AlertDialog d = builder.setTitle(R.string.dialog_commit_title).setView(layout).setPositiveButton(R.string.dialog_commit_positive_label, null).setNegativeButton(R.string.label_cancel, new DummyDialogListener()).create();
    d.setOnShowListener(new DialogInterface.OnShowListener() {

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

                @Override
                public void onClick(View view) {
                    String msg = commitMsg.getText().toString();
                    String author = commitAuthor.getText().toString().trim();
                    String authorName = null, authorEmail = null;
                    int ltidx;
                    if (msg.trim().equals("")) {
                        commitMsg.setError(mActivity.getString(R.string.error_no_commit_msg));
                        return;
                    }
                    if (!author.equals("")) {
                        ltidx = author.indexOf('<');
                        if (!author.endsWith(">") || ltidx == -1) {
                            commitAuthor.setError(mActivity.getString(R.string.error_invalid_author));
                            return;
                        }
                        authorName = author.substring(0, ltidx);
                        authorEmail = author.substring(ltidx + 1, author.length() - 1);
                    }
                    boolean amend = isAmend.isChecked();
                    boolean stage = autoStage.isChecked();
                    commit(msg, amend, stage, authorName, authorEmail);
                    d.dismiss();
                }
            });
        }
    });
    d.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) HashSet(java.util.HashSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) DummyDialogListener(me.sheimi.sgit.dialogs.DummyDialogListener) CompoundButton(android.widget.CompoundButton) 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