Search in sources :

Example 1 with ACTION_PROCESS_TEXT

use of com.ichi2.compat.Compat.ACTION_PROCESS_TEXT in project AnkiChinaAndroid by ankichinateam.

the class AbstractFlashcardViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Timber.d("onCreate()");
    preferences = restorePreferences();
    mCardAppearance = CardAppearance.create(new ReviewerCustomFonts(this.getBaseContext()), preferences);
    super.onCreate(savedInstanceState);
    setContentView(getContentViewAttr(mPrefFullscreenReview));
    // Make ACTION_PROCESS_TEXT for in-app searching possible on > Android 4.0
    getDelegate().setHandleNativeActionModesEnabled(true);
    // initNavigationDrawer(mainView);
    Toolbar toolbar = findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        // enable ActionBar app icon to behave as action to toggle nav drawer
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        // int[] attrs = new int[] {
        // R.attr.reviewStatusBarColor,
        // };
        // TypedArray ta = obtainStyledAttributes(attrs);
        // toolbar.setBackground(ta.getDrawable(0));
        mTitle = toolbar.findViewById(R.id.toolbar_title);
        mTitle.setVisibility(View.VISIBLE);
    // Decide which action to take when the navigation button is tapped.
    // toolbar.setNavigationOnClickListener(v -> onNavigationPressed());
    }
    mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mFreeVipCount = preferences.getInt("speak_count", 0);
    mVip = preferences.getBoolean(Consts.KEY_IS_VIP, false);
    mFreeOnlineEngineCount = preferences.getInt(Consts.KEY_REST_ONLINE_SPEAK_COUNT, 1000);
    // mFreeVipRecordDay = preferences.getInt("speak_count_day", 0);
    // Calendar calendar = Calendar.getInstance();
    // if (mFreeVipRecordDay != calendar.get(Calendar.DAY_OF_YEAR)) {//已经不是记录里的同一天
    // mFreeVipCount = 0;
    // preferences.edit().putInt("speak_count", mFreeVipCount)
    // .putInt("speak_count_day", calendar.get(Calendar.DAY_OF_YEAR)).apply();
    // }
    mainHandler = new Handler();
}
Also used : ReviewerCustomFonts(com.ichi2.anki.reviewer.ReviewerCustomFonts) Handler(android.os.Handler) MissingImageHandler(com.ichi2.anki.cardviewer.MissingImageHandler) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with ACTION_PROCESS_TEXT

use of com.ichi2.compat.Compat.ACTION_PROCESS_TEXT in project AnkiChinaAndroid by ankichinateam.

the class CardBrowser method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    Timber.d("onCreateOptionsMenu()");
    mActionBarMenu = menu;
    if (!mInMultiSelectMode) {
        // restore drawer click listener and icon
        // restoreDrawerIcon();
        getMenuInflater().inflate(R.menu.card_browser, menu);
        mSaveSearchItem = menu.findItem(R.id.action_save_search);
        // the searchview's query always starts empty.
        mSaveSearchItem.setVisible(false);
        mMySearchesItem = menu.findItem(R.id.action_list_my_searches);
        JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
        mMySearchesItem.setVisible(savedFiltersObj != null && savedFiltersObj.length() > 0);
        mSearchItem = menu.findItem(R.id.action_search);
        mSearchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                // SearchView doesn't support empty queries so we always reset the search when collapsing
                mSearchTerms = "";
                mSearchView.setQuery(mSearchTerms, false);
                searchCards();
                // invalidate options menu so that disappeared icons would appear again
                supportInvalidateOptionsMenu();
                return true;
            }
        });
        mSearchView = (SearchView) mSearchItem.getActionView();
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextChange(String newText) {
                mSaveSearchItem.setVisible(!TextUtils.isEmpty(newText));
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(String query) {
                onSearch();
                mSearchView.clearFocus();
                return true;
            }
        });
        mSearchView.setOnSearchClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // Provide SearchView with the previous search terms
                mSearchView.setQuery(mSearchTerms, false);
            }
        });
        // Fixes #6500 - keep the search consistent
        if (!TextUtils.isEmpty(mSearchTerms)) {
            mSearchItem.expandActionView();
            mSearchView.setQuery(mSearchTerms, false);
        }
    } else {
        // multi-select mode
        getMenuInflater().inflate(R.menu.card_browser_multiselect, menu);
    // showBackIcon();
    }
    if (mActionBarMenu != null && mActionBarMenu.findItem(R.id.action_undo) != null) {
        MenuItem undo = mActionBarMenu.findItem(R.id.action_undo);
        undo.setVisible(getCol().undoAvailable());
        undo.setTitle(getResources().getString(R.string.studyoptions_congrats_undo, getCol().undoName(getResources())));
    }
    // Maybe we were called from ACTION_PROCESS_TEXT.
    // In that case we already fill in the search.
    Intent intent = getIntent();
    Compat compat = CompatHelper.getCompat();
    if (intent.getAction() == compat.ACTION_PROCESS_TEXT) {
        CharSequence search = intent.getCharSequenceExtra(compat.EXTRA_PROCESS_TEXT);
        if (search != null && search.length() != 0) {
            Timber.i("CardBrowser :: Called with search intent: %s", search.toString());
            mSearchView.setQuery(search, true);
            intent.setAction(Intent.ACTION_DEFAULT);
        }
    }
    mPreviewItem = menu.findItem(R.id.action_preview);
    onSelectionChanged();
    updatePreviewMenuItem();
    return super.onCreateOptionsMenu(menu);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) SearchView(androidx.appcompat.widget.SearchView) Compat(com.ichi2.compat.Compat) MenuItem(android.view.MenuItem) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView)

Example 3 with ACTION_PROCESS_TEXT

use of com.ichi2.compat.Compat.ACTION_PROCESS_TEXT in project Anki-Android by ankidroid.

the class AbstractFlashcardViewer method onCreate.

// ----------------------------------------------------------------------------
// ANDROID METHODS
// ----------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
    Timber.d("onCreate()");
    restorePreferences();
    mTagsDialogFactory = new TagsDialogFactory(this).attachToActivity(this);
    super.onCreate(savedInstanceState);
    setContentView(getContentViewAttr(mPrefFullscreenReview));
    // Make ACTION_PROCESS_TEXT for in-app searching possible on > Android 4.0
    getDelegate().setHandleNativeActionModesEnabled(true);
    View mainView = findViewById(android.R.id.content);
    initNavigationDrawer(mainView);
    mPreviousAnswerIndicator = new PreviousAnswerIndicator(findViewById(R.id.choosen_answer));
    mShortAnimDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
}
Also used : PreviousAnswerIndicator(com.ichi2.anki.reviewer.PreviousAnswerIndicator) TagsDialogFactory(com.ichi2.anki.dialogs.tags.TagsDialogFactory) View(android.view.View) WebView(android.webkit.WebView)

Example 4 with ACTION_PROCESS_TEXT

use of com.ichi2.compat.Compat.ACTION_PROCESS_TEXT in project Anki-Android by ankidroid.

the class CardBrowser method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    Timber.d("onCreateOptionsMenu()");
    mActionBarMenu = menu;
    if (!mInMultiSelectMode) {
        // restore drawer click listener and icon
        restoreDrawerIcon();
        getMenuInflater().inflate(R.menu.card_browser, menu);
        mSaveSearchItem = menu.findItem(R.id.action_save_search);
        // the searchview's query always starts empty.
        mSaveSearchItem.setVisible(false);
        mMySearchesItem = menu.findItem(R.id.action_list_my_searches);
        JSONObject savedFiltersObj = getCol().get_config("savedFilters", (JSONObject) null);
        mMySearchesItem.setVisible(savedFiltersObj != null && savedFiltersObj.length() > 0);
        mSearchItem = menu.findItem(R.id.action_search);
        mSearchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                // SearchView doesn't support empty queries so we always reset the search when collapsing
                mSearchTerms = "";
                mSearchView.setQuery(mSearchTerms, false);
                searchCards();
                // invalidate options menu so that disappeared icons would appear again
                supportInvalidateOptionsMenu();
                mTempSearchQuery = null;
                return true;
            }
        });
        mSearchView = (CardBrowserSearchView) mSearchItem.getActionView();
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextChange(String newText) {
                if (mSearchView.shouldIgnoreValueChange()) {
                    return true;
                }
                mSaveSearchItem.setVisible(!TextUtils.isEmpty(newText));
                mTempSearchQuery = newText;
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(String query) {
                onSearch();
                mSearchView.clearFocus();
                return true;
            }
        });
        // Fixes #9010 - consistent search after drawer change calls supportInvalidateOptionsMenu (mTempSearchQuery)
        if (!TextUtils.isEmpty(mTempSearchQuery) || !TextUtils.isEmpty(mSearchTerms)) {
            // This calls mSearchView.setOnSearchClickListener
            mSearchItem.expandActionView();
            String toUse = !TextUtils.isEmpty(mTempSearchQuery) ? mTempSearchQuery : mSearchTerms;
            mSearchView.setQuery(toUse, false);
        }
        mSearchView.setOnSearchClickListener(v -> {
            // Provide SearchView with the previous search terms
            mSearchView.setQuery(mSearchTerms, false);
        });
    } else {
        // multi-select mode
        getMenuInflater().inflate(R.menu.card_browser_multiselect, menu);
        showBackIcon();
    }
    if (mActionBarMenu != null && mActionBarMenu.findItem(R.id.action_undo) != null) {
        MenuItem undo = mActionBarMenu.findItem(R.id.action_undo);
        undo.setVisible(getCol().undoAvailable());
        undo.setTitle(getResources().getString(R.string.studyoptions_congrats_undo, getCol().undoName(getResources())));
    }
    // Maybe we were called from ACTION_PROCESS_TEXT.
    // In that case we already fill in the search.
    Intent intent = getIntent();
    Compat compat = CompatHelper.getCompat();
    if (compat.ACTION_PROCESS_TEXT.equals(intent.getAction())) {
        CharSequence search = intent.getCharSequenceExtra(compat.EXTRA_PROCESS_TEXT);
        if (search != null && search.length() != 0) {
            Timber.i("CardBrowser :: Called with search intent: %s", search.toString());
            mSearchView.setQuery(search, true);
            intent.setAction(Intent.ACTION_DEFAULT);
        }
    }
    mPreviewItem = menu.findItem(R.id.action_preview);
    onSelectionChanged();
    updatePreviewMenuItem();
    return super.onCreateOptionsMenu(menu);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) SearchView(androidx.appcompat.widget.SearchView) CardBrowserSearchView(com.ichi2.ui.CardBrowserSearchView) LanguageUtil.getLocaleCompat(com.ichi2.utils.LanguageUtil.getLocaleCompat) Compat(com.ichi2.compat.Compat) MenuItem(android.view.MenuItem) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 SearchView (androidx.appcompat.widget.SearchView)2 Compat (com.ichi2.compat.Compat)2 JSONObject (com.ichi2.utils.JSONObject)2 Handler (android.os.Handler)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 MissingImageHandler (com.ichi2.anki.cardviewer.MissingImageHandler)1 TagsDialogFactory (com.ichi2.anki.dialogs.tags.TagsDialogFactory)1 PreviousAnswerIndicator (com.ichi2.anki.reviewer.PreviousAnswerIndicator)1 ReviewerCustomFonts (com.ichi2.anki.reviewer.ReviewerCustomFonts)1 CardBrowserSearchView (com.ichi2.ui.CardBrowserSearchView)1 LanguageUtil.getLocaleCompat (com.ichi2.utils.LanguageUtil.getLocaleCompat)1