Merge pull request #837 from keymanapp/android-cleanup-console-log

[android] cleanup console log
This commit is contained in:
Darcy Wong 2018-05-08 11:17:02 +07:00 committed by GitHub
commit 4fd4349632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 81 deletions

View file

@ -71,7 +71,6 @@ public class SystemKeyboard extends InputMethodService implements OnKeyboardEven
*/
@Override
public View onCreateInputView() {
//Log.i("SystemKeyboard", "onCreateInputView");
if (inputView == null) {
inputView = KMManager.createInputView(this);
}
@ -105,7 +104,6 @@ public class SystemKeyboard extends InputMethodService implements OnKeyboardEven
KMManager.onStartInput(attribute, restarting);
KMManager.resetContext(KeyboardType.KEYBOARD_TYPE_SYSTEM);
//Log.i("SystemKeyboard", "onStartInput");
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ExtractedText icText = ic.getExtractedText(new ExtractedTextRequest(), 0);
@ -123,13 +121,11 @@ public class SystemKeyboard extends InputMethodService implements OnKeyboardEven
@Override
public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);
//Log.i("SystemKeyboard", "onStartInputView");
}
@Override
public void onUpdateExtractingVisibility(EditorInfo ei) {
super.onUpdateExtractingVisibility(ei);
//Log.i("SystemKeyboard", "onUpdateExtractingVisibility");
}
@Override

View file

@ -321,7 +321,7 @@ public class MainActivity extends Activity implements OnKeyboardEventListener, O
}
break;
default :
Log.d(TAG, "Unrecognized protocol " + data.getScheme());
Log.e(TAG, "Unrecognized protocol " + data.getScheme());
}
}
intent.setData(null);
@ -614,15 +614,12 @@ public class MainActivity extends Activity implements OnKeyboardEventListener, O
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_STORAGE) {
// Request for storage permission
Log.d(TAG, "Received response for Storage permission request");
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission has been granted. Resume task needing this permission
Log.d(TAG, "Permission: " + permissions[0] + " was " + grantResults[0]);
useLocalKMP(data);
} else {
// Permission request denied
String message = "Storage permission request was denied. Unable to install keyboard package";
Log.d(TAG, message);
Toast.makeText(getApplicationContext(), message,
Toast.LENGTH_SHORT).show();
}
@ -634,16 +631,13 @@ public class MainActivity extends Activity implements OnKeyboardEventListener, O
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Read external storage permission granted");
useLocalKMP(data);
} else {
Log.d(TAG, "Read external storage permission denied");
// Permission is missing and must be requested
requestStoragePermission();
}
} else {
// Permission automatically granted on older Android versions
Log.d(TAG, "Read external storage permission granted");
useLocalKMP(data);
}
}
@ -703,7 +697,6 @@ public class MainActivity extends Activity implements OnKeyboardEventListener, O
cacheKMPFile.delete();
}
Log.d(TAG, "Copying " + filename + " to app cache");
FileUtils.copy(inputFile, new FileOutputStream(cacheKMPFile));
} else {
String noKeyboardsInstalledMessage = " is not a valid keyboard package file.\nNo keyboards were installed.";

View file

@ -1,6 +1,6 @@
<html>
<!--
Copyright (C) 2017 SIL International. All rights reserved.
Copyright (C) 2017-2018 SIL International. All rights reserved.
-->
<head>
@ -16,8 +16,8 @@
function init() {
//document.body.style.backgroundColor="transparent";
window.console.log('Device type = '+device);
window.console.log('Keyboard height = '+oskHeight);
//window.console.log('Device type = '+device);
//window.console.log('Keyboard height = '+oskHeight);
var kmw=window['keyman'];
kmw.init({'app':device,'fonts':'packages/'});
kmw['util']['setOption']('attachType','manual');
@ -57,7 +57,7 @@
if(oskWidth <= 0) {
oskWidth = window.jsInterface.getKeyboardWidth();
}
window.console.log('Keyboard width = '+oskWidth);
//window.console.log('Keyboard width = '+oskWidth);
return oskWidth;
}
@ -66,16 +66,12 @@
var name = typeof(keyboardProperties.internalName) == 'undefined' ? keyboardProperties.keyboardName : keyboardProperties.internalName;
var kmw=window['keyman'];
var isChiral = kmw.isChiral(name);
window.console.log('For keyboard "' + name + '"');
window.console.log('setIsChiral = ' + isChiral);
window.jsInterface.setIsChiral(isChiral);
return true;
}
function setKeymanLanguage(keyboardName, internalName, languageName, langId, kbdFile, font, oskFont, package) {
//oskFont.files = ['NotoSansSyriacWestern-Regular.svg#NotoSansSyriacWesternRegular'];
//window.console.log('oskFonts = '+JSON.stringify(oskFont));
var kmw=window['keyman'];
var kbdInterface=kmw['interface'];
@ -108,11 +104,11 @@
};
if (font) {
k.KFont = font;
window.console.log('keyboard.html assigning k.KFont = ' + font);
//window.console.log('keyboard.html assigning k.KFont = ' + font);
}
if (oskFont) {
k.KOskFont = oskFont;
window.console.log('keyboard.html assigning k.KOskFont = ' + oskFont);
//window.console.log('keyboard.html assigning k.KOskFont = ' + oskFont);
}
kbdInterface.registerStub(k);
@ -121,7 +117,7 @@
}
function insertText(dn, s) {
window.console.log('insertText('+ dn +', ' + s +');');
//window.console.log('insertText('+ dn +', ' + s +');');
window.jsInterface.insertText(dn, s);
}
@ -198,7 +194,6 @@
fragmentToggle = (fragmentToggle + 1) % 100;
var kmw = window['keyman'];
var pos = kmw['touchMenuPos']();
window.console.log('showHelpBubble ' + pos);
window.location.hash = 'showHelpBubble-' + fragmentToggle + '+keyPos=' + pos;
}
@ -206,18 +201,18 @@
var kmw=window['keyman'];
// KMW only needs keyID to process the popup key. keyText merely logged to console
window.console.log('executePopupKey('+keyID+'); keyText: ' + keyText);
//window.console.log('executePopupKey('+keyID+'); keyText: ' + keyText);
kmw['executePopupKey'](keyID);
}
function executeHardwareKeystroke(code, shift, lstates) {
var kmw=window['keyman'];
window.console.log('executeHardwareKeystroke:('+code+', ' + shift + ', ' + lstates + ');');
//window.console.log('executeHardwareKeystroke:('+code+', ' + shift + ', ' + lstates + ');');
try {
var r = kmw['executeHardwareKeystroke'](code, shift, lstates);
window.console.log('executeHardwareKeystroke completed with '+r);
//window.console.log('executeHardwareKeystroke completed with '+r);
} catch(e) {
window.console.log('oops: '+e);
window.console.log('executeHardwareKeystroke exception: '+e);
}
}

View file

@ -351,9 +351,6 @@ final class KMKeyboard extends WebView {
String jsFormat = "javascript:setKeymanLanguage('%s','%s','%s','%s','%s', %s, %s, '%s')";
String jsString = String.format(jsFormat, keyboardName, keyboardID, languageName, languageID, keyboardPath, tFont, oFont, packageID);
loadUrl(jsString);
if (KMManager.isDebugMode()) {
Log.d("KMKeyboard", jsString);
}
this.packageID = packageID;
this.keyboardID = keyboardID;
@ -455,9 +452,6 @@ final class KMKeyboard extends WebView {
String jsFormat = "javascript:setKeymanLanguage('%s','%s','%s','%s','%s', %s, %s, '%s')";
String jsString = String.format(jsFormat, keyboardName, keyboardID, languageName, languageID, keyboardPath, tFont, oFont, packageID);
loadUrl(jsString);
if (KMManager.isDebugMode()) {
Log.d("KMKeyboard", jsString);
}
this.packageID = packageID;
this.keyboardID = keyboardID;

View file

@ -188,7 +188,7 @@ public final class KMManager {
} else if (keyboardType == KeyboardType.KEYBOARD_TYPE_SYSTEM) {
initSystemKeyboard(appContext);
} else {
Log.w(TAG, "Cannot initialize: Invalid keyboard type");
Log.e(TAG, "Cannot initialize: Invalid keyboard type");
}
// Initializes the PackageProcessor with the base resource directory, which is the parent directory
@ -225,8 +225,6 @@ public final class KMManager {
private static void initInAppKeyboard(Context appContext) {
if (InAppKeyboard == null) {
if (isDebugMode())
Log.d(TAG, "Initializing In-App Keyboard...");
int kbHeight = appContext.getResources().getDimensionPixelSize(R.dimen.keyboard_height);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, kbHeight);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
@ -242,8 +240,6 @@ public final class KMManager {
private static void initSystemKeyboard(Context appContext) {
if (SystemKeyboard == null) {
if (isDebugMode())
Log.d(TAG, "Initializing System Keyboard...");
int kbHeight = appContext.getResources().getDimensionPixelSize(R.dimen.keyboard_height);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, kbHeight);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
@ -743,7 +739,7 @@ public final class KMManager {
return SystemKeyboard;
} else {
// What should we do if KeyboardType.KEYBOARD_TYPE_UNDEFINED?
Log.w("KMManager", "Invalid keyboard");
Log.e("KMManager", "Invalid keyboard");
return null;
}
}
@ -1257,9 +1253,6 @@ public final class KMManager {
public void onPageFinished(WebView view, String url) {
if (url.endsWith(KMFilename_KeyboardHtml)) {
InAppKeyboardLoaded = true;
if (isDebugMode()) {
Log.d("KMManager", "In-App Keyboard loaded.");
}
if (!InAppKeyboard.keyboardSet) {
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
@ -1435,10 +1428,6 @@ public final class KMManager {
public void onPageFinished(WebView view, String url) {
if (url.endsWith(KMFilename_KeyboardHtml)) {
SystemKeyboardLoaded = true;
if (isDebugMode()) {
Log.d("KMManager", "System Keyboard loaded.");
}
if (!SystemKeyboard.keyboardSet) {
SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE);
int index = prefs.getInt(KMManager.KMKey_UserKeyboardIndex, 0);
@ -1624,9 +1613,6 @@ public final class KMManager {
// Store the current keyboard chirality status from KMW in InAppKeyboard
@JavascriptInterface
public void setIsChiral(boolean isChiral) {
if (isDebugMode()) {
Log.d("KMManager", "InAppKeyboard chirality: " + String.valueOf(isChiral));
}
InAppKeyboard.setChirality(isChiral);
}
@ -1637,8 +1623,9 @@ public final class KMManager {
mainLoop.post(new Runnable() {
public void run() {
if (InAppKeyboard.subKeysWindow != null || KMTextView.activeView == null || KMTextView.activeView.getClass() != KMTextView.class) {
if (KMTextView.activeView == null)
if ((KMTextView.activeView == null) && isDebugMode()) {
Log.w("IAK: JS Handler", "insertText failed: activeView is null");
}
return;
}
@ -1738,9 +1725,6 @@ public final class KMManager {
// Store the current keyboard chirality status from KMW in SystemKeyboard
@JavascriptInterface
public void setIsChiral(boolean isChiral) {
if (isDebugMode()) {
Log.d("KMManager", "SystemKeyboard chirality: " + String.valueOf(isChiral));
}
SystemKeyboard.setChirality(isChiral);
}
@ -1755,7 +1739,7 @@ public final class KMManager {
}
InputConnection ic = IMService.getCurrentInputConnection();
if (ic == null) {
if ((ic == null) && isDebugMode()) {
Log.w("SWK: JS Handler", "insertText failed: InputConnection is null");
return;
}

View file

@ -102,8 +102,6 @@ public final class KMTextView extends EditText {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (KMManager.isDebugMode())
Log.d("OnFocusChange", "gotFocus: " + v.toString());
activeView = v;
if (KMManager.InAppKeyboardLoaded) {
KMTextView textView = (KMTextView) activeView;
@ -115,8 +113,6 @@ public final class KMTextView extends EditText {
}
showKeyboard();
} else {
if (KMManager.isDebugMode())
Log.d("OnFocusChange", "lostFocus: " + v.toString());
activeView = null;
dismissKeyboard();
}
@ -166,8 +162,6 @@ public final class KMTextView extends EditText {
Activity activity = (Activity) context;
Window mainWindow = activity.getWindow();
if (hasWindowFocus) {
if (KMManager.isDebugMode())
Log.d("onWindowFocusChanged", "gotFocus:" + mainWindow.toString());
KMManager.KMInAppKeyboardWebViewClient.context = context;
activeView = mainWindow.getCurrentFocus();
@ -179,9 +173,6 @@ public final class KMTextView extends EditText {
}
if (activeView != null && activeView.equals(this)) {
if (KMManager.isDebugMode()) {
Log.d("onWindowFocusChanged", "activeView = " + activeView.toString());
}
if (KMManager.InAppKeyboardLoaded) {
KMTextView textView = (KMTextView) activeView;
int selStart = textView.getSelectionStart();
@ -194,10 +185,6 @@ public final class KMTextView extends EditText {
showKeyboard();
}
}
} else {
if (KMManager.isDebugMode()) {
Log.d("onWindowFocusChanged", "lostFocus:" + mainWindow.toString());
}
}
}
@ -291,8 +278,6 @@ public final class KMTextView extends EditText {
mainLayout.requestLayout();
mainLayout.invalidate();
if (KMManager.isDebugMode())
Log.d("showKeyboard()", "Keyboard shown");
KeyboardEventHandler.notifyListeners(kbEventListeners, KeyboardType.KEYBOARD_TYPE_INAPP, EventType.KEYBOARD_SHOWN, null);
}
@ -308,8 +293,6 @@ public final class KMTextView extends EditText {
keyboardLayout.setEnabled(false);
keyboardVisible = false;
if (KMManager.isDebugMode())
Log.d("dismissKeyboard()", "Keyboard dismissed");
KeyboardEventHandler.notifyListeners(kbEventListeners, KeyboardType.KEYBOARD_TYPE_INAPP, EventType.KEYBOARD_DISMISSED, null);
}

View file

@ -101,7 +101,7 @@ public class PackageProcessor {
JSONParser parser = new JSONParser();
return parser.getJSONObjectFromFile(infoFile);
} else {
Log.d("PackageProcessor", infoFile.toString() + " does not exist.");
Log.e("PackageProcessor", infoFile.toString() + " does not exist.");
return null;
}
}

View file

@ -88,14 +88,11 @@ public final class Connection {
urlValid = true;
ret = true;
} else {
Log.d("util.Connection", "HttpURLConnection response code: " + status);
// Handle HTTP Status Codes 3xx
if (HttpURLConnection.HTTP_MULT_CHOICE <= status &&
status <= HttpURLConnection.HTTP_USE_PROXY &&
status != HttpURLConnection.HTTP_NOT_MODIFIED) {
urlStr = urlConnection.getHeaderField("Location");
Log.d("util.Connection", "Redirecting from " + url + " to " + urlStr);
} else {
// Abort for all other Status Codes
break;

View file

@ -96,8 +96,6 @@ public final class FileUtils {
}
if (!tmpFile.renameTo(file)) {
ret = DOWNLOAD_ERROR;
} else if (KMManager.isDebugMode()) {
Log.d("FileUtils", "Download finished for filename " + file.toString());
}
} else {
ret = DOWNLOAD_ERROR;
@ -109,9 +107,7 @@ public final class FileUtils {
if (tmpFile.exists()) {
tmpFile.delete();
}
if (KMManager.isDebugMode()) {
Log.d("FileUtils", "Could not download filename " + file.toString());
}
Log.e("FileUtils", "Could not download filename " + file.toString());
}
Connection.disconnect();

View file

@ -2,6 +2,7 @@
## 2018-05-08 10.0.386 beta
* Fix crashes from invalid package name/version (#819)
* Clean up console log (#748)
## 2018-04-30 10.0.380 beta
* Fix OSK missing some keys on older Android configurations (#304)