-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clement
authored and
Clement
committed
Sep 26, 2016
1 parent
5586f66
commit b406c6b
Showing
31 changed files
with
489 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Drawing; | ||
using System.Text; | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Graphics; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Views; | ||
using Android.Webkit; | ||
using Android.Widget; | ||
using Android.Util; | ||
using System.IO; | ||
using Android.Media; | ||
|
||
using MPayXDKExample.Droid; | ||
using MPayXDKExample; | ||
|
||
[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))] | ||
|
||
namespace MPayXDKExample.Droid | ||
{ | ||
public class MPExtension : MOLPayExtension | ||
{ | ||
private static Object molpayActivity; | ||
|
||
public void SetMOLPayContext(Object mpActivity) | ||
{ | ||
molpayActivity = mpActivity; | ||
} | ||
|
||
public String GetAssetPath() | ||
{ | ||
return "file:///android_asset/"; | ||
} | ||
|
||
public void saveImageToDevice(String base64ImageString, String filename) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString); | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename); | ||
|
||
byte[] imageAsBytes = Base64.Decode(base64ImageString, Base64Flags.Default); | ||
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length); | ||
|
||
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; | ||
var filePath = System.IO.Path.Combine(sdCardPath.ToString(), filename); | ||
var stream = new FileStream(filePath, FileMode.Create); | ||
|
||
bool compress = bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); | ||
stream.Close(); | ||
|
||
MediaScannerConnection.ScanFile(Application.Context, new String[] { filePath }, null, null); | ||
|
||
if (compress) | ||
{ | ||
Toast.MakeText((MainActivity)molpayActivity, "Image saved", ToastLength.Short).Show(); | ||
} | ||
else | ||
{ | ||
Toast.MakeText((MainActivity)molpayActivity, "Image not saved", ToastLength.Short).Show(); | ||
} | ||
} | ||
|
||
private static String Base64Encode(String plainText) | ||
{ | ||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); | ||
return System.Convert.ToBase64String(plainTextBytes); | ||
} | ||
|
||
private static String Base64Decode(String base64EncodedData) | ||
{ | ||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); | ||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Foundation; | ||
using UIKit; | ||
using System.IO; | ||
|
||
using MPayXDKExample.iOS; | ||
using MPayXDKExample; | ||
|
||
[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))] | ||
|
||
namespace MPayXDKExample.iOS | ||
{ | ||
public class MPExtension : MOLPayExtension | ||
{ | ||
public void SetMOLPayContext(Object mpActivity) | ||
{ | ||
// iOS does nothing | ||
} | ||
|
||
public String GetAssetPath() | ||
{ | ||
return NSBundle.MainBundle.BundlePath; | ||
} | ||
|
||
public void saveImageToDevice(String base64ImageString, String filename) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString); | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename); | ||
|
||
byte[] imageData = System.Convert.FromBase64String(base64ImageString.ToString()); | ||
NSData data = NSData.FromArray(imageData); | ||
UIImage img = UIImage.LoadFromData(data); | ||
img.SaveToPhotosAlbum((image, error) => | ||
{ | ||
//var o = image as UIImage; | ||
if (error == null || error.ToString() == "") | ||
{ | ||
UIAlertView alert = new UIAlertView() | ||
{ | ||
Title = "Info", | ||
Message = "Image saved" | ||
}; | ||
alert.AddButton("OK"); | ||
alert.Show(); | ||
} | ||
else | ||
{ | ||
UIAlertView alert = new UIAlertView() | ||
{ | ||
Title = "Info", | ||
Message = "Image not saved" | ||
}; | ||
alert.AddButton("OK"); | ||
alert.Show(); | ||
} | ||
}); | ||
} | ||
|
||
private static String Base64Encode(String plainText) | ||
{ | ||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); | ||
return System.Convert.ToBase64String(plainTextBytes); | ||
} | ||
|
||
private static String Base64Decode(String base64EncodedData) | ||
{ | ||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); | ||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1014 Bytes
MPayXDKExample/Droid/Assets/molpay-mobile-xdk-www/images/ImageUnavailable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <!-- <meta name="viewport" content="width=device-width"> --> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.34eb91d2.css"> <link rel="stylesheet" href="styles/main.d7816846.css"> </head> <body ng-app="molpayXsdkApp"> <div class="header"> </div> <div id="app-body" class="app-body container-fluid"> <div class="row"> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" ng-view=""></div> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> </div> </div> <div ng-show="isStarting" class="loading text-center vertical-center"> <p>Loading.</p> <p>Please wait.</p> </div> <div class="footer"> </div> <div ng-show="isLoading" class="loading text-center vertical-center"> <div class="loadingbackground"></div> <i class="fa fa-spinner fa-spin fa-3x"></i> <div class="loading-text">Loading...</div> </div> <script src="scripts/vendor.5c22674a.js"></script> <script src="scripts/scripts.5df0fc73.js"></script> </body> </html> | ||
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <!-- <meta name="viewport" content="width=device-width"> --> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.34eb91d2.css"> <link rel="stylesheet" href="styles/main.d7e0b867.css"> </head> <body ng-app="molpayXsdkApp"> <div class="header"> </div> <div id="app-body" class="app-body container-fluid"> <div class="row"> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" ng-view=""></div> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> </div> </div> <div ng-show="isStarting" class="loading text-center vertical-center"> <p>Loading.</p> <p>Please wait.</p> </div> <div class="footer"> </div> <div ng-show="isLoading" class="loading text-center vertical-center"> <div class="loadingbackground"></div> <i class="fa fa-spinner fa-spin fa-3x"></i> <div class="loading-text">Loading...</div> </div> <script src="scripts/vendor.f206a627.js"></script> <script src="scripts/scripts.2c26c95c.js"></script> </body> </html> |
1 change: 1 addition & 0 deletions
1
MPayXDKExample/Droid/Assets/molpay-mobile-xdk-www/scripts/scripts.2c26c95c.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
MPayXDKExample/Droid/Assets/molpay-mobile-xdk-www/scripts/scripts.5df0fc73.js
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
...mobile-xdk-www/scripts/vendor.5c22674a.js → ...mobile-xdk-www/scripts/vendor.f206a627.js
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...y-mobile-xdk-www/styles/main.d7816846.css → ...y-mobile-xdk-www/styles/main.d7e0b867.css
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Drawing; | ||
using System.Text; | ||
using Android.App; | ||
using Android.Content; | ||
using Android.Graphics; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Views; | ||
using Android.Webkit; | ||
using Android.Widget; | ||
using Android.Util; | ||
using System.IO; | ||
using Android.Media; | ||
|
||
using MPayXDKExample.Droid; | ||
using MPayXDKExample; | ||
|
||
[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))] | ||
|
||
namespace MPayXDKExample.Droid | ||
{ | ||
public class MPExtension : MOLPayExtension | ||
{ | ||
private static Object molpayActivity; | ||
|
||
public void SetMOLPayContext(Object mpActivity) | ||
{ | ||
molpayActivity = mpActivity; | ||
} | ||
|
||
public String GetAssetPath() | ||
{ | ||
return "file:///android_asset/"; | ||
} | ||
|
||
public void saveImageToDevice(String base64ImageString, String filename) | ||
{ | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString); | ||
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename); | ||
|
||
byte[] imageAsBytes = Base64.Decode(base64ImageString, Base64Flags.Default); | ||
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length); | ||
|
||
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; | ||
var filePath = System.IO.Path.Combine(sdCardPath.ToString(), filename); | ||
var stream = new FileStream(filePath, FileMode.Create); | ||
|
||
bool compress = bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); | ||
stream.Close(); | ||
|
||
MediaScannerConnection.ScanFile(Application.Context, new String[] { filePath }, null, null); | ||
|
||
if (compress) | ||
{ | ||
Toast.MakeText((MainActivity)molpayActivity, "Image saved", ToastLength.Short).Show(); | ||
} | ||
else | ||
{ | ||
Toast.MakeText((MainActivity)molpayActivity, "Image not saved", ToastLength.Short).Show(); | ||
} | ||
} | ||
|
||
private static String Base64Encode(String plainText) | ||
{ | ||
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); | ||
return System.Convert.ToBase64String(plainTextBytes); | ||
} | ||
|
||
private static String Base64Decode(String base64EncodedData) | ||
{ | ||
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); | ||
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.molpay.mpayxdkexample"> | ||
<uses-sdk android:minSdkVersion="16" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<application android:label="MPayXDKExample"></application> | ||
</manifest> |
Oops, something went wrong.