<?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>Juggling Eggs &#187; Android</title>
	<atom:link href="http://sonnygill.net/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://sonnygill.net</link>
	<description>Priceless eggs, variable gravity</description>
	<lastBuildDate>Sat, 17 Apr 2010 17:28:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a horizontal rule (line) in Android</title>
		<link>http://sonnygill.net/android/horizontal-rule/</link>
		<comments>http://sonnygill.net/android/horizontal-rule/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 07:23:04 +0000</pubDate>
		<dc:creator>Sonny Gill</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonnygill.wordpress.com/?p=128</guid>
		<description><![CDATA[Use a View with fixed height -


 android:layout_width=&#34;fill_parent&#34;
 android:layout_height=&#34;2dip&#34;
 android:background=&#34;#FF00FF00&#34; /&#62;

or, in code -

View ruler = new View(myContext); ruler.setBackgroundColor(0xFF00FF00);
theParent.addView(ruler,
 new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 2));

Source &#8211; Romain Guy
]]></description>
			<content:encoded><![CDATA[<p>Use a View with fixed height -</p>
<pre class="brush: xml;">

 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;2dip&quot;
 android:background=&quot;#FF00FF00&quot; /&gt;
</pre>
<p>or, in code -</p>
<pre class="brush: java;">
View ruler = new View(myContext); ruler.setBackgroundColor(0xFF00FF00);
theParent.addView(ruler,
 new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 2));
</pre>
<p>Source &#8211; <a href="http://markmail.org/message/qcyt3uf5o2nexpwl">Romain Guy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/android/horizontal-rule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Viewport in Android</title>
		<link>http://sonnygill.net/android/android-viewport/</link>
		<comments>http://sonnygill.net/android/android-viewport/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 13:07:24 +0000</pubDate>
		<dc:creator>Sonny Gill</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Viewport]]></category>

		<guid isPermaLink="false">http://sonnygill.net/tech/android/creating-a-viewport-in-android/</guid>
		<description><![CDATA[I was writing a simple PacMan like game for Android, and needed to scroll the game area shown as the user moves inside it. In J2ME, you will use LayerManager.setViewWindow to create this kind of Viewport like behaviour. In Android, this can be achieved by using methods in Canvas and View classes.
Here is a simple [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing a simple PacMan like game for <strong>Android</strong>, and needed to scroll the game area shown as the user moves inside it. In J2ME, you will use LayerManager.setViewWindow to create this kind of <strong>Viewport</strong> like behaviour. In Android, this can be achieved by using methods in Canvas and View classes.</p>
<p>Here is a simple program demonstrating how to do it -</p>
<pre class="brush: java;">
public class AViewport extends Activity
{

 public void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
 setContentView( new PortView( this ) );

 }

 private class PortView extends View
 {
 // the length and width of a single square
 private int tileSide = 50;
 // the number of squares along x-axis and y-axis
 private int numTiles = 15;

 int fieldWidth = numTiles * tileSide;
 int fieldHeight = numTiles * tileSide;

 private int halfViewWidth;
 private int halfViewHeight;
 private int maxTranslateX;
 private int maxTranslateY;

 int viewWidth = 200;
 int viewHeight = 200;

 private int circleX;
 private int circleY;
 private int diameter = 50;

 private ShapeDrawable one;
 private ShapeDrawable two;

 private ShapeDrawable circle;
 Rect rect = new Rect();
 private Paint p;

 public PortView( Context context )
 {
 super( context );
 one = new ShapeDrawable( new RectShape() );
 two = new ShapeDrawable( new RectShape() );
 circle = new ShapeDrawable( new OvalShape() );
 one.getPaint().setColor( 0x88FF8844 );
 two.getPaint().setColor( 0x8844FF88 );
 circle.getPaint().setColor( 0x99000000 );
 p = new Paint();
 setFocusable( true );
 }

 @Override
 protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
 {
 int width = Math.min( fieldWidth, MeasureSpec.getSize( widthMeasureSpec ) );
 int height = Math.min( fieldHeight, MeasureSpec.getSize( heightMeasureSpec ) );

 viewWidth = width;
 viewHeight = height;
 halfViewWidth = width/2;
 halfViewHeight = height/2;
 maxTranslateX = fieldWidth - width;
 maxTranslateY = fieldHeight - height;

 setMeasuredDimension( width, height );
 }

/*
 _______________________________________
 | ______________                        |
 ||              |                       |
 ||              |vH                     |
 ||              |                       |
 ||______________|                       |
 |       vW                              |fH
 |       .(x1, y1)         ______________|
 |                        |              |
 |                        |              |
 |&lt;----------------------&gt;|              |
 |     maxTranslateX      |______________|
 |_______________________________________|
 fW

 We start translating once x,y goes past x1 (viewWidth/2),y1 (viewHeight/2).
 Movement along x-axis is x - x1, to the maximum of maxTranslateX (fieldWidth - viewWidth).
 The movement along y-axis is calculated similarly.
*/
 @Override
 protected void onDraw( Canvas canvas )
 {
 super.onDraw( canvas );

 canvas.save();

 if ( circleX &gt; halfViewWidth )
 {
 int translateX = Math.min( circleX - halfViewWidth, maxTranslateX );
 canvas.translate( -translateX, 0 );
 }

 if ( circleY &gt; halfViewHeight )
 {
 int translateY = Math.min( circleY - halfViewHeight, maxTranslateY );
 canvas.translate( 0, -translateY );
 }

 drawBoard( canvas );
 drawCircle( canvas );
 canvas.restore();
 }

 private void drawBoard( Canvas canvas )
 {
 int num = 1;
 boolean useTwo = false;
 for ( int row = 0; row &lt; numTiles; row++ )
 {
 int y = row * tileSide;
 for ( int col = 0; col &lt; numTiles; col++ )
 {
 int x = col * tileSide;
 Drawable d = useTwo ? two : one;
 d.setBounds( x, y, x + tileSide, y + tileSide );
 d.draw( canvas );
 canvas.drawText( &quot;&quot; + num, x + 10 , y + 20, p );
 ++num;
 useTwo = !useTwo;
 }
 }
 }

 private void setRect()
 {
 rect.set( circleX, circleY, circleX + diameter, circleY + diameter );
 }

 private void drawCircle( Canvas canvas )
 {
 setRect();
 circle.setBounds( rect );
 circle.draw( canvas );
 }

 @Override
 public boolean onKeyDown( int keyCode, KeyEvent keyEvent )
 {
 boolean handled = true;
 switch ( keyCode )
 {
 case KeyEvent.KEYCODE_DPAD_DOWN:
 if ( circleY &lt;= fieldHeight - diameter - 5 ) circleY += 5;
 break;
 case KeyEvent.KEYCODE_DPAD_UP:
 if( circleY &gt;= 5) circleY -= 5;
 break;
 case KeyEvent.KEYCODE_DPAD_LEFT:
 if( circleX &gt;= 5 ) circleX -= 5;
 break;
 case KeyEvent.KEYCODE_DPAD_RIGHT:
 if( circleX &lt;= fieldWidth - diameter -5 ) circleX += 5;
 break;
 default: handled = false;
 }
 if ( handled )
 {
 invalidate();
 }
 return handled;
 }
 }
}
</pre>
<p>See the Android API docs of <a title="View.onMeasure()" href="http://developer.android.com/reference/android/view/View.html#onMeasure(int,%20int)">View.onMeasure()</a> and <a title="Canvas.translate()" href="http://developer.android.com/reference/android/graphics/Canvas.html#translate(float,%20float)">Canvas.translate()</a> methods to understand the code used to create the Viewport.</p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/android/android-viewport/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android on Intellij Idea &#8211; run activity on emulator</title>
		<link>http://sonnygill.net/android/android-intellij-idea/</link>
		<comments>http://sonnygill.net/android/android-intellij-idea/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 22:11:58 +0000</pubDate>
		<dc:creator>Sonny Gill</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[IDEA]]></category>
		<category><![CDATA[IntelliJ]]></category>

		<guid isPermaLink="false">http://sonnygill.wordpress.com/?p=111</guid>
		<description><![CDATA[The official Android plugin is only for Eclipse, but thankfully Android provides Ant support for those of us who prefer other IDEs (http://developer.android.com/guide/developing/other-ide.html).
I use Intellij IDEA, and the main problem for me was that, after building the application using the Ant build script created by activitycreator tool, you have to manually reload the application in [...]]]></description>
			<content:encoded><![CDATA[<p>The official Android plugin is only for Eclipse, but thankfully Android provides Ant support for those of us who prefer other IDEs (http://developer.android.com/guide/developing/other-ide.html).</p>
<p>I use Intellij IDEA, and the main problem for me was that, after building the application using the Ant build script created by activitycreator tool, you have to manually reload the application in the emulator.</p>
<p>This is easily fixed by tweaking the generated Ant build file.<br />
Add the following target to the build.xml -</p>
<pre class="brush: xml;">
 &lt;!-- Main activity --&gt;
&lt;property name=&quot;main-activity&quot; value=&quot;MyMainActivity&quot; /&gt;

 &lt;!-- Run the main Activity after reinstall --&gt;
 &lt;target name=&quot;run&quot; depends=&quot;reinstall&quot;&gt;
 &lt;echo&gt;Running ${application-package}.${main-activity} on default emulator...&lt;/echo&gt;
 &lt;exec executable=&quot;${adb}&quot; failonerror=&quot;true&quot;&gt;
 &lt;arg value=&quot;shell&quot; /&gt;
 &lt;arg value=&quot;am&quot; /&gt;
 &lt;arg value=&quot;start&quot; /&gt;
 &lt;arg value=&quot;-a&quot; /&gt;
 &lt;arg value=&quot;android.intent.action.MAIN&quot; /&gt;
 &lt;arg value=&quot;-n&quot; /&gt;
 &lt;arg value=&quot;${application-package}/${application-package}.${main-activity}&quot; /&gt;
 &lt;/exec&gt;
 &lt;/target&gt;
</pre>
<p>MyMainActivity is, of course, your main activity. Remember to change the build file if you rename or change the main activity.</p>
<p>I also changed the default target to run, and after loading build.xml as an Ant build file in IDEA, I assigned it a shortcut key.<br />
I also made these changes to ANDROID_SDK/tools/lib/build.template, so from now on, when I create a new Android project, it is already set up this way. If you are editing the template file, use -</p>
<pre class="brush: xml;">
 &lt;!-- Main activity --&gt;
&lt;property name=&quot;main-activity&quot; value=&quot;ACTIVITY_NAME&quot; /&gt;
</pre>
<p>This will automatically pick up the class name you specify on the command line when running activitycreator.</p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/android/android-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
