changes
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<TextView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
@@ -8,10 +8,18 @@ import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.plot.GraphLineColor;
|
||||
import org.solovyev.android.prefs.*;
|
||||
import org.solovyev.android.calculator.plot.ParcelablePlotInput;
|
||||
import org.solovyev.android.prefs.BooleanPreference;
|
||||
import org.solovyev.android.prefs.IntegerPreference;
|
||||
import org.solovyev.android.prefs.LongPreference;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.prefs.R;
|
||||
import org.solovyev.android.prefs.StringPreference;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
import org.solovyev.common.ListMapper;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/5/13
|
||||
* Time: 10:45 PM
|
||||
*/
|
||||
public enum FunctionLineColorType {
|
||||
|
||||
color_map,
|
||||
solid;
|
||||
}
|
@@ -0,0 +1,156 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/5/13
|
||||
* Time: 7:41 PM
|
||||
*/
|
||||
public class FunctionLineDef implements Parcelable {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CONSTANTS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private static final Float DEFAULT_LINE_WIDTH = -1f;
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
private static final Creator<FunctionLineDef> CREATOR = new Creator<FunctionLineDef>() {
|
||||
@Override
|
||||
public FunctionLineDef createFromParcel(@NotNull Parcel in) {
|
||||
return fromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionLineDef[] newArray(int size) {
|
||||
return new FunctionLineDef[size];
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private FunctionLineColorType lineColorType = FunctionLineColorType.solid;
|
||||
|
||||
private int lineColor = Color.WHITE;
|
||||
|
||||
@NotNull
|
||||
private FunctionLineStyle lineStyle = FunctionLineStyle.solid;
|
||||
|
||||
private float lineWidth = -DEFAULT_LINE_WIDTH;
|
||||
|
||||
private FunctionLineDef() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FunctionLineDef newInstance(int lineColor, @NotNull FunctionLineStyle lineStyle) {
|
||||
final FunctionLineDef result = new FunctionLineDef();
|
||||
result.lineColor = lineColor;
|
||||
result.lineStyle = lineStyle;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FunctionLineDef newInstance(int lineColor, @NotNull FunctionLineStyle lineStyle, float lineWidth) {
|
||||
final FunctionLineDef result = new FunctionLineDef();
|
||||
result.lineColor = lineColor;
|
||||
result.lineStyle = lineStyle;
|
||||
result.lineWidth = lineWidth;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FunctionLineDef newInstance(int lineColor, @NotNull FunctionLineStyle lineStyle, float lineWidth, @NotNull FunctionLineColorType lineColorType) {
|
||||
final FunctionLineDef result = new FunctionLineDef();
|
||||
result.lineColor = lineColor;
|
||||
result.lineColorType = lineColorType;
|
||||
result.lineStyle = lineStyle;
|
||||
result.lineWidth = lineWidth;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static FunctionLineDef fromParcel(@NotNull Parcel in) {
|
||||
final FunctionLineDef result = new FunctionLineDef();
|
||||
|
||||
result.lineColorType = (FunctionLineColorType) in.readSerializable();
|
||||
result.lineColor = in.readInt();
|
||||
result.lineStyle = (FunctionLineStyle) in.readSerializable();
|
||||
result.lineWidth = in.readFloat();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static FunctionLineDef newDefaultInstance() {
|
||||
return new FunctionLineDef();
|
||||
}
|
||||
|
||||
|
||||
public int getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FunctionLineStyle getLineStyle() {
|
||||
return lineStyle;
|
||||
}
|
||||
|
||||
public float getLineWidth() {
|
||||
return lineWidth;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FunctionLineColorType getLineColorType() {
|
||||
return lineColorType;
|
||||
}
|
||||
|
||||
public void applyToPaint(@NotNull Paint paint) {
|
||||
paint.setColor(lineColor);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
if ( lineWidth == DEFAULT_LINE_WIDTH ) {
|
||||
paint.setStrokeWidth(0);
|
||||
} else {
|
||||
paint.setStrokeWidth(lineWidth);
|
||||
}
|
||||
|
||||
lineStyle.applyToPaint(paint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NotNull Parcel out, int flags) {
|
||||
out.writeSerializable(lineColorType);
|
||||
out.writeInt(lineColor);
|
||||
out.writeSerializable(lineStyle);
|
||||
out.writeFloat(lineWidth);
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.graphics.DashPathEffect;
|
||||
import android.graphics.Paint;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/5/13
|
||||
* Time: 7:37 PM
|
||||
*/
|
||||
public enum FunctionLineStyle {
|
||||
|
||||
solid {
|
||||
@Override
|
||||
public void applyToPaint(@NotNull Paint paint) {
|
||||
paint.setPathEffect(null);
|
||||
}
|
||||
},
|
||||
|
||||
dashed {
|
||||
@Override
|
||||
public void applyToPaint(@NotNull Paint paint) {
|
||||
paint.setPathEffect(new DashPathEffect(new float[] {10, 20}, 0));
|
||||
}
|
||||
},
|
||||
|
||||
dotted {
|
||||
@Override
|
||||
public void applyToPaint(@NotNull Paint paint) {
|
||||
paint.setPathEffect(new DashPathEffect(new float[] {5, 1}, 0));
|
||||
}
|
||||
},
|
||||
|
||||
dash_dotted {
|
||||
@Override
|
||||
public void applyToPaint(@NotNull Paint paint) {
|
||||
paint.setPathEffect(new DashPathEffect(new float[] {10, 20, 5, 1}, 0));
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void applyToPaint(@NotNull Paint paint);
|
||||
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ParcelablePlotInput implements Parcelable {
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* STATIC
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
@NotNull
|
||||
public static Creator<ParcelablePlotInput> CREATOR = new Creator<ParcelablePlotInput>() {
|
||||
@Override
|
||||
public ParcelablePlotInput createFromParcel(@NotNull Parcel in) {
|
||||
return fromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelablePlotInput[] newArray(int size) {
|
||||
return new ParcelablePlotInput[size];
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* FIELDS
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
@NotNull
|
||||
private String expression;
|
||||
|
||||
@Nullable
|
||||
private String xVariableName;
|
||||
|
||||
@Nullable
|
||||
private String yVariableName;
|
||||
|
||||
@Nullable
|
||||
private FunctionLineDef lineDef;
|
||||
|
||||
public ParcelablePlotInput(@NotNull String expression,
|
||||
@Nullable String xVariableName,
|
||||
@Nullable String yVariableName) {
|
||||
this(expression, xVariableName, yVariableName, null);
|
||||
}
|
||||
|
||||
public ParcelablePlotInput(@NotNull String expression,
|
||||
@Nullable String xVariableName,
|
||||
@Nullable String yVariableName,
|
||||
@Nullable FunctionLineDef lineDef) {
|
||||
this.expression = expression;
|
||||
this.xVariableName = xVariableName;
|
||||
this.yVariableName = yVariableName;
|
||||
this.lineDef = lineDef;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ParcelablePlotInput fromParcel(@NotNull Parcel in) {
|
||||
final String expression = in.readString();
|
||||
final String xVariableName = in.readString();
|
||||
final String yVariableName = in.readString();
|
||||
final FunctionLineDef lineDef = in.readParcelable(Thread.currentThread().getContextClassLoader());
|
||||
return new ParcelablePlotInput(expression, xVariableName, yVariableName, lineDef);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getXVariableName() {
|
||||
return xVariableName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getYVariableName() {
|
||||
return yVariableName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FunctionLineDef getLineDef() {
|
||||
return lineDef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NotNull Parcel out, int flags) {
|
||||
out.writeString(expression);
|
||||
out.writeString(xVariableName);
|
||||
out.writeString(yVariableName);
|
||||
out.writeParcelable(lineDef, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ParcelablePlotInput)) return false;
|
||||
|
||||
final ParcelablePlotInput that = (ParcelablePlotInput) o;
|
||||
|
||||
if (!expression.equals(that.expression)) return false;
|
||||
if (xVariableName != null ? !xVariableName.equals(that.xVariableName) : that.xVariableName != null)
|
||||
return false;
|
||||
if (yVariableName != null ? !yVariableName.equals(that.yVariableName) : that.yVariableName != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = expression.hashCode();
|
||||
result = 31 * result + (xVariableName != null ? xVariableName.hashCode() : 0);
|
||||
result = 31 * result + (yVariableName != null ? yVariableName.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.core.R;
|
||||
import org.solovyev.android.list.ListItem;
|
||||
import org.solovyev.android.view.TextViewBuilder;
|
||||
import org.solovyev.android.view.UpdatableViewBuilder;
|
||||
|
||||
public class ParcelablePlotInputListItem implements ListItem {
|
||||
|
||||
@NotNull
|
||||
private ParcelablePlotInput plotInput;
|
||||
|
||||
@NotNull
|
||||
private UpdatableViewBuilder<TextView> viewBuilder;
|
||||
|
||||
public ParcelablePlotInputListItem(@NotNull ParcelablePlotInput plotInput) {
|
||||
this.plotInput = plotInput;
|
||||
// todo serso: use correct tag
|
||||
this.viewBuilder = TextViewBuilder.newInstance(R.layout.plot_functions_fragment_list_item, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OnClickAction getOnClickAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OnClickAction getOnLongClickAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public View updateView(@NotNull Context context, @NotNull View view) {
|
||||
// todo serso: optimize
|
||||
return build(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public View build(@NotNull Context context) {
|
||||
TextView textView = viewBuilder.build(context);
|
||||
fill(textView);
|
||||
return textView;
|
||||
}
|
||||
|
||||
private void fill(@NotNull TextView textView) {
|
||||
textView.setText(plotInput.getExpression());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user