Skip to content

Commit 886db76

Browse files
committed
Initial commit
0 parents  commit 886db76

38 files changed

+1490
-0
lines changed

.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### Android ###
2+
# Built application files
3+
*.apk
4+
*.ap_
5+
6+
# Files for the Dalvik VM
7+
*.dex
8+
9+
# Java class files
10+
*.class
11+
12+
# Generated files
13+
bin/
14+
gen/
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+
27+
### Intellij ###
28+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
29+
30+
## Directory-based project format
31+
.idea/
32+
# if you remove the above rule, at least ignore user-specific stuff:
33+
# .idea/workspace.xml
34+
# .idea/tasks.xml
35+
# and these sensitive or high-churn files:
36+
# .idea/dataSources.ids
37+
# .idea/dataSources.xml
38+
# .idea/sqlDataSources.xml
39+
# .idea/dynamic.xml
40+
41+
## File-based project format
42+
*.ipr
43+
*.iws
44+
*.iml
45+
46+
## Additional for IntelliJ
47+
out/
48+
49+
# generated by mpeltonen/sbt-idea plugin
50+
.idea_modules/
51+
52+
# generated by JIRA plugin
53+
atlassian-ide-plugin.xml
54+
55+
# generated by Crashlytics plugin (for Android Studio and Intellij)
56+
com_crashlytics_export_strings.xml
57+

app/.gitignore

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

app/build.gradle

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:1.1.1'
7+
}
8+
}
9+
apply plugin: 'com.android.application'
10+
11+
repositories {
12+
jcenter()
13+
}
14+
15+
android {
16+
compileSdkVersion 22
17+
buildToolsVersion "22.0.1"
18+
19+
defaultConfig {
20+
applicationId "com.dd.realmsample"
21+
minSdkVersion 14
22+
targetSdkVersion 22
23+
versionCode 1
24+
versionName "1.0"
25+
}
26+
buildTypes {
27+
release {
28+
minifyEnabled false
29+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30+
}
31+
}
32+
}
33+
34+
dependencies {
35+
compile fileTree(dir: 'libs', include: ['*.jar'])
36+
compile 'com.android.support:appcompat-v7:22.1.1'
37+
compile 'io.realm:realm-android:0.80.1'
38+
compile project(':realm-browser')
39+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:/Work/Android/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+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.dd.realmsample;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.dd.realmsample" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/title"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name=".MainActivity"
12+
android:label="@string/title" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.dd.realmsample;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
import com.dd.realmbrowser.RealmBrowser;
9+
import com.dd.realmbrowser.RealmFilesActivity;
10+
import com.dd.realmbrowser.RealmModelsActivity;
11+
import io.realm.Realm;
12+
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
16+
public class MainActivity extends Activity implements View.OnClickListener {
17+
18+
public static final String REALM_FILE_NAME = "db7";
19+
private TextView mTxtTitle;
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
setContentView(R.layout.activity_main);
25+
26+
RealmBrowser.getInstance().getRealmModelList().add(User.class);
27+
28+
mTxtTitle = (TextView) findViewById(R.id.txtTitle);
29+
findViewById(R.id.btnInsert).setOnClickListener(this);
30+
findViewById(R.id.btnRemove).setOnClickListener(this);
31+
findViewById(R.id.btnOpenFile).setOnClickListener(this);
32+
findViewById(R.id.btnOpenModel).setOnClickListener(this);
33+
34+
updateTitle();
35+
}
36+
37+
@Override
38+
public void onClick(View v) {
39+
switch (v.getId()) {
40+
case R.id.btnInsert:
41+
insertUsers(100);
42+
updateTitle();
43+
break;
44+
case R.id.btnRemove:
45+
removeAllUsers();
46+
updateTitle();
47+
break;
48+
case R.id.btnOpenFile:
49+
startRealmFilesActivity();
50+
break;
51+
case R.id.btnOpenModel:
52+
startRealmModelsActivity();
53+
break;
54+
}
55+
}
56+
57+
private void updateTitle() {
58+
Realm realm = Realm.getInstance(getApplicationContext(), REALM_FILE_NAME);
59+
int size = realm.allObjects(User.class).size();
60+
mTxtTitle.setText(String.format("Items in database: %d", size));
61+
realm.close();
62+
}
63+
64+
private void removeAllUsers() {
65+
Realm realm = Realm.getInstance(getApplicationContext(), REALM_FILE_NAME);
66+
67+
realm.executeTransaction(new Realm.Transaction() {
68+
@Override
69+
public void execute(Realm realm) {
70+
realm.clear(User.class);
71+
}
72+
});
73+
74+
realm.close();
75+
}
76+
77+
private void insertUsers(int count) {
78+
Realm realm = Realm.getInstance(getApplicationContext(), REALM_FILE_NAME);
79+
80+
final List<User> userList = new ArrayList<>();
81+
for (int i = 0; i < count; i++) {
82+
User user = new User();
83+
user.setName("Jon Doe " + i);
84+
user.setIsBlocked(Math.random() > 0.5);
85+
user.setAge(i);
86+
user.setLat(49.8397473);
87+
user.setLon(24.0233077);
88+
userList.add(user);
89+
}
90+
91+
realm.executeTransaction(new Realm.Transaction() {
92+
@Override
93+
public void execute(Realm realm) {
94+
realm.copyToRealm(userList);
95+
}
96+
});
97+
98+
realm.close();
99+
}
100+
101+
private void startRealmFilesActivity() {
102+
Intent intent = new Intent(this, RealmFilesActivity.class);
103+
startActivity(intent);
104+
}
105+
106+
private void startRealmModelsActivity() {
107+
RealmModelsActivity.start(this, REALM_FILE_NAME);
108+
}
109+
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.dd.realmsample;
2+
3+
import io.realm.RealmObject;
4+
5+
public class User extends RealmObject {
6+
7+
private String name;
8+
private boolean isBlocked;
9+
private int age;
10+
private double lat;
11+
private double lon;
12+
13+
public double getLat() {
14+
return lat;
15+
}
16+
17+
public void setLat(double lat) {
18+
this.lat = lat;
19+
}
20+
21+
public double getLon() {
22+
return lon;
23+
}
24+
25+
public void setLon(double lon) {
26+
this.lon = lon;
27+
}
28+
29+
public String getName() {
30+
return name;
31+
}
32+
33+
public void setName(String name) {
34+
this.name = name;
35+
}
36+
37+
public int getAge() {
38+
return age;
39+
}
40+
41+
public void setAge(int age) {
42+
this.age = age;
43+
}
44+
45+
public boolean isBlocked() {
46+
return isBlocked;
47+
}
48+
49+
public void setIsBlocked(boolean isBlocked) {
50+
this.isBlocked = isBlocked;
51+
}
52+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:gravity="center"
7+
tools:context="${relativePackage}.${activityClass}">
8+
9+
<TextView
10+
android:id="@+id/txtTitle"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
tools:text="Items in database: 100"/>
14+
15+
<Button
16+
android:id="@+id/btnInsert"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:text="@string/Insert_users"/>
20+
21+
<Button
22+
android:id="@+id/btnRemove"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:text="@string/Clear_database"/>
26+
27+
<Button
28+
android:id="@+id/btnOpenFile"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:text="@string/Open_file_list"/>
32+
33+
<Button
34+
android:id="@+id/btnOpenModel"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:text="@string/Open_model_list"/>
38+
39+
40+
</LinearLayout>
3.34 KB
Loading
2.15 KB
Loading
4.73 KB
Loading
7.54 KB
Loading

app/src/main/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
<string name="app_name">Realm Sample</string>
3+
<string name="hello_world">Hello world!</string>
4+
<string name="Insert_users">Insert 100 Users</string>
5+
<string name="Clear_database">Clear database</string>
6+
<string name="Open_file_list">Open file list</string>
7+
<string name="Open_model_list">Open model list</string>
8+
</resources>

app/src/main/res/values/styles.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
</style>
7+
8+
</resources>

build.gradle

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:1.1.1'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
jcenter()
18+
}
19+
}

0 commit comments

Comments
 (0)