Java源码示例:com.pluscubed.logcat.data.SortedFilterArrayAdapter

示例1
public static void showFilterDialogForRecording(final Context context, final String queryFilterText,
                                                final String logLevelText, final List<String> filterQuerySuggestions,
                                                final Callback<FilterQueryWithLevel> callback) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    @SuppressLint("InflateParams") View filterView = inflater.inflate(R.layout.dialog_recording_filter, null, false);

    // add suggestions to autocompletetextview
    final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) filterView.findViewById(android.R.id.text1);
    autoCompleteTextView.setText(queryFilterText);

    SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<String>(
            context, R.layout.list_item_dropdown, filterQuerySuggestions);
    autoCompleteTextView.setAdapter(suggestionAdapter);

    // set values on spinner to be the log levels
    final Spinner spinner = (Spinner) filterView.findViewById(R.id.spinner);

    // put the word "default" after whatever the default log level is
    CharSequence[] logLevels = context.getResources().getStringArray(R.array.log_levels);
    String defaultLogLevel = Character.toString(PreferenceHelper.getDefaultLogLevelPreference(context));
    int index = ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values), defaultLogLevel);
    logLevels[index] = logLevels[index].toString() + " " + context.getString(R.string.default_in_parens);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(
            context, android.R.layout.simple_spinner_item, logLevels);
    adapter.setDropDownViewResource(R.layout.list_item_dropdown);
    spinner.setAdapter(adapter);

    // in case the user has changed it, choose the pre-selected log level
    spinner.setSelection(ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values),
            logLevelText));

    // create alertdialog for the "Filter..." button
    new MaterialDialog.Builder(context)
            .title(R.string.title_filter)
            .customView(filterView, true)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    int logLevelIdx = spinner.getSelectedItemPosition();
                    String[] logLevelValues = context.getResources().getStringArray(R.array.log_levels_values);
                    String logLevelValue = logLevelValues[logLevelIdx];

                    String filterQuery = autoCompleteTextView.getText().toString();

                    callback.onCallback(new FilterQueryWithLevel(filterQuery, logLevelValue));
                }
            })
            .show();

}
 
示例2
private void showAddFilterDialog(final FilterAdapter filterAdapter) {

        // show a popup to add a new filter text
        LayoutInflater inflater = getLayoutInflater();
        @SuppressLint("InflateParams")
        final AutoCompleteTextView editText =
                (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false);

        // show suggestions as the user types
        List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet);
        SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
                this, R.layout.list_item_dropdown, suggestions);
        editText.setAdapter(suggestionAdapter);

        final MaterialDialog alertDialog = new MaterialDialog.Builder(this)
                .title(R.string.add_filter)
                .positiveText(android.R.string.ok)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        handleNewFilterText(editText.getText().toString(), filterAdapter);
                        dialog.dismiss();
                    }
                })
                .negativeText(android.R.string.cancel)
                .customView(editText, true)
                .build();

        // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked
        editText.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // dismiss soft keyboard

                    handleNewFilterText(editText.getText().toString(), filterAdapter);

                    alertDialog.dismiss();
                    return true;
                }
                return false;
            }
        });

        alertDialog.show();

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, 0);

    }
 
示例3
public static void showFilterDialogForRecording(final Context context, final String queryFilterText,
                                                final String logLevelText, final List<String> filterQuerySuggestions,
                                                final Callback<FilterQueryWithLevel> callback) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    @SuppressLint("InflateParams") View filterView = inflater.inflate(R.layout.dialog_recording_filter, null, false);

    // add suggestions to autocompletetextview
    final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) filterView.findViewById(android.R.id.text1);
    autoCompleteTextView.setText(queryFilterText);

    SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<String>(
            context, R.layout.list_item_dropdown, filterQuerySuggestions);
    autoCompleteTextView.setAdapter(suggestionAdapter);

    // set values on spinner to be the log levels
    final Spinner spinner = (Spinner) filterView.findViewById(R.id.spinner);

    // put the word "default" after whatever the default log level is
    CharSequence[] logLevels = context.getResources().getStringArray(R.array.log_levels);
    String defaultLogLevel = Character.toString(PreferenceHelper.getDefaultLogLevelPreference(context));
    int index = ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values), defaultLogLevel);
    logLevels[index] = logLevels[index].toString() + " " + context.getString(R.string.default_in_parens);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(
            context, android.R.layout.simple_spinner_item, logLevels);
    adapter.setDropDownViewResource(R.layout.list_item_dropdown);
    spinner.setAdapter(adapter);

    // in case the user has changed it, choose the pre-selected log level
    spinner.setSelection(ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values),
            logLevelText));

    // create alertdialog for the "Filter..." button
    new MaterialDialog.Builder(context)
            .title(R.string.title_filter)
            .customView(filterView, true)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    int logLevelIdx = spinner.getSelectedItemPosition();
                    String[] logLevelValues = context.getResources().getStringArray(R.array.log_levels_values);
                    String logLevelValue = logLevelValues[logLevelIdx];

                    String filterQuery = autoCompleteTextView.getText().toString();

                    callback.onCallback(new FilterQueryWithLevel(filterQuery, logLevelValue));
                }
            })
            .show();

}
 
示例4
private void showAddFilterDialog(final FilterAdapter filterAdapter) {

        // show a popup to add a new filter text
        LayoutInflater inflater = getLayoutInflater();
        @SuppressLint("InflateParams")
        final AutoCompleteTextView editText =
                (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false);

        // show suggestions as the user types
        List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet);
        SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
                this, R.layout.list_item_dropdown, suggestions);
        editText.setAdapter(suggestionAdapter);

        final MaterialDialog alertDialog = new MaterialDialog.Builder(this)
                .title(R.string.add_filter)
                .positiveText(android.R.string.ok)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        handleNewFilterText(editText.getText().toString(), filterAdapter);
                        dialog.dismiss();
                    }
                })
                .negativeText(android.R.string.cancel)
                .customView(editText, true)
                .build();

        // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked
        editText.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // dismiss soft keyboard

                    handleNewFilterText(editText.getText().toString(), filterAdapter);

                    alertDialog.dismiss();
                    return true;
                }
                return false;
            }
        });

        alertDialog.show();

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, 0);

    }
 
示例5
public static void showFilterDialogForRecording(final Context context, final String queryFilterText,
                                                final String logLevelText, final List<String> filterQuerySuggestions,
                                                final Callback<FilterQueryWithLevel> callback) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    @SuppressLint("InflateParams") View filterView = inflater.inflate(R.layout.dialog_recording_filter, null, false);

    // add suggestions to autocompletetextview
    final AutoCompleteTextView autoCompleteTextView = filterView.findViewById(android.R.id.text1);
    autoCompleteTextView.setText(queryFilterText);

    SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
            context, R.layout.list_item_dropdown, filterQuerySuggestions);
    autoCompleteTextView.setAdapter(suggestionAdapter);

    // set values on spinner to be the log levels
    final Spinner spinner = filterView.findViewById(R.id.spinner);

    // put the word "default" after whatever the default log level is
    CharSequence[] logLevels = context.getResources().getStringArray(R.array.log_levels);
    String defaultLogLevel = Character.toString(PreferenceHelper.getDefaultLogLevelPreference(context));
    int index = ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values), defaultLogLevel);
    logLevels[index] = logLevels[index].toString() + " " + context.getString(R.string.default_in_parens);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(
            context, android.R.layout.simple_spinner_item, logLevels);
    adapter.setDropDownViewResource(R.layout.list_item_dropdown);
    spinner.setAdapter(adapter);

    // in case the user has changed it, choose the pre-selected log level
    spinner.setSelection(ArrayUtil.indexOf(context.getResources().getStringArray(R.array.log_levels_values),
            logLevelText));

    // create alertdialog for the "Filter..." button
    new MaterialDialog.Builder(context)
            .title(R.string.title_filter)
            .customView(filterView, true)
            .negativeText(android.R.string.cancel)
            .positiveText(android.R.string.ok)
            .onPositive((dialog, which) -> {
                int logLevelIdx = spinner.getSelectedItemPosition();
                String[] logLevelValues = context.getResources().getStringArray(R.array.log_levels_values);
                String logLevelValue = logLevelValues[logLevelIdx];

                String filterQuery = autoCompleteTextView.getText().toString();

                callback.onCallback(new FilterQueryWithLevel(filterQuery, logLevelValue));
            })
            .show();

}
 
示例6
private void showAddFilterDialog(final FilterAdapter filterAdapter) {

        // show a popup to add a new filter text
        LayoutInflater inflater = getLayoutInflater();
        @SuppressLint("InflateParams")
        final AutoCompleteTextView editText =
                (AutoCompleteTextView) inflater.inflate(R.layout.dialog_new_filter, null, false);

        // show suggestions as the user types
        List<String> suggestions = new ArrayList<>(mSearchSuggestionsSet);
        SortedFilterArrayAdapter<String> suggestionAdapter = new SortedFilterArrayAdapter<>(
                this, R.layout.list_item_dropdown, suggestions);
        editText.setAdapter(suggestionAdapter);

        final MaterialDialog alertDialog = new MaterialDialog.Builder(this)
                .title(R.string.add_filter)
                .positiveText(android.R.string.ok)
                .onPositive((dialog, which) -> {
                    handleNewFilterText(editText.getText().toString(), filterAdapter);
                    dialog.dismiss();
                })
                .negativeText(android.R.string.cancel)
                .customView(editText, true)
                .build();

        // when 'Done' is clicked (i.e. enter button), do the same as when "OK" is clicked
        editText.setOnEditorActionListener((v, actionId, event) -> {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                // dismiss soft keyboard

                handleNewFilterText(editText.getText().toString(), filterAdapter);

                alertDialog.dismiss();
                return true;
            }
            return false;
        });

        alertDialog.show();

        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, 0);

    }