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();
}
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);
}
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);
}
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);
}
Aggregations