├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ └── fonts
│ │ │ │ ├── Roboto-Bold.ttf
│ │ │ │ └── Roboto-Regular.ttf
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── hyperledger.png
│ │ │ │ ├── rounded_button.xml
│ │ │ │ ├── rounded_edittext.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── dialog_add_balance.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ ├── dialog_fund_transfer.xml
│ │ │ │ ├── adapter_transaction_layout.xml
│ │ │ │ ├── activity_sign_up.xml
│ │ │ │ └── activity_home.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── ibmhyperlegerblockchain
│ │ │ │ ├── Utils.java
│ │ │ │ ├── model
│ │ │ │ ├── Customer.java
│ │ │ │ ├── Transaction.java
│ │ │ │ └── BankAccount.java
│ │ │ │ ├── fonts
│ │ │ │ ├── TextViewRobotoBold.java
│ │ │ │ └── TextViewRobotoRegular.java
│ │ │ │ ├── constants
│ │ │ │ └── Constants.java
│ │ │ │ ├── adapter
│ │ │ │ └── TransactionAdapter.java
│ │ │ │ ├── activity
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── SignUpActivity.java
│ │ │ │ └── HomeActivity.java
│ │ │ │ └── Webservice.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── ibmhyperlegerblockchain
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── ibmhyperlegerblockchain
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── Screenshots
├── 1.png
├── 2.png
├── 3.png
├── 4.png
└── 5.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── misc.xml
├── runConfigurations.xml
├── gradle.xml
└── codeStyles
│ └── Project.xml
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Screenshots/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/Screenshots/1.png
--------------------------------------------------------------------------------
/Screenshots/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/Screenshots/2.png
--------------------------------------------------------------------------------
/Screenshots/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/Screenshots/3.png
--------------------------------------------------------------------------------
/Screenshots/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/Screenshots/4.png
--------------------------------------------------------------------------------
/Screenshots/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/Screenshots/5.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Roboto-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/assets/fonts/Roboto-Bold.ttf
--------------------------------------------------------------------------------
/app/src/main/res/drawable/hyperledger.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/drawable/hyperledger.png
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/assets/fonts/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | IBM Hyperleger Blockchain
3 | €
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anshumanpattnaik/Android-IBM-Hyperledger-Blockchain-Demo/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 10 21:32:37 EET 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_edittext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000
4 | #000
5 | #D81B60
6 | #335eff
7 | #0a2aa1
8 | #FFF
9 | #000
10 | #7a7a7a
11 | #eaeaea
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/ibmhyperlegerblockchain/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/Utils.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain;
2 |
3 | import java.text.NumberFormat;
4 | import java.util.Currency;
5 | import java.util.Locale;
6 |
7 | public class Utils {
8 | public static String getBalance(double balance){
9 | NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
10 | format.setMaximumFractionDigits(2);
11 | Currency currency = Currency.getInstance("EUR");
12 | format.setCurrency(currency);
13 | String amount = format.format(balance);
14 | return amount;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/model/Customer.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.model;
2 |
3 | public class Customer {
4 | private String $class;
5 | private String customerId;
6 | private String firstName;
7 | private String lastName;
8 |
9 | public String get$class() {
10 | return $class;
11 | }
12 |
13 | public String getCustomerId() {
14 | return customerId;
15 | }
16 |
17 | public String getFirstName() {
18 | return firstName;
19 | }
20 |
21 | public String getLastName() {
22 | return lastName;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/model/Transaction.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.model;
2 |
3 | public class Transaction {
4 | private String transactionId;
5 | private String receiverName;
6 | private double amount;
7 |
8 | public String getTransactionId() {
9 | return transactionId;
10 | }
11 |
12 | public void setTransactionId(String transactionId) {
13 | this.transactionId = transactionId;
14 | }
15 |
16 | public String getReceiverName() {
17 | return receiverName;
18 | }
19 |
20 | public void setReceiverName(String receiverName) {
21 | this.receiverName = receiverName;
22 | }
23 |
24 | public double getAmount() {
25 | return amount;
26 | }
27 |
28 | public void setAmount(double amount) {
29 | this.amount = amount;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/ibmhyperlegerblockchain/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.ibmhyperlegerblockchain", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/model/BankAccount.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.model;
2 |
3 | public class BankAccount {
4 |
5 | private String $class;
6 | private String customer;
7 | private String accountId;
8 | private int balance;
9 |
10 | public String get$class() {
11 | return $class;
12 | }
13 |
14 | public void set$class(String $class) {
15 | this.$class = $class;
16 | }
17 |
18 | public String getCustomer() {
19 | return customer;
20 | }
21 |
22 | public void setCustomer(String customer) {
23 | this.customer = customer;
24 | }
25 |
26 | public String getAccountId() {
27 | return accountId;
28 | }
29 |
30 | public void setAccountId(String accountId) {
31 | this.accountId = accountId;
32 | }
33 |
34 | public int getBalance() {
35 | return balance;
36 | }
37 |
38 | public void setBalance(int balance) {
39 | this.balance = balance;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-IBM-Hyperledger-Blockchain-Demo
2 |
3 | ## Overview
4 | This is a sample demonstration of IBM-Hyperledger-Blockchain platform, this is an application UI which will communicate to Blockchain Rest API, you can find the repository link for Rest-API.
5 |
6 | # Blockchain Rest API Repository Link
7 | [https://github.com/anshumanpattnaik/IBM-Hyperledger-Blockchain-Demo-using-Node.js.git](https://github.com/anshumanpattnaik/IBM-Hyperledger-Blockchain-Demo-using-Node.js.git)
8 |
9 | # Application Demo
10 |
11 |
12 |

13 |
14 |
15 |
16 |

17 |
18 |
19 |
20 |

21 |
22 |
23 |
24 |

25 |
26 |
27 |
28 |

29 |
30 |
31 |
32 | ## IBM Blockchain Concepts Overview
33 | - [https://ibm-blockchain.github.io/develop/](https://ibm-blockchain.github.io/develop/).
34 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
17 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/fonts/TextViewRobotoBold.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.fonts;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Typeface;
6 | import android.util.AttributeSet;
7 | import android.widget.TextView;
8 |
9 | @SuppressLint("AppCompatCustomView")
10 | public class TextViewRobotoBold extends TextView {
11 |
12 | public TextViewRobotoBold(Context context) {
13 | super(context);
14 | init(context);
15 | }
16 |
17 | public TextViewRobotoBold(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | init(context);
20 | }
21 |
22 | public TextViewRobotoBold(Context context, AttributeSet attrs, int defStyleAttr) {
23 | super(context, attrs, defStyleAttr);
24 | init(context);
25 | }
26 |
27 | public TextViewRobotoBold(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
28 | super(context, attrs, defStyleAttr, defStyleRes);
29 | init(context);
30 | }
31 |
32 | private void init(Context context){
33 | Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf");
34 | setTypeface(typeface);
35 | }
36 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.ibmhyperlegerblockchain"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | implementation 'com.android.support:recyclerview-v7:28.0.0'
26 | implementation 'com.google.code.gson:gson:2.8.5'
27 | implementation 'com.android.volley:volley:1.1.0'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31 | implementation 'org.jetbrains:annotations-java5:15.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/fonts/TextViewRobotoRegular.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.fonts;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.Typeface;
6 | import android.util.AttributeSet;
7 | import android.widget.TextView;
8 |
9 | @SuppressLint("AppCompatCustomView")
10 | public class TextViewRobotoRegular extends TextView {
11 |
12 | public TextViewRobotoRegular(Context context) {
13 | super(context);
14 | init(context);
15 | }
16 |
17 | public TextViewRobotoRegular(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | init(context);
20 | }
21 |
22 | public TextViewRobotoRegular(Context context, AttributeSet attrs, int defStyleAttr) {
23 | super(context, attrs, defStyleAttr);
24 | init(context);
25 | }
26 |
27 | public TextViewRobotoRegular(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
28 | super(context, attrs, defStyleAttr, defStyleRes);
29 | init(context);
30 | }
31 |
32 | private void init(Context context){
33 | Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
34 | setTypeface(typeface);
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/constants/Constants.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.constants;
2 |
3 | public class Constants {
4 | public static final String LOG_TAG = "IBM_Hyperledger";
5 | public static final String PLEASE_WAIT = "Please wait";
6 |
7 | /**
8 | * Customer Keys
9 | */
10 | public static final String CUSTOMER_CLASS = "customer_class";
11 | public static final String CUSTOMER_ID = "customer_id";
12 | public static final String CUSTOMER_NAME = "customer_name";
13 |
14 | /**
15 | * Bank Account
16 | */
17 | public static final String isAccount = "is_account";
18 | public static final String BALANCE = "balance";
19 |
20 | /**
21 | * Transaction
22 | */
23 | public static final String TRANSACTION_ID = "transaction_id";
24 |
25 | /**
26 | * Hyperledger Classes
27 | */
28 | public static final String CUSTOMER = "org.samplebanking.network.Customer";
29 | public static final String BANK_ACCOUNT = "org.samplebanking.network.bankAccount";
30 | public static final String TRANSFER_AMOUNT = "org.samplebanking.network.transferAmount";
31 |
32 | /**
33 | * Tags
34 | */
35 | public static final String CUSTOMER_TAG = "resource:org.samplebanking.network.Customer#";
36 | public static final String BANK_ACCOUNT_TAG = "resource:org.samplebanking.network.bankAccount#";
37 |
38 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_add_balance.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
36 |
37 |
38 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
38 |
39 |
40 |
50 |
51 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_fund_transfer.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
35 |
36 |
51 |
52 |
53 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/adapter/TransactionAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.adapter;
2 |
3 | import android.graphics.Color;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.RelativeLayout;
9 | import android.widget.TextView;
10 |
11 | import com.example.ibmhyperlegerblockchain.R;
12 | import com.example.ibmhyperlegerblockchain.model.Transaction;
13 |
14 | import java.util.ArrayList;
15 |
16 | import static com.example.ibmhyperlegerblockchain.Utils.getBalance;
17 |
18 | public class TransactionAdapter extends RecyclerView.Adapter {
19 |
20 | private ArrayList mTransactions;
21 |
22 | public TransactionAdapter(ArrayList transactionsList) {
23 | this.mTransactions = transactionsList;
24 | }
25 |
26 | public class TransactionViewHolder extends RecyclerView.ViewHolder {
27 | private RelativeLayout transactionLayout;
28 | public TextView transactionIdTxt, receiverNameTxt, amountTxt;
29 |
30 | public TransactionViewHolder(View view) {
31 | super(view);
32 | transactionLayout = (RelativeLayout) view.findViewById(R.id.transcations_layout);
33 | transactionIdTxt = (TextView) view.findViewById(R.id.transcation_txt);
34 | receiverNameTxt = (TextView) view.findViewById(R.id.receiver_txt);
35 | amountTxt = (TextView) view.findViewById(R.id.amount_txt);
36 | }
37 | }
38 |
39 | @Override
40 | public TransactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
41 | View itemView = LayoutInflater.from(parent.getContext())
42 | .inflate(R.layout.adapter_transaction_layout, parent, false);
43 |
44 | return new TransactionViewHolder(itemView);
45 | }
46 |
47 | @Override
48 | public void onBindViewHolder(TransactionViewHolder holder, int position) {
49 |
50 | if(position%2 == 0){
51 | holder.transactionLayout.setBackgroundColor(Color.parseColor("#f2f2f2"));
52 | }else{
53 | holder.transactionLayout.setBackgroundColor(Color.parseColor("#ffffff"));
54 | }
55 |
56 | holder.transactionIdTxt.setText(mTransactions.get(position).getTransactionId());
57 | holder.receiverNameTxt.setText(mTransactions.get(position).getReceiverName());
58 | holder.amountTxt.setText(getBalance(mTransactions.get(position).getAmount()));
59 | }
60 |
61 | @Override
62 | public int getItemCount() {
63 | return mTransactions.size();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_transaction_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
28 |
29 |
30 |
31 |
32 |
38 |
39 |
47 |
48 |
49 |
50 |
51 |
56 |
57 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sign_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
30 |
31 |
37 |
38 |
50 |
51 |
65 |
66 |
80 |
81 |
82 |
92 |
93 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/activity/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.activity;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.os.AsyncTask;
7 | import android.preference.PreferenceManager;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import com.example.ibmhyperlegerblockchain.constants.Constants;
17 | import com.example.ibmhyperlegerblockchain.R;
18 | import com.example.ibmhyperlegerblockchain.Webservice;
19 | import com.example.ibmhyperlegerblockchain.model.Customer;
20 | import com.google.gson.Gson;
21 |
22 | import static com.example.ibmhyperlegerblockchain.constants.Constants.LOG_TAG;
23 |
24 | public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
25 |
26 | private EditText mCustomerIdEtd;
27 | private Button mLoginBtn, mSignUpBtn;
28 |
29 | private String mCustomerId;
30 |
31 | private SharedPreferences prefs;
32 |
33 | private ProgressDialog dialog;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_login);
39 |
40 | getSupportActionBar().hide();
41 |
42 | dialog = new ProgressDialog(this);
43 |
44 | mCustomerIdEtd = (EditText) findViewById(R.id.customer_id_etd);
45 | mLoginBtn = (Button) findViewById(R.id.login_btn);
46 | mSignUpBtn = (Button) findViewById(R.id.signup_btn);
47 |
48 | prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
49 |
50 | if(prefs.getString(Constants.CUSTOMER_NAME,null)!=null){
51 | Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
52 | startActivity(intent);
53 | finish();
54 | }
55 |
56 | mLoginBtn.setOnClickListener(this);
57 | mSignUpBtn.setOnClickListener(this);
58 | }
59 |
60 | @Override
61 | public void onClick(View v) {
62 | switch (v.getId()){
63 | case R.id.login_btn:
64 | mCustomerId = mCustomerIdEtd.getText().toString();
65 | if(mCustomerId.length() > 0){
66 | new LoginTask().execute();
67 | }else{
68 | Toast.makeText(getApplicationContext(), "Field Cannot be blank", Toast.LENGTH_SHORT).show();
69 | }
70 | break;
71 | case R.id.signup_btn:
72 | Intent signUpIntent = new Intent(this, SignUpActivity.class);
73 | startActivity(signUpIntent);
74 | break;
75 | default:
76 | break;
77 | }
78 | }
79 |
80 | private class LoginTask extends AsyncTask {
81 |
82 | @Override
83 | protected void onPreExecute() {
84 | super.onPreExecute();
85 | dialog.setMessage(Constants.PLEASE_WAIT);
86 | dialog.setCancelable(false);
87 | dialog.show();
88 | }
89 |
90 | @Override
91 | protected String doInBackground(String... strings) {
92 | String response = null;
93 |
94 | Webservice webservice = new Webservice();
95 | response = webservice.getRequest(Webservice.BASE_URL+Webservice.CUSTOMER_SIGN_UP+"/"+mCustomerId);
96 |
97 | return response;
98 | }
99 |
100 | @Override
101 | protected void onPostExecute(String result) {
102 | super.onPostExecute(result);
103 | if (dialog.isShowing()) {
104 | dialog.dismiss();
105 | }
106 |
107 | String response = result.replaceAll("\r", "");
108 |
109 | try{
110 | Gson gson = new Gson();
111 | Customer customer = gson.fromJson(response, Customer.class);
112 |
113 | Log.d(LOG_TAG , "onPostExecute : "+response+" --- "+customer.getCustomerId());
114 |
115 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
116 | SharedPreferences.Editor editor = prefs.edit();
117 | editor.putString(Constants.CUSTOMER_CLASS, customer.get$class());
118 | editor.putString(Constants.CUSTOMER_ID, customer.getCustomerId());
119 | editor.putString(Constants.CUSTOMER_NAME, customer.getFirstName()+" "+customer.getLastName());
120 | editor.commit();
121 |
122 | Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
123 | startActivity(intent);
124 | finish();
125 | }catch (Exception e){
126 | Toast.makeText(getApplicationContext(), "Wrong Customer Id", Toast.LENGTH_SHORT).show();
127 | }
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/activity/SignUpActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.activity;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.os.AsyncTask;
7 | import android.preference.PreferenceManager;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.os.Bundle;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import com.example.ibmhyperlegerblockchain.constants.Constants;
17 | import com.example.ibmhyperlegerblockchain.R;
18 | import com.example.ibmhyperlegerblockchain.Webservice;
19 | import com.example.ibmhyperlegerblockchain.model.Customer;
20 | import com.google.gson.Gson;
21 |
22 | import org.json.JSONException;
23 | import org.json.JSONObject;
24 |
25 | import static com.example.ibmhyperlegerblockchain.constants.Constants.LOG_TAG;
26 |
27 | public class SignUpActivity extends AppCompatActivity implements View.OnClickListener {
28 |
29 | private EditText mCustomerEtd, mFirstNameEtd, mLastNameEtd;
30 | private Button mCreateBtn, mBackBtn;
31 |
32 | private String mCustomerId, mFirstName, mLastName;
33 |
34 | private ProgressDialog dialog;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_sign_up);
40 | getSupportActionBar().hide();
41 |
42 | dialog = new ProgressDialog(this);
43 |
44 | mCustomerEtd = (EditText) findViewById(R.id.customer_id_etd);
45 | mFirstNameEtd = (EditText) findViewById(R.id.customer_fname_etd);
46 | mLastNameEtd = (EditText) findViewById(R.id.customer_lname_etd);
47 | mCreateBtn = (Button) findViewById(R.id.create_btn);
48 | mBackBtn = (Button) findViewById(R.id.back_btn);
49 |
50 | mCreateBtn.setOnClickListener(this);
51 | mBackBtn.setOnClickListener(this);
52 | }
53 |
54 | @Override
55 | public void onClick(View v) {
56 | switch (v.getId()){
57 | case R.id.create_btn:
58 | mCustomerId = mCustomerEtd.getText().toString();
59 | mFirstName = mFirstNameEtd.getText().toString();
60 | mLastName = mLastNameEtd.getText().toString();
61 |
62 | if(mCustomerId.length() > 0 && mFirstName.length() > 0 && mLastName.length() > 0){
63 | new CreateAccountTask().execute();
64 | }else{
65 | Toast.makeText(getApplicationContext(), "Field Cannot be blank", Toast.LENGTH_SHORT).show();
66 | }
67 | break;
68 | case R.id.back_btn:
69 | Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
70 | startActivity(intent);
71 | finish();
72 | break;
73 | default:
74 | break;
75 | }
76 | }
77 |
78 | private class CreateAccountTask extends AsyncTask {
79 |
80 | private String response;
81 |
82 | @Override
83 | protected void onPreExecute() {
84 | super.onPreExecute();
85 | dialog.setMessage(Constants.PLEASE_WAIT);
86 | dialog.setCancelable(false);
87 | dialog.show();
88 | }
89 |
90 | @Override
91 | protected String doInBackground(String... strings) {
92 |
93 | JSONObject jsonObject = new JSONObject();
94 | try {
95 | jsonObject.put("$class", Constants.CUSTOMER);
96 | jsonObject.put("customerId", mCustomerId);
97 | jsonObject.put("firstName", mFirstName);
98 | jsonObject.put("lastName", mLastName);
99 |
100 | Webservice Webservice = new Webservice();
101 | response = Webservice.postRequest(Webservice.BASE_URL+Webservice.CUSTOMER_SIGN_UP, jsonObject.toString());
102 |
103 | } catch (JSONException e) {
104 | }
105 | return response;
106 | }
107 |
108 | @Override
109 | protected void onPostExecute(String result) {
110 | super.onPostExecute(result);
111 | if (dialog.isShowing()) {
112 | dialog.dismiss();
113 | }
114 | Log.d(LOG_TAG, "onPostExecute : "+result);
115 |
116 | String response = result.replaceAll("\r", "");
117 |
118 | try{
119 | Gson gson = new Gson();
120 | Customer customer = gson.fromJson(response, Customer.class);
121 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
122 | SharedPreferences.Editor editor = prefs.edit();
123 | editor.putString(Constants.CUSTOMER_CLASS, customer.get$class());
124 | editor.putString(Constants.CUSTOMER_ID, customer.getCustomerId());
125 | editor.putString(Constants.CUSTOMER_NAME, customer.getFirstName()+" "+customer.getLastName());
126 | editor.commit();
127 |
128 | Intent intent = new Intent(SignUpActivity.this, HomeActivity.class);
129 | startActivity(intent);
130 | finish();
131 | }catch (Exception e){
132 | }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/Webservice.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.DataOutputStream;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 |
12 | import static com.example.ibmhyperlegerblockchain.constants.Constants.LOG_TAG;
13 |
14 | public class Webservice {
15 | public static final String BASE_URL = "http://YOUR_LOCAL_ADDRESS/api";
16 |
17 | public static final String CUSTOMER_SIGN_UP = "/Customer";
18 | public static final String ADD_BALANCE = "/bankAccount";
19 | public static final String TRANSFER_AMOUNT = "/transferAmount";
20 |
21 |
22 | public String postRequest(String basUrl, String jsonParam){
23 |
24 | Log.d(LOG_TAG , "postRequest : "+basUrl+" -- "+jsonParam);
25 |
26 | String response = "";
27 |
28 | try {
29 | URL url = new URL(basUrl);
30 | HttpURLConnection connection = (HttpURLConnection) url.openConnection();
31 | connection.setDoOutput(true);
32 | connection.setDoInput(true);
33 | connection.setInstanceFollowRedirects(false);
34 | connection.setRequestMethod("POST");
35 | connection.setRequestProperty("Content-Type", "application/json");
36 | connection.setRequestProperty("charset", "utf-8");
37 | connection.setUseCaches (false);
38 |
39 | DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
40 | wr.writeBytes(jsonParam.toString());
41 |
42 | wr.flush();
43 | wr.close();
44 |
45 | BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
46 |
47 | String output;
48 | StringBuilder stringBuilder = new StringBuilder();
49 | while ((output = br.readLine()) != null) {
50 | stringBuilder.append(output);
51 | stringBuilder.append('\r');
52 | }
53 | response = stringBuilder.toString();
54 |
55 | Log.d(LOG_TAG , String.valueOf(connection.getResponseCode())+" -- "+response);
56 |
57 | connection.disconnect();
58 |
59 |
60 | } catch (Exception e) {
61 | Log.d(LOG_TAG , "Exception : "+e.toString());
62 | }
63 |
64 | return response;
65 | }
66 |
67 | public String putRequest(String basUrl, String jsonParam){
68 |
69 | Log.d(LOG_TAG , "putRequest : "+basUrl+" -- "+jsonParam);
70 |
71 | String response = "";
72 |
73 | try {
74 | URL url = new URL(basUrl);
75 | HttpURLConnection connection = (HttpURLConnection) url.openConnection();
76 | connection.setDoOutput(true);
77 | connection.setDoInput(true);
78 | connection.setInstanceFollowRedirects(false);
79 | connection.setRequestMethod("PUT");
80 | connection.setRequestProperty("Content-Type", "application/json");
81 | connection.setRequestProperty("charset", "utf-8");
82 | connection.setUseCaches (false);
83 |
84 | DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
85 | wr.writeBytes(jsonParam.toString());
86 |
87 | wr.flush();
88 | wr.close();
89 |
90 | BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
91 |
92 | String output;
93 | StringBuilder stringBuilder = new StringBuilder();
94 | while ((output = br.readLine()) != null) {
95 | stringBuilder.append(output);
96 | stringBuilder.append('\r');
97 | }
98 | response = stringBuilder.toString();
99 |
100 | Log.d(LOG_TAG , String.valueOf(connection.getResponseCode())+" -- "+response);
101 |
102 | connection.disconnect();
103 |
104 |
105 | } catch (Exception e) {
106 | Log.d(LOG_TAG , "Exception : "+e.toString());
107 | }
108 |
109 | return response;
110 | }
111 |
112 |
113 | public String getRequest(String basUrl){
114 |
115 | Log.d(LOG_TAG , "getRequest : "+basUrl);
116 |
117 | String response = "Wrong Customer Id";
118 |
119 | HttpURLConnection urlConnection = null;
120 | try {
121 | URL url = new URL(basUrl);
122 |
123 | urlConnection = (HttpURLConnection) url.openConnection();
124 |
125 | InputStream in = urlConnection.getInputStream();
126 |
127 | InputStreamReader isw = new InputStreamReader(in);
128 |
129 | int data = isw.read();
130 | StringBuilder stringBuilder = new StringBuilder();
131 | while (data != -1) {
132 | char current = (char) data;
133 | data = isw.read();
134 | stringBuilder.append(current);
135 | stringBuilder.append('\r');
136 | }
137 | response = stringBuilder.toString();
138 | Log.d(LOG_TAG , "getRequest : "+stringBuilder.toString());
139 | } catch (Exception e) {
140 | Log.d(LOG_TAG , "Exception getRequest : "+e.toString());
141 | } finally {
142 | if (urlConnection != null) {
143 | urlConnection.disconnect();
144 | }
145 | }
146 |
147 | return response;
148 | }
149 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
26 |
27 |
39 |
40 |
52 |
53 |
54 |
55 |
62 |
63 |
68 |
69 |
76 |
77 |
86 |
87 |
96 |
97 |
98 |
99 |
105 |
106 |
110 |
111 |
123 |
124 |
125 |
126 |
127 |
133 |
134 |
144 |
145 |
146 |
147 |
148 |
153 |
154 |
164 |
165 |
166 |
167 |
168 |
169 |
175 |
176 |
180 |
181 |
182 |
183 |
194 |
195 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/ibmhyperlegerblockchain/activity/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.ibmhyperlegerblockchain.activity;
2 |
3 | import android.app.Dialog;
4 | import android.app.ProgressDialog;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.os.AsyncTask;
8 | import android.preference.PreferenceManager;
9 | import android.support.v4.widget.SwipeRefreshLayout;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.os.Bundle;
12 | import android.support.v7.widget.DefaultItemAnimator;
13 | import android.support.v7.widget.LinearLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.util.Log;
16 | import android.view.View;
17 | import android.view.Window;
18 | import android.widget.Button;
19 | import android.widget.EditText;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import com.example.ibmhyperlegerblockchain.constants.Constants;
24 | import com.example.ibmhyperlegerblockchain.R;
25 | import com.example.ibmhyperlegerblockchain.Webservice;
26 | import com.example.ibmhyperlegerblockchain.adapter.TransactionAdapter;
27 | import com.example.ibmhyperlegerblockchain.model.BankAccount;
28 | import com.example.ibmhyperlegerblockchain.model.Transaction;
29 | import com.google.gson.Gson;
30 |
31 | import org.json.JSONArray;
32 | import org.json.JSONException;
33 | import org.json.JSONObject;
34 |
35 | import java.util.ArrayList;
36 |
37 | import static com.example.ibmhyperlegerblockchain.constants.Constants.LOG_TAG;
38 | import static com.example.ibmhyperlegerblockchain.Utils.getBalance;
39 |
40 | public class HomeActivity extends AppCompatActivity implements View.OnClickListener {
41 |
42 | private RecyclerView mTransactionListView;
43 | private Button mFundTransferBtn;
44 | private TextView mBalanceTxt, mCustomerNameTxt, mLogoutBtn, mAddBalanceBtn;
45 |
46 | private TransactionAdapter mAdapter;
47 |
48 | private ArrayList mTransactions;
49 |
50 | private SharedPreferences prefs;
51 |
52 | private String mTransactionId;
53 | private String mCustomerId;
54 | private String mCustomerName;
55 | private String mReceiverId;
56 |
57 | private double mBalance;
58 | private String mTransferAmount;
59 |
60 | private String mBalanceValue;
61 |
62 | private ProgressDialog dialog;
63 |
64 | private SwipeRefreshLayout mSwipeRefreshLayout;
65 |
66 | @Override
67 | protected void onCreate(Bundle savedInstanceState) {
68 | super.onCreate(savedInstanceState);
69 | setContentView(R.layout.activity_home);
70 |
71 | getSupportActionBar().hide();
72 |
73 | dialog = new ProgressDialog(this);
74 |
75 | prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
76 |
77 | mTransactionListView = (RecyclerView) findViewById(R.id.transcation_list);
78 | mBalanceTxt = (TextView) findViewById(R.id.balance_txt);
79 | mCustomerNameTxt = (TextView) findViewById(R.id.customer_name);
80 | mAddBalanceBtn = (TextView) findViewById(R.id.add_money_btn);
81 | mLogoutBtn = (TextView) findViewById(R.id.logout_btn);
82 | mFundTransferBtn = (Button)findViewById(R.id.money_transfer_btn);
83 | mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
84 |
85 | mBalance = prefs.getFloat(Constants.BALANCE, 0);
86 |
87 | new FetchTransactionTask().execute();
88 |
89 | if(mBalance > 0){
90 | setBalance(mBalanceTxt, mBalance);
91 | }else{
92 | new FetchBalance().execute();
93 | }
94 |
95 | mTransactionId = prefs.getString(Constants.TRANSACTION_ID, null);
96 | mCustomerName = prefs.getString(Constants.CUSTOMER_NAME, null);
97 | mCustomerId = prefs.getString(Constants.CUSTOMER_ID, null);
98 |
99 | mCustomerNameTxt.setText(mCustomerName);
100 |
101 | mTransactions = new ArrayList<>();
102 |
103 | setTransactionAdapter();
104 |
105 | mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
106 | @Override
107 | public void onRefresh() {
108 | new FetchBalance().execute();
109 | new FetchTransactionTask().execute();
110 | mSwipeRefreshLayout.setRefreshing(false);
111 | }
112 | });
113 |
114 | mAddBalanceBtn.setOnClickListener(this);
115 | mLogoutBtn.setOnClickListener(this);
116 | mFundTransferBtn.setOnClickListener(this);
117 | }
118 |
119 | @Override
120 | public void onClick(View v) {
121 | switch (v.getId()){
122 | case R.id.add_money_btn:
123 | final Dialog addBalanceDialog = new Dialog(this);
124 | addBalanceDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
125 | addBalanceDialog.setContentView(R.layout.dialog_add_balance);
126 |
127 | final EditText balanceTxt = (EditText) addBalanceDialog.findViewById(R.id.add_amount_etd);
128 | Button addBalanceBtn = (Button) addBalanceDialog.findViewById(R.id.add_balance_btn);
129 |
130 | addBalanceBtn.setOnClickListener(new View.OnClickListener() {
131 | @Override
132 | public void onClick(View v) {
133 | mBalanceValue = balanceTxt.getText().toString();
134 | if(mBalanceValue.length() > 0){
135 | boolean isAccount = prefs.getBoolean(Constants.isAccount, false);
136 | if(isAccount){
137 | new UpdateBalanceTask().execute();
138 | }else{
139 | new AddBalanceTask().execute();
140 | }
141 | addBalanceDialog.dismiss();
142 | }else{
143 | Toast.makeText(HomeActivity.this, "Field cannot be blank", Toast.LENGTH_SHORT).show();
144 | }
145 | }
146 | });
147 |
148 | addBalanceDialog.show();
149 | break;
150 | case R.id.money_transfer_btn:
151 | final Dialog dialog = new Dialog(this);
152 | dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
153 | dialog.setContentView(R.layout.dialog_fund_transfer);
154 |
155 | final EditText receiverAccountEtd = (EditText) dialog.findViewById(R.id.customer_account_etd);
156 | final EditText transferAmountEtd = (EditText) dialog.findViewById(R.id.amount_etd);
157 | Button transferBtn = (Button) dialog.findViewById(R.id.transfer_btn);
158 |
159 | transferBtn.setOnClickListener(new View.OnClickListener() {
160 | @Override
161 | public void onClick(View v) {
162 | mReceiverId = receiverAccountEtd.getText().toString();
163 | mTransferAmount = transferAmountEtd.getText().toString();
164 |
165 | double currentBalance = prefs.getFloat(Constants.BALANCE, 0);
166 |
167 | if(mReceiverId.length() > 0 && mTransferAmount.length() > 0){
168 | if(!mReceiverId.contains(mCustomerId)){
169 | if(currentBalance >= Double.parseDouble(mTransferAmount)){
170 | new TransferBalanceTask().execute();
171 | dialog.dismiss();
172 | }else{
173 | Toast.makeText(HomeActivity.this, "Not enough balance to send", Toast.LENGTH_SHORT).show();
174 | }
175 | }else{
176 | Toast.makeText(HomeActivity.this, "Invalid Id", Toast.LENGTH_SHORT).show();
177 | }
178 | }else{
179 | Toast.makeText(HomeActivity.this, "Field cannot be blank", Toast.LENGTH_SHORT).show();
180 | }
181 | }
182 | });
183 |
184 | dialog.show();
185 | break;
186 | case R.id.logout_btn:
187 | SharedPreferences.Editor editor = prefs.edit();
188 | editor.clear();
189 | editor.commit();
190 |
191 | Intent intent = new Intent(HomeActivity.this, LoginActivity.class);
192 | startActivity(intent);
193 | finish();
194 | break;
195 | default:
196 | break;
197 | }
198 | }
199 |
200 | private void setTransactionAdapter(){
201 | mAdapter = new TransactionAdapter(mTransactions);
202 | RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
203 | mTransactionListView.setLayoutManager(mLayoutManager);
204 | mTransactionListView.setItemAnimator(new DefaultItemAnimator());
205 | mTransactionListView.setAdapter(mAdapter);
206 | }
207 |
208 | private class FetchTransactionTask extends AsyncTask {
209 |
210 | private String response;
211 |
212 | @Override
213 | protected void onPreExecute() {
214 | super.onPreExecute();
215 | dialog.setMessage(Constants.PLEASE_WAIT);
216 | dialog.setCancelable(false);
217 | dialog.show();
218 | }
219 |
220 | @Override
221 | protected String doInBackground(String... strings) {
222 |
223 | Webservice webservice = new Webservice();
224 | response = webservice.getRequest(Webservice.BASE_URL+Webservice.TRANSFER_AMOUNT);
225 |
226 | return response;
227 | }
228 |
229 | @Override
230 | protected void onPostExecute(String result) {
231 | super.onPostExecute(result);
232 | if (dialog.isShowing()) {
233 | dialog.dismiss();
234 | }
235 | Log.d(LOG_TAG, "onPostExecute : "+result);
236 |
237 | mTransactions.clear();
238 |
239 | String response = result.replaceAll("\r", "");
240 |
241 | try{
242 | JSONArray jsonarray = new JSONArray(response);
243 | for (int i = 0; i < jsonarray.length(); i++) {
244 | JSONObject jsonObject = jsonarray.getJSONObject(i);
245 | String transactionId = jsonObject.getString("transactionId");
246 | String senderAccountId = jsonObject.getString("from");
247 | String receiverAccountId = jsonObject.getString("to");
248 | double amount = jsonObject.getDouble("amount");
249 |
250 | String senderId = senderAccountId.replace(Constants.BANK_ACCOUNT_TAG, "");
251 | String receiverId = receiverAccountId.replace(Constants.BANK_ACCOUNT_TAG,"");
252 |
253 | if(mCustomerId.equals(senderId)){
254 | Log.d(LOG_TAG, "senderId : "+senderId+" -- "+receiverId+" -- "+amount);
255 | Transaction transaction = new Transaction();
256 | transaction.setTransactionId(transactionId);
257 | transaction.setReceiverName(receiverId);
258 | transaction.setAmount(amount);
259 | mTransactions.add(transaction);
260 | }
261 | setTransactionAdapter();
262 | }
263 | }catch (Exception e){
264 | }
265 | }
266 | }
267 |
268 | private class FetchBalance extends AsyncTask {
269 |
270 | private String response;
271 |
272 | @Override
273 | protected void onPreExecute() {
274 | super.onPreExecute();
275 | dialog.setMessage(Constants.PLEASE_WAIT);
276 | dialog.setCancelable(false);
277 | dialog.show();
278 | }
279 |
280 | @Override
281 | protected String doInBackground(String... strings) {
282 |
283 | Webservice webservice = new Webservice();
284 | response = webservice.getRequest(Webservice.BASE_URL+Webservice.ADD_BALANCE+"/"+mCustomerId);
285 |
286 | return response;
287 | }
288 |
289 | @Override
290 | protected void onPostExecute(String result) {
291 | super.onPostExecute(result);
292 | if (dialog.isShowing()) {
293 | dialog.dismiss();
294 | }
295 | Log.d(LOG_TAG, "onPostExecute : "+result);
296 |
297 | String response = result.replaceAll("\r", "");
298 |
299 | try{
300 | Gson gson = new Gson();
301 | BankAccount bankAccount = gson.fromJson(response, BankAccount.class);
302 | Log.d(LOG_TAG , "onPostExecute : "+response+" --- "+bankAccount.getBalance());
303 |
304 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
305 | SharedPreferences.Editor editor = prefs.edit();
306 | editor.putBoolean(Constants.isAccount, true);
307 | editor.putFloat(Constants.BALANCE, bankAccount.getBalance());
308 | editor.commit();
309 |
310 | double currentBalance = prefs.getFloat(Constants.BALANCE, 0);
311 | double totalBalance = bankAccount.getBalance();
312 |
313 | setBalance(mBalanceTxt, totalBalance);
314 |
315 | }catch (Exception e){
316 | }
317 | }
318 | }
319 |
320 | private class AddBalanceTask extends AsyncTask {
321 |
322 | private String response;
323 |
324 | @Override
325 | protected void onPreExecute() {
326 | super.onPreExecute();
327 | dialog.setMessage(Constants.PLEASE_WAIT);
328 | dialog.setCancelable(false);
329 | dialog.show();
330 | }
331 |
332 | @Override
333 | protected String doInBackground(String... strings) {
334 |
335 | JSONObject balanceObject = new JSONObject();
336 | try {
337 | balanceObject.put("$class", Constants.BANK_ACCOUNT_TAG);
338 | balanceObject.put("customer", Constants.CUSTOMER_TAG+mCustomerId);
339 | balanceObject.put("accountId", mCustomerId);
340 | balanceObject.put("balance", Double.parseDouble(mBalanceValue));
341 |
342 | Log.d(Constants.LOG_TAG, ""+balanceObject);
343 |
344 | Webservice webservice = new Webservice();
345 | response = webservice.postRequest(Webservice.BASE_URL+Webservice.ADD_BALANCE, balanceObject.toString());
346 |
347 | } catch (JSONException e) {
348 | }
349 |
350 | return response;
351 | }
352 |
353 | @Override
354 | protected void onPostExecute(String result) {
355 | super.onPostExecute(result);
356 | if (dialog.isShowing()) {
357 | dialog.dismiss();
358 | }
359 | Log.d(LOG_TAG, "onPostExecute : "+result);
360 |
361 | String response = result.replaceAll("\r", "");
362 |
363 | try{
364 | Gson gson = new Gson();
365 | BankAccount bankAccount = gson.fromJson(response, BankAccount.class);
366 | Log.d(LOG_TAG , "onPostExecute : "+response+" --- "+bankAccount.getBalance());
367 |
368 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
369 | SharedPreferences.Editor editor = prefs.edit();
370 | editor.putBoolean(Constants.isAccount, true);
371 | editor.putFloat(Constants.BALANCE, bankAccount.getBalance());
372 | editor.commit();
373 |
374 | setBalance(mBalanceTxt, bankAccount.getBalance());
375 |
376 | }catch (Exception e){
377 | }
378 | }
379 | }
380 |
381 | private class UpdateBalanceTask extends AsyncTask {
382 |
383 | private String response;
384 |
385 | @Override
386 | protected void onPreExecute() {
387 | super.onPreExecute();
388 | dialog.setMessage(Constants.PLEASE_WAIT);
389 | dialog.setCancelable(false);
390 | dialog.show();
391 | }
392 |
393 | @Override
394 | protected String doInBackground(String... strings) {
395 |
396 | JSONObject balanceObject = new JSONObject();
397 | try {
398 | balanceObject.put("$class", Constants.BANK_ACCOUNT);
399 | balanceObject.put("customer", Constants.CUSTOMER_TAG+mCustomerId);
400 |
401 | double currentBalance = prefs.getFloat(Constants.BALANCE, 0);
402 | balanceObject.put("balance", currentBalance + Double.parseDouble(mBalanceValue));
403 |
404 | Log.d(Constants.LOG_TAG, ""+balanceObject);
405 |
406 | Webservice webservice = new Webservice();
407 | response = webservice.putRequest(Webservice.BASE_URL+Webservice.ADD_BALANCE+"/"+mCustomerId, balanceObject.toString());
408 |
409 | } catch (JSONException e) {
410 | }
411 |
412 | return response;
413 | }
414 |
415 | @Override
416 | protected void onPostExecute(String result) {
417 | super.onPostExecute(result);
418 | if (dialog.isShowing()) {
419 | dialog.dismiss();
420 | }
421 | Log.d(LOG_TAG, "onPostExecute : "+result);
422 |
423 | String response = result.replaceAll("\r", "");
424 |
425 | try{
426 | Gson gson = new Gson();
427 | BankAccount bankAccount = gson.fromJson(response, BankAccount.class);
428 | Log.d(LOG_TAG , "onPostExecute : "+response+" --- "+bankAccount.getBalance());
429 |
430 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
431 | SharedPreferences.Editor editor = prefs.edit();
432 | editor.putFloat(Constants.BALANCE, bankAccount.getBalance());
433 | editor.commit();
434 |
435 | setBalance(mBalanceTxt, bankAccount.getBalance());
436 |
437 | }catch (Exception e){
438 | }
439 | }
440 | }
441 |
442 | private class TransferBalanceTask extends AsyncTask {
443 |
444 | private String response;
445 |
446 | @Override
447 | protected void onPreExecute() {
448 | super.onPreExecute();
449 | dialog.setMessage(Constants.PLEASE_WAIT);
450 | dialog.setCancelable(false);
451 | dialog.show();
452 | }
453 |
454 | @Override
455 | protected String doInBackground(String... strings) {
456 |
457 | JSONObject transferJsonObject = new JSONObject();
458 | try {
459 | transferJsonObject.put("$class", Constants.TRANSFER_AMOUNT);
460 | transferJsonObject.put("from", Constants.BANK_ACCOUNT_TAG+mCustomerId);
461 | transferJsonObject.put("to", Constants.BANK_ACCOUNT_TAG+mReceiverId);
462 | transferJsonObject.put("amount", Double.parseDouble(mTransferAmount));
463 |
464 | Log.d(Constants.LOG_TAG, ""+transferJsonObject);
465 |
466 | Webservice webservice = new Webservice();
467 | response = webservice.postRequest(Webservice.BASE_URL+Webservice.TRANSFER_AMOUNT, transferJsonObject.toString());
468 |
469 | } catch (JSONException e) {
470 | }
471 |
472 | return response;
473 | }
474 |
475 | @Override
476 | protected void onPostExecute(String result) {
477 | super.onPostExecute(result);
478 | if (dialog.isShowing()) {
479 | dialog.dismiss();
480 | }
481 |
482 | double currentBalance = prefs.getFloat(Constants.BALANCE, 0);
483 | double totalBalance = currentBalance - Double.parseDouble(mTransferAmount);
484 |
485 | setBalance(mBalanceTxt, totalBalance);
486 |
487 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
488 | SharedPreferences.Editor editor = prefs.edit();
489 | editor.putFloat(Constants.BALANCE, (float) totalBalance);
490 | editor.commit();
491 |
492 | Log.d(LOG_TAG, "onPostExecute : "+currentBalance+" - "+mTransferAmount+" = "+totalBalance);
493 |
494 | new FetchTransactionTask().execute();
495 | }
496 | }
497 |
498 | private void setBalance(TextView balanceTxt, double balance){
499 | balanceTxt.setText(""+getBalance(balance));
500 | }
501 | }
502 |
--------------------------------------------------------------------------------