diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..3ed0c66 Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ba7052b..e0d5b93 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,26 +5,31 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml index 6169877..3480a4a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d496a8c..e89940f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 26 - buildToolsVersion "26.0.2" + buildToolsVersion '28.0.3' defaultConfig { applicationId "tech.iosd.calculaterhacktober" minSdkVersion 15 diff --git a/app/src/main/java/tech/iosd/calculaterhacktober/MainActivity.java b/app/src/main/java/tech/iosd/calculaterhacktober/MainActivity.java index a0cb52b..80acc3b 100644 --- a/app/src/main/java/tech/iosd/calculaterhacktober/MainActivity.java +++ b/app/src/main/java/tech/iosd/calculaterhacktober/MainActivity.java @@ -1,25 +1,86 @@ package tech.iosd.calculaterhacktober; +import android.content.DialogInterface; import android.content.Intent; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import static java.lang.Math.sqrt; + public class MainActivity extends AppCompatActivity { - Button add,sub,div,mul,one,two,three,four,five,six,seven,eight,nine,zero,equal,clear,decimal,clearall,percent,change,sign; + Button add,sub,div,mul,one,two,three,four,five,six,seven,eight,nine,zero,equal,clear,decimal,clearall,percent,change,sign, + pi,root,power,mod,history; TextView edit2,edit1; float value1,value2; float ans=0; - boolean addition,subtraction,division,multiplication,answer; + boolean addition,subtraction,division,multiplication,answer,calcPower,calcMod; + + /** + * Zyro + * Added string to save HISTORY + * **/ + + StringBuilder historyString = new StringBuilder(""); + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_history,menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + if(item.getItemId() == R.id.action_history) + { + AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); //Read Update + alertDialog.setTitle("History"); + alertDialog.setMessage(historyString); + alertDialog.show(); //<-- See This! + } + + +return true; + } + + /** + * Zyro + * Added history button + * **/ + + + + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + + /** + * 14th October 2018 + * HactoberFest + * Zyro adds four buttons PI,root,power,mod + **/ + + pi=(Button)findViewById(R.id.pi); + root=(Button)findViewById(R.id.root); + power=(Button)findViewById(R.id.power); + mod=(Button)findViewById(R.id.mod); + + add=(Button)findViewById(R.id.add); sub=(Button)findViewById(R.id.sub); mul=(Button)findViewById(R.id.mul); @@ -44,6 +105,37 @@ protected void onCreate(Bundle savedInstanceState) { sign= (Button) findViewById(R.id.sign); // change= (Button) findViewById(R.id.change); + /** Zyro add onCLickListener + * + */ + + //What happens on PI? + + pi.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + edit1.setText(edit1.getText()+"3.14159"); + historyString.append(edit1.getText()+"3.14159"+"\n"); + } + }); + + //What happens on root? + + root.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try{ + value1=Float.parseFloat(edit1.getText()+""); + + edit1.setText((sqrt(value1))+""); + historyString.append(sqrt(value1)+"\n"); + } + catch (Exception e){ + edit1.setText("error"); + } + } + }); + one.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -138,18 +230,79 @@ public void onClick(View view) { edit1.setText(""); } }); + + //What happens on power? + power.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + try { + + value1 = Float.parseFloat(edit1.getText() + ""); + edit2.setText(edit1.getText() + "^"); + historyString.append(edit1.getText() + "^" + "\n"); + edit1.setText(""); +// ans=Float.parseFloat(edit.getText()+""); + calcPower = true; + addition = false; + subtraction = false; + division = false; + multiplication = false; + calcMod = false; + } + catch (Exception e){ + edit1.setText("error"); + } + + } + }); + + //What happens on MODULUS? + + mod.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try { + + value1 = Float.parseFloat(edit1.getText() + ""); + edit2.setText(edit1.getText() + "%"); + historyString.append(edit1.getText() + "%"+"\n"); + edit1.setText(""); +// ans=Float.parseFloat(edit.getText()+""); + calcMod = true; + calcPower = false; + addition = false; + subtraction = false; + division = false; + multiplication = false; + } + catch (Exception e){ + edit1.setText("error"); + } + } + }); + add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - value1=Float.parseFloat(edit1.getText()+""); - edit2.setText(edit1.getText()+"+"); - edit1.setText(""); + try { + value1 = Float.parseFloat(edit1.getText() + ""); + edit2.setText(edit1.getText() + "+"); + historyString.append(edit1.getText() + "+" + "\n"); + edit1.setText(""); // ans=Float.parseFloat(edit.getText()+""); - addition=true; - subtraction=false; - division=false; - multiplication=false; + addition = true; + subtraction = false; + division = false; + multiplication = false; + calcPower = false; + calcMod = false; + // edit.setText(null); + } + catch (Exception e){ + edit1.setText("error"); + } } }); sub.setOnClickListener(new View.OnClickListener() { @@ -161,9 +314,12 @@ public void onClick(View view) { addition=false; division=false; multiplication=false; + calcPower=false; + calcMod = false; // edit.setText(null); value1=Float.parseFloat(edit1.getText()+""); edit2.setText(edit1.getText()+"-"); + historyString.append(edit1.getText()+"-"+"\n"); edit1.setText(""); } catch (Exception e){ @@ -180,9 +336,12 @@ public void onClick(View view) { subtraction=false; addition=false; multiplication=false; + calcPower=false; + calcMod = false; // edit.setText(null); value1=Float.parseFloat(edit1.getText()+""); edit2.setText(edit1.getText()+"/"); + historyString.append(edit1.getText()+"/"+"\n"); edit1.setText(""); } catch (Exception e){ @@ -199,9 +358,12 @@ public void onClick(View view) { subtraction=false; division=false; addition=false; + calcPower=false; + calcMod = false; // edit.setText(null); value1=Float.parseFloat(edit1.getText()+""); edit2.setText(edit1.getText()+"*"); + historyString.append(edit1.getText()+"*"+"\n"); edit1.setText(""); } catch (Exception e){ @@ -234,7 +396,15 @@ else if(multiplication==true){ //multiplication=false; } + else if(calcPower==true){ + ans = (float)Math.pow(value1,value2); + + } + else if(calcMod==true){ + ans = value1 % value2; + } edit1.setText(ans+""); + historyString.append(ans+""+"\n"); } catch (Exception e){ edit1.setText("error"); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1376ff9..cbb3cb7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -47,6 +47,64 @@ android:layout_weight="1.75" android:orientation="vertical"> + + + + +