[android-developers] Re: Good practise
Thnx Kaj, well it is not really an app. I am exploring Android and Java, coming from an AS3 backgound. I havent even begun to look inot threads. But to answer your question. The app is just drawing dots to the canvas and one button is moving them all x+=1. I wanted to find out how to deal with this in Android. 1. use an intent that all the newly created dots are listenening to. 2. use a model and register this to listen to an intent. When it responds, it goes through the dots and updates them. Jiri Kaj Bjurman wrote: You haven't told us how many dots that you have, but I do think it sounds like an odd design. What kind of application is it? How often are they moved? How many dots do you have? What do they represent? I might of course be wrong here, but this sounds a bit like a common problem that I often see in people who are starting with game programming and is using e.g. one thread per bullet or what ever they have that is moving. On 11 Aug, 20:10, Jiri jiriheitla...@googlemail.com wrote: Thanx Yusuf, your advice is right, i should optimise later. I have to admit i am just started exploring Java and the android API, so hence the sloppyness. The main point is, that being so new, i have to post these kind of questions to take away some insecurity on choices i make. If I understand your point correctly, it is not bad practice what i did. I just need to optimize... Using a dotmanager, isnt it more expensive to go through all the dots an update them. I can imagine by using the architecture as is and not implement another structure, this would be faster. Any ideas on that? Jiri Yusuf T. Mobile wrote: Code first for simplicity then optimize if/as needed. That being said (well, more like pontificated, sorry), a simpler design would be to aggregate all your dots into a DotManager. This would listen and draw all the dots as needed. Aggregation works if all the dots are similar enough that their code can be centralized, and if I understand your problem correctly (all dots listen for the same event and then they all move), my brilliant and royalty-free design would be appropriate. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Aug 11, 9:13 am, jiriheitla...@googlemail.com jiriheitla...@googlemail.com wrote: I was wondering if the following is considered good practice. I am creating mulitple Dot instance. A Dot instance is a value object containing x,y, color, diameter fields. I draw each created Dot to a view: code canvas.drawCircle( dot.getX(),dot.getY(),dot.getDiameter (),paint); /code Now i want all the Dots to listen to a certain event, lets say that i want to click a button and move all the Dots. What i do is in the Dot constructor i add this code: code IntentFilter intentFilter = new IntentFilter (org.dadata.demo.SEND_TO_REACTOR); Appcontext.registerReceiver(this, intentFilter); ... @Override public void onReceive(Context context, Intent intent) { this.x += 5; } /code Then from my button i send the intent : code intent.setAction(org.dadata.demo.SEND_TO_REACTOR); getApplicationContext().sendBroadcast(intent); View.invalidate(); /code I am wondering if someone could give me some feedback on this. Is it expensive for instance, and are there better ways to achive the same. Thank you, Jiri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Good practise
You haven't told us how many dots that you have, but I do think it sounds like an odd design. What kind of application is it? How often are they moved? How many dots do you have? What do they represent? I might of course be wrong here, but this sounds a bit like a common problem that I often see in people who are starting with game programming and is using e.g. one thread per bullet or what ever they have that is moving. On 11 Aug, 20:10, Jiri jiriheitla...@googlemail.com wrote: Thanx Yusuf, your advice is right, i should optimise later. I have to admit i am just started exploring Java and the android API, so hence the sloppyness. The main point is, that being so new, i have to post these kind of questions to take away some insecurity on choices i make. If I understand your point correctly, it is not bad practice what i did. I just need to optimize... Using a dotmanager, isnt it more expensive to go through all the dots an update them. I can imagine by using the architecture as is and not implement another structure, this would be faster. Any ideas on that? Jiri Yusuf T. Mobile wrote: Code first for simplicity then optimize if/as needed. That being said (well, more like pontificated, sorry), a simpler design would be to aggregate all your dots into a DotManager. This would listen and draw all the dots as needed. Aggregation works if all the dots are similar enough that their code can be centralized, and if I understand your problem correctly (all dots listen for the same event and then they all move), my brilliant and royalty-free design would be appropriate. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Aug 11, 9:13 am, jiriheitla...@googlemail.com jiriheitla...@googlemail.com wrote: I was wondering if the following is considered good practice. I am creating mulitple Dot instance. A Dot instance is a value object containing x,y, color, diameter fields. I draw each created Dot to a view: code canvas.drawCircle( dot.getX(),dot.getY(),dot.getDiameter (),paint); /code Now i want all the Dots to listen to a certain event, lets say that i want to click a button and move all the Dots. What i do is in the Dot constructor i add this code: code IntentFilter intentFilter = new IntentFilter (org.dadata.demo.SEND_TO_REACTOR); Appcontext.registerReceiver(this, intentFilter); ... @Override public void onReceive(Context context, Intent intent) { this.x += 5; } /code Then from my button i send the intent : code intent.setAction(org.dadata.demo.SEND_TO_REACTOR); getApplicationContext().sendBroadcast(intent); View.invalidate(); /code I am wondering if someone could give me some feedback on this. Is it expensive for instance, and are there better ways to achive the same. Thank you, Jiri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Good practise
Code first for simplicity then optimize if/as needed. That being said (well, more like pontificated, sorry), a simpler design would be to aggregate all your dots into a DotManager. This would listen and draw all the dots as needed. Aggregation works if all the dots are similar enough that their code can be centralized, and if I understand your problem correctly (all dots listen for the same event and then they all move), my brilliant and royalty-free design would be appropriate. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Aug 11, 9:13 am, jiriheitla...@googlemail.com jiriheitla...@googlemail.com wrote: I was wondering if the following is considered good practice. I am creating mulitple Dot instance. A Dot instance is a value object containing x,y, color, diameter fields. I draw each created Dot to a view: code canvas.drawCircle( dot.getX(),dot.getY(),dot.getDiameter (),paint); /code Now i want all the Dots to listen to a certain event, lets say that i want to click a button and move all the Dots. What i do is in the Dot constructor i add this code: code IntentFilter intentFilter = new IntentFilter (org.dadata.demo.SEND_TO_REACTOR); Appcontext.registerReceiver(this, intentFilter); ... @Override public void onReceive(Context context, Intent intent) { this.x += 5; } /code Then from my button i send the intent : code intent.setAction(org.dadata.demo.SEND_TO_REACTOR); getApplicationContext().sendBroadcast(intent); View.invalidate(); /code I am wondering if someone could give me some feedback on this. Is it expensive for instance, and are there better ways to achive the same. Thank you, Jiri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: Good practise
Thanx Yusuf, your advice is right, i should optimise later. I have to admit i am just started exploring Java and the android API, so hence the sloppyness. The main point is, that being so new, i have to post these kind of questions to take away some insecurity on choices i make. If I understand your point correctly, it is not bad practice what i did. I just need to optimize... Using a dotmanager, isnt it more expensive to go through all the dots an update them. I can imagine by using the architecture as is and not implement another structure, this would be faster. Any ideas on that? Jiri Yusuf T. Mobile wrote: Code first for simplicity then optimize if/as needed. That being said (well, more like pontificated, sorry), a simpler design would be to aggregate all your dots into a DotManager. This would listen and draw all the dots as needed. Aggregation works if all the dots are similar enough that their code can be centralized, and if I understand your problem correctly (all dots listen for the same event and then they all move), my brilliant and royalty-free design would be appropriate. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Aug 11, 9:13 am, jiriheitla...@googlemail.com jiriheitla...@googlemail.com wrote: I was wondering if the following is considered good practice. I am creating mulitple Dot instance. A Dot instance is a value object containing x,y, color, diameter fields. I draw each created Dot to a view: code canvas.drawCircle( dot.getX(),dot.getY(),dot.getDiameter (),paint); /code Now i want all the Dots to listen to a certain event, lets say that i want to click a button and move all the Dots. What i do is in the Dot constructor i add this code: code IntentFilter intentFilter = new IntentFilter (org.dadata.demo.SEND_TO_REACTOR); Appcontext.registerReceiver(this, intentFilter); ... @Override public void onReceive(Context context, Intent intent) { this.x += 5; } /code Then from my button i send the intent : code intent.setAction(org.dadata.demo.SEND_TO_REACTOR); getApplicationContext().sendBroadcast(intent); View.invalidate(); /code I am wondering if someone could give me some feedback on this. Is it expensive for instance, and are there better ways to achive the same. Thank you, Jiri --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---