Changed the sample app's package name

This commit is contained in:
Nelson R. Perez 2018-06-08 18:42:30 -05:00
parent c71d9802ba
commit 7c6dd95f2c
7 changed files with 2 additions and 411 deletions

View file

@ -5,7 +5,7 @@ android {
defaultConfig {
applicationId "com.luminiasoft.labs.sample"
applicationId "cy.agorise.labs.sample"
minSdkVersion 14
targetSdkVersion 26
versionCode 1

View file

@ -1,26 +0,0 @@
package com.luminiasoft.labs.sample;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.luminiasoft.labs.sample", appContext.getPackageName());
}
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.luminiasoft.labs.sample">
package="cy.agorise.labs.sample">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"

View file

@ -1,170 +0,0 @@
package com.luminiasoft.labs.sample;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.gson.Gson;
import java.util.HashMap;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.ConnectionStatusUpdate;
import cy.agorise.graphenej.api.android.NetworkService;
import cy.agorise.graphenej.api.android.RxBus;
import cy.agorise.graphenej.api.calls.GetAccounts;
import cy.agorise.graphenej.api.calls.GetBlock;
import cy.agorise.graphenej.models.JsonRpcResponse;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
public class MainActivity extends AppCompatActivity {
private final String TAG = this.getClass().getName();
@BindView(R.id.connection_status)
TextView mConnectionStatus;
@BindView(R.id.response)
TextView mResponse;
// In case we want to interact directly with the service
private NetworkService mService;
private Gson gson = new Gson();
private Disposable mDisposable;
private HashMap<Long, Integer> responseMap = new HashMap<>();
private final int GET_BLOCK_RESPONSE = 0;
private final int GET_ACCOUNTS_RESPONSE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mDisposable = RxBus.getBusInstance()
.asFlowable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object message) throws Exception {
if(message instanceof String){
Log.d(TAG,"Got text message: "+(message));
mResponse.setText(mResponse.getText() + ((String) message) + "\n");
handleTextMessage((String) message);
}else if(message instanceof ConnectionStatusUpdate){
Log.d(TAG,"Got connection update. Status: "+((ConnectionStatusUpdate)message).getConnectionStatus());
mConnectionStatus.setText(((ConnectionStatusUpdate) message).getConnectionStatus());
}else if(message instanceof JsonRpcResponse){
handleJsonRpcResponse((JsonRpcResponse) message);
}
}
});
}
private void handleTextMessage(String text){
}
/**
* Internal method that will decide what to do with each JSON-RPC response
*
* @param response The JSON-RPC api call response
*/
private void handleJsonRpcResponse(JsonRpcResponse response){
int id = (int) response.id;
if(responseMap.get(id) != null){
int responseId = responseMap.get(id);
switch(responseId){
case GET_BLOCK_RESPONSE:
mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break;
case GET_ACCOUNTS_RESPONSE:
mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
break;
default:
Log.w(TAG,"Case not handled");
}
// Remember to remove the used id entry from the map, as it would
// otherwise just increase the app's memory usage
responseMap.remove(id);
}else{
mResponse.setText(mResponse.getText() + gson.toJson(response, JsonRpcResponse.class) + "\n");
}
}
@OnClick(R.id.call_get_block)
public void onGetBlock(View v){
GetBlock getBlock = new GetBlock(1000000);
long id = mService.sendMessage(getBlock, GetBlock.REQUIRED_API);
// Registering the used sequence id
responseMap.put(id, GET_BLOCK_RESPONSE);
}
@OnClick(R.id.call_get_accounts)
public void onGetAccounts(View v){
GetAccounts getAccounts = new GetAccounts(new UserAccount("1.2.1000"));
long id = mService.sendMessage(getAccounts, GetBlock.REQUIRED_API);
// Registering the used sequence id
responseMap.put(id, GET_ACCOUNTS_RESPONSE);
}
@OnClick(R.id.next_activity)
public void onNextActivity(View v){
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
@Override
protected void onStart() {
super.onStart();
// Bind to LocalService
Intent intent = new Intent(this, NetworkService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onPause() {
super.onPause();
unbindService(mConnection);
}
@Override
protected void onDestroy() {
super.onDestroy();
mDisposable.dispose();
}
/** Defines callbacks for backend binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
Log.d(TAG,"onServiceConnected");
// We've bound to LocalService, cast the IBinder and get LocalService instance
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
mService = binder.getService();
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.d(TAG,"onServiceDisconnected");
}
};
}

View file

@ -1,37 +0,0 @@
package com.luminiasoft.labs.sample;
import android.app.Application;
import android.preference.PreferenceManager;
import cy.agorise.graphenej.api.ApiAccess;
import cy.agorise.graphenej.api.android.NetworkService;
import cy.agorise.graphenej.api.android.NetworkServiceManager;
/**
* Sample application class
*/
public class SampleApplication extends Application {
private final String TAG = this.getClass().getName();
@Override
public void onCreate() {
super.onCreate();
// Specifying some important information regarding the connection, such as the
// credentials and the requested API accesses
int requestedApis = ApiAccess.API_DATABASE | ApiAccess.API_HISTORY | ApiAccess.API_NETWORK_BROADCAST;
PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putString(NetworkService.KEY_USERNAME, "nelson")
.putString(NetworkService.KEY_PASSWORD, "secret")
.putInt(NetworkService.KEY_REQUESTED_APIS, requestedApis)
.apply();
/*
* Registering this class as a listener to all activity's callback cycle events, in order to
* better estimate when the user has left the app and it is safe to disconnect the websocket connection
*/
registerActivityLifecycleCallbacks(new NetworkServiceManager(this));
}
}

View file

@ -1,159 +0,0 @@
package com.luminiasoft.labs.sample;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.common.primitives.UnsignedLong;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.graphenej.Asset;
import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.BaseOperation;
import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.android.NetworkService;
import cy.agorise.graphenej.api.android.RxBus;
import cy.agorise.graphenej.api.calls.GetRequiredFees;
import cy.agorise.graphenej.models.JsonRpcResponse;
import cy.agorise.graphenej.operations.LimitOrderCreateOperation;
import cy.agorise.graphenej.operations.TransferOperation;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
public class SecondActivity extends AppCompatActivity {
private final String TAG = this.getClass().getName();
@BindView(R.id.text_field)
TextView mTextField;
// In case we want to interact directly with the service
private NetworkService mService;
private Gson gson = new Gson();
private Disposable mDisposable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.d(TAG,"onCreate");
ButterKnife.bind(this);
mDisposable = RxBus.getBusInstance()
.asFlowable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Object>() {
@Override
public void accept(Object message) throws Exception {
if(message instanceof String){
Log.d(TAG,"Got text message: "+(message));
mTextField.setText(mTextField.getText() + ((String) message) + "\n");
}else if(message instanceof JsonRpcResponse){
mTextField.setText(mTextField.getText() + gson.toJson(message, JsonRpcResponse.class) + "\n");
}
}
});
}
@Override
protected void onStart() {
super.onStart();
// Bind to LocalService
Intent intent = new Intent(this, NetworkService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onPause() {
super.onPause();
unbindService(mConnection);
}
@Override
protected void onDestroy() {
super.onDestroy();
mDisposable.dispose();
}
/** Defines callbacks for backend binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
Log.d(TAG,"onServiceConnected");
// We've bound to LocalService, cast the IBinder and get LocalService instance
NetworkService.LocalBinder binder = (NetworkService.LocalBinder) service;
mService = binder.getService();
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Log.d(TAG,"onServiceDisconnected");
}
};
@OnClick(R.id.transfer_fee_usd)
public void onTransferFeeUsdClicked(View v){
List<BaseOperation> operations = getTransferOperation();
mService.sendMessage(new GetRequiredFees(operations, new Asset("1.3.121")), GetRequiredFees.REQUIRED_API);
}
@OnClick(R.id.transfer_fee_bts)
public void onTransferFeeBtsClicked(View v){
List<BaseOperation> operations = getTransferOperation();
mService.sendMessage(new GetRequiredFees(operations, new Asset("1.3.0")), GetRequiredFees.REQUIRED_API);
}
@OnClick(R.id.exchange_fee_usd)
public void onExchangeFeeUsdClicked(View v){
List<BaseOperation> operations = getExchangeOperation();
mService.sendMessage(new GetRequiredFees(operations, new Asset("1.3.121")), GetRequiredFees.REQUIRED_API);
}
@OnClick(R.id.exchange_fee_bts)
public void onExchangeFeeBtsClicked(View v){
List<BaseOperation> operations = getExchangeOperation();
mService.sendMessage(new GetRequiredFees(operations, new Asset("1.3.0")), GetRequiredFees.REQUIRED_API);
}
private List<BaseOperation> getTransferOperation(){
TransferOperation transferOperation = new TransferOperation(
new UserAccount("1.2.138632"),
new UserAccount("1.2.129848"),
new AssetAmount(UnsignedLong.ONE, new Asset("1.3.0")));
ArrayList<BaseOperation> operations = new ArrayList();
operations.add(transferOperation);
return operations;
}
public List<BaseOperation> getExchangeOperation() {
LimitOrderCreateOperation operation = new LimitOrderCreateOperation(
new UserAccount("1.2.138632"),
new AssetAmount(UnsignedLong.valueOf(10000), new Asset("1.3.0")),
new AssetAmount(UnsignedLong.valueOf(10), new Asset("1.3.121")),
1000000,
true);
ArrayList<BaseOperation> operations = new ArrayList();
operations.add(operation);
return operations;
}
}

View file

@ -1,17 +0,0 @@
package com.luminiasoft.labs.sample;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}