Scale buttons in a floating window

This commit is contained in:
serso 2016-02-17 13:58:40 +01:00
parent 14f76fb47b
commit 0a121a9685
4 changed files with 44 additions and 18 deletions

View File

@ -36,6 +36,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
@ -47,8 +48,10 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import org.solovyev.android.calculator.AppModule;
import org.solovyev.android.calculator.BaseUi;
import org.solovyev.android.calculator.DisplayState;
import org.solovyev.android.calculator.DisplayView;
import org.solovyev.android.calculator.Editor;
@ -58,6 +61,8 @@ import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.buttons.CppButton;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
import javax.annotation.Nonnull;
import javax.inject.Inject;
@ -248,6 +253,8 @@ public class FloatingCalculatorView {
Editor editor;
@Inject
SharedPreferences preferences;
@Inject
Typeface typeface;
@Named(AppModule.PREFS_FLOATING)
@Inject
SharedPreferences myPreferences;
@ -363,6 +370,14 @@ public class FloatingCalculatorView {
return true;
}
});
if (widgetButton == CppButton.erase && button instanceof ImageView) {
Adjuster.adjustImage((ImageView) button, BaseKeyboardUi.IMAGE_SCALE_ERASE);
} else {
BaseKeyboardUi.adjustButton(button);
}
if (button instanceof TextView) {
BaseUi.setFont((TextView) button, typeface);
}
}
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

View File

@ -18,6 +18,7 @@ import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.BaseUi;
@ -44,6 +45,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
public static final float TEXT_SCALE = 0.6f;
public static final float IMAGE_SCALE = 0.6f;
public static final float IMAGE_SCALE_ERASE = 0.5f;
@NonNull
private final List<DragButton> dragButtons = new ArrayList<>();
@ -69,6 +71,14 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
listener = new SimpleDragListener(this, application);
}
public static void adjustButton(@NonNull View button) {
if (button instanceof TextView) {
Adjuster.adjustText((TextView) button, TEXT_SCALE);
} else if (button instanceof ImageView) {
Adjuster.adjustImage((ImageView) button, IMAGE_SCALE);
}
}
public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
cast(activity.getApplication()).getComponent().inject(this);
preferences.registerOnSharedPreferenceChangeListener(this);

View File

@ -1,5 +1,12 @@
package org.solovyev.android.calculator.keyboard;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton;
import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress;
import static org.solovyev.android.views.dragbutton.DragDirection.down;
import static org.solovyev.android.views.dragbutton.DragDirection.left;
import static org.solovyev.android.views.dragbutton.DragDirection.up;
import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;
@ -13,11 +20,13 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
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.ActivityLauncher;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.EditorLongClickEraser;
import org.solovyev.android.calculator.view.NumeralBasesButton;
@ -25,14 +34,13 @@ import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
import butterknife.Bind;
import butterknife.ButterKnife;
import jscl.NumeralBase;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton;
import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress;
import static org.solovyev.android.views.dragbutton.DragDirection.*;
public class PartialKeyboardUi extends BaseKeyboardUi {
@Nullable
@ -69,7 +77,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
if (eraseButton != null) {
Check.isTrue(IMAGE_SCALE == 0.6f);
// backspace button is too big, scale it more
prepareButton(eraseButton, 0.5f);
prepareButton(eraseButton, IMAGE_SCALE_ERASE);
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress());
}
if (isSimpleLayout()) {

View File

@ -28,9 +28,7 @@ import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Spinner;
import org.solovyev.android.Views;
@ -38,7 +36,6 @@ import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
import java.util.ArrayList;
import java.util.List;
@ -95,11 +92,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
Views.processViews(preview, new Views.ViewProcessor<View>() {
@Override
public void process(@Nonnull View view) {
if (view instanceof Button) {
Adjuster.adjustText((Button) view, BaseKeyboardUi.TEXT_SCALE);
} else if (view instanceof ImageView) {
Adjuster.adjustImage((ImageView) view, BaseKeyboardUi.IMAGE_SCALE);
}
BaseKeyboardUi.adjustButton(view);
}
});
}