Pages

Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Tuesday, April 12, 2011

Android Launcher Icons Color Palette for Incscape

Since we are 'forced' to submit a 512x512 launcher icon when publishing apps I guess I'm not the only one thinking that a master vector icon would be handy.

I've made  a color palette for Inkscape with the recommended colors for launcher icons. Simply copy/paste this and save as Android.gpl and move it to your palette folder in Inkscape and it will be loaded as a selectable palette next time you start.

GIMP Palette
Name: Android Launcher Icons
Columns: 3
#
255 255 255     White (#FFFFFF)
  0   0   0    Black (#000000)
 64  64  64   Dark Gray (#404040)
128 128 128    Medium Gray (#808080)
191 191 191     Light Gray (#BFBFBF)
102 153 255     Light Blue (#6699FF)
 51 102 204    Medium Blue (#3366CC)
  0  51 153     Dark Blue (#003399)
153 204  51     Light Green (#99CC33)
  0 204   0     Medium Green (#00CC00)
102 153   0     Dark Green (#669900)
255 204   0     Light Orange (#FFCC00)
255 153   0     Medium Orange (#FF9900)
255 102   0     Dark Orange (#FF6600)
204   0   0     Red (#CC0000)



New vector based icon for TravAlert

Wednesday, April 6, 2011

In-app billing - first impressions

So finally Google has released in-app billing for the android market. It is also documented and bundled with a sample app to use for testing, learning and as a demo.

Here is my two cents on what I want to see in next in-app billing updade:

1:st cent Make it easier to test for the developer!

I have spent a night or three browsing the sample code (Dungeons!) and trying to make it work for me, only to be slapped by INTERNAL_SERVICE_ERROR each time I tried to buy something.

The error was far from internal and service related - in fact - it was I who had foreseen this little sentence:

"You cannot use your developer account to test the complete in-app purchase process because Google Checkout does not let you buy items from yourself."


So to be able to actually try the in-app billing I need to factory reset my phone - hook it to a different Google account - register VISA-credentials (Google checkout). Then - I can install my apk and try this new feature. Puh..

Now that I've done all this - I'll have to make a refund from the merchant account - or I've lost 30% to Google. This leads to ...

2:nd cent: Give us micro payments!
Minimum price is same as for apps: $.99 | .50€ | SEK 7:-
Thats pretty much for in-app payments - VISA can handle cents, it must be possible to divide in to 30% - so theoretically $.03 | €.03 | SEK 0:03 could be minimum -

Yeah, I'm ready to give Google that extra 3% for this ;)

Sunday, March 20, 2011

Including QR-reader in your app

Thanks to android intents, it is easy to include functionality from other apps to you own. Say for example you have an app that should be able to read QR-codes. You could easily call a barcode scanner to do the dirty work for you and just bother about the result.

Create a button that will launch Barcode Scanner from Zxing:
public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.setPackage("com.google.zxing.client.android");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

Handle the callback for result:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

This is a raw copy/paste from the ZXING-project. Nothing that I can take credit for, but I have tested it and it works as a charm.

Yes, it requires the user to have the Barcode Scanner installed. This can be handled smoothly by calling url instead - if the barcoder is installed - it will launch - otherwise launch a web browser (with a install guide of course). Very nice!

Wednesday, March 16, 2011

Extract HTML from Android webview

Having a webview in android and wanting to fiddle with the HTML?

Injecting javascript in android webview

Its easy, make sure you have javascript enabled and simply load url containing javascript:
mBrowser = new WebView(context);
mBrowser.getSettings().setJavaScriptEnabled(true);
mBrowser.loadUrl("javascript:getElementById('ad_container').style.display='none');");

In most cases, you first want to load the actual web page, then inject the javascript - this is done by using a WebViewClient which overrides onPageFinished.

mBrowser.setWebViewClient(new WebViewClient() {
   @Override
   public void onPageFinished(WebView view, String url) {
      // check url
      if (SOME_WEBPAGE.equals(url) {
        loadUrl(JAVASCRIPT_CODE);
      }
   }
});
mBrowser.loadUrl(SOME_WEBPAGE);

Extracting HTML from Android webview

Taking it one step further - let's get HTML from a page and use it in our program. This is accomplished by using a JavascriptInterface with our webview.

mBrowser.getSettings().setJavaScriptEnabled();
// add javascript interface with example method
mBrowser.addJavaScriptInterface(new JavaScriptInterface() {
   public void setTitle(String html) {
      mTitle = html;
   }
}, "MY_JS");
// add webview client that calls javascript interface when page is loaded
mBrowser.addWebViewClient(new WebViewClient() {
   @Override
   public void onPageFinished(WebView view, String url) {
       view.loadUrl("javascript:window.MY_JS.setTitle(document.getElementsByTagName('title')[0].innerHTML);");
   }

mBrowser.loadUrl(SOME_WEBPAGE);

That's it - using the combination of WebVievClient and JavascriptInterface is very powerful - drawback is that I have not found an easy way of debugging javascript - if your javascript fails it will fail silent.

Nice thing is you can test your javascript on Firefox using Firebug on your main computer before adding code to your android project.

Saturday, March 12, 2011

TravAlert Lite 1.1.1 released

TravAlert Lite has been updated.
It's a minor update but I hope you will enjoy the new features.

Account Editor
The Account Editor will no longer accept empty username or password and it will also validate the server to at least somewhat correct.

Notification settings
If you go to settings you will see that the notifications has got its own preference screen and you can now set ring tone/vibration separately for incoming attacks, no incoming attacks and error-notifications.

Wednesday, March 9, 2011

QR-code to launch your app

Android intents are powerful, you can even set you application to launch on a certain URL.

Launch app on defined URL

To make your app launch on a specific URL you simply create an intent filter.

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="http" android:host="xebralabs.blogspot.com" android:path="/travalert"/>
</intent-filter>

This way you can have your application launched from a QR-code containing the specific URL. Nice thing is that if the app isn't installed the user will most likely have the url opened in a browser instead.

Monday, March 7, 2011

Static buttons in listview

A common gui-layout strategy is having static buttons above or below a listview.

Consider the following layout:


This is accomplished by using a relative layout which includes the listview inside LinearLayout with bottom padding, then the buttons relative to parent.

Example layout xml of static buttons below listview. Key parameters are highlighted.
<RelativeLayout 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

   <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_alignParentTop="true"
     android:paddingBottom="50sp">

      <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

      <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

   </LinearLayout>

   <Button
     android:layout_height="wrap_content"
     android:layout_width="124sp"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"/>

   <Button
     android:layout_width="124sp"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"/>

   <Button
     android:layout_width="124sp"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"/>

</RelativeLayout>

TravAlert Lite 1.1.0 with Travian 4 (T4) support

1.1.0

TravAlert Lite has gotten its first update and can now handle Travian 4 (T4) servers as well. It has also been localized to Swedish.

Sunday, March 6, 2011

Proguard - keeping onclick methods from layout xml

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.

When running Proguard on your jar-file it is important to configure it to keep click listeners that you use from your layout xml.
# keep methods accessed from xml/android:onClick
-keepclassmembers class *{
public void *(android.view.View);
~
More on Proguard.
More on click listeners from layout xml.
~

Wednesday, March 2, 2011

TravAlert Lite is published on android market

TravAlert Lite

TravAlert Lite just got published on the android market. It's free as in free beer and free of ads!

Friday, February 18, 2011

TravAlert comes in two flavours

TravAlert will come in a free version, TravAlert Lite, as well as a paid, TravAlert Premium, version. The Lite version will be limited to run only one account at a time - where the Premium version will have no account limit. Initially, TravAlert Lite will be free from ads, but may get future update that brings ads as well as multiple account support. This depends on what the users, you, want.
So tell me! ;)

TravAlert is an android application for Travian

Thursday, February 10, 2011

Android Market is updated

Android market has gotten a very much needed update, and in-app billing is around the corner. The market has been enhanced for browsing 'off-phone'. You can see installed apps and even install directly to your device. If you can't see your device in the list, make sure you are logged in and have your phone number registered under 'recovering you password'. You may need to logout/login to have the setting to take effect.

Android Developers Blog: New Merchandising and Billing Features on Android Market

Friday, January 28, 2011

TravAlert soon coming to android market

We are about to publish our first android app on the market. It will be (yet another) app for the ever so popular browser game Travian.

As the name suggests, its primary functions is to alert you when any village has an incoming attack.

Travian Android Apps

When I started the development from scratch there where no travian apps on the market - now there is already four! At the time of writing three of these are in beta testing and doesn't provide much functionality. This might end up in a feature-race against "competing" apps or we might branch out and provide different functionality. Hey who knows - we might end up co-operate using intents to launch each other apps ;)

Search market for 'travian'

Android Preference Icon

This might be old news, but I recently realized that the default menu icon for settings in android has was changed for android API 5 (Version 2.0). Gone is the ol' edgy and aggressive hammer 'n wrench and in is the new sleeker über-rounded tuning knob.

Eclair style
Old style





Which one do you prefer?

Did you know that you can find all the android default icons inside your android/platform/platform-{api-lvl}/res/drawables?