diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index f3e54db..2aa75e4 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -1,16 +1,12 @@ - - - - - + package="com.example.lenovo.notes"> @@ -20,14 +16,11 @@ - + - - - - + android:name=".AddNote" + android:label="Add a Note" + android:parentActivityName=".MainActivity"/> \ No newline at end of file diff --git a/main/java/com/example/lenovo/notes/AddNote.java b/main/java/com/example/lenovo/notes/AddNote.java new file mode 100644 index 0000000..bcf383c --- /dev/null +++ b/main/java/com/example/lenovo/notes/AddNote.java @@ -0,0 +1,93 @@ +package com.example.lenovo.notes; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.EditText; + +import java.util.HashSet; + +/** + * The Project Notes is Created by Rohan on 5/10/2018. + */ +public class AddNote extends AppCompatActivity implements TextWatcher { + int noteId; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.add_note); + + EditText editText = (EditText) findViewById(R.id.editText); + + Intent i = getIntent(); + noteId = i.getIntExtra("noteId", -1); + + if (noteId != -1) { + + editText.setText(MainActivity.notes.get(noteId)); + } + + editText.addTextChangedListener( this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_add_note, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //Noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + MainActivity.notes.set(noteId, String.valueOf(s)); + MainActivity.arrayAdapter.notifyDataSetChanged(); + + SharedPreferences sharedPreferences = getSharedPreferences("com.example.lenovo.notes", Context.MODE_PRIVATE); + + if (MainActivity.set == null) { + + MainActivity.set = new HashSet(); + + } else { + + MainActivity.set.clear(); + + } + + MainActivity.set.addAll(MainActivity.notes); + sharedPreferences.edit().remove("notes").apply(); + sharedPreferences.edit().putStringSet("notes", MainActivity.set).apply(); + } + + @Override + public void afterTextChanged(Editable s) { + + } +} \ No newline at end of file diff --git a/main/java/com/example/lenovo/notes/MainActivity.java b/main/java/com/example/lenovo/notes/MainActivity.java new file mode 100644 index 0000000..c256e2a --- /dev/null +++ b/main/java/com/example/lenovo/notes/MainActivity.java @@ -0,0 +1,149 @@ +package com.example.lenovo.notes; + +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.support.v7.app.AppCompatActivity; +import android.view.Menu; +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; +import java.util.Set; + +public class MainActivity extends AppCompatActivity { + + //Declaration + static ArrayList notes = new ArrayList<>(); + static ArrayAdapter arrayAdapter; + static Set set; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Declaring listview and SharedPreferences + ListView listView = (ListView) findViewById(R.id.listView); + + SharedPreferences sharedPreferences = this.getSharedPreferences("com.example.lenovo.notes", Context.MODE_PRIVATE); + + set = sharedPreferences.getStringSet("notes", null); + notes.clear(); + + if (set != null) { + + notes.addAll(set); + } else { + + notes.add("Example note"); + set = new HashSet(); + set.addAll(notes); + sharedPreferences.edit().putStringSet("notes", set).apply(); + } + + 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 parent, View view, int position, long id) { + + Intent i = new Intent(getApplicationContext(), AddNote.class); + i.putExtra("noteId", position); + startActivity(i); + } + }); + + listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { + new AlertDialog.Builder(MainActivity.this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("Are you sure?") + .setMessage("Do you want to delete this note?") + .setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + notes.remove(position); + SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("com.example.lenovo.notes", Context.MODE_PRIVATE); + + if (set == null) { + + set = new HashSet(); + + } else { + + set.clear(); + + } + set.addAll(notes); + sharedPreferences.edit().remove("notes").apply(); + sharedPreferences.edit().putStringSet("notes", set).apply(); + arrayAdapter.notifyDataSetChanged(); + + } + }) + .setNegativeButton("No", null) + .show(); + return true; + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //Noinspection SimplifiableIfStatement + if (id == R.id.add) { + + notes.add(""); + + SharedPreferences sharedPreferences = this.getSharedPreferences("com.example.robpercival.notes", + Context.MODE_PRIVATE); + + if (set == null) { + + set = new HashSet(); + + } else { + + set.clear(); + } + + set.addAll(notes); + arrayAdapter.notifyDataSetChanged(); + + sharedPreferences.edit().remove("notes").apply(); + sharedPreferences.edit().putStringSet("notes", set).apply(); + + Intent i = new Intent(getApplicationContext(), AddNote.class); + i.putExtra("noteId", notes.size() - 1); + startActivity(i); + return true; + } + return super.onOptionsItemSelected(item); + } +} + diff --git a/main/res/drawable-v24/ic_launcher_foreground.xml b/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..ddb26ad --- /dev/null +++ b/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/main/res/drawable/ic_launcher_background.xml b/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..3a37cf6 --- /dev/null +++ b/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/res/layout/activity_main.xml b/main/res/layout/activity_main.xml index b7d06e3..c674402 100644 --- a/main/res/layout/activity_main.xml +++ b/main/res/layout/activity_main.xml @@ -1,22 +1,17 @@ - - - + + - - - + android:id="@+id/listView" + android:layout_alignParentStart="true" + android:layout_alignParentTop="true" + android:layout_alignParentLeft="true" /> - + \ No newline at end of file diff --git a/main/res/layout/add_note.xml b/main/res/layout/add_note.xml new file mode 100644 index 0000000..96962a5 --- /dev/null +++ b/main/res/layout/add_note.xml @@ -0,0 +1,18 @@ + + + + + \ No newline at end of file diff --git a/main/res/menu/menu_add_note.xml b/main/res/menu/menu_add_note.xml new file mode 100644 index 0000000..cc48db3 --- /dev/null +++ b/main/res/menu/menu_add_note.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/main/res/menu/menu_main.xml b/main/res/menu/menu_main.xml new file mode 100644 index 0000000..be44e4e --- /dev/null +++ b/main/res/menu/menu_main.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/main/res/mipmap-anydpi-v26/ic_launcher.xml b/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..a26f6fb --- /dev/null +++ b/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..a26f6fb --- /dev/null +++ b/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/main/res/mipmap-hdpi/ic_launcher.png b/main/res/mipmap-hdpi/ic_launcher.png index cde69bc..a2f5908 100644 Binary files a/main/res/mipmap-hdpi/ic_launcher.png and b/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/main/res/mipmap-hdpi/ic_launcher_round.png b/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..1b52399 Binary files /dev/null and b/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-mdpi/ic_launcher.png b/main/res/mipmap-mdpi/ic_launcher.png index c133a0c..ff10afd 100644 Binary files a/main/res/mipmap-mdpi/ic_launcher.png and b/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/main/res/mipmap-mdpi/ic_launcher_round.png b/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..115a4c7 Binary files /dev/null and b/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xhdpi/ic_launcher.png b/main/res/mipmap-xhdpi/ic_launcher.png index bfa42f0..dcd3cd8 100644 Binary files a/main/res/mipmap-xhdpi/ic_launcher.png and b/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xhdpi/ic_launcher_round.png b/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..459ca60 Binary files /dev/null and b/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xxhdpi/ic_launcher.png b/main/res/mipmap-xxhdpi/ic_launcher.png index 324e72c..8ca12fe 100644 Binary files a/main/res/mipmap-xxhdpi/ic_launcher.png and b/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxhdpi/ic_launcher_round.png b/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..8e19b41 Binary files /dev/null and b/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/main/res/mipmap-xxxhdpi/ic_launcher.png b/main/res/mipmap-xxxhdpi/ic_launcher.png index aee44e1..b824ebd 100644 Binary files a/main/res/mipmap-xxxhdpi/ic_launcher.png and b/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..4c19a13 Binary files /dev/null and b/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index 1a0a9b1..72199a4 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -1,17 +1,3 @@ - View Pager - Sign in - - - Email - Password (optional) - Sign in or register - Sign in - This email address is invalid - This password is too short - This password is incorrect - This field is required - "Contacts permissions are needed for providing email - completions." - + Notes diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml new file mode 100644 index 0000000..6f19b47 --- /dev/null +++ b/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + +