Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java cleanup in v2.1-dev #116

Open
wants to merge 1 commit into
base: v2.1-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/com/ichi2/anki/AnkiFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,30 @@ public static AnkiFont createAnkiFont(Context ctx, String path, boolean fromAsse
// unable to create typeface
return null;
}
if (tf.isBold() || name.toLowerCase().contains("bold")) {
final String nameLowerCase = name.toLowerCase();
if (tf.isBold() || nameLowerCase.contains("bold")) {
attributes.add("font-weight: bolder;");
family = family.replaceFirst("(?i)-?Bold", "");
} else if (name.toLowerCase().contains("light")) {
} else if (nameLowerCase.contains("light")) {
attributes.add("font-weight: lighter;");
family = family.replaceFirst("(?i)-?Light", "");
} else {
attributes.add("font-weight: normal;");
}
if (tf.isItalic() || name.toLowerCase().contains("italic")) {
if (tf.isItalic() || nameLowerCase.contains("italic")) {
attributes.add("font-style: italic;");
family = family.replaceFirst("(?i)-?Italic", "");
} else if (name.toLowerCase().contains("oblique")) {
} else if (nameLowerCase.contains("oblique")) {
attributes.add("font-style: oblique;");
family = family.replaceFirst("(?i)-?Oblique", "");
} else {
attributes.add("font-style: normal;");
}
if (name.toLowerCase().contains("condensed") || name.toLowerCase().contains("narrow")) {
if (nameLowerCase.contains("condensed") || nameLowerCase.contains("narrow")) {
attributes.add("font-stretch: condensed;");
family = family.replaceFirst("(?i)-?Condensed", "");
family = family.replaceFirst("(?i)-?Narrow(er)?", "");
} else if (name.toLowerCase().contains("expanded") || name.toLowerCase().contains("wide")) {
} else if (nameLowerCase.contains("expanded") || nameLowerCase.contains("wide")) {
attributes.add("font-stretch: expanded;");
family = family.replaceFirst("(?i)-?Expanded", "");
family = family.replaceFirst("(?i)-?Wide(r)?", "");
Expand Down
25 changes: 14 additions & 11 deletions src/com/ichi2/anki/Reviewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public class Reviewer extends AnkiActivity {
* From http://stackoverflow.com/questions/2317428/android-i-want-to-shake-it Thilo Koehler
*/
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent se) {

float x = se.values[0];
Expand All @@ -418,6 +419,7 @@ public void onSensorChanged(SensorEvent se) {
}


@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
Expand Down Expand Up @@ -1721,8 +1723,8 @@ private void initLayout(Integer layout) {
mTextBarBlue = (TextView) findViewById(R.id.blue_number);

if (mShowProgressBars) {
mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
mSessionProgressBar = (View) findViewById(R.id.session_progress);
mSessionProgressTotalBar = findViewById(R.id.daily_bar);
mSessionProgressBar = findViewById(R.id.session_progress);
mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
}

Expand Down Expand Up @@ -2208,15 +2210,15 @@ private void updateStatisticBars() {
private Runnable mShowQuestionTask = new Runnable() {
public void run() {
// Assume hitting the "Again" button when auto next question
if (mEase1Layout.isEnabled() == true && mEase1Layout.getVisibility() == View.VISIBLE) {
if (mEase1Layout.isEnabled() && mEase1Layout.getVisibility() == View.VISIBLE) {
mEase1Layout.performClick();
}
}
};

private Runnable mShowAnswerTask = new Runnable() {
public void run() {
if (mFlipCardLayout.isEnabled() == true && mFlipCardLayout.getVisibility() == View.VISIBLE) {
if (mFlipCardLayout.isEnabled() && mFlipCardLayout.getVisibility() == View.VISIBLE) {
mFlipCardLayout.performClick();
}
}
Expand Down Expand Up @@ -2351,7 +2353,7 @@ private void displayCardAnswer() {
// Obtain the diff and send it to updateCard
DiffEngine diff = new DiffEngine();

StringBuffer span = new StringBuffer();
StringBuilder span = new StringBuilder();
span.append("<span style=\"font-family: '").append(mTypeFont)
.append("'; font-size: ").append(mTypeSize).append("px\">");
span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
Expand Down Expand Up @@ -2680,7 +2682,7 @@ public static Card getEditorCard() {
* @return
*/
private static String enrichWithQADiv(String content, boolean isAnswer) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append("<div class=\"");
if (isAnswer) {
sb.append(ANSWER_CLASS);
Expand Down Expand Up @@ -2776,7 +2778,7 @@ private final boolean typeAnswer() {
* Calculates a dynamic font size depending on the length of the contents taking into account that the input string
* contains html-tags, which will not be displayed and therefore should not be taken into account.
*
* @param htmlContents
* @param htmlContent
* @return font size respecting MIN_DYNAMIC_FONT_SIZE and MAX_DYNAMIC_FONT_SIZE
*/
private static int calculateDynamicFontSize(String htmlContent) {
Expand Down Expand Up @@ -2924,12 +2926,12 @@ public boolean getRefreshWebviewAndInitializeWebviewVariables() {
mCustomFonts.put(f.getName(), f);
}
for (String s : new String[] { "nook" }) {
if (android.os.Build.DEVICE.toLowerCase().indexOf(s) != -1
|| android.os.Build.MODEL.toLowerCase().indexOf(s) != -1) {
if (android.os.Build.DEVICE.toLowerCase().contains(s)
|| android.os.Build.MODEL.toLowerCase().contains(s)) {
return true;
}
}
if (mCustomFonts.size() != 0) {
if (!mCustomFonts.isEmpty()) {
return true;
}
return false;
Expand Down Expand Up @@ -3033,7 +3035,7 @@ private void executeCommand(int which) {
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging your javascript.
*/
public final class AnkiDroidWebChromeClient extends WebChromeClient {
public static final class AnkiDroidWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.i(AnkiDroidApp.TAG, message);
Expand Down Expand Up @@ -3274,6 +3276,7 @@ public void run() {

private TagHandler mSimpleInterfaceTagHandler = new TagHandler () {

@Override
public void handleTag(boolean opening, String tag, Editable output,
XMLReader xmlReader) {
// if(tag.equalsIgnoreCase("div")) {
Expand Down
10 changes: 5 additions & 5 deletions src/com/ichi2/async/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,12 @@ 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;
Expand Down Expand Up @@ -939,11 +939,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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/ichi2/libanki/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ public long fixIntegrity() {
if (m.getInt("type") != Sched.MODEL_STD) {
continue;
}
ArrayList<Integer> ords = new ArrayList<Integer>();
JSONArray tmpls = m.getJSONArray("tmpls");
List<Integer> ords = new ArrayList<Integer>(tmpls.length());
for (int t = 0; t < tmpls.length(); t++) {
ords.add(tmpls.getJSONObject(t).getInt("ord"));
}
Expand Down
26 changes: 13 additions & 13 deletions src/com/ichi2/libanki/Decks.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class Decks {
private boolean mChanged;


/**
/*
* Registry save/load *******************************************************
* ****************************************
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ public void flush() {
}


/**
/*
* Deck save/load *********************************************************** ************************************
*/

Expand Down Expand Up @@ -441,7 +441,7 @@ public String _ensureParents(String name) {
}


/**
/*
* Deck configurations ******************************************************
* *****************************************
*/
Expand Down Expand Up @@ -542,7 +542,7 @@ public void setConf(JSONObject deck, long id) {
// didsforConf
// restoretodefault

/**
/*
* Deck utils *************************************************************** ********************************
*/

Expand Down Expand Up @@ -627,11 +627,11 @@ public void recoverOrphans() {
}


/**
/*
* Deck selection *********************************************************** ************************************
*/

/* The currrently active dids. MAke sure to copy before modifying */
/** The currrently active dids. MAke sure to copy before modifying */
public LinkedList<Long> active() {
try {
String actv = mCol.getConf().getString("activeDecks");
Expand All @@ -647,7 +647,7 @@ public LinkedList<Long> active() {
}


/* The currently selected did. */
/** The currently selected did. */
public long selected() {
try {
return mCol.getConf().getLong("curDeck");
Expand All @@ -662,7 +662,7 @@ public JSONObject current() {
}


/* Select a new branch. */
/** Select a new branch. */
public void select(long did) {
try {
String name = mDecks.get(did).getString("name");
Expand All @@ -683,7 +683,7 @@ public void select(long did) {
}


/* all children of did as (name, id) */
/** all children of did as (name, id) */
public TreeMap<String, Long> children(long did) {
String name;
try {
Expand All @@ -701,7 +701,7 @@ public TreeMap<String, Long> children(long did) {
}


/* all parents of did */
/** all parents of did */
public ArrayList<JSONObject> parents(long did) {
// get parent and grandparent names
ArrayList<JSONObject> list = new ArrayList<JSONObject>();
Expand All @@ -723,7 +723,7 @@ public ArrayList<JSONObject> parents(long did) {
}


/**
/*
* Sync handling ************************************************************ ***********************************
*/

Expand All @@ -742,11 +742,11 @@ public void beforeUpload() {
}


/**
/*
* Deck utils
***************************************************************/

/* Return a new dynamic deck and set it as the current deck. */
/** Return a new dynamic deck and set it as the current deck. */
public long newDyn(String name) {
long did = id(name, true, defaultDynamicDeck);
select(did);
Expand Down
8 changes: 4 additions & 4 deletions src/com/ichi2/libanki/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void syncRemove(JSONArray fnames) {
try {
for (int i = 0; i < fnames.length(); ++i) {
String f = fnames.optString(i);
if (f == "") {
if (f.length() == 0) {
continue;
}
File file = new File(getDir(), f);
Expand Down Expand Up @@ -727,9 +727,9 @@ private Pair<List<String>, List<String>> _changes() {
}

// look for any entries in the cache that no longer exist on disk
for (String fname : used.keySet()) {
if (!used.get(fname)) {
removed.add(fname);
for (Map.Entry<String, Boolean> pair : used.entrySet()) {
if (!pair.getValue()) {
removed.add(pair.getKey());
}
}
return new Pair<List<String>, List<String>>(added, removed);
Expand Down
19 changes: 12 additions & 7 deletions src/com/ichi2/libanki/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Tags {
private boolean mChanged;


/**
/*
* Registry save/load
* ***********************************************************************************************
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ public void flush() {
}


/**
/*
* Registering and fetching tags
* ***********************************************************************************************
*/
Expand Down Expand Up @@ -162,23 +162,28 @@ public void save() {
}


/**
/*
* Bulk addition/removal from notes
* ***********************************************************************************************
*/

/**
* Add/remove tags in bulk
* Adds tags in bulk.
*
* @param ids The cards to tag.
* @param tags List of tags to add/remove. They are space-separated.
* @param add True/False to add/remove.
*/
public void bulkAdd(List<Long> ids, String tags) {
bulkAdd(ids, tags, true);
}


/**
* Adds/removes tags in bulk.
*
* @param ids The cards to tag.
* @param tags List of tags to add/remove. They are space-separated.
* @param add True/False to add/remove.
*/
public void bulkAdd(List<Long> ids, String tags, boolean add) {
List<String> newTags = split(tags);
if (newTags == null || newTags.isEmpty()) {
Expand Down Expand Up @@ -236,7 +241,7 @@ public void bulkRem(List<Long> ids, String tags) {
}


/**
/*
* String-based utilities
* ***********************************************************************************************
*/
Expand Down
Loading