diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index ca34746..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Calculator \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 827ba1e..6354b66 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,7 +3,7 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981..ba7052b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + diff --git a/.idea/modules.xml b/.idea/modules.xml index dcdca1a..297565b 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 6564d52..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Calculator.iml b/DrStrangeCalculator.iml similarity index 67% rename from Calculator.iml rename to DrStrangeCalculator.iml index 6aea003..cd5436c 100644 --- a/Calculator.iml +++ b/DrStrangeCalculator.iml @@ -1,5 +1,5 @@ - + @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 9a3b8a1..f6105ec 100644 --- a/app/app.iml +++ b/app/app.iml @@ -9,13 +9,9 @@ - + - + + + + - + + + + + + + + + + + + + + + - + - + + + + + + + + - + + + + - - - - - - - - - + + + + + + + - - - + + + + + + + - - - + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ccf7d1f..547205a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,6 +20,7 @@ android { } dependencies { + implementation 'com.android.support:support-v4:23.4.0' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.1' } diff --git a/app/src/main/java/com/example/android/calculator/MainActivity.java b/app/src/main/java/com/example/android/calculator/MainActivity.java index 54143e2..b65088e 100644 --- a/app/src/main/java/com/example/android/calculator/MainActivity.java +++ b/app/src/main/java/com/example/android/calculator/MainActivity.java @@ -1,5 +1,10 @@ package com.example.android.calculator; +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; @@ -10,25 +15,39 @@ import android.widget.TextView; import android.widget.Toast; + + import org.w3c.dom.Text; public class MainActivity extends AppCompatActivity { -Button plus,minus,multiply,divide; -TextView input_et; -TextView result_tv; -double a=0,res=0; - boolean set=false; -char operation='0'; + Button plus, minus, multiply, divide; + TextView input_et; + TextView result_tv; + double a = 0, res = 0; + boolean set = false; + char operation = '0'; + + SensorManager mSensorManager; + SensorEventListener mSensorListener; + float mAcceleration = 0.0f, mAccelerationCurrent = 0.0f, mAccelerationLast = 0.0f; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - plus=(Button)findViewById(R.id.add); - minus=(Button)findViewById(R.id.subtract); - multiply=(Button)findViewById(R.id.multiply); - divide=(Button)findViewById(R.id.divide); - input_et=(TextView)findViewById(R.id.input_et); - result_tv=(TextView)findViewById(R.id.result_tv); + plus = (Button) findViewById(R.id.add); + minus = (Button) findViewById(R.id.subtract); + multiply = (Button) findViewById(R.id.multiply); + divide = (Button) findViewById(R.id.divide); + input_et = (TextView) findViewById(R.id.input_et); + result_tv = (TextView) findViewById(R.id.result_tv); + + mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); + mAcceleration = 0.0f; + mAccelerationCurrent = SensorManager.GRAVITY_EARTH; + mAccelerationLast = SensorManager.GRAVITY_EARTH; + + bindShakeToClearListener(); } @Override @@ -52,131 +71,184 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + + @Override + protected void onResume() { + super.onResume(); + mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + } + + @Override + protected void onPause() { + super.onPause(); + mSensorManager.unregisterListener(mSensorListener); + } + public void display(View view) { - switch(operation){ + switch (operation) { case '+': - res+=a; + res += a; break; case '-': - res-=a; + res -= a; break; case '*': - res*=a; + res *= a; break; case '/': - res/=a; + res /= a; break; default: break; } - a=res; - result_tv.setText(""+res); - } - - public void clear(View view){ - res=0; - a=0; - set=false; - operation= '0'; - result_tv.setText(""+res); - input_et.setText(""+a); - } - public void add(View view){ - if(!set){ - res=a; - result_tv.setText(""+res); - set=true; + a = res; + result_tv.setText("" + res); + } + + public void clear(View view) { + res = 0; + a = 0; + set = false; + operation = '0'; + result_tv.setText("" + res); + input_et.setText("" + a); + } + + public void add(View view) { + if (!set) { + res = a; + result_tv.setText("" + res); + set = true; + } + // Toast.makeText(this,"Plus button clicked",Toast.LENGTH_SHORT).show(); + // a=Float.parseFloat(input_et.getText().toString()); + a = 0; + operation = '+'; + input_et.setText("" + a); + } + + public void subtract(View view) { + if (!set) { + res = a; + result_tv.setText("" + res); + set = true; } - // Toast.makeText(this,"Plus button clicked",Toast.LENGTH_SHORT).show(); - // a=Float.parseFloat(input_et.getText().toString()); - a=0; - operation='+'; - input_et.setText(""+a); - } - public void subtract(View view){ - if(!set){ - res=a; - result_tv.setText(""+res); - set=true; - } // Toast.makeText(this,"Plus button clicked",Toast.LENGTH_SHORT).show(); - // a=Float.parseFloat(input_et.getText().toString()); - a=0; - operation='-'; - input_et.setText(""+a); - } - public void multiply(View view){ - if(!set){ - res=a; - result_tv.setText(""+res); - set=true; + // a=Float.parseFloat(input_et.getText().toString()); + a = 0; + operation = '-'; + input_et.setText("" + a); + } + + public void multiply(View view) { + if (!set) { + res = a; + result_tv.setText("" + res); + set = true; } // Toast.makeText(this,"Plus button clicked",Toast.LENGTH_SHORT).show() - a=0; - operation='*'; - input_et.setText(""+a); - } - public void divide(View view){ - if(!set){ - res=a; - result_tv.setText(""+res); - set=true; + a = 0; + operation = '*'; + input_et.setText("" + a); + } + + public void divide(View view) { + if (!set) { + res = a; + result_tv.setText("" + res); + set = true; } // Toast.makeText(this,"Plus button clicked",Toast.LENGTH_SHORT).show(); - // a=Float.parseFloat(input_et.getText().toString()); - a=0; - operation='/'; - input_et.setText(""+a); - } - public void value1(View view){ - a*=10; - a+=1; - input_et.setText(""+a); - } - public void value2(View view){ - a*=10; - a+=2; - input_et.setText(""+a); - } - public void value3(View view){ - a*=10; - a+=3; - input_et.setText(""+a); - } - public void value4(View view){ - a*=10; - a+=4; - input_et.setText(""+a); - } - public void value5(View view){ - a*=10; - a+=5; - input_et.setText(""+a); - } - public void value6(View view){ - a*=10; - a+=6; - input_et.setText(""+a); - } - public void value7(View view){ - a*=10; - a+=7; - input_et.setText(""+a); - } - public void value8(View view){ - a*=10; - a+=8; - input_et.setText(""+a); - } - public void value9(View view){ - a*=10; - a+=9; - input_et.setText(""+a); - } - public void value0(View view){ - a*=10; - input_et.setText(""+a); + // a=Float.parseFloat(input_et.getText().toString()); + a = 0; + operation = '/'; + input_et.setText("" + a); } + public void value1(View view) { + a *= 10; + a += 1; + input_et.setText("" + a); + } + + public void value2(View view) { + a *= 10; + a += 2; + input_et.setText("" + a); + } + + public void value3(View view) { + a *= 10; + a += 3; + input_et.setText("" + a); + } + + public void value4(View view) { + a *= 10; + a += 4; + input_et.setText("" + a); + } + + public void value5(View view) { + a *= 10; + a += 5; + input_et.setText("" + a); + } + + public void value6(View view) { + a *= 10; + a += 6; + input_et.setText("" + a); + } + + public void value7(View view) { + a *= 10; + a += 7; + input_et.setText("" + a); + } + + public void value8(View view) { + a *= 10; + a += 8; + input_et.setText("" + a); + } + + public void value9(View view) { + a *= 10; + a += 9; + input_et.setText("" + a); + } + + public void value0(View view) { + a *= 10; + input_et.setText("" + a); + } + + // Method to implement shake to clear feature + public void bindShakeToClearListener(){ + mSensorListener = new SensorEventListener() { + @Override + public void onSensorChanged(SensorEvent sensorEvent) { + float x,y,z; + x = sensorEvent.values[0]; + y = sensorEvent.values[1]; + // z = sensorEvent.values[2]; + + mAccelerationLast = mAccelerationCurrent; + mAccelerationCurrent = (float)Math.sqrt(((x * x + y * y ))); // Not taking z-axis to avoid clearing when the device is picked up or lowered + double delta = mAccelerationCurrent - mAccelerationLast; + mAcceleration = (float)(mAcceleration * 0.9f + delta); + + if (mAcceleration > 10.5) { // Value '12' so that triggered only after a reasonable acceleration + clear(findViewById(android.R.id.content)); + } + } + + @Override + public void onAccuracyChanged(Sensor sensor, int i) { + // Do nothing + } + }; + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d1b611f..bde8107 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,4 +4,7 @@ Hello world! Settings + + + Hello blank fragment diff --git a/build.gradle b/build.gradle index 1b7886d..2540ef4 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.0' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b71008..d830927 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jan 21 19:23:56 IST 2016 +#Sun Dec 24 03:08:23 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip