Mainactivity Java
Mainactivity Java
Mainactivity Java
Fa18-bse-016
MainActivity.java :
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.text.DecimalFormat;
import android.graphics.Typeface;
return splitedEquation;
}
strings.xml:
<resources>
<string name="app_name">LinearEquation </string>
<string name="equation_hint">Enter values of a b and c </string>
<string name="accepted_values">123 </string>
</resources>
Main.xml:
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/equation"
android:layout_marginTop="20dp"
android:layout_height="52dp"
android:layout_width="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="@drawable/rectangular_input"
android:hint="@string/equation_hint"
android:textSize="17sp"
android:digits="@string/accepted_values"
android:inputType="text"
android:paddingLeft="10dp" />
<LinearLayout
android:id="@+id/wrapper"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
<TextView
android:id="@+id/error"
android:gravity="center"
android:textSize="20dp"
android:textColor="#000"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
/>
</LinearLayout>
RootResultActivity.java:
stepTextView.setLayoutParams(textParams);
stepTextView.setText(step);
stepContentTextView.setLayoutParams(textParams);
stepContentTextView.setText(content);
stepContentTextView.setTextSize(17);
stepContentTextView.setTextColor(textColor);
stepTextView.setLayoutParams(textParams);
stepTextView.setText(step);
stepTextView.setTextSize(17);
stepTextView.setTextColor(textColor);
stepTextView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
solutionTextView.setLayoutParams(solutionTextParams);
solutionTextView.setText(solution);
solutionTextView.setTextSize(17);
solutionTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
solutionTextView.setTextColor(textColor);
linearLayout.setLayoutParams(linearLayouParams);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(stepTextView);
linearLayout.addView(stepContentTextView);
wrapper.addView(linearLayout);
wrapper.addView(solutionTextView);
Activity_Root_Result.xml
if(equation.length() == 0){
textView.setText("You did not input anything!");
return false;
}
int numOfEqualitySign = 0;
for(int j = 0; j < equation.length(); j++){
if (equation.charAt(j) == '=') {
numOfEqualitySign +=1;
numOfEqualitySign +=1;
}
if(equation.charAt(equation.length()-1) == '='){
textView.setText("Invalid equation! You did not input anything
return false;
if(Character.isLetter(equation.charAt(k+1))){
textView.setText("Invalid equation! Two or more variables can not be together. ");
return false;
}
}
}
if(k != equation.length() -1){
if(Character.isLetter(equation.charAt(k)) && Character.isDigit(equation.charAt(k+1)))
{
textView.setText("Invalid equation! You are expected to input either \"+\" or \"-\" sign after
" + equation.charAt(k) + " but you input " + equation.charAt(k+1) + " which is a number");
return false;
}
}
if(equation.charAt(k) == '(' || equation.charAt(k) == ')'){
sign = "" + equation.charAt(k);
if(k != equation.length() -1){
if(equation.charAt(k+1) == '(' || equation.charAt(k+1) == ')'){
textView.setText("Invalid equation! You cant have two or more " + sign + " together");
return false;
}
}
}
}
}
if(ovar == 1){
textView.setText("Invalid equation! You didnt close a bracket you opened.");
return false;
}
String hold = "";
int k = i+1;
if(j>= 0){
while(Character.isDigit(equation.charAt(j)) || Character.isLetter(equation.charAt(j))){
num = num + equation.charAt(j);
j -=1;
if (j < 0) break;
}
}