The Pizza Timer - Threading/Drawing on Canvas

Tutorials with advanced 'difficulty' and more Lines of Code.

Postby apple2183 » Wed Apr 15, 2009 12:19 pm

Dear sir/madam,
I just try to provide useful information to all people about android, and it may or may not useful to you , that is way I did not post more information in the messages.
Thank you
apple2183
Junior Developer
Junior Developer
 
Posts: 23
Joined: Fri Apr 10, 2009 2:07 pm

Top

Postby WarrenFaith » Wed Apr 15, 2009 12:25 pm

apple2183 wrote:Dear sir/madam,
I just try to provide useful information to all people about android, and it may or may not useful to you , that is way I did not post more information in the messages.
Thank you

you argument against yourself.... "i just try to provide useful information to all" and "that is why I did not post more information [...]"
You spam for you very small and very unuseful website. You posted one link 16 times! The other link 4 times. Thats pure spam and even bad spam if I read your post count.... 22, that makes 2 posts without a link... congratulation for this performance!
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby apple2183 » Wed Apr 15, 2009 1:00 pm

Hi sir/madam,
Sorry, since the information is not useful to you.
Thank you.
apple2183
Junior Developer
Junior Developer
 
Posts: 23
Joined: Fri Apr 10, 2009 2:07 pm

Cannot compile code

Postby slashrun » Wed Aug 12, 2009 2:57 am

I am using the downloaded .java files and just copy pasting them into like named .java files within an eclipse project. The project does not compile however; I have errors on line 90 in PizzaTimer.java stating that:
Description Resource Path Location Type
R.string.menu_reset cannot be resolved PizzaTimer.java AndDev Pizza/src/org/training/anddev/pizza line

and in PizzaView.java on line 77 stating that:
Description Resource Path Location Type
R.string.pizza_countdown_end cannot be resolved PizzaView.java AndDev Pizza/src/org/training/anddev/pizza line 77 Java Problem

Is there something that I need to add somewhere else? Thanks for your assistance.

Mac
slashrun
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 12, 2009 12:34 am

Postby hypermiler » Wed Nov 11, 2009 6:28 pm

Very helpful tutorial, thanks!
hypermiler
Freshman
Freshman
 
Posts: 4
Joined: Mon Nov 02, 2009 5:27 am

Notification not working

Postby jayaram » Fri Dec 18, 2009 5:09 am

Hello,
Thanks for this tutorial.
I tried this application. Everything is working right except the Notification.
As i'm using the newer SDK, i replaced this code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. nm.notifyWithText(PIZZA_NOTIFICATION_ID,
  2.  
  3.                                        getText(R.string.pizza_notification_text),
  4.  
  5. NotificationManager.LENGTH_LONG, null);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


with this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Notification notification = new Notification(0,getText(R.string.pizza_notification_text),System.currentTimeMillis());
  3.  
  4. nm.notify(PIZZA_NOTIFICATION_ID,notification);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But i'm not getting it.
Can someone help please...
jayaram
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Jul 29, 2009 3:37 am
Location: India

Top

Re: Notification not working

Postby dgmdan » Sat Jan 02, 2010 4:10 am

Thanks for the tutorial, it's helping me wrap my brain around handlers. I made a few changes and have attached my source code. My changes are:
- Fixed a few small problems to make it build on android 1.5
- Changed the notification to a toast (as suggested by someone earlier)
- Added a onSaveInstanceState method, and added code to the OnCreate method, so the timer can survive a screen rotation (when the activity gets re-created)
- Changed all instances of this.whateverVariable to just whateverVariable

I'm a beginner myself so if there's any bugs, or I'm doing things the wrong way, please let me know!

Edited to fix some code.
Attachments
PizzaTimer.zip
(3.39 KiB) Downloaded 322 times
dgmdan
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Dec 23, 2009 3:19 pm

how to stop the timer!!!!!!!

Postby sheshi85 » Fri Jan 29, 2010 12:51 am

First of all very thanks for the code PlusMinus.Regarding the thread in the program .How does the thread get stopped from sleeping.I was implementing simple ticking program for something to be fired .I came across the prob.It says uncaught remote exception :Exceptions not yet supported across processes.when I hit the key .Also i am not able to stop the thread from sleeping .Please find the file attached here .Please give me a solution .Thanks in advance!!!!!!!!!!!!
Attachments
Ticking.java
Simple ticking program.
(2.05 KiB) Downloaded 181 times
sheshi85
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Jun 08, 2009 11:17 am

Postby spring » Fri Mar 05, 2010 8:58 am

great work,thanks :D
spring
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 09, 2010 4:37 am
Location: China

Re: how to stop the timer!!!!!!!

Postby pskink » Fri Mar 05, 2010 10:25 am

sheshi85 wrote:First of all very thanks for the code PlusMinus.Regarding the thread in the program .How does the thread get stopped from sleeping.I was implementing simple ticking program for something to be fired .I came across the prob.It says uncaught remote exception :Exceptions not yet supported across processes.when I hit the key .Also i am not able to stop the thread from sleeping .Please find the file attached here .Please give me a solution .Thanks in advance!!!!!!!!!!!!



please, please, please don't use Threads for such thing!!!

its like using cannons to shut the fly!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.arka.Ticking;
  2.  
  3. import android.app.Activity;
  4. import android.os.Handler;
  5. import android.os.Message;
  6. import android.util.Log;
  7. import android.view.KeyEvent;
  8.  
  9. public class Ticking extends Activity {
  10.         static final String TAG = "Ticking";
  11.  
  12.         static final int MSG_CONTINUE = 0x1;
  13.         static final int MSG_RESET    = 0x2;
  14.         static final int TOUT = 10;
  15.  
  16.         private int secondspassed = 0;
  17.     @Override
  18.     protected void onResume() {
  19.         super.onResume();
  20.         // start count down
  21.         Log.i(TAG, "Start counting down");
  22. mHandler.sendEmptyMessage(MSG_CONTINUE);
  23.     }
  24.     @Override
  25.     protected void onPause() {
  26.         super.onPause();
  27.         // stop count down
  28.         Log.i(TAG, "Stop counting down");
  29. mHandler.removeCallbacksAndMessages(null);
  30.     }
  31.  
  32.     Handler mHandler = new Handler() {
  33.         @Override
  34.         public void handleMessage(Message msg) {
  35.             if (msg.what == MSG_CONTINUE) {
  36.                                 secondspassed++;
  37.                                 if(secondspassed == TOUT) {
  38.                                         Log.i(TAG, "TimeOut!!!");
  39.                                         secondspassed = 0;
  40.                                 }
  41.                         } else
  42.                         if (msg.what == MSG_RESET) {
  43.                                 mHandler.removeCallbacksAndMessages(null);
  44.                                 secondspassed = 0;
  45.                                 Log.i(TAG, "Reset!!!");
  46.                         }
  47.                         Log.i(TAG, "Ticking!!! " + secondspassed);
  48.                         // send next tick
  49.                         sendEmptyMessageDelayed(MSG_CONTINUE, 1000);
  50.                 }
  51.         };
  52.  
  53.    
  54.         @Override
  55.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  56.                 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
  57.                         // reset me
  58.                         mHandler.sendEmptyMessage(MSG_RESET);
  59.                         return true;
  60.                 }
  61.                 if (keyCode == KeyEvent.KEYCODE_BACK) {
  62.                         finish();
  63.                         return true;
  64.                 }
  65.                 return false;
  66.         }
  67. }
  68.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


p.s. something screw up formatting so i'm attaching source as well
Attachments
Ticking.java
(1.53 KiB) Downloaded 185 times
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby pskink » Fri Mar 05, 2010 1:33 pm

btw i see so many people using Threads/Timers/TimerTasks just to make some animations, changing periodically TextViews etc which is askinkg for troubles...

don't do that: use Handlers & Messages instead (see my previous post)
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: The Pizza Timer - Threading/Drawing on Canvas

Postby avicohen33 » Tue May 18, 2010 5:49 pm

i have a compilation problem. do i need to write the xml files by myself ? i don't know how to define the strings (for example R.string.menu_reset).
i also have some other java compilation problem. i am using sdk 1.5. is the tutorial written for an higher version?


thanks
avicohen33
Freshman
Freshman
 
Posts: 4
Joined: Mon Apr 05, 2010 12:58 pm

Re: The Pizza Timer - Threading/Drawing on Canvas

Postby Elte » Thu Jul 01, 2010 11:51 pm

avicohen33 wrote:i have a compilation problem. do i need to write the xml files by myself ? i don't know how to define the strings (for example R.string.menu_reset).


Download this updated pizzatimer zip file
http://www.anddev.org/advanced-tutorials-f21/the-pizza-timer-threading-drawing-on-canvas-t126-30.html#p32205

and YES you need to define the strings.
go to these folders res > values > strings.xml
then add the strings and their values

The problem i am having with this timer is when I press BACK button to multi-task, the timer is stopped and saved.
When I resume the pizzatimer, the timer then starts to countdown.
Meaning, if the pizzatimer app is not active on your screen, the timer freezes and waits until you resume.
The timer is then pointless because I cannot do anything with my phone except stare at the timer. :roll:

In order to make an efficient timer that wont be killed when inactive or that will continue counting down when inactive, do I need to make a service?
Elte
Freshman
Freshman
 
Posts: 5
Joined: Fri Jun 25, 2010 4:54 pm

Re: The Pizza Timer - Threading/Drawing on Canvas

Postby storm_to » Mon Jul 19, 2010 4:55 pm

I am trying to use .invalidate() in my app and it is not working out as expected.

Can someone please take a look at my post below and help?

Thanks!

[url]
view-layout-resource-problems-f27/show-dynamic-imagebuttons-one-at-a-time-as-their-backgrounds-t16057.html
[/url]
storm_to
Freshman
Freshman
 
Posts: 8
Joined: Thu Jul 08, 2010 4:24 pm

I need to draw some text on image then want to store it as a

Postby srisan29 » Wed Aug 18, 2010 8:48 pm

Please help
srisan29
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 18, 2010 7:19 pm

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests