<?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>Impressive Artworx</title>
	<atom:link href="http://impressive-artworx.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://impressive-artworx.de</link>
	<description>A blog about Robots and Coffee Beans...</description>
	<lastBuildDate>Thu, 19 Jan 2012 19:11:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>VibrantPlayer &#8211; an open source MP3 Player!</title>
		<link>http://impressive-artworx.de/2011/vibrantplayer-an-open-source-mp3-player/</link>
		<comments>http://impressive-artworx.de/2011/vibrantplayer-an-open-source-mp3-player/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 14:33:23 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[player]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=166</guid>
		<description><![CDATA[In 2008 I created a Java Swing-based MP3 player which I called "VibrantPlayer". My intention was to create a beautiful looking media player which could be styled through custom themes, extended via downloadable plugins and which should offer the possibility to edit the ID3 meta data of MP3 songs.]]></description>
			<content:encoded><![CDATA[<p>VibrantPlayer is an open-source MP3 media player that lets you organize and play your entire music library.</p>
<p>It is entirely written in Java and offers you the possibility to download additional artist information and cover images. You are also able to edit the files&#8217; ID3 tags which contain the song title, album and artist name.</p>
<p>The player is also extendable by providing downloadable plugins. There is a plugin which enables you to convert an MP3 file to a WAV file so you can burn an album onto a regular music CD.</p>
<p>In addition the player is skinnable through custom themes.</p>
<h2>Features</h2>
<ul>
<li>manage and view your entire music library with ease</li>
<li>ability to view and edit ID3 tags that are embedded within mp3 files</li>
<li>show detailed information about a song, an album or an artist</li>
<li>possibility to automatically search for artist information on the Web</li>
<li>retrieve and view album cover images and images of artists</li>
<li>space saving tiny view</li>
<li>intelligent search function</li>
<li>extensible through plugins and themes</li>
<li>comfortable user interface</li>
<li>integrated update function: keep your VibrantPlayer up to date</li>
<li>free of charge and open-source!</li>
</ul>
<h2>Screen shots</h2>
<table width="100%" border="0" style="margin-top: 5px; margin-bottom: 20px;" cellpadding="8">
<tr>
<td>
<a style="float: left;" class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_mainscreen.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_mainscreen-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
<td>
<a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_playlist.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_playlist-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
<td>
<a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_artistinfo.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_artistinfo-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
</tr>
<tr>
<td>
<a style="float: left;" class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_songinfo.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_songinfo-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
<td>
<a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_settings.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_settings-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
<td>
<a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_themes.png" rel="VibrantPlayer"><img src="http://impressive-artworx.de/wp-content/uploads/2011/12/vibrantplayer_themes-150x150.png" alt="" title="VibrantPlayer" width="150" height="150" class="aligncenter size-medium wp-image-137" /></a>
 </td>
</tr>
</table>
<h2>Download</h2>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/downloads/tools/VibrantPlayer.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/windows.png" alt="Windows" title="Windows" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">for Windows: .zip (14.0 MB)</span></a><a class="downloadButton" href="http://www.impressive-artworx.de/downloads/tools/VibrantPlayer.tar.gz"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/linux.png" alt="Unix" title="Unix" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">for Linux/Mac: .tar.gz (13.9 MB)</span></a></td>
</tr>
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/downloads/tools/VibrantPlayerSrc.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download src</span><span class="downloadButtonSize">sources: .zip (14.9 MB)</span></a></td>
</tr>
</table>
<div class='et-box et-info'>
					<div class='et-box-content'>This media player was programmed a few years ago. Its development is no longer continued. Feel free to download the sources and modify it at will. I hope that you can learn from my code or give me advice on how things could have been done better. Enjoy!</div></div>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/vibrantplayer-an-open-source-mp3-player/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uninstall an app programmatically</title>
		<link>http://impressive-artworx.de/2011/uninstall-an-app-programmatically/</link>
		<comments>http://impressive-artworx.de/2011/uninstall-an-app-programmatically/#comments</comments>
		<pubDate>Sat, 25 Jun 2011 11:23:20 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[uninstall]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=144</guid>
		<description><![CDATA[In this post entry I will enhance the previous one which lists all currently installed apps on your phone by adding the possiblity to uninstall a selected app. Our example program will also display the file size and installation location of an app upon selection. ]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://impressive-artworx.de/2011/list-all-installed-apps/">previous tutorial</a> we created a list of all apps that are currently installed on the phone. Upon clicking on an app entry, the user was shown additional information about the selected app and had the opportunity to start it. A <a href="http://impressive-artworx.de/2011/list-all-installed-apps-in-style/">follow-up</a> also displayed the associated icons by loading them asynchroneously.</p>
<p>This time I will show you how to enhance this demo program by displaying the associated package file location of a selected app as well as the amount of disk space it consumes on your phone. In addition, we will add the possibility to uninstall a selected app.</p>
<h2>Displaying the package location and file size</h2>
<p>The first improvement that we will make on the demo app is to display the path where the app is actually installed and the size on disk that it consumes. To store this information our <code>App</code> bean will get two new String fields: <code>installDir</code> and <code>installSize</code> complete with accompanying getters and setters.</p>
<p>We then have to extend our <code>listInstalledApps(...)</code> method inside our main activity:</p>
<pre class="brush: java; title: ; notranslate">
app.setInstallDir(p.applicationInfo.sourceDir);
app.setInstallSize(calculateSize(app.getInstallDir()));
</pre>
<p>The <code>calculateSize(...)</code> method is a custom method that takes the path to the installed package as a parameter and returns a human-readable form of the file&#8217;s size, e.g. &#8220;420.23 KB&#8221; or &#8220;1.23 MB&#8221;. It is implemented as follows:</p>
<pre class="brush: java; title: ; notranslate">
private String calculateSize(String installPath) {
  File file = new File(installPath);

  String unit = &quot;Bytes&quot;;
  double sizeInUnit = 0d;

  if (file.exists()) {
    double size = (double) file.length();

    if (size &gt; 1024 * 1024 * 1024) { // Gigabyte
      sizeInUnit = size / (1024 * 1024 * 1024);
      unit = &quot;GB&quot;;
    } else if (size &gt; 1024 * 1024) { // Megabyte
      sizeInUnit = size / (1024 * 1024);
      unit = &quot;MB&quot;;
    } else if (size &gt; 1024) { // Kilobyte
      sizeInUnit = size / 1024;
      unit = &quot;KB&quot;;
    } else { // Byte
      sizeInUnit = size;
    }
  }

  // only show two digits after the comma
  return new DecimalFormat(&quot;###.##&quot;).format(sizeInUnit) + &quot; &quot; + unit;
}
</pre>
<p>The only thing that is left to do now is to display the gathered information to the user. We do this inside our dialog box that is shown upon selection of an app in the list:</p>
<pre class="brush: java; title: ; notranslate">
AlertDialog dialog = new AlertDialog.Builder(this).create();

String msg = app.getTitle() + &quot;\n\n&quot; +
  &quot;Version &quot; + app.getVersionName() + &quot; (&quot; + app.getVersionCode() + &quot;)&quot; +
   &quot;\n&quot; + app.getDescription() + &quot;\n&quot; +
  app.getInstallDir() + &quot;\n&quot; + app.getInstallSize();
dialog.setTitle(app.getTitle());
dialog.setMessage(msg);
</pre>
<p>The user can now see where the selected app is installed and how much space it consumes.</p>
<h2>Adding the ability to uninstall a selected app</h2>
<p>We will also add the ability to uninstall a selected app. This can be achieved very easily: all you have to do is execute an intent to remove a given package name. We will add a third button to our dialog box which enables the user to unsinstall the selected app:</p>
<pre class="brush: java; title: ; notranslate">
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, &quot;Uninstall&quot;,
  new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
      Intent intent = new Intent(Intent.ACTION_DELETE);
      intent.setData(Uri.parse(&quot;package:&quot; + app.getPackageName()));
      startActivity(intent);
      mApps.remove(appPosition);
      mAdapter.notifyDataSetChanged(); // update the UI
    }
});
</pre>
<p>That&#8217;s all there is to it! Android will do the rest for you including showing an additional activity where the user has to confirm his choice to actually remove the selected app for good.</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/06/appslist3.png" rel="appslist3"><img src="http://impressive-artworx.de/wp-content/uploads/2011/06/appslist3-151x300.png" alt="" title="appslist3" width="155" height="300" class="aligncenter size-medium wp-image-137" /></a></p>
<p>As always you can download the sample application containing all source code and layout resource files:</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/InstalledApps3.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.zip (71 KB)</span></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/uninstall-an-app-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List all installed apps in style</title>
		<link>http://impressive-artworx.de/2011/list-all-installed-apps-in-style/</link>
		<comments>http://impressive-artworx.de/2011/list-all-installed-apps-in-style/#comments</comments>
		<pubDate>Sun, 22 May 2011 00:51:38 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[apps]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=124</guid>
		<description><![CDATA[In a previous tutorial I showed you how to list all apps that are currently installed on the phone. This tutorial enhances the functionality of the demo program by adding the respective application icons to the list of apps and displaying detailed information about them upon selection.]]></description>
			<content:encoded><![CDATA[<p>In the previous tutorial <a href="http://impressive-artworx.de/2011/list-all-installed-apps/">List all installed apps</a> I showed you how to list the apps that are currently installed on the phone. The displayed information was rather sparse: we showed the title of the app and started it upon clicking on it.</p>
<p>In this tutorial we will enhance the demo program by adding an application icon next to each title and also display some information about the app when clicking on it. The user can then choose to start the app or return to the list.</p>
<h2>Layout changes</h2>
<p>We will only adapt the layout of a row in the list by adding an <code>ImageView</code> next to the <code>TextView</code> which holds the app&#8217;s title. Since we will need to update the image programmatically we assign an id to it.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:orientation=&quot;horizontal&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;fill_parent&quot;&gt;
  &lt;ImageView
    android:id=&quot;@+id/appicon&quot;
    android:scaleType=&quot;fitCenter&quot;
    android:layout_width=&quot;40dp&quot;
    android:layout_height=&quot;40dp&quot;
    android:layout_marginRight=&quot;6dip&quot;
    android:layout_marginLeft=&quot;2dip&quot;
    android:layout_marginTop=&quot;2dip&quot;
    android:layout_marginBottom=&quot;2dip&quot;
    android:src=&quot;@drawable/icon&quot;
    android:layout_gravity=&quot;center_vertical&quot; /&gt;
  &lt;TextView
    android:id=&quot;@+id/apptitle&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:textSize=&quot;20dip&quot;
    android:layout_gravity=&quot;center_vertical&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<h2>Code adaptations</h2>
<p>We will first need to modify our custom list adpater class <code>AppListAdapter</code>. The class will get a map containing the app&#8217;s package names mapped to the respective icon images. We also need to provide a getter and setter for this field. We will also add a default image which is shown before the icons are loaded and when no icon could be found for a particular app.</p>
<p>Last but not least we will update our <code>ViewHolder</code> object to also hold an <code>ImageView</code> for the current row. This view is retrieved through the id we gave it in the layout earlier. The icon will be taken from the map that we just defined.</p>
<pre class="brush: java; title: ; notranslate">
public class AppListAdapter extends BaseAdapter {
  // ...

  // a map which maps the package name of an app to its icon drawable
  private Map&lt;String, Drawable&gt; mIcons;
  // default icon for each app until the actual icon is loaded
  private Drawable mStdImg;

  /**
   * Constructor.
   *
   * @param context the application context for the layout inflater
   */
  public AppListAdapter(Context context) {
    // ...

    // set the default icon until the actual icon is loaded for an app
    mStdImg = context.getResources().getDrawable(R.drawable.icon);
  } 

  // ...

  @Override
  public View getView(int position, View convertView, ViewGroup parent){

    AppViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.row, null);
      holder = new AppViewHolder();
      holder.mTitle = (TextView) convertView.findViewById(R.id.apptitle);
      holder.mIcon = (ImageView) convertView.findViewById(R.id.appicon);
      convertView.setTag(holder);
    } else {
      holder = (AppViewHolder) convertView.getTag();
    }

    App app = mApps.get(position);

    holder.setTitle(app.getTitle());
    if (mIcons == null || mIcons.get(app.getPackageName()) == null) {
      holder.setIcon(mStdImg);
    } else {
      holder.setIcon(mIcons.get(app.getPackageName()));
    }

    return convertView;
  }

  // ...

  /**
    * Sets the map containing the icons for each displayed app.
    *
    * @param icons the map which maps the app's package name to its icon
    */
  public void setIcons(Map&lt;String, Drawable&gt; icons) {
    this.mIcons = icons;
  }

  /**
   * Returns the map containing the icons for each displayed app.
   *
   * @return a map with a mapping of package names to icon drawables
   */
  public Map&lt;String, Drawable&gt; getIcons() {
    return mIcons;
  }

  /**
   * A view holder which is used to re/use views inside a list.
   */
  public class AppViewHolder {

    // ...

    private ImageView mIcon;

    // ...

    /**
     * Sets the icon to be shown next to the app's title
     *
     * @param img the icon drawable to be displayed
     */
    public void setIcon(Drawable img) {
      if (img != null) {
        mIcon.setImageDrawable(img);
      }
    }
  }
}
</pre>
<p>Please refer to the <a href="http://impressive-artworx.de/2011/list-all-installed-apps/">first tutorial</a> for the parts of the code which are left out for brevity.</p>
<h2>Using an asynchroneous task to load the icons</h2>
<p>Since it can take quite a while to load all the icon images for all installed applications and we don&#8217;t want our app to be unresonsive I decided to first display the list of installed apps and then load the images asynchroneously. This is done using an <code>AsyncTask</code> which makes multi-threading really easy. All you have to do is create a class which extends <code>AsyncTask</code> and override its <code>doInBackground(...)</code> method to perform all the work there is to do and which should not happen on the UI thread as it would block the process of painting the elements on the screen.</p>
<p>Once we are finished loading the images, we signalize that the dataset of the list has changed. This is done in the <code>onPostExecute(...)</code> method:</p>
<pre class="brush: java; title: ; notranslate">
private class LoadIconsTask extends AsyncTask&lt;App, Void, Void&gt; {
  @Override
  protected Void doInBackground(App... apps) {

    Map&lt;String, Drawable&gt; icons = new HashMap&lt;String, Drawable&gt;();
    PackageManager manager = getApplicationContext().getPackageManager();

    for (App app : apps) {
      String pkgName = app.getPackageName();
      Drawable ico = null;
      try {
        Intent i = manager.getLaunchIntentForPackage(pkgName);
        if (i != null) {
          ico = manager.getActivityIcon(i);
        }
      } catch (NameNotFoundException e) {
        Log.e(&quot;ERROR&quot;, &quot;Unable to find icon for package '&quot; + pkgName);
      }
      icons.put(app.getPackageName(), ico);
    }
    mAdapter.setIcons(icons);

    return null;
  }

  @Override
  protected void onPostExecute(Void result) {
    mAdapter.notifyDataSetChanged();
  }
}
</pre>
<h2>Showing additional information about the selected app</h2>
<p>Finally, we will extend our original demo program by showing an informative dialog whenever an entry is selected in the list. We offer the user the possibility to launch the selected app or abort and get back to the app list.</p>
<pre class="brush: java; title: ; notranslate">
@Override
public void onItemClick(AdapterView&lt;?&gt; p, View view, int pos, long id) {

  final App app = (App) parent.getItemAtPosition(pos);
  String pkg = app.getPackageName();

  AlertDialog.Builder builder = new AlertDialog.Builder(this);

  String msg = app.getTitle() + &quot;\n\nVersion &quot; + app.getVersionName() +
    &quot; (&quot; + app.getVersionCode() + &quot;)\n\n&quot; +
    (app.getDescription() != null ? app.getDescription() : &quot;&quot;);

    builder.setMessage(msg)
      .setCancelable(true)
      .setTitle(app.getTitle())
      .setIcon(mAdapter.getIcons().get(pkg))
      .setPositiveButton(&quot;Launch&quot;,new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int id) {
          // start the app by invoking its launch intent
          Intent i = getPackageManager().getLaunchIntentForPackage(pkg);
          try {
            if (i != null) {
              startActivity(i);
            }
          } catch (ActivityNotFoundException err) {
            Toast.makeText(ListInstalledApps.this, &quot;App launch failed!&quot;,
              Toast.LENGTH_SHORT).show();
          }
        }
      })
      .setNegativeButton(&quot;Cancel&quot;, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
          dialog.cancel();
        }
      });
  AlertDialog dialog = builder.create();
  dialog.show();
}
</pre>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/appslist2.jpg" rel="appslist2"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/appslist2-155x300.jpg" alt="" title="appslist2" width="155" height="300" class="aligncenter size-medium wp-image-137" /></a></p>
<p>You can download the sample application containing all source code and layout resource files:</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/InstalledApps2.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.zip (66.8 KB)</span></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/list-all-installed-apps-in-style/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>List all installed apps</title>
		<link>http://impressive-artworx.de/2011/list-all-installed-apps/</link>
		<comments>http://impressive-artworx.de/2011/list-all-installed-apps/#comments</comments>
		<pubDate>Thu, 19 May 2011 12:43:55 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[apps]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=107</guid>
		<description><![CDATA[The android plattform offers the unique concept of intents: with their help you can interconnect you app with other apps that are installed on the device. This tutorial shows you how to list all currently installed applications on the phone and offer you a way to start them.]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to retrieve all currently installed apps on your phone as well as to start them. We will keep the GUI very simple: our main activity will only contain a list where each row contains the name of an installed app. By clicking on the row the respective app is started.</p>
<h2>The layout</h2>
<p>As I mentioned, the GUI will be fairly simple. We will only need to define a layout file for our main activity and one for each entry of the app list.</p>
<p>The main activity simply contains a list which spans the entire screen:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:orientation=&quot;vertical&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;fill_parent&quot;&gt;
    &lt;ListView android:id=&quot;@+id/appslist&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<p>The layout for a row of that list is equally simple: we will only display a textview which will hold the app&#8217;s name:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:orientation=&quot;horizontal&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;fill_parent&quot;&gt;
  &lt;TextView
    android:id=&quot;@+id/apptitle&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:textSize=&quot;20dip&quot;
    android:layout_gravity=&quot;center_vertical&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<h2>The code</h2>
<p>We will first create a simple Java bean which will hold the interesting attributes of an app. It merely consists of a few fields and respective getters and setters:</p>
<pre class="brush: java; title: ; notranslate">
public class App {

  private String title;
  private String packageName;
  private String versionName;
  private int versionCode;

  // ...getters and setters omitted...
}
</pre>
<p>Next up is a custom list adapter which we will use to render our list of apps. It will hold a reference to the list of <code>App</code> beans that it is displaying. Don&#8217;t worry about the <code>ViewHolder</code> class too much; it is only used to reuse views and speed things up.</p>
<pre class="brush: java; title: ; notranslate">
public class AppListAdapter extends BaseAdapter {

  private LayoutInflater mInflater;
  private List&lt;App&gt; mApps;

  public AppListAdapter(Context context) {
     // cache the LayoutInflater to avoid asking for a new one each time
     mInflater = LayoutInflater.from(context);
  }

  @Override
  public int getCount() {
    return mApps.size();
  }

  @Override
  public Object getItem(int position) {
    return mApps.get(position);
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int pos, View convertView, ViewGroup parent) {

    AppViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.row, null);

      // creates a ViewHolder and stores a reference to the child view
      holder = new AppViewHolder();
      holder.mTitle = (TextView) convertView.findViewById(R.id.apptitle);
      convertView.setTag(holder);
    } else {
      // reuse/overwrite the view passed assuming(!) that it is castable!
      holder = (AppViewHolder) convertView.getTag();
    }
    holder.setTitle(mApps.get(pos).getTitle());

    return convertView;
  }

  public void setListItems(List&lt;App&gt; list) {
    mApps = list;
  }

  /**
   * A view holder which is used to reuse views inside a list.
   */
  public class AppViewHolder {

    private TextView mTitle;

    /**
     * Sets the text to be shown as the app's title
     *
     * @param title the text to be shown inside the list row
     */
     public void setTitle(String title) {
       mTitle.setText(title);
     }
  }
}
</pre>
<p>So far, so easy. Now comes the most interesting class: our main activity which handles the retrieval of the installed apps as well as the start of an app when it&#8217;s title is being pressed in the list.</p>
<pre class="brush: java; title: ; notranslate">
public class ListInstalledApps extends Activity
implements OnItemClickListener {

  /** whether or not to include system apps */
  private static final boolean INCLUDE_SYSTEM_APPS = true;

  private ListView mAppsList;
  private List&lt;App&gt; mApps;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mAppsList = (ListView) findViewById(R.id.appslist);
    mAppsList.setOnItemClickListener(this);

    mApps = loadInstalledApps(INCLUDE_SYSTEM_APPS);

    AppListAdapter adapter = new AppListAdapter(getApplicationContext());
    adapter.setListItems(mApps);
    mAppsList.setAdapter(adapter);
  }

  @Override
  public void onItemClick(AdapterView&lt;?&gt; p, View v, int pos, long id) {
    // start the app by invoking its launch intent
    App app = (App) parent.getItemAtPosition(position);
    Intent i = getPackageManager().getLaunchIntentForPackage(
      app.getPackageName());
    try {
      if (i != null) {
        startActivity(i);
      } else {
        i = new Intent(app.getPackageName());
        startActivity(i);
      }
    } catch (ActivityNotFoundException err) {
      Toast.makeText(ListInstalledApps.this, &quot;Error launching app&quot;,
        Toast.LENGTH_SHORT).show();
    }
  }

  /**
   * Uses the package manager to query for all currently installed apps
   * which are put into beans and returned in form of a list.
   *
   * @param includeSysApps whether or not to include system apps
   * @return a list containing {@code App} beans
   */
  private List&lt;App&gt; loadInstalledApps(boolean includeSysApps) {
    List&lt;App&gt; apps = new ArrayList&lt;App&gt;();

    // the PackageManager contains information about installed apps
    PackageManager packageManager = getPackageManager();

    List&lt;PackageInfo&gt; pgs = packageManager.getInstalledPackages(0);

    for(int i=0; i &lt; pgs.size(); i++) {
      PackageInfo p = pgs.get(i);
      ApplicationInfo a = p.applicationInfo;
      // skip system apps if they shall not be included
      if ((!includeSysApps) &amp;&amp;
         ((a.flags &amp; ApplicationInfo.FLAG_SYSTEM) == 1)) {
        continue;
      }
      App app = new App();
      app.setTitle(p.applicationInfo.loadLabel(packageManager)
        .toString());
      app.setPackageName(p.packageName);
      app.setVersionName(p.versionName);
      app.setVersionCode(p.versionCode);
      apps.add(app);
    }
    return apps;
  }
}
</pre>
<p>The code contains two interesting blocks. The first one is the final block which starts at line 45. It displays the usage of the <code>PackageManager</code> in order to retrieve the installed packages. I then create a new instance of an <code>App</code> bean and store the most interesting information about each installed package.</p>
<p>The other interesting block starts at line 25 and contains the code that is necessary to launch a selected app. It uses the application&#8217;s package name to find its launch intent. If that intent can be retrieved it is executed. Note that our activity is implementing the <code>OnItemClickListener</code> and sets the listener on the list view on line 16.</p>
<p>That is all the magic. Thanks to the <code>PackageManager</code> class it is very easy to retrieve the list of installed apps on a phone!</p>
<h2>The result</h2>
<p>The following screenshot shows how this app looks like on my emulator:</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/apps_list_1.jpg" rel="installed_apps_1"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/apps_list_1-159x300.jpg" alt="" title="apps_list_1" width="159" height="300" class="aligncenter size-medium wp-image-109" /></a></p>
<p>As always you can download the source code to this tutorial:</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/InstalledApps1.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.zip (55.7 KB)</span></a></td>
</tr>
</table>
<p>In a future tutorial I will show you how to add the application&#8217;s icon as well as version information to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/list-all-installed-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Background image on JPanel</title>
		<link>http://impressive-artworx.de/2011/background-image-on-jpanel/</link>
		<comments>http://impressive-artworx.de/2011/background-image-on-jpanel/#comments</comments>
		<pubDate>Wed, 18 May 2011 07:32:56 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jpanel]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=95</guid>
		<description><![CDATA[Applications often look sterile and lifeless. Adding a background image is a simple yet effective way to fight boring and dull interfaces.]]></description>
			<content:encoded><![CDATA[<p>User interfaces often look boring or lifeless. Most of them feature an arbitrary amount of buttons, text input boxes, select boxes and other form elements that need to be filled out by the user. The acceptance of windows containing such forms often depends on how esthetic a user finds them.</p>
<p>This tutorial will show you how easy it is to add a background image to a <code>JPanel</code> and thereby making your application look prettier and probably more exciting to use!</p>
<h2>How will it look like?</h2>
<p>The following shows an example of an otherwise pretty dull user interface which got enriched by a background image making the application more exciting and fun to use.</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/jpanel_background.jpg" rel="jpanel_background"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/jpanel_background-300x195.jpg" alt="" title="jpanel_background" width="300" height="195" class="aligncenter size-medium wp-image-100" /></a></p>
<p>The image from the screenshot was taken from www.theblackparade.de (the site does no longer exist).</p>
<h2>How it is done</h2>
<p>We create an ordinary <code>JPanel</code> and override its <code>paintComponent(Graphics g)</code> method. Within this method we paint the background image:</p>
<pre class="brush: java; title: ; notranslate">
public class JBackgroundPanel extends JPanel {
  private BufferedImage img;

  public JBackgroundPanel() {
    // load the background image
    try {
      img = ImageIO.read(new File(&quot;./back.jpg&quot;));
    } catch(IOException e) {
      e.printStackTrace();
    }
  }

  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    // paint the background image and scale it to fill the entire space
    g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
  }
}
</pre>
<p>As usual we can now add any kind of component to our <code>JPanel</code>. Finally, we add our background image panel to a <code>JFrame</code>.</p>
<pre class="brush: java; title: ; notranslate">
// create the panel with the background image
JBackgroundPanel bgPanel = new JBackgroundPanel();

// add some elements...
bgPanel.add(new JLabel(&quot;Applications don't have to look boring!&quot;));
bgPanel.add(new JComboBox(new String[] {&quot;Background 1&quot;, &quot;Background 2&quot;}));
bgPanel.add(new JButton(&quot;True&quot;));

// create a window
JFrame f = new JFrame(&quot;JPanel with background image&quot;);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 250);
f.setLocationRelativeTo(null);

// add the panel with the background image
f.add(bgPanel);

// show the window
f.setVisible(true);
</pre>
<p>Of course you could set the image path in the constructor of the <code>JBackgroundPanel</code> class and thereby making its usage much more flexible.</p>
<p>That&#8217;s it. With the use of this simple trick you will be able to design attractive windows that will make the user of your app enjoy working with it. Just make sure not to use too many image or images that distract the user!</p>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/background-image-on-jpanel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Where am I? Display current GPS location</title>
		<link>http://impressive-artworx.de/2011/where-am-i-display-current-gps-location/</link>
		<comments>http://impressive-artworx.de/2011/where-am-i-display-current-gps-location/#comments</comments>
		<pubDate>Tue, 17 May 2011 05:44:38 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[location]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=75</guid>
		<description><![CDATA[Most android phones benefit from a built-in GPS sensor. This tutorial shows you how to make use of the GPS signal and display the user's current position (latitude and longitude) on the screen.]]></description>
			<content:encoded><![CDATA[<p>One of the very cool features that an android device offers are its GPS capabilities. This tutorial will show you how to make use of the GPS sensor information by displaying the user&#8217;s current position on the screen.</p>
<h2>The basics: adding the necessary permissions</h2>
<p>In order to retrieve the current GPS sensor information the user of your app must grant the <code>android.permission.ACCESS_FINE_LOCATION</code> permission. Add it to your app&#8217;s manifest:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  package=&quot;de.impressive.artworx.tutorials.gps&quot;
  android:versionCode=&quot;1&quot;
  android:versionName=&quot;1.0&quot;&gt;
  &lt;application android:icon=&quot;@drawable/icon&quot;
    android:label=&quot;@string/app_name&quot;&gt;
    &lt;activity android:name=&quot;.GPSTest&quot; android:label=&quot;@string/app_name&quot;&gt;
      &lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
      &lt;/intent-filter&gt;
    &lt;/activity&gt;
  &lt;/application&gt;
  &lt;uses-sdk android:minSdkVersion=&quot;4&quot; /&gt;
  &lt;uses-permission
    android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
&lt;/manifest&gt;
</pre>
<h2>The layout</h2>
<p>The layout of this sample app will be very simple: it will only contain a text view which we use to display the current position. To get a hold on this text view from within our code, we assign a new id called <code>infotext</code> to it:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:orientation=&quot;vertical&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;fill_parent&quot;&gt;
  &lt;TextView
    android:id=&quot;@+id/infotext&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;@string/app_name&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<h2>The code</h2>
<p>Now comes the interesting part. We only need one main activity which implements the <code>LocationListener</code> interface. This listener informs us about location changes as well as status updates to the GPS signal.</p>
<pre class="brush: java; title: ; notranslate">
public class GPSTest extends Activity implements LocationListener {

  private TextView mInfoText;
  private LocationManager mLoc;

  // update every 10 seconds
  private static final Integer MINIMUM_UPDATE_INTERVAL = 10000;
  // update every 10 meters
  private static final Integer MINIMUM_UPDATE_DISTANCE = 10;

  @Override
  public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     // get a handle to the text view to display the GPS location data
     mInfoText = (TextView) findViewById(R.id.infotext);

     // allows access to the current location and GPS status
     mLoc = (LocationManager) getSystemService(LOCATION_SERVICE);
  }

  @Override
  protected void onResume() {
    // add a location listener and request updates every 10000ms or 10m
    mLoc.requestLocationUpdates(LocationManager.GPS_PROVIDER,
      MINIMUM_UPDATE_INTERVAL, MINIMUM_UPDATE_DISTANCE, this);
    super.onResume();
  }

  @Override
  protected void onPause() {
    // GPS, as it turns out, consumes battery like crazy
    mLoc.removeUpdates(this);
    super.onPause();
  }

  @Override
  protected void onStop() {
    // may as well just finish since saving the state is not important
    finish();
    super.onStop();
  }

  @Override
  public void onLocationChanged(Location loc) {
    // display some information based on the current position
    String title = &quot;Your current location is:\n\n&quot;;
    StringBuilder sb = new StringBuilder(title);
    sb.append(&quot;Longitude: &quot;);
    sb.append(loc.getLongitude());
    sb.append('\n');
    sb.append(&quot;Latitude: &quot;);
    sb.append(loc.getLatitude());
    sb.append('\n');
    sb.append(&quot;Altitiude: &quot;);
    sb.append(loc.getAltitude());
    sb.append('\n');
    sb.append(&quot;Accuracy: &quot;);
    sb.append(loc.getAccuracy());
    sb.append('\n');
    sb.append(&quot;Timestamp: &quot;);
    Date timestamp = new Date(loc.getTime());
    sb.append(new SimpleDateFormat().format(timestamp));
    mInfoText.setText(sb.toString());
  }

  @Override
  public void onProviderDisabled(String provider) {
    // called if/when the GPS is disabled in settings
    Toast.makeText(this, &quot;GPS disabled&quot;, Toast.LENGTH_LONG).show();
    // end program since we depend on GPS
    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
    alertbox.setMessage(&quot;This app requires GPS. Please activate it!&quot;);
    alertbox.setNeutralButton(&quot;Ok&quot;,
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
          finish();
        }
      }
    );
    alertbox.show();
  }

  @Override
  public void onProviderEnabled(String provider) {
    Toast.makeText(this, &quot;GPS enabled&quot;, Toast.LENGTH_LONG).show();
  }

  @Override
  public void onStatusChanged(String prov, int status, Bundle b) {
    // called upon GPS status changes
    switch (status) {
    case LocationProvider.OUT_OF_SERVICE:
      Toast.makeText(this, &quot;Status changed: out of service&quot;,
        Toast.LENGTH_LONG).show();
      break;
    case LocationProvider.TEMPORARILY_UNAVAILABLE:
      Toast.makeText(this, &quot;Status changed: temporarily unavailable&quot;,
        Toast.LENGTH_LONG).show();
      break;
    case LocationProvider.AVAILABLE:
      Toast.makeText(this, &quot;Status changed: available&quot;,
        Toast.LENGTH_LONG).show();
      break;
    }
  }
}
</pre>
<p>The heart and soul of this code is the <code>LocationManager</code>. It will give us access to the current GPS data as well as inform us about status updates.</p>
<p>We override the <code>onPause</code>, <code>onResume</code> and <code>onStop</code> methods mainly to stop/resume the GPS updates so we can save our precious battery.</p>
<p>The <code>onLocationChanged</code> method is the most important one as it informs us whenever a change in the location is detected. How often these changes are notified depends on the minimum update interval as well as the minimum update distance which I defined as contants.</p>
<p>The final three overridden methods handle GPS sensor status updates such as disabling the GPS sensor etc.</p>
<h2>Interacting with the emulator</h2>
<p>In order to test the code you can either upload your app to your phone and walk around with it or use the emulator that comes with the SDK. The emulator can also simulate a GPS sensor and you can fool it by sending any location coordinates to it that come to your mind.</p>
<p>You first need to launch your app in the emulator. Then open a terminal window and use the following command to connect to the emulator:</p>
<p><code>telnet localhost 5554</code></p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_telnet.jpg" rel="gps_tutorial_1"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_telnet-300x151.jpg" alt="" title="gps_tutorial_telnet" width="300" height="151" class="aligncenter size-medium wp-image-80" /></a></p>
<p>Now you should see a command prompt which allows you to send instructions to the emulator. To send a location you need to type the following:</p>
<p><code>geo fix -31.9667 115.8325</code></p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_telnet_geo_fix.jpg" rel="gps_tutorial_1"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_telnet_geo_fix-300x151.jpg" alt="" title="gps_tutorial_telnet_geo_fix" width="300" height="151" class="aligncenter size-medium wp-image-78" /></a></p>
<p>The result should instantly be visible in your emulator window:</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_screen_1.jpg" rel="gps_tutorial_1"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/gps_tutorial_screen_1-151x300.jpg" alt="" title="gps_tutorial_screen_1" width="151" height="300" class="aligncenter size-medium wp-image-79" /></a></p>
<p>In a future blog post I will show you how to display this location on a map.</p>
<p>As always, you can download the source code for this tutorial.</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/gps_tutorial_1.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.zip (48.6 KB)</span></a></td>
</tr>
</table>
<div class='et-box et-info'>
					<div class='et-box-content'>This tutorial is based on a blog entry by Howard Paget: <a href="http://hejp.co.uk/android/android-gps-example/">http://hejp.co.uk/android/android-gps-example/</a>.</div></div>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/where-am-i-display-current-gps-location/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splash screen on startup</title>
		<link>http://impressive-artworx.de/2011/splash-screen-on-startup/</link>
		<comments>http://impressive-artworx.de/2011/splash-screen-on-startup/#comments</comments>
		<pubDate>Sun, 15 May 2011 07:59:34 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[launch screen]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[splash]]></category>
		<category><![CDATA[startup]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=50</guid>
		<description><![CDATA[Bigger applications and especially games often feature a loading screen which displays an image for a certain amount of time. In this tutorial you will learn how to add such a splash screen to your application.]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you will learn how to add a splash screen to your application. This screen will display an image for a defined amount of time before passing on to your main application.</p>
<h2>Defining the launch screen</h2>
<p>The layout of the launch screen will be fairly simple: we will only display an image which will span the entire available space. Of course you can also choose to use a more sophisticated layout but for simplicity I will keep things simple and easy.</p>
<h3>Defining the layout</h3>
<p>Create a new file called <code>splash.xml</code> into the <code>/res/layout</code> directory of your project. Add the following contents to it:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout
   xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
   android:orientation=&quot;vertical&quot;
   android:layout_width=&quot;fill_parent&quot;
   android:layout_height=&quot;fill_parent&quot;&gt;
   &lt;ImageView
      android:src=&quot;@drawable/splashimg&quot;
      android:layout_width=&quot;fill_parent&quot;
      android:layout_height=&quot;fill_parent&quot;
      android:scaleType=&quot;fitCenter&quot; /&gt;
&lt;/LinearLayout&gt;
</pre>
<p>Note that I reference an image file called <code>splashimg.jpg</code> here which must be present inside your <code>/res/drawable</code> folder. You can find a sample image in the downloadable zip archive which is attached at the end of this post.</p>
<h3>Implementing the splash screen activity</h3>
<p>Now we need to add an activity to your project which will be shown when the app is started. Create a new class called <code>SplashActivity</code> and add the following code to it:</p>
<pre class="brush: java; title: ; notranslate">
public class SplashScreen extends Activity {

   private boolean mActive = true;
   private int mSplashTime = 4000; // display time in ms

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      // hide the app title and also the notification bar
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

      setContentView(R.layout.splash);

      // thread for displaying the splash screen
      Thread splashThread = new Thread() {
         @Override
         public void run() {
            try {
               int waited = 0;
               while(mActive &amp;&amp; (waited &lt; mSplashTime)) {
                  sleep(100);
                  if(mActive) {
                     waited += 100;
                  }
               }
            } catch(InterruptedException e) {
               // do nothing
            } finally {
               Intent i = new Intent(getApplicationContext(),
                  MainActivity.class);
               startActivity(i);
               finish();
            }
         }
      };
      splashThread.start();
   }

   @Override
   public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {
         mActive = false;
      }
      return true;
   }
}</pre>
<p>So what is going on here? In lines 11-14 we hide the status and title bar of the phone as we want our splash screen to be shown only. After specifying the layout that we previously defined we start a new thread (line 19) which checks every 100 milliseconds whether the specified duration has been reached. If not, the thread sleeps for another 100ms. Once the specified duration is reached, the activity&#8217;s <code>finish()</code> method is called signaling the system that we are done. A new intent is then fired which launches our actual main application.</p>
<p>The overridden <code>onTouchEvent</code> method checks whether the screen has been touched and flips the <code>mActive</code> flag if so. The aforementioned thread regards this flag and aborts even when the duration has not been reached, yet.</p>
<h2>Putting it all together</h2>
<p>Since the launch screen is an additional activity in your project you will need to add it to your application&#8217;s manifest file and define it as the starting point of your app:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  package=&quot;de.impressive.artworx.tutorials.splash&quot;
  android:versionCode=&quot;1&quot; android:versionName=&quot;1.0&quot;&gt;
  &lt;application android:icon=&quot;@drawable/icon&quot;
    android:label=&quot;@string/app_name&quot;&gt;
    &lt;activity android:name=&quot;.SplashScreen&quot;
      android:label=&quot;@string/app_name&quot;&gt;
      &lt;intent-filter&gt;
        &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
      &lt;/intent-filter&gt;
    &lt;/activity&gt;
    &lt;activity android:name=&quot;.MainActivity&quot;&gt;
      &lt;intent-filter&gt;
        &lt;action android:name=
          &quot;de.impressive.artworx.tutorials.splash.MainActivity&quot; /&gt;
        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
      &lt;/intent-filter&gt;
    &lt;/activity&gt;
  &lt;/application&gt;
  &lt;uses-sdk android:minSdkVersion=&quot;3&quot; /&gt;
&lt;/manifest&gt;
</pre>
<p>You can donwload the entire sample project and use it as a starting point for your own app!</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/splash.zip"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.zip (120 KB)</span></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/splash-screen-on-startup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yes, no or maybe?</title>
		<link>http://impressive-artworx.de/2011/yes-no-or-maybe/</link>
		<comments>http://impressive-artworx.de/2011/yes-no-or-maybe/#comments</comments>
		<pubDate>Sat, 14 May 2011 00:52:26 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=41</guid>
		<description><![CDATA[You sometimes run into situations where a simple true or false boolean value simply isn't enough and you are looking for three possible states: yes, no or maybe. This tiny tutorial shows you how to achieve this in two ways: the traditional way in a good software design manner or the short and tricky way.]]></description>
			<content:encoded><![CDATA[<p>When programming, you sometimes run into situations where a simple <code>true</code> or <code>false</code> boolean value simply isn&#8217;t enough and you are looking for three possible states: yes, no or maybe.</p>
<p>From a software design point of view, this is achieved by introducing an enum which can hold these three values:</p>
<pre class="brush: java; title: ; notranslate">
enum CHOICE {
   YES,
   NO,
   MAYBE
}

CHOICE myChoice = CHOICE.MAYBE;

if (myChoice == CHOICE.YES) {
   // yes
} elseif (myChoice == CHOICE.NO) {
   // no
} else {
   // maybe
}
</pre>
<p>But sometimes, this generates too much boilerplate code. Instead, you can use this tiny trick: use the Boolean wrapper class instead and define a Boolean value which can either be <code>true</code> (= yes), <code>false</code> (= no) or <code>null</code> (= maybe). As long as the value is not initialized you treat it as <i>maybe</i>:</p>
<pre class="brush: java; title: ; notranslate">
Boolean choice;

if (choice == null) {
   // maybe
} else if (choice) {
   // yes (through auto-unboxing)
} else {
  // no
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/yes-no-or-maybe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTC Hero Emulator Skin</title>
		<link>http://impressive-artworx.de/2011/htc-hero-emulator-skin/</link>
		<comments>http://impressive-artworx.de/2011/htc-hero-emulator-skin/#comments</comments>
		<pubDate>Sat, 14 May 2011 00:26:30 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[hero]]></category>
		<category><![CDATA[htc]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=30</guid>
		<description><![CDATA[When developing apps for the android platform you will most probably use the emulator which comes with the android SDK. To get a better feeling about how your application will look on a real device you can now download the HTC Hero emulator skin!]]></description>
			<content:encoded><![CDATA[<p>When developing apps for the android platform you will most probably use the emulator which comes with the android SDK. To get a better feeling about how your application will actually look like on a real device you can specify a different emulator skin.</p>
<p>Several of these emulator skins already come out of the box but if you want to mimic a real device such as the HTC Hero you have the ability to install additional ones.</p>
<p>The HTC Hero emulator skin looks just like the real device; it will make developing and testing your apps more fun!</p>
<h2>Installation</h2>
<p>First you need to download the zip archive which contains all necessary files.</p>
<table width="100%">
<tr>
<td align="center"><a class="downloadButton" href="http://www.impressive-artworx.de/tutorials/android/emulator/skins/htc_hero.rar"><span class="downloadButtonImg"><img src="/wp-content/themes/Chameleon/images/zip.png" alt="Download" title="Download" /></span><span class="downloadButtonContent">Download now</span><span class="downloadButtonSize">.rar (93.5 KB)</span></a></td>
</tr>
</table>
<p> Extract the files inside the zip archive into your android SDK&#8217;s platforms folder, e.g.</p>
<p><code>C:\android\sdk_r07\android-sdk-windows\platforms\android-7\skins</code></p>
<p>There should now be a folder called <code>HTC_HERO</code> within this directory.</p>
<p>Inside eclipse you have to open the Android SDK and AVD Manager (under the menu entry &#8220;Window&#8221;). There, create a new virtual device.</p>
<p>Choose a name of your liking (e.g. &#8220;HTC-Hero&#8221;) and select &#8220;Android 2.1-update1 &#8211; API Level 7&#8243; as target. Under skin you will now be able to select &#8220;HTC_HERO&#8221; as shown in the screen shot below.</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero_create.png" rel="htc_hero_skin"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero_create-230x300.png" alt="" title="eclipse_htc_hero_create" width="230" height="300" class="aligncenter size-medium wp-image-16" /></a></p>
<h2>Launch</h2>
<p>Now you can run your app and select the newly created virtual device as the launch target.</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero_launch.png" rel="htc_hero_skin"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero_launch-300x215.png" alt="" title="eclipse_htc_hero_launch" width="300" height="215" class="aligncenter size-medium wp-image-17" /></a></p>
<p>Et voilà! You will see your app running in your virtual HTC Hero device!</p>
<p><a class="fancybox" href="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero.png" rel="htc_hero_skin"><img src="http://impressive-artworx.de/wp-content/uploads/2011/05/eclipse_htc_hero-173x300.png" alt="" title="eclipse_htc_hero" width="173" height="300" class="aligncenter size-medium wp-image-14" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/htc-hero-emulator-skin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complete page redesign</title>
		<link>http://impressive-artworx.de/2011/complete-page-redesign/</link>
		<comments>http://impressive-artworx.de/2011/complete-page-redesign/#comments</comments>
		<pubDate>Thu, 12 May 2011 12:39:07 +0000</pubDate>
		<dc:creator>mschwarz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://impressive-artworx.de/?p=28</guid>
		<description><![CDATA[Welcome to my new blog. The former Impressive Artworx page has been redesigned and restructured completely. The focus is now based on programming tipps and tutorials. In addition, the page will in English entirely. I hope you enjoy the look of the new page and all the amazing content that is about to come soon.]]></description>
			<content:encoded><![CDATA[<p>Welcome to my new blog. The former Impressive Artworx page has been redesigned and restructured completely. The focus is now based on programming tipps and tutorials. In addition, the page will in English entirely. I hope you enjoy the look of the new page and all the amazing content that is about to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://impressive-artworx.de/2011/complete-page-redesign/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
