Commit 7cbcf7845c6ec7aa4f0cb12e7ed38e81e8e6beb9

Authored by 赵康
1 parent f60c7c1fb6
Exists in master

add sample project

Showing 22 changed files with 400 additions and 0 deletions Inline Diff

File was created 1 CohesiveSDKSample/bin
2 CohesiveSDKSample/gen
CohesiveSDKSample/.classpath
File was created 1 <?xml version="1.0" encoding="UTF-8"?>
2 <classpath>
3 <classpathentry kind="src" path="src"/>
4 <classpathentry kind="src" path="gen"/>
5 <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6 <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7 <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8 <classpathentry kind="output" path="bin/classes"/>
9 </classpath>
10
CohesiveSDKSample/.project
File was created 1 <?xml version="1.0" encoding="UTF-8"?>
2 <projectDescription>
3 <name>CohesiveSDKSample</name>
4 <comment></comment>
5 <projects>
6 </projects>
7 <buildSpec>
8 <buildCommand>
9 <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10 <arguments>
11 </arguments>
12 </buildCommand>
13 <buildCommand>
14 <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15 <arguments>
16 </arguments>
17 </buildCommand>
18 <buildCommand>
19 <name>org.eclipse.jdt.core.javabuilder</name>
20 <arguments>
21 </arguments>
22 </buildCommand>
23 <buildCommand>
24 <name>com.android.ide.eclipse.adt.ApkBuilder</name>
25 <arguments>
26 </arguments>
27 </buildCommand>
28 </buildSpec>
29 <natures>
30 <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31 <nature>org.eclipse.jdt.core.javanature</nature>
32 </natures>
33 </projectDescription>
34
CohesiveSDKSample/AndroidManifest.xml
File was created 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.tencent.tmgp.testgump"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="21" />
10
11 <uses-permission android:name="android.permission.BLUETOOTH" />
12 <uses-permission android:name="android.permission.WRITE_SETTINGS" />
13 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
14 <uses-permission android:name="android.permission.INTERNET" />
15 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
16
17 <application
18 android:name="com.gump.cohesivesdk.sample.MyApplication"
19 android:allowBackup="true"
20 android:icon="@drawable/ic_launcher"
21 android:label="@string/app_name" >
22 <activity
23 android:name="com.gump.cohesivesdk.sample.MainActivity"
24 android:label="@string/app_name" >
25 </activity>
26 <activity android:name="com.gump.cohesivesdk.sample.MySplashActivity" >
27 <intent-filter>
28 <action android:name="android.intent.action.MAIN" />
29
30 <category android:name="android.intent.category.LAUNCHER" />
31 </intent-filter>
32 </activity>
33 </application>
34
35 </manifest>
CohesiveSDKSample/assets/cohesive.conf
File was created 1 {
2 "ChannelId":"100700",
3 "MainClass":"PJ",
4 "CAId":"1267",
5 "CAKey":"Nf4cl66bcnlJ2taJ5i9guRdaokriRJJp",
6 "CASecret":"Nf4cl66bcnlJ2taJ5i9guRdaokriRJJp"
7 }
8
CohesiveSDKSample/libs/CohesiveSDK.jar
No preview for this file type
CohesiveSDKSample/proguard-project.txt
File was created 1 # To enable ProGuard in your project, edit project.properties
2 # to define the proguard.config property as described in that file.
3 #
4 # Add project specific ProGuard rules here.
5 # By default, the flags in this file are appended to flags specified
6 # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 # You can edit the include path and order by changing the ProGuard
8 # include property in project.properties.
9 #
10 # For more details, see
11 # http://developer.android.com/guide/developing/tools/proguard.html
12
13 # Add any project specific keep options here:
14
15 # If your project uses WebView with JS, uncomment the following
16 # and specify the fully qualified class name to the JavaScript interface
17 # class:
18 #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 # public *;
20 #}
21
CohesiveSDKSample/project.properties
File was created 1 # This file is automatically generated by Android Tools.
2 # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 #
4 # This file must be checked in Version Control Systems.
5 #
6 # To customize properties used by the Ant build system edit
7 # "ant.properties", and override values to adapt the script to your
8 # project structure.
9 #
10 # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12
13 # Project target.
14 target=android-19
15
CohesiveSDKSample/res/drawable-hdpi/ic_launcher.png

9.18 KB

CohesiveSDKSample/res/drawable-hdpi/sample_yuanbao.png

4.85 KB

CohesiveSDKSample/res/drawable-mdpi/ic_launcher.png

5.11 KB

CohesiveSDKSample/res/drawable-xhdpi/ic_launcher.png

14 KB

CohesiveSDKSample/res/layout/activity_main.xml
File was created 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical"
6 android:paddingBottom="@dimen/activity_vertical_margin"
7 android:paddingLeft="@dimen/activity_horizontal_margin"
8 android:paddingRight="@dimen/activity_horizontal_margin"
9 android:paddingTop="@dimen/activity_vertical_margin"
10 tools:context="com.gump.cohesivesdk.sample.MainActivity" >
11
12 <TextView
13 android:id="@+id/info"
14 android:layout_width="match_parent"
15 android:layout_height="wrap_content"
16 android:gravity="center_horizontal" />
17
18 <Button
19 android:id="@+id/login"
20 android:layout_width="match_parent"
21 android:layout_height="wrap_content"
22 android:text="login" />
23
24 <Button
25 android:id="@+id/pay"
26 android:layout_width="match_parent"
27 android:layout_height="wrap_content"
28 android:layout_below="@id/login"
29 android:text="pay" />
30
31 </LinearLayout>
CohesiveSDKSample/res/values-v11/styles.xml
File was created 1 <resources>
2
3
4 </resources>
5
CohesiveSDKSample/res/values-v14/styles.xml
File was created 1 <resources>
2
3
4 </resources>
5
CohesiveSDKSample/res/values-w820dp/dimens.xml
File was created 1 <resources>
2
3 <!--
4 Example customization of dimensions originally defined in res/values/dimens.xml
5 (such as screen margins) for screens with more than 820dp of available width. This
6 would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
7 -->
8 <dimen name="activity_horizontal_margin">64dp</dimen>
9
10 </resources>
11
CohesiveSDKSample/res/values/dimens.xml
File was created 1 <resources>
2
3 <!-- Default screen margins, per the Android Design guidelines. -->
4 <dimen name="activity_horizontal_margin">16dp</dimen>
5 <dimen name="activity_vertical_margin">16dp</dimen>
6
7 </resources>
8
CohesiveSDKSample/res/values/strings.xml
File was created 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3
4 <string name="app_name">CohesiveSDKSample</string>
5 </resources>
6
CohesiveSDKSample/res/values/styles.xml
File was created 1 <resources>
2
3
4 </resources>
5
CohesiveSDKSample/src/com/gump/cohesivesdk/sample/MainActivity.java
File was created 1 package com.gump.cohesivesdk.sample;
2
3 import android.app.Activity;
4 import android.app.ProgressDialog;
5 import android.content.Intent;
6 import android.os.Bundle;
7 import android.util.Log;
8 import android.view.View;
9 import android.widget.Button;
10 import android.widget.TextView;
11
12 import com.gump.cohesivesdk.CohesiveApi;
13 import com.gump.cohesivesdk.callback.ExitCallback;
14 import com.gump.cohesivesdk.callback.InitialCallback;
15 import com.gump.cohesivesdk.callback.PaymentListener;
16 import com.gump.cohesivesdk.callback.UserStateListener;
17 import com.gump.cohesivesdk.model.GPUser;
18 import com.gump.cohesivesdk.model.Payment;
19 import com.tencent.tmgp.testgump.R;
20
21 public class MainActivity extends Activity implements UserStateListener {
22 private static final String TAG = "MainActivity";
23
24 CohesiveApi cohesiveApi;
25 private Button btnLogin;
26 private Button btnPay;
27 private TextView tvInfo;
28 private boolean isLogin = false;
29
30 private ProgressDialog prog;
31
32 @Override
33 protected void onCreate(Bundle savedInstanceState) {
34 super.onCreate(savedInstanceState);
35 setContentView(R.layout.activity_main);
36
37 CohesiveApi.setDebugging(true);
38 cohesiveApi = CohesiveApi.build(this);
39 cohesiveApi.onCreate(this, getIntent());
40 cohesiveApi.init(this, "1002", new InitialCallback() {
41
42 @Override
43 public void onInitComplete(int result) {
44 Log.d(TAG, "sdk init completed result:" + result);
45 if (result == 0)
46 setListeners();
47 }
48 });
49 cohesiveApi.setUserListener(this);
50 btnLogin = (Button) findViewById(R.id.login);
51 btnPay = (Button) findViewById(R.id.pay);
52 tvInfo = (TextView) findViewById(R.id.info);
53 tvInfo.setText("SDK Version:" + CohesiveApi.getVersion());
54 }
55
56 private void setListeners() {
57 btnLogin.setOnClickListener(new View.OnClickListener() {
58
59 @Override
60 public void onClick(View v) {
61 prog = ProgressDialog.show(MainActivity.this, "", isLogin ? "正在注销" : "正在登录");
62 if (isLogin)
63 cohesiveApi.logout(MainActivity.this);
64 else
65 cohesiveApi.login(MainActivity.this);
66 }
67 });
68 btnPay.setOnClickListener(new View.OnClickListener() {
69
70 @Override
71 public void onClick(View v) {
72 Bundle payinfo = new Bundle();
73 payinfo.putString("orderId", System.currentTimeMillis() + "");
74 payinfo.putString("product", "coin");
75 payinfo.putString("extra", "buy 10 coins");
76 payinfo.putLong("amount", 1);
77 cohesiveApi.goPay(MainActivity.this, payinfo, new PaymentListener() {
78
79 @Override
80 public void onPaySuccess(Payment arg0) {
81 Log.i(TAG, arg0.toString());
82 }
83
84 @Override
85 public void onPayError(int code) {
86 Log.i(TAG, "pay Error:" + code);
87 }
88 });
89 }
90 });
91 }
92
93 @Override
94 public void onBackPressed() {
95 cohesiveApi.exit(this, new ExitCallback() {
96
97 @Override
98 public void onNo3rdExiterProvide() {
99 // 退出窗口需要游戏自定义,并且实现资源回收,杀死进程等退出逻辑
100 // TODO 实现退出窗口
101 cohesiveApi.appDestroy(MainActivity.this);
102 MainActivity.super.onBackPressed();
103 }
104
105 @Override
106 public void onExit() {
107 // 退出窗口由渠道提供,游戏只须实现资源回收,杀死进程等退出逻辑
108 cohesiveApi.appDestroy(MainActivity.this);
109 // 调用游戏退出逻辑
110 MainActivity.super.onBackPressed();
111 }
112 });
113 }
114
115 @Override
116 protected void onNewIntent(Intent intent) {
117 super.onNewIntent(intent);
118 cohesiveApi.onNewIntent(this, intent);
119 }
120
121 @Override
122 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
123 super.onActivityResult(requestCode, resultCode, data);
124 cohesiveApi.onActivityResult(requestCode, resultCode, data);
125 }
126
127 @Override
128 protected void onPause() {
129 super.onPause();
130 cohesiveApi.onPause(this);
131 }
132
133 @Override
134 protected void onResume() {
135 super.onResume();
136 cohesiveApi.onResume(this);
137 }
138
139 @Override
140 protected void onDestroy() {
141 super.onDestroy();
142 cohesiveApi.onDestroy(this);
143 }
144
145 @Override
146 protected void onRestart() {
147 super.onRestart();
148 cohesiveApi.onRestart(this);
149 }
150
151 @Override
152 protected void onStop() {
153 super.onStop();
154 cohesiveApi.onStop(this);
155 }
156
157 @Override
158 public void onLoginFailed(String arg0) {
159 Log.i(TAG, "Login Failed:" + arg0);
160 if (prog != null)
161 prog.cancel();
162 }
163
164 @Override
165 public void onLoginSuccess(GPUser arg0) {
166 Log.i(TAG, "Login success:" + arg0.toString());
167 btnLogin.setText("logout");
168 isLogin = true;
169 if (prog != null)
170 prog.cancel();
171 }
172
173 @Override
174 public void onLogout() {
175 Log.i(TAG, "logout");
176 btnLogin.setText("login");
177 isLogin = false;
178 if (prog != null)
179 prog.cancel();
180 }
181
182 }
183
CohesiveSDKSample/src/com/gump/cohesivesdk/sample/MyApplication.java
File was created 1 package com.gump.cohesivesdk.sample;
2
3 import com.gump.cohesivesdk.CohesiveApplication;
4
5 import android.content.Context;
6 import android.support.multidex.MultiDex;
7 import android.support.multidex.MultiDexApplication;
8
9 public class MyApplication extends CohesiveApplication {
10
11 // @Override
12 // protected void attachBaseContext(Context base) {
13 // super.attachBaseContext(base);
14 // MultiDex.install(this);
15 // }
16
17 }
18
CohesiveSDKSample/src/com/gump/cohesivesdk/sample/MySplashActivity.java
File was created 1 package com.gump.cohesivesdk.sample;
2
3 import android.content.Intent;
4
5 import com.gump.cohesivesdk.SplashActivity;
6
7 public class MySplashActivity extends SplashActivity {
8
9 @Override
10 public void onSplashStop() {
11 Intent intent = new Intent(this,MainActivity.class);
12 startActivity(intent);
13 finish();
14 }
15
16 }
17