Toggling a image - Android Software Development

I'm working on an app where there is a requirement to "mark" an item, specifically a question on a quiz app.
There is an image button on the top of the screen and when pressed, will put a "star" by the question. The user wants this to toggle, that is, every time the imagebutton is pressed, the star will appear or disappear.
Any "easy" way to do this? LOL Obviously I know how to show and hide it. But the code on the actual button press could be a pain. Not to mention, once set to View.VISIBLE, it's visible on ALL pages of the quiz.
My thought is to store the state of the question# and status of button in a database table: Y for on, N for off. Then query that status on every page. What I prefer would be something like this:
Code:
switch(V.getid()) {
case starButton: // button pressed!
if(star.VISIBLE) // it's there already, get rid of it
star.setVisibility(View.INVISIBLE);
else
star.setVisibility(View.VISIBLE); // not there, show it
}
There isn't a "star.VISIBLE" There is "star.setEnabled(true/false)", but that just "turns off" the button and grays it out a little. Any ideas? I want to keep this code short and sweet because I have to put it in onFling() too!
TIA,
Roots

if (star.getVisibility() == View.VISIBLE)
......

OMG...ok, I need to retire from programming ROFL So simple, so easy and yet I am so dumb to not see that solution.
Man, I was all around it wasn't I? LOL
Thanks. <hides under desk in shame>

Related

App Request : Enable keypad backlight while screen is on

For any devs out there...
Would it or is it possible to develop an app that will keep the backlight on for the keypad ? i.e. On while the screen is on and go off when the screen goes off ?
In the dark its very annoying when using the Hero and having to fumble for the right key to press - Home, Back, Search etc.
i second that
well erm just press any key and the light will go on dude, you dont need an app for this
So you fumble and hit Home or even power off (to sleep) the screen when you only wanted to hit search or back.
Flicking the scroll wheel is the only way to light up the keys and not press the wrong one by mistake, but that tends to highlight a button, link etc... and sometimes if you hit the ball too hard, you select a screen element.
Still a pain and TBH not like any handset I used before. Backlight time out was always linked to screen time out.
You dont need to hit any key, just move the scroll wheel even slightly and lights come up. And it does need decent amount of pressure to press the scroll button, you wont accidentally press it.
er, yer, I know... but I don't want too
lets just say "even if it doesnt make sense to some people, WE want it!"
btw, there is one app "dark keys" that keeps the backlights of the keypads off all the time. this was made for the white G1. maybe it can simply be rewritten to make the reverse happen?
joemax said:
For any devs out there...
Would it or is it possible to develop an app that will keep the backlight on for the keypad ? i.e. On while the screen is on and go off when the screen goes off ?
In the dark its very annoying when using the Hero and having to fumble for the right key to press - Home, Back, Search etc.
Click to expand...
Click to collapse
+1
i'm beeing annoyed by the keys not being lit as well ...
Glad I'm not the only one
Yeah, I want it too. Thanks for bringing this up!
I think it's good idea, btw it looks cool at night. I want it too
Good idea. +1
So which dev is gong to earn a couple of $$, ££, €€ by writing this for each copy sold then ??
From what I can tell of the API docs (http://developer.android.com/reference/android/os/PowerManager.html, the SDK only allows for the keyboard backlight to be on in FULL_WAKE_LOCK state, meaning the screen will have to be full brightness.
So I don't think this request can be achieved by a pure SDK app.
How come it lights up at any screen brightness on the Hero ?
Surely its also a hardware call and not just an OS call ? These would be independent of Android and particular to each manufactures handset, else they would all be the same.
Not questioning you, but it would seem strange that its not addressable separately to the screen ???
joemax said:
How come it lights up at any screen brightness on the Hero ?
Surely its also a hardware call and not just an OS call ? These would be independent of Android and particular to each manufactures handset, else they would all be the same.
Not questioning you, but it would seem strange that its not addressable separately to the screen ???
Click to expand...
Click to collapse
I'm by no means an Android SDK expert, just posting what I found in a quick search round the docs. Happy to be proven wrong!
Lee
Of course - wasn't criticising at all
Might be able to dabble in the /sys/class/leds/ folder.
I'll take a look when I get in.
Not a dev though. Lol.
soulehmoo said:
Might be able to dabble in the /sys/class/leds/ folder.
I'll take a look when I get in.
Not a dev though. Lol.
Click to expand...
Click to collapse
Correct.
echoing a value to:
/sys/devices/platform/i2c-adapter/i2c-0/0-0066/leds/button-backlight/brightness
through adb shell turns on the backlight.
I think an SDK app could be created as a service with a broadcast receiver listening for the power state changing that just writes a positive value to the file above.
Loads of similar examples here: http://forum.xda-developers.com/showthread.php?t=565015
I'll take this on, just about got it working.
Wicked thx
You are stars (especially fullerlee)
Don't make it too expensive though

[Q] What is the proper way to close an activity/application?

I started to develope an application.
When I wanted to close the application I clicked on the home screen,
but the app is still playing in the background.
Than I tried to click on the "back" key, but nothing happend, so I've
created a key event listener for the 'back" key, and inside that
method I wrote finish();
Now my app is closing but I think it's still running in the
background, because when I go to "manage applications" I can still see
it in the "running" tab, and if I press it, I see I can click on the
"force close" to actually close the app.
What do I need to do in order to really close the app without leaving
it open (one way or another)?
Thanks, Yaniv
You does not need a Exit Button, because Android will close things up as needed.
Perhaps you should read this: click
Otherwise you can exit your app with System.exit(0) at the end of your
onDestroy() methode.
Yes, I do know that Android is closing unused apps, but I do want to put also an exit option.
And thanks, the System.exit(0) worked for me
How does that compare to having an Activity-extending class call finish() from the main UI thread?
Actually... now that I think about it... if you're going to call it, do you have to call finish() as the last thing you do before returning from onResume(), etc? Or is it literally a black void from which the calling thread is guaranteed to never return? If you look at the Javadocs, they merely say that calling it indicates that the Activity should be closed, with the result propagated back to the parent (if any).
I've gotten burned by Java enough times over the past 10 years to know it's dangerous to read more into Javadocs than they literally say, regardless of how commonsense and reasonable it might seem. Going by the Javadocs' literal wording, it would be perfectly reasonable for a call to finish() to simply mark the Activity as eligible for aggressive closure and recovery... then return from the call and have a trainwreck after it executes code in the following finally{} block, or between the point where you called finish() and the return from the end of the current method. It would be outrageous, make lots of developers mad, and cause huge problems... but technically not inconceivable... which is why traditionally, I end up following every call to finish() with throw new RuntimeException("WTF?!?");, just to be safe and guarantee that execution will never, ever continue beyond that point.

Activity Popping LOL

First screen is a Main Menu Activity.
It calls an activity (a quiz) based on user choice. User can abort to Main Menu with a button.
Quiz runs and at end, button is hit to score which opens new activity for scoring.
So, I have
Activity1 (Main Menu)
Activity2 (Quiz)
Activity3 (Scoring)
Now, it's easy enough to go back to the Quiz from Scoring with a finish() (and I do have that working and disabling all the quiz answers). That "pops" Activity3 off. And Activity2 can go to the Main Menu on button press (a finish()) and that pops off Activity2. All is good
Now, what if I want to go to the Main Menu from the Scoring Activity? I don't want to call a new Intent on it do I? Won't that leave Activity2 and Activity3 "un-popped"?
You know, when you leave something for a couple of days, it always seems to resolve its self LOL.
So remember coders, if you get really STUCK on something, let it go for a couple of days...it'll come to you

[Q] Screen on - New Activity created

Hi!
I've found a strange Activity behavior while programming a game for Android (currently with API level 8)
Following Situation:
The Main Activity only consinsts of one View on which the Game Thread draws all the sprites and stuff. In the manifest I checked android:multiprocess="false" and android:launchMode="singleInstance" for the Main Activity, so that Android only creates one instance of this activity, so you always come back to your left game after pressing the home button and starting the app again. This works great, but if I turn off the screen WHILE in game, and the activity is active, and turning it back on, Android creates another instance of the game (the Main Activity), so it starts over again.
So my question is, what could I do to prevent this and have the same behavior as if switched back to Home Screen before turning off the screen?
(The testing device is a HTC Desire HD with Android Revolution HD 5.1.7, if this is necessary information for helpers )
I hope someone here can help me!
I think you will have to listen for the screen off intent and handle this situation very explicitly. Maybe make the pause screen come up and then when it turns back on have your activity check for instances of itself and then deal with it.
Do you use static activities?
From something awesome
Thanks for your answer
The ScreenOff/On Intents method would be easy, but how can I recover the old Activity in the new one?
The Activity should be static, cause of the manifest properties, or not?
Another idea: In the onPause() Method queck if it was Screen off (with the corresponding intent) and 'call' the home button
Is this possible? And how could I realize this?
There is a way to use adb to send the home key press. And you can run adb on the phone with getRuntime().exec("adb keyevent xx")
Where xx is the home button constant
From something awesome
Thanks for your help!
But I made it now a much easier way...
One single 'moveTaskToBack()' in the onPause and everything works perfect!
Nice. Its always best to assume that android will do nothing to manage your app and to just do everything very explicitly
From something awesome

[Q] Listener problem

Hi,
I want my app to start, after the back button was pressed 3x.
So I got this class which is executed in the Launcher.
Code:
public class KeyManager extends Activity {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(KeyEvent == "Back key"){
Log.e("KM", "PRESSED!!!!!"+keyCode);
}
//return super.onKeyDown(keyCode, event);
return false;
}
}
This code works, if it s implemented in the launcher class, but it does not work, if the app is in the background. How or which key listener do I need for listening to background keys or more if the app is working only in the background?
Of course it doesn't work when being background. These events aren't sent to the activitiy if it's not in the foreground, and as far as I know even services can't react to them.
Well, ok so that is the problem. But I think it should be possible to solve that as some apps also react if for example the browser is being opened etc. Also, Samsung user might know, by clicking 2x the home button the app S Voice opens. And it should not be a system app, but just a usual one.
Maybe something like a global key listener is available? Unfortunately I couldnt find anything referring to that, yet.
Deyaz said:
Well, ok so that is the problem. But I think it should be possible to solve that as some apps also react if for example the browser is being opened etc. Also, Samsung user might know, by clicking 2x the home button the app S Voice opens. And it should not be a system app, but just a usual one.
Maybe something like a global key listener is available? Unfortunately I couldnt find anything referring to that, yet.
Click to expand...
Click to collapse
The Samsung S voice example is a really bad example to use because that's just code implemented in TouchWiz's launcher, I'm guessing its a timer that listens for 2 presses of the home button within a set time, if 2 presses are registered in the given time-frame, S Voice is launched via intent, if not then the default action for the home button is taken.

Categories

Resources