Skip to content

Commit

Permalink
#127 Operation with an array on the top of equation results NaN or in…
Browse files Browse the repository at this point in the history
…valid value: fixed
  • Loading branch information
mkulesh committed Oct 10, 2022
1 parent d6978e7 commit 2faee65
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ public boolean isUseBrackets()
return useBrackets;
}

/**
* Returns whether the conversion to other terms is disabled.
* When disabled, no other conversion conditions will be considered
*/
public boolean isConversionDisabled()
{
return false;
}

/*--------------------------------------------------------*
* Methods to be Implemented in derived a class
*--------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.mkulesh.micromath.formula.PaletteButton.Category;
import com.mkulesh.micromath.formula.terms.ArrayFunctions;
import com.mkulesh.micromath.formula.terms.Comparators;
import com.mkulesh.micromath.formula.terms.Intervals;
import com.mkulesh.micromath.formula.terms.TermFactory;
import com.mkulesh.micromath.formula.terms.TermTypeIf;
import com.mkulesh.micromath.formula.terms.UserFunctions;
Expand Down Expand Up @@ -1193,7 +1192,7 @@ public void requestFocus()
*/
public boolean isEnabledInPalette(Category pt)
{
if (isTerm() && term instanceof Intervals && pt != Category.NEW_TERM)
if (isTerm() && term.isConversionDisabled() && pt != Category.NEW_TERM)
{
return false;
}
Expand All @@ -1202,7 +1201,7 @@ public boolean isEnabledInPalette(Category pt)
case NEW_TERM:
return parentFormula.isNewTermEnabled() && text.isNewTermEnabled();
case TOP_LEVEL_TERM:
return text.isIntervalEnabled() || text.isFileOperationEnabled();
return text.isIntervalEnabled() || text.isArrayFunctionEnabled();
case CONVERSION:
return text.isConversionEnabled();
case INDEX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public int getBracketId()

public boolean isEnabled(CustomEditText field)
{
return this != READ || field.isFileOperationEnabled();
return this != READ || field.isArrayFunctionEnabled();
}

public PaletteButton.Category getPaletteCategory()
Expand Down Expand Up @@ -513,6 +513,12 @@ private void initMatrix(@NonNull final MatrixProperties dim)
}
}

@Override
public boolean isConversionDisabled()
{
return isArray();
}

/*--------------------------------------------------------*
* Methods implementing array operations
*--------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ else if (v.getText().toString()
return v;
}

@Override
public boolean isConversionDisabled()
{
return true;
}

/*--------------------------------------------------------*
* FormulaTermInterval-specific methods
*--------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum ArrayType
private boolean complexEnabled = true;
private boolean comparatorEnabled = false;
private boolean newTermEnabled = false;
private boolean fileOperationEnabled = false;
private boolean arrayFunctionEnabled = false;
private ArrayType arrayType = ArrayType.DISABLED;

// context menu handling
Expand Down Expand Up @@ -116,7 +116,7 @@ private void prepare(AttributeSet attrs)
intervalEnabled = a.getBoolean(R.styleable.CustomViewExtension_intervalEnabled, false);
complexEnabled = a.getBoolean(R.styleable.CustomViewExtension_complexEnabled, true);
newTermEnabled = a.getBoolean(R.styleable.CustomViewExtension_newTermEnabled, false);
fileOperationEnabled = a.getBoolean(R.styleable.CustomViewExtension_fileOperationEnabled, false);
arrayFunctionEnabled = a.getBoolean(R.styleable.CustomViewExtension_arrayFunctionEnabled, false);
final int arrayTypeInt = a.getInteger(R.styleable.CustomViewExtension_arrayType, -1);
if (arrayTypeInt >= 0 && arrayTypeInt < ArrayType.values().length)
{
Expand Down Expand Up @@ -217,9 +217,9 @@ public boolean isNewTermEnabled()
return newTermEnabled;
}

public boolean isFileOperationEnabled()
public boolean isArrayFunctionEnabled()
{
return fileOperationEnabled;
return arrayFunctionEnabled;
}

public ArrayType getArrayType()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/formula_equation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
android:layout_height="wrap_content"
android:text="@string/formula_right_term_key"
micromath:intervalEnabled="true"
micromath:fileOperationEnabled="true" />
micromath:arrayFunctionEnabled="true" />

</merge>
2 changes: 1 addition & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<attr name="intervalEnabled" format="boolean" />
<attr name="complexEnabled" format="boolean" />
<attr name="newTermEnabled" format="boolean" />
<attr name="fileOperationEnabled" format="boolean" />
<attr name="arrayFunctionEnabled" format="boolean" />
<attr name="arrayType"/>
</declare-styleable>
<declare-styleable name="PlotViewExtension">
Expand Down

0 comments on commit 2faee65

Please sign in to comment.