diff --git a/README.md b/README.md index 9ef6675..7b9e3cc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ -Group Members: - -Pooja Pasawala: Worked on allowing the user to select an image from their gallery, and saving the meme to the camera roll once it was generated. Coordinated with the team on what needed to be done (mostly via slack), kept team updated on what everyone was working on and what features had been merged or needed to be reviewed, noted any bugs that needed to be fixed as they came up, and reviewed all pull requests. -Time Spent: 12 hours - -Anthony Fermin: Worked on allowing the user to use their camera to take a picture, generating demotivational memes, and reviewed pull requests. -Time Spent: - -Tasha Smith: Created the layout for choosing a Vanilla or Demotivational Meme and worked on generating vanilla memes. -Time Spent: 12 hours - -Jorge Reina: Created the layout for choosing camera or gallery image, created the layout for choosing save or share, and added share capability. -Time Spent: +Updates: +Added some comments, +Added save to ExternalPublicDir Method, +Refactored some of the code and +Got rid of some extra activities diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3939b4f..53d0d47 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,34 +14,35 @@ android:largeHeap="true"> + android:label="@string/app_name" + android:screenOrientation="portrait" + > + + android:label="@string/title_activity_choose_meme_style" + android:screenOrientation="portrait"> + android:label="@string/title_activity_vanilla_test" + android:screenOrientation="portrait"> - - - + android:label="@string/title_activity_demotivational_meme" + android:screenOrientation="portrait"> + android:label="@string/title_activity_splash_screen" + android:screenOrientation="portrait"> - diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/ChooseMemeStyle.java b/app/src/main/java/meme5/c4q/nyc/meme_project/ChooseMemeStyle.java index e89f9ae..e8a86ff 100644 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/ChooseMemeStyle.java +++ b/app/src/main/java/meme5/c4q/nyc/meme_project/ChooseMemeStyle.java @@ -23,13 +23,10 @@ public class ChooseMemeStyle extends Activity { - public static final String TAG = "MEME_ACTIVITY"; - protected RadioGroup styleGroup; - protected RadioButton styleButton; + Button small, medium, large; protected Button nextButton; protected boolean vanilla; - protected Random slideShow; ImageView img, thumbnail; AnimationDrawable frameAnimation; String imgFilePath; @@ -40,6 +37,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choose_meme_style); + //Get Image Chosen and place it on the thumbnail ImageView Bundle bundle = getIntent().getExtras(); if(bundle.getString("imgFilePath") != null) { @@ -50,20 +48,17 @@ protected void onCreate(Bundle savedInstanceState) { thumbnail.setImageBitmap(bmp2); //apply fonts - - //TODO: need to find a way to add this font globally through style! - TextView step1 = (TextView) findViewById(R.id.step1); - TextView step2 = (TextView) findViewById(R.id.step2); - TextView step3 = (TextView) findViewById(R.id.step3); + TextView title = (TextView) findViewById(R.id.title); - TextView vanillaRadio = (TextView) findViewById(R.id.chooseVanilla); + small=(Button) findViewById(R.id.small); + medium=(Button) findViewById(R.id.medium); + large=(Button) findViewById(R.id.large); + TextView demotivationalRadio = (TextView) findViewById(R.id.chooseDemotivational); Typeface tf = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/ubuntu.ttf"); - step1.setTypeface(tf); - step2.setTypeface(tf); - step3.setTypeface(tf); title.setTypeface(tf); - vanillaRadio.setTypeface(tf); + demotivationalRadio.setTypeface(tf); RadioGroup group = (RadioGroup) findViewById(R.id.styleGroup); @@ -72,8 +67,7 @@ protected void onCreate(Bundle savedInstanceState) { public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { Log.d(TAG, "onCheckedChanged()"); // Is the button now checked? -// boolean checked = ((RadioButton) view).isChecked(); - + //boolean checked = ((RadioButton) view).isChecked(); // Check which radio button was clicked switch (checkedId) { case R.id.chooseVanilla: @@ -105,6 +99,8 @@ public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { } }); + //Intents to go to corresponding activity + group.check(R.id.chooseDemotivational); nextButton = (Button) findViewById(R.id.nextButton); diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/DemotivationalMemeActivity.java b/app/src/main/java/meme5/c4q/nyc/meme_project/DemotivationalMemeActivity.java index 0f8ad99..fcfc173 100644 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/DemotivationalMemeActivity.java +++ b/app/src/main/java/meme5/c4q/nyc/meme_project/DemotivationalMemeActivity.java @@ -1,172 +1,153 @@ package meme5.c4q.nyc.meme_project; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; - +import android.widget.RelativeLayout; +import android.widget.Toast; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; /** * Created by c4q-anthonyf on 6/5/15. */ public class DemotivationalMemeActivity extends Activity { - Bitmap image; - Bitmap memeImage; - ImageView preview; - EditText largeText; - EditText smallText; - + ImageView image; + EditText line1; + EditText line2; + Bitmap bmp2; + String imgFilePath; + Button share; + Button save; + RelativeLayout memeLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demotivational_meme); - preview = (ImageView) findViewById(R.id.preview); - String imgFilePath = ""; + //get image path from previous activity Bundle bundle = getIntent().getExtras(); - if(bundle.getString("imgFilePath") != null) - { - imgFilePath = bundle.getString("imgFilePath"); - decodeFile(imgFilePath); - } - - largeText = (EditText) findViewById(R.id.large); - smallText = (EditText) findViewById(R.id.small); - Button previewText = (Button) findViewById(R.id.previewText); - previewText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - memeImage = drawTextToBitmap(image.copy(image.getConfig(),true),largeText.getText().toString(),true); - memeImage = drawTextToBitmap(memeImage,smallText.getText().toString(),false); - preview.setImageBitmap(memeImage); - } - }); - } - public void launchLastActivity(View view){ - - if(memeImage != null) { - try { - //Write file - String filename = "meme.png"; - FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE); - memeImage.compress(Bitmap.CompressFormat.PNG, 100, stream); - - //Cleanup - stream.close(); - memeImage.recycle(); - - //Pop intent - Intent lastActivity = new Intent(this, add_text.class); - lastActivity.putExtra("memeImage", filename); - startActivity(lastActivity); - } catch (Exception e) { - e.printStackTrace(); + try { + if (bundle.getString("imgFilePath") != null) { + imgFilePath = bundle.getString("imgFilePath"); + image = (ImageView) findViewById(R.id.image); + bmp2 = BitmapFactory.decodeFile(imgFilePath); + image.setImageBitmap(bmp2); } + } catch (NullPointerException e) { + Toast.makeText(this, "No Image Found", Toast.LENGTH_LONG).show(); } - } - private Bitmap addBorder(Bitmap bmp,int color, int borderSize) { - return addBorder(bmp, color,borderSize, borderSize, borderSize, borderSize); + save = (Button) findViewById(R.id.saveButton); + share = (Button) findViewById(R.id.shareButton); + line1 = (EditText) findViewById(R.id.title); + line2 = (EditText) findViewById(R.id.description); + image = (ImageView) findViewById(R.id.image); + memeLayout = (RelativeLayout) findViewById(R.id.memeLayout); } - private Bitmap addBorder(Bitmap bmp, int color, int left, int top, int right, int bottom){ - Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + left + right, bmp.getHeight() + top + bottom, bmp.getConfig()); - Canvas canvas = new Canvas(bmpWithBorder); - canvas.drawColor(color); - canvas.drawBitmap(bmp, left, top, null); - - return bmpWithBorder; + //Method to create a bitmap from a view, in our case from a linearLayout + public Bitmap getBitmapFromView(View view) { + Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(returnedBitmap); + + Drawable bgDrawable = view.getBackground(); + if (bgDrawable != null) + bgDrawable.draw(canvas); + else + canvas.drawColor(Color.WHITE); + view.draw(canvas); + return returnedBitmap; } - private void decodeFile(String filePath) { - - // Decode image size - BitmapFactory.Options o = new BitmapFactory.Options(); - o.inJustDecodeBounds = true; - BitmapFactory.decodeFile(filePath, o); - - // The new size we want to scale to - final int REQUIRED_SIZE = 1024; - - // Find the correct scale value. It should be the power of 2. - int width_tmp = o.outWidth, height_tmp = o.outHeight; - int scale = 1; - while (true) { - if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) - break; - width_tmp /= 2; - height_tmp /= 2; - scale *= 2; - } - - // Decode with inSampleSize - BitmapFactory.Options o2 = new BitmapFactory.Options(); - o2.inSampleSize = scale; - Bitmap b1 = BitmapFactory.decodeFile(filePath, o2); - image= ExifUtils.rotateBitmap(filePath, b1); + //Method to share the meme + public void sharingM(View view) { - image = addBorder(image, Color.BLACK, 5); - image = addBorder(image,Color.WHITE, 5); - image = addBorder(image, Color.BLACK, 100, 150, 100, 300); - preview.setImageBitmap(image); - } + bmp2 = getBitmapFromView(memeLayout); - public Bitmap drawTextToBitmap(Bitmap bitmapImage, String mText1, boolean largeText) { + Intent share = new Intent(Intent.ACTION_SEND); + share.setType("image/jpeg"); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + bmp2.compress(Bitmap.CompressFormat.JPEG, 100, bytes); + File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"); try { + f.createNewFile(); + FileOutputStream fo = new FileOutputStream(f); + fo.write(bytes.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + } + share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg")); + startActivity(Intent.createChooser(share, "Share Image")); + } - Canvas newCanvas = new Canvas(bitmapImage); - - newCanvas.drawBitmap(bitmapImage, 0, 0, null); - int textSize; - int heightOffset; - if(largeText) { - textSize = 80; - heightOffset = 30; - mText1 = mText1.toUpperCase(); - }else{ - textSize = 40; - heightOffset = 140; - } - - if(mText1 != null) { + //Method to Save the Meme into the camera roll + public void savingM(View view) { + bmp2 = getBitmapFromView(memeLayout); - Paint paintText = new Paint(Paint.ANTI_ALIAS_FLAG); - paintText.setColor(Color.WHITE); - paintText.setTextSize(textSize); - paintText.setStyle(Paint.Style.FILL); - paintText.setShadowLayer(10f, 10f, 10f, Color.BLACK); + MediaStore.Images.Media.insertImage(DemotivationalMemeActivity.this.getContentResolver(), bmp2, "title.jpg", "some description"); + Toast.makeText(this, "Meme saved!", Toast.LENGTH_LONG).show(); + } - Rect rectText = new Rect(); - paintText.getTextBounds(mText1, 0, mText1.length(), rectText); - newCanvas.drawText(mText1, - newCanvas.getWidth() /2 - rectText.width() /2, newCanvas.getHeight() - 299 + rectText.height() + heightOffset, paintText); + //Method to save meme to ExternalPublicDirectory + public void saveMemeToCacheDir(View v){ + + bmp2 = getBitmapFromView(memeLayout); + String timeStamp = new SimpleDateFormat("MMddyyyy_HHmmss").format(new Date()); + String imageName="Meme_"+timeStamp+".jpg"; + File path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); + File myFile=new File(path,imageName); + FileOutputStream fos=null; + try{ + fos=new FileOutputStream(myFile); + bmp2.compress(Bitmap.CompressFormat.JPEG, 100, fos); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Toast.makeText(this, "NO File Found",Toast.LENGTH_LONG).show(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + fos.close(); + Toast.makeText(DemotivationalMemeActivity.this,"File Saved",Toast.LENGTH_LONG).show(); + try{ + Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + Uri uri = Uri.fromFile(myFile); + mediaScanIntent.setData(uri); + sendBroadcast(mediaScanIntent); + } catch (Exception e){ + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (NullPointerException e){ + e.printStackTrace(); + Toast.makeText(this, "No File Found To Save",Toast.LENGTH_LONG).show(); } - - return bitmapImage; - } catch (Exception e) { - // TODO: handle exception - - - return null; } - } - -} + } +} \ No newline at end of file diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/ExifUtils.java b/app/src/main/java/meme5/c4q/nyc/meme_project/ExifUtils.java deleted file mode 100644 index bf5011a..0000000 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/ExifUtils.java +++ /dev/null @@ -1,115 +0,0 @@ -package meme5.c4q.nyc.meme_project; - -import android.graphics.Bitmap; -import android.graphics.Matrix; -import android.os.Build; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -public class ExifUtils { - /** - * @see http://sylvana.net/jpegcrop/exif_orientation.html - */ - public static Bitmap rotateBitmap(String src, Bitmap bitmap) { - try { - int orientation = getExifOrientation(src); - - if (orientation == 1) { - return bitmap; - } - - Matrix matrix = new Matrix(); - switch (orientation) { - case 2: - matrix.setScale(-1, 1); - break; - case 3: - matrix.setRotate(180); - break; - case 4: - matrix.setRotate(180); - matrix.postScale(-1, 1); - break; - case 5: - matrix.setRotate(90); - matrix.postScale(-1, 1); - break; - case 6: - matrix.setRotate(90); - break; - case 7: - matrix.setRotate(-90); - matrix.postScale(-1, 1); - break; - case 8: - matrix.setRotate(-90); - break; - default: - return bitmap; - } - - try { - Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0, - bitmap.getWidth(), bitmap.getHeight(), matrix, true); - bitmap.recycle(); - return oriented; - } catch (OutOfMemoryError e) { - e.printStackTrace(); - return bitmap; - } - } catch (IOException e) { - e.printStackTrace(); - } - - return bitmap; - } - - private static int getExifOrientation(String src) throws IOException { - int orientation = 1; - - try { - /** - * if your are targeting only api level >= 5 ExifInterface exif = - * new ExifInterface(src); orientation = - * exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); - */ - if (Build.VERSION.SDK_INT >= 5) { - Class exifClass = Class - .forName("android.media.ExifInterface"); - Constructor exifConstructor = exifClass - .getConstructor(new Class[]{String.class}); - Object exifInstance = exifConstructor - .newInstance(new Object[]{src}); - Method getAttributeInt = exifClass.getMethod("getAttributeInt", - new Class[]{String.class, int.class}); - Field tagOrientationField = exifClass - .getField("TAG_ORIENTATION"); - String tagOrientation = (String) tagOrientationField.get(null); - orientation = (Integer) getAttributeInt.invoke(exifInstance, - new Object[]{tagOrientation, 1}); - } - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SecurityException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - - return orientation; - } -} \ No newline at end of file diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/SplashScreen.java b/app/src/main/java/meme5/c4q/nyc/meme_project/SplashScreen.java index 3d1beab..cbb90ee 100644 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/SplashScreen.java +++ b/app/src/main/java/meme5/c4q/nyc/meme_project/SplashScreen.java @@ -2,6 +2,7 @@ /** * Created by c4q-tashasmith on 6/7/15. + * This activity will display a screen when the app is initially opened for 2.5 seconds */ import android.app.Activity; import android.content.Intent; @@ -15,8 +16,9 @@ public class SplashScreen extends Activity { + /** Duration of wait **/ - private final int SPLASH_DISPLAY_LENGTH = 2500; + private final int SPLASH_DISPLAY_LENGTH = 1000;//Time which activity will be displayed for in ms ImageView img; AnimationDrawable frameAnimation; diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/VanillaMeme.java b/app/src/main/java/meme5/c4q/nyc/meme_project/VanillaMeme.java index b3ff942..3871fd3 100644 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/VanillaMeme.java +++ b/app/src/main/java/meme5/c4q/nyc/meme_project/VanillaMeme.java @@ -10,7 +10,12 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; +import android.os.Environment; +import android.provider.ContactsContract; +import android.provider.MediaStore; import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; @@ -19,184 +24,186 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import org.w3c.dom.Text; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; public class VanillaMeme extends Activity { ImageView image; EditText line1; - Bitmap bmp, bmp2; - String line1Text; + EditText line2; + Bitmap bmp2; String imgFilePath; - Button nextButton; TextView title; - RadioButton small, medium, large; + Button share; + Button save; + RelativeLayout memeLayout; + Button small, medium, large; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_vanilla_meme); + //get image path from previous activity Bundle bundle = getIntent().getExtras(); - if (bundle.getString("imgFilePath") != null) { - imgFilePath = bundle.getString("imgFilePath"); - decodeFile(imgFilePath); + + try { + if (bundle.getString("imgFilePath") != null) { + imgFilePath = bundle.getString("imgFilePath"); + image = (ImageView) findViewById(R.id.testImage); + bmp2 = BitmapFactory.decodeFile(imgFilePath); + image.setImageBitmap(bmp2); + } + } catch (NullPointerException e) { + Toast.makeText(this, "No Image Found", Toast.LENGTH_LONG).show(); } + + save = (Button) findViewById(R.id.saveButton); + share = (Button) findViewById(R.id.shareButton); line1 = (EditText) findViewById(R.id.top); + line2 = (EditText) findViewById(R.id.bottom); image = (ImageView) findViewById(R.id.testImage); - nextButton = (Button) findViewById(R.id.next); title = (TextView) findViewById(R.id.title); - small = (RadioButton) findViewById(R.id.small); - medium = (RadioButton) findViewById(R.id.medium); - large = (RadioButton) findViewById(R.id.large); + small = (Button) findViewById(R.id.small); + medium = (Button) findViewById(R.id.medium); + large = (Button) findViewById(R.id.large); + memeLayout = (RelativeLayout) findViewById(R.id.memeLayout); - //apply font + //apply Font Typeface Typeface tf = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/ubuntu.ttf"); title.setTypeface(tf); small.setTypeface(tf); medium.setTypeface(tf); large.setTypeface(tf); line1.setTypeface(tf); - nextButton.setTypeface(tf); - - //create on check listener to see which size is chosen - RadioGroup group = (RadioGroup) findViewById(R.id.textSizes); - group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { - - line1Text = line1.getText().toString(); - - switch (checkedId) { - case R.id.small: - bmp = drawTextToBitmap(bmp2, line1Text, 40, 2); - image.setImageBitmap(bmp); - break; - case R.id.medium: - bmp = drawTextToBitmap(bmp2, line1Text, 55, 3); - image.setImageBitmap(bmp); - break; - case R.id.large: - bmp = drawTextToBitmap(bmp2, line1Text, 80, 4); - image.setImageBitmap(bmp); - break; - } - } - }); + line2.setTypeface(tf); + + } - //method used to write text on image - public Bitmap drawTextToBitmap(Bitmap bitmap, String mText1, int textSize, int strokeSize) { - try { - android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); + //following three methods will change the font size for the textViews + public void textSizeSmall(View v) { + line1.setTextSize(15); + line2.setTextSize(15); + } - // set default bitmap config if none - if (bitmapConfig == null) { - bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; - } - // resource bitmaps are imutable, - // so we need to convert it to mutable one - bitmap = bitmap.copy(bitmapConfig, true); - Canvas canvas = new Canvas(bitmap); - // new antialised Paint - TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); - paint.setColor(Color.rgb(255, 255, 255)); - // text size in pixels - paint.setTextSize(textSize); - // text shadow - paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY); - // make text font impact - Typeface tf = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/impact.ttf"); - paint.setTypeface(tf); - paint.setTextAlign(Paint.Align.CENTER); - // center text - int xPos = (bitmap.getWidth() / 2) - 2; //-2 is for regulating the x position offset - - // create a static layout for word wrapping - StaticLayout mTextLayout = new StaticLayout(mText1, paint, canvas.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); - canvas.translate(xPos, 10); //position the text - //draw text without stroke first - mTextLayout.draw(canvas); - - //set options on paint for stroke - paint.setColor(Color.BLACK); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(strokeSize); - - //then redraw text for stroke - mTextLayout.draw(canvas); - - return bitmap; - } catch (Exception e) { - // TODO: handle exception - - - return null; - } + public void textSizeMed(View v) { + line1.setTextSize(25); + line2.setTextSize(25); + } + public void textSizeLg(View v) { + line1.setTextSize(35); + line2.setTextSize(35); } - //method used to resize, rotate and set up bitmap - private void decodeFile(String filePath) { - - // Decode image size - BitmapFactory.Options o = new BitmapFactory.Options(); - o.inJustDecodeBounds = true; - BitmapFactory.decodeFile(filePath, o); - - // The new size we want to scale to - final int REQUIRED_SIZE = 1024; - - // Find the correct scale value. It should be the power of 2. - int width_tmp = o.outWidth, height_tmp = o.outHeight; - int scale = 1; - while (true) { - if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) - break; - width_tmp /= 2; - height_tmp /= 2; - scale *= 2; + +//Method to create a bitmap from a view, in our case from a linearLayout + public Bitmap getBitmapFromView(View view) { + Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(returnedBitmap); + + Drawable bgDrawable = view.getBackground(); + if (bgDrawable != null) + bgDrawable.draw(canvas); + else + canvas.drawColor(Color.WHITE); + view.draw(canvas); + return returnedBitmap; + } + +//Method to share the meme + public void sharingM(View view) { + + bmp2 = getBitmapFromView(memeLayout); + + Intent share = new Intent(Intent.ACTION_SEND); + share.setType("image/jpeg"); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + bmp2.compress(Bitmap.CompressFormat.JPEG, 100, bytes); + File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"); + try { + f.createNewFile(); + FileOutputStream fo = new FileOutputStream(f); + fo.write(bytes.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); } + share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg")); + startActivity(Intent.createChooser(share, "Share Image")); + } - // Decode with inSampleSize - BitmapFactory.Options o2 = new BitmapFactory.Options(); - o2.inSampleSize = scale; - Bitmap b1 = BitmapFactory.decodeFile(filePath, o2); - bmp2= ExifUtils.rotateBitmap(filePath, b1); +//Method to Save the Meme into the camera roll + public void savingM(View view) { + bmp2 = getBitmapFromView(memeLayout); + + MediaStore.Images.Media.insertImage(VanillaMeme.this.getContentResolver(), bmp2, "title.jpg", "some description"); + Toast.makeText(this, "Meme saved!", Toast.LENGTH_LONG).show(); } - public void launchLastActivity(View view){ - if(bmp != null) { + //Method to save meme to ExternalPublicDirectory + public void saveMemeToCacheDir(View v){ + + bmp2 = getBitmapFromView(memeLayout); + String timeStamp = new SimpleDateFormat("MMddyyyy_HHmmss").format(new Date()); + String imageName="Meme_"+timeStamp+".jpg"; + File path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); + File myFile=new File(path,imageName); + FileOutputStream fos=null; + + + try{ + fos=new FileOutputStream(myFile); + bmp2.compress(Bitmap.CompressFormat.JPEG, 100, fos); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + Toast.makeText(this, "NO File Found",Toast.LENGTH_LONG).show(); + } catch (IOException e) { + e.printStackTrace(); + } finally { try { - //Write file - String filename = "meme.png"; - FileOutputStream stream = this.openFileOutput(filename, Context.MODE_PRIVATE); - bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); - - //Cleanup - stream.close(); - bmp.recycle(); - - //Pop intent - Intent lastActivity = new Intent(VanillaMeme.this, add_text.class); - lastActivity.putExtra("memeImage", filename); - startActivity(lastActivity); - } catch (Exception e) { + fos.close(); + Toast.makeText(VanillaMeme.this,"File Saved",Toast.LENGTH_LONG).show(); + try{ + Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + Uri uri = Uri.fromFile(myFile); + mediaScanIntent.setData(uri); + sendBroadcast(mediaScanIntent); + } catch (Exception e){ + e.printStackTrace(); + } + } catch (IOException e) { e.printStackTrace(); + } catch (NullPointerException e){ + e.printStackTrace(); + Toast.makeText(this, "No File Found To Save",Toast.LENGTH_LONG).show(); } } - } -} + } + +} \ No newline at end of file diff --git a/app/src/main/java/meme5/c4q/nyc/meme_project/add_text.java b/app/src/main/java/meme5/c4q/nyc/meme_project/add_text.java deleted file mode 100644 index cffe1fc..0000000 --- a/app/src/main/java/meme5/c4q/nyc/meme_project/add_text.java +++ /dev/null @@ -1,108 +0,0 @@ -package meme5.c4q.nyc.meme_project; - -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.Image; -import android.net.Uri; -import android.os.Environment; -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.EditText; -import android.widget.ImageView; -import android.provider.MediaStore; -import android.widget.Toast; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - - -public class add_text extends ActionBarActivity { - - Bitmap memeImage; - ImageView share; - ImageView save; - ImageView preview; - Bitmap previewMeme; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_add_text); - - - - String filename = getIntent().getStringExtra("memeImage"); - try { - FileInputStream is = this.openFileInput(filename); - memeImage = BitmapFactory.decodeStream(is); - is.close(); - } catch (Exception e) { - e.printStackTrace(); - } - - ImageView previewMeme = (ImageView) findViewById(R.id.previewMeme); - if(memeImage != null) { - previewMeme.setImageBitmap(memeImage); - } - - share = (ImageView) findViewById(R.id.shareButton); - share.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - - Intent share = new Intent(Intent.ACTION_SEND); - share.setType("image/jpeg"); - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - memeImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); - File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"); - try { - f.createNewFile(); - FileOutputStream fo = new FileOutputStream(f); - fo.write(bytes.toByteArray()); - } catch (IOException e) { - e.printStackTrace(); - } - share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg")); - startActivity(Intent.createChooser(share, "Share Image")); - - - } - }); - - } - - public void saveImage(View view) { - MediaStore.Images.Media.insertImage(add_text.this.getContentResolver(), memeImage, "title.jpg", "some description"); - Toast.makeText(this, "Meme saved!", Toast.LENGTH_LONG).show(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_add_text, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } - -} diff --git a/app/src/main/res/layout-land/activity_add_text.xml b/app/src/main/res/layout-land/activity_add_text.xml deleted file mode 100644 index e4be82f..0000000 --- a/app/src/main/res/layout-land/activity_add_text.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout-land/activity_choose_meme_style.xml b/app/src/main/res/layout-land/activity_choose_meme_style.xml deleted file mode 100644 index 5cd25d3..0000000 --- a/app/src/main/res/layout-land/activity_choose_meme_style.xml +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -