Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 7 | 7:40 PM |
EGHDK | has entered the room |
Mark M. |
hello, EGHDK!
|
Mark M. |
how can I help you today?
|
EGHDK |
I'm trying to make a "drawing" application that can draw on the screen/picture.
|
EGHDK |
SO I've found sample code online to do this.
|
EGHDK |
And it works well.
|
EGHDK |
Drawing on a canvas and such.
|
EGHDK |
Something else I want to do is add images on top of that image. Almost like a stamp. Or "stickers" as some new apps are calling it.
|
EGHDK |
That is where I get stuck.
|
EGHDK |
I can add the image to the layout, but I need to be able to scale the image.
|
EGHDK |
But I think I'm doing it the wrong way, because If I try to draw after that... its extremely laggy.
|
EGHDK |
How would you go about making a project like that?
|
Mark M. |
I have absolutely no idea
|
Apr 7 | 7:45 PM |
EGHDK |
Would you add the image as an ImageView or?
|
Mark M. |
well, if you are drawing on the Canvas for the lines/whatever, you may as well draw the image on the Canvas as well
|
Mark M. |
but I haven't done anything like this, ever
|
Mark M. |
and so I have near-zero relevant experience
|
EGHDK |
Alright I figured I'd ask.
|
EGHDK |
Heh. Let me check my list to see if I have any more questions.
|
EGHDK |
oh. Random question. Buying a new laptop for development. Do you have any preference with an OS?
|
EGHDK |
Or hardware for Android development?
|
Mark M. |
well, I've been using Linux for a decade
|
Mark M. |
but that's a bit of an acquired taste
|
Mark M. |
so to speak
|
Apr 7 | 7:50 PM |
EGHDK |
Which flavor if you don't mind me asking. I'm guessing Ubuntu. But I'm getting tired of windows and its adb drivers for every device.
|
Mark M. |
yes, I am using Ubuntu
|
EGHDK |
Do you use a desktop or laptop? System 76 makes ubuntu laptops that look kinda nice, but I'm trying to get a feel. Maybe macbook
|
Mark M. |
laptop
|
Mark M. |
mostly because I travel
|
EGHDK |
Do you use a macbook with linux? like linus torvalds? hah
|
Mark M. |
no
|
Mark M. |
Dell XPS 15
|
EGHDK |
Gotcha. Those look pretty nice.
|
Mark M. |
it you have another question, go right ahead
|
Apr 7 | 7:55 PM |
EGHDK |
Alright. Back to Android. I'm having a bit of trouble when wanting to create my own "OnSomethingListener". How would I create one of those. I know it's an interface, but again I've never done it before.
|
Mark M. |
um
|
Mark M. |
you do it more or less the same way you write a class
|
Mark M. |
just replace "class" with "interface"
|
Mark M. |
and don't provide method bodies, just the signatures
|
Mark M. | |
EGHDK |
And I do "implements MyCustomInterface" on both my activity and my custom class?
|
Mark M. |
you add the implements keyword wherever you want to implement the interface
|
Mark M. |
whether that is your activity, your "custom class", both, or neither, I can't say
|
EGHDK |
Well I have a custom class that does this audio playback.
|
Apr 7 | 8:00 PM |
Mark M. |
OK
|
EGHDK |
View paste
|
EGHDK |
That's my end goal.
|
Mark M. |
OK
|
EGHDK |
So I have the playing done.
|
EGHDK |
And I know when the playing completes.
|
Mark M. |
your custom class then is *holding* an instance of some object that *implements* the interface
|
EGHDK |
but only in the audio class.
|
Mark M. |
the custom class is not implementing the interface itself, most likely
|
EGHDK |
Nope. Not implementing. Just "triggering"
|
Mark M. |
sorry, I was going back to your "do "implements MyCustomInterface" on both my activity and my custom class?"
|
Mark M. |
the answer is "no" for the custom class, as that is not an implementation of the interface, but a user of objects that implement the interface
|
EGHDK |
Gotcha.
|
Apr 7 | 8:05 PM |
EGHDK |
Alright, my next question is on implementing tabs in Android. I recently implemented and it was easy to make the different "tabs" load a different layout when a tab is clicked.
|
EGHDK |
That was super easy.
|
EGHDK |
Next I want to figure out how to have two tabs, but so that you can "slide" between the two.
|
EGHDK |
I feel like this is super hard.
|
EGHDK |
Because there seems to be a lot of different ways to do it.
|
Mark M. |
ViewPager and a PagerTabStrip
|
EGHDK |
Then recently google dev bytes came out with a video on how to do it like last week.
|
Mark M. |
or, ViewPager and TabPagerIndicator (the latter from the ViewPagerIndicator library)
|
EGHDK |
But they use a custom view.
|
Mark M. |
only because they wanted to do fancy stuff with changing the color of the selected-tab indicator bar
|
Mark M. |
and that was perhaps the worst DevBytes I've ever seen
|
EGHDK |
Oh.
|
EGHDK |
Hah.
|
EGHDK |
I usually like their dev bytes.
|
Mark M. |
me too
|
EGHDK |
That one... was definitely interesting.
|
Mark M. |
that one was too short for the topic, IMHO
|
EGHDK |
Yeah. Okay, so ViewPager is the common factor here.
|
EGHDK |
Whats the difference between PagerTabStrip and TabPagerIndicator?
|
Mark M. |
look and feel, mostly
|
Mark M. |
they're functionally fairly equivalent
|
Mark M. |
PagerTabStrip is part of the Android Support package, just like ViewPager
|
Mark M. |
TabPagerIndicator comes from Jake Wharton's ViewPagerIndicator library
|
Apr 7 | 8:10 PM |
Mark M. |
personally, I prefer the out-of-the-box look of TabPagerIndicator, but that's just me
|
EGHDK |
Why'd he come up with a library for something thats possible out of the box?
|
Mark M. |
at the time, PagerTabStrip didn't exist
|
Mark M. |
and, the library offers other indicators beyond that one
|
EGHDK |
Gotcha.
|
EGHDK |
Interesting.
|
EGHDK |
SO google copied him?
|
Mark M. |
probably not
|
Mark M. |
they probably had their own tab solution
|
Mark M. |
and didn't roll it out to the library right away for whatever reason
|
Apr 7 | 8:20 PM |
EGHDK |
Gotcha. Sorry got held up.
|
EGHDK |
Well.. not "held up"
|
EGHDK |
You know what I mean.
|
EGHDK |
Okay, so even if I don't need like 10 tabs, I just need 2, I should just use the out of the box PagerTabStrip?
|
Mark M. |
if you want swiping, it's the simplest solution
|
EGHDK |
Just because I don't want to include any more libraries to my project at this point.
|
EGHDK |
And the view pager uses fragments to swipe across?
|
Mark M. |
that's the stock approach
|
Mark M. |
you don't have to do it that way
|
Mark M. |
the chapters in the book on ViewPager show alternatives
|
EGHDK |
Hahaha. Too many alternaatives!
|
Apr 7 | 8:25 PM |
EGHDK |
That's the thing I get confused about. There are too many ways to do the same thing, and I spend way too much time looking for the "perfect" solution.
|
Mark M. |
well, that's why reading through the relevant book material may be useful
|
Mark M. |
as you can see implementations without having to roll the code yourself
|
Mark M. |
so you can gauge which approach seems to be the best fit for what you need
|
Mark M. |
at least in this case, regarding ViewPager
|
EGHDK |
Alright. Sounds good.
|
EGHDK |
So again with images, and the drawing on top of them. I should be able to draw the image on the canvas directly?
|
Mark M. |
Canvas has a drawBitmap() method
|
Mark M. |
whether it is right for your circumstances, I cannot say
|
EGHDK |
Okay.
|
EGHDK |
And last thing about bitmaps before we're through.
|
EGHDK |
You mentioned that each pixel of a bitmap takes up 4bytes?
|
EGHDK |
And thats why bitmaps allocate so much freaking ram?
|
Apr 7 | 8:30 PM |
Mark M. |
each pixel of a standard "8888" ARGB bitmap takes 4 bytes
|
Mark M. |
they "allocate so much freaking ram" because you want a lot of pixels, apparently
|
EGHDK |
Yep.
|
EGHDK |
so an image that is 2 x 2 pixels
|
EGHDK |
is 4 pixels total
|
Mark M. |
right
|
EGHDK |
and would take up 16 bytes of ram?
|
EGHDK |
in* ram?
|
Mark M. |
right (plus a bit of Java overhead for the Bitmap object itself)
|
EGHDK |
more or less?
|
EGHDK |
great.
|
EGHDK |
Alright. Will you be registering for google i/o tomorrow morning?
|
Mark M. |
probably not
|
Mark M. |
and that's a wrap for today's chat
|
Mark M. |
next one is tomorrow, 10am US Eastern Daylight Time
|
EGHDK |
Oh man. Thought I might get to meet the infamous commonsware. Guess not. Have a good night!
|
Mark M. |
the transcript will be posted shortly to http://commonsware.com/office-hours/
|
Mark M. |
have a pleasant day!
|
EGHDK | has left the room |
Mark M. | turned off guest access |