// Path: src/main/java/it/eternitywall/eternitywall/IdenticonGenerator.java
// public class IdenticonGenerator {
//     private static final String TAG = "IdenticonGenerator";
// 
//     public static int SIDE = 7;
//     public static int MUL = 9;
// 
//     public static Bitmap generate(String string, int side, int mul) {
//         return generate(Sha256Hash.create(string.getBytes()).getBytes(), side, mul);
//     }
// 
// 	public static Bitmap generate(String string) {
// 		return generate(Sha256Hash.create(string.getBytes()).getBytes(), SIDE, MUL);
// 	}
// 
// 	public static Bitmap generate(byte[] hash, int side, int mul) {
// 		final Bitmap identicon = Bitmap.createBitmap(side*mul, side*mul, Bitmap.Config.ARGB_8888);
// 
// 		//get byte values as unsigned ints
// 		int r = hash[0] & 255;
// 		int g = hash[1] & 255;
// 		int b = hash[2] & 255;
// 		Log.i(TAG, "r " + r + " g " + g + " b " + b);
// 
// 		int background = Color.argb(0,255,255,255);
// 		int foreground = Color.argb(255,r,g,b);
// 
// 		for(int x=0 ; x < side ; x++) {
// 			int i = x < side/2 ? x : side - 1 - x;
//             final int i1 = x * mul;
// 			for(int y=0 ; y < side; y++) {
//                 final int i2 = y * mul;
//                 int currentColor;
// 
// 				if((hash[i] >> y & 1) == 1)
//                     currentColor=foreground;
// 				else
//                     currentColor=background;
// 
//                 for (int a = 0; a < mul; a++) {
//                     final int x1 = i1 + a;
//                     for (int c = 0; c < mul; c++) {
//                         final int y1 = i2 + c;
//                         identicon.setPixel(x1, y1, currentColor);
//                     }
//                 }
//             }
// 		}
// 
// 		return identicon;
// 	}
// 
// }


import android.graphics.Bitmap;
import android.util.Log;
import org.bitcoinj.core.Address;
import java.util.Observable;
import java.util.Observer;
import it.eternitywall.eternitywall.IdenticonGenerator;
package it.eternitywall.eternitywall.wallet;





/**
 * Created by Riccardo Casatta @RCasatta on 30/11/15.
 */
public class WalletObserver implements Observer {
    private static final String TAG = "WalletObserver";
    private EWWalletService ewWalletService;
    private WalletObservable.State was;

    public WalletObserver(EWWalletService ewWalletService) {
        this.ewWalletService = ewWalletService;
        was= WalletObservable.State.STARTED;
    }

    @Override
    public void update(Observable observable, Object data) {
        final WalletObservable walletObservable= (WalletObservable) observable;
        Log.i(TAG, android.os.Process.myTid() + " TID :" + walletObservable+ " was: " + was);

        final String alias = walletObservable.getAlias();
        if (alias != null && !alias.equals(walletObservable.getCurrentIdenticonSource())) {
            Log.i(TAG, "CreateOrRefreshingIdenticon");
// Path: src/main/java/it/eternitywall/eternitywall/IdenticonGenerator.java
// public class IdenticonGenerator {
//     private static final String TAG = "IdenticonGenerator";
// 
//     public static int SIDE = 7;
//     public static int MUL = 9;
// 
//     public static Bitmap generate(String string, int side, int mul) {
//         return generate(Sha256Hash.create(string.getBytes()).getBytes(), side, mul);
//     }
// 
// 	public static Bitmap generate(String string) {
// 		return generate(Sha256Hash.create(string.getBytes()).getBytes(), SIDE, MUL);
// 	}
// 
// 	public static Bitmap generate(byte[] hash, int side, int mul) {
// 		final Bitmap identicon = Bitmap.createBitmap(side*mul, side*mul, Bitmap.Config.ARGB_8888);
// 
// 		//get byte values as unsigned ints
// 		int r = hash[0] & 255;
// 		int g = hash[1] & 255;
// 		int b = hash[2] & 255;
// 		Log.i(TAG, "r " + r + " g " + g + " b " + b);
// 
// 		int background = Color.argb(0,255,255,255);
// 		int foreground = Color.argb(255,r,g,b);
// 
// 		for(int x=0 ; x < side ; x++) {
// 			int i = x < side/2 ? x : side - 1 - x;
//             final int i1 = x * mul;
// 			for(int y=0 ; y < side; y++) {
//                 final int i2 = y * mul;
//                 int currentColor;
// 
// 				if((hash[i] >> y & 1) == 1)
//                     currentColor=foreground;
// 				else
//                     currentColor=background;
// 
//                 for (int a = 0; a < mul; a++) {
//                     final int x1 = i1 + a;
//                     for (int c = 0; c < mul; c++) {
//                         final int y1 = i2 + c;
//                         identicon.setPixel(x1, y1, currentColor);
//                     }
//                 }
//             }
// 		}
// 
// 		return identicon;
// 	}
// 
// }


// Path: src/main/java/it/eternitywall/eternitywall/wallet/WalletObserver.java
import android.graphics.Bitmap;
import android.util.Log;
import org.bitcoinj.core.Address;
import java.util.Observable;
import java.util.Observer;
import it.eternitywall.eternitywall.IdenticonGenerator;

package it.eternitywall.eternitywall.wallet;





/**
 * Created by Riccardo Casatta @RCasatta on 30/11/15.
 */
public class WalletObserver implements Observer {
    private static final String TAG = "WalletObserver";
    private EWWalletService ewWalletService;
    private WalletObservable.State was;

    public WalletObserver(EWWalletService ewWalletService) {
        this.ewWalletService = ewWalletService;
        was= WalletObservable.State.STARTED;
    }

    @Override
    public void update(Observable observable, Object data) {
        final WalletObservable walletObservable= (WalletObservable) observable;
        Log.i(TAG, android.os.Process.myTid() + " TID :" + walletObservable+ " was: " + was);

        final String alias = walletObservable.getAlias();
        if (alias != null && !alias.equals(walletObservable.getCurrentIdenticonSource())) {
            Log.i(TAG, "CreateOrRefreshingIdenticon");
            Bitmap identicon = IdenticonGenerator.generate(alias);