<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gwenn GUIHAL</title>
	<atom:link href="http://blog.myrddin.fr/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.myrddin.fr</link>
	<description>Mobile development</description>
	<lastBuildDate>Tue, 19 Mar 2013 10:29:16 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Drop shadow layer below UITextView</title>
		<link>http://blog.myrddin.fr/drop-shadow-layer-below-uitextview/</link>
		<comments>http://blog.myrddin.fr/drop-shadow-layer-below-uitextview/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 10:29:16 +0000</pubDate>
		<dc:creator>Gwenn Guihal</dc:creator>
				<category><![CDATA[IOS]]></category>

		<guid isPermaLink="false">http://blog.myrddin.fr/?p=34</guid>
		<description><![CDATA[I needed a UITextView as textField. I decided to add an inner drop shadow at my textview to seem pretty cool It seems be easy to do : just add a drop shadowed CALayer below the textView and set masksToBounds to YES. Unfortunately, it doesn&#8217;t work I don&#8217;t know why, but some blinking appears and [...]]]></description>
				<content:encoded><![CDATA[<p>I needed a UITextView as textField. I decided to add an inner drop shadow at my textview to seem pretty cool <img src='http://blog.myrddin.fr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It seems be easy to do : just add a drop shadowed CALayer below the textView and set masksToBounds to YES.</p>
<pre class="brush: cpp; title: ; notranslate">
self.textView.layer.cornerRadius = 8.0;

self.shadowLayer = [[CALayer alloc] init];

self.shadowLayer.frame = self.textField.frame;
self.shadowLayer.cornerRadius = self.textView.layer.cornerRadius;
self.shadowLayer.borderColor = [UIColor lightGrayColor].CGColor;
self.shadowLayer.borderWidth = 1.5f;
self.shadowLayer.shadowColor = [UIColor blackColor].CGColor;
self.shadowLayer.shadowOpacity = 0.7;
self.shadowLayer.shadowOffset = CGSizeMake(2.0, 2.0);
self.shadowLayer.shadowRadius = 3.0;
self.shadowLayer.masksToBounds = YES;

[self.view.layer insertSublayer:self.shadowLayer above:self.textView.layer];
</pre>
<p><img src="http://blog.myrddin.fr/wp-content/uploads/2013/03/Capture-d’écran-2013-03-19-à-10.44.54.png" alt="Capture d’écran 2013-03-19 à 10.44.54" width="336" height="513" class="alignnone size-full wp-image-43" /></p>
<p>Unfortunately, it doesn&rsquo;t work <img src='http://blog.myrddin.fr/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  I don&rsquo;t know why, but some blinking appears and the behaviour of the caret isn&rsquo;t normal. Sometimes a black rectangle appears above the text.<br />
If I set the value of maskToBounds to NO, it works very well but my drop shadow overflows.</p>
<p><img src="http://blog.myrddin.fr/wp-content/uploads/2013/03/Capture-d’écran-2013-03-19-à-10.48.57.png" alt="Capture d’écran 2013-03-19 à 10.48.57" width="249" height="140" class="alignnone size-full wp-image-44" /></p>
<p>To avoid that, the only solution I know is to add a mask to the layer.</p>
<pre class="brush: cpp; title: ; notranslate">
CALayer *maskLayer = [[CALayer alloc] init];
maskLayer.anchorPoint = CGPointZero;
maskLayer.bounds = self.shadowLayer.bounds;
maskLayer.backgroundColor = [UIColor blackColor].CGColor;
maskLayer.cornerRadius = self.shadowLayer.cornerRadius;

[self.shadowLayer setMask:maskLayer];
</pre>
<p><img src="http://blog.myrddin.fr/wp-content/uploads/2013/03/Capture-d’écran-2013-03-19-à-10.53.36.png" alt="Capture d’écran 2013-03-19 à 10.53.36" width="338" height="173" class="alignnone size-full wp-image-45" /></p>
<p>Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myrddin.fr/drop-shadow-layer-below-uitextview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Native Interface for Android</title>
		<link>http://blog.myrddin.fr/java-native-interface-for-android/</link>
		<comments>http://blog.myrddin.fr/java-native-interface-for-android/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 14:35:14 +0000</pubDate>
		<dc:creator>Gwenn Guihal</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jni]]></category>

		<guid isPermaLink="false">http://blog.myrddin.fr/?p=15</guid>
		<description><![CDATA[What ? JNI allows to use C++ code with Java, on Android for example. For what ? For few stuff : To not rewrite in Java a useful existing library. To use the same library on Android and IOS. At my mind, point 2 is essential. For many things, C++ is faster than Java. How [...]]]></description>
				<content:encoded><![CDATA[<h2>What ?</h2>
<p>JNI allows to use C++ code with Java, on Android for example.</p>
<h2>For what ?</h2>
<p>For few stuff :</p>
<ol>
<li>To not rewrite in Java a useful existing library.</li>
<li>To use the same library on Android and IOS.</li>
<li>At my mind, point 2 is essential.</li>
<li>For many things, C++ is faster than Java.</li>
</ol>
<h2>How to proceed ?</h2>
<p>Because I don&rsquo;t know C++, I will be brief. I looked the <a href="http://www.andengine.org/" target="_blank">AndEngine</a>&lsquo;s guys job and reproduce it for my works.<br />
You would only need to copy and edit two or three files, install Cygwin (with c++ extensions) if you are on Windows and that&rsquo;s all !</p>
<h2>Sample ?</h2>
<p>Yes, print a random number in console : the best example never seen before.<br />
1) Install the <a title="android ndk crystaX" href="http://www.crystax.net/fr/android/ndk" target="_blank">last improved Android NDK</a> from Dmitry Moskalchuk aka CrystaX.<br />
He says :</p>
<blockquote><p>You shouldn&rsquo;t care about wide chars/strings/streams anymore when porting existing code to Android &#8211; just compile it using my NDK and go further. Download and enjoy!</p></blockquote>
<p>I used ndk6 for the sample.<br />
2) Create a new android project in eclipse, call it &laquo;&nbsp;HelloJNI&nbsp;&raquo;, choose SDK 2.1.<br />
3) Create a folder &laquo;&nbsp;jni&nbsp;&raquo; and copy files from the same folder on <a href="https://github.com/myrddinus/HelloJNI" target="_blank">the github repository</a>.<br />
4) The C++ lib is called myGreatLib and contains one function : &laquo;&nbsp;giveMeANumber&nbsp;&raquo;  which returns a random int.<br />
5) Now, we have to write a little bit of java code! Create &laquo;&nbsp;HelloJNI.java&nbsp;&raquo; then declare required native and java methods.</p>
<pre class="brush: java; title: ; notranslate">
// native methods
private native int jniGiveMeANumber();

// java methods
public void giveMeANumber()
{
	int num = jniGiveMeANumber();
	Log.e(&quot;JNI&quot;, &quot;Number : &quot; + num );
}
</pre>
<p>With this class, we generate a header C++ file with which we will write the C++ code to call our amazing lib.<br />
Open a shell, go to HelloJNI/bin/classes then run command:</p>
<pre class="brush: bash; title: ; notranslate">
javah fr.myrddin.hellojni.HelloJNI
</pre>
<p>This command generates a C++ header file at the root of your bin/classes folder. Copy the &laquo;&nbsp;fr_myrddin_hellojni_HelloJNI.h&nbsp;&raquo; file into the &laquo;&nbsp;jni&nbsp;&raquo; folder and rename it &laquo;&nbsp;HelloJNI.h&nbsp;&raquo;.<br />
<a href="http://blog.myrddin.fr/wp-content/uploads/2012/03/shell.jpg"><img class="alignnone size-full wp-image-17" title="shell" src="http://blog.myrddin.fr/wp-content/uploads/2012/03/shell.jpg" alt="" width="677" height="342" /></a><br />
Well done. We write now the cpp file HelloJNI.cpp from the generated header :</p>
<pre class="brush: cpp; title: ; notranslate">
#include &quot;HelloJNI.h&quot;
#include &quot;myGreatLib/Hello.cpp&quot;

#ifdef ANDROID
#include
#endif

JNIEXPORT jint JNICALL Java_fr_myrddin_hellojni_HelloJNI_jniGiveMeANumber(JNIEnv *, jobject)
{
	Hello hello;
	return hello.giveMeANumber();
}
</pre>
<p>6) We just have to compile our C++ lib. For that, I took Android.mk, Application.mk, and build.sh files from the port of Box2D by <a title="libgdx" href="http://code.google.com/p/libgdx/" target="_blank">Libgdx</a> (Mario Zechner) and <a title="andengine" href="http://code.google.com/p/andenginephysicsbox2dextension/" target="_blank">AndEngine</a> (Nicolas Gramlich).<br />
Edit Android.mk file :</p>
<pre class="brush: bash; title: ; notranslate">
...
LOCAL_MODULE := libHelloJNI
...
LOCAL_SRC_FILES := \
HelloJNI.cpp
</pre>
<p>Edit build.sh to set the project place and change the ndk folder by yours.<br />
Run Cygwin, then launch build.sh.<br />
<a href="http://blog.myrddin.fr/wp-content/uploads/2012/03/cygwin.jpg"><img class="alignnone size-full wp-image-18" title="cygwin" src="http://blog.myrddin.fr/wp-content/uploads/2012/03/cygwin.jpg" alt="" width="677" height="342" /></a><br />
Yes! It works! In the project, we have now a libs folder which contains the compiled lib : armeabi-v7a/libHelloJNI.so. Add it to build path.<br />
Add that code in HelloJNI.java, it allows to load the library.</p>
<pre class="brush: java; title: ; notranslate">
static
{
	System.loadLibrary(&quot;HelloJNI&quot;);
}
</pre>
<p>Edit HelloJNIActivity to test your library :</p>
<pre class="brush: java; title: ; notranslate">
HelloJNI test = new HelloJNI();
test.giveMeANumber();
</pre>
<p>Compile and run, &#8230;, look at the console, &#8230;, it works, you are the best!</p>
<h2>Next</h2>
<p>For more information, look a these links :<br />
<a title="androind ndk" href="http://developer.android.com/sdk/ndk/index.html" target="_blank">Android NDK</a><br />
<a href="http://developer.android.com/sdk/ndk/overview.html" target="_blank">What is the NDK?</a><br />
<a href="http://java.sun.com/docs/books/jni/html/jniTOC.html" target="_blank">The Java Native Interface, Programmer&rsquo;s Guide and Specification</a></p>
<p>For more detailled samples, there is a couple of library of my github :<br />
- <a href="https://github.com/myrddinus/AndroidClipper" target="_blank">AndroidClipper</a> : JNI wrapper of Angus Johnson&rsquo;s Polygon clipping library (my fist JNI library)<br />
- <a href="https://github.com/myrddinus/AndroidTriangulate" target="_blank">Triangulate</a> : JNI wrapper of John W. Ratcliff&rsquo;s Triangulate library.*<br />
- <a href="https://github.com/myrddinus/AndroidPoly2Tri" target="_blank">AndroidPoly2Tri</a> : JNI wrapper of poly2tri, a 2D constrained Delaunay triangulation library.</p>
<p>Good luck !</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myrddin.fr/java-native-interface-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
