Skip to content

Commit db550e6

Browse files
committed
Initial sample test app
1 parent 4a3d324 commit db550e6

18 files changed

+226
-0
lines changed

Example/src/main/AndroidManifest.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.parse.example" xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
6+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
8+
android:supportsRtl="true" android:theme="@style/AppTheme">
9+
<activity android:name=".MainActivity">
10+
<intent-filter>
11+
<action android:name="android.intent.action.MAIN" />
12+
13+
<category android:name="android.intent.category.LAUNCHER" />
14+
</intent-filter>
15+
</activity>
16+
</application>
17+
18+
</manifest>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.parse.example;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.util.Log;
6+
7+
import com.parse.GetCallback;
8+
import com.parse.Parse;
9+
import com.parse.ParseException;
10+
import com.parse.ParseLiveQueryClient;
11+
import com.parse.ParseObject;
12+
import com.parse.ParseQuery;
13+
import com.parse.SubscriptionHandling;
14+
import com.parse.interceptors.ParseLogInterceptor;
15+
16+
import java.net.URI;
17+
import java.net.URISyntaxException;
18+
19+
public class MainActivity extends AppCompatActivity {
20+
21+
String URL = "http://192.168.3.9:1337/parse/";
22+
String wsURL = "ws://192.168.3.9:1337/parse/";
23+
String applicationId = "mytest";
24+
String DEBUG_TAG = "debug";
25+
26+
Room mRoom;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_main);
32+
33+
ParseObject.registerSubclass(Room.class);
34+
ParseObject.registerSubclass(Message.class);
35+
36+
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
37+
Parse.initialize(new Parse.Configuration.Builder(this)
38+
.applicationId(applicationId) // should correspond to APP_ID env variable
39+
.clientKey("clientKey") // set explicitly blank unless clientKey is configured on Parse server
40+
.addNetworkInterceptor(new ParseLogInterceptor())
41+
.server(URL).build());
42+
43+
ParseQuery<Room> roomParseQuery = ParseQuery.getQuery(Room.class);
44+
// fixme - why isn't it retrieving
45+
roomParseQuery.whereEqualTo("name", "test");
46+
roomParseQuery.getFirstInBackground(new GetCallback<Room>() {
47+
@Override
48+
public void done(Room room, ParseException e) {
49+
if (e != null) {
50+
Log.d(DEBUG_TAG, "Found exception" + e);
51+
e.printStackTrace();
52+
} else {
53+
Log.d(DEBUG_TAG, "Found room: " + room);
54+
}
55+
mRoom = room;
56+
57+
ParseLiveQueryClient<Message> parseLiveQueryClient = null;
58+
59+
try {
60+
parseLiveQueryClient
61+
= ParseLiveQueryClient.Factory.getClient(new URI(wsURL));
62+
} catch (URISyntaxException uriException) {
63+
Log.d(DEBUG_TAG, "Could not connect");
64+
65+
}
66+
67+
if (parseLiveQueryClient != null) {
68+
// op=subscribe, className=Message, roomName=test, requestId=1
69+
// op=subscribe, className=Message, roomName=null, requestId=1, order=createdAt
70+
ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
71+
// FIXME
72+
parseQuery.whereEqualTo("roomName", "test");
73+
74+
// FIXME (rhu) - parse query hates created at
75+
// parseQuery.orderByAscending("createdAt");
76+
77+
SubscriptionHandling<Message> subscriptionHandling = parseLiveQueryClient
78+
.subscribe(parseQuery);
79+
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE,
80+
new SubscriptionHandling.HandleEventCallback<Message>() {
81+
@Override
82+
public void onEvent(ParseQuery<Message> query, Message object) {
83+
Log.d(DEBUG_TAG, "Message" + object);
84+
}
85+
});
86+
}
87+
}
88+
});
89+
90+
91+
}
92+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.parse.example;
2+
3+
4+
import com.parse.ParseClassName;
5+
import com.parse.ParseObject;
6+
import com.parse.ParseUser;
7+
8+
@ParseClassName("Message")
9+
public class Message extends ParseObject {
10+
11+
ParseUser parseUser;
12+
String authorName;
13+
String message;
14+
Room room;
15+
16+
public Message() {
17+
18+
}
19+
20+
public ParseUser getParseUser() {
21+
return parseUser;
22+
}
23+
24+
public void setParseUser(ParseUser parseUser) {
25+
this.parseUser = parseUser;
26+
}
27+
28+
public String getAuthorName() {
29+
return authorName;
30+
}
31+
32+
public void setAuthorName(String authorName) {
33+
this.authorName = authorName;
34+
}
35+
36+
public String getMessage() {
37+
return message;
38+
}
39+
40+
public void setMessage(String message) {
41+
this.message = message;
42+
}
43+
44+
public Room getRoom() {
45+
return room;
46+
}
47+
48+
public void setRoom(Room room) {
49+
this.room = room;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return String.format("objectId=%s: message=%s room=%s", getObjectId(), getMessage(), getRoom());
55+
}
56+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.parse.example;
2+
3+
import com.parse.ParseClassName;
4+
import com.parse.ParseObject;
5+
6+
@ParseClassName("Room")
7+
public class Room extends ParseObject {
8+
9+
public Room() {
10+
11+
}
12+
13+
String name;
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return String.format("objectId=%s: name=%s", getObjectId(), getName());
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
6+
android:layout_height="match_parent" tools:context="com.parse.example.MainActivity">
7+
8+
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
9+
android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent"
10+
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"
11+
app:layout_constraintTop_toTopOf="parent" />
12+
13+
</android.support.constraint.ConstraintLayout>
3.34 KB
Loading
Loading
2.15 KB
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Example</string>
3+
</resources>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
10+
11+
</resources>

0 commit comments

Comments
 (0)