<?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>Mea Cup O' Jo &#187; Programming</title>
	<atom:link href="http://dev.bostone.us/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.bostone.us</link>
	<description>Jump Right Ahead In My Web</description>
	<lastBuildDate>Mon, 12 Dec 2011 18:30:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>View core Android Java sources in Eclipse (final solution)</title>
		<link>http://dev.bostone.us/2011/12/13/android-core-sources-eclips/</link>
		<comments>http://dev.bostone.us/2011/12/13/android-core-sources-eclips/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 18:26:55 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=399</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why this is not really showing in Google search results but if you want to step through the core Android Java code in your Eclipse project, finally there&#8217;s a legit and very convenient solution that is a part of <a href="http://code.google.com/p/adt-addons/">ADT-Addons</a> project. Steps are pretty self-explanatory but just in case,  here&#8217;s what you need to do:</p>
<ol>
<li>In your Eclipse click Help-&gt;Install New Software</li>
<li>Click &#8220;Add&#8221; button and put this URL into resulting Pop-up (name it whatever you want): <a href="http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/">http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/</a></li>
<li>Click &#8220;OK&#8221; and mark &#8220;Android Sources&#8221; checkbox</li>
<li>Click &#8220;Next&#8221; and any &#8220;OK&#8221;, &#8220;Agree&#8221;, &#8220;Next&#8221; or &#8220;Finish&#8221; buttons afterwards</li>
<li>Restart Eclipse after the installation and now you can step right into Android code from your debugger and see the source code for Android Java files right in the Eclipse editor</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2011/12/13/android-core-sources-eclips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android: display orientation in phones vs tablets</title>
		<link>http://dev.bostone.us/2011/06/30/android-display-orientation-in-phones-vs-tablets/</link>
		<comments>http://dev.bostone.us/2011/06/30/android-display-orientation-in-phones-vs-tablets/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 15:57:20 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=386</guid>
		<description><![CDATA[If you have 2 layouts (portrait and landscape) and the order seems to be reversed on the tablet then switch to using getRotation instead of deprecated getOrientation. Something like this

    private void setLayout() {
        // Get display for detecting the phone orientation
    [...]]]></description>
			<content:encoded><![CDATA[<p>If you have 2 layouts (portrait and landscape) and the order seems to be reversed on the tablet then switch to using <strong>getRotation </strong>instead of deprecated <strong>getOrientation</strong>. Something like this</p>
<pre class="brush: java; title: ; notranslate">
    private void setLayout() {
        // Get display for detecting the phone orientation
        final Display display = ((WindowManager) getSystemService(
            WINDOW_SERVICE)).getDefaultDisplay();
        if (display.getRotation() == Surface.ROTATION_0 ||
            display.getRotation() == Surface.ROTATION_180) {
            setContentView(R.layout.home);
        } else {
            setContentView(R.layout.home_l);
        }
    }
</pre>
<p>P.S.<br />
Actually, ignore code above it will not work. All you really need to do is to detect what is larger &#8211; height or width and adjust layout accordingly</p>
<pre class="brush: java; title: ; notranslate">
    private void setLayout() {
        // Get display for detecting the phone orientation
        final Display display = ((WindowManager)
             getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
        final boolean isTall = display.getHeight() &gt; display.getWidth();
        setContentView(isTall ? R.layout.home : R.layout.home_l);
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2011/06/30/android-display-orientation-in-phones-vs-tablets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Pygments in Java with Jython</title>
		<link>http://dev.bostone.us/2010/12/01/python-pygments-in-java-with-jython/</link>
		<comments>http://dev.bostone.us/2010/12/01/python-pygments-in-java-with-jython/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 19:10:13 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=369</guid>
		<description><![CDATA[I was looking for the good code-highlighting package to use in my Java (GWT) project and after much research selected Pygments. It took me a while to figure out how to make all different parts work happily together so here&#8217;s a tutorial on how to do it.
Jython setup
To run Pygments you need to add Jython.jar [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for the good code-highlighting package to use in my Java (GWT) project and after much research selected <a href="http://pygments.org/">Pygments</a>. It took me a while to figure out how to make all different parts work happily together so here&#8217;s a tutorial on how to do it.</p>
<h1>Jython setup</h1>
<p>To run Pygments you need to add Jython.jar to the list of your libraries. I&#8217;m using release 2.5.1 at the time of writing. First and foremost &#8211; using barebone distribution such as found in Maven repo or in the Jython distro is not sufficient. I tried many ways to setup and the only way that worked is to</p>
<ol>
<li>Uncompress jython.jar in some temp directory</li>
<li>Add Jython/Lib directory to the top</li>
<li>Add Pygments Python files to the top</li>
<li>Jar everything back again and add resulting archive to your project. I called it jython-full.jar</li>
<li>No matter what you are using this jar has to be on your classpath</li>
</ol>
<h1>Code</h1>
<h2>Highlighter.py</h2>
<p>Create custom highlighter.py file and place it to your resources or even Java files as long as it gets placed in the top level of your classpath. In my case I&#8217;m using Eclipse/Maven so I placed this file into src/main/python and added that folder as a source folder. Here&#8217;s complete code for highlighter.py:</p>
<pre class="brush: python; title: ; notranslate">
from reporting.python import Highlighter
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

class PyHighlighter(Highlighter):
    def __init__(self, lexername):
        self.lexer = get_lexer_by_name(lexername, stripall=True)
        self.formatter = HtmlFormatter(linenos=True, cssclass=&quot;source&quot;)
    def colorize(self, code):
        return highlight(code, self.lexer, self.formatter)
</pre>
<h2>Highlighter.java</h2>
<p>Highlighter.java is interface that your Java code will be using to communicate with Pygments.</p>
<pre class="brush: java; title: ; notranslate">
package reporting.python;

public interface Highlighter {
    String colorize(String rawText);
}
</pre>
<h2>HighlighterFactory.java</h2>
<p>HighlighterFactory is Java class that creates instances of Highlighter object. It&#8217;s given here in barebone form and can be greatly optimized by converting to a singleton and cashing particular instances of Highlighter for further reuse. But it will work as given:</p>
<pre class="brush: java; title: ; notranslate">
package reporting.python;

import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;

public class HighlighterFactory {
    private PyObject matrix;

    public HighlighterFactory() {
        PythonInterpreter pi = new PythonInterpreter();
        pi.exec(&quot;import sys&quot;);
        // makes Jython able to find your custom Python code
        pi.exec(&quot;sys.path.append('WEB-INF/classes')&quot;);
        pi.exec(&quot;from highlighter import PyHighlighter&quot;);
        matrix = pi.get(&quot;PyHighlighter&quot;);
    }

    public Highlighter create(String type) {
        final PyObject instance = matrix.__call__(new PyString(type));
        return (Highlighter) instance.__tojava__(Highlighter.class);
    }
}</pre>
<h1>Putting it all together</h1>
<p>After creating/placing all these parts here&#8217;s code example on how to use it</p>
<pre class="brush: java; title: ; notranslate">
    public String colorize(String text, String type) {
        HighlighterFactory factory = new HighlighterFactory();
        Highlighter highlighter = factory.create(type);
        return highlighter.colorize(text);
    }
</pre>
<h1>References</h1>
<ul>
<li><a href="http://pygments.org/">Pygments</a></li>
<li><a href="http://jythonpodcast.hostjava.net/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications">Jython Book chapter 10</a></li>
</ul>
<p>Good luck and let me know if it worked for you</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2010/12/01/python-pygments-in-java-with-jython/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android &#8211; prevent Dialog to be cashed in the Activity</title>
		<link>http://dev.bostone.us/2010/05/11/android-prevent-dialog-to-be-cashed-in-the-activity/</link>
		<comments>http://dev.bostone.us/2010/05/11/android-prevent-dialog-to-be-cashed-in-the-activity/#comments</comments>
		<pubDate>Tue, 11 May 2010 05:13:45 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=339</guid>
		<description><![CDATA[If you override Activity#onCreateDialog method to create a pop-up dialog something that you have to be aware is this dialog will be cashed for any subsequent calls. For most cases it is just the right behavior but what if you want to change contents of the dialog on the next call? One possible scenario &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>If you override <strong>Activity#onCreateDialog</strong> method to create a pop-up dialog something that you have to be aware is this dialog will be cashed for any subsequent calls. For most cases it is just the right behavior but what if you want to change contents of the dialog on the next call? One possible scenario &#8211; say you have few tabs that display similar content in the same pop-up but the info changes based on the active tab. Here&#8217;s one way to do it. When you set your onClick listener put this into onClick call:<br />
<code>dialog.dismiss();<br />
activity.removeDialog(DIALOG_ID);</code><br />
Here DIALOG_ID is the same ID you are using in the <strong>Activity#onCreateDialog</strong> call</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2010/05/11/android-prevent-dialog-to-be-cashed-in-the-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GOTO Java</title>
		<link>http://dev.bostone.us/2010/02/27/goto-java/</link>
		<comments>http://dev.bostone.us/2010/02/27/goto-java/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 22:39:11 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=327</guid>
		<description><![CDATA[Here&#8217;s the scenario:

Loop through the list and for each slot

Compare current value with the given value
If match is found modify current item and break the loop


If the given value wasn&#8217;t find in the loop add it to the list

Turns out breaking out of loops using labels also works for curly block of code so the [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the scenario:</p>
<ol>
<li>Loop through the list and for each slot
<ol>
<li>Compare current value with the given value</li>
<li>If match is found modify current item and break the loop</li>
</ol>
</li>
<li>If the given value wasn&#8217;t find in the loop add it to the list</li>
</ol>
<p>Turns out breaking out of loops using labels also works for curly block of code so the solution is below</p>
<pre type="code" class="java">
List<Foo> list = getFromSomewhere();
Foo foo = whatever();
gotu: {
    for (Foo f : list) {
        if ( f.equals(foo)) {
            f.setBlah(foo.getBlah()); // blah is not used in compare()
            break gotu;
       }
    }
// only want to execute the following if the loop was never broken
list.add(foo);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2010/02/27/goto-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teleportation? Yes, way!</title>
		<link>http://dev.bostone.us/2009/12/04/teleportation-yes-way/</link>
		<comments>http://dev.bostone.us/2009/12/04/teleportation-yes-way/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 22:58:48 +0000</pubDate>
		<dc:creator>bo</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dev.bostone.us/?p=306</guid>
		<description><![CDATA[I was googling  download link for Sun&#8217;s VirtualBox when my eye caught word &#8220;Teleportation&#8221;. Whatta? I thought to myself while following the link. I have not heard the word since my youth days of reading likes of Sir Artur Clarke.
Turned out &#8211; the teleportation is real. It is ability to move running! VM from host [...]]]></description>
			<content:encoded><![CDATA[<p>I was googling  download link for Sun&#8217;s VirtualBox when <a href="http://is.gd/5bDCP">my eye caught word </a>&#8220;Teleportation&#8221;. Whatta? I thought to myself while following the link. I have not heard the word since my youth days of reading likes of Sir Artur Clarke.</p>
<p>Turned out &#8211; the teleportation is real. It is ability to move running! VM from host to host and it is now supported in VirtualBox v. 3.1.0! What downtime?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.bostone.us/2009/12/04/teleportation-yes-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

