Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Android.Dialog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<RootNamespace>Android.Dialog</RootNamespace>
<AssemblyName>Android.Dialog</AssemblyName>
<FileAlignment>512</FileAlignment>
<TargetFrameworkVersion>v1.6</TargetFrameworkVersion>
<AndroidSupportedAbis>armeabi%3barmeabi-v7a%3bx86</AndroidSupportedAbis>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidStoreUncompressedFileExtensions />
Expand All @@ -35,7 +34,6 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -77,9 +75,15 @@
<Compile Include="StringElement.cs" />
<Compile Include="ViewElement.cs" />
<Compile Include="WebContentElement.cs" />
<Compile Include="DrawingActivity.cs" />
<Compile Include="DrawingElement.cs" />
<Compile Include="DrawingView.cs" />
<Compile Include="Utility\ImageUtility.cs" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Layout\dialog_boolfieldleft.xml" />
<AndroidResource Include="Resources\Layout\drawing_element.axml" />
<AndroidResource Include="Resources\Layout\drawing_field.axml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\Layout\dialog_boolfieldright.xml" />
Expand Down
8 changes: 8 additions & 0 deletions DialogActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ namespace Android.Dialog
{
public class DialogActivity : ListActivity
{


protected override void OnResume()
{
base.OnResume();
ReloadData();
}

public RootElement Root
{
get { return _dialogAdapter == null ? null : _dialogAdapter.Root; }
Expand Down
51 changes: 51 additions & 0 deletions DrawingActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Java.IO;

namespace Android.Dialog
{
[Activity (Label = "DrawingActivity", Theme = "@android:style/Theme.NoTitleBar.Fullscreen")]
public class DrawingActivity : Activity
{

public static readonly string DRAWING_LOCATION_INTENT = "DrawingLocation";
public static string BACKGROUND_FILE_PATH = Android.OS.Environment.ExternalStorageDirectory + File.Separator + "drawing_image_reservered_location.png";
private LinearLayout _signatureLayout;
private DrawingView _signatureDrawingView;
private string drawingLocation;

protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

drawingLocation = Intent.GetStringExtra(DRAWING_LOCATION_INTENT);


SetContentView(Resource.Layout.drawing_field);
_signatureLayout = FindViewById<LinearLayout>(Resource.Id.drawingfield_drawingview);
_signatureDrawingView = new DrawingView(this, drawingLocation);
_signatureLayout.AddView(_signatureDrawingView);
Button saveButton = FindViewById<Button>(Resource.Id.drawingfield_save);
Button clearButton = FindViewById<Button>(Resource.Id.drawingfield_clear);


saveButton.Click += delegate
{
_signatureDrawingView.SaveImage(drawingLocation);

Finish();
};

clearButton.Click += delegate
{
_signatureDrawingView.ClearImage();
};
}
}
}

154 changes: 154 additions & 0 deletions DrawingElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Widget;

namespace Android.Dialog
{
public class DrawingElement : Element
{
// Height for rows
const int dimx = 400;
const int dimy = 300;
// radius for rounding
const int roundPx = 12;
Bitmap backgroundBitmap;
Bitmap drawingBitmap;
string drawingLocation;
string fieldLabel;

public DrawingElement(string fieldLabel,
Bitmap backgroundBitmap,
string drawingLocation)
: base(string.Empty)
{
this.fieldLabel = fieldLabel;
this.backgroundBitmap = backgroundBitmap;
this.drawingLocation = drawingLocation;
}


private View MakeEmpty(Context context)
{


LayoutInflater layoutInflater = LayoutInflater.FromContext(context);
View curView = (View)layoutInflater.Inflate(Resource.Layout.drawing_element,
null);

return curView;
}


protected override void Dispose(bool disposing)
{
if (disposing)
{
if (backgroundBitmap != null)
backgroundBitmap.Dispose();
if (drawingBitmap != null)
drawingBitmap.Dispose();
}
base.Dispose(disposing);
}

/* C# doens't support Tagging
private class ViewHolder
{
public TextView labelTV;
public ImageView drawingIV;
}
*/

public void InitializeView(View row)
{
/** C# doesn't support setTag methods, fixed in next patch.
ViewHolder viewHolder = new ViewHolder();
viewHolder.labelTV = (TextView) row.FindViewById(Resource.Id.drawing_element_textview);
viewHolder.drawingIV = (ImageView) row.FindViewById(Resource.Id.drawing_element_imageview);
row.SetTag(viewHolder); */
}



public void SetValues(View row)
{
//TODO: Need suppport for tagging to reuse these views.
TextView labelTV = (TextView) row.FindViewById(Resource.Id.drawing_element_textview);
ImageView drawingIV = (ImageView) row.FindViewById(Resource.Id.drawing_element_imageview);


labelTV.SetText(fieldLabel, TextView.BufferType.Normal);

/* TODO: should only be loaded when it is changed */
drawingBitmap = ImageUtility.LoadImage(this.drawingLocation);

if (drawingBitmap != null)
{
drawingIV.SetImageBitmap(drawingBitmap);
}
else
{
drawingIV.SetImageBitmap(backgroundBitmap);
}

/* C# doesn't support tagging
ViewHolder vh = (ViewHolder) row.GetTag();
vh.labelTV.SetText(fieldLabel, TextView.BufferType.Normal);
drawingBitmap = ImageUtility.LoadImage(this.drawingLocation);

if (drawingBitmap != null)
{
vh.drawingIV.SetImageBitmap(drawingBitmap);
drawingBitmap.Recycle();
drawingBitmap = null;

}
else
{
vh.drawingIV.SetImageBitmap(backgroundBitmap);
}
*/
}


public override View GetView(Context context,
View convertView,
ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = MakeEmpty(context);
InitializeView(row);
SetValues(row);

} else
{
SetValues(row);
}
Click = delegate
{
DrawImage();
};

return row;

}

public void DrawImage()
{
ImageUtility.SaveImage(backgroundBitmap,
DrawingActivity.BACKGROUND_FILE_PATH);
Intent drawImageIntent = new Intent(GetContext(),
typeof(DrawingActivity));
drawImageIntent.PutExtra(DrawingActivity.DRAWING_LOCATION_INTENT,
drawingLocation);


GetContext().StartActivity(drawImageIntent);
}
}
}
Loading