Scale buttons in a floating window
This commit is contained in:
parent
14f76fb47b
commit
0a121a9685
@ -36,6 +36,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@ -47,8 +48,10 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.AppModule;
|
import org.solovyev.android.calculator.AppModule;
|
||||||
|
import org.solovyev.android.calculator.BaseUi;
|
||||||
import org.solovyev.android.calculator.DisplayState;
|
import org.solovyev.android.calculator.DisplayState;
|
||||||
import org.solovyev.android.calculator.DisplayView;
|
import org.solovyev.android.calculator.DisplayView;
|
||||||
import org.solovyev.android.calculator.Editor;
|
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.Preferences;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.buttons.CppButton;
|
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.annotation.Nonnull;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -248,6 +253,8 @@ public class FloatingCalculatorView {
|
|||||||
Editor editor;
|
Editor editor;
|
||||||
@Inject
|
@Inject
|
||||||
SharedPreferences preferences;
|
SharedPreferences preferences;
|
||||||
|
@Inject
|
||||||
|
Typeface typeface;
|
||||||
@Named(AppModule.PREFS_FLOATING)
|
@Named(AppModule.PREFS_FLOATING)
|
||||||
@Inject
|
@Inject
|
||||||
SharedPreferences myPreferences;
|
SharedPreferences myPreferences;
|
||||||
@ -363,6 +370,14 @@ public class FloatingCalculatorView {
|
|||||||
return true;
|
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);
|
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
@ -18,6 +18,7 @@ import android.support.annotation.Nullable;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.solovyev.android.Views;
|
import org.solovyev.android.Views;
|
||||||
import org.solovyev.android.calculator.BaseUi;
|
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 TEXT_SCALE = 0.6f;
|
||||||
public static final float IMAGE_SCALE = 0.6f;
|
public static final float IMAGE_SCALE = 0.6f;
|
||||||
|
public static final float IMAGE_SCALE_ERASE = 0.5f;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<DragButton> dragButtons = new ArrayList<>();
|
private final List<DragButton> dragButtons = new ArrayList<>();
|
||||||
@ -69,6 +71,14 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
|
|||||||
listener = new SimpleDragListener(this, application);
|
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) {
|
public void onCreateView(@Nonnull Activity activity, @Nonnull View view) {
|
||||||
cast(activity.getApplication()).getComponent().inject(this);
|
cast(activity.getApplication()).getComponent().inject(this);
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package org.solovyev.android.calculator.keyboard;
|
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.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@ -13,11 +20,13 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import butterknife.Bind;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import jscl.NumeralBase;
|
|
||||||
import org.solovyev.android.Check;
|
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.buttons.CppSpecialButton;
|
||||||
import org.solovyev.android.calculator.view.EditorLongClickEraser;
|
import org.solovyev.android.calculator.view.EditorLongClickEraser;
|
||||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
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.DragButton;
|
||||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import jscl.NumeralBase;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.inject.Inject;
|
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 {
|
public class PartialKeyboardUi extends BaseKeyboardUi {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -69,7 +77,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
|
|||||||
if (eraseButton != null) {
|
if (eraseButton != null) {
|
||||||
Check.isTrue(IMAGE_SCALE == 0.6f);
|
Check.isTrue(IMAGE_SCALE == 0.6f);
|
||||||
// backspace button is too big, scale it more
|
// backspace button is too big, scale it more
|
||||||
prepareButton(eraseButton, 0.5f);
|
prepareButton(eraseButton, IMAGE_SCALE_ERASE);
|
||||||
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress());
|
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress());
|
||||||
}
|
}
|
||||||
if (isSimpleLayout()) {
|
if (isSimpleLayout()) {
|
||||||
|
@ -28,9 +28,7 @@ import android.view.ContextThemeWrapper;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import org.solovyev.android.Views;
|
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.Preferences;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
|
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
|
||||||
import org.solovyev.android.views.Adjuster;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -95,11 +92,7 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
|
|||||||
Views.processViews(preview, new Views.ViewProcessor<View>() {
|
Views.processViews(preview, new Views.ViewProcessor<View>() {
|
||||||
@Override
|
@Override
|
||||||
public void process(@Nonnull View view) {
|
public void process(@Nonnull View view) {
|
||||||
if (view instanceof Button) {
|
BaseKeyboardUi.adjustButton(view);
|
||||||
Adjuster.adjustText((Button) view, BaseKeyboardUi.TEXT_SCALE);
|
|
||||||
} else if (view instanceof ImageView) {
|
|
||||||
Adjuster.adjustImage((ImageView) view, BaseKeyboardUi.IMAGE_SCALE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user