Skip to content

Commit 5c385a2

Browse files
committed
initial commit
0 parents  commit 5c385a2

37 files changed

+780
-0
lines changed

.gitignore

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the ART/Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
out/
15+
16+
# Gradle files
17+
.gradle/
18+
build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
# Log Files
27+
*.log
28+
29+
# Android Studio Navigation editor temp files
30+
.navigation/
31+
32+
# Android Studio captures folder
33+
captures/
34+
35+
# Intellij
36+
*.iml
37+
.idea/workspace.xml
38+
.idea/libraries
39+
.idea/
40+
41+
# Keystore files
42+
*.jks
43+
44+
# External native build folder generated in Android Studio 2.2 and later
45+
.externalNativeBuild

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'realm-android'
3+
4+
android {
5+
compileSdkVersion 25
6+
buildToolsVersion "25.0.3"
7+
defaultConfig {
8+
applicationId "me.karishnu.simplenotes"
9+
minSdkVersion 19
10+
targetSdkVersion 25
11+
versionCode 1
12+
versionName "1.0"
13+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26+
exclude group: 'com.android.support', module: 'support-annotations'
27+
})
28+
compile 'com.android.support:appcompat-v7:25.3.1'
29+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
30+
compile 'com.android.support:design:25.3.1'
31+
compile 'com.github.thorbenprimke:realm-recyclerview:0.9.25'
32+
testCompile 'junit:junit:4.12'
33+
}

app/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Users\Karishnu Poddar\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package me.karishnu.simplenotes;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("me.karishnu.simplenotes", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="me.karishnu.simplenotes">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".MainActivity"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
<activity android:name=".CreateNoteActivity"></activity>
23+
</application>
24+
25+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.karishnu.simplenotes;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.Button;
7+
import android.widget.EditText;
8+
9+
import io.realm.Realm;
10+
11+
public class CreateNoteActivity extends AppCompatActivity {
12+
13+
EditText editText;
14+
Button button;
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
setContentView(R.layout.activity_create_note);
20+
21+
final Realm realm = Realm.getDefaultInstance();
22+
final Number currentIdNum = realm.where(Note.class).max("id");
23+
24+
editText = (EditText) findViewById(R.id.editText);
25+
button = (Button) findViewById(R.id.button);
26+
27+
button.setOnClickListener(new View.OnClickListener() {
28+
@Override
29+
public void onClick(View v) {
30+
String textToSave = editText.getText().toString();
31+
32+
Note note = new Note();
33+
note.setId(currentIdNum.intValue() + 1);
34+
note.setText(textToSave);
35+
36+
realm.beginTransaction();
37+
realm.copyToRealm(note);
38+
realm.commitTransaction();
39+
40+
finish();
41+
}
42+
});
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.karishnu.simplenotes;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.design.widget.FloatingActionButton;
6+
import android.support.design.widget.Snackbar;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.support.v7.widget.Toolbar;
9+
import android.view.View;
10+
import android.view.Menu;
11+
import android.view.MenuItem;
12+
13+
import co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView;
14+
import io.realm.Realm;
15+
import io.realm.RealmResults;
16+
import io.realm.Sort;
17+
18+
public class MainActivity extends AppCompatActivity {
19+
20+
private RealmRecyclerView realmRecyclerView;
21+
private NoteAdapter noteAdapter;
22+
private Realm realm;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_main);
28+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
29+
setSupportActionBar(toolbar);
30+
31+
Realm.init(this);
32+
33+
realmRecyclerView = (RealmRecyclerView) findViewById(R.id.rv);
34+
35+
realm = Realm.getDefaultInstance();
36+
37+
RealmResults<Note> notes = realm.where(Note.class).findAllSorted("id", Sort.DESCENDING);
38+
39+
noteAdapter = new NoteAdapter(this, notes);
40+
realmRecyclerView.setAdapter(noteAdapter);
41+
42+
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
43+
fab.setOnClickListener(new View.OnClickListener() {
44+
@Override
45+
public void onClick(View view) {
46+
Intent intent = new Intent(MainActivity.this, CreateNoteActivity.class);
47+
startActivity(intent);
48+
}
49+
});
50+
}
51+
52+
@Override
53+
public boolean onCreateOptionsMenu(Menu menu) {
54+
// Inflate the menu; this adds items to the action bar if it is present.
55+
getMenuInflater().inflate(R.menu.menu_main, menu);
56+
return true;
57+
}
58+
59+
@Override
60+
public boolean onOptionsItemSelected(MenuItem item) {
61+
// Handle action bar item clicks here. The action bar will
62+
// automatically handle clicks on the Home/Up button, so long
63+
// as you specify a parent activity in AndroidManifest.xml.
64+
int id = item.getItemId();
65+
66+
//noinspection SimplifiableIfStatement
67+
if (id == R.id.action_settings) {
68+
return true;
69+
}
70+
71+
return super.onOptionsItemSelected(item);
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package me.karishnu.simplenotes;
2+
3+
import io.realm.RealmObject;
4+
import io.realm.annotations.PrimaryKey;
5+
6+
public class Note extends RealmObject {
7+
@PrimaryKey
8+
private int id;
9+
private String text;
10+
11+
public String getText(){
12+
return text;
13+
}
14+
15+
public void setText(String text){
16+
this.text = text;
17+
}
18+
19+
public int getId(){
20+
return id;
21+
}
22+
23+
public void setId(int id){
24+
this.id = id;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package me.karishnu.simplenotes;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
import android.widget.TextView;
7+
8+
import io.realm.RealmBasedRecyclerViewAdapter;
9+
import io.realm.RealmResults;
10+
import io.realm.RealmViewHolder;
11+
12+
public class NoteAdapter extends RealmBasedRecyclerViewAdapter<Note, NoteAdapter.ViewHolder> {
13+
14+
public NoteAdapter(Context context, RealmResults<Note> realmResults) {
15+
super(context, realmResults, true, false, null);
16+
}
17+
18+
public class ViewHolder extends RealmViewHolder {
19+
20+
public TextView textView;
21+
22+
public ViewHolder(View view) {
23+
super(view);
24+
this.textView = (TextView) view.findViewById(R.id.textView);
25+
}
26+
}
27+
28+
@Override
29+
public ViewHolder onCreateRealmViewHolder(ViewGroup viewGroup, int viewType) {
30+
View v = inflater.inflate(R.layout.item_note, viewGroup, false);
31+
return new ViewHolder(v);
32+
}
33+
34+
@Override
35+
public void onBindRealmViewHolder(ViewHolder viewHolder, int position) {
36+
final Note note = realmResults.get(position);
37+
viewHolder.textView.setText(note.getText());
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context="me.karishnu.simplenotes.CreateNoteActivity"
7+
android:orientation="vertical">
8+
9+
<EditText
10+
android:id="@+id/editText"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:hint="Enter Note Here!"/>
14+
15+
<Button
16+
android:id="@+id/button"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:text="SAVE"/>
20+
21+
</LinearLayout>

0 commit comments

Comments
 (0)