Android Open Source - egotrip Image Handler






From Project

Back to project page egotrip.

License

The source code is released under:

Apache License

If you think the Android project egotrip listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.myegotrip.egotrip.image;
//w w w  .j av a 2s  . c o m
import java.io.FileNotFoundException;
import java.io.IOException;

import net.myegotrip.egotrip.TaskDoneListener;
import net.myegotrip.egotrip.map.Placemark;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.Toast;

public class ImageHandler {

  private static final int CAMERA_REQUEST = 1888; 
  private static final int SELECT_IMAGE_REQUEST = 1889;

  private Activity act;  
  private Placemark place;
  private TaskDoneListener taskDoneListener;
  public ImageHandler(Activity act, TaskDoneListener taskDoneListener) {
    this.act = act;
    this.taskDoneListener = taskDoneListener;
    
  }
  
  DialogInterface.OnClickListener cameraOrStoredListener = new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
          switch (which){
          case DialogInterface.BUTTON_POSITIVE:
            
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
              act.startActivityForResult(cameraIntent, CAMERA_REQUEST);     
              break;

          case DialogInterface.BUTTON_NEGATIVE:
              act.startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE_REQUEST);          
              break;
          }
      }
  };

  public void addImageToLocation(Placemark place) {
    // ask for image or camera
    this.place = place;
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
    builder.setMessage("Would you like to attach an image from the camera or a stored image?").setPositiveButton("Camera", cameraOrStoredListener)
        .setNegativeButton("Pick image", cameraOrStoredListener).show();
    
  }
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Bitmap bitmap = null;
        if (requestCode == CAMERA_REQUEST) {  
          Toast.makeText(act, "Attaching image to " + place.getTitle(), Toast.LENGTH_SHORT);
            bitmap= (Bitmap) data.getExtras().get("data");            
        }  
        else if (requestCode == SELECT_IMAGE_REQUEST) {  
          Toast.makeText(act, "currentPlacemark image to " + place.getTitle(), Toast.LENGTH_SHORT);
          Uri imageUri = data.getData(); 
            
      try {
        bitmap = android.provider.MediaStore.Images.Media.getBitmap(act.getContentResolver(), imageUri);
      } catch (FileNotFoundException e) {
        Toast.makeText(act, "Could not load image "+imageUri, Toast.LENGTH_SHORT);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        Toast.makeText(act, "Problem reading image " +imageUri, Toast.LENGTH_SHORT);
      }
            if (bitmap != null) {
              //uploader.uploadImage(bitmap);
              place.setBitMap(bitmap);
              Toast.makeText(act, "Attached image to  " +place.getTitle(), Toast.LENGTH_SHORT);
              taskDoneListener.taskDone(bitmap);
            }
        } 
    } 

}




Java Source Code List

net.myegotrip.egotrip.CommonGPSServiceFunctions.java
net.myegotrip.egotrip.ControlHandler.java
net.myegotrip.egotrip.ControlWindow.java
net.myegotrip.egotrip.DbListener.java
net.myegotrip.egotrip.DbTools.java
net.myegotrip.egotrip.DownloadProgressHandler.java
net.myegotrip.egotrip.FallbackDefaults.java
net.myegotrip.egotrip.GPSService.java
net.myegotrip.egotrip.Installation.java
net.myegotrip.egotrip.LocationUpdate.java
net.myegotrip.egotrip.MapViewActivity.java
net.myegotrip.egotrip.PrefActivity.java
net.myegotrip.egotrip.ReleaseConfig.java
net.myegotrip.egotrip.StartupActivity.java
net.myegotrip.egotrip.TaskDoneListener.java
net.myegotrip.egotrip.Tools.java
net.myegotrip.egotrip.TripManager.java
net.myegotrip.egotrip.help.HelpActivity.java
net.myegotrip.egotrip.help.TopicActivity.java
net.myegotrip.egotrip.image.ImageHandler.java
net.myegotrip.egotrip.map.MockLocationProvider.java
net.myegotrip.egotrip.map.PlacemarkOverlay.java
net.myegotrip.egotrip.map.Placemark.java
net.myegotrip.egotrip.map.RouteOverlay.java
net.myegotrip.egotrip.map.RoutePoint.java
net.myegotrip.egotrip.map.Trip.java
net.myegotrip.egotrip.metadata.EgotripMetadata.java
net.myegotrip.egotrip.metadata.GenericMetadata.java
net.myegotrip.egotrip.metadata.Icon.java
net.myegotrip.egotrip.metadata.Image.java
net.myegotrip.egotrip.metadata.MetadataManager.java
net.myegotrip.egotrip.metadata.Text.java
net.myegotrip.egotrip.net.BetaUpdateManager.java
net.myegotrip.egotrip.net.ProtocolConstants.java
net.myegotrip.egotrip.net.ServerReply.java
net.myegotrip.egotrip.net.Uploader.java
net.myegotrip.egotrip.profile.ProfileActivity.java
net.myegotrip.egotrip.profile.ProfilePrefActivity.java
net.myegotrip.egotrip.profile.ProfileView.java
net.myegotrip.egotrip.utils.DebugActivity.java
net.myegotrip.egotrip.utils.Debug.java
net.myegotrip.egotrip.utils.GuiUtils.java
net.myegotrip.egotrip.utils.IconItem.java
net.myegotrip.egotrip.utils.TwoDScrollView.java
net.myegotrip.egotrip.utils.XYScaleGestureDetector.java