Office Hours — Today, April 7

Thursday, March 27

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!
how can I help you today?
EGHDK
I'm trying to make a "drawing" application that can draw on the screen/picture.
SO I've found sample code online to do this.
And it works well.
Drawing on a canvas and such.
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.
That is where I get stuck.
I can add the image to the layout, but I need to be able to scale the image.
But I think I'm doing it the wrong way, because If I try to draw after that... its extremely laggy.
How would you go about making a project like that?
Mark M.
I have absolutely no idea
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
but I haven't done anything like this, ever
and so I have near-zero relevant experience
EGHDK
Alright I figured I'd ask.
Heh. Let me check my list to see if I have any more questions.
oh. Random question. Buying a new laptop for development. Do you have any preference with an OS?
Or hardware for Android development?
Mark M.
well, I've been using Linux for a decade
but that's a bit of an acquired taste
so to speak
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
mostly because I travel
EGHDK
Do you use a macbook with linux? like linus torvalds? hah
Mark M.
no
Dell XPS 15
EGHDK
Gotcha. Those look pretty nice.
Mark M.
it you have another question, go right ahead
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
you do it more or less the same way you write a class
just replace "class" with "interface"
and don't provide method bodies, just the signatures
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
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.
8:00 PM
Mark M.
OK
EGHDK
View paste
MyAudioPlayback audio = MyAudioPlayback(audiofile);
audio.play();
audio.setComplettionListener();
That's my end goal.
Mark M.
OK
EGHDK
So I have the playing done.
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?"
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.
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.
That was super easy.
Next I want to figure out how to have two tabs, but so that you can "slide" between the two.
I feel like this is super hard.
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
and that was perhaps the worst DevBytes I've ever seen
EGHDK
Oh.
Hah.
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.
Whats the difference between PagerTabStrip and TabPagerIndicator?
Mark M.
look and feel, mostly
they're functionally fairly equivalent
PagerTabStrip is part of the Android Support package, just like ViewPager
TabPagerIndicator comes from Jake Wharton's ViewPagerIndicator library
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
and, the library offers other indicators beyond that one
EGHDK
Gotcha.
Interesting.
SO google copied him?
Mark M.
probably not
they probably had their own tab solution
and didn't roll it out to the library right away for whatever reason
8:20 PM
EGHDK
Gotcha. Sorry got held up.
Well.. not "held up"
You know what I mean.
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.
And the view pager uses fragments to swipe across?
Mark M.
that's the stock approach
you don't have to do it that way
the chapters in the book on ViewPager show alternatives
EGHDK
Hahaha. Too many alternaatives!
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
as you can see implementations without having to roll the code yourself
so you can gauge which approach seems to be the best fit for what you need
at least in this case, regarding ViewPager
EGHDK
Alright. Sounds good.
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
whether it is right for your circumstances, I cannot say
EGHDK
Okay.
And last thing about bitmaps before we're through.
You mentioned that each pixel of a bitmap takes up 4bytes?
And thats why bitmaps allocate so much freaking ram?
8:30 PM
Mark M.
each pixel of a standard "8888" ARGB bitmap takes 4 bytes
they "allocate so much freaking ram" because you want a lot of pixels, apparently
EGHDK
Yep.
so an image that is 2 x 2 pixels
is 4 pixels total
Mark M.
right
EGHDK
and would take up 16 bytes of ram?
in* ram?
Mark M.
right (plus a bit of Java overhead for the Bitmap object itself)
EGHDK
more or less?
great.
Alright. Will you be registering for google i/o tomorrow morning?
Mark M.
probably not
and that's a wrap for today's chat
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/
have a pleasant day!
EGHDK
has left the room
Mark M.
turned off guest access

Thursday, March 27

 

Office Hours

People in this transcript

  • EGHDK
  • Mark Murphy