Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package madelyntav.c4q.nyc.memeproject;


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.os.Handler;
import android.support.v4.app.NotificationCompat;
import android.widget.Button;
import android.content.Context;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
Expand All @@ -20,7 +16,9 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
Expand All @@ -32,8 +30,8 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -44,26 +42,34 @@
public class EditPhoto extends Activity implements View.OnTouchListener {


Bitmap bitmap,b;
private int delta_x, delta_y, color;
public static ImageView imageView;
private String TAG = "GallerySaving";
private NotificationManager mNotificationManager;
private Bitmap returnedBitmap;
Bitmap b;
Bitmap bitmap;
private int delta_x;
private int delta_y;
public static ImageView imageView;
private int color;
private ColorPicker colorPicker;
private Button ten, fifteen, twenty, twentyFive,vanilla;
ImageButton share;
private Button vanilla;
private Button demotivational;
private EditText editText, editText2, demoTitle, demoText;
private ImageView demoImage;
RelativeLayout memeLayout, root;
LinearLayout linearLayout2, linearLayout3;
private String TAG = "GallerySaving";
RelativeLayout memeLayout;
LinearLayout linearLayout2;
LinearLayout linearLayout3;
Button ten;
Button fifteen;
Button twenty;
Button twentyFive;
RelativeLayout root;
private boolean isVanilla = true;

public static EditPhoto getInstance() {
return instance;
}

static EditPhoto instance;
private NotificationManager mNotificationManager;
private Bitmap returnedBitmap;
ImageButton share;


@Override
Expand Down Expand Up @@ -112,34 +118,49 @@ protected void onCreate(Bundle savedInstanceState) {
//----------------------------GET IMAGE FROM PREVIOUS INTENT--------------------------//

//opens pic in this activity
if (getIntent().hasExtra("byteArray")) {

b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0, getIntent().getByteArrayExtra("byteArray").length);
if(true){
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

// String filePath=storageDir+"/"+MainActivity.FILE_NAME;

BitmapFactory.Options options = new BitmapFactory.Options();
b = BitmapFactory.decodeFile(MainActivity.actualFile,options);
// b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0, getIntent().getByteArrayExtra("byteArray").length);
imageView = (ImageView) findViewById(R.id.mImageView);
vanilla = (Button) findViewById(R.id.vanilla);
editText = (EditText) findViewById(R.id.editText);
editText2 = (EditText) findViewById(R.id.editText2);
demoTitle = (EditText) findViewById(R.id.demotivationalTitle);
demoText = (EditText) findViewById(R.id.demotivationalText);
imageView.setImageBitmap(b);
demoImage.setImageBitmap(b);
// Log.d("b height: "+ b.getHeight()," width: "+b.getWidth());



bitmap = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0, getIntent().getByteArrayExtra("byteArray").length);
}
//Gets drawable resource from the intent
else if (getIntent().hasExtra("drawable")) {
int drawableID = getIntent().getExtras().getInt("drawable");
bitmap = BitmapFactory.decodeResource(getResources(), drawableID);

} else {

//retrieve passed uri
Uri uri = getIntent().getExtras().getParcelable("image");
//retrieve bitmap uri from intent
try {
bitmap = Bitmap.createBitmap(MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri));
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);

} catch (IOException e) {
e.printStackTrace();
}
//create bitmap for use within activity
try {
bitmap = Bitmap.createBitmap(MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri));
} catch (IOException e) {
e.printStackTrace();
}
imageView.setImageBitmap(bitmap);
demoImage.setImageBitmap(bitmap);
Log.d(TAG,"bitmap height: "+ bitmap.getHeight()+" width: "+bitmap.getWidth());
}



//-----------------------------SHARE BUTTON ONCLICKLISTENER---------------------------//

// Shares image via Email, Text, Bluetooth, etc...
Expand Down Expand Up @@ -189,8 +210,8 @@ public void onClick(View v) {


//Sets imageviews to the bitmaps once it receives it from the intent
imageView.setImageBitmap(bitmap);
demoImage.setImageBitmap(bitmap);
imageView.setImageBitmap(b);
demoImage.setImageBitmap(b);

instance = this;

Expand Down Expand Up @@ -488,11 +509,11 @@ public void engravedImage(View view) {
public void run() {
if (getIntent().hasExtra("byteArray")) {

Bitmap engraved = ApplyFilters.engrave(bitmap);
Bitmap engraved = ApplyFilters.engrave(b);
imageView.setImageBitmap(engraved);
demoImage.setImageBitmap(engraved);
} else {
Bitmap engraved = ApplyFilters.engrave(bitmap);
Bitmap engraved = ApplyFilters.engrave(b);
imageView.setImageBitmap(engraved);
demoImage.setImageBitmap(engraved);
}
Expand All @@ -510,11 +531,11 @@ public void invertColors(View view) {
@Override
public void run() {
if (getIntent().hasExtra("byteArray")) {
Bitmap inverted = ApplyFilters.doInvert(bitmap);
Bitmap inverted = ApplyFilters.doInvert(b);
imageView.setImageBitmap(inverted);
demoImage.setImageBitmap(inverted);
} else {
Bitmap inverted = ApplyFilters.doInvert(bitmap);
Bitmap inverted = ApplyFilters.doInvert(b);
imageView.setImageBitmap(inverted);
demoImage.setImageBitmap(inverted);
}
Expand All @@ -532,11 +553,11 @@ public void greyscaleImage(View view) {
@Override
public void run() {
if (getIntent().hasExtra("byteArray")) {
Bitmap greyscaled = ApplyFilters.doGreyscale(bitmap);
Bitmap greyscaled = ApplyFilters.doGreyscale(b);
imageView.setImageBitmap(greyscaled);
demoImage.setImageBitmap(greyscaled);
} else {
Bitmap greyscaled = ApplyFilters.doGreyscale(bitmap);
Bitmap greyscaled = ApplyFilters.doGreyscale(b);
imageView.setImageBitmap(greyscaled);
demoImage.setImageBitmap(greyscaled);
}
Expand All @@ -549,11 +570,11 @@ public void run() {
// Applies blue shading effect to image
public void shadingFilterBlue(View view) {
if (getIntent().hasExtra("byteArray")) {
Bitmap blueShade = ApplyFilters.applyShadingFilter(bitmap, Color.BLUE);
Bitmap blueShade = ApplyFilters.applyShadingFilter(b, Color.BLUE);
imageView.setImageBitmap(blueShade);
demoImage.setImageBitmap(blueShade);
} else {
Bitmap blueShade = ApplyFilters.applyShadingFilter(bitmap, Color.BLUE);
Bitmap blueShade = ApplyFilters.applyShadingFilter(b, Color.BLUE);
imageView.setImageBitmap(blueShade);
demoImage.setImageBitmap(blueShade);
}
Expand All @@ -563,11 +584,11 @@ public void shadingFilterBlue(View view) {
// Applies red shading effect to image
public void shadingFilterRed(View view) {
if (getIntent().hasExtra("byteArray")) {
Bitmap redShade = ApplyFilters.applyShadingFilter(bitmap, Color.RED);
Bitmap redShade = ApplyFilters.applyShadingFilter(b, Color.RED);
imageView.setImageBitmap(redShade);
demoImage.setImageBitmap(redShade);
} else {
Bitmap redShade = ApplyFilters.applyShadingFilter(bitmap, Color.RED);
Bitmap redShade = ApplyFilters.applyShadingFilter(b, Color.RED);
imageView.setImageBitmap(redShade);
demoImage.setImageBitmap(redShade);
}
Expand All @@ -577,11 +598,11 @@ public void shadingFilterRed(View view) {
// Applies green shading effect to image
public void shadingFilterGreen(View view) {
if (getIntent().hasExtra("byteArray")) {
Bitmap greenShade = ApplyFilters.applyShadingFilter(bitmap, Color.GREEN);
Bitmap greenShade = ApplyFilters.applyShadingFilter(b, Color.GREEN);
imageView.setImageBitmap(greenShade);
demoImage.setImageBitmap(greenShade);
} else {
Bitmap greenShade = ApplyFilters.applyShadingFilter(bitmap, Color.GREEN);
Bitmap greenShade = ApplyFilters.applyShadingFilter(b, Color.GREEN);
imageView.setImageBitmap(greenShade);
demoImage.setImageBitmap(greenShade);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package madelyntav.c4q.nyc.memeproject;
import android.content.ContentResolver;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;

import java.io.File;
import java.io.IOException;


Expand All @@ -19,6 +20,10 @@ public class MainActivity extends ActionBarActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
static final int EXTERNAL_CONTENT_URI = 0;

public static final String FILE_NAME = "photo_file";
public static String actualFile = null;
private static final int REQUEST_TAKE_PHOTO = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -43,11 +48,40 @@ public void usePic(View v) {

public void takePic(View v) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
// Create the File where the photo should go
File photoFile = null;
try {
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

photoFile = File.createTempFile(FILE_NAME, ".jpg", storageDir);

actualFile=photoFile.getCanonicalPath();

Log.i("||||| wrote to file: ", photoFile.getCanonicalPath());


} catch (IOException ex) {
// Error occurred while creating the File
// Log.e("failed to create " + FILE_NAME + " because ");
}

// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}

// startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);


}
}


public void chooseMeme(View view){
Intent popularMemeIntent = new Intent(this, MemeList.class);
startActivity(popularMemeIntent);
Expand All @@ -58,40 +92,44 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

Intent intent = new Intent(MainActivity.this, EditPhoto.class);

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bs);
intent.putExtra("byteArray", bs.toByteArray());
startActivity(intent);


} else if (requestCode == EXTERNAL_CONTENT_URI && resultCode == RESULT_OK) {
//Image selected message
Toast.makeText(this, "Please select VANILLA or DEMO layout to begin", Toast.LENGTH_SHORT).show();
// if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
// Bundle extras = data.getExtras();
// Bitmap imageBitmap = (Bitmap) extras.get("data");
// Log.i("||||| image bitmap height: " + imageBitmap.getHeight(), " width: " + imageBitmap.getWidth());
// ByteArrayOutputStream bs = new ByteArrayOutputStream();
//
// //imageBitmap.compress(Bitmap.CompressFormat.JPEG, 80, bs);
// imageBitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
// intent.putExtra("byteArray", bs.toByteArray());
// startActivity(intent);
//
//
// } else if (requestCode == EXTERNAL_CONTENT_URI && resultCode == RESULT_OK) {
// //Image selected message


// TODO: causing small photo error?!
// get Uri from selected image
Uri targetUri = data.getData();
Bitmap bitmap = null;
ContentResolver cr = getContentResolver();

// TODO: is this code used??
ByteArrayOutputStream bs = new ByteArrayOutputStream();

//turn selected image into a Bitmap image
try {
bitmap = MediaStore.Images.Media.getBitmap(cr, targetUri);
} catch (IOException e) {
e.printStackTrace();
}
//pass image to intent
intent.putExtra("image", targetUri);
startActivity(intent);
Toast.makeText(this, "Image selected", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Please select VANILLA or DEMO layout to begin", Toast.LENGTH_SHORT).show();
//
//
//
// // get Uri from selected image
// Uri targetUri = data.getData();
// Bitmap bitmap = null;
// ContentResolver cr = getContentResolver();
// ByteArrayOutputStream bs = new ByteArrayOutputStream();
//
// //turn selected image into a Bitmap image
// try {
// bitmap = MediaStore.Images.Media.getBitmap(cr, targetUri);
// } catch (IOException e) {
// e.printStackTrace();
// }

//pass image to intent
//intent.putExtra("image", targetUri);
startActivity(intent);

}
}

}
}
6 changes: 6 additions & 0 deletions sort/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
Loading