forked from extern/Unexpected-Keyboard
Refactor: Centralize logging in a static class
This new class will help write more logs. The LogPrinter is no longer created everytime the keyboard is opened. An error log is added if failing to load the custom extra keys.
This commit is contained in:
parent
458e17bf31
commit
8b2c07c9cb
@ -109,7 +109,10 @@ public class CustomExtraKeysPreference extends PreferenceCategory
|
||||
for (int i = 0; i < arr.length(); i++)
|
||||
keys.add(arr.getString(i));
|
||||
}
|
||||
catch (JSONException e) {}
|
||||
catch (JSONException e)
|
||||
{
|
||||
Logs.err_load_custom_extra_keys(e);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,6 @@ import java.util.Set;
|
||||
public class Keyboard2 extends InputMethodService
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
static private final String TAG = "Keyboard2";
|
||||
|
||||
private Keyboard2View _keyboardView;
|
||||
private KeyEventHandler _keyeventhandler;
|
||||
// If not 'null', the layout to use instead of [_currentTextLayout].
|
||||
@ -40,8 +38,6 @@ public class Keyboard2 extends InputMethodService
|
||||
|
||||
private Config _config;
|
||||
|
||||
private boolean _debug_logs = false;
|
||||
|
||||
/** Layout currently visible. */
|
||||
KeyboardData current_layout()
|
||||
{
|
||||
@ -87,7 +83,7 @@ public class Keyboard2 extends InputMethodService
|
||||
_config = Config.globalConfig();
|
||||
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
||||
_keyboardView.reset();
|
||||
_debug_logs = getResources().getBoolean(R.bool.debug_logs);
|
||||
Logs.set_debug_logs(getResources().getBoolean(R.bool.debug_logs));
|
||||
}
|
||||
|
||||
private List<InputMethodSubtype> getEnabledSubtypes(InputMethodManager imm)
|
||||
@ -239,16 +235,6 @@ public class Keyboard2 extends InputMethodService
|
||||
return null;
|
||||
}
|
||||
|
||||
private void log_editor_info(EditorInfo info)
|
||||
{
|
||||
LogPrinter p = new LogPrinter(Log.DEBUG, TAG);
|
||||
info.dump(p, "");
|
||||
if (info.extras != null)
|
||||
Log.d(TAG, "extras: "+info.extras.toString());
|
||||
Log.d(TAG, "swapEnterActionKey: "+_config.swapEnterActionKey);
|
||||
Log.d(TAG, "actionLabel: "+_config.actionLabel);
|
||||
}
|
||||
|
||||
private void refresh_special_layout(EditorInfo info)
|
||||
{
|
||||
switch (info.inputType & InputType.TYPE_MASK_CLASS)
|
||||
@ -274,8 +260,7 @@ public class Keyboard2 extends InputMethodService
|
||||
_keyboardView.setKeyboard(current_layout());
|
||||
_keyeventhandler.started(info);
|
||||
setInputView(_keyboardView);
|
||||
if (_debug_logs)
|
||||
log_editor_info(info);
|
||||
Logs.debug_startup_input_view(info, _config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
34
srcs/juloo.keyboard2/Logs.java
Normal file
34
srcs/juloo.keyboard2/Logs.java
Normal file
@ -0,0 +1,34 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.LogPrinter;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import org.json.JSONException;
|
||||
|
||||
public final class Logs
|
||||
{
|
||||
static final String TAG = "juloo.keyboard2";
|
||||
|
||||
static LogPrinter _debug_logs = null;
|
||||
|
||||
public static void set_debug_logs(boolean d)
|
||||
{
|
||||
_debug_logs = d ? new LogPrinter(Log.DEBUG, TAG) : null;
|
||||
}
|
||||
|
||||
public static void debug_startup_input_view(EditorInfo info, Config conf)
|
||||
{
|
||||
if (_debug_logs == null)
|
||||
return;
|
||||
info.dump(_debug_logs, "");
|
||||
if (info.extras != null)
|
||||
_debug_logs.println("extras: "+info.extras.toString());
|
||||
_debug_logs.println("swapEnterActionKey: "+conf.swapEnterActionKey);
|
||||
_debug_logs.println("actionLabel: "+conf.actionLabel);
|
||||
}
|
||||
|
||||
public static void err_load_custom_extra_keys(JSONException e)
|
||||
{
|
||||
Log.e(TAG, "Failed to read custom extra keys from preferences", e);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user