Skip to content

Commit 8888227

Browse files
committed
Add example module, which shows usage of SDK
1 parent 5eaaab0 commit 8888227

File tree

16 files changed

+252
-0
lines changed

16 files changed

+252
-0
lines changed

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/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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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.Menu;
10+
import android.view.MenuItem;
11+
import android.view.View;
12+
import android.widget.Toast;
13+
14+
import com.google.common.eventbus.Subscribe;
15+
16+
import jp.studyplus.android.sdk.service.api.ApiRequest;
17+
import jp.studyplus.android.sdk.service.api.ApiRequestListener;
18+
import jp.studyplus.android.sdk.service.api.StudyplusApi;
19+
import jp.studyplus.android.sdk.service.api.response.ErrorResponse;
20+
import jp.studyplus.android.sdk.service.api.response.SuccessfulResponse;
21+
import jp.studyplus.android.sdk.service.auth.AuthTransit;
22+
import jp.studyplus.android.sdk.service.auth.CertificationStore;
23+
import jp.studyplus.android.sdk.service.studyrecord.StudyRecordBuilder;
24+
import jp.studyplus.android.sdk.service.studyrecord.StudyRecordPostRequest;
25+
26+
import static android.view.View.OnClickListener;
27+
28+
public class ExampleActivity extends ActionBarActivity {
29+
30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.activity_example);
34+
35+
findViewById(R.id.start_auth)
36+
.setOnClickListener(new OnClickToAuth(this));
37+
38+
findViewById(R.id.post_study_record)
39+
.setOnClickListener(new OnClickToPost(this));
40+
}
41+
42+
@Override
43+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
44+
CertificationStore.create(this).update(data);
45+
}
46+
47+
private static class OnClickToPost implements OnClickListener, ApiRequestListener {
48+
private final Context context;
49+
50+
private OnClickToPost(Context context) {
51+
this.context = context;
52+
}
53+
@Override
54+
public void onClick(View v) {
55+
ApiRequest request = StudyRecordPostRequest.of(
56+
new StudyRecordBuilder()
57+
.setComment("勉強した!!!")
58+
.setAmountTotal(30)
59+
.setDurationSeconds(2 * 60)
60+
.build());
61+
62+
StudyplusApi.getClient(context).send(request.with(this));
63+
}
64+
65+
@Subscribe
66+
public void showMessage(SuccessfulResponse response){
67+
Toast.makeText(context, "投稿完了!", Toast.LENGTH_SHORT).show();
68+
}
69+
@Subscribe
70+
public void showError(ErrorResponse response){
71+
Log.e(OnClickToPost.class.getName(), "response:" + response.getStatusCode());
72+
}
73+
@Subscribe
74+
public void showException(Exception e){
75+
e.printStackTrace();
76+
}
77+
}
78+
79+
private static class OnClickToAuth implements OnClickListener {
80+
private final Activity activity;
81+
private final Context context;
82+
83+
private OnClickToAuth(Activity activity) {
84+
this.activity = activity;
85+
this.context = activity.getApplicationContext();
86+
}
87+
@Override
88+
public void onClick(View v) {
89+
AuthTransit.from(activity).startActivity(
90+
context.getString(R.string.sample_consumer_key),
91+
context.getString(R.string.sample_consumer_key_secret)
92+
);
93+
}
94+
}
95+
96+
@Override
97+
public boolean onCreateOptionsMenu(Menu menu) {
98+
99+
// Inflate the menu; this adds items to the action bar if it is present.
100+
getMenuInflater().inflate(R.menu.example, menu);
101+
return true;
102+
}
103+
104+
@Override
105+
public boolean onOptionsItemSelected(MenuItem item) {
106+
// Handle action bar item clicks here. The action bar will
107+
// automatically handle clicks on the Home/Up button, so long
108+
// as you specify a parent activity in AndroidManifest.xml.
109+
int id = item.getItemId();
110+
if (id == R.id.action_settings) {
111+
return true;
112+
}
113+
return super.onOptionsItemSelected(item);
114+
}
115+
116+
}
7.6 KB
Loading
3.67 KB
Loading
12.1 KB
Loading
24.2 KB
Loading

0 commit comments

Comments
 (0)