-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainJavaActivity.java
140 lines (111 loc) · 4.97 KB
/
MainJavaActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package io.eosnova.wallet.android.sdk.sample;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import com.google.gson.JsonObject;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import io.eosnova.wallet.android.sdk.NovaAuth;
import io.eosnova.wallet.android.sdk.OnNovaListener;
import io.eosnova.wallet.android.sdk.model.NovaAction;
import io.eosnova.wallet.android.sdk.model.NovaSignature;
import io.eosnova.wallet.android.sdk.model.NovaStake;
import io.eosnova.wallet.android.sdk.model.NovaTransfer;
public class MainJavaActivity extends AppCompatActivity {
private TextView text;
private OnNovaListener callback = new OnNovaListener() {
@Override
public void callback(@NotNull HashMap<String, String> map) {
text.setText("");
for (String key : map.keySet()) {
text.append(key + ": " + map.get(key) + "\n");
}
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
text = findViewById(R.id.text);
NovaAuth.INSTANCE.setTest(true);
// Account
findViewById(R.id.account).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NovaAuth.INSTANCE.requestAccount(MainJavaActivity.this, callback);
}
});
// Transfer
findViewById(R.id.transfer).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NovaTransfer transfer = new NovaTransfer(
"shinhyo", "eosio.token", "emart",
0.0001, 4, "EOS", "from EOSNOVA"
);
NovaAuth.INSTANCE.requestTransfer(MainJavaActivity.this, transfer, callback);
}
});
// Stake
findViewById(R.id.stake).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NovaStake stake = new NovaStake("shinhyo", NovaStake.Stake.STAKE,
"shinhyo", 1.0, 1.0, false);
NovaAuth.INSTANCE.requestStake(MainJavaActivity.this, stake, callback);
}
});
// UnStake
findViewById(R.id.unskake).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NovaStake stake = new NovaStake("shinhyo", NovaStake.Stake.UNSTAKE,
"shinhyo", 1.0, 1.0, false);
NovaAuth.INSTANCE.requestStake(MainJavaActivity.this, stake, callback);
}
});
// Transcation
findViewById(R.id.transcation).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
JsonObject transferArgs = new JsonObject();
transferArgs.addProperty("from", "shinhyo");
transferArgs.addProperty("to", "emart");
transferArgs.addProperty("quantity", "1.0000 EOS");
transferArgs.addProperty("memo", "test");
NovaAction transfer = new NovaAction("shinhyo",
"eosio.token", "transfer", transferArgs.toString());
JsonObject delegatebwArgs = new JsonObject();
delegatebwArgs.addProperty("from", "shinhyo");
delegatebwArgs.addProperty("receiver", "shinhyo");
delegatebwArgs.addProperty("stake_cpu_quantity", "1.0000 EOS");
delegatebwArgs.addProperty("stake_net_quantity", "1.0000 EOS");
delegatebwArgs.addProperty("transfer", false);
NovaAction delegatebw = new NovaAction("shinhyo",
"eosio", "delegatebw", delegatebwArgs.toString());
ArrayList<NovaAction> list = new ArrayList<>();
list.add(transfer);
list.add(delegatebw);
NovaAuth.INSTANCE.requestTransaction(MainJavaActivity.this, list, callback);
}
});
// Signature
findViewById(R.id.signature).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Gson
JsonObject sigs = new JsonObject();
sigs.addProperty("wallet", "eosnova");
sigs.addProperty("eos", "sample");
NovaSignature signature = new NovaSignature("shinhyo", sigs);
NovaAuth.INSTANCE.requestSignature(MainJavaActivity.this, signature, callback);
}
});
}
}