mirror of
				https://github.com/SimpleMobileTools/Simple-Calculator.git
				synced 2025-06-05 21:49:13 +02:00 
			
		
		
		
	implement digit buttons
This commit is contained in:
		| @@ -23,4 +23,5 @@ dependencies { | ||||
|     compile fileTree(dir: 'libs', include: ['*.jar']) | ||||
|     testCompile 'junit:junit:4.12' | ||||
|     compile 'com.android.support:appcompat-v7:23.1.1' | ||||
|     compile 'com.jakewharton:butterknife:7.0.1' | ||||
| } | ||||
|   | ||||
							
								
								
									
										14
									
								
								app/proguard-rules.pro
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								app/proguard-rules.pro
									
									
									
									
										vendored
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| # Add project specific ProGuard rules here. | ||||
| # By default, the flags in this file are appended to flags specified | ||||
| # in /home/tibbi/misc/sdk/tools/proguard/proguard-android.txt | ||||
| # in $ANDROID_HOME/tools/proguard/proguard-android.txt | ||||
| # You can edit the include path and order by changing the proguardFiles | ||||
| # directive in build.gradle. | ||||
| # | ||||
| @@ -15,3 +15,15 @@ | ||||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||||
| #   public *; | ||||
| #} | ||||
|  | ||||
| -keep class butterknife.** { *; } | ||||
| -dontwarn butterknife.internal.** | ||||
| -keep class **$$ViewBinder { *; } | ||||
|  | ||||
| -keepclasseswithmembernames class * { | ||||
|     @butterknife.* <fields>; | ||||
| } | ||||
|  | ||||
| -keepclasseswithmembernames class * { | ||||
|     @butterknife.* <methods>; | ||||
| } | ||||
|   | ||||
| @@ -1,13 +1,77 @@ | ||||
| package calculator.simplemobiletools.com.simple_calculator; | ||||
|  | ||||
| import android.support.v7.app.AppCompatActivity; | ||||
| import android.os.Bundle; | ||||
| import android.support.v7.app.AppCompatActivity; | ||||
| import android.view.View; | ||||
| import android.widget.TextView; | ||||
|  | ||||
| import butterknife.Bind; | ||||
| import butterknife.ButterKnife; | ||||
| import butterknife.OnClick; | ||||
|  | ||||
| public class MainActivity extends AppCompatActivity { | ||||
|     @Bind(R.id.result) TextView result; | ||||
|  | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setContentView(R.layout.activity_main); | ||||
|         ButterKnife.bind(this); | ||||
|     } | ||||
|  | ||||
|     private void addDigit(int number) { | ||||
|         final String currentValue = result.getText().toString(); | ||||
|         final String newValue = getFormattedValue(currentValue + number); | ||||
|         result.setText(newValue); | ||||
|     } | ||||
|  | ||||
|     private String getFormattedValue(String str) { | ||||
|         return formatDouble(Double.parseDouble(str)); | ||||
|     } | ||||
|  | ||||
|     private String formatDouble(double d) { | ||||
|         if (d == (long) d) { | ||||
|             return String.format("%d", (long) d); | ||||
|         } else { | ||||
|             return String.format("%s", d); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @OnClick({R.id.btn_0, R.id.btn_1, R.id.btn_2, R.id.btn_3, R.id.btn_4, R.id.btn_5, R.id.btn_6, R.id.btn_7, R.id.btn_8, R.id.btn_9}) | ||||
|     public void digitClicked(View view) { | ||||
|         switch (view.getId()) { | ||||
|             case R.id.btn_0: | ||||
|                 addDigit(0); | ||||
|                 break; | ||||
|             case R.id.btn_1: | ||||
|                 addDigit(1); | ||||
|                 break; | ||||
|             case R.id.btn_2: | ||||
|                 addDigit(2); | ||||
|                 break; | ||||
|             case R.id.btn_3: | ||||
|                 addDigit(3); | ||||
|                 break; | ||||
|             case R.id.btn_4: | ||||
|                 addDigit(4); | ||||
|                 break; | ||||
|             case R.id.btn_5: | ||||
|                 addDigit(5); | ||||
|                 break; | ||||
|             case R.id.btn_6: | ||||
|                 addDigit(6); | ||||
|                 break; | ||||
|             case R.id.btn_7: | ||||
|                 addDigit(7); | ||||
|                 break; | ||||
|             case R.id.btn_8: | ||||
|                 addDigit(8); | ||||
|                 break; | ||||
|             case R.id.btn_9: | ||||
|                 addDigit(9); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -11,11 +11,13 @@ | ||||
|     tools:context="calculator.simplemobiletools.com.simple_calculator.MainActivity"> | ||||
|  | ||||
|     <TextView | ||||
|         android:id="@+id/display" | ||||
|         android:id="@+id/result" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_marginBottom="@dimen/activity_margin" | ||||
|         android:gravity="right" | ||||
|         android:lines="1" | ||||
|         android:maxLength="15" | ||||
|         android:padding="@dimen/activity_margin" | ||||
|         android:text="0" | ||||
|         android:textSize="@dimen/display_text_size"/> | ||||
| @@ -23,7 +25,7 @@ | ||||
|     <TableLayout | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="match_parent" | ||||
|         android:layout_below="@+id/display"> | ||||
|         android:layout_below="@+id/result"> | ||||
|  | ||||
|         <TableRow | ||||
|             android:layout_width="match_parent" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user