完善魅族必接功能

This commit is contained in:
zhl 2020-11-27 12:01:57 +08:00
parent 936267cc85
commit 4a6801185c

View File

@ -25,6 +25,7 @@ import com.meizu.gamesdk.model.model.LoginResultCode;
import com.meizu.gamesdk.model.model.MzAccountInfo; import com.meizu.gamesdk.model.model.MzAccountInfo;
import com.meizu.gamesdk.model.model.MzBuyInfo; import com.meizu.gamesdk.model.model.MzBuyInfo;
import com.meizu.gamesdk.model.model.PayResultCode; import com.meizu.gamesdk.model.model.PayResultCode;
import com.meizu.gamesdk.online.core.MzGameBarPlatform;
import com.meizu.gamesdk.online.core.MzGameCenterPlatform; import com.meizu.gamesdk.online.core.MzGameCenterPlatform;
import org.egret.egretnativeandroid.EgretNativeAndroid; import org.egret.egretnativeandroid.EgretNativeAndroid;
@ -40,6 +41,7 @@ public class MainActivity extends Activity implements MzLoginListener, MzPayList
private FrameLayout rootLayout = null; private FrameLayout rootLayout = null;
private Vibrator vibrator; private Vibrator vibrator;
private MzAccountInfo accountInfo; private MzAccountInfo accountInfo;
private MzGameBarPlatform mzGameBarPlatform;
@Override @Override
@ -76,18 +78,29 @@ public class MainActivity extends Activity implements MzLoginListener, MzPayList
rootLayout = nativeAndroid.getRootFrameLayout(); rootLayout = nativeAndroid.getRootFrameLayout();
showLoadingView(); showLoadingView();
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
//初始化可以指定gamebar第一次显示的位置在游戏退出时会记住用户操作的最后一次位置再次启动时使用上一次的位置
//第一次显示的位置可以指定四个方向左上左下右上右下
// public static final int GRAVITY_LEFT_TOP = 1;
// public static final int GRAVITY_LEFT_BOTTOM = 2;
// public static final int GRAVITY_RIGHT_TOP = 3;
// public static final int GRAVITY_RIGHT_BOTTOM = 4;
mzGameBarPlatform = new MzGameBarPlatform(this, MzGameBarPlatform.GRAVITY_LEFT_TOP);
mzGameBarPlatform.onActivityCreate();
mzGameBarPlatform.showGameBar();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
nativeAndroid.pause(); nativeAndroid.pause();
mzGameBarPlatform.onActivityPause();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
nativeAndroid.resume(); nativeAndroid.resume();
mzGameBarPlatform.onActivityResume();
} }
@Override @Override
@ -188,26 +201,23 @@ public class MainActivity extends Activity implements MzLoginListener, MzPayList
try { try {
JSONObject jsonObject = new JSONObject(message); JSONObject jsonObject = new JSONObject(message);
String cpOrderId = jsonObject.getString("orderId"); Log.i(TAG, "pay info: " + jsonObject.toString());
String productCode = jsonObject.getString("productCode");
int count = jsonObject.getInt("count");
//TODO: 平台的支付
Bundle buyBundle = new MzBuyInfo() Bundle buyBundle = new MzBuyInfo()
.setBuyCount(1) .setBuyCount(jsonObject.getInt("buy_amount"))
// .setCpUserInfo(cpUserInfo) .setCpUserInfo(jsonObject.getString("user_info"))
// .setOrderAmount(1) .setOrderAmount(jsonObject.getString("total_price"))
// .setOrderId(cpOrderId) .setOrderId(jsonObject.getString("cp_order_id"))
// .setPerPrice(count) .setPerPrice(jsonObject.getString("product_per_price"))
// .setProductBody(productBody) .setProductBody(jsonObject.getString("product_body"))
// .setProductId(productId) .setProductId(jsonObject.getString("product_id"))
// .setProductSubject(productSubject) .setProductSubject(jsonObject.getString("product_subject"))
// .setProductUnit(productUnit) .setProductUnit(jsonObject.getString("product_unit"))
// .setSign(sign) .setSign(jsonObject.getString("sign"))
// .setSignType(signType) .setSignType(jsonObject.getString("sign_type"))
// .setCreateTime(createTime) .setCreateTime(jsonObject.getLong("create_time"))
// .setAppid(appid) .setAppid(jsonObject.getString("app_id"))
// .setUserUid(uid) .setUserUid(jsonObject.getString("uid"))
// .setPayType(payType) .setPayType(jsonObject.getInt("pay_type"))
.toBundle(); .toBundle();
MzGameCenterPlatform.payOnline(MainActivity.this, buyBundle, MainActivity.this); MzGameCenterPlatform.payOnline(MainActivity.this, buyBundle, MainActivity.this);
} catch (JSONException e) { } catch (JSONException e) {
@ -239,6 +249,8 @@ public class MainActivity extends Activity implements MzLoginListener, MzPayList
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
//调一下onActivityDestroy
mzGameBarPlatform.onActivityDestroy();
} }
private void showLoadingView() { private void showLoadingView() {