Skatteverket tvärvänder – appar slipper dubbelmoms
Yay!
http://computersweden.idg.se/2.2683/1.418906/skatteverket-tvarvander–appar-slipper-dubbelmoms
Custom Android TabWidget with Badges
For an android app I’m working on I needed to present badges for tabs much like on the iPhone. I looked around for a bit but could not find any good solution for this. It seems the android SDK does not provide this feature out of the box. At least I could not find it. So I had a go at writing a custom TabWidget for this nifty feature.
I’m sure it can be made to look even better with some work. The icon is not the most pretty image and should probably be replaced. Called badge.png in the source files.
I used a singleton class BadgeTabManager to manage the tabs and get access to them from anywhere in the app. I guess this approach could be changed if several tabwidgets need to be used at the same time.
The badges are set by a simple call:
BadgeTabManager.getInstance().setBadgeAtIndex(5, 2);
The BadgeTabWidget looks like this:
/*
* Copyright (C) 2011 Nilisoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.nilisoft.examples.badgetabs;
import java.util.HashMap;
import com.nilisoft.examples.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TabWidget;
public class BadgeTabWidget extends TabWidget{
HashMap map;
public BadgeTabWidget(Context context) {
super(context);
map = new HashMap();
}
public BadgeTabWidget(Context c, AttributeSet set){
super(c, set);
map = new HashMap();
}
public int getBadgeNumAtIndex(int index){
Badge b = map.get(index);
if (b == null){
return 0;
}
else{
return b.getNum();
}
}
public void setBadgeAtIndex(int num, int index){
Badge b = map.get(index);
if (b == null){
b = new Badge();
map.put(index, b);
}
b.setNum(num);
public void setBadgeAtIndex(int num, int index){
Badge b = map.get(index);
if (b == null){
b = new Badge();
map.put(index, b);
}
b.setNum(num);
// should probably use some other way to update the view (repaint the tabs) but this works...
this.getChildAt(index).setVisibility(View.INVISIBLE);
this.getChildAt(index).setVisibility(View.VISIBLE);
}
}
@Override
protected boolean drawChild (Canvas canvas, View child, long drawingTime){
boolean b = super.drawChild(canvas, child, drawingTime);
// figure out our index in the tabs, need it for the badge number
int index = 0;
for(int i=0; i < this.getTabCount(); i++){
if (this.getChildAt(i) == child){
index = i;
break;
}
}
int num = this.getBadgeNumAtIndex(index);
if (num > 0){
Bitmap src = BitmapFactory.decodeResource(this.getResources(),R.drawable.badge);
Bitmap badge = Bitmap.createScaledBitmap(src, 24, 19, true);
int x = child.getRight()-badge.getWidth()-5;
canvas.drawBitmap(badge, x, 0, new Paint());
Typeface face = Typeface.create("Verdana", Typeface.BOLD);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTypeface(face);
paint.setTextSize(12);
paint.setARGB(255, 255, 255, 255);
String text = ""+num;
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
canvas.drawText(
text,
(x+badge.getWidth()/2)-bounds.width()/2,
// -1 here because the badge icon is looking as it does with some
// more space at the bottom for shadows, might need change if the
// size of the icon is changed
(badge.getHeight()/2)+bounds.height()/2 -2,
paint);
}
return b;
}
private class Badge {
int num;
public Badge(){
num = 0;
}
public void setNum(int num){
this.num = num;
}
public int getNum(){
return num;
}
}
}
And the full source code the for example project can be downloaded here: BadgeTabs
Enjoy! And please let me know if you find this useful in any of your apps.
Email marketing
Do you need help with setting up a good looking newsletter for your business? Check out our affiliate Mad Mimi Email Marketing.
Contact us if you need help with setting up your audience (lists) and integrating the API on your website for subscriptions/unsubscriptions.
CrossOver
One thing I’ve missed when using the mac for development is the radmin program (remote administrator):
http://www.radmin.com/products/radmin/rviewer.php
We use this at work a lot for the windows servers. Until now I’ve had to run windows in vmware fusion or Parallells but now i tried installing the mac program “CrossOver”:
http://www.codeweavers.com/products/crossover/
This neat little program lets you install (some) windows applications on your mac without using a complete windows VM (such as Parallells). Really awesome! You can add the program icon to your dock and run the app immediately.
So, now it is time for some testing!
Apputveckling ett hett ämne!
Apputveckling är ett hett ämne just nu. Det verkar som att svenska marknaden (kanske globalt också) har en brist på just app utvecklare. Jag har själv blivit erbjuden flera jobb fast jag redan är anställd och driver mitt eget företag.
Jag tror dock att det snarare rör sig om en brist på utvecklare i stort eftersom att gå från att vara en bra utvecklare till en bra app utvecklare är ett mindre steg. Steget var inte stort för mig själv som Java utvecklare att installera Android SDK och slänga ihop en rätt avancerad Android app på några dagar endast baserat på mina tidigare Java kunskaper. Det tog dock llite ängre tid att sätta sig in i iOS eftersom det är baserat på objective-c vilket inte är helt synonymt med Java. Men även det gick utan större problem.
Nu verkar det som att det poppar fram en massa utbildningar och kurser för apputveckling. Bland annat så kan man hitta en 120 poängs kurs på Mittuniversitetet för Android här: Mobila applikationer och nätverkstjänster för Android 120 hp
Jag ser dock att det verkar finnas en uppsjö med företag som utvecklar mot mobila applikationer (bara här i Sverige) och det verkar komma fler hela tiden. (T.ex mitt eget företag Nilisoft). Det verkar också vara populärt bland reklambyråer att söka utvecklare för mobila applikationer för att kunna erbjuda appar som ett marknadsföringspaket. Det är också här som jag tror man kan tjäna pengar på apputveckling. Jag gjorde tidigare ett inlägg om att det verkar lönlöst att försöka tjäna pengar på Android appar såvida man inte verkligen lyckas göra en riktig superhit som hamnar överst på listorna i Android Market. Läs mer här: “80% of all paid apps have been downloaded less than 100 times until now.” Dock kan en app vara en bra marknadsföringsprodukt även om den inte direkt inbringar pengar baserat på nedladdningar.
“Android Developers Who Charge for their App Can Say Goodbye to Revenue”
Recently read the post here:
http://blog.inner-active.com/2011/05/android-developers-who-charge-for-their-app-can-say-goodbye-to-any-revenue/
It is a bit discouraging reading regarding earning revenue from Android apps…
"80% of all paid apps have been downloaded less than 100 times until now."
That sounds alarming… So for MOST developers (except the 20% that gets more than “100″ downloads) the revenue is practically near zero.
So how do you earn from Android apps? With ads like admob etc? I’m not sure I believe the ads will generate any large kinds of income from apps that would fall into those “80%”. With ads (as far as I can tell) you need SHITLOADS of users using your app ALL THE TIME. Perhaps I am wrong…?
Anyways, I’m curious about which way would generate the best income from releasing apps in Android Market.
Edit: test
HTC Wildfire S
After some consideration I’ve decided to use a HTC Wildfire S for Android development. It is not too bad but still not too good either. Using a too fancy phone may obscure some of the problems that may arise from code that may be too complex for lesser devices. Wildfire S seems like a nice middle cut that will hopefully be fine for development purposes.
Android Apps
I’m currently looking into the android sdk and checking out how hard it would be to create some android apps. It feels like the market for android is getting bigger and bigger and I shouldn’t miss out on the chance to build android apps. Even more so when I am actually a hardcore java developer and Eclipse is my backyard. Hopefully the learning curve won’t be as big as it was with learning a new language (objective-c) for building iPhone apps.
Android here we come!
Injecting Javascript in UIWebView
This is an interesting technique similar to what I’ve talked about in a previous post about extracting data from an UIWebView using the stringByEvaluatingJavaScriptFromString function. Instead of just fetching a value using this method you can inject a complete javascript into the page and call the functions in that javascript to extract data from the html.
I recently wrote an App that used this technique to add a few javascripts into the UIWebView and then called the functions in the script using the stringByEvaluatingJavaScriptFromString call to fetch data transformed into JSON format by the scripts. The javascript functions easily found particular elements in the html and composed a JSON string from them which was returned.
Really neat. Makes it easy to fetch data from websites for your Iphone apps without having to “parse” html code or similar. Instead use the existing javascript language to get what you need in a few simple steps.
Parallels Desktop 6
I’ve been using VMware fusion lately for running windows side-by-side on the mac.
Supposedly the new Parallels Desktop 6 should be better in many aspects.
http://www.parallels.com/landingpage/pd6-vs-fusion/
I’m just now trying the new Parallels to see if it really beats fusion or not.
Extracting data from HTML in iOS/Objective-c
Suppose you have a piece of HTML you need to extract information from.
One solution is to “parse” the html data using XPath such as described here:
http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone
A more simple and neat trick is to simply load your html data into a UIWebView and extract the information from it using javascript. You can keep the webview hidden during the process.
Example:
[webView loadHTMLString:html baseURL:nil];
NSString *value = [webView stringByEvaluatingJavaScriptFromString:@"document.myform.myfield.value;"];
Simple!


Nilisoft: Cool that it works for you!...
Peyton: NM... I forgot to update my layout to use the custom BadgeTabWidget in...
Peyton: I'm getting a type cast exception on this line: BadgeTabWidget tabWid...
RRaja: Awesome! This was precisely what I have been wanting to do. Thanks ...
Nilisoft: The download link should now work again. When moving sites the old lin...