initial commit

This commit is contained in:
minhtrannhat 2023-09-14 22:18:25 -04:00
parent 3d9f175ce0
commit b167a0a0cb
Signed by: minhtrannhat
GPG Key ID: E13CFA85C53F8062
9 changed files with 248 additions and 21 deletions

View File

@ -10,10 +10,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Assignment1"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
tools:targetApi="31">
<activity
android:name=".dataActivity"
android:parentActivityName=".MainActivity"
android:exported="false" />
<activity
android:name=".SettingsActivity"
android:parentActivityName=".MainActivity"
android:exported="false" />
<activity
android:name=".MainActivity"

View File

@ -9,9 +9,9 @@ import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
protected EventButtonSharedPreferenceHelper firstEventButton;
protected EventButtonSharedPreferenceHelper secondEventButton;
protected EventButtonSharedPreferenceHelper thirdEventButton;
protected CounterButtonSharedPreferenceHelper firstEventButton;
protected CounterButtonSharedPreferenceHelper secondEventButton;
protected CounterButtonSharedPreferenceHelper thirdEventButton;
protected Button settingsButton = null;
@ -22,9 +22,9 @@ public class MainActivity extends AppCompatActivity {
settingsButton = findViewById(R.id.settings_button);
firstEventButton = new EventButtonSharedPreferenceHelper(MainActivity.this, EventButton.FIRST);
secondEventButton = new EventButtonSharedPreferenceHelper(MainActivity.this, EventButton.SECOND);
thirdEventButton = new EventButtonSharedPreferenceHelper(MainActivity.this, EventButton.THIRD);
firstEventButton = new CounterButtonSharedPreferenceHelper(MainActivity.this, CounterButton.FIRST);
secondEventButton = new CounterButtonSharedPreferenceHelper(MainActivity.this, CounterButton.SECOND);
thirdEventButton = new CounterButtonSharedPreferenceHelper(MainActivity.this, CounterButton.THIRD);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -35,14 +35,15 @@ public class MainActivity extends AppCompatActivity {
});
}
@Override
protected void onStart()
{
super.onStart();
if(
firstEventButton.getEventButtonName(EventButton.FIRST) == null ||
secondEventButton.getEventButtonName(EventButton.SECOND) == null ||
thirdEventButton.getEventButtonName(EventButton.THIRD) == null) {
firstEventButton.getCounterButtonName(CounterButton.FIRST) == null ||
secondEventButton.getCounterButtonName(CounterButton.SECOND) == null ||
thirdEventButton.getCounterButtonName(CounterButton.THIRD) == null) {
goToSettingsActivity();
}

View File

@ -1,14 +1,70 @@
package com.example.assignment1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
public class SettingsActivity extends AppCompatActivity {
protected Button saveButton;
protected Toolbar myToolbar;
protected CounterButtonSharedPreferenceHelper firstEventButton;
protected CounterButtonSharedPreferenceHelper secondEventButton;
protected CounterButtonSharedPreferenceHelper thirdEventButton;
protected EditText counter_1_name_edit_text;
protected EditText counter_2_name_edit_text;
protected EditText counter_3_name_edit_text;
protected EditText maximum_counts_edit_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
myToolbar = (Toolbar) findViewById(R.id.settings_toolbar);
saveButton = (Button) findViewById(R.id.saveButton);
counter_1_name_edit_text = (EditText) findViewById(R.id.counter_1_edit_text);
counter_2_name_edit_text = (EditText) findViewById(R.id.counter_2_edit_text);
counter_3_name_edit_text = (EditText) findViewById(R.id.counter_3_edit_text);
maximum_counts_edit_text = (EditText) findViewById(R.id.maximum_counts_edit_text);
firstEventButton = new CounterButtonSharedPreferenceHelper(SettingsActivity.this, CounterButton.FIRST);
secondEventButton = new CounterButtonSharedPreferenceHelper(SettingsActivity.this, CounterButton.SECOND);
thirdEventButton = new CounterButtonSharedPreferenceHelper(SettingsActivity.this, CounterButton.THIRD);
// enable toolbar/actionbar
setSupportActionBar(myToolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //show back button
// no save button in Display Mode
saveButton.setVisibility(View.INVISIBLE);
// in DISPLAY mode, it's not possible to edit counter button names
counter_1_name_edit_text.setEnabled(false);
counter_2_name_edit_text.setEnabled(false);
counter_3_name_edit_text.setEnabled(false);
maximum_counts_edit_text.setEnabled(false);
}
@Override
protected void onStart()
{
super.onStart();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.settings_activity_menu, menu);
return true;
}
}

View File

@ -0,0 +1,14 @@
package com.example.assignment1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class dataActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data);
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".dataActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -29,7 +29,7 @@
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_marginBottom="20dp"
android:text="@string/FirstEventButton"
android:text="@string/counter_1_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -39,7 +39,7 @@
android:id="@+id/SecondEventButton"
android:layout_width="150dp"
android:layout_height="60dp"
android:text="@string/SecondEventButton"
android:text="@string/counter_2_name"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -50,7 +50,7 @@
android:id="@+id/ThirdEventButton"
android:layout_width="150dp"
android:layout_height="60dp"
android:text="@string/ThirdEventButton"
android:text="@string/counter_3_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

@ -1,9 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingsActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- Action Bar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
<!-- Content Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:orientation="vertical"
android:layout_gravity="center">
<!-- Text Views -->
<TextView
android:id="@+id/counter_1_text_view"
android:layout_width="200dp"
android:layout_height="50dp"
android:textSize="24sp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="16dp"
android:text="@string/counter_1_string" />
<EditText
android:id="@+id/counter_1_edit_text"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:hint="@string/counter_1_name"
android:inputType="text"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="200dp"
android:layout_height="50dp"
android:textSize="24sp"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:text="@string/counter_2_string" />
<EditText
android:id="@+id/counter_2_edit_text"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:hint="@string/counter_2_name"
android:inputType="text"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="200dp"
android:layout_height="50dp"
android:textSize="24sp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="16dp"
android:text="@string/counter_3_string" />
<EditText
android:id="@+id/counter_3_edit_text"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:hint="@string/counter_3_name"
android:inputType="text"
/>
<TextView
android:id="@+id/maximum_counts_text_view"
android:layout_width="200dp"
android:layout_height="50dp"
android:textSize="24sp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="16dp"
android:text="@string/maximum_counts_text" />
<EditText
android:id="@+id/maximum_counts_edit_text"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="50dp"
android:layout_width="200dp"
android:digits="0123456789"
android:hint="@string/maximum_counts"
android:inputType="number"
/>
</LinearLayout>
<!-- Save Button -->
<Button
android:id="@+id/saveButton"
android:layout_width="200dp"
android:layout_height="60dp"
android:textSize="24sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:text="@string/save_button_string" />
</RelativeLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/edit_settings"
android:title="@string/edit_settings" />
</menu>

View File

@ -1,10 +1,17 @@
<resources>
<string name="app_name">assignment1</string>
<string name="settings_btn_string">SETTINGS</string>
<string name="FirstEventButton"></string>
<string name="SecondEventButton"></string>
<string name="ThirdEventButton"></string>
<string name="counter_1_name"/>
<string name="counter_2_name"/>
<string name="counter_3_name"/>
<string name="total_count_text_view_string">Total Count:</string>
<string name="total_count_number_text_view_string">0</string>
<string name="show_my_counts_btn_string">SHOW MY COUNTS</string>
<string name="edit_settings">Edit Settings</string>
<string name="counter_3_string">Counter 3 Name</string>
<string name="counter_2_string">Counter 2 Name</string>
<string name="counter_1_string">Counter 1 Name</string>
<string name="save_button_string">Save</string>
<string name="maximum_counts_text">Maximum Counts</string>
<string name="maximum_counts"/>
</resources>