No one else has seen anything like this?  Is there a way to enter this
as a bug against the Android codebase?  I haven't actually seen the
open source part of this yet (I'd actually try and fix it if it was
out there already).



On Sep 29, 11:09 am, Joe Erickson <[EMAIL PROTECTED]> wrote:
> I'm seeing some caching problems when using anImageButtonwith a Uri
> and I'm not sure if there's a flag that needs set somewhere or not.
>
> I'm using the button to add an icon to an item in one of my
> applications, exactly like it's being used for the Contact application
> (which I don't think the source is available for).  I'm using the CROP
> trick seen in this 
> application:http://code.google.com/p/apps-for-android/source/browse/trunk/Photost...
>
> Specifically, I'm calling the image picker and then the crop like so:
>
> protected OnClickListener cmdIconListener = new OnClickListener() {
>     // @Override
>         public void onClick(View arg0) {
>             Intent i = new
> Intent("android.intent.action.GET_CONTENT");
>             i.setType("image/*");
>             startActivityForResult(i, AddTea.ADD_ICON);
>         }
>
> };
>
> protected void onActivityResult(int requestCode, int resultCode,
> Intent data){
>     // See which child activity is calling us back.
>     switch (requestCode) {
>     case AddTea.ADD_ICON:
>         // This is the standard resultCode that is sent back if the
>         // activity crashed or didn't doesn't supply an explicit
> result.
>         if (resultCode != RESULT_CANCELED){
>              Intent i = new Intent("com.android.camera.action.CROP");
>              i.setClassName("com.android.camera",
> "com.android.camera.CropImage");
>              i.setData(data.getData());
>              Log.d(TAG, "path: " + data.getData().getPath());
>              i.putExtra("noFaceDetection", true);
>              i.putExtra("outputX", iconWidth);
>              i.putExtra("outputY", iconHeight);
>              i.putExtra("aspectX", iconWidth);
>              i.putExtra("aspectY", iconHeight);
>              i.putExtra("scale", true);
>
>              if(iconUri == null){
>                  ContentValues values = new ContentValues();
>
> values.put(android.provider.MediaStore.Images.Media.TITLE, name + "
> Icon");
>
> values.put(android.provider.MediaStore.Images.Media.BUCKET_ID,
> "STeaP_Tea_Timer_Icons");
>
> values.put(android.provider.MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
> "STeaP Tea Timer Icons");
>                  iconUri =
> getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
> values).toString();
>               }
>               i.putExtra("output", Uri.parse(iconUri));
>               startActivityForResult(i, CROP_ICON);
>         }
>         break;
>     case AddTea.CROP_ICON:
>         if (resultCode != RESULT_CANCELED){
>         Log.d(TAG, "Data String: " + iconUri);
>         showIconButton(iconUri);
>     }
>     default:
>         break;
>     }
>
> }
>
> protected void showIconButton(String iconUri){
>     if(iconUri != null){
>        ImageButtoniconField = (ImageButton)
> findViewById(R.id.iconButton);
>         Log.d(TAG, "iconUri: " + iconUri);
>         iconField.setImageURI(Uri.parse(iconUri));
>         iconField.invalidate();
>     }
>
> }
>
> So if the item doesn't have an icon, set one in the ContentProvider
> and save the iconUri.  If it does, just overwrite it with the new
> cropped image.
>
> This works fine if the item never had an icon.  It shows in 
> theImageButtonwhen the Activity returns.  However, if the item already
> had an icon, my Activity still shows the old icon, even though it was
> overwritten.  It seems that if theImageButtongets the same Uri back,
> even if I wrote a new image to it, it doesn't redraw, even if I tell
> it to invalidate().  If I relaunch my Activity, the new image shows up
> just like I expected.  Funny enough, the Pictures application doesn't
> see any images I created until I restart the emulator, which also
> doesn't seem ideal!
>
> So, is there anyway to handle this caching of the Uri?  I seems like
> the ContentProvider should be doing this when I write a new image to
> it, but it doesn't seem to be.  Also, before anyone suggests, I tried
> deleteing the entry in the ContentProvider and making a new one and
> that seems to partially work.  It partilly works because, if the Uri
> we get back it new, the view does refresh with this new Uri.  However,
> if the icon was the last picture to be saved to the ContentProvider,
> say item 10, then the ContentProvider will delete item 10 and the
> reuses 10 as the next id!  So I'm back where I started and 
> theImageButtonshows the old icon.
>
> Any help in kicking the ContentProvider ofImageButtoninto shape
> would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to