Exact timing - Metronome - Android Software Development

I'm a newbie to development on Android, and I'm trying to learn through developing a simple Metronome app. The app that I've developed uses soundPool with 2 samples, and I've tried using either a Timer or a thread with nano calculation of sleep time but the sound never happens accurately.
Can anyone direct me to how I can get exact timing for developing such a app?

Related

[Q] Forcing screen rotation

Hi all,
If this is in the wrong place, i apologise unreservedly. It's really a question about android generally, but it's a question which has arisen specifically due to the behaviour of many of the various android builds available for the HD2, so i figure this is a sensible enough place to put it.
Enough waffle; the question:
Given the screen freezing issues associated with the gsensor/autorotate (i know this is at least relatively widespread as it's mentioned in many of the rom threads, and at least one dedicated thread), is there a setting/widget/app that can be used to force-rotate the screen and lock it in that orientation, if auto-rotate is disabled? For example, if i know i'm about to launch my browser or texting app, i can flip to landscape.
Many thanks all!
_tangent said:
Hi all,
If this is in the wrong place, i apologise unreservedly. It's really a question about android generally, but it's a question which has arisen specifically due to the behaviour of many of the various android builds available for the HD2, so i figure this is a sensible enough place to put it.
Enough waffle; the question:
Given the screen freezing issues associated with the gsensor/autorotate (i know this is at least relatively widespread as it's mentioned in many of the rom threads, and at least one dedicated thread), is there a setting/widget/app that can be used to force-rotate the screen and lock it in that orientation, if auto-rotate is disabled? For example, if i know i'm about to launch my browser or texting app, i can flip to landscape.
Many thanks all!
Click to expand...
Click to collapse
1. That is a very good idea and might fight the freezes caused by autorotation.
2. I want this anyway, because I want to be able to force a specific orientation when lying in bed. With autorotation the screen usually rotates the wrong way...
So any help would be appreciated!
+1 on this ^
Sent from my HTC HD2 Using the XDA App on ANDROID 2.2
MAMeingast said:
1. That is a very good idea and might fight the freezes caused by autorotation.
2. I want this anyway, because I want to be able to force a specific orientation when lying in bed. With autorotation the screen usually rotates the wrong way...
So any help would be appreciated!
Click to expand...
Click to collapse
I have this problem also
I've tried googling for an app of this sort, but so far no joy. Might try and create one myself. Never written something for android before, but software development is my day job, so i'd be willing to give it a crack. Crazy-busy at the moment though, so not sure when i'd get time
how about assigning a longpress-homekey something like rotate by 90° each time it is longpressed?
something like longpress-endkey menu in windows mobile devices.
shouldn't be that much of a problem to write such a program with appinventor?
I have Switch Pro Widget (it's a customizable energy control widget). One of the shortcut buttons enables/disables auto-screen rotation, so that does the trick for me.

Anyone Using Tasker?

Anyone here using it? what is this app for? is it worth buying? does it give u battery life? im really interested but i cant find no videos on it on youtube. please share your thoughts.
Yeah, I have it. First app I bought for my SGS. Tasker allows you to automate a lot of actions on an android phone based on conditions like time, location, application usage, a lot of stuff. It is very powerful but may be complicated at the start. There are a lot of good ideas on the web.
It doesn't give you battery life but you can automate settings which can help battery life.
Some of the things I have set up:
- Turn on GPS when I start Google maps. Turn it off when I exit.
- When I plug in headset, bring up a dialog which allows me to turn on radio, music player, or podcast player (this is worth the price of software).
- Turn on the internet every 2 hours for 5 mins to automatically sync gmail, etc when at work.
There are plenty of other examples on the web. My suggestion is to look at Tasker or Locale as these are two of the main products which do this. Tasker from what I hear is more powerful but Locale is simpler to use and has a heap of Locale plugins.
extremly helpful and cool program. But i have turned it off now for a while to se if it caused heavy lagg. Have anyone else with sgs experienced lagging caused by tasker?
I have not noticed any lag but I have Ryan's Lag fix installed. I do have a sneaking suspicion that if you have a lot of profiles running particularly time based, it may slow your phone down. FYI, I have 13 profiles I have set up and 6 of those are time and date based and I don't see any performance slow downs. I have this set to ignore on my task killer so it is always on.

random images while shaking

Hi,
I NEED TO ACCOMPLISH THE FOLLOWING
Displaying a series of random images during a shake,
Activate the accelerometer and timer on button click
increase the speed random images are displayed with the increased speed of shaking
HOW WOULD I ACCOMPLISH THESE?/WHAT IS THE SYNTAX FOR THESE?
thanks
Did you have a question?
Gene Poole said:
Did you have a question?
Click to expand...
Click to collapse
Mod edit: flaming and personal attack removed
OP, can you stop making personal attacks against another member.
I had to remove your edit reason for what you said to someone replying, and a personal attack against him.
XDA doesn't tolerate this, and we ask that you do not do this again.
isn't the accelerometre on all the time?
I can check to see what the coding would be for this in the app inventor, (gonna have to figure out how to make it do just that first, but should be alot easier than manually coding it, right?)
OK well i have completed almost all of this except for activating the onSensorChanged by a button click. As well as initiating a timer on the button click that will stop the onSensorChanged listener when time is up.

[Q] a guide to "non-convoluted android game programming"?

this question is actually about a small network of things: what the default android framework permits, how users use it and what engines can do.
after getting into android programming, it soon seemed to me that the android framework would require me to manage a lot of things i simply don't want to put up with for a simple game (e.g. i don't care about managing intents, creating xml-layouts and stuff like that... slap a couple of images on the screen and i'm fine - well... basically), i started looking for game engines.
after almost a month of research and tests (with default framework, andengine and libgdx), i finally whipped up a little prototype of the game i want to program using libgdx in just two days.
but then i noticed something...
the following issue might make the last third of this post irrevelant:
this game runs at 70% cpu usage on my desktop. even though i would only need to render on user input (it's a puzzle game). so i'm guessing it would use 20 times (or whatever) the battery of the phone it actually should.
since it seems to me "render on demand" isn't possible with libgdx, i figured i'd take another stab working with the default android framework and hope that this doesn't redraw like crazy even though it's not needed.
if such a thing is simply impossible, please tell me and i'll just keep on working with libgdx.
now, the most compact open source game example to learn from that i found is this:
http://code.google.com/p/asqare/source/browse/#svn/trunk/a2
after i tried it out and studied the code, i was stunned by how much stuff is being handled for this very, very simple game (pretty much as simple as mine). so i counted the lines of code... ~4200! while my libgdx prototype has roughly 800. sure, it doesn't have a preferences menu, no about screen and doesn't handle what happens on things like pause/resume but even with those things i highly doubt i'd get anywhere near that amount of code.
so:
IF it is indeed possible to produce a full-screen android app that draws images only on demand, is it possible to do that in a less convoluted fashion than in that 4200 line example?
i'm hopeful that this guy has simply overdone it and i've just been looking in the wrong places for slim examples.
Fyi I did not read 100% of your post, but I think I can help you out.
Imo do not waste your time with game engines. If you are serious about game dev then learn opengl. Its worth it.
With the glsurfaceview you can ether render on demand or as fast as possible. Also as with all opengl u have full control over what is rendered. If need be I can provide an example but it will have to wait a few days.
Sent from my MB860 using Tapatalk
actually, i've learned opengl in the past (but forgotten a lot already - didn't use those skills much) but a) i'll only do 2d games anyway and b) opengl isn't really the problem. getting to where i can actually render things is. and engines allow you to focus on gameplay/rendering without dealing too much with the whole setup and management of things.
i don't feel like libgdx takes control away from me, since i can still use all the opengl-commands i want. and i will definitely look up glsurfaceview and see how it fits into what i currently have. thanks!!
btw - i'm not really "serious". i'm a fulltime artist who happened to have learned about eight years of programming in the past and just wants to try to make a little extra on the side. and create some games i'd like to see but simply aren't out there yet.
and i don't want to spend more time programming all the management nonsense around it than the gameplay itself and working on the design.
I wouldn't rely on the cpu usage on the desktop. The emulator isn't efficient at all...
libgdx is a multiplatform engine, so that cpu usage is based on the desktop-version.
but it does use continuous rendering and can't be switched to on demand. tried to extend the classes of the engine and adapt them so that it renders in on demand for the last three hours without success...
but i've found a neat blog post on the android developers website called "The Simplest GLSurfaceView Application" and hope that i'll be able to find my way from there. after all, i now already at least have a nice full screen canvas with just 54 lines of code... that's something i did not expect i would ever see happening.

Tasker: Do you use it? How So?

I'm a user of AutoHotKey on my PC, and I love the little quirky scripts I can write to get rid of daily annoyances or do repetitive tasks.
I'm assuming Tasker is somewhat similar for Android. I've heard a bit about it, but because of the price-tag, never really indulged.
Who around here uses the app, can't live without it, etc?
What types of things do you rely on it for?
Thanks!
I really don't condone stealing, but find Tasker apk *hint* google*hint* test it out see does it meet your needs/wants and if you like purchase the legal app.
Sent from my SPH-D700 using XDA Premium App
I use it for a profile switcher and to toggle between 3g/WiFi when I enter/leave the home or office (each has an Airave).
When we had the Time Without Signal problem and toggling Airplane Mode was the quick fix, I set Tasker to toggle whenever I booted the phone or took it off the charger.
My kids have some geo-fencing text reminders set up for them as well for when they leave school.
Here's a quick link to some of the different tasks you can set up. Some quick Googling and you can pretty much find the script for whatever you need. I love it because one app can handle the job of 5-10 different apps, although sometimes the scripting can be frustrating.
http://tasker.wikidot.com/profile-index
Tasker
I use tasker for quite a few things. First and foremost is my pattern lock. I hate putting it in all the time at home, so I have tasker disable the pattern lock when I'm on my own wifi. I still keep the slide unlock active because I like the shortcuts on the lock screen.
I also use it for music. So when I plug in a 3.5mm plug without a mic it starts my music player and sets the volume. It also disables the lock screen which is insecure but when I'm driving or running I don't want to mess with a lock screen. When I'm casually listening to music, I have a headset which has a mic attached. Tasker can differentiate and therefore starts up my music app and sets the volume to a non-earsplitting level. For this I leave the lock screen active.
Lets see, when I start any app that uses GPS it automatically activates the GPS and polls my position. I have it automatically manage the screen brightness depending on the time of day. I also have it go to airplane mode if the battery is <5%. If I'm feeling lazy I have it manage when my wifi is on based on location. I have several locations (home, work, coffee shop) that I typically connect while I'm there and turn off wifi when I leave. I don't always use this because it's not 100% reliable.
That's about all I use it for. I can post instructions if anyone is interested.
I went ahead and purchased the app. Pretty cool so far. I'm interested in the profiles you are using, it sounds like you know what you are doing.
Thanks!
Sent from my Touchpad using XDA
Microsoft just introduced a similar app that's free. On{x} I think it's called.
I used to have it set wifi based on network location, but that wasn't always reliable. I use it to set volume levels depending on time, so that way it turns the phone down for work, and then cranks it up after work. I generally always have it making noise on email and phone calls, because I don't always feel it vibrate.
One other neat one I use is to put it in vibrate mode whenever I place the device face down. That way when I'm in a meeting, I take out my phone and just put it face down on the conference table...instant mute. When I pick it up, the sound comes back on. Also handy for charging at night, I just put it face down for the night and everything gets silenced.
I also have a profile that activates based on time and location...so now I don't have to worry about the "loudest cellphone in the world" -- one that goes off in church! :angel:
Only limited by your imagination, I found a lot of good ideas on the tasker site.
MeetFace said:
I went ahead and purchased the app. Pretty cool so far. I'm interested in the profiles you are using, it sounds like you know what you are doing.
Thanks!
Sent from my Touchpad using XDA
Click to expand...
Click to collapse
Here's how I have some of my tasks setup. I made a profile that activates when wifi connected (state->net->wifi connected->fill in whatever you need) and then have two tasks associated with it that I called "keyguard off" and "keyguard on". Keyguard on is my exit task. For Keyguard off go to (display->keyguard->set off) repeat for keyguard on. If you want to have the slide unlock to stay on you have to use a plugin called secure settings. Otherwise it's a similar process you just navigate to "plugins" instead of "display". From there it takes you into secure settings app which is easy enough to figure out.
For the music stuff: I made a profile one for a 3.5mm with a mic and one without (new profile->state->hardware->headset plugged in). Then I made a task which is assigned to the one without a mic, set the keyguard off like above then go to app->load app->your music app of choice. Then set the volume audio->media volume->whatever volume you want. Add an exit task that reactivates the keyguard I just use my wifi task for this. Same process for the one with the mic except I have it go to a lower volume.
To use GPS you probably have to use that secure settings plugin again depending on the rom you are on (im on AOKP and have to use it). Make an new profile (application->choose all apps with gps that you want to trigger this). Make a task (plugin->secure settings->edit->gps->pick state) then add another (misc->get location). Make an exit task that disables gps.
Finally, for low battery make a profile (state->power->battery level->whatever level) and associated task (net->airplane mode->on) and an exit task which turns it off.
There's plenty more that tasker can do, hope this helps you figure it out a little. I mostly just bumbled around the app until I found some useful things plus their website is full of good ideas.
I hope everyone doesn't mind if I add another question to the thread.
I'm interested in using Tasker as well, but I'm concerned that the benefits of automation will cost me in battery life. How much has you battery life changed using tasker, if at all?
Sent from my SPH-D700 using xda premium
amateurhack said:
I hope everyone doesn't mind if I add another question to the thread.
I'm interested in using Tasker as well, but I'm concerned that the benefits of automation will cost me in battery life. How much has you battery life changed using tasker, if at all?
Sent from my SPH-D700 using xda premium
Click to expand...
Click to collapse
Well, you could use the Battery Monitor Widget from the play store (the one with all the graphs and stuff), and use it to see how much the app is using. I doubt it's a lot but I know that it is SOME. The more apps running (and updating/logging) in the background the more battery you are using. Also, someone correct me if I'm wrong but, your phone has to "wake" every time an app needs to do something (update/log)
It does use power but nothing extreme in my experience. If you're using it for setting basic sound profiles and the like it won't be noticable really. You should look at it the other way though, taskers power of automating stuff like knocking off wifi and data connections when you dont need them will probably save battery life.
masaidjet said:
I really don't condone stealing, but find Tasker apk *hint* google*hint* test it out see does it meet your needs/wants and if you like purchase the legal app.
Click to expand...
Click to collapse
For the record, you can download a fully functional week-long trial from the dev's website for free.
I do a fair amount with Tasker, but one thing that I haven't seen many other people do is enable/disable battery-draining apps in certain contexts.
For example, I have a power-saving profile that disables a set of apps and services that would otherwise run 24/7. I also use have a profile which lets me run and disable AirDroid in response to a Google Voice text, so I can manage my phone from my laptop without ever touching it.
On my Nook, even small wakelocks add up over time when the battery life would otherwise be measured in days, so I use Tasker to disable just about any app that likely to throw a wakelock while I'm not using the device. Because I'm forgetful I also have profiles to disable wifi when the device goes to sleep, and to email me when the battery is getting low so I remember to charge it.
Finally, I also have generic profiles to lock and reply with GPS coordinates in response to text, turn volume to max and make noise in response to text, unlock when connected to home wifi, and unlock when my alarm goes off so that I don't have to enter my passcode and scan the alarm-silencing QR code I put up in the bathroom.
Let me know if you want more info on any of the above!
Would you mind posting the low battery profile?
I'd like to set that up on my TP.
Thanks!
Sent from my SGH-T989 using xda app-developers app
Sure, it's not too complicated although it does take a bit of setting up. To start with, in order to enable/disable apps you must use either the SecureSettings plugin with an updated su binary, or use adb commands. I choose to use SecureSettings, since that way I don't have to look up package names.
To disable groups of packages, I first make several individual tasks disabling each one. Then, I make another task which turns off wifi, 4g, and GPS. Next, I make another task which runs appropriate package-disabling tasks for that grouping, as well as the wifi/4g/GPS off task. Finally, I put an icon to run that group task on my homescreen.
Obviously, you'll have to figure out what apps/services you may want to disable for yourself.
Note that you could just as easily put all the package disabling actions in one task, thereby obviating the need to nest tasks. I just did it this way since that's what seemed natural to me, given that I have a few different groupings.
Links to XML files for the wifi/GPS off task, an example package disabling task, and a low power consumption master task.
amateurhack said:
I'm interested in using Tasker as well, but I'm concerned that the benefits of automation will cost me in battery life. How much has you battery life changed using tasker, if at all?
Click to expand...
Click to collapse
I had the same concerns when I purchased Tasker, and I've found the battery life impact to be undetectable by me. Mainly, that's because tasker runs based on states, and it doesn't constantly poll the OS for what state it's in.
For instance, I have a task that puts my device on silent when it's face down. From how I understand it works, tasker tells the OS "let me know when you are face down" and then pretty much goes to sleep. The OS handles that, and when it goes face down, it tells tasker "ok, i'm face down now" and then tasker executes its script.
So, tasker really doesn't impact battery life, but if you have it switch on high-drain stuff, then yep, you'll see a difference, but that's what you've set it to do, not the app itself.
HTH,
Michael
I've been very thankful for Tasker. I've used it for over a year now, and its one that I continually use and keep.
A few different ways I use is to set the sound profile depending day and time. It auto sets to vibrate at church and auto sets to sound off overnight. But if certain contacts call (mom, dad, wife, etc) the ringer turns on.
I also use it to turn on wifi when I'm home. Thankfully, I'm on Sprint with unlimited data. But I'm sure on other carriers, data usage may be a concern and using wifi at home could save that data usage.
Another cool way I use it is if I'm driving and recieve a text message, it will auto-reply with a text saying "Texting while driving is bad. I'm traveling at 47.3 mph currently. I'll reply later when it's safe". I know that's alittle overboard, but I think it's nifty.

Categories

Resources