P3 unfinished

This commit is contained in:
icewithcola 2024-04-09 08:48:27 +08:00
parent d2e8ef37db
commit 940552ab62
5 changed files with 260 additions and 0 deletions

View file

@ -18,6 +18,9 @@
<timeTargetWasSelectedWithDropDown value="2024-03-26T06:34:42.198995747Z" />
</State>
</entry>
<entry key="Page3">
<State />
</entry>
<entry key="app">
<State />
</entry>

View file

@ -0,0 +1,7 @@
package uk.kagurach.android101
import android.content.Context
fun Kaculate(src: String,ctx :Context) : String{
return ""
}

View file

@ -1,6 +1,11 @@
package uk.kagurach.android101;
import static uk.kagurach.android101.KaculateKt.Kaculate;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
@ -8,6 +13,7 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import uk.kagurach.android101.KaculateKt;
public class Page3 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -19,6 +25,57 @@ public class Page3 extends AppCompatActivity {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
findViewById(R.id.P3_0).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_1).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_2).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_3).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_4).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_5).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_6).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_7).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_8).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3_9).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3BK).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3X).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3Plus).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3Minus).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3Div).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3Dot).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3CE).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3ChengFang).setOnClickListener(new CalculateOnClickListener());
findViewById(R.id.P3Result).setOnClickListener(new CalculateOnClickListener());
}
class CalculateOnClickListener implements View.OnClickListener{
@Override
public void onClick(View v){
TextView tv = findViewById(R.id.P3CalcResult);
String s = tv.getText().toString();
String o = ((Button)v).getText().toString();
switch (o){
case "退格":
if (!s.isEmpty()){
s = s.substring(0,s.length()-1);
}
break;
case "CE":
s = "";
break;
case "=":
calc();
return;
default:
s += o;
}
tv.setText(s);
}
}
private void calc(){
TextView textView = findViewById(R.id.P3Result);
String result = Kaculate(textView.getText().toString(),this);
textView.setText(result);
}
}

View file

@ -7,4 +7,195 @@
android:layout_height="match_parent"
tools:context=".Page3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="35dp" />
<TextView
android:id="@+id/P3CalcName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/kaculate"
android:textSize="40sp"/>
<TextView
android:id="@+id/P3CalcResult"
android:layout_width="match_parent"
android:layout_height="400dp"
android:text="" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="4"
android:rowCount="5">
<Button
android:id="@+id/P3CE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:text="CE" />
<Button
android:id="@+id/P3Div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="1"
android:text="/" />
<Button
android:id="@+id/P3X"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="2"
android:text="x" />
<Button
android:id="@+id/P3Nextpage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="3"
android:text="@string/next_page" />
<Button
android:id="@+id/P3_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="0"
android:text="7" />
<Button
android:id="@+id/P3_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="1"
android:text="8" />
<Button
android:id="@+id/P3_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="2"
android:text="9" />
<Button
android:id="@+id/P3Plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_column="3"
android:text="+" />
<Button
android:id="@+id/P3_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="0"
android:text="4" />
<Button
android:id="@+id/P3_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="1"
android:text="5" />
<Button
android:id="@+id/P3_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="2"
android:text="6" />
<Button
android:id="@+id/P3Minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_column="3"
android:text="-" />
<Button
android:id="@+id/P3_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="0"
android:text="1" />
<Button
android:id="@+id/P3_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="1"
android:text="2" />
<Button
android:id="@+id/P3_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="2"
android:text="3" />
<Button
android:id="@+id/P3ChengFang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_column="3"
android:text="^" />
<Button
android:id="@+id/P3BK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="0"
android:text="@string/Backspace" />
<Button
android:id="@+id/P3_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="1"
android:text="0" />
<Button
android:id="@+id/P3Dot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="2"
android:text="." />
<Button
android:id="@+id/P3Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_column="3"
android:text="=" />
</GridLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -7,4 +7,6 @@
<string name="set_color">设置颜色</string>
<string name="set">设置</string>
<string name="setText">设置文本</string>
<string name="kaculate">Kaculate</string>
<string name="Backspace">退格</string>
</resources>