Keyboard styles

This commit is contained in:
serso 2016-02-07 20:18:37 +01:00
parent 30eed6af8c
commit 47075b0c10
153 changed files with 225 additions and 118 deletions

Binary file not shown.

View File

@ -71,7 +71,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
final int parametersCount = parameterNames.size();
LinearLayout row = makeRow();
addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp);
addButton(row, 0, parametersCount > 0 ? parameterNames.get(0) : "x");
addButton(row, 0, "7");
addButton(row, 0, "8");
@ -88,7 +88,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, "6");
addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText("%", up).setText("sqrt", down);
addOperationButton(row, R.id.cpp_kb_button_minus, "");
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
row = makeRow();
@ -98,8 +98,8 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, "2");
addButton(row, 0, "3");
addButton(row, 0, "0").setText("00", up).setText("000", down);
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_white_24dp);
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp);
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp);
}
private void makeViewPort() {
@ -115,7 +115,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, "5");
addButton(row, 0, "6");
addOperationButton(row, R.id.cpp_kb_button_divide, "/").setText("%", up).setText("sqrt", down);
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
final View backspace = addImageButton(row, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
row = makeRow();
@ -123,14 +123,14 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, "2");
addButton(row, 0, "3");
addOperationButton(row, R.id.cpp_kb_button_plus, "+");
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_white_24dp);
addImageButton(row, R.id.cpp_kb_button_space, R.drawable.ic_space_bar_grey300_24dp);
row = makeRow();
addButton(row, R.id.cpp_kb_button_brackets, "( )").setText("(", up).setText(")", down);
addButton(row, 0, "0").setText("00", up).setText("000", down);
addButton(row, 0, ".").setText(",", up);
addOperationButton(row, R.id.cpp_kb_button_minus, "");
addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
addImageButton(row, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp);
row = makeRow();
final int parametersCount = parameterNames.size();
@ -138,7 +138,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
addButton(row, 0, parametersCount > 1 ? parameterNames.get(1) : "y");
addButton(row, R.id.cpp_kb_button_functions, "f");
addButton(row, R.id.cpp_kb_button_constants, "π");
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
addImageButton(row, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp);
}
public int getRowsCount(boolean landscape) {

View File

@ -10,10 +10,12 @@ import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.HapticFeedbackConstants;
import android.view.View;
import android.widget.ImageView;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.SimpleDragListener;
@ -28,6 +30,9 @@ import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobi
public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, SimpleDragListener.DragProcessor, View.OnClickListener {
protected static final float TEXT_SCALE = 0.6f;
protected static final float IMAGE_SCALE = 0.6f;
@NonNull
protected final SimpleDragListener listener;
@Inject
@ -59,6 +64,18 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
textSize = layout.optimized ? 0 : calculateTextSize();
}
protected final void prepareButton(@Nullable ImageView button) {
prepareButton(button, IMAGE_SCALE);
}
protected final void prepareButton(@Nullable ImageView button, float scale) {
if (button == null) {
return;
}
prepareButton((View) button);
Adjuster.adjustImage(button, scale);
}
protected final void prepareButton(@Nullable View button) {
if (button == null) {
return;
@ -76,6 +93,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
if (textSize > 0) {
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
Adjuster.adjustText(button, TEXT_SCALE);
}
protected final void hideText(@Nullable DirectionDragButton button, @Nonnull DragDirection... directions) {

View File

@ -16,6 +16,7 @@ import android.widget.ImageButton;
import butterknife.Bind;
import butterknife.ButterKnife;
import jscl.NumeralBase;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.EditorLongClickEraser;
@ -62,8 +63,10 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
prepareButton(leftButton);
prepareButton(equalsButton);
prepareButton(clearButton);
prepareButton(eraseButton);
if (eraseButton != null) {
Check.isTrue(IMAGE_SCALE == 0.6f);
// backspace button is too big, scale it more
prepareButton(eraseButton, 0.5f);
EditorLongClickEraser.attachTo(eraseButton);
}
if (isSimpleLayout()) {

View File

@ -56,17 +56,17 @@ public class GreekFloatingKeyboard extends BaseFloatingKeyboard implements View.
private void makeLastColumnLand(@NonNull LinearLayout rowView, int row) {
switch (row) {
case 0:
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
break;
case 1:
addButton(rowView, R.id.cpp_kb_button_change_case, "");
break;
case 2:
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp);
break;
case 3:
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp);
break;
default:
addButton(rowView, View.NO_ID, "");
@ -80,17 +80,17 @@ public class GreekFloatingKeyboard extends BaseFloatingKeyboard implements View.
addButton(rowView, R.id.cpp_kb_button_clear, "C");
break;
case 1:
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_white_24dp);
final View backspace = addImageButton(rowView, R.id.cpp_kb_button_backspace, R.drawable.ic_backspace_grey300_24dp);
EditTextLongClickEraser.attachTo(backspace, user.getEditor());
break;
case 2:
addButton(rowView, R.id.cpp_kb_button_change_case, "");
break;
case 3:
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_white_24dp);
addImageButton(rowView, R.id.cpp_kb_button_keyboard, R.drawable.ic_keyboard_grey300_24dp);
break;
case 4:
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_white_24dp);
addImageButton(rowView, R.id.cpp_kb_button_close, R.drawable.ic_done_grey300_24dp);
break;
default:
addButton(rowView, View.NO_ID, "");

View File

@ -0,0 +1,109 @@
package org.solovyev.android.views;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;
import static android.graphics.Matrix.MSCALE_Y;
public class Adjuster {
private static final float[] MATRIX = new float[9];
public static void adjustText(@NonNull final TextView view, final float percentage) {
ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver == null) {
return;
}
treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage));
}
@Nullable
private static ViewTreeObserver getTreeObserver(@NonNull View view) {
final ViewTreeObserver treeObserver = view.getViewTreeObserver();
if (treeObserver == null) {
return null;
}
if (!treeObserver.isAlive()) {
return null;
}
return treeObserver;
}
public static void adjustImage(@NonNull final ImageView view, final float percentage) {
ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver == null) {
return;
}
treeObserver.addOnPreDrawListener(new ImageViewAdjuster(view, percentage));
}
private static class TextViewAdjuster implements ViewTreeObserver.OnPreDrawListener {
@NonNull
private final TextView view;
private final float percentage;
public TextViewAdjuster(@NonNull TextView view, float percentage) {
this.view = view;
this.percentage = percentage;
}
@Override
public boolean onPreDraw() {
// assume that the view properties are constant
final ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver != null) {
treeObserver.removeOnPreDrawListener(this);
}
final int height = view.getHeight();
final float oldTextSize = Math.round(view.getTextSize());
final float newTextSize = Math.round(height * percentage);
if (oldTextSize == newTextSize) {
return true;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize);
return false;
}
}
private static class ImageViewAdjuster implements ViewTreeObserver.OnPreDrawListener {
@NonNull
private final ImageView view;
private final float percentage;
public ImageViewAdjuster(@NonNull ImageView view, float percentage) {
this.view = view;
this.percentage = percentage;
}
@Override
public boolean onPreDraw() {
// assume that the view properties are constant
final ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver != null) {
treeObserver.removeOnPreDrawListener(this);
}
final Drawable d = view.getDrawable();
if (d == null) {
return true;
}
final int height = view.getHeight();
view.getImageMatrix().getValues(MATRIX);
final int oldImageHeight = Math.round(d.getIntrinsicHeight() * MATRIX[MSCALE_Y]);
final int newImageHeight = Math.round(height * percentage);
if (oldImageHeight == newImageHeight) {
return true;
}
final int newPaddings = Math.max(0, height - newImageHeight) / 2;
view.setPadding(0, newPaddings, 0, newPaddings);
return false;
}
}
}

View File

Before

Width:  |  Height:  |  Size: 525 B

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

View File

Before

Width:  |  Height:  |  Size: 264 B

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

View File

Before

Width:  |  Height:  |  Size: 343 B

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

View File

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

View File

Before

Width:  |  Height:  |  Size: 207 B

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

View File

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 B

View File

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

View File

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

View File

Before

Width:  |  Height:  |  Size: 316 B

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 838 B

After

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

View File

Before

Width:  |  Height:  |  Size: 455 B

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

View File

Before

Width:  |  Height:  |  Size: 389 B

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

After

Width:  |  Height:  |  Size: 99 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 994 B

View File

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 471 B

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 96 B

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_0"
style="?attr/cpp_button_style_digit"
a:text="0"
c:directionTextScale="0.5"
c:textDown="000"
c:textUp="00"
tools:ignore="HardcodedText" />

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_6"
style="?attr/cpp_button_style_digit"
a:text="6"
c:directionTextScale="0.33;0.30;0.33;0.33"
c:textDown="rad"
c:textLeft="F"
c:textUp="deg"

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_7"
style="?attr/cpp_button_style_digit"
a:text="7"
c:directionTextScale="0.5;0.5;0.5;0.33"
c:textDown="!"
c:textLeft="0b:"
c:textUp="i"

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_8"
style="?attr/cpp_button_style_digit"
a:text="8"
c:directionTextScale="0.5;0.5;0.5;0.33"
c:textDown="lg"
c:textLeft="0d:"
c:textUp="ln"

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_9"
style="?attr/cpp_button_style_digit"
a:text="9"
c:directionTextScale="0.5;0.5;0.5;0.33"
c:textDown="e"
c:textLeft="0x:"
c:textUp="π"

View File

@ -26,4 +26,4 @@
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_copy"
style="?attr/cpp_button_style_control_image"
a:src="@drawable/kb_copy" />
a:src="@drawable/ic_content_copy_white_48dp" />

View File

@ -29,7 +29,6 @@
a:id="@id/cpp_button_division"
style="?attr/cpp_button_style_operation"
a:text="/"
c:directionTextScale="0.5"
c:textDown="√"
c:textUp="%"
tools:ignore="HardcodedText" />

Some files were not shown because too many files have changed in this diff Show More