Commit 8589a692 authored by T Dev. D's avatar T Dev. D 😎
Browse files

Merge branch 'dojo' of https://github.com/Samourai-Wallet/sentinel-android into dojo

parents cf461775 94d66121
......@@ -87,6 +87,7 @@ dependencies {
}
implementation 'com.yanzhenjie.zbar:camera:1.0.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.squareup.okhttp3:okhttp:3.13.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
......
......@@ -39,7 +39,7 @@
</intent-filter>
</activity>
<activity android:name=".Network" android:label="Network" />
<activity android:name=".network.dojo.Network" android:theme="@style/AppThemeV2" android:label="Network" />
<receiver android:name=".tor.TorBroadCastReceiver" />
......@@ -76,6 +76,7 @@
<activity android:name="com.samourai.sentinel.BalanceActivity"
android:label="@string/app_name"
android:theme="@style/AppThemeV2"
android:configChanges="keyboardHidden|orientation|screenSize"
>
</activity>
......@@ -88,6 +89,7 @@
<activity android:name="com.samourai.sentinel.XPUBListActivity"
android:label="@string/app_name"
android:theme="@style/AppThemeV2"
android:configChanges="keyboardHidden|orientation|screenSize"
>
</activity>
......@@ -107,7 +109,7 @@
<activity android:name="com.samourai.sentinel.InsertActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Holo.Dialog"
android:theme="@style/AppThemeV2Alert"
>
</activity>
......
......@@ -2,41 +2,19 @@ package com.samourai.sentinel;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import com.samourai.sentinel.access.AccessFactory;
import com.samourai.sentinel.network.dojo.Network;
import com.samourai.sentinel.permissions.PermissionsUtil;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.FormatsUtil;
import net.sourceforge.zbar.Symbol;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.ByteBuffer;
public class InitActivity extends Activity {
......@@ -92,7 +70,7 @@ public class InitActivity extends Activity {
AppUtil.getInstance(InitActivity.this).doRestore();
}
if (id == R.id.action_network_init) {
startActivity(new Intent(this,Network.class));
startActivity(new Intent(this, Network.class));
}
else {
;
......
......@@ -5,21 +5,20 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
//import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import com.samourai.sentinel.access.AccessFactory;
import com.samourai.sentinel.codescanner.CameraFragmentBottomSheet;
import com.samourai.sentinel.util.FormatsUtil;
import net.sourceforge.zbar.Symbol;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import org.json.JSONException;
......@@ -27,7 +26,9 @@ import org.json.JSONException;
import java.io.IOException;
import java.nio.ByteBuffer;
public class InsertActivity extends Activity {
//import android.widget.Toast;
public class InsertActivity extends AppCompatActivity {
private final static int SCAN_XPUB = 2011;
private final static int INSERT_SEGWIT = 2012;
......@@ -37,13 +38,20 @@ public class InsertActivity extends Activity {
public final static int TYPE_SEGWIT_XPUB = 2;
private int storedType = 0;
private CameraFragmentBottomSheet cameraFragmentBottomSheet;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insert);
setTitle(R.string.track_new);
// setTitle();
setSupportActionBar(findViewById(R.id.toolbar));
if(getSupportActionBar()!=null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.track_new);
}
InsertActivity.this.setFinishOnTouchOutside(false);
......@@ -78,7 +86,13 @@ public class InsertActivity extends Activity {
});
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
finish();
}
return (super.onOptionsItemSelected(menuItem));
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
......@@ -181,9 +195,28 @@ public class InsertActivity extends Activity {
}
private void doScan() {
Intent intent = new Intent(InsertActivity.this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, SCAN_XPUB);
cameraFragmentBottomSheet = new CameraFragmentBottomSheet();
cameraFragmentBottomSheet.show(this.getSupportFragmentManager(), cameraFragmentBottomSheet.getTag());
cameraFragmentBottomSheet.setQrCodeScanLisenter(code -> {
cameraFragmentBottomSheet.dismiss();
// this.connectToDojo(code);
if(code.startsWith("bitcoin:")) {
code = code.substring(8);
}
if(code.contains("?")) {
code = code.substring(0, code.indexOf("?"));
}
addXPUB(code, storedType);
});
//
//
//
// Intent intent = new Intent(InsertActivity.this, ZBarScannerActivity.class);
// intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
// startActivityForResult(intent, SCAN_XPUB);
}
private void addXPUB(final String xpubStr, final int type) {
......
......@@ -8,6 +8,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.samourai.sentinel.api.APIFactory;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.WebUtil;
......@@ -77,6 +78,7 @@ public class InsertSegwitActivity extends Activity {
.add("xpub", params[0])
.add("type", "restore")
.add("segwit", "bip".concat(params[1]))
.add("at", APIFactory.getInstance(getApplicationContext()).getAccessToken())
.build();
......
......@@ -90,8 +90,7 @@ public class MainActivity2 extends Activity {
}
else {
feeThread();
exchangeRateThread();
if(PrefsUtil.getInstance(MainActivity2.this).getValue("popup_" + getResources().getString(R.string.version_name), false) == true) {
......@@ -185,7 +184,8 @@ public class MainActivity2 extends Activity {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
feeThread();
exchangeRateThread();
}
BackgroundManager.get(MainActivity2.this).addListener(bgListener);
......
......@@ -6,6 +6,7 @@ import android.util.Log;
//import android.util.Log;
import com.samourai.sentinel.crypto.AESUtil;
import com.samourai.sentinel.network.dojo.DojoUtil;
import com.samourai.sentinel.segwit.P2SH_P2WPKH;
import com.samourai.sentinel.segwit.SegwitAddress;
import com.samourai.sentinel.util.AddressFactory;
......@@ -214,6 +215,9 @@ public class SamouraiSentinel {
if(obj != null && obj.has("receives")) {
ReceiveLookAtUtil.getInstance().fromJSON(obj.getJSONArray("receives"));
}
if(obj != null && obj.has("dojo")) {
DojoUtil.getInstance(context).fromJSON(new JSONObject(obj.getString("dojo")));
}
}
catch(JSONException ex) {
......@@ -265,6 +269,12 @@ public class SamouraiSentinel {
obj.put("legacy", _addr);
obj.put("receives", ReceiveLookAtUtil.getInstance().toJSON());
obj.put("receives", ReceiveLookAtUtil.getInstance().toJSON());
if(DojoUtil.getInstance(context).getDojoParams() != null){
obj.put("dojo", DojoUtil.getInstance(context).toJSON().toString());
}
return obj;
}
......
package com.samourai.sentinel;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.LayoutInflater;
......@@ -24,42 +19,34 @@ import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
//import android.util.Log;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.samourai.sentinel.api.APIFactory;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.FormatsUtil;
import com.samourai.sentinel.util.MonetaryUtil;
import com.samourai.sentinel.util.PrefsUtil;
import net.i2p.android.ext.floatingactionbutton.FloatingActionButton;
import net.sourceforge.zbar.Symbol;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.Coin;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import com.samourai.sentinel.access.AccessFactory;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.samourai.sentinel.api.APIFactory;
import com.samourai.sentinel.util.AppUtil;
import com.samourai.sentinel.util.FormatsUtil;
import com.samourai.sentinel.util.MapUtil;
import com.samourai.sentinel.util.MonetaryUtil;
import com.samourai.sentinel.util.PrefsUtil;
//import android.util.Log;
public class XPUBListActivity extends Activity {
public class XPUBListActivity extends AppCompatActivity {
private SwipeMenuListView xpubList = null;
private XPUBAdapter xpubAdapter = null;
......@@ -81,6 +68,7 @@ public class XPUBListActivity extends Activity {
PrefsUtil.getInstance(XPUBListActivity.this).setValue(PrefsUtil.XPUB, "");
AppUtil.getInstance(XPUBListActivity.this).restartApp();
}
setSupportActionBar(findViewById(R.id.toolbar));
xpubList = (SwipeMenuListView)findViewById(R.id.xpubList);
xpubAdapter = new XPUBAdapter();
......@@ -195,6 +183,9 @@ public class XPUBListActivity extends Activity {
}
});
if(getSupportActionBar()!=null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
......
/*
* MIT License
*
* Copyright (c) 2017 Yuriy Budiyev [yuriy.budiyev@yandex.ru]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.samourai.sentinel.codescanner;
/**
* Code scanner auto focus mode
*
* @see CodeScanner#setAutoFocusMode(AutoFocusMode)
*/
public enum AutoFocusMode {
/**
* Auto focus camera with the specified interval
*
* @see CodeScanner#setAutoFocusInterval(long)
*/
SAFE,
/**
* Continuous auto focus, may not work on some devices
*/
CONTINUOUS
}
/*
* MIT License
*
* Copyright (c) 2017 Yuriy Budiyev [yuriy.budiyev@yandex.ru]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.samourai.sentinel.codescanner;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.PlanarYUVLuminanceSource;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
/**
* Utils for decoding and encoding bar codes
*/
public final class BarcodeUtils {
public static final int ROTATION_0 = 0;
public static final int ROTATION_90 = 90;
public static final int ROTATION_180 = 180;
public static final int ROTATION_270 = 270;
private BarcodeUtils() {
}
/**
* Decode barcode from bitmap
*
* @param bitmap Bitmap
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
*/
@Nullable
public static Result decodeBitmap(@NonNull final Bitmap bitmap) {
return decodeBitmap(bitmap, null);
}
/**
* Decode barcode from bitmap
*
* @param bitmap Bitmap
* @param hints Decoder hints
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
* @see DecodeHintType
*/
@Nullable
public static Result decodeBitmap(@NonNull final Bitmap bitmap,
@Nullable final Map<DecodeHintType, ?> hints) {
Objects.requireNonNull(bitmap);
final int width = bitmap.getWidth();
final int height = bitmap.getHeight();
final int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
return decodeRgb(pixels, width, height, hints);
}
/**
* Decode barcode from RGB pixels array
*
* @param pixels Colors in standard Android ARGB format
* @param width Image width
* @param height Image height
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
* @see Color
*/
@Nullable
public static Result decodeRgb(@NonNull final int[] pixels, final int width, final int height) {
return decodeRgb(pixels, width, height, null);
}
/**
* Decode barcode from RGB pixels array
*
* @param pixels Colors in standard Android ARGB format
* @param width Image width
* @param height Image height
* @param hints Decoder hints
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
* @see DecodeHintType
* @see Color
*/
@Nullable
public static Result decodeRgb(@NonNull final int[] pixels, final int width, final int height,
@Nullable final Map<DecodeHintType, ?> hints) {
Objects.requireNonNull(pixels);
final MultiFormatReader reader = createReader(hints);
try {
return Utils
.decodeLuminanceSource(reader, new RGBLuminanceSource(width, height, pixels));
} catch (final ReaderException e) {
return null;
}
}
/**
* Decode barcode from YUV pixels array
*
* @param pixels YUV image data
* @param width Image width
* @param height Image height
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
*/
@Nullable
public static Result decodeYuv(@NonNull final byte[] pixels, final int width,
final int height) {
return decodeYuv(pixels, width, height, ROTATION_0, false, null);
}
/**
* Decode barcode from YUV pixels array
*
* @param pixels YUV image data
* @param width Image width
* @param height Image height
* @param rotation Degrees to rotate image before decoding (only 0, 90, 180 or 270 are allowed)
* @param reverseHorizontal Reverse image horizontally before decoding
* @param hints Decoder hints
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
* @see DecodeHintType
*/
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public static Result decodeYuv(@NonNull final byte[] pixels, final int width, final int height,
@Rotation final int rotation, final boolean reverseHorizontal,
@Nullable final Map<DecodeHintType, ?> hints) {
Objects.requireNonNull(pixels);
final byte[] rotatedPixels = Utils.rotateYuv(pixels, width, height, rotation);
final int rotatedWidth;
final int rotatedHeight;
if (rotation == ROTATION_90 || rotation == ROTATION_270) {
rotatedWidth = height;
rotatedHeight = width;
} else {
rotatedWidth = width;
rotatedHeight = height;
}
final MultiFormatReader reader = createReader(hints);
try {
return Utils.decodeLuminanceSource(reader,
new PlanarYUVLuminanceSource(rotatedPixels, rotatedWidth, rotatedHeight, 0, 0,
rotatedWidth, rotatedHeight, reverseHorizontal));
} catch (final ReaderException e) {
return null;
}
}
/**
* Encode text content
*
* @param content Text to be encoded
* @param format Result barcode format
* @param width Result image width