Fix text scales in keyboard buttons

This commit is contained in:
serso 2016-02-16 16:00:22 +01:00
parent 7e41f30e06
commit 8a5d163b06
5 changed files with 66 additions and 61 deletions

View File

@ -1,6 +1,5 @@
package org.solovyev.android.calculator;
import dagger.Component;
import org.solovyev.android.calculator.converter.ConverterFragment;
import org.solovyev.android.calculator.errors.FixableErrorFragment;
import org.solovyev.android.calculator.errors.FixableErrorsActivity;
@ -16,6 +15,9 @@ import org.solovyev.android.calculator.preferences.PreferencesActivity;
import org.solovyev.android.calculator.preferences.PurchaseDialogActivity;
import org.solovyev.android.calculator.variables.EditVariableFragment;
import org.solovyev.android.calculator.variables.VariablesFragment;
import org.solovyev.android.calculator.wizard.DragButtonWizardStep;
import dagger.Component;
import javax.inject.Singleton;
@ -46,4 +48,5 @@ public interface AppComponent {
void inject(PreferencesActivity activity);
void inject(BaseKeyboardUi ui);
void inject(CalculatorOnscreenView view);
void inject(DragButtonWizardStep fragment);
}

View File

@ -1,5 +1,13 @@
package org.solovyev.android.calculator.keyboard;
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING;
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING;
import static android.view.HapticFeedbackConstants.KEYBOARD_TAP;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.App.getScreenMetrics;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;
@ -10,8 +18,14 @@ import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.BaseUi;
import org.solovyev.android.calculator.Calculator;
import org.solovyev.android.calculator.Editor;
import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.PreferredPreferences;
import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.ScreenMetrics;
import org.solovyev.android.views.Adjuster;
@ -20,21 +34,16 @@ import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.SimpleDragListener;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import static android.view.HapticFeedbackConstants.*;
import static org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.App.getScreenMetrics;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
import javax.annotation.Nonnull;
import javax.inject.Inject;
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;
public static final float TEXT_SCALE = 0.6f;
public static final float IMAGE_SCALE = 0.6f;
@NonNull
private final List<DragButton> dragButtons = new ArrayList<>();

View File

@ -28,16 +28,23 @@ 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;
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 javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
public class ChooseThemeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener {
@Nonnull
@ -85,6 +92,16 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView
preview.removeAllViews();
final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.theme);
LayoutInflater.from(context).inflate(R.layout.cpp_wizard_step_choose_theme_preview, preview);
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);
}
}
});
}
@Override

View File

@ -22,13 +22,19 @@
package org.solovyev.android.calculator.wizard;
import static org.solovyev.android.calculator.App.cast;
import android.graphics.PointF;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import org.solovyev.android.calculator.BaseUi;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DragButton;
import org.solovyev.android.views.dragbutton.DragDirection;
@ -38,41 +44,24 @@ import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
public class DragButtonWizardStep extends WizardFragment {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
private static final String ACTION = "action";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private DirectionDragButton dragButton;
@Nullable
private TextView actionTextView;
@Nonnull
private TextView descriptionTextView;
private DragButtonAction action = DragButtonAction.center;
@Inject
Typeface typeface;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cast(this).getComponent().inject(this);
}
@Override
@ -84,12 +73,13 @@ public class DragButtonWizardStep extends WizardFragment {
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
dragButton = (DirectionDragButton) root.findViewById(R.id.wizard_dragbutton);
dragButton.setOnClickListener(new DragButtonOnClickListener());
dragButton.setOnDragListener(new SimpleDragListener(new DragButtonProcessor(), getActivity()));
final DirectionDragButton dragButton =(DirectionDragButton) root.findViewById(R.id.wizard_dragbutton);
dragButton.setOnClickListener(this);
dragButton.setOnDragListener(
new SimpleDragListener(new DragButtonProcessor(), getActivity()));
BaseUi.setFont(dragButton, typeface);
Adjuster.adjustText(dragButton, BaseKeyboardUi.TEXT_SCALE);
actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview);
descriptionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_description_textview);
if (savedInstanceState != null) {
setAction((DragButtonAction) savedInstanceState.getSerializable(ACTION));
}
@ -102,14 +92,6 @@ public class DragButtonWizardStep extends WizardFragment {
outState.putSerializable(ACTION, action);
}
/*
**********************************************************************
*
* STATIC/INNER
*
**********************************************************************
*/
private void setNextAction() {
setAction(action.getNextAction());
}
@ -120,14 +102,6 @@ public class DragButtonWizardStep extends WizardFragment {
if (actionTextView != null) {
actionTextView.setText(this.action.actionTextResId);
}
boolean firstChange = false;
if (action != DragButtonAction.center) {
firstChange = true;
}
if (firstChange) {
//descriptionTextView.setVisibility(GONE);
}
}
}
@ -159,13 +133,15 @@ public class DragButtonWizardStep extends WizardFragment {
}
}
private class DragButtonOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
@Override
public void onClick(View v) {
if(v.getId() == R.id.wizard_dragbutton) {
if (action == DragButtonAction.center || action == DragButtonAction.end) {
setNextAction();
}
return;
}
super.onClick(v);
}
private class DragButtonProcessor implements SimpleDragListener.DragProcessor {

View File

@ -34,7 +34,7 @@
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:layout_height="60dp"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_equals_no_bg" />
@ -51,7 +51,7 @@
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:layout_height="60dp"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_0" />
@ -64,7 +64,7 @@
<LinearLayout
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:layout_height="60dp"
a:orientation="horizontal">
<include layout="@layout/cpp_app_button_1" />