remove debug logs and add documentation

This commit is contained in:
Roi 2018-08-21 21:51:10 +03:00
parent 8503507828
commit 42d9a86487
5 changed files with 56 additions and 52 deletions

View File

@ -22,7 +22,6 @@ import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -59,7 +58,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.ope
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version; import nodomain.freeyourgadget.gadgetbridge.util.Version;
@ -87,18 +85,13 @@ public class AmazfitBipSupport extends HuamiSupport {
String senderOrTiltle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title); String senderOrTiltle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
String message = StringUtils.truncate(senderOrTiltle, 32) + "\0"; String message = StringUtils.truncate(senderOrTiltle, 32) + "\0";
Log.d("ROIGR", "senderOrTiltle: " + senderOrTiltle);
if (notificationSpec.subject != null) { if (notificationSpec.subject != null) {
message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n"; message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n";
Log.d("ROIGR", "subject: " + notificationSpec.subject);
} }
if (notificationSpec.body != null) { if (notificationSpec.body != null) {
message += StringUtils.truncate(notificationSpec.body, 128); message += StringUtils.truncate(notificationSpec.body, 128);
Log.d("ROIGR", "body: " + notificationSpec.body);
} }
// message = LanguageUtils.fixRtl(message, message.length());
try { try {
TransactionBuilder builder = performInitialized("new notification"); TransactionBuilder builder = performInitialized("new notification");

View File

@ -18,18 +18,15 @@
package nodomain.freeyourgadget.gadgetbridge.util; package nodomain.freeyourgadget.gadgetbridge.util;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -160,15 +157,15 @@ public class LanguageUtils {
} }
/** /**
* Checks the status of transliteration option * Checks the status of right-to-left option
* @return true if transliterate option is On, and false, if Off or not exist * @return true if right-to-left option is On, and false, if Off or not exist
*/ */
public static boolean rtlSupport() public static boolean rtlSupport()
{ {
return GBApplication.getPrefs().getBoolean("rtl", false); return GBApplication.getPrefs().getBoolean("rtl", false);
} }
//transliteration map with english equivalent for unsupported chars //map with brackets chars to change there direction
private static Map<Character, Character> directionSignsMap = new HashMap<Character, Character>(){ private static Map<Character, Character> directionSignsMap = new HashMap<Character, Character>(){
{ {
put('(', ')'); put(')', '('); put('[', ']'); put(']', '['); put('{','}'); put('}','{'); put('(', ')'); put(')', '('); put('[', ']'); put(']', '['); put('{','}'); put('}','{');
@ -177,7 +174,7 @@ public class LanguageUtils {
} }
}; };
//transliteration map with english equivalent for unsupported chars //list of unicode ranges of rtl chars
private static ArrayList <Pair<Character, Character>> rtlRange = new ArrayList<Pair<Character, Character>>() { private static ArrayList <Pair<Character, Character>> rtlRange = new ArrayList<Pair<Character, Character>>() {
{ {
add(new Pair<Character, Character>('\u0590', '\u05F4')); add(new Pair<Character, Character>('\u0590', '\u05F4'));
@ -190,6 +187,9 @@ public class LanguageUtils {
} }
}; };
/**
* @return true if the char is in the rtl range, otherwise false
*/
private static Boolean isRtl(char c){ private static Boolean isRtl(char c){
for (Pair<Character, Character> rang: rtlRange) { for (Pair<Character, Character> rang: rtlRange) {
if (rang.first <= c && c <= rang.second) { if (rang.first <= c && c <= rang.second) {
@ -199,7 +199,8 @@ public class LanguageUtils {
return false; return false;
} }
private static ArrayList <Pair<Character, Character>> stsRange = new ArrayList<Pair<Character, Character>>() { //list of unicode ranges of punctuations chars
private static ArrayList <Pair<Character, Character>> punctuationsRange = new ArrayList<Pair<Character, Character>>() {
{ {
add(new Pair<Character, Character>('\u0021', '\u002F')); add(new Pair<Character, Character>('\u0021', '\u002F'));
add(new Pair<Character, Character>('\u003A', '\u0040')); add(new Pair<Character, Character>('\u003A', '\u0040'));
@ -208,8 +209,11 @@ public class LanguageUtils {
} }
}; };
private static Boolean isSts(char c){ /**
for (Pair<Character, Character> rang: stsRange) { * @return true if the char is in the punctuations range, otherwise false
*/
private static Boolean isPunctuations(char c){
for (Pair<Character, Character> rang: punctuationsRange) {
if (rang.first <= c && c <= rang.second) { if (rang.first <= c && c <= rang.second) {
return true; return true;
} }
@ -217,7 +221,8 @@ public class LanguageUtils {
return false; return false;
} }
private static ArrayList<Character> endSigns = new ArrayList<Character>() { //list of sign that ends a word
private static ArrayList<Character> wordEndSigns = new ArrayList<Character>() {
{ {
add('\0'); add('\0');
add('\n'); add('\n');
@ -225,8 +230,11 @@ public class LanguageUtils {
} }
}; };
private static Boolean isEndSign(char c){ /**
for (char sign: endSigns){ * @return true if the char is in the end of word list, otherwise false
*/
private static Boolean isWordEndSign(char c){
for (char sign: wordEndSigns){
if (c == sign){ if (c == sign){
return true; return true;
} }
@ -235,30 +243,45 @@ public class LanguageUtils {
return false; return false;
} }
private static String reverse(String a) { /**
int j = a.length(); * The function get a string and reverse it.
* in case of end-of-word sign, it will leave it at the end.
* in case of sign with direction like brackets, it will change the direction.
* @param s - the string to reverse
* @return reversed string
*/
private static String reverse(String s) {
int j = s.length();
int startWithSpace = 0; int startWithSpace = 0;
char[] newWord = new char[j]; char[] newWord = new char[j];
if (j == 0) { if (j == 0) {
return a; return s;
} }
if (isEndSign(a.charAt(a.length() - 1))){ // remain end-of-word sign at the end
if (isWordEndSign(s.charAt(s.length() - 1))){
startWithSpace = 1; startWithSpace = 1;
newWord[--j] = a.charAt(a.length() - 1); newWord[--j] = s.charAt(s.length() - 1);
} }
for (int i = 0; i < a.length() - startWithSpace; i++) { for (int i = 0; i < s.length() - startWithSpace; i++) {
if (LanguageUtils.directionSignsMap.containsKey(a.charAt(i))) { if (LanguageUtils.directionSignsMap.containsKey(s.charAt(i))) {
newWord[--j] = LanguageUtils.directionSignsMap.get(a.charAt(i)); newWord[--j] = LanguageUtils.directionSignsMap.get(s.charAt(i));
} else { } else {
newWord[--j] = a.charAt(i); newWord[--j] = s.charAt(i);
} }
} }
return new String(newWord); return new String(newWord);
} }
/**
* The function get a string and fix the rtl words.
* since simple reverse puts the beginning of the text at the end, the text should have been from bottom to top.
* To avoid that, we save the text in lines (line max size can be change in the settings)
* @param s - the string to fix.
* @return a fix string.
*/
public static String fixRtl(String s) { public static String fixRtl(String s) {
if (s == null || s.isEmpty()){ if (s == null || s.isEmpty()){
return s; return s;
@ -277,13 +300,12 @@ public class LanguageUtils {
String line = ""; String line = "";
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
c = oldString.charAt(i); c = oldString.charAt(i);
Log.d("ROIGR", String.format("%s: i %x i", c, (int) c)); if ((LanguageUtils.isRtl(c) == isRtlState || LanguageUtils.isPunctuations(c)) && i < length - 1) {
if ((LanguageUtils.isRtl(c) == isRtlState || LanguageUtils.isSts(c)) && i < length - 1) {
endPos++; endPos++;
} else { } else {
String word; String word;
if (isEndSign(c)){ if (isWordEndSign(c)){
endPos++; endPos++;
} }
@ -295,7 +317,6 @@ public class LanguageUtils {
} else { } else {
word = (oldString.substring(startPos, endPos)); word = (oldString.substring(startPos, endPos));
} }
Log.d("ROIGR", String.format("|%s| is now |%s|", oldString.substring(startPos, endPos), word));
if (line.length() + word.length() > line_max_size) { if (line.length() + word.length() > line_max_size) {
lines.add(line + "\n"); lines.add(line + "\n");
line = ""; line = "";
@ -306,7 +327,7 @@ public class LanguageUtils {
line = ""; line = "";
} }
startPos = endPos; startPos = endPos;
if (!isEndSign(c)){ if (!isWordEndSign(c)){
endPos++; endPos++;
isRtlState = !isRtlState; isRtlState = !isRtlState;
} }
@ -316,13 +337,7 @@ public class LanguageUtils {
lines.add(line); lines.add(line);
newString = TextUtils.join("", lines); newString = TextUtils.join("", lines);
Log.d("ROIGR", "lines:\n\n" + lines);
Log.d("ROIGR", "final messege:\n\n" + newString);
// if (LanguageUtils.isRtl(s.charAt(0))){
// newString = reverse(s);
// } else {
// newString = s;
// }
return newString; return newString;
} }
} }

View File

@ -17,9 +17,6 @@
package nodomain.freeyourgadget.gadgetbridge.util; package nodomain.freeyourgadget.gadgetbridge.util;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log;
import java.util.ArrayList;
public class StringUtils { public class StringUtils {
@ -32,7 +29,7 @@ public class StringUtils {
} }
int length = Math.min(s.length(), maxLength); int length = Math.min(s.length(), maxLength);
if(length <= 0) { if(length < 0) {
return ""; return "";
} }

View File

@ -621,5 +621,4 @@
<string name="watch9_calibration_button">Calibrate</string> <string name="watch9_calibration_button">Calibrate</string>
<string name="title_activity_watch9_pairing">Watch 9 pairing</string> <string name="title_activity_watch9_pairing">Watch 9 pairing</string>
<string name="title_activity_watch9_calibration">Watch 9 calibration</string> <string name="title_activity_watch9_calibration">Watch 9 calibration</string>
</resources> </resources>

View File

@ -156,12 +156,12 @@
android:title="@string/pref_title_whenscreenon" /> android:title="@string/pref_title_whenscreenon" />
<CheckBoxPreference <CheckBoxPreference
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"
android:defaultValue="false" android:defaultValue="false"
android:key="transliteration" android:key="transliteration"
android:summary="@string/pref_summary_transliteration" android:summary="@string/pref_summary_transliteration"
android:title="@string/pref_title_transliteration" android:title="@string/pref_title_transliteration"
/> />
<CheckBoxPreference <CheckBoxPreference
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"