Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.viewpager">

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
package="com.example.lenovo.notes">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
Expand All @@ -20,14 +16,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NumberFragment" />
<!--Registered the Activity -->
<activity
android:name=".LoginActivityFragment"
android:label="@string/title_activity_login" />
<activity android:name=".PharaseFragment" />
<activity android:name=".ColorFragment" />
<activity android:name=".FamilyFragment" />
<activity android:name=".NewsFragment"></activity>
android:name=".AddNote"
android:label="Add a Note"
android:parentActivityName=".MainActivity"/>
</application>

</manifest>
93 changes: 93 additions & 0 deletions main/java/com/example/lenovo/notes/AddNote.java
Original file line number Diff line number Diff line change
@@ -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<String>();

} 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) {

}
}
149 changes: 149 additions & 0 deletions main/java/com/example/lenovo/notes/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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<String> notes = new ArrayList<>();
static ArrayAdapter arrayAdapter;
static Set<String> 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<String>();
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<String>();

} 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<String>();

} 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);
}
}

34 changes: 34 additions & 0 deletions main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
Loading