Skip to content

Commit 9e8ba80

Browse files
committed
Merge pull request #1 from studyplus/prepare
Add Studyplus SDK and its usage example
2 parents 0f965e8 + 7c65260 commit 9e8ba80

File tree

65 files changed

+1305
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1305
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gradle
2+
gradle.properties
3+
/local.properties
4+
5+
/.idea/workspace.xml
6+
*.iml
7+
.idea
8+
9+
*.tmp
10+
.DS_Store

SDKExample/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
*.development.xml

SDKExample/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apply plugin: 'android'
2+
3+
android {
4+
compileSdkVersion 18
5+
buildToolsVersion "19.0.1"
6+
7+
defaultConfig {
8+
minSdkVersion 8
9+
targetSdkVersion 16
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
signingConfigs {
14+
release {
15+
storeFile file(project.properties.storeFile)
16+
storePassword project.properties.storePassword
17+
keyAlias project.properties.storeAlias
18+
keyPassword project.properties.keyPassword
19+
}
20+
}
21+
buildTypes {
22+
release {
23+
debuggable false
24+
signingConfig signingConfigs.release
25+
runProguard true
26+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
27+
}
28+
}
29+
productFlavors {
30+
production {
31+
packageName 'jp.studyplus.android.sdk.example'
32+
}
33+
development {
34+
packageName 'jp.studyplus.android.sdk.example.dev'
35+
}
36+
}
37+
}
38+
39+
dependencies {
40+
compile 'com.android.support:appcompat-v7:19.0.1'
41+
compile 'com.google.code.findbugs:jsr305:1.3.9'
42+
compile project(':StudyplusAndroidSDK')
43+
}

SDKExample/gradle.properties.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
storeFile=__your_value__
2+
storeAlias=__your_value__
3+
storePassword=__your_value__
4+
keyPassword=__your_value__

SDKExample/proguard-rules.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
-keepclassmembers class * {
3+
@com.google.common.eventbus.Subscribe *;
4+
}
5+
6+
-dontwarn sun.misc.Unsafe
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="jp.studyplus.android.sdk.example" >
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@drawable/ic_launcher"
10+
android:label="@string/app_name"
11+
android:theme="@style/AppTheme" >
12+
<activity
13+
android:name="jp.studyplus.android.sdk.example.ExampleActivity"
14+
android:label="@string/app_name" >
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
46 KB
Loading
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package jp.studyplus.android.sdk.example;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.support.v7.app.ActionBarActivity;
8+
import android.util.Log;
9+
import android.view.View;
10+
import android.widget.Toast;
11+
12+
import com.google.common.eventbus.Subscribe;
13+
14+
import jp.studyplus.android.sdk.service.api.ApiRequest;
15+
import jp.studyplus.android.sdk.service.api.ApiRequestListener;
16+
import jp.studyplus.android.sdk.service.api.StudyplusApi;
17+
import jp.studyplus.android.sdk.service.api.response.ErrorResponse;
18+
import jp.studyplus.android.sdk.service.api.response.SuccessfulResponse;
19+
import jp.studyplus.android.sdk.service.auth.AuthTransit;
20+
import jp.studyplus.android.sdk.service.auth.CertificationStore;
21+
import jp.studyplus.android.sdk.service.studyrecord.StudyRecordBuilder;
22+
import jp.studyplus.android.sdk.service.studyrecord.StudyRecordPostRequest;
23+
24+
import static android.view.View.OnClickListener;
25+
26+
public class ExampleActivity extends ActionBarActivity {
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.activity_example);
32+
33+
findViewById(R.id.start_auth)
34+
.setOnClickListener(new OnClickToAuth(this));
35+
36+
findViewById(R.id.post_study_record)
37+
.setOnClickListener(new OnClickToPost(this));
38+
}
39+
40+
@Override
41+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
42+
CertificationStore.create(this).update(data);
43+
}
44+
45+
private static class OnClickToPost implements OnClickListener, ApiRequestListener {
46+
private final Context context;
47+
48+
private OnClickToPost(Context context) {
49+
this.context = context;
50+
}
51+
@Override
52+
public void onClick(View v) {
53+
ApiRequest request = StudyRecordPostRequest.of(
54+
new StudyRecordBuilder()
55+
.setComment("勉強した!!!")
56+
.setAmountTotal(30)
57+
.setDurationSeconds(2 * 60)
58+
.build());
59+
60+
StudyplusApi.getClient(context).send(request.with(this));
61+
}
62+
63+
@Subscribe
64+
public void showMessage(SuccessfulResponse response){
65+
Toast.makeText(context, "投稿完了!", Toast.LENGTH_SHORT).show();
66+
}
67+
@Subscribe
68+
public void showError(ErrorResponse response){
69+
Log.e(OnClickToPost.class.getName(), "response:" + response.getStatusCode());
70+
}
71+
@Subscribe
72+
public void showException(Exception e){
73+
e.printStackTrace();
74+
}
75+
}
76+
77+
private static class OnClickToAuth implements OnClickListener {
78+
private final Activity activity;
79+
private final Context context;
80+
81+
private OnClickToAuth(Activity activity) {
82+
this.activity = activity;
83+
this.context = activity.getApplicationContext();
84+
}
85+
@Override
86+
public void onClick(View v) {
87+
AuthTransit.from(activity).startActivity(
88+
context.getString(R.string.sample_consumer_key),
89+
context.getString(R.string.sample_consumer_key_secret)
90+
);
91+
}
92+
}
93+
94+
}
7.6 KB
Loading
3.67 KB
Loading

0 commit comments

Comments
 (0)