-
Notifications
You must be signed in to change notification settings - Fork 0
complete #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrxjeus
wants to merge
1
commit into
develop
Choose a base branch
from
code_v1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
complete #2
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
225 changes: 225 additions & 0 deletions
225
app/src/main/java/com/mrjeus/calculator/CalculatorFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| package com.mrjeus.calculator; | ||
|
|
||
| import android.content.Context; | ||
| import android.net.Uri; | ||
| import android.os.Bundle; | ||
| import android.support.v4.app.Fragment; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.Button; | ||
| import android.widget.TextView; | ||
|
|
||
| public class CalculatorFragment extends Fragment { | ||
| View view; | ||
| private TextView mTxtInput; | ||
| private TextView mTxtOutput; | ||
|
|
||
| private Button mBtnNumber0; | ||
| private Button mBtnNumber1; | ||
| private Button mBtnNumber2; | ||
| private Button mBtnNumber3; | ||
| private Button mBtnNumber4; | ||
| private Button mBtnNumber5; | ||
| private Button mBtnNumber6; | ||
| private Button mBtnNumber7; | ||
| private Button mBtnNumber8; | ||
| private Button mBtnNumber9; | ||
| private Button mBtnDot; | ||
|
|
||
| private Button mBtnAdd; | ||
| private Button mBtnSub; | ||
| private Button mBtnDiv; | ||
| private Button mBtnMul; | ||
|
|
||
| private Button mBtnResult; | ||
| private Button mBtnPercent; | ||
| private Button mBtnAC; | ||
| private Button mBtnDEL; | ||
| private Button mBtnNagPos; | ||
| @Override | ||
| public void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| } | ||
|
|
||
| @Override | ||
| public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
| Bundle savedInstanceState) { | ||
| view = inflater.inflate(R.layout.fragment_calculator,container,false); | ||
| initWidget(); | ||
| setClick(); | ||
| return view; | ||
| } | ||
|
|
||
| public void initWidget() { | ||
| mTxtInput = (TextView) view.findViewById(R.id.text_view_in_put); | ||
| mTxtOutput = (TextView) view.findViewById(R.id.text_view_out_put); | ||
|
|
||
| mBtnNumber0 = (Button) view.findViewById(R.id.button_0); | ||
| mBtnNumber1 = (Button) view.findViewById(R.id.button_1); | ||
| mBtnNumber2 = (Button) view.findViewById(R.id.button_2); | ||
| mBtnNumber3 = (Button) view.findViewById(R.id.button_3); | ||
| mBtnNumber4 = (Button) view.findViewById(R.id.button_4); | ||
| mBtnNumber5 = (Button) view.findViewById(R.id.button_5); | ||
| mBtnNumber6 = (Button) view.findViewById(R.id.button_6); | ||
| mBtnNumber7 = (Button) view.findViewById(R.id.button_7); | ||
| mBtnNumber8 = (Button) view.findViewById(R.id.button_8); | ||
| mBtnNumber9 = (Button) view.findViewById(R.id.button_9); | ||
| mBtnDot = (Button) view.findViewById(R.id.button_dot); | ||
|
|
||
| mBtnAdd = (Button) view.findViewById(R.id.button_add); | ||
| mBtnSub = (Button) view.findViewById(R.id.button_sub); | ||
| mBtnDiv = (Button) view.findViewById(R.id.button_div); | ||
| mBtnMul = (Button) view.findViewById(R.id.button_mul); | ||
|
|
||
| mBtnResult = (Button) view.findViewById(R.id.button_result); | ||
| mBtnPercent = (Button) view.findViewById(R.id.button_percent); | ||
| mBtnNagPos = (Button) view.findViewById(R.id.button_neg_pos); | ||
| mBtnAC = (Button) view.findViewById(R.id.button_ac); | ||
| mBtnDEL = (Button) view.findViewById(R.id.button_del); | ||
| } | ||
|
|
||
| public void setClick(){ | ||
| mBtnNumber0.setOnClickListener(click); | ||
| mBtnNumber1.setOnClickListener(click); | ||
| mBtnNumber2.setOnClickListener(click); | ||
| mBtnNumber3.setOnClickListener(click); | ||
| mBtnNumber4.setOnClickListener(click); | ||
| mBtnNumber5.setOnClickListener(click); | ||
| mBtnNumber6.setOnClickListener(click); | ||
| mBtnNumber7.setOnClickListener(click); | ||
| mBtnNumber8.setOnClickListener(click); | ||
| mBtnNumber9.setOnClickListener(click); | ||
| mBtnDot.setOnClickListener(click); | ||
|
|
||
| mBtnAdd.setOnClickListener(click); | ||
| mBtnSub.setOnClickListener(click); | ||
| mBtnDiv.setOnClickListener(click); | ||
| mBtnMul.setOnClickListener(click); | ||
|
|
||
| mBtnAC.setOnClickListener(click); | ||
| mBtnPercent.setOnClickListener(click); | ||
| mBtnNagPos.setOnClickListener(click); | ||
| mBtnDEL.setOnClickListener(click); | ||
| mBtnResult.setOnClickListener(click); | ||
| } | ||
|
|
||
| View.OnClickListener click = new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View v) { | ||
| switch (v.getId()) { | ||
| case R.id.button_0: | ||
| mTxtInput.append("0"); | ||
| break; | ||
| case R.id.button_1: | ||
| mTxtInput.append("1"); | ||
| break; | ||
| case R.id.button_2: | ||
| mTxtInput.append("2"); | ||
| break; | ||
| case R.id.button_3: | ||
| mTxtInput.append("3"); | ||
| break; | ||
| case R.id.button_4: | ||
| mTxtInput.append("4"); | ||
| break; | ||
| case R.id.button_5: | ||
| mTxtInput.append("5"); | ||
| break; | ||
| case R.id.button_6: | ||
| mTxtInput.append("6"); | ||
| break; | ||
| case R.id.button_7: | ||
| mTxtInput.append("7"); | ||
| break; | ||
| case R.id.button_8: | ||
| mTxtInput.append("8"); | ||
| break; | ||
| case R.id.button_9: | ||
| mTxtInput.append("9"); | ||
| break; | ||
| case R.id.button_dot: | ||
| mTxtInput.append("."); | ||
| break; | ||
| case R.id.button_add: | ||
| mTxtInput.append("+"); | ||
| break; | ||
| case R.id.button_sub: | ||
| mTxtInput.append("-"); | ||
| break; | ||
| case R.id.button_div: | ||
| mTxtInput.append("/"); | ||
| break; | ||
| case R.id.button_mul: | ||
| mTxtInput.append("*"); | ||
| break; | ||
| case R.id.button_result: | ||
| //todo some thing | ||
| mTxtOutput.setText(resultNumber(mTxtInput.getText().toString())); | ||
| break; | ||
| case R.id.button_percent: | ||
|
|
||
| break; | ||
| case R.id.button_neg_pos: | ||
|
|
||
| break; | ||
| case R.id.button_ac: | ||
| mTxtInput.setText(""); | ||
| break; | ||
| case R.id.button_del: | ||
| String numberAffterRemove = deleteNumber(mTxtInput.getText().toString()); | ||
| mTxtInput.setText(numberAffterRemove); | ||
| break; | ||
| } | ||
| } | ||
| }; | ||
| public String deleteNumber(String number) { | ||
| if (number.length() != 0) { | ||
| int length = number.length(); | ||
| String mTem = number.substring(0, length - 1); | ||
| return mTem; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public String resultNumber(String input) { | ||
| String mNumber1 = ""; | ||
| String mNumber2 = ""; | ||
| double mResult = 0, mNum1, mNum2; | ||
| for (int i = 0; i < input.length(); i++) { | ||
| if (input.charAt(i) == '+') { | ||
| mNumber1 = input.substring(0, i); | ||
| mNum1 = Double.parseDouble(mNumber1); | ||
| mNumber2 = input.substring(i + 1, input.length()); | ||
| mNum2 = Double.parseDouble(mNumber2); | ||
| mResult = mNum1 + mNum2; | ||
| return (String.valueOf(mResult)); | ||
| } | ||
| if (input.charAt(i) == '-') { | ||
| mNumber1 = input.substring(0, i); | ||
| mNum1 = Double.parseDouble(mNumber1); | ||
| mNumber2 = input.substring(i + 1, input.length()); | ||
| mNum2 = Double.parseDouble(mNumber2); | ||
| mResult = mNum1 - mNum2; | ||
| return (String.valueOf(mResult)); | ||
| } | ||
| if (input.charAt(i) == '*') { | ||
| mNumber1 = input.substring(0, i); | ||
| mNum1 = Double.parseDouble(mNumber1); | ||
| mNumber2 = input.substring(i + 1, input.length()); | ||
| mNum2 = Double.parseDouble(mNumber2); | ||
| mResult = mNum1 * mNum2; | ||
| return (String.valueOf(mResult)); | ||
| } | ||
| if (input.charAt(i) == '/') { | ||
| mNumber1 = input.substring(0, i); | ||
| mNum1 = Double.parseDouble(mNumber1); | ||
| mNumber2 = input.substring(i + 1, input.length()); | ||
| mNum2 = Double.parseDouble(mNumber2); | ||
| mResult = mNum1 / mNum2; | ||
| return (String.valueOf(mResult)); | ||
| } | ||
| } | ||
| return String.valueOf(mResult); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| package com.mrjeus.calculator; | ||
|
|
||
| import android.support.v4.app.FragmentTransaction; | ||
| import android.support.v7.app.AppCompatActivity; | ||
| import android.os.Bundle; | ||
|
|
||
| public class MainActivity extends AppCompatActivity { | ||
|
|
||
| CalculatorFragment calculatorFragment; | ||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
|
|
||
| calculatorFragment = new CalculatorFragment(); | ||
| FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | ||
| fragmentTransaction.replace(R.id.frame_cal,calculatorFragment); | ||
| fragmentTransaction.commit(); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,4 @@ | |
| android:strokeColor="#00000000" | ||
| android:strokeWidth="1" /> | ||
| </vector> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:shape="rectangle"> | ||
| <solid android:color="#ffffff"/> | ||
| <stroke | ||
| android:width="1dp" | ||
| android:color="#000000"/> | ||
| </shape> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:shape="rectangle"> | ||
| <solid android:color="#f47d3e"/> | ||
| <stroke | ||
| android:width="3dp" | ||
| android:color="#000000" /> | ||
| </shape> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,3 +168,4 @@ | |
| android:strokeColor="#33FFFFFF" | ||
| android:strokeWidth="0.8" /> | ||
| </vector> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <color name="colorPrimary">#3F51B5</color> | ||
| <color name="colorPrimaryDark">#303F9F</color> | ||
| <color name="colorAccent">#FF4081</color> | ||
| </resources> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <dimen name="sp_25">25sp</dimen> | ||
| <dimen name="dp_75">75dp</dimen> | ||
| </resources> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add blank line |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <resources> | ||
| <string name="app_name">Calculator</string> | ||
| <string name="number0">0</string> | ||
| <string name="number1">1</string> | ||
| <string name="number2">2</string> | ||
| <string name="number3">3</string> | ||
| <string name="number4">4</string> | ||
| <string name="number5">5</string> | ||
| <string name="number6">6</string> | ||
| <string name="number7">7</string> | ||
| <string name="number8">8</string> | ||
| <string name="number9">9</string> | ||
| <string name="dot">.</string> | ||
| <string name="sub">-</string> | ||
| <string name="add">+</string> | ||
| <string name="div">/</string> | ||
| <string name="mul">*</string> | ||
| <string name="sign">+/-</string> | ||
| <string name="percent">%</string> | ||
| <string name="AC">AC</string> | ||
| <string name="DEL">DEL</string> | ||
| <string name="result">=</string> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <resources> | ||
|
|
||
| <!-- Base application theme. --> | ||
| <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
| <!-- Customize your theme here. --> | ||
| <item name="colorPrimary">@color/colorPrimary</item> | ||
| <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
| <item name="colorAccent">@color/colorAccent</item> | ||
| </style> | ||
|
|
||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.constraint.ConstraintLayout 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" | ||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| tools:context=".MainActivity"> | ||
| </android.support.constraint.ConstraintLayout> | ||
| <FrameLayout | ||
| android:id="@+id/frame_cal" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
| </FrameLayout> | ||
| </RelativeLayout> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mấy cái này ông không cần khai báo instance variable, chỉ cần findViewById().setOnClick()