Android Open Source - android-002 Selfie Detail Activity






From Project

Back to project page android-002.

License

The source code is released under:

Apache License

If you think the Android project android-002 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 com.michaelfitzmaurice.dailyselfie;
//  ww  w .  j a  va  2  s. c  o  m
import static com.michaelfitzmaurice.dailyselfie.SelfieListActivity.LOG_TAG;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

public class SelfieDetailActivity extends Activity {
  
  public static final String IMAGE_FILE_URI = "image-file-uri";  
  
  private File imageFile;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.selfie_detail_view);
    Intent intent = getIntent();
    if (intent != null) {
      Bundle data = intent.getExtras();
      if (data != null) {
        imageFile = (File) data.get(IMAGE_FILE_URI);
        Log.d(LOG_TAG, "Showing detail for image at " + imageFile);
      }
    }
    
    ImageView imageView = (ImageView) findViewById(R.id.selfie_detail);
    int viewWidth = Math.max(imageView.getWidth(), 300);
    int viewHeight = Math.max(imageView.getHeight(), 300);
    Log.d(LOG_TAG, "Scaling image to width and height " 
            + viewWidth + ", " + viewHeight);
    Bitmap image = getScaledBitMap(imageFile, viewWidth, viewHeight );
    imageView.setImageBitmap(image);
    setTitle( imageFile.getName() );
  }
  
  private Bitmap getScaledBitMap(File imageFile, 
                  int targetWidth, 
                  int targetHeight) {

      // Get the dimensions of the original bitmap
      BitmapFactory.Options bmOptions = new BitmapFactory.Options();
      bmOptions.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(imageFile.getAbsolutePath(), bmOptions);
      int photoWidth = bmOptions.outWidth;
      int photoHeight = bmOptions.outHeight;
      
      Log.d(LOG_TAG, "Scaling image from " + imageFile 
              + " down from original width " 
              + photoWidth + " and height " + photoHeight);

      // Determine how much to scale down the image
      int scaleFactor = 
        Math.min(photoWidth/targetWidth, photoHeight/targetHeight);

      // Decode the image file into a Bitmap sized to fill the View
      bmOptions.inJustDecodeBounds = false;
      bmOptions.inSampleSize = scaleFactor;
      bmOptions.inPurgeable = true;

      return BitmapFactory.decodeFile(imageFile.getAbsolutePath(), 
                      bmOptions);
  }
}




Java Source Code List

com.michaelfitzmaurice.android.modernart.MainActivity.java
com.michaelfitzmaurice.dailyselfie.AlarmReceiver.java
com.michaelfitzmaurice.dailyselfie.AlarmTimeInterval.java
com.michaelfitzmaurice.dailyselfie.Alarms.java
com.michaelfitzmaurice.dailyselfie.SelfieDetailActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListActivity.java
com.michaelfitzmaurice.dailyselfie.SelfieListViewAdapter.java
com.michaelfitzmaurice.dailyselfie.SelfieRecord.java
com.michaelfitzmaurice.dailyselfie.settings.ReminderIntervalDialogPreference.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsActivity.java
com.michaelfitzmaurice.dailyselfie.settings.SettingsFragment.java
course.labs.contentproviderlab.MockLocationProvider.java
course.labs.contentproviderlab.PlaceDownloaderTask.java
course.labs.contentproviderlab.PlaceRecord.java
course.labs.contentproviderlab.PlaceViewActivity.java
course.labs.contentproviderlab.PlaceViewAdapter.java
course.labs.contentproviderlab.provider.PlaceBadgeContentProvider.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.contentproviderlab.provider.PlaceBadgesContract.java
course.labs.graphicslab.BubbleActivity.java
course.labs.locationlab.MockLocationProvider.java
course.labs.locationlab.PlaceDownloaderTask.java
course.labs.locationlab.PlaceRecord.java
course.labs.locationlab.PlaceViewActivity.java
course.labs.locationlab.PlaceViewAdapter.java
course.labs.notificationslab.DownloaderTask.java
course.labs.notificationslab.FeedFragment.java
course.labs.notificationslab.FriendsFragment.java
course.labs.notificationslab.MainActivity.java
course.labs.notificationslab.SelectionListener.java
course.labs.notificationslab.TestFrontEndActivity.java