Part 12 - Students Problem Solving

 Java Part : 

package first.learn.passingdatabetweenactivities;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText etName;
Button btnSimpleString;

TextView textTwo,
textOne;


void add (int a, int b){
int c = a+b;
textTwo.setText(""+c);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textTwo = (TextView)findViewById(R.id.textTwo);

add (10, 20);






etName = (EditText) findViewById(R.id.etName);

btnSimpleString = (Button) findViewById(R.id.btnSimpleString);



}
}



Xml Part : 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp">



<TextView
android:hint="Text One... "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textOne"/>


<TextView
android:hint="Text two... "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textTwo"/>

<EditText
android:layout_marginTop="25dp"
android:hint="write...."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etName"/>

<Button
android:id="@+id/btnSimpleString"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple String"/>

</LinearLayout>



Part 10 - Passing Data Between Activities - Method One

 Java Part One : 

package first.learn.passingdatabetweenactivities;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

EditText etName;
Button btnSimpleString;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

etName = (EditText) findViewById(R.id.etName);

btnSimpleString = (Button) findViewById(R.id.btnSimpleString);

btnSimpleString.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

String s = etName.getText().toString();

if(TextUtils.isEmpty(s)){
etName.setError("Empty");
return;
}

etName.setError(null);


Intent intent = new Intent(MainActivity.this, DataGettingActivity.class );

intent.putExtra("StringPacket", s );

startActivity(intent);

}
});

}
}

xml part One : 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp">

<EditText
android:hint="write...."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etName"/>

<Button
android:id="@+id/btnSimpleString"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple String"/>

</LinearLayout>


Java Part Two : 

package first.learn.passingdatabetweenactivities;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class DataGettingActivity extends AppCompatActivity {

TextView tvData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_getting);

setTitle("Data Getting Activity");

tvData = (TextView) findViewById(R.id.tvData);


if(getIntent()!=null){

if(getIntent().getStringExtra("StringPacket")!=null){

String gettingString = getIntent().getStringExtra("StringPacket");

tvData.setText(gettingString);

}
}


}
}


Xml Part Two : 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DataGettingActivity"
android:layout_margin="16dp">


<TextView
android:id="@+id/tvData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="Text"
android:gravity="center"
android:layout_marginTop="25dp"/>


</LinearLayout>





Sample App - Calculator With JavaScript Library Rhino

Dependency : 

implementation 'com.faendir.rhino:rhino-android:1.5.2'


 Java Part : 

package first.learn.calculator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.button.MaterialButton;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


TextView tvMath, tvResult;
MaterialButton btnDoubleZero, btnZero, btnDot, btnEqual, btnOne, btnTwo, btnThree, btnFour,
btnFive, btnSix, btnSeven, btnEight, btnNine, btnPlus, btnMinus, btnMultiply, btnDivide,
btnBracketOpen, btnBracketEnd, btnC;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvMath = (TextView) findViewById(R.id.tvMath);
tvResult = (TextView) findViewById(R.id.tvResult);

castingAndSettingClickListener(btnDoubleZero, R.id.btnDoubleZero);
castingAndSettingClickListener(btnZero, R.id.btnZero);
castingAndSettingClickListener(btnDot, R.id.btnDot);
castingAndSettingClickListener(btnEqual, R.id.btnEqual);
castingAndSettingClickListener(btnOne, R.id.btnOne);
castingAndSettingClickListener(btnTwo, R.id.btnTwo);
castingAndSettingClickListener(btnThree, R.id.btnThree);
castingAndSettingClickListener(btnFour, R.id.btnFour);
castingAndSettingClickListener(btnFive, R.id.btnFive);
castingAndSettingClickListener(btnSix, R.id.btnSix);
castingAndSettingClickListener(btnSeven, R.id.btnSeven);
castingAndSettingClickListener(btnEight, R.id.btnEight);
castingAndSettingClickListener(btnNine, R.id.btnNine);
castingAndSettingClickListener(btnPlus, R.id.btnPlus);
castingAndSettingClickListener(btnMinus, R.id.btnMinus);
castingAndSettingClickListener(btnMultiply, R.id.btnMultiply);
castingAndSettingClickListener(btnDivide, R.id.btnDivide);
castingAndSettingClickListener(btnBracketOpen, R.id.btnBracketOpen);
castingAndSettingClickListener(btnBracketEnd, R.id.btnBracketEnd);
castingAndSettingClickListener(btnC, R.id.btnC);




}


void castingAndSettingClickListener(MaterialButton bttn, int id){
bttn = findViewById(id);
bttn.setOnClickListener(this);
}


@Override
public void onClick(View view) {


MaterialButton clickedButton = (MaterialButton) view;

String buttonText = clickedButton.getText().toString();

String dataForCalculation = tvMath.getText().toString();

if (buttonText.equals("C")){
tvMath.setText("");
tvResult.setText("0");
return;
}else if (buttonText.equals("=")){
tvMath.setText(tvResult.getText().toString());
return;
}else{
dataForCalculation = dataForCalculation+buttonText;
}

tvMath.setText(dataForCalculation);

String finalResult = makeResult(dataForCalculation);

if (!finalResult.equals("Error")){
tvResult.setText(finalResult);
}


}



String makeResult(String data){
try {
Context newContext = Context.enter();
newContext.setOptimizationLevel(-1);
Scriptable newScriptable = newContext.initStandardObjects();
String finalResult = newContext.evaluateString(newScriptable, data, "Javascript", 1, null).toString();

if (finalResult.endsWith(".0")){
finalResult = finalResult.replace(".0", "");
}
return finalResult;
}catch (Exception e){
return "Error";
}
}


}


Xml Part : 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F6B6B6"
android:gravity="bottom"
android:paddingBottom="15dp"
android:orientation="vertical"
tools:context=".MainActivity">


<TextView
android:layout_width="match_parent"
android:id="@+id/tvMath"
android:layout_marginBottom="20dp"
android:textSize="30dp"
android:textColor="@color/black"
android:paddingHorizontal="40dp"
android:gravity="right"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:id="@+id/tvResult"
android:text="0"
android:layout_marginBottom="20dp"
android:textSize="60dp"
android:textColor="@color/black"
android:paddingHorizontal="40dp"
android:gravity="right"
android:layout_height="wrap_content"/>



<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="C"
android:id="@+id/btnC"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="("
android:id="@+id/btnBracketOpen"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text=")"
android:id="@+id/btnBracketEnd"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="/"
android:id="@+id/btnDivide"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="7"
android:id="@+id/btnSeven"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="8"
android:id="@+id/btnEight"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="9"
android:id="@+id/btnNine"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="*"
android:id="@+id/btnMultiply"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="4"
android:id="@+id/btnFour"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="5"
android:id="@+id/btnFive"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="6"
android:id="@+id/btnSix"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="-"
android:id="@+id/btnMinus"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="1"
android:id="@+id/btnOne"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="2"
android:id="@+id/btnTwo"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="3"
android:id="@+id/btnThree"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="+"
android:id="@+id/btnPlus"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="00"
android:id="@+id/btnDoubleZero"
android:layout_margin="10dp"
android:textSize="22sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="0"
android:id="@+id/btnZero"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="@color/white"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="."
android:id="@+id/btnDot"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/black" />
<com.google.android.material.button.MaterialButton
android:layout_width="70dp"
android:layout_height="70dp"
android:backgroundTint="#0022FF"
app:cornerRadius="35dp"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
android:text="="
android:id="@+id/btnEqual"
android:layout_margin="10dp"
android:textSize="30sp"
android:textColor="@color/white" />

</LinearLayout>


</LinearLayout>



Part 9 : Working with Colors and Color Algorithm.

Java Part : 

package first.learn.edittextproject;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity {

EditText etTwo,
etOne;

TextView tvResult, txtNewResult;
Button btnPlus, btnMinus, btnDevide, btnMulitiply;

int grey, sky, red, blue, yellow;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

etTwo = (EditText) findViewById(R.id.etTwo);
etOne = (EditText) findViewById(R.id.etOne);

tvResult = (TextView) findViewById(R.id.tvResult);
btnPlus = (Button) findViewById(R.id.btnPlus);
btnMinus = (Button)findViewById(R.id.btnMinus);
btnDevide = (Button)findViewById(R.id.btnDevide);
btnMulitiply = (Button)findViewById(R.id.btnMulitiply);
txtNewResult = (TextView)findViewById(R.id.txtNewResult);

/*
yellow: -10752
blue: -16776961
grey: -13291215
sky: -13611010
red: -2818048
*/

yellow = ContextCompat.getColor(MainActivity.this, R.color.yellow);
// btnMinus.setBackgroundColor(-10752);

blue = Color.BLUE;
// btnDevide.setBackgroundColor(-16776961);


grey = Color.parseColor("#353131");
// btnPlus.setBackgroundColor(-13291215);


sky = 0xFF304FFE;
// btnMinus.setBackgroundColor(-2818048);

red = Color.rgb(213,0,0);
// btnMulitiply.setBackgroundColor(-2818048);


System.out.println("yellow: "+yellow+"\nblue: "+blue+"\ngrey: "+grey
+"\nsky: "+sky+"\nred: "+red);


btnPlus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//changeColorBtnColor(btnPlus);
changeColorBtnPlus ();
String a = getTextFromEditText(etOne);

if (a == null) {

return;
}

String b = getTextFromEditText(etTwo);

if (b == null) {
return;
}

float c = stringToFloat(a);
float d = stringToFloat(b);

float e = resultAddFloat(c, d);

String formatted = new DecimalFormat("#.####").format(e);
tvResult.setText("" + formatted);
txtNewResult.setText("" + formatted);


}
});

btnMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


// changeColorBtnColor(btnMinus);
changeColorBtnMinus();

String a = getTextFromEditText(etOne);

if (a == null) {

return;
}

String b = getTextFromEditText(etTwo);

if (b == null) {
return;
}

float c = stringToFloat(a);
float d = stringToFloat(b);


minus(c, d, tvResult);
minus(c, d, txtNewResult);


}
});

btnDevide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//changeColorBtnColor(btnDevide);
changeColorBtnDevide();
String a = getTextFromEditText(etOne);

if (a == null) {

return;
}

String b = getTextFromEditText(etTwo);

if (b == null) {
return;
}

float c = stringToFloat(a);
float d = stringToFloat(b);

float p = divide( c, d );

System.out.println("Divide Section: before Formatted : "+ p );

String formatted = new DecimalFormat("#.####").format(p);

System.out.println("Divide Section: after Formatted : "+ formatted );

tvResult.setText(""+formatted );
txtNewResult.setText(""+formatted);

}
});

btnMulitiply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

// changeColorBtnColor(btnMulitiply);

changeColorBtnMultiply();

String a = getTextFromEditText(etOne);

if (a == null) {

return;
}

String b = getTextFromEditText(etTwo);

if (b == null) {
return;
}

float c = stringToFloat(a);
float d = stringToFloat(b);

multiply (c, d, tvResult );
multiply (c, d, txtNewResult );

}
});

}

void changeColorBtnColor(Button btn){

btnPlus.setBackgroundColor(grey);
btnMinus.setBackgroundColor(grey);
btnDevide.setBackgroundColor(grey);
btnMulitiply.setBackgroundColor(grey);

btn.setBackgroundColor(red);
}

void changeColorBtnPlus (){
btnPlus.setBackgroundColor(red);
btnMinus.setBackgroundColor(grey);
btnDevide.setBackgroundColor(grey);
btnMulitiply.setBackgroundColor(grey);
}




void changeColorBtnMinus (){

btnPlus.setBackgroundColor(grey);
btnMinus.setBackgroundColor(red);
btnDevide.setBackgroundColor(grey);
btnMulitiply.setBackgroundColor(grey);
}



void changeColorBtnDevide (){

btnPlus.setBackgroundColor(grey);
btnMinus.setBackgroundColor(grey);
btnDevide.setBackgroundColor(red);
btnMulitiply.setBackgroundColor(grey);
}


void changeColorBtnMultiply (){

btnPlus.setBackgroundColor(grey);
btnMinus.setBackgroundColor(grey);
btnDevide.setBackgroundColor(grey);
btnMulitiply.setBackgroundColor(red);
}

void multiply (float a , float b, TextView txtResult ){

float c = a*b ;
String formatted = new DecimalFormat("#.####").format(c);

txtResult.setText(""+formatted );

}


float divide (float n, float m ){

float x = n/m;

return x ;
}



void minus (float a , float b, TextView txtResult ){

float c = a - b;

String formatted = new DecimalFormat("#.####").format(c);

txtResult.setText(""+formatted);

}

boolean isIntegerCharacter(String s) {

int c = -1;

try {
c = Integer.parseInt(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}

float stringToFloat(String s) {
return Float.parseFloat(s);
}


float resultAddFloat(float a, float b) {
return a + b;
}


String getTextFromEditText(EditText editText) {
String s = editText.getText().toString();

if (TextUtils.isEmpty(s)) {
editText.setError("Empty");
return null;
} else {
editText.setError(null);
return s;
}

}


}


Xml Part : 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp"

>



<EditText
android:hint="number One...."
android:layout_marginTop="25dp"
android:id="@+id/etOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>

<EditText
android:hint="number two..."
android:layout_marginTop="25dp"
android:id="@+id/etTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>


<TextView
android:textSize="25dp"
android:textColor="@color/purple_700"
android:layout_marginTop="20dp"
android:id="@+id/tvResult"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Result..."
/>


<LinearLayout
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">

<Button
android:layout_weight="1"
android:id="@+id/btnPlus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="+"
android:backgroundTint="@color/grey"/>

<Button
android:layout_marginLeft="2dp"
android:id="@+id/btnMinus"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="-"
android:backgroundTint="@color/grey"/>

<Button
android:layout_marginLeft="2dp"
android:id="@+id/btnDevide"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="/"
android:backgroundTint="@color/grey"/>


<Button
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:id="@+id/btnMulitiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="x"
android:backgroundTint="@color/grey"/>

</LinearLayout>



<LinearLayout
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:weightSum="4">

<TextView
android:background="@color/my_color_red"
android:layout_width="0dp"
android:layout_weight="3"
android:text="Final Resul"
android:gravity="center"
android:textColor="@color/white"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/txtNewResult"
android:background="@color/my_color_green"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="@color/white"
android:text="value"
android:layout_height="match_parent"/>

</LinearLayout>










</LinearLayout>



Color.xml : 


<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>


<color name="my_color_red">#B81059</color>

<color name="my_color_green">#06A120</color>


<color name="yellow">#FFD600</color>

<color name="sky">#304FFE</color>

<color name="blue">#070F40</color>

<color name="grey">#353131</color>

<color name="red">#D50000</color>


</resources>




 

Featured Post

Lesson 1 : Android Studio : DownLoad And Install and First App

বিসমিল্লাহির রাহমানির রাহীম Lesson 1 : Android Studio : DownLoad And Install  and First App এই লেসনটির ভিডিও ইউটিউবে দেখতে এখানে ক্ল...

Popular Posts