Remove the preview popup

This was a half-finished feature:
- Dangerous when typing passwords
- Caused crash on some devices
- Ugly (on its own but also blinking when sliding and not fixed in size)
This commit is contained in:
Jules Aguillon 2021-01-05 00:18:24 +01:00
parent 1cda23ad2c
commit 8dc085048a
8 changed files with 0 additions and 167 deletions

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corner android:radius="@dimen/preview_corners" />
<solid android:color="@color/preview_bg" />
<stroke
android:width="@dimen/preview_stroke"
android:color="@color/preview_stroke"
/>
</shape>

View File

@ -6,9 +6,6 @@
<item name="key_label" type="color">#FFFFFF</item>
<item name="key_label_locked" type="color">#229933</item>
<item name="key_sub_label" type="color">#A0A0A0</item>
<item name="preview_text" type="color">#FFFFFF</item>
<item name="preview_bg" type="color">#202020</item>
<item name="preview_stroke" type="color">#666666</item>
<item name="emoji_button_bg" type="color">#202020</item>
<item name="emoji_color" type="color">#FFFFFF</item>
<item name="emoji_key_bg" type="color">@color/emoji_button_bg</item>

View File

@ -9,11 +9,6 @@
<dimen name="key_round">4dp</dimen>
<dimen name="label_text_size">16dp</dimen>
<dimen name="sublabel_text_size">10dp</dimen>
<dimen name="preview_text">16dp</dimen>
<dimen name="preview_corners">6dp</dimen>
<dimen name="preview_stroke">1dp</dimen>
<dimen name="preview_margin">4dp</dimen>
<dimen name="preview_padding">8dp</dimen>
<dimen name="emoji_type_button_height">56dp</dimen>
<dimen name="emoji_grid_height">250dp</dimen>
</resources>

View File

@ -34,8 +34,4 @@
<string name="pref_key_height_summary">%sdp</string>
<string name="pref_horizontal_margin_title">Horizontal margin</string>
<string name="pref_horizontal_margin_summary">%sdp</string>
<string name="pref_category_preview">Preview</string>
<string name="pref_preview_title">Preview</string>
<string name="pref_preview_summary">Enable/Disable preview on key down</string>
</resources>

View File

@ -52,14 +52,6 @@
max="50"
/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_preview">
<CheckBoxPreference
android:key="preview_enabled"
android:title="@string/pref_preview_title"
android:summary="@string/pref_preview_summary"
android:defaultValue="false"
/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_style">
<juloo.common.IntSlideBarPreference
android:key="margin_bottom"

View File

@ -10,14 +10,11 @@ class Config
private Keyboard2 _context;
public final long previewDismissTimeout;
public final int previewBottomMargin;
public final float marginTop;
public final float keyPadding;
public final float keyBgPadding;
public final float keyRound;
public boolean previewEnabled;
public float subValueDist;
public boolean vibrateEnabled;
public long vibrateDuration;
@ -33,14 +30,11 @@ class Config
_context = context;
// static values
previewDismissTimeout = 150;
previewBottomMargin = (int)res.getDimension(R.dimen.preview_margin);
marginTop = res.getDimension(R.dimen.margin_top);
keyPadding = res.getDimension(R.dimen.key_padding);
keyBgPadding = res.getDimension(R.dimen.key_bg_padding);
keyRound = res.getDimension(R.dimen.key_round);
// default values
previewEnabled = false;
subValueDist = 10f;
vibrateEnabled = true;
vibrateDuration = 20;
@ -60,7 +54,6 @@ class Config
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
previewEnabled = prefs.getBoolean("preview_enabled", previewEnabled);
subValueDist = prefs.getFloat("sub_value_dist", subValueDist);
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);

View File

@ -1,108 +0,0 @@
package juloo.keyboard2;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;
class KeyPreviewPopup extends PopupWindow
implements Handler.Callback
{
private final TextView _content;
private final View _anchor;
private Config _config;
private final Handler _handler;
private int _minWidth;
public KeyPreviewPopup(View anchor, Config config)
{
super(anchor.getContext());
_config = config;
_content = new TextView(anchor.getContext());
/*
** TODO: move all resources get to Config object
*/
_content.setTextColor(anchor.getResources().getColor(R.color.preview_text));
_content.setTextSize(anchor.getResources().getDimension(R.dimen.preview_text));
int padding = (int)anchor.getResources().getDimension(R.dimen.preview_padding);
_content.setPaddingRelative(padding, padding, padding, padding);
_content.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
_content.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
_anchor = anchor;
_handler = new Handler(this);
setMinWidth(0);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setBackgroundDrawable(anchor.getResources().getDrawable(R.drawable.preview_popup));
setContentView(_content);
setClippingEnabled(false);
setTouchable(false);
}
@Override
public boolean handleMessage(Message msg)
{
forceDismiss();
return (true);
}
public void forceDismiss()
{
setMinWidth(0);
dismiss();
}
public void setPreview(KeyValue key, int flags)
{
StringBuilder preview;
if (key == null)
{
_handler.sendEmptyMessageDelayed(0, _config.previewDismissTimeout);
return ;
}
_handler.removeMessages(0);
preview = new StringBuilder();
if ((flags & KeyValue.FLAG_CTRL) != 0)
preview.append("Ctrl-");
if ((flags & KeyValue.FLAG_ALT) != 0)
preview.append("Alt-");
if ((flags & KeyValue.FLAG_SHIFT) != 0 && !Character.isLetter(key.getChar(0)))
preview.append("Shift-");
preview.append(key.getSymbol(flags));
_content.setText(preview.toString());
show();
}
private void setMinWidth(int minWidth)
{
_minWidth = minWidth;
_content.setMinWidth(minWidth);
}
private void show()
{
int x;
int y;
int width;
int height;
_content.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
width = _content.getMeasuredWidth();
height = _content.getMeasuredHeight();
if (width > _minWidth)
setMinWidth(width);
x = (_anchor.getMeasuredWidth() - width) / 2;
y = -(height + _config.previewBottomMargin);
if (!isShowing())
showAtLocation(_anchor, Gravity.NO_GRAVITY, x, y);
update(x, y, width, height);
}
}

View File

@ -34,13 +34,6 @@ public class Keyboard2View extends View
private Handler _handler;
private static int _currentWhat = 0;
private KeyPreviewPopup _previewPopup;
/*
** TODO: settings: preview_text_size
** TODO: settings: preview_timeout
** TODO: disable preview in password fields
*/
private Config _config;
private float _keyWidth;
@ -64,7 +57,6 @@ public class Keyboard2View extends View
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
_handler = new Handler(this);
_config = ((Keyboard2)context).getConfig();
_previewPopup = new KeyPreviewPopup(this, _config);
_keyBgPaint.setColor(getResources().getColor(R.color.key_bg));
_keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg));
_keyLabelPaint = initLabelPaint(_keyLabelPaint, Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, null);
@ -273,24 +265,12 @@ public class Keyboard2View extends View
{
if (key.value != null && (key.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0)
((Keyboard2)getContext()).handleKeyUp(key.value, _flags);
// previewNextKeyDown
if (!_config.previewEnabled)
return ;
for (KeyDown k : _downKeys)
if ((k.value.getFlags() & (KeyValue.FLAG_KEY_FONT | KeyValue.FLAG_NOREPEAT | KeyValue.FLAG_NOCHAR)) == 0)
{
_previewPopup.setPreview(k.value, _flags);
return ;
}
_previewPopup.setPreview(null, 0);
}
private void handleKeyDown(KeyValue key)
{
if (key == null)
return ;
if (_config.previewEnabled && (key.getFlags() & (KeyValue.FLAG_KEY_FONT | KeyValue.FLAG_NOREPEAT | KeyValue.FLAG_NOCHAR)) == 0)
_previewPopup.setPreview(key, _flags);
vibrate();
}
@ -395,7 +375,6 @@ public class Keyboard2View extends View
public void onDetachedFromWindow()
{
super.onDetachedFromWindow();
_previewPopup.forceDismiss();
}
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, boolean locked)