take profile photos by android phone (still very buggy)
This commit is contained in:
1 parent
da843b4f06
commit
6d008cdc06
17 files changed
+339
-48
No files matched your search
@@ -15,6 +15,7 @@
|
||||
<AndroidApplication>True</AndroidApplication>
|
||||
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
|
||||
<AssemblyName>AndroidRemote</AssemblyName>
|
||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -78,7 +79,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
<None Include="Assets\AboutAssets.txt" />
|
||||
<None Include="Properties\AndroidManifest.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\Main.axml" />
|
||||
@@ -88,5 +89,6 @@
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="ClientServerLib\" />
|
||||
<Folder Include="Assets\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.Content.PM;
|
||||
using Android.Graphics;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.OS;
|
||||
using Android.Provider;
|
||||
|
||||
using ClientServerLib;
|
||||
using Vocaluxe.Base.Server;
|
||||
@@ -20,7 +24,14 @@ namespace AndroidRemote
|
||||
Button bLogin;
|
||||
Button bUp;
|
||||
Button bDown;
|
||||
Button bSendAvatar;
|
||||
bool loggedIn;
|
||||
byte[] fileBytes;
|
||||
|
||||
ImageView imageView;
|
||||
Java.IO.File file;
|
||||
Java.IO.File dir;
|
||||
System.IO.FileStream fs;
|
||||
|
||||
protected override void OnCreate (Bundle bundle)
|
||||
{
|
||||
@@ -46,12 +57,66 @@ namespace AndroidRemote
|
||||
bDown.Click += delegate {
|
||||
client.SendMessage (CCommands.CreateCommandWithoutParams (CCommands.CommandSendKeyDown), OnResponse);
|
||||
};
|
||||
|
||||
imageView = FindViewById<ImageView>(Resource.Id.imageView1);
|
||||
|
||||
bSendAvatar = FindViewById<Button> (Resource.Id.btSendAvatar);
|
||||
bSendAvatar.Click += SendAvatar;
|
||||
}
|
||||
|
||||
protected override void OnStop ()
|
||||
{
|
||||
base.OnStop();
|
||||
client.Close();
|
||||
//client.Close();
|
||||
}
|
||||
|
||||
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
||||
{
|
||||
base.OnActivityResult(requestCode, resultCode, data);
|
||||
|
||||
// make it available in the gallery
|
||||
Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
|
||||
Android.Net.Uri contentUri = Android.Net.Uri.FromFile(file);
|
||||
mediaScanIntent.SetData(contentUri);
|
||||
SendBroadcast(mediaScanIntent);
|
||||
System.IO.FileInfo fi = new System.IO.FileInfo(file.Path);
|
||||
fs = new System.IO.FileStream(file.Path, System.IO.FileMode.Open);
|
||||
fileBytes = new byte[fi.Length];
|
||||
fs.BeginRead (fileBytes, 0, (int)fi.Length, new AsyncCallback(OnFileRead), null);
|
||||
}
|
||||
|
||||
private void OnFileRead(IAsyncResult ar)
|
||||
{
|
||||
if (fileBytes == null)
|
||||
return;
|
||||
|
||||
fs.Flush();
|
||||
fs.Close();
|
||||
client.SendMessage (CCommands.CreateCommandSendAvatarPictureJpg(fileBytes), OnResponse);
|
||||
}
|
||||
|
||||
private bool IsThereAnAppToTakePictures()
|
||||
{
|
||||
Intent intent = new Intent(MediaStore.ActionImageCapture);
|
||||
IList<ResolveInfo> availableActivities = PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
|
||||
return availableActivities != null && availableActivities.Count > 0;
|
||||
}
|
||||
|
||||
private void SendAvatar(object sender, EventArgs eventArgs)
|
||||
{
|
||||
if (!IsThereAnAppToTakePictures())
|
||||
return;
|
||||
|
||||
Intent intent = new Intent(MediaStore.ActionImageCapture);
|
||||
dir = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures), "AndroidRemote");
|
||||
if (dir.Exists())
|
||||
{
|
||||
dir.Mkdirs();
|
||||
}
|
||||
|
||||
file = new Java.IO.File(dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
|
||||
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
|
||||
StartActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
private void Connect()
|
||||
@@ -138,6 +203,35 @@ namespace AndroidRemote
|
||||
Toast.MakeText(this, "Not Logged In", ToastLength.Short).Show();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BitmapHelpers
|
||||
{
|
||||
public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
|
||||
{
|
||||
// First we get the the dimensions of the file on disk
|
||||
BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
|
||||
BitmapFactory.DecodeFile(fileName, options);
|
||||
|
||||
// Next we calculate the ratio that we need to resize the image by
|
||||
// in order to fit the requested dimensions.
|
||||
int outHeight = options.OutHeight;
|
||||
int outWidth = options.OutWidth;
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (outHeight > height || outWidth > width)
|
||||
{
|
||||
inSampleSize = outWidth > outHeight
|
||||
? outHeight / height
|
||||
: outWidth / width;
|
||||
}
|
||||
|
||||
// Now we will load the image and have BitmapFactory resize it for us.
|
||||
options.InSampleSize = inSampleSize;
|
||||
options.InJustDecodeBounds = false;
|
||||
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
|
||||
return resizedBitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?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="AndroidRemote.AndroidRemote">
|
||||
<uses-sdk />
|
||||
<application android:label="AndroidRemote" android:icon="@drawable/icon"></application>
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
</manifest>
|
||||
+22
-13
@@ -72,9 +72,15 @@ namespace AndroidRemote
|
||||
// aapt resource value: 0x7f060005
|
||||
public const int btLogin = 2131099653;
|
||||
|
||||
// aapt resource value: 0x7f060008
|
||||
public const int btSendAvatar = 2131099656;
|
||||
|
||||
// aapt resource value: 0x7f060006
|
||||
public const int btUp = 2131099654;
|
||||
|
||||
// aapt resource value: 0x7f060009
|
||||
public const int imageView1 = 2131099657;
|
||||
|
||||
// aapt resource value: 0x7f060001
|
||||
public const int tbIP = 2131099649;
|
||||
|
||||
@@ -137,32 +143,35 @@ namespace AndroidRemote
|
||||
// aapt resource value: 0x7f040004
|
||||
public const int button_logout = 2130968580;
|
||||
|
||||
// aapt resource value: 0x7f040007
|
||||
public const int button_send_avatar = 2130968583;
|
||||
|
||||
// aapt resource value: 0x7f040005
|
||||
public const int button_up = 2130968581;
|
||||
|
||||
// aapt resource value: 0x7f04000d
|
||||
public const int ip_address = 2130968589;
|
||||
|
||||
// aapt resource value: 0x7f040007
|
||||
public const int message_connected = 2130968583;
|
||||
// aapt resource value: 0x7f04000e
|
||||
public const int ip_address = 2130968590;
|
||||
|
||||
// aapt resource value: 0x7f040008
|
||||
public const int message_disconnected = 2130968584;
|
||||
public const int message_connected = 2130968584;
|
||||
|
||||
// aapt resource value: 0x7f040009
|
||||
public const int message_logged_in = 2130968585;
|
||||
public const int message_disconnected = 2130968585;
|
||||
|
||||
// aapt resource value: 0x7f04000a
|
||||
public const int message_logged_out = 2130968586;
|
||||
|
||||
// aapt resource value: 0x7f04000e
|
||||
public const int password = 2130968590;
|
||||
public const int message_logged_in = 2130968586;
|
||||
|
||||
// aapt resource value: 0x7f04000b
|
||||
public const int text_ip_address = 2130968587;
|
||||
public const int message_logged_out = 2130968587;
|
||||
|
||||
// aapt resource value: 0x7f04000f
|
||||
public const int password = 2130968591;
|
||||
|
||||
// aapt resource value: 0x7f04000c
|
||||
public const int text_password = 2130968588;
|
||||
public const int text_ip_address = 2130968588;
|
||||
|
||||
// aapt resource value: 0x7f04000d
|
||||
public const int text_password = 2130968589;
|
||||
|
||||
static String()
|
||||
{
|
||||
|
||||
@@ -49,4 +49,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btDown"
|
||||
android:enabled="false" />
|
||||
<Button
|
||||
android:text="@string/button_send_avatar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btSendAvatar"
|
||||
android:enabled="true" />
|
||||
<ImageView
|
||||
android:src="@android:drawable/ic_menu_gallery"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/imageView1" />
|
||||
</LinearLayout>
|
||||
@@ -7,6 +7,7 @@
|
||||
<string name="button_logout">Logout</string>
|
||||
<string name="button_up">Up</string>
|
||||
<string name="button_down">Down</string>
|
||||
<string name="button_send_avatar">Send Avatar Picture</string>
|
||||
<string name="message_connected">Connected</string>
|
||||
<string name="message_disconnected">Disconnected</string>
|
||||
<string name="message_logged_in">Logged in</string>
|
||||
|
||||
Reference in new issue
Block a user