-
-
Notifications
You must be signed in to change notification settings - Fork 322
Add ParseUI-Widget-Sample #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
applicationId "com.parse.ui.widget.sample" | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile project(':ParseUI-Widget') | ||
|
||
testCompile 'junit:junit:4.12' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.parse.ui.widget.sample" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:name=".MyApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<meta-data | ||
android:name="com.parse.APPLICATION_ID" | ||
android:value="@string/parse_app_id" /> | ||
<meta-data | ||
android:name="com.parse.CLIENT_KEY" | ||
android:value="@string/parse_client_key" /> | ||
|
||
<activity | ||
android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".ListActivity" | ||
android:label="@string/list_name"/> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.parse.ui.widget.sample; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.ListView; | ||
import android.widget.Toast; | ||
|
||
import com.parse.ParseException; | ||
import com.parse.ParseObject; | ||
import com.parse.ParseQuery; | ||
import com.parse.ParseQueryAdapter; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class ListActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_list); | ||
|
||
ListView listView = (ListView) findViewById(R.id.list); | ||
|
||
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<>(this, | ||
new ParseQueryAdapter.QueryFactory<ParseObject>() { | ||
@Override | ||
public ParseQuery<ParseObject> create() { | ||
return ParseQuery.getQuery("Contact") | ||
.orderByAscending("name") | ||
.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK); | ||
} | ||
}, android.R.layout.simple_list_item_1); | ||
adapter.setTextKey("name"); | ||
adapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<ParseObject>() { | ||
@Override | ||
public void onLoading() { | ||
|
||
} | ||
|
||
@Override | ||
public void onLoaded(List<ParseObject> objects, Exception e) { | ||
if (e != null | ||
&& e instanceof ParseException | ||
&& ((ParseException) e).getCode() != ParseException.CACHE_MISS) { | ||
Toast.makeText(ListActivity.this, "Error: " + e.getMessage(), Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
}); | ||
listView.setAdapter(adapter); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.parse.ui.widget.sample; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
findViewById(R.id.sample_list).setOnClickListener(this); | ||
} | ||
|
||
//region OnClickListener | ||
|
||
@Override | ||
public void onClick(View v) { | ||
int id = v.getId(); | ||
switch (id) { | ||
case R.id.sample_list: { | ||
Intent intent = new Intent(this, ListActivity.class); | ||
startActivity(intent); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
//endregion | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.parse.ui.widget.sample; | ||
|
||
import android.app.Application; | ||
|
||
import com.parse.Parse; | ||
|
||
public class MyApplication extends Application { | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
Parse.initialize(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<ListView | ||
android:id="@+id/list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
</FrameLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:orientation="vertical" | ||
tools:context="com.parse.ui.widget.sample.MainActivity"> | ||
|
||
<Button | ||
android:id="@+id/sample_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/list_name"/> | ||
</LinearLayout> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="parse_app_id">YOUR_PARSE_APP_ID</string> | ||
<string name="parse_client_key">YOUR_PARSE_CLIENT_KEY</string> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<string name="app_name">ParseUI-Widget Sample</string> | ||
<string name="list_name">ListView Sample</string> | ||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# bootstrap.js | ||
|
||
Bootstraps a Parse application to be used with the samples in this repository. | ||
|
||
# Requirements | ||
|
||
* [Node.js](https://nodejs.org) | ||
|
||
## Usage | ||
|
||
1. Add your keys to `config.js` | ||
2. `npm install` | ||
3. `npm bootstrap.js` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var https = require('https'); | ||
var Parse = require('parse/node'); | ||
var Promise = require('promise'); | ||
var config = require('./config'); | ||
|
||
Parse.initialize(config.parse.appId, config.parse.jsKey); | ||
|
||
var count = 100; | ||
var className = "Contact"; | ||
|
||
var args = process.argv.slice(2); | ||
if (args >= 1) { | ||
count = args[0]; | ||
} | ||
if (args >= 2) { | ||
className = args[1]; | ||
} | ||
|
||
function toTitleCase(str) | ||
{ | ||
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); | ||
} | ||
|
||
console.log('Creating ' + count + ' ' + className + ' objects'); | ||
new Promise(function(resolve, reject) { | ||
var options = { | ||
hostname: 'randomuser.me', | ||
path: '/api/?results=' + count | ||
} | ||
var req = https.request(options, function(res) { | ||
res.setEncoding('utf8'); | ||
var data = ''; | ||
res.on('data', function(chunk) { | ||
data += chunk; | ||
}); | ||
res.on('end', function() { | ||
try { | ||
resolve(JSON.parse(data)); | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
}); | ||
}); | ||
req.end(); | ||
}).then(function(json) { | ||
var objects = json.results.map(function(result) { | ||
var object = new Parse.Object(className); | ||
object.set('name', toTitleCase(result.user.name.first + ' ' + result.user.name.last)); | ||
return object; | ||
}); | ||
|
||
return Parse.Object.saveAll(objects); | ||
}).then(function(result) { | ||
console.log('done'); | ||
}, function(error) { | ||
console.log('error: ' + error); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var config = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no reason, do you prefer that way more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a JSON format is more easy to read, but I do not have a strong preference, up to you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave it as is for now, since it's accessed via the dot format that it's defined. |
||
|
||
config.parse = {}; | ||
config.parse.appId = 'YOUR_PARSE_APP_ID'; | ||
config.parse.jsKey = 'YOUR_PARSE_JS_KEY'; | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "bootstrap", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "bootstrap.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Grantland Chew", | ||
"license": "Platform License", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wangmengyan95 change was done here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
"dependencies": { | ||
"parse": "^1.6.13", | ||
"promise": "^7.1.1" | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the min node version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hrmm this was automatically generated for me. what does the syntax look like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax is "engines": {
"node": ">=XXX"
} Since you do not use es6 feature, probably just check the libraries you use and choose the min version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add min node version here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my current node is v4.2.3, should i put that or something more generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you can use
>= XXX
in youpackage.json
and add explantation here.