develop #10
@ -12,15 +12,29 @@ using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Klient.Droid.Modules;
|
||||
using Android.Provider;
|
||||
using Android.Content;
|
||||
using Android.Graphics;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using Com.Xamarin.Formsviewgroup;
|
||||
using Android.Icu.Text;
|
||||
using System.IO;
|
||||
using Android.Media;
|
||||
using System.Threading.Tasks;
|
||||
using Java.IO;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Klient.Droid
|
||||
{
|
||||
[Activity(Label = "Klient", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
|
||||
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
||||
{
|
||||
Bitmap bitmap;
|
||||
ByteArrayContent fileContent;
|
||||
public static int PickImageId = 1000;
|
||||
private static readonly HttpClient client = new HttpClient();
|
||||
public static Android.Content.Intent photo;
|
||||
@ -36,6 +50,8 @@ namespace Klient.Droid
|
||||
|
||||
base.OnCreate(savedInstanceState);
|
||||
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
||||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
||||
StrictMode.SetVmPolicy(builder.Build());
|
||||
LoadApplication(new App());
|
||||
SetContentView(Resource.Layout.ekranStartowy);
|
||||
}
|
||||
@ -86,6 +102,12 @@ namespace Klient.Droid
|
||||
}
|
||||
}
|
||||
|
||||
[Java.Interop.Export("HelpLoginScreen")]
|
||||
public void GoToAboutScreen(View v)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranInformacji);
|
||||
}
|
||||
|
||||
[Java.Interop.Export("SignUp")]
|
||||
async public void SignUp(View v)
|
||||
{
|
||||
@ -152,6 +174,13 @@ namespace Klient.Droid
|
||||
}
|
||||
}
|
||||
|
||||
[Java.Interop.Export("HelpRegisterScreen")]
|
||||
public void GoToRegisterHelp(View v)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranPomocRejestracja);
|
||||
}
|
||||
|
||||
|
||||
[Java.Interop.Export("GoToProfile")]
|
||||
public void GoBackToProfile(View v)
|
||||
{
|
||||
@ -175,11 +204,6 @@ namespace Klient.Droid
|
||||
SetContentView(Resource.Layout.ekranRejestracji);
|
||||
}
|
||||
|
||||
[Java.Interop.Export("HelpLoginScreen")]
|
||||
public void MainScreenAbout(View v)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranInformacji);
|
||||
}
|
||||
[Java.Interop.Export("GoToMainScreenFromInformation")]
|
||||
public void GoToMainScreenFromInformation(View v)
|
||||
{
|
||||
@ -194,6 +218,18 @@ namespace Klient.Droid
|
||||
|
||||
StartActivityForResult(Android.Content.Intent.CreateChooser(Intent, "Select Picture"), PickImageId);
|
||||
}
|
||||
|
||||
[Java.Interop.Export("LoadFromCamera")]
|
||||
public void LoadFromCamera(View v)
|
||||
{
|
||||
Intent intent = new Intent(MediaStore.ActionImageCapture);
|
||||
//Android.Net.Uri pictureUri = Android.Net.Uri.FromFile(new File(GetExternalFilesDir(Android.OS.Environment.DirectoryDcim), Guid.NewGuid().ToString().Replace(".", "")+".jpg"));
|
||||
//intent.PutExtra(MediaStore.ExtraOutput, pictureUri);
|
||||
StartActivityForResult(intent, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Java.Interop.Export("GoToStart")]
|
||||
public void GoToStart(View v)
|
||||
{
|
||||
@ -208,15 +244,87 @@ namespace Klient.Droid
|
||||
protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranPoZdjeciu);
|
||||
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = "";
|
||||
if (requestCode == 0)
|
||||
{
|
||||
photo = data;
|
||||
base.OnActivityResult(requestCode, resultCode, data);
|
||||
if(data != null) bitmap = (Bitmap)data.Extras.Get("data");
|
||||
|
||||
byte[] bitmapData;
|
||||
var stream = new MemoryStream();
|
||||
bitmap.Compress(Bitmap.CompressFormat.Jpeg, 60, stream);
|
||||
bitmapData = stream.ToArray();
|
||||
fileContent = new ByteArrayContent(bitmapData);
|
||||
|
||||
|
||||
FindViewById<ImageView>(Resource.Id.Preview).SetImageBitmap(bitmap);
|
||||
|
||||
}
|
||||
else if(requestCode == PickImageId)
|
||||
{
|
||||
Android.Net.Uri uri = data.Data;
|
||||
photo = data;
|
||||
FindViewById<ImageView>(Resource.Id.Preview).SetImageURI(uri);
|
||||
}
|
||||
else if(data == null)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranPoLogowaniu);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Java.Interop.Export("SendPhoto")]
|
||||
async public void UploadPhoto(View v)
|
||||
{
|
||||
if(photo.Data == null)
|
||||
{
|
||||
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
|
||||
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||
{
|
||||
Name = "image",
|
||||
FileName = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
string boundary = "---8d0f01e6b3b5dafaaadaad";
|
||||
MultipartFormDataContent formDataContent = new MultipartFormDataContent(boundary);
|
||||
formDataContent.Add(fileContent);
|
||||
|
||||
var response = await client.PostAsync("http://10.0.2.2:5001/api/Image/Process", formDataContent);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = "Przesłano zdjęcie!";
|
||||
SetContentView(Resource.Layout.ekranZLinkami);
|
||||
var second_response = await client.GetAsync($"http://10.0.2.2:5001/api/Search/{jsonString}");
|
||||
if (second_response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var second_jsonString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
List<SearchResult> fullLink = JsonConvert.DeserializeObject<List<SearchResult>>(second_jsonString);
|
||||
|
||||
int end = 10;
|
||||
if (fullLink.Count < 10) end = fullLink.Count;
|
||||
for (int i = 0; i < end; i++)
|
||||
{
|
||||
FindViewById<TextView>(Resource.Id.links).Text = FindViewById<TextView>(Resource.Id.links).Text + fullLink[i].title + ": " + fullLink[i].link + "\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FindViewById<TextView>(Resource.Id.links).Text = "Coś poszło nie tak!";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
string msg = await response.Content.ReadAsStringAsync();
|
||||
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = msg;
|
||||
}
|
||||
}
|
||||
|
||||
using(var imageStream = ContentResolver.OpenInputStream(photo.Data))
|
||||
using(var stramContent = new StreamContent(imageStream))
|
||||
using(var byteArrayContent = new ByteArrayContent(await stramContent.ReadAsByteArrayAsync()))
|
||||
@ -232,22 +340,19 @@ namespace Klient.Droid
|
||||
if(response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
dynamic jsonObject = JsonConvert.DeserializeObject(jsonString);
|
||||
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = "Przesłano zdjęcie!";
|
||||
SetContentView(Resource.Layout.ekranZLinkami);
|
||||
var second_response = await client.GetAsync("http://10.0.2.2:5001/api/Search", jsonObject.response);
|
||||
var second_response = await client.GetAsync($"http://10.0.2.2:5001/api/Search/{jsonString}");
|
||||
if(second_response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var second_jsonString = await response.Content.ReadAsStringAsync();
|
||||
dynamic second_jsonObject = JsonConvert.DeserializeObject(second_jsonString);
|
||||
|
||||
List<SearchResult> fullLink = JsonConvert.DeserializeObject<List<SearchResult>>(second_jsonObject);
|
||||
var second_jsonString = await second_response.Content.ReadAsStringAsync();
|
||||
List<SearchResult> fullLink = JsonConvert.DeserializeObject<List<SearchResult>>(second_jsonString);
|
||||
|
||||
int end = 10;
|
||||
if (fullLink.Count < 10) end = fullLink.Count;
|
||||
for (int i = 0; i < end; i++)
|
||||
{
|
||||
FindViewById<TextView>(Resource.Id.links).Text = FindViewById<TextView>(Resource.Id.links).Text + fullLink[i].Title + ": " + fullLink[i].Link + "\n\n";
|
||||
FindViewById<TextView>(Resource.Id.links).Text = FindViewById<TextView>(Resource.Id.links).Text + fullLink[i].title + ": " + fullLink[i].link + "\n\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -331,7 +436,8 @@ namespace Klient.Droid
|
||||
{
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
dynamic jsonObject = JsonConvert.DeserializeObject(jsonString);
|
||||
List<string> history = JsonConvert.DeserializeObject<List<string>>(jsonObject.history);
|
||||
var hs = (JArray)jsonObject.history;
|
||||
List<string> history = hs.ToObject<List<string>>();
|
||||
int end = 10;
|
||||
int temp;
|
||||
if (history.Count < 10) end = history.Count;
|
||||
@ -343,8 +449,15 @@ namespace Klient.Droid
|
||||
}
|
||||
else
|
||||
{
|
||||
FindViewById<TextView>(Resource.Id.history).Text = "Coś poszło nie tak!";
|
||||
}
|
||||
string msg = await response.Content.ReadAsStringAsync();
|
||||
FindViewById<TextView>(Resource.Id.HistoryError).Text = msg;
|
||||
}
|
||||
}
|
||||
|
||||
[Java.Interop.Export("HelpPhoto")]
|
||||
public void GotToHelpPhoto(View v)
|
||||
{
|
||||
SetContentView(Resource.Layout.ekranPomocZdjecie);
|
||||
}
|
||||
}
|
||||
}
|
@ -13,8 +13,8 @@ namespace Klient.Droid.Modules
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Link { get; set; }
|
||||
public string Snippet { get; set; }
|
||||
public string title { get; set; }
|
||||
public string link { get; set; }
|
||||
public string snippet { get; set; }
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@
|
||||
<BundleAssemblies>false</BundleAssemblies>
|
||||
<MandroidI18n />
|
||||
<Debugger>Xamarin</Debugger>
|
||||
<AndroidSupportedAbis />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -149,11 +150,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResourceAnalysisConfig Include="Resources\layout\ekranPomocRejestracja.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResourceAnalysisConfig>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\ekranPomocZdjecie.xml">
|
||||
<SubType>Designer</SubType>
|
||||
@ -174,6 +170,17 @@
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\ekranPomocRejestracja.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</AndroidResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\drawable\Obraz4.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\xml\file_paths.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
|
@ -1,7 +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.companyname.Klient.Android" android:installLocation="preferExternal">
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.Klient.Android" android:installLocation="internalOnly">
|
||||
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="27" />
|
||||
<application android:label="Klient.Android" android:usesCleartextTraffic="true" android:theme="@style/Base.Theme.AppCompat.Light.DarkActionBar" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
1412
Klient/Klient/Klient.Android/Resources/Resource.designer.cs
generated
1412
Klient/Klient/Klient.Android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
BIN
Klient/Klient/Klient.Android/Resources/drawable/Obraz4.png
Normal file
BIN
Klient/Klient/Klient.Android/Resources/drawable/Obraz4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
@ -7,15 +7,14 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#ffbdd7f0">
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backHistory"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToProfile" />
|
||||
<TextView
|
||||
@ -44,7 +43,27 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/history"
|
||||
android:layout_below="@+id/HistoryError"
|
||||
android:textColor="#ff000000"
|
||||
android:paddingBottom="35dp"
|
||||
android:focusableInTouchMode="true"
|
||||
android:isScrollContainer="true"
|
||||
android:fadeScrollbars="true"
|
||||
android:scrollbars="vertical"
|
||||
android:verticalScrollbarPosition="right"
|
||||
android:scrollIndicators="right"
|
||||
android:scrollbarAlwaysDrawVerticalTrack="true"
|
||||
android:textIsSelectable="true"
|
||||
android:paddingTop="10dp"/>
|
||||
<TextView
|
||||
android:text=""
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/HistoryError"
|
||||
android:layout_below="@+id/HistoryTitle"
|
||||
android:textColor="#ff000000" />
|
||||
android:textColor="#ffff0000"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingTop="10dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -39,15 +39,14 @@
|
||||
android:textColor="#ff000000"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backInformation"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToMainScreenFromInformation" />
|
||||
|
||||
|
@ -60,15 +60,14 @@
|
||||
android:text="Zaloguj"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:foregroundGravity="center" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backLogowanie"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToStart"/>
|
||||
<TextView
|
||||
|
@ -27,15 +27,14 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_below="@id/SendPhoto"
|
||||
android:textColor="#ffd60000" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backZdjecie"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToPoLogowaniu" />
|
||||
<TextView
|
||||
|
@ -35,7 +35,8 @@
|
||||
android:id="@+id/textView1"
|
||||
android:textColor="#ffb1d5f8"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentBottom="true" />
<TextView
|
||||
android:layout_alignParentBottom="true" />
|
||||
<TextView
|
||||
android:text="Poszukiwacz 2021"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="wrap_content"
|
||||
@ -43,7 +44,8 @@
|
||||
android:id="@+id/text1"
|
||||
android:textColor="#ff000000"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
<Button
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
@ -53,4 +55,6 @@
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToRegister" />
</RelativeLayout>
|
||||
android:onClick="GoToRegister" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -15,15 +15,14 @@
|
||||
android:textColor="#ff000000"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backPomocZdjecie"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToPoLogowaniu" />
|
||||
<TextView
|
||||
@ -31,6 +30,7 @@
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView1" />
|
||||
android:id="@+id/textView1"
|
||||
android:textColor="#ff000000" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -102,15 +102,14 @@
|
||||
android:textColor="#ff000000"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backProfil"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToPoLogowaniu" />
|
||||
<Button
|
||||
|
@ -80,6 +80,8 @@
|
||||
android:layout_height="58.0dp"
|
||||
android:minWidth="25px"
|
||||
android:minHeight="25px"
|
||||
android:textColor="#ff000000"
|
||||
android:textColorHint="#ff6c6767"
|
||||
android:id="@+id/NewPassword"
|
||||
android:inputType="none|textPassword" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@ -100,7 +102,8 @@
|
||||
android:minHeight="25px"
|
||||
android:id="@+id/RepeatPassword"
|
||||
android:inputType="none|textPassword"
|
||||
android:textColor="#ff000000" />
|
||||
android:textColor="#ff000000"
|
||||
android:textColorHint="#ff6c6767" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/LayoutNewLogin"
|
||||
@ -160,15 +163,14 @@
|
||||
android:textColor="#fffcfcfc"
|
||||
android:gravity="center"
|
||||
android:onClick="HelpRegisterScreen" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backRejestracja"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToStart" />
|
||||
|
||||
|
@ -29,9 +29,9 @@
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:text="i"
|
||||
android:layout_width="35.0dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:text="?"
|
||||
android:layout_width="25.0dp"
|
||||
android:layout_height="25.0dp"
|
||||
android:id="@+id/about"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
|
@ -24,19 +24,38 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/links"
|
||||
android:layout_below="@+id/linkTitle"
|
||||
android:layout_below="@+id/LinkError"
|
||||
android:textColor="#ff393939"
|
||||
android:linksClickable="true"
|
||||
android:autoLink="web" />
|
||||
<Button
|
||||
android:text="Back"
|
||||
android:autoLink="web"
|
||||
android:fadeScrollbars="true"
|
||||
android:scrollbars="vertical"
|
||||
android:verticalScrollbarPosition="right"
|
||||
android:scrollIndicators="right"
|
||||
android:paddingBottom="35dp"
|
||||
android:scrollbarAlwaysDrawVerticalTrack="true"
|
||||
android:isScrollContainer="true"
|
||||
android:textIsSelectable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:paddingTop="10dp" />
|
||||
<TextView
|
||||
android:text=""
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/linkTitle"
|
||||
android:id="@+id/LinkError"
|
||||
android:textColor="#ffff0000"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingTop="10dp" />
|
||||
<ImageButton
|
||||
android:src="@drawable/obraz4"
|
||||
android:layout_width="38.5dp"
|
||||
android:layout_height="35.0dp"
|
||||
android:id="@+id/backToSendPhoto"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="#ff0b31c8"
|
||||
android:textColor="#fffcfcfc"
|
||||
android:background="#ffbdd7f0"
|
||||
android:gravity="center"
|
||||
android:onClick="GoToPoLogowaniu" />
|
||||
<TextView
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<cache-path name="my_images"
|
||||
path="path" />
|
||||
</paths>
|
14
Serwer/Serwer.Infrastructure/DTO/UserHistoryDto.cs
Normal file
14
Serwer/Serwer.Infrastructure/DTO/UserHistoryDto.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serwer.Infrastructure.DTO
|
||||
{
|
||||
public class UserHistoryDto
|
||||
{
|
||||
public List<string> History { get; set; }
|
||||
public UserDto User { get; set; }
|
||||
}
|
||||
}
|
74
Serwer/Serwer.Infrastructure/Framework/OCRResponseData.cs
Normal file
74
Serwer/Serwer.Infrastructure/Framework/OCRResponseData.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serwer.Infrastructure.Framework
|
||||
{
|
||||
public class OCRResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// Error message
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Available pages
|
||||
/// </summary>
|
||||
public int AvailablePages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OCRed text
|
||||
/// </summary>
|
||||
public List<List<string>> OCRText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output file1 URL
|
||||
/// </summary>
|
||||
public string OutputFileUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output file2 URL
|
||||
/// </summary>
|
||||
public string OutputFileUrl2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Output file3 URL
|
||||
/// </summary>
|
||||
public string OutputFileUrl3 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reserved
|
||||
/// </summary>
|
||||
public List<List<string>> Reserved { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OCRWords
|
||||
/// </summary>
|
||||
public List<List<OCRWSWord>> OCRWords { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Task description
|
||||
/// </summary>
|
||||
public string TaskDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public OCRResponseData()
|
||||
{
|
||||
OCRText = new List<List<string>>();
|
||||
Reserved = new List<List<string>>();
|
||||
OCRWords = new List<List<OCRWSWord>>();
|
||||
}
|
||||
}
|
||||
public class OCRWSWord
|
||||
{
|
||||
public int Top;
|
||||
public int Left;
|
||||
public int Height;
|
||||
public int Width;
|
||||
public string OCRWord;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ namespace Serwer.Infrastructure.Mappers
|
||||
=> new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<User, UserDto>();
|
||||
cfg.CreateMap<UserHistory, UserHistoryDto>();
|
||||
})
|
||||
.CreateMapper();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using Serwer.Core.Domain;
|
||||
using AutoMapper;
|
||||
using Serwer.Core.Domain;
|
||||
using Serwer.Core.Repositories;
|
||||
using Serwer.Infrastructure.DTO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -12,13 +14,15 @@ namespace Serwer.Infrastructure.Services
|
||||
{
|
||||
private readonly IHistoryRepository _historyRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository)
|
||||
private readonly IMapper _mapper;
|
||||
public HistoryService(IHistoryRepository historyRepository, IUserRepository userRepository, IMapper mapper)
|
||||
{
|
||||
_historyRepository = historyRepository;
|
||||
_userRepository = userRepository;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<UserHistory> GetAsync(Guid userId)
|
||||
public async Task<UserHistoryDto> GetAsync(Guid userId)
|
||||
{
|
||||
var user = await _userRepository.GetAsync(userId);
|
||||
if(user == null)
|
||||
@ -26,7 +30,7 @@ namespace Serwer.Infrastructure.Services
|
||||
throw new Exception("Coś poszło nie tak.");
|
||||
}
|
||||
var history = await _historyRepository.GetAsync(user);
|
||||
return history;
|
||||
return _mapper.Map<UserHistoryDto>(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Serwer.Core.Domain;
|
||||
using Serwer.Infrastructure.DTO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -9,6 +10,6 @@ namespace Serwer.Infrastructure.Services
|
||||
{
|
||||
public interface IHistoryService
|
||||
{
|
||||
Task<UserHistory> GetAsync(Guid userId);
|
||||
Task<UserHistoryDto> GetAsync(Guid userId);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
using Serwer.Core.Domain;
|
||||
using Newtonsoft.Json;
|
||||
using Serwer.Core.Domain;
|
||||
using Serwer.Infrastructure.Framework;
|
||||
using Serwer.Infrastructure.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tesseract;
|
||||
@ -19,12 +22,64 @@ namespace Serwer.Infrastructure.Services
|
||||
}
|
||||
public async Task<string> Process(string name, string contentType, byte[] bytes)
|
||||
{
|
||||
string license_code = "FC935C59-F248-48A3-9970-8A6BDB66FA86";
|
||||
string user_name = "poszukiwacz";
|
||||
|
||||
string ocrURL = @"http://www.ocrwebservice.com/restservices/processDocument?gettext=true&outputformat=txt&language=polish";
|
||||
byte[] uploadData = bytes;
|
||||
|
||||
HttpWebRequest request = CreateHttpRequest(ocrURL, user_name, license_code, "POST");
|
||||
request.ContentLength = uploadData.Length;
|
||||
|
||||
// Send request
|
||||
using (System.IO.Stream post = request.GetRequestStream())
|
||||
{
|
||||
post.Write(uploadData, 0, (int)uploadData.Length);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Get response
|
||||
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
|
||||
{
|
||||
// Parse JSON response
|
||||
string strJSON = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
|
||||
OCRResponseData ocrResponse = JsonConvert.DeserializeObject<OCRResponseData>(strJSON);
|
||||
|
||||
return await Task.FromResult(ocrResponse.OCRText.First().First());
|
||||
|
||||
}
|
||||
}
|
||||
catch (WebException wex)
|
||||
{
|
||||
var x = string.Format("OCR API Error. HTTPCode:{0}", ((HttpWebResponse)wex.Response).StatusCode);
|
||||
throw wex;
|
||||
}
|
||||
/*
|
||||
var engine = new TesseractEngine(System.IO.Path.Combine(_env, "tessdata"),"eng+equ", EngineMode.Default);
|
||||
var img = Pix.LoadFromMemory(bytes);
|
||||
var res = engine.Process(img);
|
||||
var txt = res.GetText();
|
||||
|
||||
return await Task.FromResult(txt);
|
||||
*/
|
||||
|
||||
}
|
||||
private static HttpWebRequest CreateHttpRequest(string address_url, string user_name, string license_code, string http_method)
|
||||
{
|
||||
Uri address = new Uri(address_url);
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
|
||||
|
||||
byte[] authBytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", user_name, license_code).ToCharArray());
|
||||
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);
|
||||
request.Method = http_method;
|
||||
request.Timeout = 600000;
|
||||
|
||||
// Specify Response format to JSON or XML (application/json or application/xml)
|
||||
request.ContentType = "application/json";
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,30 @@ namespace Serwer.Infrastructure.Services
|
||||
}
|
||||
await _historyRepository.AddAsync(user, query);
|
||||
|
||||
var queries = query.Split('.').ToList();
|
||||
if (queries.Count > 2)
|
||||
{
|
||||
var q0 = queries[0].Split(' ');
|
||||
if (q0.Length < 3)
|
||||
{
|
||||
queries.RemoveAt(0);
|
||||
}
|
||||
if(queries.Last().Length < 5)
|
||||
{
|
||||
queries.RemoveAt(queries.Count - 1);
|
||||
}
|
||||
}
|
||||
query = String.Join(".", queries);
|
||||
var result = await sendRequest(query);
|
||||
if(result.Count == 0)
|
||||
{
|
||||
result = await sendRequest(queries.Last());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
private async Task<List<SearchResultDTO>> sendRequest(string query)
|
||||
{
|
||||
WebRequest webRequest = WebRequest.Create($"https://www.googleapis.com/customsearch/v1?key={apiKey}&cx={searchEngineId}&q={query}");
|
||||
using (var stream = new StreamReader(webRequest.GetResponse().GetResponseStream()))
|
||||
{
|
||||
@ -42,6 +66,8 @@ namespace Serwer.Infrastructure.Services
|
||||
dynamic jsonData = JsonConvert.DeserializeObject(response);
|
||||
|
||||
var results = new List<SearchResultDTO>();
|
||||
try
|
||||
{
|
||||
foreach (var item in jsonData.items)
|
||||
{
|
||||
results.Add(new SearchResultDTO
|
||||
@ -53,6 +79,11 @@ namespace Serwer.Infrastructure.Services
|
||||
}
|
||||
return results;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user