diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index b7a16ca4..a1af5ae6 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -41,9 +41,12 @@ import android.support.v7.view.ContextThemeWrapper; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; +import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; +import android.util.TypedValue; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import com.squareup.otto.Bus; @@ -397,7 +400,14 @@ public final class App { } public static int toPixels(@Nonnull DisplayMetrics dm, float dps) { - final float scale = dm.density; - return (int) (dps * scale + 0.5f); + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, dm); + } + + public static int toPixels(@Nonnull Context context, float dps) { + return toPixels(context.getResources().getDisplayMetrics(), dps); + } + + public static int toPixels(@Nonnull View view, float dps) { + return toPixels(view.getContext(), dps); } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java b/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java index deaf7eff..aab6a20c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java +++ b/app/src/main/java/org/solovyev/android/calculator/widget/CalculatorWidget.java @@ -50,7 +50,6 @@ import javax.annotation.Nullable; import javax.inject.Inject; import java.util.EnumMap; -import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT; import static android.content.Intent.ACTION_CONFIGURATION_CHANGED; import static android.os.Build.VERSION_CODES.JELLY_BEAN; import static org.solovyev.android.calculator.App.cast; @@ -181,7 +180,7 @@ public class CalculatorWidget extends AppWidgetProvider { return getDefaultLayout(theme); } - final int widgetMinHeight = App.toPixels(resources.getDisplayMetrics(), options.getInt(OPTION_APPWIDGET_MIN_HEIGHT, 0)); + final int widgetMinHeight = App.toPixels(resources.getDisplayMetrics(), options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0)); final int lockScreenMinHeight = resources.getDimensionPixelSize(R.dimen.min_expanded_height_lock_screen); final boolean expanded = widgetMinHeight >= lockScreenMinHeight; if (expanded) { diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/WizardFragment.java b/app/src/main/java/org/solovyev/android/calculator/wizard/WizardFragment.java index 611921af..278b566b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/WizardFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/WizardFragment.java @@ -8,12 +8,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteFragment; import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteStep; import org.solovyev.android.calculator.release.ReleaseNoteFragment; import org.solovyev.android.calculator.release.ReleaseNoteStep; +import org.solovyev.android.views.Adjuster; import org.solovyev.android.wizard.Wizard; import org.solovyev.android.wizard.WizardFlow; import org.solovyev.android.wizard.WizardStep; @@ -21,6 +21,8 @@ import org.solovyev.android.wizard.WizardStep; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static org.solovyev.android.calculator.App.toPixels; + public abstract class WizardFragment extends Fragment implements View.OnClickListener { @Nullable @@ -63,6 +65,7 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis final ViewGroup content = (ViewGroup) view.findViewById(R.id.wizard_content); inflater.inflate(getViewResId(), content, true); + Adjuster.maxWidth(content, toPixels(view, 300)); nextButton = (TextView) view.findViewById(R.id.wizard_next); if (nextButton != null) { @@ -118,18 +121,21 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis public void onClick(View v) { final int id = v.getId(); final WizardActivity activity = getWizardActivity(); - if (id == R.id.wizard_next) { - if (activity.canGoNext()) { - activity.goNext(); - } else { - activity.finishWizard(); - } - } else if (id == R.id.wizard_prev) { - if (activity.canGoPrev()) { - activity.goPrev(); - } else { - activity.finishWizardAbruptly(); - } + switch (id) { + case R.id.wizard_next: + if (activity.canGoNext()) { + activity.goNext(); + } else { + activity.finishWizard(); + } + break; + case R.id.wizard_prev: + if (activity.canGoPrev()) { + activity.goPrev(); + } else { + activity.finishWizardAbruptly(); + } + break; } } diff --git a/app/src/main/java/org/solovyev/android/views/Adjuster.java b/app/src/main/java/org/solovyev/android/views/Adjuster.java index 63097ca4..e6fd0292 100644 --- a/app/src/main/java/org/solovyev/android/views/Adjuster.java +++ b/app/src/main/java/org/solovyev/android/views/Adjuster.java @@ -1,17 +1,18 @@ package org.solovyev.android.views; -import static android.graphics.Matrix.MSCALE_Y; - import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.ViewCompat; import android.util.TypedValue; import android.view.View; +import android.view.ViewGroup; 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]; @@ -41,35 +42,58 @@ public class Adjuster { } public static void adjustImage(@NonNull final ImageView view, final float percentage) { - ViewTreeObserver treeObserver = getTreeObserver(view); + final 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; - private final float minTextSizePxs; + public static void maxWidth(@NonNull View view, int maxWidth) { + final ViewTreeObserver treeObserver = getTreeObserver(view); + if (treeObserver == null) { + return; + } + treeObserver.addOnPreDrawListener(new MaxWidthAdjuster(view, maxWidth)); + } - public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) { + private static abstract class BaseViewAdjuster implements ViewTreeObserver.OnPreDrawListener { + @NonNull + protected final V view; + + protected BaseViewAdjuster(@NonNull V view) { this.view = view; - this.percentage = percentage; - this.minTextSizePxs = minTextSizePxs; } @Override - public boolean onPreDraw() { + public final boolean onPreDraw() { + final int width = view.getWidth(); final int height = view.getHeight(); - if (!ViewCompat.isLaidOut(view) || height <= 0) { + if (!ViewCompat.isLaidOut(view) || height <= 0 || width <= 0) { return true; } final ViewTreeObserver treeObserver = getTreeObserver(view); if (treeObserver != null) { treeObserver.removeOnPreDrawListener(this); } + return adjust(width, height); + } + + protected abstract boolean adjust(int width, int height); + } + + private static class TextViewAdjuster extends BaseViewAdjuster { + private final float percentage; + private final float minTextSizePxs; + + public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) { + super(view); + this.percentage = percentage; + this.minTextSizePxs = minTextSizePxs; + } + + @Override + protected boolean adjust(int width, int height) { final float oldTextSize = Math.round(view.getTextSize()); final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage)); if (oldTextSize == newTextSize) { @@ -80,26 +104,37 @@ public class Adjuster { } } - private static class ImageViewAdjuster implements ViewTreeObserver.OnPreDrawListener { - @NonNull - private final ImageView view; + private static class MaxWidthAdjuster extends BaseViewAdjuster { + + private final int maxWidth; + + public MaxWidthAdjuster(@NonNull View view, int maxWidth) { + super(view); + this.maxWidth = maxWidth; + } + + @Override + protected boolean adjust(int width, int height) { + if (width <= maxWidth) { + return true; + } + final ViewGroup.LayoutParams lp = view.getLayoutParams(); + lp.width = maxWidth; + view.setLayoutParams(lp); + return false; + } + } + + private static class ImageViewAdjuster extends BaseViewAdjuster { private final float percentage; public ImageViewAdjuster(@NonNull ImageView view, float percentage) { - this.view = view; + super(view); this.percentage = percentage; } @Override - public boolean onPreDraw() { - final int height = view.getHeight(); - if (!ViewCompat.isLaidOut(view) || height <= 0) { - return true; - } - final ViewTreeObserver treeObserver = getTreeObserver(view); - if (treeObserver != null) { - treeObserver.removeOnPreDrawListener(this); - } + protected boolean adjust(int width, int height) { final Drawable d = view.getDrawable(); if (d == null) { return true; diff --git a/app/src/main/res/drawable-hdpi/ic_file_upload_white_24dp.png b/app/src/main/res/drawable-hdpi/ic_file_upload_white_24dp.png deleted file mode 100644 index 4203a957..00000000 Binary files a/app/src/main/res/drawable-hdpi/ic_file_upload_white_24dp.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_file_upload_white_24dp.png b/app/src/main/res/drawable-mdpi/ic_file_upload_white_24dp.png deleted file mode 100644 index 8ad2957a..00000000 Binary files a/app/src/main/res/drawable-mdpi/ic_file_upload_white_24dp.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_file_upload_white_24dp.png b/app/src/main/res/drawable-xhdpi/ic_file_upload_white_24dp.png deleted file mode 100644 index 939a5b70..00000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_file_upload_white_24dp.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_file_upload_white_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_file_upload_white_24dp.png deleted file mode 100644 index 172c3ff3..00000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_file_upload_white_24dp.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_file_upload_white_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_file_upload_white_24dp.png deleted file mode 100644 index 17652e41..00000000 Binary files a/app/src/main/res/drawable-xxxhdpi/ic_file_upload_white_24dp.png and /dev/null differ diff --git a/app/src/main/res/layout/fragment_wizard.xml b/app/src/main/res/layout/fragment_wizard.xml index 6a97ab36..22e7017b 100644 --- a/app/src/main/res/layout/fragment_wizard.xml +++ b/app/src/main/res/layout/fragment_wizard.xml @@ -1,9 +1,12 @@ - + - + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_wizard_buttons.xml b/app/src/main/res/layout/fragment_wizard_buttons.xml deleted file mode 100644 index fb028386..00000000 --- a/app/src/main/res/layout/fragment_wizard_buttons.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9f567618..82d91191 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -161,15 +161,6 @@ @android:style/TextAppearance.Medium - - - -