Commit f905cc4105f59921e7840dbd80421509955603fe

Authored by 赵康
1 parent 083363adac
Exists in master

SDK has update to 5.1.0

Showing 17 changed files with 768 additions and 63 deletions Side-by-side Diff

1 1 # Gump SDK 5 for Android接入文档
2 2  
3   -V5.0.0
4   -2018年11月02日
  3 +V5.1.0
  4 +2019年03月18日
5 5  
6 6 ## 版本概述
7 7  
... ... @@ -22,11 +22,11 @@ V5.0.0
22 22 }
23 23 dependencies {
24 24 //基础功能依赖,必须
25   - implementation 'com.gump:base:5.0.0'
  25 + implementation 'com.gump:base:5.1.0'
26 26 //登录功能依赖
27   - implementation 'com.gump:Passport:5.0.0'
  27 + implementation 'com.gump:Passport:5.1.0'
28 28 //支付功能依赖
29   - implementation 'com.gump:Payment:5.0.0'
  29 + implementation 'com.gump:Payment:5.1.0'
30 30 }
31 31  
32 32 ### 2.修改AndroidManifest.xml文件
... ... @@ -52,9 +52,6 @@ V5.0.0
52 52 android:value="@integer/google_play_services_version"/>
53 53  
54 54 ### 3.1 初始化与配置
55   -*横竖屏控制,默认为横屏,参数为false即为竖屏
56   -
57   - SDKAgent.getSettings().setScreenLandscape(true);
58 55  
59 56 *若要使用V4版支付请设置
60 57  
... ... @@ -65,6 +62,14 @@ V5.0.0
65 62 SDKAgent.init(Context,Appid,ChannelId);
66 63  
67 64 ### 3.2 登录接入
  65 +AndroidManifest.xml配置:
  66 +
  67 + <activity
  68 + android:name="com.gump.gpassport.GumpLoginActivity"
  69 + android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
  70 + android:launchMode="singleTask"
  71 + android:screenOrientation="behind"
  72 + android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
68 73 构建Passport实例
69 74  
70 75 passport = new Passport.Builder().context(Context).setListener(StateListener).build();
... ... @@ -92,13 +97,25 @@ V5.0.0
92 97 super.onActivityResult(requestCode, resultCode, data);
93 98 }
94 99  
95   -### 3.3 支付接入
  100 +### 3.3 账号绑定
  101 +
  102 + passport.link(Activity);
  103 +
  104 +### 3.4 账号切换
  105 +切换到系统账号
  106 +
  107 + passport.switchAccount(PlayerType.GamePlayer);
  108 +切换gump账号
  109 +
  110 + passport.switchAccount(PlayerType.GumpPlayer);
  111 +### 3.5 支付接入
96 112 注册相应的Activity,具体如下:
97 113  
98 114 <activity
99 115 android:name="com.gumptech.sdk.PaymentActivity"
100 116 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
101 117 android:launchMode="singleTask"
  118 + android:screenOrientation="behind"
102 119 android:theme="@android:style/Theme.Translucent.NoTitleBar" >
103 120 <intent-filter>
104 121 <category android:name="android.intent.category.DEFAULT" />
... ... @@ -5,11 +5,12 @@ android {
5 5 compileSdkVersion 27
6 6 defaultConfig {
7 7 applicationId "com.gump.passport.demo"
8   - minSdkVersion 14
  8 + minSdkVersion 15
9 9 targetSdkVersion 27
10   - versionCode 2
11   - versionName "1.0.1"
  10 + versionCode 9
  11 + versionName "1.0.9"
12 12 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  13 + vectorDrawables.useSupportLibrary = true
13 14 }
14 15 buildTypes {
15 16 release {
... ... @@ -33,15 +34,17 @@ android {
33 34 dependencies {
34 35 implementation fileTree(dir: 'libs', include: ['*.jar'])
35 36 implementation 'com.android.support:appcompat-v7:27.1.1'
  37 + implementation 'com.android.support:support-v4:27.1.1'
  38 + implementation 'com.android.support:support-vector-drawable:27.1.1'
36 39 testImplementation 'junit:junit:4.12'
37 40  
38 41 //基础功能依赖,必须
39   - implementation 'com.gump:base:5.0.0'
  42 + implementation 'com.gump:base:5.1.0'
40 43 // implementation project(':base')
41   - //登录功能依赖
42   - implementation 'com.gump:Passport:5.0.0'
  44 +// 登录功能依赖
  45 + implementation 'com.gump:Passport:5.1.0'
43 46 // implementation project(':passport')
44 47 //支付功能依赖
45   - implementation 'com.gump:Payment:5.0.0'
  48 + implementation 'com.gump:Payment:5.1.0'
46 49 // implementation project(':payment')
47 50 }
app/src/main/AndroidManifest.xml
... ... @@ -8,7 +8,9 @@
8 8  
9 9 <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
10 10 <uses-permission android:name="com.android.vending.BILLING"/>
  11 +
11 12 <application
  13 + android:name=".GameApplication"
12 14 android:allowBackup="true"
13 15 android:icon="@mipmap/ic_launcher"
14 16 android:label="@string/app_name"
... ... @@ -29,17 +31,17 @@
29 31 <category android:name="android.intent.category.LAUNCHER"/>
30 32 </intent-filter>
31 33 </activity>
32   -
33 34 <activity
34 35 android:name="com.gump.payment.PaymentActivity"
35 36 android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
  37 + android:screenOrientation="behind"
36 38 android:launchMode="singleTask"
37   - android:theme="@android:style/Theme.Light.NoTitleBar">
  39 + android:theme="@style/Theme.Translucent">
38 40 <intent-filter>
39   - <category android:name="android.intent.category.DEFAULT"/>
40   -
41 41 <action android:name="android.intent.action.VIEW"/>
42 42  
  43 + <category android:name="android.intent.category.DEFAULT"/>
  44 +
43 45 <category android:name="android.intent.category.BROWSABLE"/>
44 46  
45 47 <data
... ... @@ -47,6 +49,20 @@
47 49 android:scheme="gump100"/>
48 50 </intent-filter>
49 51 </activity>
  52 + <activity
  53 + android:name="com.gump.gpassport.GumpLoginActivity"
  54 + android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
  55 + android:launchMode="singleTask"
  56 + android:screenOrientation="behind"
  57 + android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
  58 + <activity
  59 + android:name=".SettingsActivity"
  60 + android:label="@string/title_activity_settings"
  61 + android:parentActivityName=".MainActivity">
  62 + <meta-data
  63 + android:name="android.support.PARENT_ACTIVITY"
  64 + android:value="com.gump.passport.demo.MainActivity"/>
  65 + </activity>
50 66 </application>
51 67  
52 68 </manifest>
53 69 \ No newline at end of file
app/src/main/java/com/gump/passport/demo/AppCompatPreferenceActivity.java
... ... @@ -0,0 +1,109 @@
  1 +package com.gump.passport.demo;
  2 +
  3 +import android.content.res.Configuration;
  4 +import android.os.Bundle;
  5 +import android.preference.PreferenceActivity;
  6 +import android.support.annotation.LayoutRes;
  7 +import android.support.annotation.Nullable;
  8 +import android.support.v7.app.ActionBar;
  9 +import android.support.v7.app.AppCompatDelegate;
  10 +import android.support.v7.widget.Toolbar;
  11 +import android.view.MenuInflater;
  12 +import android.view.View;
  13 +import android.view.ViewGroup;
  14 +
  15 +/**
  16 + * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
  17 + * to be used with AppCompat.
  18 + */
  19 +public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
  20 +
  21 + private AppCompatDelegate mDelegate;
  22 +
  23 + @Override
  24 + protected void onCreate(Bundle savedInstanceState) {
  25 + getDelegate().installViewFactory();
  26 + getDelegate().onCreate(savedInstanceState);
  27 + super.onCreate(savedInstanceState);
  28 + }
  29 +
  30 + @Override
  31 + protected void onPostCreate(Bundle savedInstanceState) {
  32 + super.onPostCreate(savedInstanceState);
  33 + getDelegate().onPostCreate(savedInstanceState);
  34 + }
  35 +
  36 + public ActionBar getSupportActionBar() {
  37 + return getDelegate().getSupportActionBar();
  38 + }
  39 +
  40 + public void setSupportActionBar(@Nullable Toolbar toolbar) {
  41 + getDelegate().setSupportActionBar(toolbar);
  42 + }
  43 +
  44 + @Override
  45 + public MenuInflater getMenuInflater() {
  46 + return getDelegate().getMenuInflater();
  47 + }
  48 +
  49 + @Override
  50 + public void setContentView(@LayoutRes int layoutResID) {
  51 + getDelegate().setContentView(layoutResID);
  52 + }
  53 +
  54 + @Override
  55 + public void setContentView(View view) {
  56 + getDelegate().setContentView(view);
  57 + }
  58 +
  59 + @Override
  60 + public void setContentView(View view, ViewGroup.LayoutParams params) {
  61 + getDelegate().setContentView(view, params);
  62 + }
  63 +
  64 + @Override
  65 + public void addContentView(View view, ViewGroup.LayoutParams params) {
  66 + getDelegate().addContentView(view, params);
  67 + }
  68 +
  69 + @Override
  70 + protected void onPostResume() {
  71 + super.onPostResume();
  72 + getDelegate().onPostResume();
  73 + }
  74 +
  75 + @Override
  76 + protected void onTitleChanged(CharSequence title, int color) {
  77 + super.onTitleChanged(title, color);
  78 + getDelegate().setTitle(title);
  79 + }
  80 +
  81 + @Override
  82 + public void onConfigurationChanged(Configuration newConfig) {
  83 + super.onConfigurationChanged(newConfig);
  84 + getDelegate().onConfigurationChanged(newConfig);
  85 + }
  86 +
  87 + @Override
  88 + protected void onStop() {
  89 + super.onStop();
  90 + getDelegate().onStop();
  91 + }
  92 +
  93 + @Override
  94 + protected void onDestroy() {
  95 + super.onDestroy();
  96 + getDelegate().onDestroy();
  97 + }
  98 +
  99 + public void invalidateOptionsMenu() {
  100 + getDelegate().invalidateOptionsMenu();
  101 + }
  102 +
  103 + private AppCompatDelegate getDelegate() {
  104 + if (mDelegate == null) {
  105 + mDelegate = AppCompatDelegate.create(this, null);
  106 + }
  107 + return mDelegate;
  108 + }
  109 +}
app/src/main/java/com/gump/passport/demo/GameApplication.java
... ... @@ -0,0 +1,6 @@
  1 +package com.gump.passport.demo;
  2 +
  3 +import android.app.Application;
  4 +
  5 +public class GameApplication extends Application {
  6 +}
app/src/main/java/com/gump/passport/demo/MainActivity.java
1 1 package com.gump.passport.demo;
2 2  
3 3 import android.content.Intent;
  4 +import android.content.SharedPreferences;
4 5 import android.os.Bundle;
  6 +import android.preference.PreferenceManager;
5 7 import android.support.v7.app.AppCompatActivity;
6 8 import android.util.Log;
  9 +import android.view.Menu;
  10 +import android.view.MenuItem;
7 11 import android.view.View;
  12 +import android.widget.Button;
8 13 import android.widget.TextView;
  14 +import android.widget.Toast;
9 15  
10 16 import com.gump.PaymentVersion;
11 17 import com.gump.SDKAgent;
12 18 import com.gump.gpassport.Actions;
13 19 import com.gump.gpassport.GamePlayer;
14 20 import com.gump.gpassport.Passport;
  21 +import com.gump.gpassport.PlayerType;
15 22 import com.gump.gpassport.StateListener;
16 23 import com.gump.payment.Payment;
17   -import com.gump.payment.PurchaseCallback;
  24 +import com.gump.payment.callback.PurchaseCallback;
  25 +import com.gump.payment.callback.ResultCallback;
18 26  
19 27 public class MainActivity extends AppCompatActivity implements StateListener, PurchaseCallback {
20 28  
21   - private static final String TAG = "Gump Demo";
22   -
  29 + private static final String TAG = "MainActivity";
23 30 private Passport passport;
24   -
25 31 private TextView tvInfo;
  32 + private View mainLayout;
  33 + private Button btnLogin;
  34 +
  35 + private GamePlayer currentPlayer;
26 36  
  37 + private Button btnIab;
  38 + private Button btnPay;
  39 + private Button btnCheck;
27 40  
28 41 @Override
29 42 protected void onCreate(Bundle savedInstanceState) {
30 43 super.onCreate(savedInstanceState);
31 44 setContentView(R.layout.activity_main);
32   - SDKAgent.init(getApplicationContext(), "100", "1000");
33   -
34   - SDKAgent.getSettings().setDebug(true);
35   - SDKAgent.getSettings().setScreenLandscape(true);
36   - SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4);
37 45  
38 46 tvInfo = findViewById(R.id.info);
39   - passport = new Passport.Builder().context(this).setListener(this).build();
40   - findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
  47 + mainLayout = findViewById(R.id.main_layout);
  48 + btnLogin = findViewById(R.id.login);
  49 + btnLogin.setOnClickListener(new View.OnClickListener() {
41 50 @Override
42 51 public void onClick(View v) {
43 52 passport.signIn(MainActivity.this);
44 53 }
45 54 });
46 55  
47   -
48   - findViewById(R.id.iab).setOnClickListener(new View.OnClickListener() {
  56 + btnCheck = mainLayout.findViewById(R.id.check);
  57 + btnCheck.setOnClickListener(new View.OnClickListener() {
49 58 @Override
50 59 public void onClick(View v) {
51   - Bundle payInfo = new Bundle();
52   - payInfo.putString("product", "180010");
53   - payInfo.putFloat("amount", 0.1f);
54   - payInfo.putString("extraInfo", "This is demo!");
55   - payInfo.putString("serverId", "100");
56   - payInfo.putString("roleId", "41080");
  60 + initPay();
  61 + }
  62 + });
  63 + btnIab = mainLayout.findViewById(R.id.iab);
  64 + btnIab.setOnClickListener(new View.OnClickListener() {
  65 + @Override
  66 + public void onClick(View v) {
  67 + Bundle payInfo = assemblePayBundle();
57 68 Payment.launchIAP(MainActivity.this, payInfo, MainActivity.this);
58 69 }
59 70 });
60 71  
61   - findViewById(R.id.pay).setOnClickListener(new View.OnClickListener() {
  72 + btnPay = mainLayout.findViewById(R.id.pay);
  73 + btnPay.setOnClickListener(new View.OnClickListener() {
62 74 @Override
63 75 public void onClick(View v) {
64   - Bundle payInfo = new Bundle();
65   - payInfo.putString("product", "wa2");
66   - payInfo.putFloat("amount", 0.1f);
67   - payInfo.putString("extraInfo", "This is demo!");
68   - payInfo.putString("serverId", "100");
69   - payInfo.putString("roleId", "41080");
  76 + Bundle payInfo = assemblePayBundle();
70 77 Payment.pay(MainActivity.this, payInfo, MainActivity.this);
71 78 }
72 79 });
  80 +
  81 + mainLayout.findViewById(R.id.bind).setOnClickListener(new View.OnClickListener() {
  82 + @Override
  83 + public void onClick(View v) {
  84 + passport.link(MainActivity.this);
  85 + }
  86 + });
  87 +
  88 + mainLayout.findViewById(R.id.switch_acc).setOnClickListener(new View.OnClickListener() {
  89 + @Override
  90 + public void onClick(View v) {
  91 + passport.switchAccount(PlayerType.GamePlayer);
  92 + }
  93 + });
  94 +
  95 + mainLayout.findViewById(R.id.switch_gump).setOnClickListener(new View.OnClickListener() {
  96 + @Override
  97 + public void onClick(View v) {
  98 + passport.switchAccount(PlayerType.GumpPlayer);
  99 + }
  100 + });
  101 +
  102 +
  103 + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  104 + boolean mode = sp.getBoolean("key_mode", true);
  105 + String appId = sp.getString("key_appid", "100");
  106 + String channel = sp.getString("key_channel", "1000");
  107 + String payVersion = sp.getString("key_pay_version", "V3");
  108 +
  109 + SDKAgent.init(getApplicationContext(), appId, channel);
  110 + SDKAgent.getSettings().setDebug(mode);
  111 + SDKAgent.getSettings().setPaymentVersion(PaymentVersion.valueOf(payVersion));
  112 +
  113 + passport = new Passport.Builder().context(MainActivity.this).setListener(MainActivity.this).build();
  114 +
  115 + }
  116 +
  117 + private Bundle assemblePayBundle() {
  118 + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  119 + Bundle payInfo = new Bundle();
  120 + payInfo.putString("product", sp.getString("key_product", "10080"));
  121 + payInfo.putFloat("amount", sp.getFloat("key_amount", 0.1f));
  122 + payInfo.putString("extraInfo", sp.getString("key_extra", "test"));
  123 + payInfo.putString("serverId", sp.getString("key_server_id", "100"));
  124 + payInfo.putString("roleId", sp.getString("key_role_id", "41080"));
  125 + payInfo.putString("currency", sp.getString("key_currency", "THB"));
  126 + return payInfo;
  127 + }
  128 +
  129 +
  130 + private void initPay() {
  131 + btnCheck.setEnabled(false);
  132 + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  133 + String serverId = sp.getString("key_server_id", "100");
  134 + String roleId = sp.getString("key_role_id", "41080");
  135 + Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() {
  136 + @Override
  137 + public void onResult(boolean isRisk) {
  138 + btnCheck.setEnabled(true);
  139 + btnIab.setEnabled(isRisk);
  140 + btnPay.setEnabled(!isRisk);
  141 + }
  142 + });
  143 + }
  144 +
  145 + @Override
  146 + public boolean onCreateOptionsMenu(Menu menu) {
  147 + getMenuInflater().inflate(R.menu.main, menu);
  148 + return super.onCreateOptionsMenu(menu);
  149 + }
  150 +
  151 + @Override
  152 + public boolean onOptionsItemSelected(MenuItem item) {
  153 + if (item.getItemId() == R.id.setting) {
  154 + Intent intent = new Intent(this, SettingsActivity.class);
  155 + startActivity(intent);
  156 + return true;
  157 + }
  158 + return super.onOptionsItemSelected(item);
73 159 }
74 160  
75 161 @Override
76   - protected void onResume() {
  162 + public void onResume() {
77 163 super.onResume();
78 164 passport.onResume();
79 165 }
80 166  
81 167 @Override
82   - protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  168 + public void onActivityResult(int requestCode, int resultCode, Intent data) {
83 169 if (!passport.onActivityResult(requestCode, resultCode, data))
84 170 super.onActivityResult(requestCode, resultCode, data);
85 171 }
86 172  
87 173 @Override
88 174 public void onActionSucced(Actions action, GamePlayer player) {
89   - tvInfo.setText("login succed! gump id=" + player.getId() + ",playerType=" + player.getPlayerType());
  175 + switch (action) {
  176 + case SIGN:
  177 + currentPlayer = player;
  178 + tvInfo.setText("Login succed! gump id=" + player.getId() + ",playerType=" + player.getPlayerType());
  179 + btnLogin.setVisibility(View.GONE);
  180 + mainLayout.setVisibility(View.VISIBLE);
  181 + break;
  182 + case SWITCH:
  183 + tvInfo.setText("Switch account succed! Pls reboot the game!");
  184 + Toast.makeText(this, "The account has switched,pls reboot the Game!", Toast.LENGTH_LONG).show();
  185 + break;
  186 + }
90 187 }
91 188  
92 189 @Override
93   - public void onActionFailured() {
94   - tvInfo.setText("login has error");
  190 + public void onActionFailured(Throwable e) {
  191 + tvInfo.setText("login has error:" + e.getMessage());
95 192 }
96 193  
97 194 @Override
app/src/main/java/com/gump/passport/demo/SettingsActivity.java
... ... @@ -0,0 +1,235 @@
  1 +package com.gump.passport.demo;
  2 +
  3 +import android.annotation.TargetApi;
  4 +import android.content.Context;
  5 +import android.content.Intent;
  6 +import android.content.res.Configuration;
  7 +import android.os.Build;
  8 +import android.os.Bundle;
  9 +import android.preference.ListPreference;
  10 +import android.preference.Preference;
  11 +import android.preference.PreferenceActivity;
  12 +import android.preference.PreferenceFragment;
  13 +import android.preference.PreferenceManager;
  14 +import android.support.annotation.Nullable;
  15 +import android.support.v4.app.NavUtils;
  16 +import android.support.v7.app.ActionBar;
  17 +import android.view.MenuItem;
  18 +
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * A {@link PreferenceActivity} that presents a set of application settings. On
  23 + * handset devices, settings are presented as a single list. On tablets,
  24 + * settings are split by category, with category headers shown to the left of
  25 + * the list of settings.
  26 + * <p>
  27 + * See <a href="http://developer.android.com/design/patterns/settings.html">
  28 + * Android Design: Settings</a> for design guidelines and the <a
  29 + * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
  30 + * API Guide</a> for more information on developing a Settings UI.
  31 + */
  32 +public class SettingsActivity extends AppCompatPreferenceActivity {
  33 +
  34 + /**
  35 + * A preference value change listener that updates the preference's summary
  36 + * to reflect its new value.
  37 + */
  38 + private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
  39 + @Override
  40 + public boolean onPreferenceChange(Preference preference, Object value) {
  41 + String stringValue = value.toString();
  42 +
  43 + if (preference instanceof ListPreference) {
  44 + // For list preferences, look up the correct display value in
  45 + // the preference's 'entries' list.
  46 + ListPreference listPreference = (ListPreference) preference;
  47 + int index = listPreference.findIndexOfValue(stringValue);
  48 +
  49 + // Set the summary to reflect the new value.
  50 + preference.setSummary(
  51 + index >= 0
  52 + ? listPreference.getEntries()[index]
  53 + : null);
  54 +
  55 + } else {
  56 + // For all other preferences, set the summary to the value's
  57 + // simple string representation.
  58 + preference.setSummary(stringValue);
  59 + }
  60 + return true;
  61 + }
  62 + };
  63 +
  64 + /**
  65 + * Helper method to determine if the device has an extra-large screen. For
  66 + * example, 10" tablets are extra-large.
  67 + */
  68 + private static boolean isXLargeTablet(Context context) {
  69 + return (context.getResources().getConfiguration().screenLayout
  70 + & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
  71 + }
  72 +
  73 + /**
  74 + * Binds a preference's summary to its value. More specifically, when the
  75 + * preference's value is changed, its summary (line of text below the
  76 + * preference title) is updated to reflect the value. The summary is also
  77 + * immediately updated upon calling this method. The exact display format is
  78 + * dependent on the type of preference.
  79 + *
  80 + * @see #sBindPreferenceSummaryToValueListener
  81 + */
  82 + private static void bindPreferenceSummaryToValue(Preference preference) {
  83 + // Set the listener to watch for value changes.
  84 + preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
  85 +
  86 + // Trigger the listener immediately with the preference's
  87 + // current value.
  88 + sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
  89 + PreferenceManager.getDefaultSharedPreferences(preference.getContext())
  90 + .getString(preference.getKey(), ""));
  91 + }
  92 +
  93 + @Override
  94 + protected void onCreate(Bundle savedInstanceState) {
  95 + super.onCreate(savedInstanceState);
  96 + setupActionBar();
  97 + }
  98 +
  99 + /**
  100 + * Set up the {@link android.app.ActionBar}, if the API is available.
  101 + */
  102 + private void setupActionBar() {
  103 + ActionBar actionBar = getSupportActionBar();
  104 + if (actionBar != null) {
  105 + // Show the Up button in the action bar.
  106 + actionBar.setDisplayHomeAsUpEnabled(true);
  107 + }
  108 + }
  109 +
  110 + @Override
  111 + public boolean onMenuItemSelected(int featureId, MenuItem item) {
  112 + int id = item.getItemId();
  113 + if (id == android.R.id.home) {
  114 + if (!super.onMenuItemSelected(featureId, item)) {
  115 + NavUtils.navigateUpFromSameTask(this);
  116 + }
  117 + return true;
  118 + }
  119 + return super.onMenuItemSelected(featureId, item);
  120 + }
  121 +
  122 + /**
  123 + * {@inheritDoc}
  124 + */
  125 + @Override
  126 + public boolean onIsMultiPane() {
  127 + return isXLargeTablet(this);
  128 + }
  129 +
  130 + /**
  131 + * {@inheritDoc}
  132 + */
  133 + @Override
  134 + @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  135 + public void onBuildHeaders(List<Header> target) {
  136 + loadHeadersFromResource(R.xml.pref_headers, target);
  137 + }
  138 +
  139 + /**
  140 + * This method stops fragment injection in malicious applications.
  141 + * Make sure to deny any unknown fragments here.
  142 + */
  143 + protected boolean isValidFragment(String fragmentName) {
  144 + return PreferenceFragment.class.getName().equals(fragmentName)
  145 + || GeneralPreferenceFragment.class.getName().equals(fragmentName)
  146 + || ParamPreferenceFragment.class.getName().equals(fragmentName);
  147 + }
  148 +
  149 + /**
  150 + * sdk配置
  151 + */
  152 + @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  153 + public static class GeneralPreferenceFragment extends PreferenceFragment {
  154 + @Override
  155 + public void onCreate(Bundle savedInstanceState) {
  156 + super.onCreate(savedInstanceState);
  157 + addPreferencesFromResource(R.xml.pref_general);
  158 + setHasOptionsMenu(true);
  159 +
  160 + // Bind the summaries of EditText/List/Dialog/Ringtone preferences
  161 + // to their values. When their values change, their summaries are
  162 + // updated to reflect the new value, per the Android Design
  163 + // guidelines.
  164 +// bindPreferenceSummaryToValue(findPreference("key_mode"));
  165 + bindPreferenceSummaryToValue(findPreference("key_pay_version"));
  166 + }
  167 +
  168 + @Override
  169 + public boolean onOptionsItemSelected(MenuItem item) {
  170 + int id = item.getItemId();
  171 + if (id == android.R.id.home) {
  172 + startActivity(new Intent(getActivity(), SettingsActivity.class));
  173 + return true;
  174 + }
  175 + return super.onOptionsItemSelected(item);
  176 + }
  177 + }
  178 +
  179 + /**
  180 + * 基础参数配置
  181 + */
  182 + @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  183 + public static class ParamPreferenceFragment extends PreferenceFragment {
  184 + @Override
  185 + public void onCreate(Bundle savedInstanceState) {
  186 + super.onCreate(savedInstanceState);
  187 + addPreferencesFromResource(R.xml.pref_param);
  188 + setHasOptionsMenu(true);
  189 +
  190 + // Bind the summaries of EditText/List/Dialog/Ringtone preferences
  191 + // to their values. When their values change, their summaries are
  192 + // updated to reflect the new value, per the Android Design
  193 + // guidelines.
  194 + bindPreferenceSummaryToValue(findPreference("key_appid"));
  195 + bindPreferenceSummaryToValue(findPreference("key_channel"));
  196 + }
  197 +
  198 + @Override
  199 + public boolean onOptionsItemSelected(MenuItem item) {
  200 + int id = item.getItemId();
  201 + if (id == android.R.id.home) {
  202 + startActivity(new Intent(getActivity(), SettingsActivity.class));
  203 + return true;
  204 + }
  205 + return super.onOptionsItemSelected(item);
  206 + }
  207 + }
  208 +
  209 + @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  210 + public static class PaymentPreerenceFragment extends PreferenceFragment {
  211 + @Override
  212 + public void onCreate(@Nullable Bundle savedInstanceState) {
  213 + super.onCreate(savedInstanceState);
  214 + addPreferencesFromResource(R.xml.pref_payment);
  215 + setHasOptionsMenu(true);
  216 +
  217 + bindPreferenceSummaryToValue(findPreference("key_server_id"));
  218 + bindPreferenceSummaryToValue(findPreference("key_role_id"));
  219 + bindPreferenceSummaryToValue(findPreference("key_product"));
  220 + bindPreferenceSummaryToValue(findPreference("key_amount"));
  221 + bindPreferenceSummaryToValue(findPreference("key_currency"));
  222 + bindPreferenceSummaryToValue(findPreference("key_extra"));
  223 + }
  224 +
  225 + @Override
  226 + public boolean onOptionsItemSelected(MenuItem item) {
  227 + int id = item.getItemId();
  228 + if (id == android.R.id.home) {
  229 + startActivity(new Intent(getActivity(), SettingsActivity.class));
  230 + return true;
  231 + }
  232 + return super.onOptionsItemSelected(item);
  233 + }
  234 + }
  235 +}
app/src/main/res/drawable/ic_attach_money_black_24dp.xml
... ... @@ -0,0 +1,9 @@
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + android:width="24dp"
  3 + android:height="24dp"
  4 + android:viewportWidth="24.0"
  5 + android:viewportHeight="24.0">
  6 + <path
  7 + android:fillColor="#FF000000"
  8 + android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
  9 +</vector>
app/src/main/res/drawable/ic_build_black_24dp.xml
... ... @@ -0,0 +1,9 @@
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + android:width="24dp"
  3 + android:height="24dp"
  4 + android:viewportWidth="24.0"
  5 + android:viewportHeight="24.0">
  6 + <path
  7 + android:fillColor="#FF000000"
  8 + android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z"/>
  9 +</vector>
app/src/main/res/drawable/ic_text_fields_black_24dp.xml
... ... @@ -0,0 +1,9 @@
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + android:width="24dp"
  3 + android:height="24dp"
  4 + android:viewportWidth="24.0"
  5 + android:viewportHeight="24.0">
  6 + <path
  7 + android:fillColor="#FF000000"
  8 + android:pathData="M2.5,4v3h5v12h3L10.5,7h5L15.5,4h-13zM21.5,9h-9v3h3v7h3v-7h3L21.5,9z"/>
  9 +</vector>
app/src/main/res/layout/activity_main.xml
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <LinearLayout
3 3 xmlns:android="http://schemas.android.com/apk/res/android"
4   - xmlns:app="http://schemas.android.com/apk/res-auto"
5 4 xmlns:tools="http://schemas.android.com/tools"
6 5 android:layout_width="match_parent"
7 6 android:layout_height="match_parent"
... ... @@ -10,8 +9,9 @@
10 9  
11 10 <TextView
12 11 android:id="@+id/info"
13   - android:layout_width="wrap_content"
14   - android:layout_height="wrap_content"/>
  12 + android:layout_width="match_parent"
  13 + android:layout_height="wrap_content"
  14 + android:lines="2"/>
15 15  
16 16 <Button
17 17 android:id="@+id/login"
... ... @@ -19,16 +19,50 @@
19 19 android:layout_height="wrap_content"
20 20 android:text="login"/>
21 21  
22   - <Button
23   - android:id="@+id/iab"
24   - android:layout_width="match_parent"
25   - android:layout_height="wrap_content"
26   - android:text="iab"/>
27 22  
28   - <Button
29   - android:id="@+id/pay"
  23 + <LinearLayout
  24 + android:id="@+id/main_layout"
30 25 android:layout_width="match_parent"
31   - android:layout_height="wrap_content"
32   - android:text="payment"/>
  26 + android:layout_height="match_parent"
  27 + android:orientation="vertical"
  28 + android:visibility="gone">
  29 +
  30 + <Button
  31 + android:id="@+id/check"
  32 + android:layout_width="match_parent"
  33 + android:layout_height="wrap_content"
  34 + android:text="check payemnt state"/>
  35 +
  36 + <Button
  37 + android:id="@+id/bind"
  38 + android:layout_width="match_parent"
  39 + android:layout_height="wrap_content"
  40 + android:text="Bind Gump account"/>
  41 +
  42 + <Button
  43 + android:id="@+id/switch_acc"
  44 + android:layout_width="match_parent"
  45 + android:layout_height="wrap_content"
  46 + android:text="Switch to games player"/>
  47 +
  48 + <Button
  49 + android:id="@+id/switch_gump"
  50 + android:layout_width="match_parent"
  51 + android:layout_height="wrap_content"
  52 + android:text="Switch to gump player"/>
  53 +
  54 + <Button
  55 + android:id="@+id/iab"
  56 + android:layout_width="match_parent"
  57 + android:layout_height="wrap_content"
  58 + android:enabled="false"
  59 + android:text="Iab"/>
33 60  
  61 + <Button
  62 + android:id="@+id/pay"
  63 + android:layout_width="match_parent"
  64 + android:layout_height="wrap_content"
  65 + android:enabled="false"
  66 + android:text="Payment"/>
  67 + </LinearLayout>
34 68 </LinearLayout>
35 69 \ No newline at end of file
app/src/main/res/menu/main.xml
... ... @@ -0,0 +1,9 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<menu xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto">
  4 +
  5 + <item
  6 + android:id="@+id/setting"
  7 + android:title="设置"
  8 + app:showAsAction="always"/>
  9 +</menu>
0 10 \ No newline at end of file
app/src/main/res/values/strings.xml
1 1 <resources>
2 2 <string name="app_name">PassportDemo</string>
  3 +
  4 + <!-- TODO: Remove or change this placeholder text -->
  5 + <string name="title_activity_settings">设置</string>
  6 +
  7 + <!-- Strings related to Settings -->
  8 +
  9 + <!-- SDK settings -->
  10 + <string name="pref_header_general">SDK设置</string>
  11 +
  12 + <string name="pref_title_mode">线上环境</string>
  13 + <string name="pref_description_mode">SDK是否使用线上正式服务器环境?</string>
  14 +
  15 + <string name="pref_title_orientation">支付界面方向</string>
  16 + <string name="pref_description_orientation">是否使用横屏?</string>
  17 +
  18 + <string name="pref_title_payment_version">支付版本</string>
  19 +
  20 + <string-array name="pref_payment_version_titles">
  21 + <item>V3版本</item>
  22 + <item>V4版本</item>
  23 + </string-array>
  24 + <string-array name="pref_payment_version_values">
  25 + <item>V3</item>
  26 + <item>V4</item>
  27 + </string-array>
  28 +
  29 +
  30 + <!--基础参数设置-->
  31 + <string name="pref_header_param">基础参数设置</string>
  32 + <string name="pref_title_appid">appId</string>
  33 + <string name="pref_description_appid">应用使用的appId</string>
  34 + <string name="pref_title_channel">ChannelId</string>
  35 + <string name="pref_description_channel">应用使用的channelId</string>
  36 + <!--支付参数-->
  37 + <string name="payment">支付参数</string>
  38 + <string name="pref_description_server_id">区服id</string>
  39 + <string name="pref_title_server_id">serverId</string>
  40 + <string name="pref_description_role_id">角色id</string>
  41 + <string name="pref_title_role_id">roleId</string>
  42 + <string name="pref_description_product">商品名/商品id</string>
  43 + <string name="pref_title_product">product</string>
  44 + <string name="pref_description_amount">金额</string>
  45 + <string name="pref_title_amount">支付金额</string>
  46 + <string name="pref_description_extra">游戏透传参数</string>
  47 + <string name="pref_title_extra">extra_info</string>
  48 + <string name="pref_description_currency">支付显示货币</string>
  49 + <string name="pref_title_currency">currency</string>
  50 +
  51 +
3 52 </resources>
app/src/main/res/xml/pref_general.xml
... ... @@ -0,0 +1,22 @@
  1 +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  2 +
  3 + <SwitchPreference
  4 + android:defaultValue="true"
  5 + android:key="key_mode"
  6 + android:summary="@string/pref_description_mode"
  7 + android:title="@string/pref_title_mode"/>
  8 +
  9 +
  10 + <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to
  11 + dismiss it. -->
  12 + <!--NOTE: ListPreference's summary should be set to its value by the activity code. -->
  13 + <ListPreference
  14 + android:defaultValue="V3"
  15 + android:entries="@array/pref_payment_version_titles"
  16 + android:entryValues="@array/pref_payment_version_values"
  17 + android:key="key_pay_version"
  18 + android:negativeButtonText="@null"
  19 + android:positiveButtonText="@null"
  20 + android:title="@string/pref_title_payment_version"/>
  21 +
  22 +</PreferenceScreen>
app/src/main/res/xml/pref_headers.xml
... ... @@ -0,0 +1,18 @@
  1 +<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
  2 +
  3 + <!-- These settings headers are only used on tablets. -->
  4 +
  5 + <header
  6 + android:fragment="com.gump.passport.demo.SettingsActivity$ParamPreferenceFragment"
  7 + android:icon="@drawable/ic_text_fields_black_24dp"
  8 + android:title="@string/pref_header_param"/>
  9 + <header
  10 + android:fragment="com.gump.passport.demo.SettingsActivity$GeneralPreferenceFragment"
  11 + android:icon="@drawable/ic_build_black_24dp"
  12 + android:title="@string/pref_header_general"/>
  13 + <header
  14 + android:fragment="com.gump.passport.demo.SettingsActivity$PaymentPreferenceFragment"
  15 + android:icon="@drawable/ic_attach_money_black_24dp"
  16 + android:title="@string/payment"/>
  17 +
  18 +</preference-headers>
app/src/main/res/xml/pref_param.xml
... ... @@ -0,0 +1,29 @@
  1 +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  2 +
  3 + <EditTextPreference
  4 + android:defaultValue="100"
  5 + android:key="key_appid"
  6 + android:summary="@string/pref_description_appid"
  7 + android:title="@string/pref_title_appid"/>
  8 +
  9 + <!-- NOTE: EditTextPreference accepts EditText attributes. -->
  10 + <!-- NOTE: EditTextPreference's summary should be set to its value by the activity code. -->
  11 + <EditTextPreference
  12 + android:defaultValue="1000"
  13 + android:key="key_channel"
  14 + android:summary="@string/pref_description_channel"
  15 + android:title="@string/pref_title_channel"/>
  16 +
  17 + <!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to
  18 + dismiss it. -->
  19 + <!-- NOTE: ListPreference's summary should be set to its value by the activity code. -->
  20 + <!--<ListPreference-->
  21 + <!--android:defaultValue="-1"-->
  22 + <!--android:entries="@array/pref_example_list_titles"-->
  23 + <!--android:entryValues="@array/pref_example_list_values"-->
  24 + <!--android:key="example_list"-->
  25 + <!--android:negativeButtonText="@null"-->
  26 + <!--android:positiveButtonText="@null"-->
  27 + <!--android:title="@string/pref_title_add_friends_to_messages"/>-->
  28 +
  29 +</PreferenceScreen>
app/src/main/res/xml/pref_payment.xml
... ... @@ -0,0 +1,34 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  3 +
  4 + <EditTextPreference
  5 + android:defaultValue="100"
  6 + android:key="key_server_id"
  7 + android:summary="@string/pref_description_server_id"
  8 + android:title="@string/pref_title_server_id"/>
  9 + <EditTextPreference
  10 + android:defaultValue="41080"
  11 + android:key="key_role_id"
  12 + android:summary="@string/pref_description_role_id"
  13 + android:title="@string/pref_title_role_id"/>
  14 + <EditTextPreference
  15 + android:defaultValue="180010"
  16 + android:key="key_product"
  17 + android:summary="@string/pref_description_product"
  18 + android:title="@string/pref_title_product"/>
  19 + <EditTextPreference
  20 + android:defaultValue="0.1"
  21 + android:key="key_amount"
  22 + android:summary="@string/pref_description_amount"
  23 + android:title="@string/pref_title_amount"/>
  24 + <EditTextPreference
  25 + android:defaultValue="THB"
  26 + android:key="key_currency"
  27 + android:summary="@string/pref_description_currency"
  28 + android:title="@string/pref_title_currency"/>
  29 + <EditTextPreference
  30 + android:defaultValue="test"
  31 + android:key="key_extra_info"
  32 + android:summary="@string/pref_description_extra"
  33 + android:title="@string/pref_title_extra"/>
  34 +</PreferenceScreen>
0 35 \ No newline at end of file