Can someone help me out on this? It involves Java, and Android.
6 replies, posted
Hey guys, I'm wanting to make a countdown application for Android counting down to 2013. I have an artist that is interested in helping me.
I'm not sure whether it should be in widget form, or in fullscreen form. I'm wanting to try both. Problem is, the only coding experience I have is Lua, and I'm pretty shit in that.
I was reading [url=http://androidgenuine.com/?tag=how-to-make-a-countdown-android]this[/url] But that doesn't seem to be the kind I want. Like, I was wanting one that'd check a webserver to update the countdown whenever you open it.
Does anyone know the basics of something like this?
Also, I'm trying to get it to look somewhat like [url=http://www.timeanddate.com/counters/customcounter.html?month=1&day=20&year=2013&hour=12&min=00&sec=00&p0=867]this[/url]
Does anyone have any easy to follow tutorials or anything that'd be able to help me?
Thanks!
Java has a Date object, you can use that to work out the difference between the current time and the start of 2013.
The Android SDK includes a layout editor for Eclipse so you should be able to pick up the various UI elements fairly quickly
Well, for starters, you need to learn that there isn't going to be a tutorial that leads you directly to your goal with programming. You need to divide your target application into steps that are needed to make it function and then look up information about these generic steps.
Let's have a look at your case here. There isn't going to be a tutorial called [i]Make a countdown app + widget for people who have never used the SDK[/i]. When you face a problem, you always need to sense the parts that make up the final solution. Although, given enough of a lack of knowledge, this sometimes isn't possible from the start.
Let me do it for you this time.
[b]1. Learn the basics of Java[/b]
Since you don't know any Java yet, at all, you should really brush up on that first. Java is a statically typed language and it doesn't have tables, so that's something you'll have to get used to. It also involves completely around classes.
This is an excellent starting point for learning Java:
[url]http://docs.oracle.com/javase/tutorial/java/[/url]
[b]2. Learn the basics of Android[/b]
Install the SDK: [url]http://developer.android.com/sdk/installing.html[/url]
Learn the basics by writing a Hello World application: [url]http://developer.android.com/resources/tutorials/hello-world.html[/url]
Learn about layout types: [url]http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts[/url]
[b]3. Check something on a web server
Since Android uses Java, it is very important that you realise you shouldn't be looking for Android-specific solutions. A generic Java http example works perfectly well on Android:
[url]http://stackoverflow.com/questions/1359689/how-to-send-http-request-in-java[/url]
But when you try this, you will notice that the connection fails. That's because we forgot something. Just look at the exception that is thrown by the HTTPUrlConnection object and you will see that it has something to do with an internet permission.
We google [i]"android internet permission"[/i] and we end up on this page:
[url]http://developer.android.com/resources/samples/SampleSyncAdapter/AndroidManifest.html[/url]
Apparently you need to add a permission to your AndroidManifest.xml to connect to the internet with your application! After recompiling our application, the HTTP request will now work fine.
[b]4. Find out how to calculate the time left[/b]
You probably made the HTTP request above return a [url=http://en.wikipedia.org/wiki/Timestamp]timestamp[/url] that the app should count down to. In Java, the Date object can be used to make time calculations. However, in this case it is not necessary to use it. A timestamp of the current time [b]in milliseconds[/b] can be retrieved with a call to [i]System.currentTimeMillis()[/i].
Now the rest is simple:
[cpp]long secondsLeft = ( System.currentTimeMillis() - timestampHttpRequest ) / 1000;
int daysLeft = secondsLeft / ( 24 * 3600 );
secondsLeft -= daysleft * 24*3600;
int hoursLeft = secondsLeft / 3600;
secondsLeft -= hoursLeft * 3600;
int minutesLeft = secondsLeft / 60;
secondsLeft = secondsLeft % 60;[/cpp]
This info can now be displayed in a [url=http://developer.android.com/reference/android/widget/TextView.html]TextView[/url] by getting a reference to it using [i]findViewById[/i] and calling [i]setText[/i] on it.
[b]5. Find out how to create a widget[/b]
Now that our application works, we still need to build the widget.
You can find out how to do that with your current knowledge here:
[url]http://www.vogella.de/articles/AndroidWidgets/article.html[/url]
It even has an example with a fixed update interval, which is of course perfect for a countdown.
[b]Conclusion[/b]
Always divide your problem into steps. There isn't going to be a tutorial for your problem as a whole, because that would be absolutely pointless. You are a smart human being like all of us, use your mind to dissect a problem into parts that are generic enough in that you feel there could be a tutorial about.
[b]Bad Google searches[/b]
» download facepunch android http
» countdown widget not refreshing android
» widget can't connect socket android
[b]Better, more generic searches that make it a lot more likely to find help[/b]
» java http request
» widget not updating android
» socket android can't connect
The chance that there is someone also making a New Year's eve countdown with the exact same problem as you on SO is very small, but the chance that someone posted about a problem that their socket couldn't connect or their widget couldn't update is quite big.
Good luck! :smile:
[QUOTE=Overv;34031931] -text- [/QUOTE]
Hot damn
That has to be the most useful single post I've ever seen.
[QUOTE=kaukassus;34032448]Hot damn
That has to be the most useful single post I've ever seen.[/QUOTE]
and then you went ahead and rated it something other than useful.
:v:
[QUOTE=BlkDucky;34032467]and then you went ahead and rated it something other than useful.
:v:[/QUOTE]
I can't rate [img]http://www.facepunch.com/fp/ratings/heart.png[/img] and [img]http://www.facepunch.com/fp/ratings/wrench.png[/img] at the same time.
Thanks Overv! That is actually super helpful. My brother has been helping me out too, but this is probably going to take a while.
All of this is quite literally a foreign language to me, so it's going to take quite a bit of time to get used to.
Again, thank you!
Sorry, you need to Log In to post a reply to this thread.