0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

removed all isHoneycomb() use, removed obsolete workarounds + related logic/resources

This commit is contained in:
Mike Hardy 2018-03-08 13:03:14 -05:00 committed by Tim Rae
parent 13c27a6a1f
commit e91cab5cd4
12 changed files with 25 additions and 157 deletions

View File

@ -4,7 +4,6 @@
<title>AnkidDroid Flashcard</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="file:///android_asset/flashcard.css">
<link rel="stylesheet" type="text/css" href="file:///android_asset/ruby.css">
<link rel="stylesheet" type="text/css" href="file:///android_asset/chess.css">
<style>
::style::

View File

@ -1,17 +0,0 @@
.legacy_ruby_rb {
display: inline-block;
text-align: center;
line-height: 1;
white-space: nowrap;
vertical-align: baseline;
margin: 0;
padding: 0;
}
.legacy_ruby_rt {
display: block;
text-decoration: none;
line-height: 1.2;
font-weight: normal;
font-size: 0.64em;
}

View File

@ -185,9 +185,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
private boolean mPrefShowETA;
private boolean mShowTimer;
protected boolean mPrefWhiteboard;
private boolean mShowTypeAnswerField;
private boolean mInputWorkaround;
private boolean mLongClickWorkaround;
private int mPrefFullscreenReview;
private int mCardZoom;
private int mImageZoom;
@ -363,8 +360,8 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
@Override
public void run() {
Timber.i("AbstractFlashcardViewer:: onEmulatedLongClick");
// Show hint about lookup function if dictionary available and Webview version supports text selection
if (!mDisableClipboard && Lookup.isAvailable() && CompatHelper.isHoneycomb()) {
// Show hint about lookup function if dictionary available
if (!mDisableClipboard && Lookup.isAvailable()) {
String lookupHint = getResources().getString(R.string.lookup_hint);
UIUtils.showThemedToast(AbstractFlashcardViewer.this, lookupHint, false);
}
@ -434,7 +431,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
if (!mDisableClipboard && !mLongClickWorkaround) {
if (!mDisableClipboard) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mTouchStarted = true;
@ -458,32 +455,11 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
} catch (NullPointerException e) {
Timber.e(e, "Error on dispatching touch event");
if (mInputWorkaround) {
Timber.e(e, "Error on using InputWorkaround");
AnkiDroidApp.getSharedPrefs(getBaseContext()).edit().putBoolean("inputWorkaround", false).commit();
AbstractFlashcardViewer.this.finishWithoutAnimation();
}
}
return false;
}
};
private View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (mIsSelecting) {
return false;
}
Timber.i("AbstractFlashcardViewer:: onLongClick");
Vibrator vibratorManager = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibratorManager.vibrate(50);
longClickHandler.postDelayed(startLongClickAction, 300);
return true;
}
};
protected DeckTask.TaskListener mDismissCardHandler = new DeckTask.TaskListener() {
@Override
public void onPreExecute() {
@ -720,7 +696,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
}
StringBuilder sb = new StringBuilder();
if (mUseInputTag) {
// These functions are definde in the JavaScript file assets/scripts/card.js. We get the text back in
// These functions are defined in the JavaScript file assets/scripts/card.js. We get the text back in
// shouldOverrideUrlLoading() in createWebView() in this file.
sb.append("<center>\n<input type=text name=typed id=typeans onfocus=\"taFocus();\" " +
"onblur=\"taBlur(this);\" onKeyPress=\"return taKey(this, event)\" autocomplete=\"off\" ");
@ -733,7 +709,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
sb.append(">\n</center>\n");
} else {
sb.append("<span id=typeans class=\"typePrompt");
if (!mShowTypeAnswerField) {
if (mUseInputTag) {
sb.append(" typeOff");
}
sb.append("\">........</span>");
@ -755,9 +731,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
DiffEngine diffEngine = new DiffEngine();
StringBuilder sb = new StringBuilder();
sb.append("<div");
if (!mUseInputTag && !mShowTypeAnswerField) {
sb.append(" class=\"typeOff\"");
}
sb.append("><code id=typeans>");
if (!TextUtils.isEmpty(userAnswer)) {
// The user did type something.
@ -776,7 +749,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
sb.append(diffedStrings[1]);
}
} else {
if (mShowTypeAnswerField) {
if (!mUseInputTag) {
sb.append(DiffEngine.wrapMissing(correctAnswer));
} else {
sb.append(correctAnswer);
@ -1337,9 +1310,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
mTouchLayer.setOnTouchListener(mGestureListener);
if (!mDisableClipboard && mLongClickWorkaround) {
mTouchLayer.setOnLongClickListener(mLongClickListener);
}
if (!mDisableClipboard) {
mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
}
@ -1467,10 +1437,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
WebView webView = new MyWebView(this);
webView.setWillNotCacheDrawing(true);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
if (CompatHelper.isHoneycomb()) {
// Disable the on-screen zoom buttons for API > 11
webView.getSettings().setDisplayZoomControls(false);
}
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
// Start at the most zoomed-out level
@ -1745,18 +1712,15 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
mPrefHideDueCount = preferences.getBoolean("hideDueCount", false);
mPrefShowETA = preferences.getBoolean("showETA", true);
mUseInputTag = preferences.getBoolean("useInputTag", false) && (CompatHelper.getSdkVersion() >= 15);
mShowTypeAnswerField = (!preferences.getBoolean("writeAnswersDisable", false)) && !mUseInputTag;
// On newer Androids, ignore this setting, which sholud be hidden in the prefs anyway.
mUseInputTag = preferences.getBoolean("useInputTag", false);
// On newer Androids, ignore this setting, which should be hidden in the prefs anyway.
mDisableClipboard = preferences.getString("dictionary", "0").equals("0");
mLongClickWorkaround = preferences.getBoolean("textSelectionLongclickWorkaround", false);
// mDeckFilename = preferences.getString("deckFilename", "");
mNightMode = preferences.getBoolean("invertedColors", false);
mPrefFullscreenReview = Integer.parseInt(preferences.getString("fullscreenMode", "0"));
mCardZoom = preferences.getInt("cardZoom", 100);
mImageZoom = preferences.getInt("imageZoom", 100);
mRelativeButtonSize = preferences.getInt("answerButtonSize", 100);
mInputWorkaround = preferences.getBoolean("inputWorkaround", false);
mSpeakText = preferences.getBoolean("tts", false);
mPrefSafeDisplay = preferences.getBoolean("safeDisplay", false);
mPrefUseTimer = preferences.getBoolean("timeoutAnswer", false);
@ -1793,10 +1757,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
mCustomButtons.put(R.id.action_suspend, Integer.parseInt(preferences.getString("customButtonSuspend", "0")));
mCustomButtons.put(R.id.action_delete, Integer.parseInt(preferences.getString("customButtonDelete", "0")));
if (mLongClickWorkaround) {
mGestureLongclick = GESTURE_LOOKUP;
}
if (preferences.getBoolean("keepScreenOn", false)) {
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@ -2404,7 +2364,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
* field to query
*/
private boolean typeAnswer() {
return mShowTypeAnswerField && null != mTypeCorrect;
return !mUseInputTag && null != mTypeCorrect;
}
@ -2552,10 +2512,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
* Returns true if we should update the content of a single {@link WebView} (called quick update) instead of switch
* between two instances.
* <p>
* Webview switching is needed in some versions of Android when using custom fonts because of a memory leak in
* WebView.
* <p>
* It is also needed to solve a refresh issue on Nook devices.
* This is needed to solve a refresh issue on Nook devices.
*
* @return true if we should use a single WebView
*/
@ -2697,17 +2654,6 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
super(context);
}
@Override
public boolean onCheckIsTextEditor() {
if (mInputWorkaround) {
return true;
} else {
return super.onCheckIsTextEditor();
}
}
@Override
protected void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) {
super.onScrollChanged(horiz, vert, oldHoriz, oldVert);

View File

@ -685,20 +685,13 @@ public class Preferences extends AppCompatPreferenceActivity implements Preferen
PreferenceCategory workarounds = (PreferenceCategory) screen.findPreference("category_workarounds");
if (workarounds != null) {
CheckBoxPreference writeAnswersDisable = (CheckBoxPreference) screen.findPreference("writeAnswersDisable");
CheckBoxPreference useInputTag = (CheckBoxPreference) screen.findPreference("useInputTag");
CheckBoxPreference inputWorkaround = (CheckBoxPreference) screen.findPreference("inputWorkaround");
CheckBoxPreference longclickWorkaround =
(CheckBoxPreference) screen.findPreference("textSelectionLongclickWorkaround");
CheckBoxPreference fixHebrewText = (CheckBoxPreference) screen.findPreference("fixHebrewText");
CheckBoxPreference safeDisplayMode = (CheckBoxPreference) screen.findPreference("safeDisplay");
CompatHelper.removeHiddenPreferences(this.getApplicationContext());
workarounds.removePreference(longclickWorkaround);
workarounds.removePreference(safeDisplayMode);
workarounds.removePreference(writeAnswersDisable);
workarounds.removePreference(inputWorkaround);
if (!CompatHelper.isNook()) {
workarounds.removePreference(safeDisplayMode);
}
if (CompatHelper.getSdkVersion() >= 16) {
workarounds.removePreference(fixHebrewText);
}

View File

@ -331,10 +331,6 @@ public class Reviewer extends AbstractFlashcardViewer {
} else {
menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.enable_whiteboard);
}
if (!CompatHelper.isHoneycomb() && !mDisableClipboard) {
menu.findItem(R.id.action_search_dictionary).setVisible(true).setEnabled(!(mPrefWhiteboard && mShowWhiteboard))
.setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select));
}
if (getCol().getDecks().isDyn(getParentDid())) {
menu.findItem(R.id.action_open_deck_options).setVisible(false);
}

View File

@ -340,11 +340,7 @@ public class DatabaseErrorDialog extends AsyncDialogFragment {
private String getMessage() {
switch (getArguments().getInt("dialogType")) {
case DIALOG_LOAD_FAILED:
if (!CompatHelper.isHoneycomb()) {
// Before honeycomb there's no way to know if the db has actually been corrupted
// so we show a non-specific message.
return res().getString(R.string.open_collection_failed_message, res().getString(R.string.repair_deck));
} else if (databaseCorruptFlag) {
if (databaseCorruptFlag) {
// The sqlite database has been corrupted (DatabaseErrorHandler.onCorrupt() was called)
// Show a specific message appropriate for the situation
return res().getString(R.string.corrupt_db_message, res().getString(R.string.repair_deck));

View File

@ -52,11 +52,6 @@ public class CompatHelper {
return Build.VERSION.SDK_INT;
}
/** Determine if the device is running API level 11 or higher. */
public static boolean isHoneycomb() {
return getSdkVersion() >= Build.VERSION_CODES.HONEYCOMB;
}
/** Determine if the device is running API level 21 or higher. */
public static boolean isLollipop() {
return getSdkVersion() >= Build.VERSION_CODES.LOLLIPOP;
@ -115,10 +110,9 @@ public class CompatHelper {
public static void removeHiddenPreferences(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (getSdkVersion() >= 15) {
preferences.edit().remove("longclickWorkaround").commit();
if (getSdkVersion() >= 15 && !isNook()) {
preferences.edit().remove("safeDisplay").commit();
preferences.edit().remove("inputWorkaround").commit();
}
if (getSdkVersion() >= 16) {
preferences.edit().remove("fixHebrewText").commit();

View File

@ -19,11 +19,9 @@
package com.ichi2.libanki;
import android.annotation.TargetApi;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Build;
import android.widget.Toast;
import com.ichi2.anki.AnkiDroidApp;
@ -57,29 +55,19 @@ public class DB {
/**
* Open a database connection to an ".anki" SQLite file.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public DB(String ankiFilename) {
// Since API 11 we can provide a custom error handler which doesn't delete the database on corruption
if (CompatHelper.isHoneycomb()) {
mDatabase = SQLiteDatabase.openDatabase(ankiFilename, null,
mDatabase = SQLiteDatabase.openDatabase(ankiFilename, null,
(SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY)
| SQLiteDatabase.NO_LOCALIZED_COLLATORS, new MyDbErrorHandler());
} else {
mDatabase = SQLiteDatabase.openDatabase(ankiFilename, null,
(SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY)
| SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}
if (mDatabase != null) {
// TODO: we can remove this eventually once everyone has stopped using old AnkiDroid clients with WAL
CompatHelper.getCompat().disableDatabaseWriteAheadLogging(mDatabase);
mDatabase.rawQuery("PRAGMA synchronous = 2", null);
}
// getDatabase().beginTransactionNonExclusive();
// TODO: remove this once everyone has stopped using old AnkiDroid clients with WAL (API >= 16)
CompatHelper.getCompat().disableDatabaseWriteAheadLogging(mDatabase);
mDatabase.rawQuery("PRAGMA synchronous = 2", null);
mMod = false;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class MyDbErrorHandler implements DatabaseErrorHandler {
@Override
public void onCorruption(SQLiteDatabase db) {

View File

@ -24,12 +24,7 @@ import java.util.regex.Pattern;
public class FuriganaFilters {
private static final Pattern r = Pattern.compile(" ?([^ >]+?)\\[(.+?)\\]");
// Since there is no ruby tag support in Android before 3.0 (SDK version 11), we must use an alternative
// approach to align the elements. Anki does the same thing in aqt/qt.py for earlier versions of qt.
// The fallback approach relies on CSS in the file /assets/ruby.css
private static final String RUBY = CompatHelper.isHoneycomb() ? "<ruby><rb>$1</rb><rt>$2</rt></ruby>"
: "<span class='legacy_ruby_rb'><span class='legacy_ruby_rt'>$2</span>$1</span>";
private static final String RUBY = "<ruby><rb>$1</rb><rt>$2</rt></ruby>";
public void install(Hooks h) {
h.addHook("fmod_kanji", new Kanji());

View File

@ -39,7 +39,6 @@
<string name="backup_restore_select_title">Select backup to restore</string>
<string name="backup_restore_no_backups">No backups available on this device. If you have backups on your desktop computer, copy them manually into your AnkiDroid folder.</string>
<string name="open_collection_failed_title">Collection not opened</string>
<string name="open_collection_failed_message">Database couldnt be opened. Its either not a real Anki database or has been corrupted.\n\nTouch “options” for various options to restore the database, or for more information about repairing corrupted collections see:\n%1$s</string>
<string name="corrupt_db_message">Your collection has become corrupted.\n\nTouch “options” to restore from a backup, or if that doesnt work, see the following instructions for manually repairing the database:\n%1$s</string>
<string name="access_collection_failed_message">An error occurred while accessing your collection. It may have been caused by a harmless bug, or there may be a problem with it. \n\nTry running check database, or restoring from backup by pressing the “options” button. If you continue to see this message, please file a bug report:\n%1$s</string>
<string name="deck_repair_error">Collection couldnt be repaired</string>

View File

@ -49,12 +49,8 @@
<string name="whiteboard_stroke_width">Stroke width</string>
<string name="whiteboard_black">Black strokes</string>
<string name="whiteboard_black_summ">Uses less memory, unless in night mode</string>
<string name="write_answers_disable">Disable typing in answer</string>
<string name="write_answers_disable_summ">Prevents keyboard from appearing on cards containing type-the-answer fields</string>
<string name="use_input_tag">Type answer into the card</string>
<string name="use_input_tag_summ">Use a text input box inside the card to type in the answer</string>
<string name="text_selection_click">Long press workaround</string>
<string name="text_selection_click_summ">Enable this if you are not able to select text with a long press</string>
<string name="dictionary">Lookup dictionary</string>
<string name="reset_languages">Reset languages</string>
<string name="reset_languages_summ">Reset language assignments (for text to speech and dictionaries) for all decks</string>
@ -126,7 +122,7 @@
<string name="timeout_question_seconds_summ">XXX s</string>
<string name="select_locale_title">Select language</string>
<string name="safe_display">Safe display mode</string>
<string name="safe_display_summ">Disable all animations and use safer method for drawing cards. E-ink and older devices using custom fonts may require this.</string>
<string name="safe_display_summ">Disable all animations and use safer method for drawing cards. E-ink devices may require this.</string>
<string name="vertical_centering">Center align</string>
<string name="vertical_centering_summ">Center the content of cards vertically</string>
<string name="pref_backup_max">Max number of backups</string>
@ -144,8 +140,6 @@
<string name="time_limit_summ">XXX min</string>
<string name="day_offset">Start of next day</string>
<string name="day_offset_summ">XXX hours past midnight</string>
<string name="input_workaround">Input workaround</string>
<string name="input_workaround_summ">Workaround for focusing problems on HTML input boxes. Causes problems on several devices.</string>
<string name="pref_keep_screen_on">Keep screen on</string>
<string name="pref_keep_screen_on_summ">Disable screen timeout</string>
<string name="convert_fen_text">Chess notation support</string>

View File

@ -57,26 +57,11 @@
android:key="safeDisplay"
android:summary="@string/safe_display_summ"
android:title="@string/safe_display" />
<CheckBoxPreference
android:defaultValue="false"
android:key="writeAnswersDisable"
android:summary="@string/write_answers_disable_summ"
android:title="@string/write_answers_disable" />
<CheckBoxPreference
android:defaultValue="false"
android:key="inputWorkaround"
android:summary="@string/input_workaround_summ"
android:title="@string/input_workaround" />
<CheckBoxPreference
android:defaultValue="false"
android:key="useInputTag"
android:summary="@string/use_input_tag_summ"
android:title="@string/use_input_tag" />
<CheckBoxPreference
android:defaultValue="false"
android:key="textSelectionLongclickWorkaround"
android:summary="@string/text_selection_click_summ"
android:title="@string/text_selection_click" />
<CheckBoxPreference
android:defaultValue="false"
android:key="fixHebrewText"