Office Hours — Today, January 8

Monday, December 21, 2009

Jan 8
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Jan 8
9:00 AM
NetApex
has entered the room
NetApex
Good morning
Mark M.
Howdy!
NetApex
I finally remembered on the correct day!! :)
NetApex
I have a huge huge favor to ask of you
Mark M.
Huge huge?
Mark M.
Not sure I can handle that
Mark M.
:-)
NetApex
Huge for me, cake for you I bet. I have been working on a soundboard for a couple of weeks now and I can not get the "save to sdcard" part working.
Mark M.
you have the WRITE_EXTERNAL_STORAGE permission?
NetApex
Mainly because.. well.. I don't have a clue what I am doing lol. Just learning a bit of java.
NetApex
Actually that part isn't even the issue yet. It's the contextmenu part.. or should I be using the onlongclick to pass the info
NetApex
heck, mind if I upload the java I have for it?
Mark M.
Sure, though if it's long, I'd recommend you use a pastebin or something
NetApex
It isn't too big I don't think
Mark M.
Campfire can handle source code, but long ones get to be troublesome sometimes
NetApex
Mark M.
OK
Mark M.
Ah, as a file -- OK -- hold on
Jan 8
9:05 AM
Mark M.
Them's a lot of buttons!
NetApex
I rewrote it from my original version (that I have in the market now) which seemed to FC a lot
NetApex
lol yeah
NetApex
Ran out of alphabet :)
Mark M.
OK, I see where you have context menu stuff commented out
NetApex
I got tired of trying
NetApex
lol
NetApex
I was going to try onlongclick.. and that threw me so I removed it and was going to work on context again
Mark M.
Part of your problem in the commented-out stuff is that you're trying to use AdapterView, but you're not using an AdapterView.
NetApex
aside from the samples in the books here, this is my first real on my own app... so be gentle
Mark M.
By which I mean you can't cast ContextMenuInfo menuInfo to AdapterView.AdapterContextMenuInfo, since the context menu is on a Button, not an AdapterView (e.g., ListView).
NetApex
views seem to have me a bit confused as well, but what you just said makes sense
Mark M.
The Button the user long-tapped on should be the View cv parameter to onCreateContextMenu()
NetApex
ok but is there something already made for that.. like a ButtonView.ButtonContextMenuInfo or something?
Mark M.
I don't know why you would need it.
NetApex
Or do I have to become smart and think instead of being lazy and using built in things? :)
NetApex
Oh?
Mark M.
Just cast cv to be a Button?
Mark M.
If all you want is the caption of the button, use: ((Button)cv).getText()
NetApex
here is what I want, and what I have been able to figure out...
Jan 8
9:10 AM
NetApex
I want on long click to be able to say "save as ringtone" which I have figured out. But if they click to save it, it doesn't know what file it is named and I don't know how to pass (cast?) that. Also the text from the button would be good to have for a name of the file. I just learned that 2 minutes ago from you now so I may be able to do that. :)
Mark M.
Well...I think you have a few challenges here.
NetApex
so can I get rid of the onlongclick listener stuff and just use contextmenu? or should I toss it all and start anew?
riley
has entered the room
Mark M.
Hold on one moment...
riley
Hello
NetApex
ok
NetApex
Hello thre
NetApex
there
Mark M.
howdy, riley!
Mark M.
As I see it, there are four main gaps in what you have and what you want
NetApex
ok
Mark M.
First, there's getting the user to indicate they want to save the sound as a ringtone.
Mark M.
Either a long-click listener or a context menu could work
NetApex
context is my choice then
NetApex
I don't know longclick yet
Mark M.
No problem.
Jan 8
9:15 AM
Mark M.
You can drop the long-click listener and leave your registerForContextMenu() calls in place, then.
NetApex
done
NetApex
also removed adapter view info
Mark M.
OK. So now you should be able to display a context menu with the appropriate title, derived from the caption of the Button.
Mark M.
Second, you need to figure out, once they choose the context menu item, which raw resource it corresponds to, based on the Button.
NetApex
that is the bear for me
NetApex
that is why I have the alert dialog there... which never shows the correct choice lol
Mark M.
Unfortunately, onContextItemSelected() does not pass in the View
NetApex
ahhhh
NetApex
and the pain begins
Mark M.
The simplest solution is for you to probably have a private data member that you populate in onCreateContextMenu(), holding what information you need should the user actually choose the menu option.
NetApex
ok, I was lazy and named the files a,b,c,blah blah... so in effect how would I go about that?
Mark M.
One trick that I have used is to take advantage of setTag()
Mark M.
When you set up your Buttons, call setTag() on each, passing in the R.raw.x value for its corresponding raw resource.
Jan 8
9:20 AM
NetApex
so in the area where I do the setOnClickListener(this); I can follow it by a setTag(R.raw.a); right?
Mark M.
This lets you do two things. 1) You can use a single OnClickListener for all the buttons, since you can get the raw resource ID to play back via calling getTag() on the Button. 2) You can then get the raw resource ID via getTag() in onCreateContextMenu() and store it in a private data member.
Mark M.
Right
NetApex
Whoo hoo.. I understood something lol
NetApex
ok one sec, trying to comprehend your last statement
Mark M.
The third and fourth gaps -- getting at the resource stream and writing it to a file -- I think you have already in your commented-out code.
NetApex
I thought that looked right too.. just couldn't get the right info there to make it work.
NetApex
ok, back to the single onclicklistener
NetApex
I could cut out about 45 lines of code if I got that setup! But.. how? lol
NetApex
riley: sorry for hogging so much of the time here, feel free to ask questions or whatever as well!
Mark M.
I am assuming you are using android:onClick (or whatever that syntax is) in your layout to tie the buttons to the various agrail() and so on methods, right?
NetApex
no, that gets tied all in the code.. I suck with layouts right now too so I went basic... uploading
Mark M.
Oh, wait, I see it
Jan 8
9:25 AM
NetApex
ok not uploading then hehe
NetApex
xml is easy (I suppose) but I haven't really played with it enough yet either to be fluent
NetApex
I figured I would get it working first, then go back and work on looks
NetApex
which might not be the best idea since my first version FC'd all the time
Mark M.
Right, so in onClick(), you would get the raw resource ID via getTag() on the passed-in View. Then, you'd just execute the same stuff you have in any one of the agrail() methods, using the raw resource ID from getTag().
riley
Don't worry about it, I remembered this session was on when I glanced at my gcal earlier so I thought I would drop by and see what is going on. I only have a fairly small question (more app design than code) so I'll let you guys finish this one first. Who knows, I might learn something!
NetApex
heheh ok
NetApex
ok let me see if I have the right area here
NetApex
public void onClick (View vv)?
Mark M.
Yes
Mark M.
It's implementation could be:
Mark M.
public void onClick(View vv) {
Mark M.
if (mp !=null){mp.stop();}
Mark M.
mp=MediaPlayer.create(this, ((Integer)vv.getTag()).intValue());'
Mark M.
mp.start();
Mark M.
}
Mark M.
and ignore that rogue ' I stuck at the end of the long line (typo)
NetApex
heheh
Mark M.
The vv is your Button
Mark M.
Your Button has the raw resource ID in its tag
Jan 8
9:30 AM
Mark M.
You're just then taking advantage of that to avoid the whole chain of if() statements and all the per-button methods.
Mark M.
Should save ~200 lines of code
NetApex
so I could lose the calls to the "public void wound()" and have it work simpler then in the onClick area
NetApex
cool
NetApex
seriously.. I love the books, but being able to talk to someone about it too, yeah I love my wife!! She got me the subscription for Christmas!
NetApex
ok, I am going to change some things around and see what I come up with.. all you riley. I will have more questions in a bit :)
NetApex
Thanks a ton Mark
Mark M.
No problem -- over to you, riley
riley
Right
riley
I have an app that sends (and receives) data from the Google App engine
riley
To do this I'm using the RESTlet framework which works well and It passes a Form with data up and gets a response of just a String in a HTTP POST
Mark M.
OK
riley
But I now have a need to pass in and receive XML back
riley
so, long story short do you know of a good example of parsing XML in Android with DOM
Mark M.
Well, I'm not sure I'd use the DOM unless necessary
Mark M.
It's slow and RAM-intensive
riley
Other suggesstions?
Mark M.
SAX is a better solution
riley
Ah, I see.
Jan 8
9:35 AM
riley
Know of a good example of SAX then? :p
Mark M.
gadzooks! ExampleDepot.com reorganized their site!
Mark M.
Mark M.
That link gives you the skeleton
Mark M.
DOM and SAX parsing is just standard Java from Android'
Mark M.
er, Android's perspective
Mark M.
So, any Java example should work
riley
Ah, thanks mark :-)
riley
I told you it was a quick question :p
riley
hehe
NetApex
Heheh, yeah, makes me feel behind the times lol
Jan 8
9:40 AM
NetApex
NetApex
ok made a couple changes, haven't run it through anything yet to see what is wrong, but just from first glance...
NetApex
All of the onclicklisteners... there should be a way to be rid of them too right?
Mark M.
I think Campfire just served up the same file again
NetApex
renaming for a sec then
Mark M.
Oh, never mind, chose the wrong link
NetApex
ehehe
Mark M.
It's OK. The top link is the newer one.
Mark M.
I don't see where you're setting the tags on the Buttons.
NetApex
oh crap.. yeah that is because I forgot
NetApex
but I remembered to call those non existent tags
Mark M.
Also, in onCreateContextMenu(), you'll need to call getTag() on the View cv parameter and store that as an int somewhere (e.g., private int contextMenuResource).
Jan 8
9:45 AM
Mark M.
Then, contextMenuResource replaces info.id in the first line of your commented-out block
NetApex
ok
NetApex
I changed the cv to vv... but they do need to be seperate views don't they?
Mark M.
Huh?
NetApex
vv is what I was using for the button view
Mark M.
Oh, sorry, I didn't see the name change.
NetApex
cv for context... then I thought about it and made it all vv...
NetApex
but I don't know if that was "legal" or not
Mark M.
Yes, in onCreateContextMenu(), you would call vv.getTag(), save that as an int data member, and use that int in onContextItemSelected()
Mark M.
Yes, that's legal
NetApex
ok cool
NetApex
(views are getting a little clearer I think)
NetApex
in the oncreatecontextmenu... I added name=....
NetApex
would that be the correct format for what I am trying to do?
Jan 8
9:50 AM
Mark M.
That depends on what you are trying to do.
Jan 8
9:50 AM
Mark M.
You used to be trying to put the Button caption in the context menu title: menu.setHeaderTitle(((Button) info.targetView).getText());
Mark M.
That would now be menu.setHeaderTitle(((Button)vv).getText())
Mark M.
You don't have a name variable declared, AFAICT
NetApex
ahh ok, so no variable needed to pass it, just call it right there
Mark M.
Yup
NetApex
that is cool
NetApex
ok declaring tags is my last bit I think
NetApex
I wouldn't even need to setTag(R.raw.a) I could just use (a) right?
Mark M.
No, you need R.raw.a
Mark M.
There is no a
Mark M.
R.raw.a is an integer identifier of the raw resource
NetApex
got it
Jan 8
9:55 AM
NetApex
so example... button0.setTag(R.raw.a); yay?!
Mark M.
That should work. setTag() takes an Object, but Java "autoboxing" will convert the int into an Integer for you.
NetApex
is there a better way of doing it?
NetApex
A more professional way I should say
Mark M.
No, that's just fine
NetApex
ok
NetApex
If I ever end up making something very cool you are being added in the credits :)
Mark M.
Thanks!
Mark M.
Happy to help!
NetApex
I love learning this stuff
NetApex
Next time I will have some XML parsing questions for my next app idea :)
Mark M.
Well, that's about it for today's chat session.
NetApex
Thanks once again!
Mark M.
I have two scheduled for next week (Monday evening and Thursday morning, US Eastern time)
Mark M.
Have a delightful day!
NetApex
you too
Jan 8
10:00 AM
NetApex
See ya Riley!
NetApex
has left the room
riley
has left the room
Mark M.
turned off guest access

Monday, December 21, 2009

 

Office Hours

People in this transcript

  • Mark Murphy
  • NetApex
  • riley

Files in this transcript