| Jul 24 |  3:50 PM  | 
| Mark M. | has entered the room  | 
| Mark M. | turned on guest access  | 
| Jul 24 |  3:55 PM  | 
| EGHDK | has entered the room  | 
| Mark M. | 
     hello, EGHDK 
    
  
   | 
| Mark M. | 
     how can I help you today? 
    
  
   | 
| Jul 24 |  4:05 PM  | 
| Carlos | has entered the room  | 
| EGHDK | 
     I have a bitmap that I'm scaling, but after like 200 x 200 it doesn't get any bigger 
    
  
   | 
| Mark M. | 
     hello, Carlos 
    
  
   | 
| Mark M. | 
     and how did you determine this? 
    
  
   | 
| Mark M. | 
     (Carlos, I will take a question from you shortly!) 
    
  
   | 
| Carlos | 
     np 
    
  
   | 
| EGHDK | 
     If I set it to 50 x 50, it get's small. When you set it 200 x 200 it gets bigger. But 500 x 500 it stays the same 200 x 200 size 
    
  
   | 
| Mark M. | 
     and how are you measuring the size? 
    
  
   | 
| EGHDK | 
     I'm doing it programatically for now. 
    
  
   | 
| Mark M. | 
     is this size of the Bitmap? size of the ImageView? size of something else? 
    
  
   | 
| EGHDK | 
     I'm setting the size of the bitmap, through scaling. 
    
  
   | 
| Jul 24 |  4:10 PM  | 
| Mark M. | 
     I repeat: is this size of the Bitmap? size of the ImageView? size of something else? 
    
  
   | 
| EGHDK | 
     Size of the bitmap. 
    
  
   | 
| EGHDK | 
     I'm not setting the size of the imageView specifically. 
    
  
   | 
| Mark M. | 
     and you are determining this size via getHeight() and getWidth()? 
    
  
   | 
| EGHDK | 
     The only thing I'm doing with the size is createScaledBitmap 
    
  
   | 
| EGHDK | 
     and then I'm doing imageView.setBitmap. 
    
  
   | 
| Mark M. | 
     earlier in this chat, you wrote: "But 500 x 500 it stays the same 200 x 200 size" 
    
  
   | 
| Mark M. | 
     this implies that you called some methods on some object that returned a pair of 200's 
    
  
   | 
| Mark M. | 
     what was the object, and what were the methods? 
    
  
   | 
| EGHDK | 
     When I do createScaledBitmap( 50, 50) I get a tiny
 image. Then I try it with 200 x 200 and I get a bigger image. When I 
try it with 500 x 500 I'm not getting anything bigger. 
    
  
   | 
| Jul 24 |  4:15 PM  | 
| EGHDK | 
     Anything between 200 - 500 seems to stay at the 200 size. 
    
  
   | 
| Mark M. | 
     I am not a mind reader 
    
  
   | 
| Mark M. | 
     please spend some time collecting your thoughts 
    
  
   | 
| Mark M. | 
     I will work with Carlos for a bit, then swing back to you 
    
  
   | 
| EGHDK | 
     The exact code for the bitmap is Bitmap resize = Bitmap.createScaledBitmap(image, 50, 50, false); 
    
  
   | 
| Mark M. | 
     at that point, in order to help you, you need to be able to answer my questions 
    
  
   | 
| Carlos | 
     Mark I have an app with a ListView backed by 
sqlite database (interfaced through Application object). I want to 
implement expanded notifications (actions). What I'm trying to figure 
out is how to update the database and ListView UI at the same time 
through the npending intent that I assign to the notification action's 
pending intent. 
    
  
   | 
| Carlos | 
     I can create a new IntentService that updates the 
database, but how do I update the database simulatanously. I've read 
about ContentProviders and it seems the have a mechanism to let the UI 
know when the UI changed, but I've been resisting implementing one since
 the Application object interface has worked thus far for the app's main
 functionality. 
    
  
   | 
| Carlos | 
     edits.....in 2nd post...meant how to update UI at the same time. 
    
  
   | 
| Mark M. | 
     your service needs to do something to let the UI layer (if it exists) know that a change has occurred 
    
  
   | 
| Mark M. | 
     LocalBroadcastManager or a third-party event bus (Square's Otto, greenrobot's EventBus, etc.) would seem like likely candidates 
    
  
   | 
| Mark M. | 
     particularly for an IntentService (as that eliminates binding-related callbacks) 
    
  
   | 
| Carlos | 
     Being my first app I've been trying to do everything without 3rd party apps in order to learn the framework :) 
    
  
   | 
| Carlos | 
     However... 
    
  
   | 
| Mark M. | 
     LocalBroadcastManager is in the Android Support package from Google 
    
  
   | 
| Carlos | 
     Since IntentService won't have the context 
associated with the acitivity hosting the ListFragment I won't have 
acccess to my ArrayADapter. 
    
  
   | 
| Mark M. | 
     correct 
    
  
   | 
| Mark M. | 
     you absolutely should not have access to an ArrayAdapter in a Service 
    
  
   | 
| Jul 24 |  4:20 PM  | 
| Mark M. | 
     and so your service sends a message, to be picked up by the activity (if it exists), telling it to refresh itself 
    
  
   | 
| Carlos | 
     So you are saying that LocalBroadcastManager would let me notify the activity about database changes? 
    
  
   | 
| Carlos | 
     Got it. 
    
  
   | 
| Mark M. | 
     yes 
    
  
   | 
| Mark M. | 
     it looks a lot like regular broadcasts, except that it is all in-process 
    
  
   | 
| Carlos | 
     I'll give that a shot and report back if I have further questions. Thanks Mark! 
    
  
   | 
| Carlos | 
     That was my only question for today. 
    
  
   | 
| Mark M. | 
     there's coverage of LocalBroadcastManager in the book, though I forget exactly which chapter 
    
  
   | 
| Mark M. | 
     OK 
    
  
   | 
| Carlos | 
     cool. I'll check it out 
    
  
   | 
| Mark M. | 
     EGHDK: now, I understand how you are creating the 
scaled Bitmap, but I need to understand how you are determining the 
resulting sizes 
    
  
   | 
| Mark M. | 
     specifically the source for your "But 500 x 500 it stays the same 200 x 200 size" statement 
    
  
   | 
| Mark M. | 
     somehow, you are measuring size, and somehow, it is coming out 200 x 200 
    
  
   | 
| Mark M. | 
     what are you measuring the size of, and how *specifically* are you measuring it? 
    
  
   | 
| EGHDK | 
     Okay, I was getting my code from my other laptop. 
    
  
   | 
| EGHDK | 
     Here is a pastebin 
    
  
   | 
| EGHDK | |
| Mark M. | 
     that's how you are creating and applying the Bitmap (and I'm skeptical that you need most of that code anyway) 
    
  
   | 
| Jul 24 |  4:25 PM  | 
| EGHDK | 
     So I'm dynamically adding an a MyImageView (I 
extended imageView), and I'm just setting some attributes to it. Then I 
call addView. Again, in the bitmap scaling method is the only time I'm 
setting a height for it. 
    
  
   | 
| EGHDK | 
     The bitmap is being retrieved from the gallery, and being passed into this method 
    
  
   | 
| Mark M. | 
     somehow, you are measuring size, and somehow, it is coming out 200 x 200 
    
  
   | 
| Mark M. | 
     what are you measuring the size of, and how *specifically* are you measuring it? 
    
  
   | 
| EGHDK | 
     I am not measuring size. I am using this imageView as a thumbnail. 
    
  
   | 
| EGHDK | 
     So I don't need it to be proportional or anything. 
    
  
   | 
| Mark M. | 
     then please explain: "But 500 x 500 it stays the same 200 x 200 size" 
    
  
   | 
| Mark M. | 
     how can you know it is 200 x 200? 
    
  
   | 
| Mark M. | 
     if you are "not measuring size"? 
    
  
   | 
| EGHDK | 
     I don't know it's 200. But it seems to stay the same size 
    
  
   | 
| EGHDK | 
     Second line of the pastebin. I change those values, and run the app again. 
    
  
   | 
| EGHDK | 
     With the 50, I get a tiny image. Setting it to 
200, the image increases. Setting it beyond 200, it doesn't seem to 
increase in size at all. 
    
  
   | 
| Mark M. | 
     right now, you are claiming that the problem is with the Bitmap 
    
  
   | 
| EGHDK | 
     I don't know if I'm making any sense either. 
    
  
   | 
| Mark M. | 
     however, since you are "not measuring size", you don't really have any proof of that 
    
  
   | 
| EGHDK | 
     I'm claiming that my imageView that is being set dynamically doesn't visually appear to be increasing in size. 
    
  
   | 
| Mark M. | 
     so, whether via breakpoints or Log statements or whatever, determine the size of the Bitmap you get out of createScaledBitmap() 
    
  
   | 
| Jul 24 |  4:30 PM  | 
| EGHDK | 
     How do I get the size of a bitmap? 
    
  
   | 
| Mark M. | 
     getWidth() and getHeight() 
    
  
   | 
| EGHDK | 
     oh... 
    
  
   | 
| Mark M. | 
     my guess is that your Bitmap is fine 
    
  
   | 
| Mark M. | 
     and that the problem lies in how you are using the ImageView 
    
  
   | 
| EGHDK | 
     I'm guessing my bitmap is fine too. 
    
  
   | 
| EGHDK | 
     But I don't understand how my imageView visually does not increase when I pass it a larger bitmap 
    
  
   | 
| EGHDK | 
     But my imageView decreases in size when I pass it a large bitmap 
    
  
   | 
| EGHDK | 
     smaller bitmap* 
    
  
   | 
| Mark M. | 
     I would fire up Hierarchy View and examine the actual size of the ImageView itself 
    
  
   | 
| Mark M. | 
     I would suggest changing your flavor of addView() (I'd use the one that takes the LayoutParams as the second parameter) 
    
  
   | 
| EGHDK | 
     ? 
    
  
   | 
| Mark M. | 
     I am also skeptical about the choice of WRAP_CONTENT, as that seems to run counter to your use of setScaleType() 
    
  
   | 
| Jul 24 |  4:35 PM  | 
| EGHDK | 
     Yeah, I'm not really sure how to add it, but on stack overflow there was a question with a lot of upvotes. 
    
  
   | 
| EGHDK | 
     All I want to do is add an imageView progamatically using a bitmap. 
    
  
   | 
| Mark M. | 
     what are you adding it to? 
    
  
   | 
| Mark M. | 
     (BTW, Carlos, if you come up with another question, chime in to let me know) 
    
  
   | 
| EGHDK | 
     I'm adding it to a linear layout. Orientation horizontal. 
    
  
   | 
| EGHDK | 
     Hieght and width of the linear layout is wrap_content 
    
  
   | 
| Mark M. | 
     OK 
    
  
   | 
| Mark M. | 
     ignoring things like scaled bitmaps and whatnot, how big are these ImageViews supposed to be? 
    
  
   | 
| EGHDK | 
     I want them to be about 200dp x 200dp 
    
  
   | 
| Mark M. | 
     OK 
    
  
   | 
| Jul 24 |  4:40 PM  | 
| EGHDK | 
     setScaleType would be optional. I really don't care if the images are squished. 
    
  
   | 
| Carlos | has left the room   | 
| Mark M. | 
     then why are you not setting them to be 200dp x 200dp? 
    
  
   | 
| EGHDK | 
     Sorry, I'm just finding this to be really 
difficult. And I made it a long way since yesterday! Selecting images 
from the gallery doesn't crash anymore! 
    
  
   | 
| Mark M. | 
     for example, you could inflate a layout with android:layout_width="200dp" and android:layout_height="200dp" 
    
  
   | 
| Mark M. | 
     or do the equivalent calculations in Java) 
    
  
   | 
| Mark M. | 
     rather than using WRAP_CONTENT 
    
  
   | 
| EGHDK | 
     Oh! Because I want to be able to add these views to this layout dynamically. 
    
  
   | 
| Mark M. | 
     so? 
    
  
   | 
| EGHDK | 
     So I want to fit 2 images in the linear layout. 
    
  
   | 
| Mark M. | 
     that does not prevent you from inflating layouts to describe the contents 
    
  
   | 
| EGHDK | 
     Or 3. 
    
  
   | 
| EGHDK | 
     ? 
    
  
   | 
| EGHDK | 
     I didn't know that was possible? 
    
  
   | 
| Mark M. | 
     sure 
    
  
   | 
| Mark M. | 
     getLayoutInflater() 
    
  
   | 
| Mark M. | 
     returns a LayoutInflater 
    
  
   | 
| Mark M. | 
     can be used to inflate layout files whenever you want 
    
  
   | 
| EGHDK | 
     So instead of setting all of these attributes I could just create an xml for an imageView? 
    
  
   | 
| Mark M. | 
     if you wanted, yes 
    
  
   | 
| EGHDK | 
     ... 
    
  
   | 
| EGHDK | 
     That would be so much easier. 
    
  
   | 
| Mark M. | 
     particularly for density-related stuff, yes, it tends to be simpler 
    
  
   | 
| EGHDK | 
     Yeah, I mean I was originally gonna get device density and use an equation from Romain Guy to set the density programatically. 
    
  
   | 
| Mark M. | 
     call the three-parameter inflate() method that 
takes the R.layout.whatever_you_want for the ImageView layout, the 
LinearLayout as the container to pour it into, and probably true for the
 third parameter 
    
  
   | 
| Jul 24 |  4:45 PM  | 
| Mark M. | 
     the only thing tricky with how you're doing it is then getting your hands on that specific ImageView to fill in the image 
    
  
   | 
| Mark M. | 
     as they will all have the same android:id value 
    
  
   | 
| Mark M. | 
     you need to make sure that you use the View that is returned by inflate() 
    
  
   | 
| Mark M. | 
     if that View is the ImageView itself, just cast it 
    
  
   | 
| EGHDK | 
     Is there a chapter in your book about it? 
    
  
   | 
| Mark M. | 
     if that View is something that contains the 
ImageView, call findViewById() on the View, not the activity, to find 
the specific ImageView you just inflated 
    
  
   | 
| Mark M. | 
     layout inflation is covered in various spots, 
though usually in the context of something else (fragments, advanced 
ListViews, etc.) 
    
  
   | 
| EGHDK | 
     Because I sort of understand you. I've never used inflate(). 
    
  
   | 
| EGHDK | 
     So I would do image.inflate(3 parameters)? 
    
  
   | 
| Mark M. | 
     no, you would do getLayoutInflater().inflate(...) 
    
  
   | 
| EGHDK | 
     Basically what object do I call inflate on 
    
  
   | 
| Mark M. | 
     where getLayoutInflater() is a method on Activity 
    
  
   | 
| Mark M. | 
     you do not have an ImageView up front -- that will be created for you by the inflation process 
    
  
   | 
| Mark M. | 
     you call inflate() on a LayoutInflater 
    
  
   | 
| Mark M. | 
     you get a LayoutInflater usually by calling getLayoutInflater() on your Activity 
    
  
   | 
| EGHDK | 
     But in this case I will just do getLayoutInflater().inflate(3 params)? 
    
  
   | 
| Mark M. | 
     assuming that you are in your activity, yes 
    
  
   | 
| EGHDK | 
     Okay, next question. 
    
  
   | 
| EGHDK | 
     I'm doing Bitmap.createScaledBitmap() but is there an easier way to make sure I don't distort the image? 
    
  
   | 
| EGHDK | 
     like createScaledRatioBitmap or something? 
    
  
   | 
| Mark M. | 
     I'm not even sure why you're bothering with createScaledBitmap() 
    
  
   | 
| Mark M. | 
     once you fix the size of your ImageView, your scaleType should handle the scaling 
    
  
   | 
| Mark M. | 
     and do it a <bleep>load faster than createScaledBitmap() 
    
  
   | 
| Jul 24 |  4:50 PM  | 
| EGHDK | 
     Well, wait. I have to do that or my app get OOM 
    
  
   | 
| Mark M. | 
     by definition, no, because your big image is already in memory by the time you call createScaledBitmap() 
    
  
   | 
| Mark M. | 
     if you want to create a smaller image to avoid OOM, you do that at the BitmapFactory level 
    
  
   | 
| EGHDK | 
     Oh. 
    
  
   | 
| EGHDK | 
     Okay stand by. Let me get my code from and you can let me know what route I should take. 
    
  
   | 
| Jul 24 |  4:55 PM  | 
| EGHDK | |
| EGHDK | 
     Sorry 
    
  
   | 
| Mark M. | 
     you almost always want to use a method on BitmapFactory that takes a BitmapFactory.Options as the last parameter 
    
  
   | 
| EGHDK | 
     Wrong code 
    
  
   | 
| EGHDK | |
| Mark M. | 
     hmmm... that looks the same 
    
  
   | 
| Mark M. | 
     at any rate 
    
  
   | 
| EGHDK | 
     Is this line done improperly? 
    
  
   | 
| EGHDK | |
| EGHDK | 
     Because that's where I'm actually setting it. 
    
  
   | 
| Mark M. | 
     it's not ideal, as you are not providing a BitmapFactory.Options to tell it what to do 
    
  
   | 
| EGHDK | 
     So how would I rewrite that line? 
    
  
   | 
| Mark M. | 
     add a BitmapFactory.Options instance as a second parameter 
    
  
   | 
| Mark M. | 
     where you configure values on the BitmapFactory.Options to indicate how you want the decoding to be done 
    
  
   | 
| Mark M. | 
     for example, inSampleSize is how you get it to create a smaller bitmap image for you 
    
  
   | 
| Mark M. | |
| EGHDK | 
     I added BitmapFactory.Options as a second param but it wont compile. 
    
  
   | 
| EGHDK | 
     Cannot be resolved to a bariable 
    
  
   | 
| Mark M. | 
     BitmapFactory.Options is a Java class 
    
  
   | 
| Mark M. | 
     you need to add an import statement for it 
    
  
   | 
| EGHDK | 
     That's what you meant by "add a BitmapFactory.Options instance as a second parameter" right? 
    
  
   | 
| Mark M. | 
     and you need to create an instance of that class 
    
  
   | 
| Jul 24 |  5:00 PM  | 
| Mark M. | 
     https://developer.android.com/reference/android..., android.graphics.Rect, android.graphics.BitmapFactory.Options) 
    
  
   | 
| Mark M. | 
     or http://goo.gl/U6AaU1 since that URL got munged by the chat room 
    
  
   | 
| EGHDK | 
     How do I create an "instance"? 
    
  
   | 
| Mark M. | 
     new BitmapFactory.Options() 
    
  
   | 
| EGHDK | 
     So BitmapFactory.Options factory = new BitmapFacotry.Options(); 
    
  
   | 
| Mark M. | 
     sure, other than typos 
    
  
   | 
| EGHDK | 
     Awesome. Then just use factory as my second param? 
    
  
   | 
| Mark M. | 
     after setting various values on the BitmapFactory.Options via its public fields, yes 
    
  
   | 
| EGHDK | 
     And then you just recomend inSampleSize instead of scaling? 
    
  
   | 
| Mark M. | 
     yes 
    
  
   | 
| EGHDK | 
     Awesome. 
    
  
   | 
| EGHDK | 
     I'm well on my way. 
    
  
   | 
| Mark M. | 
     let's suppose that your photo is 8MB uncompressed 
    
  
   | 
| Mark M. | 
     your current approach will take up, say, 8.8MB (8MB original, 0.8MB of the scaled version) 
    
  
   | 
| Mark M. | 
     inSampleSize lets you take up 0.8MB, as you *only* get the scaled version 
    
  
   | 
| EGHDK | 
     THATS AWESOME! 
    
  
   | 
| EGHDK | 
     Thanks Mark. I guess that's it for today. I'll be here to bother you tomorrow 
    
  
   | 
| Mark M. | 
     BTW, you may wish to read up on Picasso in my book 
    
  
   | 
| Mark M. | |
| Mark M. | 
     it would simplify a lot of this stuff 
    
  
   | 
| Mark M. | 
     while I cover it in the context of downloading image from the Internet, it should work with content:// Uri values as well 
    
  
   | 
| EGHDK | 
     Cool. 
    
  
   | 
| Jul 24 |  5:05 PM  | 
| EGHDK | 
     I might be downloading images from the net soon. 
    
  
   | 
| Mark M. | 
     anyway, that's a wrap for today's chat 
    
  
   | 
| EGHDK | 
     You think volley is a good approach? 
    
  
   | 
| Mark M. | 
     not really, as I don't like unpackaged, unsupported, undocumented blobs of code 
    
  
   | 
| EGHDK | 
     Alright. Thanks again! 
    
  
   | 
| Mark M. | 
     next chat is tomorrow 10am 
    
  
   | 
| Mark M. | 
     transcript for this chat will appear on http://commonsware.com/office-hours/ shortly 
    
  
   | 
| Mark M. | 
     have a pleasant day! 
    
  
   | 
| EGHDK | has left the room   | 
| Mark M. | turned off guest access  |