diff --git a/project.properties b/project.properties index 4ec7530afe..f1d33cfa35 100644 --- a/project.properties +++ b/project.properties @@ -11,5 +11,5 @@ split.density=false java.encoding=utf8 # Project target. -target=android-15 +target=android-17 apk-configurations= diff --git a/src/com/ichi2/async/Connection.java b/src/com/ichi2/async/Connection.java index d9cb05a562..0893ab5954 100644 --- a/src/com/ichi2/async/Connection.java +++ b/src/com/ichi2/async/Connection.java @@ -18,42 +18,8 @@ package com.ichi2.async; -import android.app.Application; -import android.content.Context; -import android.database.Cursor; -import android.net.ConnectivityManager; -import android.net.Uri; -import android.os.AsyncTask; -import android.util.Log; - -import com.ichi2.anki.AnkiDatabaseManager; -import com.ichi2.anki.AnkiDb; -import com.ichi2.anki.AnkiDroidApp; -import com.ichi2.anki.Feedback; -import com.ichi2.anki.R; -import com.ichi2.libanki.Collection; -import com.ichi2.libanki.Decks; -import com.ichi2.libanki.Sched; -import com.ichi2.libanki.Utils; -import com.ichi2.libanki.sync.FullSyncer; -import com.ichi2.libanki.sync.BasicHttpSyncer; -import com.ichi2.libanki.sync.MediaSyncer; -import com.ichi2.libanki.sync.RemoteMediaServer; -import com.ichi2.libanki.sync.RemoteServer; -import com.ichi2.libanki.sync.Syncer; - -import org.apache.commons.httpclient.contrib.ssl.EasySSLSocketFactory; -import org.apache.commons.httpclient.contrib.ssl.EasyX509TrustManager; -import org.apache.http.HttpResponse; -import org.json.JSONException; -import org.json.JSONObject; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileFilter; @@ -62,16 +28,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.lang.OutOfMemoryError; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.net.URLConnection; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -81,6 +43,39 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; + +import org.apache.commons.httpclient.contrib.ssl.EasyX509TrustManager; +import org.apache.http.HttpResponse; +import org.json.JSONException; +import org.json.JSONObject; + +import android.app.Application; +import android.content.Context; +import android.database.Cursor; +import android.net.ConnectivityManager; +import android.net.Uri; +import android.os.AsyncTask; +import android.util.Log; + +import com.ichi2.anki.AnkiDatabaseManager; +import com.ichi2.anki.AnkiDb; +import com.ichi2.anki.AnkiDroidApp; +import com.ichi2.anki.Feedback; +import com.ichi2.anki.R; +import com.ichi2.libanki.Collection; +import com.ichi2.libanki.Decks; +import com.ichi2.libanki.Sched; +import com.ichi2.libanki.Utils; +import com.ichi2.libanki.sync.BasicHttpSyncer; +import com.ichi2.libanki.sync.FullSyncer; +import com.ichi2.libanki.sync.MediaSyncer; +import com.ichi2.libanki.sync.RemoteMediaServer; +import com.ichi2.libanki.sync.RemoteServer; +import com.ichi2.libanki.sync.Syncer; + public class Connection extends AsyncTask { public static final int TASK_TYPE_LOGIN = 0; @@ -677,9 +672,9 @@ private Payload doInBackgroundSync(Payload data) { counts[2] += (Integer) deck[4]; } } - Object[] dc = col.getSched().deckCounts(); - data.result = dc[0]; - data.data = new Object[] { conflictResolution, col, dc[1], dc[2], mediaError }; + Sched.DeckCounts dc = col.getSched().getDeckCounts(); + data.result = dc.getDecksNet(); + data.data = new Object[] { conflictResolution, col, dc.eta, dc.cardCount, mediaError }; return data; } } @@ -696,7 +691,8 @@ public void publishProgress(int id, long up, long down) { } - private Payload doInBackgroundSendFeedback(Payload data) { + @SuppressWarnings("unchecked") + private Payload doInBackgroundSendFeedback(Payload data) { Log.i(AnkiDroidApp.TAG, "doInBackgroundSendFeedback"); String feedbackUrl = (String) data.data[0]; String errorUrl = (String) data.data[1]; @@ -745,7 +741,6 @@ private Payload doInBackgroundSendFeedback(Payload data) { return data; } - /** * Downloads any missing media files according to the mediaURL deckvar. * @@ -753,6 +748,7 @@ private Payload doInBackgroundSendFeedback(Payload data) { * @return The return type contains data.resultType and an array of Integer in data.data. data.data[0] is the number * of total missing media, data.data[1] is the number of downloaded ones. */ + // TODO: this method is broken. see FIXMEs private Payload doInBackgroundDownloadMissingMedia(Payload data) { Log.i(AnkiDroidApp.TAG, "DownloadMissingMedia"); HashMap missingPaths = new HashMap(); @@ -771,6 +767,7 @@ private Payload doInBackgroundDownloadMissingMedia(Payload data) { String urlbase = "";// deck.getVar("mediaURL"); if (urlbase.equals("")) { data.success = true; + // FIXME: the method returns here every time. return data; } @@ -781,6 +778,7 @@ private Payload doInBackgroundDownloadMissingMedia(Payload data) { Cursor cursor = null; try { + // FIXME: assign cursor to non-null variable cursor = null;// deck.getDB().getDatabase().rawQuery("SELECT filename, originalPath FROM media", null); String path = null; String f = null; @@ -801,17 +799,17 @@ private Payload doInBackgroundDownloadMissingMedia(Payload data) { } totalMissing = missingPaths.size(); - data.data[0] = new Integer(totalMissing); + data.data[0] = Integer.valueOf(totalMissing); if (totalMissing == 0) { data.success = true; return data; } - publishProgress(Boolean.FALSE, new Integer(totalMissing), new Integer(0), syncName); + publishProgress(Boolean.FALSE, Integer.valueOf(totalMissing), Integer.valueOf(0), syncName); URL url = null; HttpURLConnection connection = null; String path = null; - String sum = null; + //String sum = null; int readbytes = 0; byte[] buf = new byte[4096]; for (String file : missingPaths.keySet()) { @@ -832,17 +830,18 @@ private Payload doInBackgroundDownloadMissingMedia(Payload data) { } fos.close(); - // Verify with checksum - sum = missingSums.get(file); - if (true) {// sum.equals("") || sum.equals(Utils.fileChecksum(path))) { - grabbed++; - } else { - // Download corrupted, delete file - Log.i(AnkiDroidApp.TAG, "Downloaded media file " + path + " failed checksum."); - File f = new File(path); - f.delete(); - missing++; - } + // TODO: Verify with checksum +// sum = missingSums.get(file); +// if (true) {// sum.equals("") || sum.equals(Utils.fileChecksum(path))) { +// grabbed++; +// } else { +// // Download corrupted, delete file +// Log.i(AnkiDroidApp.TAG, "Downloaded media file " + path + " failed checksum."); +// File f = new File(path); +// f.delete(); +// missing++; +// } + grabbed++; } else { Log.e(AnkiDroidApp.TAG, "Connection error (" + connection.getResponseCode() + ") while retrieving media file " + urlbase + file); @@ -886,11 +885,11 @@ private Payload doInBackgroundDownloadMissingMedia(Payload data) { connection.disconnect(); } } - publishProgress(Boolean.TRUE, new Integer(totalMissing), new Integer(grabbed + missing), syncName); + publishProgress(Boolean.TRUE, Integer.valueOf(totalMissing), Integer.valueOf(grabbed + missing), syncName); } - data.data[1] = new Integer(grabbed); - data.data[2] = new Integer(missing); + data.data[1] = Integer.valueOf(grabbed); + data.data[2] = Integer.valueOf(missing); data.success = true; return data; } diff --git a/src/com/ichi2/async/DeckTask.java b/src/com/ichi2/async/DeckTask.java index 28c98deec8..05b08ec5b7 100644 --- a/src/com/ichi2/async/DeckTask.java +++ b/src/com/ichi2/async/DeckTask.java @@ -22,11 +22,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.TreeSet; @@ -40,6 +36,7 @@ import com.ichi2.anki.R; import com.ichi2.libanki.Card; import com.ichi2.libanki.Collection; +import com.ichi2.libanki.Models; import com.ichi2.libanki.Note; import com.ichi2.libanki.Sched; import com.ichi2.libanki.Stats; @@ -73,7 +70,7 @@ public class DeckTask extends public static final int TASK_TYPE_CHECK_DATABASE = 14; public static final int TASK_TYPE_DELETE_BACKUPS = 16; public static final int TASK_TYPE_RESTORE_DECK = 17; - public static final int TASK_TYPE_UPDATE_CARD_BROWSER_LIST = 18; +// public static final int TASK_TYPE_UPDATE_CARD_BROWSER_LIST = 18; public static final int TASK_TYPE_LOAD_TUTORIAL = 19; public static final int TASK_TYPE_REPAIR_DECK = 20; public static final int TASK_TYPE_CLOSE_DECK = 21; @@ -219,8 +216,8 @@ protected TaskData doInBackground(TaskData... params) { case TASK_TYPE_RESTORE_DECK: return doInBackgroundRestoreDeck(params); - case TASK_TYPE_UPDATE_CARD_BROWSER_LIST: - return doInBackgroundUpdateCardBrowserList(params); +// case TASK_TYPE_UPDATE_CARD_BROWSER_LIST: +// return doInBackgroundUpdateCardBrowserList(params); case TASK_TYPE_LOAD_TUTORIAL: return doInBackgroundLoadTutorial(params); @@ -479,7 +476,8 @@ private TaskData doInBackgroundLoadDeckCounts(TaskData... params) { return null; } try { - return new TaskData(col.getSched().deckCounts()); + Sched.DeckCounts dc = col.getSched().getDeckCounts(); + return new TaskData(new Object[] { dc.getDecksNet(), dc.eta, dc.cardCount }); } catch (RuntimeException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundLoadDeckCounts - error: " + e); @@ -643,7 +641,8 @@ private TaskData doInBackgroundUndo(TaskData... params) { return new TaskData(true); } - private TaskData doInBackgroundSearchCards(TaskData... params) { + @SuppressWarnings("unchecked") + private TaskData doInBackgroundSearchCards(TaskData... params) { Log.i(AnkiDroidApp.TAG, "doInBackgroundSearchCards"); Collection col = (Collection) params[0].getObjArray()[0]; HashMap deckNames = (HashMap) params[0].getObjArray()[1]; @@ -932,31 +931,31 @@ private TaskData doInBackgroundRestoreDeck(TaskData... params) { return new TaskData(BackupManager.restoreBackup((String)data[1], (String)data[2])); } - private TaskData doInBackgroundUpdateCardBrowserList(TaskData... params) { - Log.i(AnkiDroidApp.TAG, "doInBackgroundSortCards"); - if (params.length == 1) { - Comparator comparator = params[0].getComparator(); - ArrayList> card = params[0].getCards(); - Collections.sort(card, comparator); - } else { - ArrayList> allCard = params[0].getCards(); - ArrayList> cards = params[1].getCards(); - cards.clear(); - HashSet tags = new HashSet(); - for (String s : (HashSet) params[2].getObjArray()[0]) { - tags.add(s.toLowerCase()); - } - for (int i = 0; i < allCard.size(); i++) { - HashMap card = allCard.get(i); - if (Arrays.asList( - card.get("tags").toLowerCase().trim().split("\\s")) - .containsAll(tags)) { - cards.add(allCard.get(i)); - } - } - } - return null; - } +// private TaskData doInBackgroundUpdateCardBrowserList(TaskData... params) { +// Log.i(AnkiDroidApp.TAG, "doInBackgroundSortCards"); +// if (params.length == 1) { +// Comparator comparator = params[0].getComparator(); +// ArrayList> card = params[0].getCards(); +// Collections.sort(card, comparator); +// } else { +// ArrayList> allCard = params[0].getCards(); +// ArrayList> cards = params[1].getCards(); +// cards.clear(); +// HashSet tags = new HashSet(); +// for (String s : (HashSet) params[2].getObjArray()[0]) { +// tags.add(s.toLowerCase()); +// } +// for (int i = 0; i < allCard.size(); i++) { +// HashMap card = allCard.get(i); +// if (Arrays.asList( +// card.get("tags").toLowerCase().trim().split("\\s")) +// .containsAll(tags)) { +// cards.add(allCard.get(i)); +// } +// } +// } +// return null; +// } private TaskData doInBackgroundLoadTutorial(TaskData... params) { Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadTutorial"); @@ -1003,7 +1002,7 @@ private TaskData doInBackgroundLoadTutorial(TaskData... params) { // } // } if (model == null) { - model = col.getModels().addBasicModel(col, title); + model = Models.addBasicModel(col, title); } model.put("did", did); String[] questions = res.getStringArray(R.array.tutorial_questions); @@ -1065,7 +1064,7 @@ public static class TaskData { private long mLong; private Context mContext; private int mType; - private Comparator mComparator; +// private Comparator mComparator; private int[] mIntList; private Collection mCol; private Sched mSched; @@ -1118,11 +1117,11 @@ public TaskData(ArrayList> cards) { mCards = cards; } - public TaskData(ArrayList> cards, - Comparator comparator) { - mCards = cards; - mComparator = comparator; - } +// public TaskData(ArrayList> cards, +// Comparator comparator) { +// mCards = cards; +// mComparator = comparator; +// } public TaskData(boolean bool) { mBool = bool; @@ -1229,7 +1228,7 @@ public TaskData(int[] intlist) { public TaskData(List idList) { mIdList = idList; } - + public ArrayList> getCards() { return mCards; } @@ -1238,9 +1237,9 @@ public void setCards(ArrayList> cards) { mCards = cards; } - public Comparator getComparator() { - return mComparator; - } +// public Comparator getComparator() { +// return mComparator; +// } public Card getCard() { return mCard; diff --git a/src/com/ichi2/libanki/Card.java b/src/com/ichi2/libanki/Card.java index 2e7710a17e..f1aa85a41f 100644 --- a/src/com/ichi2/libanki/Card.java +++ b/src/com/ichi2/libanki/Card.java @@ -51,7 +51,6 @@ public class Card implements Cloneable { private long mNid; private long mDid; private int mOrd; - private long mCrt = Utils.intNow(); private long mMod; private int mType = 0; private int mQueue = 0; @@ -105,7 +104,6 @@ public Card(Collection col, long id) { // to flush, set nid, ord, and due mId = Utils.timestampID(mCol.getDb(), "cards"); mDid = 1; - mCrt = Utils.intNow(); mType = 0; mQueue = 0; mIvl = 0; diff --git a/src/com/ichi2/libanki/Collection.java b/src/com/ichi2/libanki/Collection.java index d571cfae8c..6eca94328b 100644 --- a/src/com/ichi2/libanki/Collection.java +++ b/src/com/ichi2/libanki/Collection.java @@ -17,6 +17,7 @@ package com.ichi2.libanki; +import android.annotation.SuppressLint; import android.content.ContentValues; import android.content.res.Resources; import android.database.Cursor; @@ -29,8 +30,6 @@ import com.ichi2.anki.Pair; import com.ichi2.anki.R; import com.ichi2.anki.UIUtils; -import com.ichi2.async.DeckTask; -import com.samskivert.mustache.Mustache; import org.json.JSONArray; import org.json.JSONException; @@ -41,7 +40,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Random; import java.util.regex.Matcher; @@ -570,7 +568,8 @@ private ArrayList _tmplsFromOrds(JSONObject model, ArrayList genCards(List nids) { return genCards(Utils.arrayList2array(nids)); } - public ArrayList genCards(long[] nids) { + @SuppressLint("UseSparseArrays") + public ArrayList genCards(long[] nids) { // build map of (nid,ord) so we don't create dupes String snids = Utils.ids2str(nids); HashMap> have = new HashMap>(); @@ -1167,7 +1166,8 @@ public boolean undoAvailable() { } - public long undo() { + @SuppressWarnings("unchecked") + public long undo() { Object[] data = mUndo.removeLast(); switch ((Integer)data[0]) { case UNDO_REVIEW: diff --git a/src/com/ichi2/libanki/Finder.java b/src/com/ichi2/libanki/Finder.java index e2c5be6b97..5214d5bddc 100644 --- a/src/com/ichi2/libanki/Finder.java +++ b/src/com/ichi2/libanki/Finder.java @@ -36,7 +36,6 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeMap; diff --git a/src/com/ichi2/libanki/LaTeX.java b/src/com/ichi2/libanki/LaTeX.java index 4b03e06f4d..f8c87eaf10 100644 --- a/src/com/ichi2/libanki/LaTeX.java +++ b/src/com/ichi2/libanki/LaTeX.java @@ -17,8 +17,6 @@ package com.ichi2.libanki; -import android.text.Html; - import com.ichi2.libanki.hooks.Hook; import com.ichi2.libanki.hooks.Hooks; diff --git a/src/com/ichi2/libanki/Media.java b/src/com/ichi2/libanki/Media.java index cf7f823e61..78285ae124 100644 --- a/src/com/ichi2/libanki/Media.java +++ b/src/com/ichi2/libanki/Media.java @@ -43,12 +43,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.DeflaterOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; diff --git a/src/com/ichi2/libanki/Models.java b/src/com/ichi2/libanki/Models.java index 0a6e34e1b4..d3a22ec8be 100644 --- a/src/com/ichi2/libanki/Models.java +++ b/src/com/ichi2/libanki/Models.java @@ -19,14 +19,13 @@ package com.ichi2.libanki; +import android.annotation.SuppressLint; import android.content.ContentValues; import android.database.Cursor; import android.util.Log; import com.ichi2.anki.AnkiDroidApp; import com.ichi2.anki.Pair; -import com.ichi2.themes.HtmlColors; -import com.mindprod.common11.StringTools; import com.samskivert.mustache.Mustache; import com.samskivert.mustache.Template; @@ -83,12 +82,12 @@ public class Models { // BEGIN SQL table entries private int mId; private String mName = ""; - private long mCrt = Utils.intNow(); - private long mMod = Utils.intNow(); - private JSONObject mConf; - private String mCss = ""; - private JSONArray mFields; - private JSONArray mTemplates; +// private long mCrt = Utils.intNow(); +// private long mMod = Utils.intNow(); +// private JSONObject mConf; +// private String mCss = ""; +// private JSONArray mFields; +// private JSONArray mTemplates; // BEGIN SQL table entries // private Decks mDeck; @@ -797,7 +796,8 @@ public void _updateTemplOrds(JSONObject m) { } - public void moveTemplate(JSONObject m, JSONObject template, int idx) { + @SuppressLint("UseSparseArrays") + public void moveTemplate(JSONObject m, JSONObject template, int idx) { try { JSONArray ja = m.getJSONArray("tmpls"); int oldidx = -1; @@ -840,7 +840,7 @@ public void moveTemplate(JSONObject m, JSONObject template, int idx) { private void _syncTemplates(JSONObject m) { - ArrayList rem = mCol.genCards(Utils.arrayList2array(nids(m))); + //ArrayList rem = mCol.genCards(Utils.arrayList2array(nids(m))); } @@ -991,7 +991,8 @@ public void change(JSONObject m, long[] nids, JSONObject newModel, Map map) { + @SuppressLint("UseSparseArrays") + private void _changeNotes(long[] nids, JSONObject newModel, Map map) { List d = new ArrayList(); int nfields; long mid; @@ -1149,7 +1150,7 @@ private Object[] _reqForTemplate(JSONObject m, ArrayList flds, JSONObjec try { ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); - for (String f : flds) { + for (int i = 0; i < flds.size(); i++) { a.add("ankiflag"); b.add(""); } @@ -1418,7 +1419,8 @@ public void setChanged() { } - public HashMap> getTemplateNames() { + @SuppressLint("UseSparseArrays") + public HashMap> getTemplateNames() { HashMap> result = new HashMap>(); for (JSONObject m : mModels.values()) { JSONArray templates; diff --git a/src/com/ichi2/libanki/Note.java b/src/com/ichi2/libanki/Note.java index 6c339b0c82..278e30bcab 100644 --- a/src/com/ichi2/libanki/Note.java +++ b/src/com/ichi2/libanki/Note.java @@ -46,7 +46,6 @@ public class Note implements Cloneable { private int mFlags; private Map> mFMap; - private long mScm; public Note(Collection col, long id) { @@ -80,7 +79,6 @@ public Note(Collection col, JSONObject model, long id) { } mData = ""; mFMap = mCol.getModels().fieldMap(mModel); - mScm = mCol.getScm(); } } @@ -102,7 +100,6 @@ public void load() { mTags = mCol.getTags().split(cursor.getString(4)); mFlags = cursor.getInt(6); mData = cursor.getString(7); - mScm = mCol.getScm(); } finally { if (cursor != null) { cursor.close(); diff --git a/src/com/ichi2/libanki/Sched.java b/src/com/ichi2/libanki/Sched.java index 7f388bcbfe..02337a27ea 100644 --- a/src/com/ichi2/libanki/Sched.java +++ b/src/com/ichi2/libanki/Sched.java @@ -46,7 +46,6 @@ import java.util.Locale; import java.util.Map; import java.util.Random; -import java.util.TreeMap; import java.util.TreeSet; public class Sched { @@ -92,7 +91,6 @@ public class Sched { public static final int MODEL_STD = 0; public static final int MODEL_CLOZE = 1; - private static final String[] REV_ORDER_STRINGS = { "ivl DESC", "ivl" }; private static final int[] FACTOR_ADDITION_VALUES = { -150, 0, 150 }; // not in libanki @@ -129,9 +127,6 @@ public class Sched { private LinkedList mLrnDids; private LinkedList mRevDids; - private TreeMap mGroupConfs; - private TreeMap mConfCache; - private HashMap> mCachedDeckCounts; /** @@ -404,17 +399,6 @@ public void extendLimits(int newc, int rev) { } } - - private int _walkingCount() { - return _walkingCount(null, null, null); - } - - - private int _walkingCount(LinkedList dids) { - return _walkingCount(dids, null, null); - } - - private int _walkingCount(Method limFn, Method cntFn) { return _walkingCount(null, limFn, cntFn); } @@ -479,7 +463,7 @@ private int _walkingCount(LinkedList dids, Method limFn, Method cntFn) { */ /** LIBANKI: not in libanki */ - public Object[] deckCounts() { + public DeckCounts getDeckCounts() { TreeSet decks = deckDueTree(0); int[] counts = new int[] { 0, 0, 0 }; for (Object[] deck : decks) { @@ -512,7 +496,7 @@ public Object[] deckCounts() { throw new RuntimeException(e); } } - return new Object[] { decksNet, eta(counts), mCol.cardCount() }; + return new DeckCounts(decksNet, eta(counts), mCol.cardCount()); } public boolean getSpreadRev() { @@ -617,7 +601,8 @@ private TreeSet _groupChildren(ArrayList grps) { private TreeSet _groupChildrenMain(TreeSet grps) { return _groupChildrenMain(grps, 0); } - private TreeSet _groupChildrenMain(TreeSet grps, int depth) { + @SuppressWarnings("unchecked") + private TreeSet _groupChildrenMain(TreeSet grps, int depth) { TreeSet tree = new TreeSet(new DeckNameCompare()); // group and recurse Iterator it = grps.iterator(); @@ -773,7 +758,9 @@ private void _resetNewCount() { } - private int _cntFnNew(long did, int lim) { + // used by Class.getDeclaredMethod() in _resetNewCount() + @SuppressWarnings("unused") + private int _cntFnNew(long did, int lim) { return mCol.getDb().queryScalar( "SELECT count() FROM (SELECT 1 FROM cards WHERE did = " + did + " AND queue = 0 LIMIT " + lim + ")"); } @@ -1186,7 +1173,8 @@ private void _answerLrnCard(Card card, int ease) { * Sorts a card into the lrn queue LIBANKI: not in libanki */ private void _sortIntoLrn(long due, long id) { - Iterator i = mLrnQueue.listIterator(); + @SuppressWarnings("rawtypes") + Iterator i = mLrnQueue.listIterator(); int idx = 0; while (i.hasNext()) { if (((long[]) i.next())[0] > due) { @@ -1460,8 +1448,9 @@ private void _resetRevCount() { } } - - private int _cntFnRev(long did, int lim) { + // used by Class.getDeclaredMethod() in _resetRevCount() + @SuppressWarnings("unused") + private int _cntFnRev(long did, int lim) { return mCol.getDb().queryScalar( "SELECT count() FROM (SELECT id FROM cards WHERE did = " + did + " AND queue = 2 and due <= " + mToday + " LIMIT " + lim + ")"); @@ -2057,7 +2046,6 @@ private JSONObject _lapseConf(Card card) { dict.put("resched", conf.getBoolean("resched")); return dict; } catch (JSONException e) { - JSONObject conf = _cardConf(card); if (!mCol.getDecks().isDyn(card.getDid()) && card.getODid() != 0) { // workaround, if a card's deck is a normal deck, but odid != 0 card.setODue(0); @@ -2422,7 +2410,7 @@ public float[] progressToday(TreeSet counts, Card card, boolean eta) { mCachedDeckCounts.clear(); if (counts == null) { // reload counts - counts = (TreeSet)deckCounts()[0]; + counts = getDeckCounts().getDecksNet(); } for (Object[] d : counts) { int done = 0; @@ -2782,6 +2770,22 @@ public int getNewCount() { public LinkedList getNewQueue() { return mNewQueue; } + + public class DeckCounts { + private TreeSet decksNet; + public final int eta; + public final int cardCount; + + public DeckCounts(TreeSet decksNet, int eta, int cardCount) { + this.decksNet = decksNet; + this.eta = eta; + this.cardCount = cardCount; + } + + public TreeSet getDecksNet() { + return decksNet; + } + } private class DeckNameCompare implements Comparator { @Override @@ -2807,7 +2811,7 @@ public int compare(Object[] lhs, Object[] rhs) { private class DueComparator implements Comparator { @Override public int compare(long[] lhs, long[] rhs) { - return new Long(lhs[0]).compareTo(rhs[0]); + return Long.valueOf(lhs[0]).compareTo(rhs[0]); } } diff --git a/src/com/ichi2/libanki/Sound.java b/src/com/ichi2/libanki/Sound.java index 1778c5f14e..27f078f267 100644 --- a/src/com/ichi2/libanki/Sound.java +++ b/src/com/ichi2/libanki/Sound.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.HashMap; +import android.annotation.SuppressLint; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; @@ -51,7 +52,8 @@ public class Sound { /** * Stores sounds for the current card, key is for question/answer */ - private static HashMap> sSoundPaths = new HashMap>(); + @SuppressLint("UseSparseArrays") + private static HashMap> sSoundPaths = new HashMap>(); /* Prevent class from being instantiated */ @@ -102,6 +104,7 @@ public static String parseSounds(String soundDir, String content, boolean ttsEna contentLeft = contentLeft.substring(markerStart + soundMarker.length()); Log.i(AnkiDroidApp.TAG, "Content left = " + contentLeft); } + if (!soundAvailable) { // TODO: readd tts // if (!soundAvailable && ttsEnabled && !ReadText.getLanguage(qa).equals(ReadText.NO_TTS)) { // stringBuilder.append(content.substring(0, content.length() - 9)); @@ -112,7 +115,7 @@ public static String parseSounds(String soundDir, String content, boolean ttsEna // + "\">"); // contentLeft = "

"; // } - + } stringBuilder.append(contentLeft); return stringBuilder.toString(); diff --git a/src/com/ichi2/libanki/Storage.java b/src/com/ichi2/libanki/Storage.java index 6494525c19..f85b54ecd3 100644 --- a/src/com/ichi2/libanki/Storage.java +++ b/src/com/ichi2/libanki/Storage.java @@ -19,7 +19,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Locale; import org.json.JSONArray; import org.json.JSONException; diff --git a/src/com/ichi2/libanki/Tags.java b/src/com/ichi2/libanki/Tags.java index 169afd957b..d2601851c6 100644 --- a/src/com/ichi2/libanki/Tags.java +++ b/src/com/ichi2/libanki/Tags.java @@ -18,13 +18,10 @@ package com.ichi2.libanki; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -56,7 +53,8 @@ public Tags(Collection col) { public void load(String json) { try { JSONObject tags = new JSONObject(json); - Iterator i = tags.keys(); + @SuppressWarnings("unchecked") + Iterator i = (Iterator) tags.keys(); while (i.hasNext()) { String t = (String) i.next(); mTags.put(t, tags.getInt(t)); @@ -127,11 +125,7 @@ public void registerNotes() { /** Add any missing tags from notes to the tags list. */ public void registerNotes(long[] nids) { // when called without an argument, the old list is cleared first. - String lim; - if (nids != null) { - lim = " WHERE id IN " + Utils.ids2str(nids); - } else { - lim = ""; + if (nids == null) { mTags.clear(); mChanged = true; } diff --git a/src/com/ichi2/libanki/Utils.java b/src/com/ichi2/libanki/Utils.java index 89e4e60d7b..bab4d75ec4 100644 --- a/src/com/ichi2/libanki/Utils.java +++ b/src/com/ichi2/libanki/Utils.java @@ -19,11 +19,9 @@ package com.ichi2.libanki; -import android.annotation.TargetApi; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; @@ -37,23 +35,19 @@ import com.ichi2.anki.AnkiDroidApp; import com.ichi2.anki.AnkiFont; import com.ichi2.anki.R; -import com.ichi2.async.Connection.OldAnkiDeckFilter; import com.mindprod.common11.BigDate; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import java.io.BufferedOutputStream; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -64,7 +58,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.sql.Date; -import java.text.Normalizer; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -72,12 +65,10 @@ import java.util.Calendar; import java.util.Collection; import java.util.GregorianCalendar; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Random; import java.util.TimeZone; -import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.Deflater; @@ -100,9 +91,6 @@ enum SqlCommandType { SQL_INS, SQL_UPD, SQL_DEL }; private static NumberFormat mCurrentNumberFormat; private static NumberFormat mCurrentPercentageFormat; - private static TreeSet sIdTree; - private static long sIdTime; - private static final int TIME_SECONDS = 0; private static final int TIME_MINUTES = 1; private static final int TIME_HOURS = 2; @@ -177,9 +165,9 @@ public static String fmtTimeSpan(int time, int format, boolean _short, boolean b double ftime = convertSecondsTo(time, type); int formatId; - if (false){//_short) { - //formatId = R.array.next_review_short; - } else { +// if (false){//_short) { +// //formatId = R.array.next_review_short; +// } else { switch (format) { case TIME_FORMAT_IN: if (Math.round(ftime * 10) == 10) { @@ -204,7 +192,7 @@ public static String fmtTimeSpan(int time, int format, boolean _short, boolean b } break; } - } +// } String timeString = String.format(AnkiDroidApp.getAppResources().getStringArray(formatId)[type], boldNumber ? "" + fmtDouble(ftime, point) + "" : fmtDouble(ftime, point)); if (boldNumber && time == 1) { @@ -299,10 +287,11 @@ public static String stripHTMLMedia(String s) { } - private String minimizeHTML(String s) { - // TODO - return s; - } + // TODO +// private String minimizeHTML(String s) { +// +// return s; +// } /** @@ -818,64 +807,64 @@ public static void writeToFile(InputStream source, String destination) throws IO // Print methods - public static void printJSONObject(JSONObject jsonObject) { - printJSONObject(jsonObject, "-", null); - } - - - public static void printJSONObject(JSONObject jsonObject, boolean writeToFile) { - BufferedWriter buff; - try { - buff = writeToFile ? - new BufferedWriter(new FileWriter("/sdcard/payloadAndroid.txt"), 8192) : null; - try { - printJSONObject(jsonObject, "-", buff); - } finally { - if (buff != null) - buff.close(); - } - } catch (IOException ioe) { - Log.e(AnkiDroidApp.TAG, "IOException = " + ioe.getMessage()); - } - } +// public static void printJSONObject(JSONObject jsonObject) { +// printJSONObject(jsonObject, "-", null); +// } - private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) { - try { - @SuppressWarnings("unchecked") Iterator keys = (Iterator) jsonObject.keys(); - TreeSet orderedKeysSet = new TreeSet(); - while (keys.hasNext()) { - orderedKeysSet.add(keys.next()); - } +// public static void printJSONObject(JSONObject jsonObject, boolean writeToFile) { +// BufferedWriter buff; +// try { +// buff = writeToFile ? +// new BufferedWriter(new FileWriter("/sdcard/payloadAndroid.txt"), 8192) : null; +// try { +// printJSONObject(jsonObject, "-", buff); +// } finally { +// if (buff != null) +// buff.close(); +// } +// } catch (IOException ioe) { +// Log.e(AnkiDroidApp.TAG, "IOException = " + ioe.getMessage()); +// } +// } - Iterator orderedKeys = orderedKeysSet.iterator(); - while (orderedKeys.hasNext()) { - String key = orderedKeys.next(); - try { - Object value = jsonObject.get(key); - if (value instanceof JSONObject) { - if (buff != null) { - buff.write(indentation + " " + key + " : "); - buff.newLine(); - } - Log.i(AnkiDroidApp.TAG, " " + indentation + key + " : "); - printJSONObject((JSONObject) value, indentation + "-", buff); - } else { - if (buff != null) { - buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString()); - buff.newLine(); - } - Log.i(AnkiDroidApp.TAG, " " + indentation + key + " = " + jsonObject.get(key).toString()); - } - } catch (JSONException e) { - Log.e(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); - } - } - } catch (IOException e1) { - Log.e(AnkiDroidApp.TAG, "IOException = " + e1.getMessage()); - } - } +// private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) { +// try { +// @SuppressWarnings("unchecked") Iterator keys = (Iterator) jsonObject.keys(); +// TreeSet orderedKeysSet = new TreeSet(); +// while (keys.hasNext()) { +// orderedKeysSet.add(keys.next()); +// } +// +// Iterator orderedKeys = orderedKeysSet.iterator(); +// while (orderedKeys.hasNext()) { +// String key = orderedKeys.next(); +// +// try { +// Object value = jsonObject.get(key); +// if (value instanceof JSONObject) { +// if (buff != null) { +// buff.write(indentation + " " + key + " : "); +// buff.newLine(); +// } +// Log.i(AnkiDroidApp.TAG, " " + indentation + key + " : "); +// printJSONObject((JSONObject) value, indentation + "-", buff); +// } else { +// if (buff != null) { +// buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString()); +// buff.newLine(); +// } +// Log.i(AnkiDroidApp.TAG, " " + indentation + key + " = " + jsonObject.get(key).toString()); +// } +// } catch (JSONException e) { +// Log.e(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); +// } +// } +// } catch (IOException e1) { +// Log.e(AnkiDroidApp.TAG, "IOException = " + e1.getMessage()); +// } +// } /* @@ -911,7 +900,7 @@ public static int booleanToInt(boolean b) { public static Date genToday(double utcOffset) { // The result is not adjusted for timezone anymore, following libanki model // Timezone adjustment happens explicitly in Deck.updateCutoff(), but not in Deck.checkDailyStats() - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", ENGLISH_LOCALE); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(System.currentTimeMillis() - (long) utcOffset * 1000l); @@ -920,13 +909,13 @@ public static Date genToday(double utcOffset) { } - public static void printDate(String name, double date) { - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); - cal.setTimeInMillis((long)date * 1000); - Log.d(AnkiDroidApp.TAG, "Value of " + name + ": " + cal.getTime().toGMTString()); - } +// public static void printDate(String name, double date) { +// SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); +// df.setTimeZone(TimeZone.getTimeZone("GMT")); +// Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); +// cal.setTimeInMillis((long)date * 1000); +// Log.d(AnkiDroidApp.TAG, "Value of " + name + ": " + cal.getTime().toGMTString()); +// } public static String doubleToTime(double value) { @@ -943,15 +932,15 @@ public static String doubleToTime(double value) { } - /** - * Returns the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. - * @param date Date to convert to ordinal, since 01/01/01 - * @return The ordinal representing the date - */ - public static int dateToOrdinal(Date date) { - // BigDate.toOrdinal returns the ordinal since 1970, so we add up the days from 01/01/01 to 1970 - return BigDate.toOrdinal(date.getYear() + 1900, date.getMonth() + 1, date.getDate()) + DAYS_BEFORE_1970; - } +// /** +// * Returns the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. +// * @param date Date to convert to ordinal, since 01/01/01 +// * @return The ordinal representing the date +// */ +// public static int dateToOrdinal(Date date) { +// // BigDate.toOrdinal returns the ordinal since 1970, so we add up the days from 01/01/01 to 1970 +// return BigDate.toOrdinal(date.getYear() + 1900, date.getMonth() + 1, date.getDate()) + DAYS_BEFORE_1970; +// } /** diff --git a/src/com/ichi2/libanki/hooks/HintFilter.java b/src/com/ichi2/libanki/hooks/HintFilter.java index 6aa1bf63dd..b713b029e9 100644 --- a/src/com/ichi2/libanki/hooks/HintFilter.java +++ b/src/com/ichi2/libanki/hooks/HintFilter.java @@ -20,8 +20,6 @@ import com.ichi2.anki.R; -import java.util.Locale; - public class HintFilter { public void install(Hooks h) { h.addHook("fmod_hint", new Hint()); diff --git a/src/com/ichi2/libanki/hooks/Hooks.java b/src/com/ichi2/libanki/hooks/Hooks.java index 7bbe742cac..08aae153fb 100644 --- a/src/com/ichi2/libanki/hooks/Hooks.java +++ b/src/com/ichi2/libanki/hooks/Hooks.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; public class Hooks { diff --git a/src/com/ichi2/libanki/importer/Anki2Importer.java b/src/com/ichi2/libanki/importer/Anki2Importer.java index fa04c0912a..a550de3221 100644 --- a/src/com/ichi2/libanki/importer/Anki2Importer.java +++ b/src/com/ichi2/libanki/importer/Anki2Importer.java @@ -29,7 +29,10 @@ import org.json.JSONException; import org.json.JSONObject; +import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.database.Cursor; +import android.os.Build; import android.util.Log; import com.ichi2.anki.AnkiDatabaseManager; @@ -144,11 +147,6 @@ private void _prepareTS() { mTs = Utils.maxID(mDst.getDb()); } - private long ts() { - mTs++; - return mTs; - } - /** Notes */ // should note new for wizard @@ -361,6 +359,7 @@ private long _did(long did) { /** Cards */ + @SuppressLint("UseSparseArrays") private int _importCards() { // build map of (guid, ord) -> cid and used id cache mCards = new HashMap>(); @@ -410,7 +409,7 @@ private int _importCards() { if (!mNotes.containsKey(guid)) { continue; } - Object[] dnid = mNotes.get(guid); + //Object[] dnid = mNotes.get(guid); // does the card already exist in the dst col? int ord = (Integer) card[5]; if (mCards.containsKey(guid) && mCards.get(guid).containsKey(ord)) { @@ -536,7 +535,8 @@ private String _mungeMedia(long mid, String fields) { * Return the contents of the given input stream, limited to Anki2Importer.MEDIAPICKLIMIT bytes * This is only used for comparison of media files with the limited resources of mobile devices */ - byte[] _mediaPick(InputStream is) { + @TargetApi(Build.VERSION_CODES.GINGERBREAD) // Arrays.copyOf + byte[] _mediaPick(InputStream is) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[MEDIAPICKLIMIT]; diff --git a/src/com/ichi2/libanki/sync/FullSyncer.java b/src/com/ichi2/libanki/sync/FullSyncer.java index 04896b1f2c..c2bf2a8062 100644 --- a/src/com/ichi2/libanki/sync/FullSyncer.java +++ b/src/com/ichi2/libanki/sync/FullSyncer.java @@ -16,13 +16,11 @@ package com.ichi2.libanki.sync; -import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import org.apache.http.HttpResponse;