-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daf2a11
commit 31a638a
Showing
10 changed files
with
241 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
55 changes: 55 additions & 0 deletions
55
...h Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteEditorActivity.java
This file contains 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,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<String> set= new HashSet<>(NoteStartActivity.notes); | ||
sharedPreferences.edit().putStringSet("notes",set).apply(); | ||
|
||
} | ||
|
||
@Override | ||
public void afterTextChanged(Editable editable) { | ||
|
||
} | ||
}); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...th Calculator complete/app/src/main/java/com/example/bmrcalculator/NoteStartActivity.java
This file contains 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,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<String> arrayAdapter; | ||
static ArrayList<String > 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<String> set = (HashSet<String>) 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<String> 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; | ||
} | ||
}); | ||
|
||
} | ||
} |
Binary file added
BIN
+10.8 KB
...myaguglani/Health Calculator complete/app/src/main/res/drawable/note_taking.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
16 changes: 16 additions & 0 deletions
16
.../Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_editor.xml
This file contains 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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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" | ||
android:orientation="vertical" | ||
tools:context=".NoteEditorActivity"> | ||
<EditText | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:inputType="textMultiLine" | ||
android:gravity="top" | ||
android:id="@+id/et_inputnote"/> | ||
|
||
</LinearLayout> |
19 changes: 19 additions & 0 deletions
19
...r/Somyaguglani/Health Calculator complete/app/src/main/res/layout/activity_note_start.xml
This file contains 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,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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" | ||
android:orientation="vertical" | ||
|
||
tools:context=".MainActivity"> | ||
|
||
<ListView | ||
|
||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/lv_listview"> | ||
|
||
</ListView> | ||
|
||
</LinearLayout> |
9 changes: 9 additions & 0 deletions
9
...Calculator/Somyaguglani/Health Calculator complete/app/src/main/res/menu/add_new_menu.xml
This file contains 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"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:id="@+id/add_note" | ||
android:title="@string/add"> | ||
|
||
</item> | ||
|
||
</menu> |
This file contains 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