-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate nyris searcher to new camera sdk
- Loading branch information
Showing
10 changed files
with
199 additions
and
78 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
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,7 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.CAMERA" /> | ||
<application android:allowBackup="true" | ||
android:icon="@mipmap/appicon" | ||
android:roundIcon="@mipmap/appicon_round" | ||
android:supportsRtl="true"/> | ||
</manifest> |
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,3 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.1" package="nyris.ui.android"> | ||
<manifest package="nyris.ui.android"> | ||
</manifest> |
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,28 @@ | ||
using Kotlin.Jvm.Functions; | ||
using Object = Java.Lang.Object; | ||
|
||
namespace Nyris.UI.Android.Custom; | ||
|
||
public class CaptureBlock<T> : Object, IFunction1 where T : Object | ||
{ | ||
private readonly Action<T> OnInvoked; | ||
|
||
public CaptureBlock(Action<T> onInvoked) | ||
{ | ||
OnInvoked = onInvoked; | ||
} | ||
|
||
public Object Invoke(Object? objParameter) | ||
{ | ||
try | ||
{ | ||
T parameter = (T)objParameter; | ||
OnInvoked.Invoke(parameter); | ||
return null; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
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,75 @@ | ||
using Android.Content; | ||
using Android.Graphics; | ||
|
||
namespace Nyris.UI.Android.Custom | ||
{ | ||
public static class Utils | ||
{ | ||
public static byte[] Optimize(this Bitmap bitmap) | ||
{ | ||
var proportionalSize = CalculateProportionalSize(bitmap.Width, bitmap.Height); | ||
return Bitmap.CreateScaledBitmap( | ||
bitmap, proportionalSize.Item1, proportionalSize.Item2, true | ||
).ToByteArray(); | ||
} | ||
|
||
public static Bitmap ToBitmap(this byte[] image) | ||
{ | ||
return BitmapFactory.DecodeByteArray(image, 0, image.Length); | ||
} | ||
|
||
public static Tuple<int, int> CalculateProportionalSize(int width, int height) | ||
{ | ||
const int maxImageSize = 1024; | ||
if (width < maxImageSize && height < maxImageSize) | ||
{ | ||
return new Tuple<int, int>(width, height); | ||
} | ||
|
||
var aspectRationWidth = maxImageSize / (float) width; | ||
var aspectRationHeight = maxImageSize / (float) height; | ||
var aspectRation = aspectRationWidth > aspectRationHeight ? aspectRationHeight : aspectRationWidth; | ||
return new Tuple<int, int>((int)(width * aspectRation), (int)(height * aspectRation)); | ||
} | ||
|
||
public static byte[] ToByteArray(this Bitmap bitmap) | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
// Compress the bitmap into the stream using the provided format and quality | ||
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); | ||
|
||
// Return the byte array from the stream | ||
return stream.ToArray(); | ||
} | ||
} | ||
|
||
public static String DefaultPathForLastTakenImage(Context context) | ||
{ | ||
var directory = new Java.IO.File(context.FilesDir, "searcher"); | ||
var file = new Java.IO.File(directory, $"last.jpg"); | ||
return file.AbsolutePath; | ||
} | ||
|
||
public static void SaveImageToInternalStorage(this byte[] image, Context context) | ||
{ | ||
try | ||
{ | ||
// Create or open a directory inside the app's internal storage | ||
var directory = new Java.IO.File(context.FilesDir, "searcher"); | ||
if (!directory.Exists()) | ||
{ | ||
directory.Mkdirs(); // Create the directory if it doesn't exist | ||
} | ||
|
||
// Write the byte array to the file | ||
var file = new Java.IO.File(directory, $"last.jpg"); | ||
File.WriteAllBytes(file.AbsolutePath, image); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error saving image: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.