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
Loading
Loading
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="parse_app_id">YOUR_PARSE_APP_ID</string>
4+
<string name="parse_client_key">YOUR_PARSE_CLIENT_KEY</string>
5+
</resources>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<resources>
2+
<string name="app_name">ParseUI-Widget Sample</string>
3+
<string name="list_name">ListView Sample</string>
4+
</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>

scripts/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
28+
node_modules
29+
30+
# Optional npm cache directory
31+
.npm
32+
33+
# Optional REPL history
34+
.node_repl_history
35+

scripts/bootstrap/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# bootstrap.js
2+
3+
Bootstraps a Parse application to be used with the samples in this repository.
4+
5+
# Requirements
6+
7+
* [Node.js](https://nodejs.org)
8+
9+
## Usage
10+
11+
1. Add your keys to `config.js`
12+
2. `npm install`
13+
3. `npm bootstrap.js`

scripts/bootstrap/bootstrap.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var https = require('https');
2+
var Parse = require('parse/node');
3+
var Promise = require('promise');
4+
var config = require('./config');
5+
6+
Parse.initialize(config.parse.appId, config.parse.jsKey);
7+
8+
var count = 100;
9+
var className = "Contact";
10+
11+
var args = process.argv.slice(2);
12+
if (args >= 1) {
13+
count = args[0];
14+
}
15+
if (args >= 2) {
16+
className = args[1];
17+
}
18+
19+
function toTitleCase(str)
20+
{
21+
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
22+
}
23+
24+
console.log('Creating ' + count + ' ' + className + ' objects');
25+
new Promise(function(resolve, reject) {
26+
var options = {
27+
hostname: 'randomuser.me',
28+
path: '/api/?results=' + count
29+
}
30+
var req = https.request(options, function(res) {
31+
res.setEncoding('utf8');
32+
var data = '';
33+
res.on('data', function(chunk) {
34+
data += chunk;
35+
});
36+
res.on('end', function() {
37+
try {
38+
resolve(JSON.parse(data));
39+
} catch (ex) {
40+
reject(ex);
41+
}
42+
});
43+
});
44+
req.end();
45+
}).then(function(json) {
46+
var objects = json.results.map(function(result) {
47+
var object = new Parse.Object(className);
48+
object.set('name', toTitleCase(result.user.name.first + ' ' + result.user.name.last));
49+
return object;
50+
});
51+
52+
return Parse.Object.saveAll(objects);
53+
}).then(function(result) {
54+
console.log('done');
55+
}, function(error) {
56+
console.log('error: ' + error);
57+
});

scripts/bootstrap/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var config = {};
2+
3+
config.parse = {};
4+
config.parse.appId = 'YOUR_PARSE_APP_ID';
5+
config.parse.jsKey = 'YOUR_PARSE_JS_KEY';
6+
7+
module.exports = config;

scripts/bootstrap/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "bootstrap",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "bootstrap.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Grantland Chew",
10+
"license": "Platform License",
11+
"engines": {
12+
"node": ">=4.0.0"
13+
},
14+
"dependencies": {
15+
"parse": "^1.6.13",
16+
"promise": "^7.1.1"
17+
}
18+
}

0 commit comments

Comments
 (0)