Last active
August 29, 2015 14:08
-
-
Save zii/259b5874d03d79c4b391 to your computer and use it in GitHub Desktop.
CCSdkUnipay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Unipay SDK for cocos2d-x */ | |
package com.xingdong.tpyzz; | |
import android.annotation.SuppressLint; | |
import android.app.AlertDialog; | |
import android.content.DialogInterface; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.widget.Toast; | |
import org.cocos2dx.lib.Cocos2dxActivity; | |
import com.unicom.dcLoader.Utils; | |
import com.unicom.dcLoader.Utils.UnipayPayResultListener; | |
class CCSdkUnipay extends Cocos2dxActivity | |
{ | |
static { | |
System.loadLibrary("cocos2dcpp"); | |
} | |
private int _mid; // last message id | |
@Override | |
protected void onCreate(Bundle savedInstanceState){ | |
super.onCreate(savedInstanceState); | |
Utils.getInstances().initSDK(this, 0); | |
} | |
public void onmessage(Message m) | |
{ | |
} | |
public void onpay(int mid, boolean status) | |
{ | |
} | |
public void onexit() | |
{ | |
this.finish(); | |
System.exit(0); | |
} | |
public void toast(String text) | |
{ | |
Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); | |
} | |
private UnipayPayResultListener listener = new UnipayPayResultListener() { | |
@Override | |
public void PayResult(final String code, final int flag, String desc) { | |
runOnGLThread(new Runnable() { | |
@Override | |
public void run() { | |
if (flag == Utils.SUCCESS || flag == Utils.SUCCESS_SMS || flag == Utils.SUCCESS_3RDPAY) | |
onpay(_mid, true); | |
else | |
onpay(_mid, false); | |
} | |
}); | |
} | |
}; | |
public void pay(final String code) | |
{ | |
Utils.getInstances().pay(this, code, listener); | |
} | |
public void pay_alert(final String title, final String msg, final String code) | |
{ | |
new AlertDialog.Builder(this) | |
.setTitle(title) | |
.setMessage(msg) | |
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface arg0, int arg1) { | |
Utils.getInstances().pay(CCSdkUnipay.this, code, listener); | |
arg0.dismiss(); | |
} | |
}) | |
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface arg0, int arg1) { | |
arg0.dismiss(); | |
} | |
}).show().setCanceledOnTouchOutside(false); | |
} | |
@SuppressLint("HandlerLeak") | |
private Handler _handler = new Handler() { | |
public void handleMessage(Message m) { | |
onmessage(m); | |
} | |
}; | |
public void sendmsg(int what, Object obj) | |
{ | |
_mid = what; | |
Message m = Message.obtain(); | |
m.what = what; | |
m.obj = obj; | |
_handler.sendMessage(m); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment