Hello Widget Tutorial

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Hello Widget Tutorial

Postby TheSmile » Tue Jul 21, 2009 11:36 pm

Hi,

the first thing I wanted to learn when developing android apps were the new desktop widgets (available since CUPCAKE = Version 1.5). I could find a few examples but they were all much more then a "Hello Widget" so I took these examples and tried to come up with some simple ones.

I hope it helps you to get started on desktop widgets. I'm still learning so if you find any bugs or incorrect explanations I'd be thankful for any feedback and corrections.

You can find the tutorial and source codehere.
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Top

Postby daliz » Thu Jul 23, 2009 12:58 pm

Really useful. Thank you for your work.
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby daliz » Thu Jul 23, 2009 2:36 pm

There is a thing I'd like to know.

I'd like to make a single-buttoned widget (a switch).
A widget isn't an activity, so I can't call findViewById() to find a view.

So how can I attach an onClickListener on the ImageButton I create on the widget??
How can I get that view from my AppWidgetProvider without findViewById()?

Thank you ;)
~ daliz ~ :: www.datapixel.eu
w w w . g e e k d r o i d . c o m
daliz
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jul 07, 2009 11:15 pm

Postby TheSmile » Fri Jul 24, 2009 8:22 pm

Hi daliz,

you have to go via RemoteViews. Here's some code that might help:

Code: Select all
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);

// Connect click intent to launch ClickActivity
Intent detailIntent = new Intent(context, ClickActivity.class);
PendingIntent pending = PendingIntent.getActivity(context, 0, detailIntent, 0);

// if you click on your widget now, it will launch ClickActivity
remoteViews.setOnClickPendingIntent(R.id.widget_textview, pending);
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Postby desuvinodkumar » Wed Jul 29, 2009 11:14 am

HI

I gone through this app..is it possible to show gif image on the home screen(desktop)...for a while.....

thanks a lot in advance
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Postby TheSmile » Wed Jul 29, 2009 2:46 pm

Hi desuvinodkumar,

to be honest, I don't know. Did you try using a gif already? If not, just give it a try and let us know.

If you plan to use a gif as animated image I'm not sure if this is working.
I could add the ProgressBar of Android to a widget and it was working so it is somehow possible to use animation I guess. Unfortunately I could not set the ProgressBar to invisible.

There is another way of animating images in android but I don't know if it's working with desktop widgets:
http://developer.android.com/guide/topi ... phics.html see chapter "Frame Animation"
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Top

Postby desuvinodkumar » Thu Jul 30, 2009 6:49 am

Hi

Thanks for ur response
from here i learned how to play the gif animated image..
how_to_play_gif_file_in_android-t3492.html

i need to show it on the mobile desktop screen...by using this app_widget is it possible to do it...
u mention that desktop widget what it means exactly.....
please give the some more info regarding these....
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Postby TheSmile » Thu Jul 30, 2009 7:41 am

Hi desuvinodkumar,

with desktop widget I mean the UI elements on your home screen .. like the AnalogClock i.g.
I just say "desktop widget" to avoid confusion with other UI-Elements since the android package "android.widget" has all visual elements (like checkbox, button, TableLayout etc.) under it.
When you tab and hold on your homescreen (or desktop .. however you call it), you will get a popup menu where you can select "Widgets" a desktop widget is exaclty that.

First of all you need Android 1.5 (aka CUPCAKE) to use/create desktop widgets. They work different then an android applikation and have restrictions to what is working on them (i.g. you can't use a TableLayout on a desktop widget ... and don't ask me why)

Just jump into my tutorial and test it.
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Postby desuvinodkumar » Thu Jul 30, 2009 7:53 am

Hi

i gone through that blog...

if i try to rum the project

these errors are coming

[2009-07-30 12:14:10 - HelloWidget] No Launcher activity found!
[2009-07-30 12:14:10 - HelloWidget] The launch will only sync the application package on the device!
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Postby TheSmile » Thu Jul 30, 2009 8:10 am

Of course there is no activity since we are using AppWidgetProvider.

Do you have the latest SDK installed and are you using the eclipse plugin to develop android? You must have Android 1.5 to create desktop widgets.

Looks like you're having a problem with your development environment, not with the code. Can't help you with that, sorry.
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Postby desuvinodkumar » Thu Jul 30, 2009 8:18 am

Hi

Me working on Android sdk 1.5 development environment only...
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Killing the app

Postby keyserSoze » Wed Sep 02, 2009 5:18 pm

Cracking demo :D

but i'm having problems killing the app.

even after deleting the widgets and restarting the emulator onUpdate is continually called!

Am i missing something? :x
keyserSoze
Freshman
Freshman
 
Posts: 9
Joined: Tue Mar 17, 2009 6:06 pm

Postby foebea » Sun Sep 20, 2009 11:29 pm

Used the tutorial and feel I understand it well enough, but the widget does not update. When i remove the widget and re place it it shows the current time, but then again will not update at all. set for 60000ms as well as 1000 and 100 and 10, no difference.

Used on both 1.6 emulator and latest cyanogenmod.

Is this source code not viable in 1.6 or is it probably something ive done wrong?
User avatar
foebea
Freshman
Freshman
 
Posts: 4
Joined: Mon Apr 20, 2009 4:18 am
Location: Ohio

Postby TheSmile » Mon Sep 21, 2009 7:22 am

Hi foebea,

no, you're probably not doing anything wrong. I recently posted this issue on my blog here.
The night when SDK 1.6 was released I tested my 2 applications available on the market against it. Unfortunately my widget app didn't pass exactly because of the same problem you mentioned.
The bug, that the onDelete() method isn't called properly was fixed, but somehow the onUpdate method is not called after the updateTimeMillis are over. I tested my widget (same code) with 1.5 and it is running fine.

I have no workaround for now because I actually don't want to use the updateTimeMillis functionality any more. It's not configurable for the user and therefore not a convenient way to do that. You have to use an AlarmManager to do so. I hope I'll find some time soon to change it and then I'll put it into the widget tutorial.
Sorry that I can't help you with the 1.6 issue at the moment.

Norbert
Whatever comes ... just keep on smiling :)

http://blog.thesmile.de
User avatar
TheSmile
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jul 17, 2009 2:22 pm
Location: Germany

Postby foebea » Mon Sep 21, 2009 3:03 pm

If it helpful, nexsoftware tells me that for his androidandme widget he has it set an alarm to perform the update and then makes a new alarm after updating, this lets him use user customizable frequencies.
User avatar
foebea
Freshman
Freshman
 
Posts: 4
Joined: Mon Apr 20, 2009 4:18 am
Location: Ohio

Top
Next

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests