Fix fonts in floating keyboards

This commit is contained in:
serso 2016-03-15 22:43:27 +01:00
parent ddb7d1b94c
commit b9432db42a
7 changed files with 38 additions and 31 deletions

View File

@ -24,6 +24,7 @@ import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language;
import org.solovyev.android.calculator.language.Languages;
import org.solovyev.android.calculator.view.Tabs;
import org.solovyev.android.views.dragbutton.DirectionDragImageButton;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -86,6 +87,14 @@ public class BaseActivity extends AppCompatActivity {
ga.getAnalytics().reportActivityStart(activity);
}
public static void setFont(@Nonnull View view, @Nonnull Typeface newTypeface) {
if (view instanceof TextView) {
setFont((TextView) view, newTypeface);
} else if (view instanceof DirectionDragImageButton) {
((DirectionDragImageButton) view).setTypeface(newTypeface);
}
}
public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) {
final Typeface oldTypeface = view.getTypeface();
if (oldTypeface == newTypeface) {
@ -248,6 +257,4 @@ public class BaseActivity extends AppCompatActivity {
}
});
}
}

View File

@ -34,23 +34,9 @@ import android.support.annotation.NonNull;
import android.support.v7.view.ContextThemeWrapper;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.*;
import android.widget.ImageView;
import android.widget.TextView;
import org.solovyev.android.calculator.AppModule;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.DisplayState;
import org.solovyev.android.calculator.DisplayView;
import org.solovyev.android.calculator.Editor;
import org.solovyev.android.calculator.EditorState;
import org.solovyev.android.calculator.EditorView;
import org.solovyev.android.calculator.Keyboard;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppButton;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.views.Adjuster;
@ -59,14 +45,8 @@ import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
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 android.view.HapticFeedbackConstants.LONG_PRESS;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
import static android.view.HapticFeedbackConstants.*;
import static android.view.WindowManager.LayoutParams.*;
import static org.solovyev.android.calculator.App.cast;
public class FloatingCalculatorView {
@ -377,9 +357,7 @@ public class FloatingCalculatorView {
} else {
BaseKeyboardUi.adjustButton(button);
}
if (button instanceof TextView) {
BaseActivity.setFont((TextView) button, typeface);
}
BaseActivity.setFont(button, typeface);
}
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

View File

@ -26,6 +26,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
@ -83,6 +84,8 @@ public abstract class BaseFunctionFragment extends BaseDialogFragment implements
@Inject
Keyboard keyboard;
@Inject
Typeface typeface;
@Inject
FunctionsRegistry functionsRegistry;
@Inject
VariablesRegistry variablesRegistry;
@ -497,6 +500,12 @@ public abstract class BaseFunctionFragment extends BaseDialogFragment implements
return keyboard.isVibrateOnKeypress();
}
@NonNull
@Override
public Typeface getTypeface() {
return typeface;
}
@Override
public void done() {
keyboardWindow.hide();

View File

@ -15,6 +15,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
@ -75,6 +76,7 @@ public abstract class BaseFloatingKeyboard implements FloatingKeyboard {
}
protected void fillButton(@NonNull View button, @IdRes int id) {
BaseActivity.setFont(button, user.getTypeface());
button.setId(id);
button.setBackgroundResource(buttonBackground);
button.setPadding(sidePadding, 1, sidePadding, 1);

View File

@ -115,6 +115,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
// we call android.view.View.performHapticFeedback(int, int) from #onClick
button.setHapticFeedbackEnabled(false);
button.setOnClickListener(this);
BaseActivity.setFont(button, typeface);
}
protected final void prepareButton(@Nullable DirectionDragImageButton button) {
@ -125,7 +126,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
button.setVibrateOnDrag(keyboard.isVibrateOnKeypress());
prepareButton((ImageView) button);
button.setOnDragListener(listener);
button.setTypeface(typeface);
button.setTextSize(textSize);
Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0);
}
@ -138,7 +138,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
button.setVibrateOnDrag(keyboard.isVibrateOnKeypress());
prepareButton((View) button);
button.setOnDragListener(listener);
BaseActivity.setFont(button, typeface);
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
Adjuster.adjustText(button, textScale);
}

View File

@ -2,6 +2,7 @@ package org.solovyev.android.calculator.keyboard;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.view.ViewGroup;
import android.widget.EditText;
@ -35,5 +36,7 @@ public interface FloatingKeyboard {
boolean isVibrateOnKeypress();
@NonNull
Typeface getTypeface();
}
}

View File

@ -27,6 +27,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
@ -93,6 +94,8 @@ public class EditVariableFragment extends BaseDialogFragment implements View.OnF
@Inject
Keyboard keyboard;
@Inject
Typeface typeface;
@Inject
FunctionsRegistry functionsRegistry;
@Inject
VariablesRegistry variablesRegistry;
@ -421,5 +424,11 @@ public class EditVariableFragment extends BaseDialogFragment implements View.OnF
public boolean isVibrateOnKeypress() {
return keyboard.isVibrateOnKeypress();
}
@NonNull
@Override
public Typeface getTypeface() {
return typeface;
}
}
}