Lint + max width for wizard
This commit is contained in:
parent
e9343e3b6b
commit
001888973a
@ -41,9 +41,12 @@ import android.support.v7.view.ContextThemeWrapper;
|
|||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
@ -397,7 +400,14 @@ public final class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int toPixels(@Nonnull DisplayMetrics dm, float dps) {
|
public static int toPixels(@Nonnull DisplayMetrics dm, float dps) {
|
||||||
final float scale = dm.density;
|
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dps, dm);
|
||||||
return (int) (dps * scale + 0.5f);
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,7 +50,6 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
|
||||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
|
|
||||||
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
|
import static android.content.Intent.ACTION_CONFIGURATION_CHANGED;
|
||||||
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
|
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
|
||||||
import static org.solovyev.android.calculator.App.cast;
|
import static org.solovyev.android.calculator.App.cast;
|
||||||
@ -181,7 +180,7 @@ public class CalculatorWidget extends AppWidgetProvider {
|
|||||||
return getDefaultLayout(theme);
|
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 int lockScreenMinHeight = resources.getDimensionPixelSize(R.dimen.min_expanded_height_lock_screen);
|
||||||
final boolean expanded = widgetMinHeight >= lockScreenMinHeight;
|
final boolean expanded = widgetMinHeight >= lockScreenMinHeight;
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
|
@ -8,12 +8,12 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteFragment;
|
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteFragment;
|
||||||
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteStep;
|
import org.solovyev.android.calculator.release.ChooseThemeReleaseNoteStep;
|
||||||
import org.solovyev.android.calculator.release.ReleaseNoteFragment;
|
import org.solovyev.android.calculator.release.ReleaseNoteFragment;
|
||||||
import org.solovyev.android.calculator.release.ReleaseNoteStep;
|
import org.solovyev.android.calculator.release.ReleaseNoteStep;
|
||||||
|
import org.solovyev.android.views.Adjuster;
|
||||||
import org.solovyev.android.wizard.Wizard;
|
import org.solovyev.android.wizard.Wizard;
|
||||||
import org.solovyev.android.wizard.WizardFlow;
|
import org.solovyev.android.wizard.WizardFlow;
|
||||||
import org.solovyev.android.wizard.WizardStep;
|
import org.solovyev.android.wizard.WizardStep;
|
||||||
@ -21,6 +21,8 @@ import org.solovyev.android.wizard.WizardStep;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.solovyev.android.calculator.App.toPixels;
|
||||||
|
|
||||||
public abstract class WizardFragment extends Fragment implements View.OnClickListener {
|
public abstract class WizardFragment extends Fragment implements View.OnClickListener {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -63,6 +65,7 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
|
|||||||
|
|
||||||
final ViewGroup content = (ViewGroup) view.findViewById(R.id.wizard_content);
|
final ViewGroup content = (ViewGroup) view.findViewById(R.id.wizard_content);
|
||||||
inflater.inflate(getViewResId(), content, true);
|
inflater.inflate(getViewResId(), content, true);
|
||||||
|
Adjuster.maxWidth(content, toPixels(view, 300));
|
||||||
|
|
||||||
nextButton = (TextView) view.findViewById(R.id.wizard_next);
|
nextButton = (TextView) view.findViewById(R.id.wizard_next);
|
||||||
if (nextButton != null) {
|
if (nextButton != null) {
|
||||||
@ -118,18 +121,21 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final int id = v.getId();
|
final int id = v.getId();
|
||||||
final WizardActivity activity = getWizardActivity();
|
final WizardActivity activity = getWizardActivity();
|
||||||
if (id == R.id.wizard_next) {
|
switch (id) {
|
||||||
|
case R.id.wizard_next:
|
||||||
if (activity.canGoNext()) {
|
if (activity.canGoNext()) {
|
||||||
activity.goNext();
|
activity.goNext();
|
||||||
} else {
|
} else {
|
||||||
activity.finishWizard();
|
activity.finishWizard();
|
||||||
}
|
}
|
||||||
} else if (id == R.id.wizard_prev) {
|
break;
|
||||||
|
case R.id.wizard_prev:
|
||||||
if (activity.canGoPrev()) {
|
if (activity.canGoPrev()) {
|
||||||
activity.goPrev();
|
activity.goPrev();
|
||||||
} else {
|
} else {
|
||||||
activity.finishWizardAbruptly();
|
activity.finishWizardAbruptly();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package org.solovyev.android.views;
|
package org.solovyev.android.views;
|
||||||
|
|
||||||
import static android.graphics.Matrix.MSCALE_Y;
|
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import static android.graphics.Matrix.MSCALE_Y;
|
||||||
|
|
||||||
public class Adjuster {
|
public class Adjuster {
|
||||||
|
|
||||||
private static final float[] MATRIX = new float[9];
|
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) {
|
public static void adjustImage(@NonNull final ImageView view, final float percentage) {
|
||||||
ViewTreeObserver treeObserver = getTreeObserver(view);
|
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
||||||
if (treeObserver == null) {
|
if (treeObserver == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
treeObserver.addOnPreDrawListener(new ImageViewAdjuster(view, percentage));
|
treeObserver.addOnPreDrawListener(new ImageViewAdjuster(view, percentage));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TextViewAdjuster implements ViewTreeObserver.OnPreDrawListener {
|
public static void maxWidth(@NonNull View view, int maxWidth) {
|
||||||
@NonNull
|
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
||||||
private final TextView view;
|
if (treeObserver == null) {
|
||||||
private final float percentage;
|
return;
|
||||||
private final float minTextSizePxs;
|
}
|
||||||
|
treeObserver.addOnPreDrawListener(new MaxWidthAdjuster(view, maxWidth));
|
||||||
|
}
|
||||||
|
|
||||||
public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) {
|
private static abstract class BaseViewAdjuster<V extends View> implements ViewTreeObserver.OnPreDrawListener {
|
||||||
|
@NonNull
|
||||||
|
protected final V view;
|
||||||
|
|
||||||
|
protected BaseViewAdjuster(@NonNull V view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.percentage = percentage;
|
|
||||||
this.minTextSizePxs = minTextSizePxs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreDraw() {
|
public final boolean onPreDraw() {
|
||||||
|
final int width = view.getWidth();
|
||||||
final int height = view.getHeight();
|
final int height = view.getHeight();
|
||||||
if (!ViewCompat.isLaidOut(view) || height <= 0) {
|
if (!ViewCompat.isLaidOut(view) || height <= 0 || width <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
||||||
if (treeObserver != null) {
|
if (treeObserver != null) {
|
||||||
treeObserver.removeOnPreDrawListener(this);
|
treeObserver.removeOnPreDrawListener(this);
|
||||||
}
|
}
|
||||||
|
return adjust(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract boolean adjust(int width, int height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TextViewAdjuster extends BaseViewAdjuster<TextView> {
|
||||||
|
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 oldTextSize = Math.round(view.getTextSize());
|
||||||
final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage));
|
final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage));
|
||||||
if (oldTextSize == newTextSize) {
|
if (oldTextSize == newTextSize) {
|
||||||
@ -80,26 +104,37 @@ public class Adjuster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ImageViewAdjuster implements ViewTreeObserver.OnPreDrawListener {
|
private static class MaxWidthAdjuster extends BaseViewAdjuster<View> {
|
||||||
@NonNull
|
|
||||||
private final ImageView view;
|
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<ImageView> {
|
||||||
private final float percentage;
|
private final float percentage;
|
||||||
|
|
||||||
public ImageViewAdjuster(@NonNull ImageView view, float percentage) {
|
public ImageViewAdjuster(@NonNull ImageView view, float percentage) {
|
||||||
this.view = view;
|
super(view);
|
||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreDraw() {
|
protected boolean adjust(int width, int height) {
|
||||||
final int height = view.getHeight();
|
|
||||||
if (!ViewCompat.isLaidOut(view) || height <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
|
||||||
if (treeObserver != null) {
|
|
||||||
treeObserver.removeOnPreDrawListener(this);
|
|
||||||
}
|
|
||||||
final Drawable d = view.getDrawable();
|
final Drawable d = view.getDrawable();
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
return true;
|
return true;
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 147 B |
Binary file not shown.
Before Width: | Height: | Size: 118 B |
Binary file not shown.
Before Width: | Height: | Size: 156 B |
Binary file not shown.
Before Width: | Height: | Size: 195 B |
Binary file not shown.
Before Width: | Height: | Size: 234 B |
@ -1,9 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
a:layout_width="match_parent"
|
||||||
style="@style/WizardFragment"
|
a:layout_height="match_parent"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical"
|
||||||
|
a:gravity="center"
|
||||||
|
a:paddingLeft="10dp"
|
||||||
|
a:paddingRight="10dp">
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
a:id="@+id/wizard_content"
|
a:id="@+id/wizard_content"
|
||||||
@ -14,6 +17,29 @@
|
|||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:fillViewport="true" />
|
a:fillViewport="true" />
|
||||||
|
|
||||||
<include layout="@layout/fragment_wizard_buttons" />
|
<LinearLayout
|
||||||
|
a:layout_width="wrap_content"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_gravity="center_horizontal|bottom"
|
||||||
|
a:layout_marginTop="@dimen/control_margin"
|
||||||
|
a:orientation="horizontal">
|
||||||
|
|
||||||
|
<org.solovyev.android.material.MaterialButton
|
||||||
|
a:id="@+id/wizard_prev"
|
||||||
|
style="@style/MaterialButton.Wizard"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_weight="1"
|
||||||
|
a:visibility="gone" />
|
||||||
|
|
||||||
|
<org.solovyev.android.material.MaterialButton
|
||||||
|
a:id="@+id/wizard_next"
|
||||||
|
style="@style/MaterialButton.Wizard"
|
||||||
|
a:layout_width="0dp"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_weight="1"
|
||||||
|
a:visibility="gone" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
|
||||||
style="@style/WizardButtons"
|
|
||||||
a:layout_gravity="center_horizontal|bottom"
|
|
||||||
a:gravity="center">
|
|
||||||
|
|
||||||
<org.solovyev.android.material.MaterialButton
|
|
||||||
a:id="@+id/wizard_prev"
|
|
||||||
style="@style/MaterialButton.Wizard"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:visibility="gone" />
|
|
||||||
|
|
||||||
<org.solovyev.android.material.MaterialButton
|
|
||||||
a:id="@+id/wizard_next"
|
|
||||||
style="@style/MaterialButton.Wizard"
|
|
||||||
a:layout_width="0dp"
|
|
||||||
a:layout_height="wrap_content"
|
|
||||||
a:layout_weight="1"
|
|
||||||
a:visibility="gone" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -161,15 +161,6 @@
|
|||||||
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
|
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="BaseWizardButtons">
|
|
||||||
<item name="android:background">@null</item>
|
|
||||||
<item name="android:layout_width">wrap_content</item>
|
|
||||||
<item name="android:layout_height">wrap_content</item>
|
|
||||||
<item name="android:layout_marginTop">@dimen/control_margin</item>
|
|
||||||
<item name="android:layout_gravity">top|center_horizontal</item>
|
|
||||||
<item name="android:orientation">horizontal</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="WizardPrimaryButton" parent="PrimaryButton">
|
<style name="WizardPrimaryButton" parent="PrimaryButton">
|
||||||
<item name="android:singleLine">true</item>
|
<item name="android:singleLine">true</item>
|
||||||
<item name="android:maxLines">1</item>
|
<item name="android:maxLines">1</item>
|
||||||
@ -178,19 +169,8 @@
|
|||||||
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
|
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="WizardButtons" parent="BaseWizardButtons" />
|
|
||||||
|
|
||||||
<style name="PrimaryButton" parent="MaterialButton"/>
|
<style name="PrimaryButton" parent="MaterialButton"/>
|
||||||
|
|
||||||
<style name="WizardFragment">
|
|
||||||
<item name="android:layout_width">match_parent</item>
|
|
||||||
<item name="android:layout_height">match_parent</item>
|
|
||||||
<item name="android:orientation">vertical</item>
|
|
||||||
<item name="android:paddingLeft">10dp</item>
|
|
||||||
<item name="android:paddingRight">10dp</item>
|
|
||||||
<item name="android:gravity">center</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style name="MaterialButton.Wizard" parent="MaterialButton">
|
<style name="MaterialButton.Wizard" parent="MaterialButton">
|
||||||
<item name="android:textColor">@color/cpp_button_text</item>
|
<item name="android:textColor">@color/cpp_button_text</item>
|
||||||
<item name="materialColor">?attr/cpp_wizard_button_bg</item>
|
<item name="materialColor">?attr/cpp_wizard_button_bg</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user