diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/AndroidManifest.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/AndroidManifest.xml
index 0e8c68b4..b44d76d5 100644
--- a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/AndroidManifest.xml
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/AndroidManifest.xml
@@ -9,16 +9,18 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
\ No newline at end of file
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java
index d0762537..34e8c326 100644
--- a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java
@@ -11,7 +11,7 @@
public class ChoosingActivity extends AppCompatActivity {
- ImageButton bmi,bmr;
+ ImageButton bmi,bmr,takenotes;
@Override
@@ -42,6 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
bmi= findViewById(R.id.imbtn_bmi);
bmr = findViewById(R.id.imbtn_bmr);
+ takenotes = findViewById(R.id.imbtn_bmi_takenotes);
bmi.setOnClickListener(new View.OnClickListener() {
@Override
@@ -57,6 +58,14 @@ public void onClick(View view) {
startActivity(i);
}
});
+ takenotes.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent i = new Intent(ChoosingActivity.this,NoteStartActivity.class);
+ startActivity(i);
+
+ }
+ });
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteEditorActivity.java b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteEditorActivity.java
new file mode 100644
index 00000000..a89460e1
--- /dev/null
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteEditorActivity.java
@@ -0,0 +1,55 @@
+package com.example.bmrcalculator;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.EditText;
+
+import java.util.HashSet;
+
+public class NoteEditorActivity extends AppCompatActivity {
+
+ int noteId;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_note_editor);
+
+ EditText editText= findViewById(R.id.et_inputnote);
+ noteId = getIntent().getIntExtra("noteId",-1);//imp since indexing starts from 0 this checks for something invalid
+ if(noteId!=-1){
+ editText.setText(NoteStartActivity.notes.get(noteId));
+ }else{
+ NoteStartActivity.notes.add("");
+ noteId= NoteStartActivity.notes.size()-1;
+ NoteStartActivity.arrayAdapter.notifyDataSetChanged();
+
+ }
+ editText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+ NoteStartActivity.notes.set(noteId,String.valueOf(charSequence));
+ NoteStartActivity.arrayAdapter.notifyDataSetChanged();
+
+ SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
+ HashSet set= new HashSet<>(NoteStartActivity.notes);
+ sharedPreferences.edit().putStringSet("notes",set).apply();
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+
+ }
+ });
+ }
+}
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteStartActivity.java b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteStartActivity.java
new file mode 100644
index 00000000..4162467e
--- /dev/null
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteStartActivity.java
@@ -0,0 +1,111 @@
+package com.example.bmrcalculator;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+public class NoteStartActivity extends AppCompatActivity {
+ ListView listView;
+
+ static ArrayAdapter arrayAdapter;
+ static ArrayList notes = new ArrayList<>();
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater menuInflater = getMenuInflater();
+ menuInflater.inflate(R.menu.add_new_menu,menu);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ super.onOptionsItemSelected(item);
+ if(item.getItemId()==R.id.add_note){
+ Intent intent = new Intent(getApplicationContext(),NoteEditorActivity.class);
+ startActivity(intent);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ listView= findViewById(R.id.lv_listview);//use ..toi save space we don't want duplicates //new concept learn
+ SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
+ HashSet set = (HashSet) sharedPreferences.getStringSet("notes",null);
+
+ if(set==null)
+ notes.add("Example note");
+ else
+ notes = new ArrayList<>(set);
+
+
+ arrayAdapter= new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1,
+ notes);
+
+ listView.setAdapter(arrayAdapter);
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
+ Intent intent= new Intent(getApplicationContext(),NoteEditorActivity.class);
+ intent.putExtra("noteId",i);
+ startActivity(intent);
+ }
+ });
+
+
+ listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView> adapterView, View view, int i, long l) {
+
+ final int item_to_delete = i;
+ new AlertDialog.Builder( NoteStartActivity.this)
+ .setCancelable(false)
+ .setTitle("Are yiou sure?")
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage("Do you want to delete this note?")
+ .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ notes.remove(item_to_delete);
+ arrayAdapter.notifyDataSetChanged();
+
+ SharedPreferences sharedPreferences= getApplicationContext().getSharedPreferences("com.example.bmrcalculator", Context.MODE_PRIVATE);
+ HashSet set= new HashSet<>(NoteStartActivity.notes);
+ sharedPreferences.edit().putStringSet("notes",set).apply();
+ }
+ })
+ .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+
+ }
+ })
+ .show();
+
+
+ return true;
+ }
+ });
+
+ }
+}
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/drawable/note_taking.jpg b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/drawable/note_taking.jpg
new file mode 100644
index 00000000..f7d8b2e7
Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/drawable/note_taking.jpg differ
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_choosing.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_choosing.xml
index 7b89056c..c32b4b98 100644
--- a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_choosing.xml
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_choosing.xml
@@ -24,9 +24,17 @@
android:layout_width="137dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
- android:layout_marginTop="130dp"
+ android:layout_marginTop="30dp"
android:src="@drawable/bmi_pic" />
+
+
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_editor.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_editor.xml
new file mode 100644
index 00000000..fb148433
--- /dev/null
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_editor.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_start.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_start.xml
new file mode 100644
index 00000000..22508e8a
--- /dev/null
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_start.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/menu/add_new_menu.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/menu/add_new_menu.xml
new file mode 100644
index 00000000..d7834c5e
--- /dev/null
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/menu/add_new_menu.xml
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/values/strings.xml b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/values/strings.xml
index 68b751fa..31dca1f9 100644
--- a/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/values/strings.xml
+++ b/P02_HealthCalculator/Somyaguglani/Health Calculator complete/app/src/main/res/values/strings.xml
@@ -16,4 +16,6 @@
Severe Underweight
Moderate weight
BODY FAT PERCENTAGE IS
+ add_note
+ Add note