custom border around camera screen - xamarin.android

Use this code to draw an custom border for the camera.
It works well on versions above 5
It does not work on less than 4.2 or 4.4 .
I want to modify the file to work on all versions.
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="220dp" android:height="220dp" android:viewportHeight="230.0" android:viewportWidth="230.0">
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M165,5C178.2,5 198.2,5 225,5L225,30.79L225,65"
android:strokeColor="#color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,65C5,51.8 5,31.8 5,5L30.79,5L65,5"
android:strokeColor="#color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M165,225C178.2,225 198.2,225 225,225L225,199.21L225,165"
android:strokeColor="#color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,165C5,178.2 5,198.2 5,225L30.79,225L65,225"
android:strokeColor="#color/qr_code_reader_square" android:strokeWidth="10"/>
</vector>

You could support older versions with the Android support library, which provides the VectorDrawableCompat and AnimatedVectorDrawableCompat classes.
Refer to Vector drawables
in Xamarin.Android,you could install the nuget VectorCompat.

Related

Visual Studio (Xamarin): DependencyService + Nuget + iOS = Fail

We are writing a Visual Studio (Xamarin) cross-platform application that will share quite a bit of functionality with the next application we write, so we wanted to put that shared functionality into a "library" so we could test it, share it easily, etc.
The only way we found to write a cross-platform library, is to create it using the standard Xamarin DependencyService paradigm, turn it into a NuGet package, and then load that package into our main app. For better or worse, we did this before Microsoft provided a template for generating NuGet libraries like this, so we had to roll it ourselves.
This works fine for Android, but now I'd like to get the same code working for iOS and it's simply not working. No errors, no warnings, but when I run the app and call
Client = DependencyService.Get<IClient>();
It simply returns null. If I look at the Output/Debug window, it is loading the 'Company.Client.Abstractions.dll' (the root DLL containing the definition of IClient) but not the iOS-specific 'Company.Client.dll' (which contains the iOS-specific implementation of IClient).
Here's my nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>Client</id>
<version>0.0.35</version>
<authors>Me</authors>
<owners>Company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Stuff</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright 2017 Company</copyright>
<dependencies>
<group targetFramework="MonoAndroid">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="Xamarin.iOS10">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="uap">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
</dependencies>
</metadata>
<files>
<!-- Cross-platform reference assemblies -->
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.dll" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.dll" />
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.pdb" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.pdb" />
<!-- iOS reference assemblies -->
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.dll" target="lib\Xamarin.iOS10\Company.Client.dll" />
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.pdb" target="lib\Xamarin.iOS10\Company.Client.pdb" />
<!-- Android reference assemblies -->
<file src="Company.Client.Android\bin\Debug\Company.Client.dll" target="lib\MonoAndroid10\Company.Client.dll" />
<file src="Company.Client.Android\bin\Debug\Company.Client.pdb" target="lib\MonoAndroid10\Company.Client.pdb" />
<!-- UWP reference assemblies -->
<file src="Company.Client.UWP\bin\Debug\Company.Client.dll" target="lib\UAP10\Company.Client.dll" />
<file src="Nuvectra.Client.UWP\bin\Debug\Company.Client.pdb" target="lib\UAP10\Company.Client.pdb" />
</files>
</package>
I'm thinking there are two classes of possible problems:
I'm generating the DLL wrong
I'm generating the application wrong
Looking at the generated DLLs, the Android DLL is 28k long, the iOS DLL is 23k, so it doesn't look like the iOS DLL is empty. Is there a tool that would let me inspect the iOS DLL and make sure it has the necessary entry point(s)?
The Project that generates the iOS DLL has these settings:
Target framework: Xamarin.iOS
Output type: Class Library
Condition compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
Platform: Active (Any CPU)
The application that is using the DLL has these settings for the iOS Project:
SDK Version: Default
Linker Behavior: Don't Link
Platform: Active (iPhone)
Supported Architectures: ARMv7 + ARM64
Target framework: Xamarin.IOS
Output type: Console Application
Conditional compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
The interface definition in my 'Abstractions' project looks like this:
namespace Company.Client
{
public abstract class IClient
{
void abstract function();
}
}
and the implementation in my iOS project looks like this:
using Company.Client.iOS;
[assembly: Xamarin.Forms.Dependency (typeof (IosClient))]
namespace Company.Client.iOS
{
public class IosClient : IClient
{
void override function();
}
}
We tried many different ways to create a NuGet package with platform-specific code loaded using DependencyService and every single way had the same problem - worked fine under Android, failed under iOS.
The solution is to create a class in the iOS library that is not loaded using DependencyService, and then in the iOS application, create an instance of that class. That's enough to convince the iOS application that it actually needs to load the iOS library DLL, and then the rest of the DependencyService magic works correctly.

How to work with AndroidManifest and Assembly

Base on Xamarin Studio instruction, I follow it to create the AndroidManifest which looks as below.
<?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="HelloMultiScreen.HelloMultiScreen">
<uses-sdk />
<application android:label="HelloMultiScreen">
<application>
<manifest>
I have these questions:
1) How come it DOES NOT list out all the control or widget like the google manifest?
2) Do I need to edit it whenever I add additional control or widget like textView ?
3) Do I need to care about the order of the control or widget of which I add first or later?
4) Do I need to manually add the below or it is self generated?
[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)]
[assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)]
thanks
Quite a lot of your questions are answered in this page - http://docs.xamarin.com/guides/android/advanced_topics/working_with_androidmanifest.xml
In general, Xamarin auto-generates much of the file for you, using hints in the code like [Activity] attributes.
I recommend you read that document above, experiment a little and then come back here if you have specific questions/problems.

Monodroid - How to include layouts?

I am looking at android documentation and if I want to use include and merge.
So I opened up eclipse and got it to extract some of the code out and it made in my layout this
<include layout="#layout/progressbar" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
and another file with
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="Loading..." android:layout_height="wrap_content" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="#+id/lblLoading" android:layout_marginLeft="180dp" android:layout_marginTop="240dp"></TextView>
<ProgressBar android:id="#+id/progBar" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="130dp" android:layout_marginTop="230dp"></ProgressBar>
</merge>
Yet when I try to do this in monodroid I get errors saying it can't find merge and include.
Do you have "warnings as errors" enabled? For code completion, Mono for Android includes an XSD for .axml files, and the XSD doesn't specify <include/> or <merge/>, and thus Visual Studio will generate a warning when those are used. Mono for Android doesn't care about them, though, and passes them through to aapt.
It would be useful if you could provide the exact error message.
try using
<ProgressBar android:progress.....
And continue, its more along the lines of messing around with different options.

iajc and aspectpath

I'm a bit confused with the aspectpath option of the iajc compiler.
My project use AspectJ to weave metric code into an existing swing application.
All the application source are packaged this way:
com.xxx.yyy.myapp.*
We have put our aspect in a package inside the same project:
com.xxx.yyy.aop.*
The project is built with javac first and the outpout goes into ${classes.dir}.
Then we invoke iacj this way:
<iajc inpath="${classes.dir}"
destDir="${classes.dir}"
fork="true"
maxmem="${aspectj.maxmem}"
verbose="true"
showWeaveInfo="true"
debug="true"
source="1.6"
target="1.6">
<classpath refid="ajclasspath"/>
</iajc>
and
<path id="ajclasspath">
<path refid="classpath"/>
<pathelement location="${scm.home}/ant_libs/aspectjrt.jar"/>
</path>
With that said, do i need to specify an aspectpath in the iajc?
Regards
According to documentation similar to classpath, aspectpath contains read-only, binary aspect libraries that are woven into sources but not included in the output. In your case you include your aspects in output and they are in ${classes.dir} with normal classes.
So you don't have to specify aspectpath when you don't want to separate your aspects.

Setting Midlet Icon using J2ME-Polish

I'm using J2ME Polish version 2.0.7 together with ant to build my Midlet application. In order to specifcy the main-class, name and icon of the application, the J2ME Polish documentation suggests that I use the midlet element inside the build element.
<build usePolishGui="false" >
<midlet name="My Killer App." icon="/logo.png" class="com.foo.MidletMain" />
...
</build>
however in the resulting .jad file only the classname is taken into account when I build my Midlet.
MIDlet-1: MidletMain,,com.foo.MidletMain
Can someone figure out what I'm doing wrong?
No it must be in the info section of the j2mepolish target:
<project ...>
<target name="j2mepolish" ...>
<j2mepolish>
<info ... icon="xxx.png">
What you will need to do is this:
<j2mepolish>
.....
<build>
...
<jad>
<attribute name="MIDlet-Icon" value="/icon.png" />
<jad>
</build>
Your icon would work!

Resources