Skip to content

Commit 629ac20

Browse files
committed
Merge pull request #120 from ParsePlatform/grantland.widget_sample
Add ParseUI-Widget-Sample
2 parents 7b1a6a0 + 2b6ddaa commit 629ac20

File tree

25 files changed

+380
-4
lines changed

25 files changed

+380
-4
lines changed

ParseUI-Widget-Sample/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
6+
7+
defaultConfig {
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
10+
applicationId "com.parse.ui.widget.sample"
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile 'com.android.support:appcompat-v7:23.1.1'
24+
compile project(':ParseUI-Widget')
25+
26+
testCompile 'junit:junit:4.12'
27+
}
Lines changed: 17 additions & 0 deletions
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 /usr/local/opt/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+
#}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.parse.ui.widget.sample"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
8+
<application
9+
android:name=".MyApplication"
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<meta-data
16+
android:name="com.parse.APPLICATION_ID"
17+
android:value="@string/parse_app_id" />
18+
<meta-data
19+
android:name="com.parse.CLIENT_KEY"
20+
android:value="@string/parse_client_key" />
21+
22+
<activity
23+
android:name=".MainActivity">
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN"/>
26+
27+
<category android:name="android.intent.category.LAUNCHER"/>
28+
</intent-filter>
29+
</activity>
30+
31+
<activity
32+
android:name=".ListActivity"
33+
android:label="@string/list_name"/>
34+
</application>
35+
36+
</manifest>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.parse.ui.widget.sample;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.widget.ListView;
7+
import android.widget.Toast;
8+
9+
import com.parse.ParseException;
10+
import com.parse.ParseObject;
11+
import com.parse.ParseQuery;
12+
import com.parse.ParseQueryAdapter;
13+
14+
import java.util.List;
15+
16+
17+
public class ListActivity extends AppCompatActivity {
18+
19+
@Override
20+
protected void onCreate(@Nullable Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_list);
23+
24+
ListView listView = (ListView) findViewById(R.id.list);
25+
26+
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<>(this,
27+
new ParseQueryAdapter.QueryFactory<ParseObject>() {
28+
@Override
29+
public ParseQuery<ParseObject> create() {
30+
return ParseQuery.getQuery("Contact")
31+
.orderByAscending("name")
32+
.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
33+
}
34+
}, android.R.layout.simple_list_item_1);
35+
adapter.setTextKey("name");
36+
adapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<ParseObject>() {
37+
@Override
38+
public void onLoading() {
39+
40+
}
41+
42+
@Override
43+
public void onLoaded(List<ParseObject> objects, Exception e) {
44+
if (e != null
45+
&& e instanceof ParseException
46+
&& ((ParseException) e).getCode() != ParseException.CACHE_MISS) {
47+
Toast.makeText(ListActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
48+
}
49+
}
50+
});
51+
listView.setAdapter(adapter);
52+
}
53+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.parse.ui.widget.sample;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
8+
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
15+
findViewById(R.id.sample_list).setOnClickListener(this);
16+
}
17+
18+
//region OnClickListener
19+
20+
@Override
21+
public void onClick(View v) {
22+
int id = v.getId();
23+
switch (id) {
24+
case R.id.sample_list: {
25+
Intent intent = new Intent(this, ListActivity.class);
26+
startActivity(intent);
27+
break;
28+
}
29+
}
30+
}
31+
32+
//endregion
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.parse.ui.widget.sample;
2+
3+
import android.app.Application;
4+
5+
import com.parse.Parse;
6+
7+
public class MyApplication extends Application {
8+
9+
@Override
10+
public void onCreate() {
11+
super.onCreate();
12+
13+
Parse.initialize(this);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<ListView
7+
android:id="@+id/list"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"/>
10+
</FrameLayout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:paddingBottom="@dimen/activity_vertical_margin"
8+
android:paddingLeft="@dimen/activity_horizontal_margin"
9+
android:paddingRight="@dimen/activity_horizontal_margin"
10+
android:paddingTop="@dimen/activity_vertical_margin"
11+
android:orientation="vertical"
12+
tools:context="com.parse.ui.widget.sample.MainActivity">
13+
14+
<Button
15+
android:id="@+id/sample_list"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:text="@string/list_name"/>
19+
</LinearLayout>
Loading
Loading

0 commit comments

Comments
 (0)