Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help with App
Options
-
15-05-2014 1:19pmHi Folks,
Sorry but i am trying to do a kids app for my niece - if you see the attached screenshot of the homescreen - the part i am having difficulty with is the drawing fun ImageButton - I have followed an online tutorial to implement this but cannot find an email address to contact the person - It all looks right on screen when you go into the various GUI's but it crashes when this button is selected when i try to call an Intent to open a new activity.
I have attached my homescreen and code below for you all to see, and would be really grateful if someone can help as i said i would have it for her communion which is next wk
Thanks in advance
HOMESCREEN JAVA CODEimport android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.ImageButton; import android.widget.Toast; public class HomeScreen extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); } public void homeScreenButtonsClicked(View view) { ImageButton alphabet = (ImageButton) findViewById(R.id.alphabet); ImageButton numbers = (ImageButton) findViewById(R.id.numbers); ImageButton days = (ImageButton) findViewById(R.id.days); ImageButton months = (ImageButton) findViewById(R.id.months); ImageButton drawingFun = (ImageButton) findViewById(R.id.drawingFun); ImageButton numberGames = (ImageButton) findViewById(R.id.number_games); if (view.getId() == R.id.alphabet) { Toast.makeText(getApplicationContext(), "Alphabet Lesson", Toast.LENGTH_SHORT).show(); // Intent intent = new Intent(this, AlphabetActivity.class); // startActivity(intent); // } } if (view.getId() == R.id.numbers) { Toast.makeText(getApplicationContext(), "Numbers Lesson", Toast.LENGTH_SHORT).show(); } if (view.getId() == R.id.days) { Toast.makeText(getApplicationContext(), "Days Lesson", Toast.LENGTH_SHORT).show(); } if (view.getId() == R.id.months) { Toast.makeText(getApplicationContext(), "Months Lesson", Toast.LENGTH_SHORT).show(); } if (view.getId() == R.id.drawingFun) { Toast.makeText(getApplicationContext(), "Drawing Fun.... Get Ready!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(this, DrawingView.class); startActivity(intent); } if (view.getId() == R.id.number_games) { Toast.makeText(getApplicationContext(), "Number Games.... Get Ready!", Toast.LENGTH_SHORT).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.home_screen, menu); return true; } }
DRAWING CANVAS JAVA CODEimport android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; public class DrawingCanvas extends Activity { private DrawingView drawView; private ImageButton currPaint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawing_canvas); // instantiate this variable by retrieving a reference to it from the layout: drawView = (DrawingView) findViewById(R.id.drawing); LinearLayout paintLayout = (LinearLayout)findViewById(R.id.paint_colors); // Get the first button and store it as the instance variable: currPaint = (ImageButton)paintLayout.getChildAt(0); // We will use a different drawable image on the button to show that it is currently selected: currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed)); } public void paintClicked(View view) { // use chosen color // but first check to see if the user has clicked a color if(view != currPaint) { // update color ImageButton imgView = (ImageButton)view; String color = view.getTag().toString(); // call the setColor Method in the drawing view class drawView.setColor(color); imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed)); currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint)); currPaint=(ImageButton)view; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.drawing_canvas, menu); return true; } }
DRAWING VIEW JAVA CODEimport android.content.Context; import android.view.View; import android.util.AttributeSet; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.view.MotionEvent; public class DrawingView extends View { // instance variables for the above //drawing path private Path drawPath; //drawing and canvas paint private Paint drawPaint, canvasPaint; //initial color private int paintColor = 0xFF660000; //canvas private Canvas drawCanvas; //canvas bitmap private Bitmap canvasBitmap; public DrawingView(Context context, AttributeSet attrs) { super(context, attrs); setupDrawing(); } // We will add an instance of the custom View to the XML layout file. //Add the specified helper method to the class: private void setupDrawing(){ //get drawing area setup for interaction // we need to instantiate some of the above instance variables drawPath = new Path(); drawPaint = new Paint(); // to set the initial color when app launched drawPaint.setColor(paintColor); // set the initial path properties drawPaint.setAntiAlias(true); drawPaint.setStrokeWidth(20); drawPaint.setStyle(Paint.Style.STROKE); drawPaint.setStrokeJoin(Paint.Join.ROUND); drawPaint.setStrokeCap(Paint.Cap.ROUND); // we need to instantiate the canvas paint object canvasPaint = new Paint(Paint.DITHER_FLAG); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); //Now instantiate the drawing canvas and bitmap using the width and height values: canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); drawCanvas = new Canvas(canvasBitmap); } @Override protected void onDraw(Canvas canvas) { //draw view - canvas and size canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); canvas.drawPath(drawPath, drawPaint); } @Override public boolean onTouchEvent(MotionEvent event) { //detect user touch // retrieve the X and Y positions of the user touch: float touchX = event.getX(); float touchY = event.getY(); // switch statement to respond to our moves - down, move and up switch(event.getAction()) { case MotionEvent.ACTION_DOWN: drawPath.moveTo(touchX, touchY); break; case MotionEvent.ACTION_MOVE: drawPath.lineTo(touchX, touchY); break; case MotionEvent.ACTION_UP: drawCanvas.drawPath(drawPath, drawPaint); drawPath.reset(); break; default: return false; } //calling invalidate method will cause the onDraw() to execute invalidate(); return true; } public void setColor(String newColor){ //set color // but first we need to invalidate the view invalidate(); // next parse and set the color for drawing paintColor = Color.parseColor(newColor); drawPaint.setColor(paintColor); } }
XML HOME SCREEN ACTIVITY<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" tools:context=".HomeScreen" android:background="#01DF12" > <ImageButton android:id="@+id/alphabet" android:background="@drawable/alphabet_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_marginLeft="33dp" android:layout_marginTop="15dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <ImageButton android:id="@+id/numbers" android:background="@drawable/numbers_icon" android:layout_width="105dp" android:layout_toRightOf="@id/alphabet" android:layout_height="85dp" android:layout_marginLeft="45dp" android:layout_marginTop="15dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/alphabetLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/alphabet" android:layout_marginLeft="42dp" android:text="Alphabet" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="20sp"/> <TextView android:id="@+id/numbersLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/alphabetLabel" android:layout_below="@id/numbers" android:layout_marginLeft="78dp" android:text="Numbers" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="20sp"/> <ImageButton android:id="@+id/days" android:background="@drawable/days_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_below="@id/alphabetLabel" android:layout_marginLeft="33dp" android:layout_marginTop="35dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/daysLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/days" android:layout_marginLeft="55dp" android:text="Days" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="20sp"/> <ImageButton android:id="@+id/months" android:background="@drawable/months_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_below="@id/numbersLabel" android:layout_toRightOf="@id/days" android:layout_marginLeft="45dp" android:layout_marginTop="35dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/monthsLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/months" android:layout_toRightOf="@id/daysLabel" android:layout_marginLeft="105dp" android:text="Months" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="20sp"/> <!-- <ImageButton android:id="@+id/word_games" android:background="@drawable/word_games_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_below="@id/daysLabel" android:layout_marginLeft="33dp" android:layout_marginTop="35dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/wordGamesLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/word_games" android:layout_marginLeft="38dp" android:text="Word Games" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="17sp"/> --> <ImageButton android:id="@+id/drawingFun" android:background="@drawable/drawing_fun_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_below="@id/daysLabel" android:layout_marginLeft="33dp" android:layout_marginTop="35dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/drawingFunLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/drawingFun" android:layout_marginLeft="38dp" android:text="Drawing Fun" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="17sp"/> <ImageButton android:id="@+id/number_games" android:background="@drawable/number_games_icon" android:layout_width="105dp" android:layout_height="85dp" android:layout_below="@id/monthsLabel" android:layout_toRightOf="@id/drawingFun" android:layout_marginLeft="45dp" android:layout_marginTop="35dp" android:soundEffectsEnabled="true" android:onClick="homeScreenButtonsClicked" /> <TextView android:id="@+id/numberGamesLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/number_games" android:layout_toRightOf="@id/drawingFunLabel" android:layout_marginLeft="42dp" android:text="Number Games" android:textColor="#ffffff" android:textStyle="bold" android:shadowColor="#000000" android:shadowRadius="5" android:textSize="17sp"/> </RelativeLayout>
XML DRAWING CANVAS ACTIVITY<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFCCCCCC" android:orientation="vertical" tools:context=".MainActivity" > <!-- this is to hold the UI Buttons along the top of the screen which we need to add the buttons inside this layout --> <LinearLayout android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="center" android:orientation="horizontal" > <ImageButton android:id="@+id/new_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:contentDescription="@string/start_new" android:src="@drawable/new_sheet_button" /> <ImageButton android:id="@+id/erase_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:contentDescription="@string/erase" android:src="@drawable/erase_button" /> <ImageButton android:id="@+id/save_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:contentDescription="@string/save" android:src="@drawable/save_button" /> <ImageButton android:id="@+id/brush_btn" android:layout_width="wrap_content" android:layout_height="fill_parent" android:contentDescription="@string/brush" android:src="@drawable/brush_button" /> </LinearLayout> <!-- The following is adding an instance of our custom class, DrawingView --> <com.example.drawingfun.DrawingView android:id="@+id/drawing" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_marginBottom="3dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="3dp" android:layout_weight="1" android:background="#FFFFFFFF" /> <!-- The following is to add pallette buttons --> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical" > <!-- Top Row --> <LinearLayout android:id="@+id/paint_colors" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF660000" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF660000" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FFFF0000" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FFFF0000" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FFFF6600" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FFFF6600" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FFFFCC00" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FFFFCC00" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF009900" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF009900" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF009999" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF009999" /> </LinearLayout> <!-- Bottom Row --> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF0000FF" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF0000FF" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF990099" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF990099" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FFFF6666" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FFFF6666" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FFFFFFFF" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FFFFFFFF" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF787878" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF787878" /> <ImageButton android:layout_width="@dimen/large_brush" android:layout_height="@dimen/large_brush" android:layout_margin="2dp" android:background="#FF000000" android:contentDescription="@string/paint" android:onClick="paintClicked" android:src="@drawable/paint" android:tag="#FF000000" /> </LinearLayout> </LinearLayout> </LinearLayout>
I hope this is ok but if you need anything further please just ask.
Appreciate any help!
K.0
Comments
-
What is the error you are getting when it crashes?0
-
-
Atomic Pineapple wrote: »What is the error you are getting when it crashes?0
-
Hmmm... did you add the new activities to your manifest?0
-
Hi Folks,
Sorry only replying now as had grad ceremony Thurs and well, It was one big piss up....
Anyways i have looked through the logcat and to see if i could fix why it is crashing prior to responding here and it seems like the problem lies with the class DrawingView (As per the code above)
I have attached a snippet of the logcat - Any help or guidance would be very much appreciated.
Thanks in advance!
K0 -
Advertisement
-
Lads,
Whoohoo - it is ok - i found the error - I went through each line meticulously and found the incorrect package name in my xml for to implement the drawing canvas...
Thanks for everything!!
K.0 -
Hi Folks,
I have all working so far for my app - apart from the save image button. I have a DrawingCanvas class which is used by the user to draw images using their finger and have buttons (ImageButtons) at the top of screen for New, Erase, Save, Brush Size and Email - I have all working apart from the Save.
The logcat is saying error is in the MediaStore (FileNotFoundException) - Can anyone help thanks.
The code is as follows: -package com.kennshanny.childsplay; import java.util.UUID; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.Toast; public class DrawingCanvas extends Activity implements OnClickListener { private DrawingView drawView; private ImageButton currPaint, drawBtn, eraseBtn, saveBtn, newBtn; private float smallBrush, mediumBrush, largeBrush; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawing_canvas); Log.d("LOGCAT DEBUG", "Inside onCreate - DrawingCanvas Class"); // instantiate this variable by retrieving a reference to it from the layout: drawView = (DrawingView) findViewById(R.id.drawing); LinearLayout paintLayout = (LinearLayout)findViewById(R.id.paint_colors); // Get the first button and store it as the instance variable: currPaint = (ImageButton)paintLayout.getChildAt(0); // We will use a different drawable image on the button to show that it is currently selected: currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed)); // We need to instantiate the brush sizes above to use them smallBrush = getResources().getInteger(R.integer.small_size); mediumBrush = getResources().getInteger(R.integer.medium_size); largeBrush = getResources().getInteger(R.integer.large_size); drawBtn = (ImageButton) findViewById(R.id.draw_btn); drawBtn.setOnClickListener(this); // this will set the initial size using the setBrushSize Method drawView.setBrushSize(mediumBrush); // retrieve a reference to the button and setup to listen for onClicks eraseBtn = (ImageButton) findViewById(R.id.erase_btn); eraseBtn.setOnClickListener(this); // retrieve a reference to the button and setup to listen for onClicks newBtn = (ImageButton)findViewById(R.id.new_btn); newBtn.setOnClickListener(this); // retrieve a reference to the button and setup to listen for onClicks saveBtn = (ImageButton)findViewById(R.id.save_btn); saveBtn.setOnClickListener(this); } public void paintClicked(View view) { Log.d("LOGCAT DEBUG", "Inside paintClicked Method - DrawingCanvas Class"); // call the erase method and set to false drawView.setErase(false); drawView.setBrushSize(drawView.getLastBrushSize()); //gets last brush size used // use chosen color // but first check to see if the user has clicked a color if(view != currPaint) { // update color ImageButton imgView = (ImageButton)view; String color = view.getTag().toString(); // call the setColor Method in the drawing view class drawView.setColor(color); imgView.setImageDrawable(getResources().getDrawable(R.drawable.paint_pressed)); currPaint.setImageDrawable(getResources().getDrawable(R.drawable.paint)); currPaint=(ImageButton)view; } } @Override public void onClick(View v) { Log.d("LOGCAT DEBUG", "Inside onClick Method - DrawingCanvas Class"); // check for when drawing button is clicked if(v.getId()== R.id.draw_btn){ // Dialog to present user with brush sizes final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Brush Size:"); //set layout for brushDialog brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(smallBrush); drawView.setLastBrushSize(smallBrush); drawView.setErase(false); brushDialog.dismiss(); //will dismiss the dialog } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(mediumBrush); drawView.setLastBrushSize(mediumBrush); drawView.setErase(false); brushDialog.dismiss(); //will dismiss the dialog } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setBrushSize(largeBrush); drawView.setLastBrushSize(largeBrush); drawView.setErase(false); brushDialog.dismiss(); //will dismiss the dialog } }); brushDialog.show(); }else if (v.getId()== R.id.erase_btn) { // switch to erase and choose the size to use // We will use a dialog as above for this option too // Setup the dialog to use final Dialog brushDialog = new Dialog(this); brushDialog.setTitle("Eraser Size:"); brushDialog.setContentView(R.layout.brush_chooser); ImageButton smallBtn = (ImageButton) brushDialog.findViewById(R.id.small_brush); smallBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(smallBrush); brushDialog.dismiss(); //will dismiss the dialog } }); ImageButton mediumBtn = (ImageButton) brushDialog.findViewById(R.id.medium_brush); mediumBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(mediumBrush); brushDialog.dismiss(); //will dismiss the dialog } }); ImageButton largeBtn = (ImageButton) brushDialog.findViewById(R.id.large_brush); largeBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { drawView.setErase(true); drawView.setBrushSize(largeBrush); brushDialog.dismiss(); //will dismiss the dialog } }); brushDialog.show(); } else if (v.getId()== R.id.new_btn) { // new Button // AlertDialog to check if user definitely wants to start new Drawing AlertDialog.Builder newDialog = new AlertDialog.Builder(this); newDialog.setTitle("New Drawing"); newDialog.setIcon(R.drawable.new_sheet_button); newDialog.setMessage("Start new drawing (You will lose the current drawing" + " unless you save it first!"); newDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { drawView.startNew(); dialog.dismiss(); } }); newDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); newDialog.show(); }else if (v.getId() == R.id.save_btn) { // save Drawing // AlertDialog to check if user definitely wants to Save Drawing AlertDialog.Builder saveDialog = new AlertDialog.Builder(this); saveDialog.setTitle("Save Drawing"); saveDialog.setIcon(R.drawable.save_button); saveDialog.setMessage("Save drawing to device Gallery?"); saveDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // save drawing drawView.setDrawingCacheEnabled(true); String imgSaved = MediaStore.Images.Media.insertImage( getContentResolver(), drawView.getDrawingCache(), UUID.randomUUID().toString()+".png", "drawing"); if(imgSaved!=null){ Toast savedToast = Toast.makeText(getApplicationContext(), "Drawing saved to Gallery!", Toast.LENGTH_SHORT); savedToast.show(); } else{ Toast unsavedToast = Toast.makeText(getApplicationContext(), "Oops! Image could not be saved.", Toast.LENGTH_SHORT); unsavedToast.show(); }drawView.destroyDrawingCache(); } }); saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); saveDialog.show(); } } public void emailPicture(View view) { ImageButton email = (ImageButton)findViewById(R.id.email_btn); Intent mail = new Intent(Intent.ACTION_SEND); mail.setType("text/html"); mail.putExtra(Intent.EXTRA_SUBJECT, "Send from Android"); mail.putExtra(Intent.EXTRA_TEXT, "Sent from Android"); startActivity(Intent.createChooser(mail, "Send email using: ")); } @Override public boolean onCreateOptionsMenu(Menu menu) { Log.d("LOGCAT DEBUG", "Inside onCreateOptionsMenu - DrawingCanvas Class"); // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.drawing_canvas, menu); return true; } }
Thanks Folks!0 -
Right, You're just being lazy now. You know the error message is "FileNotFoundException" and that it's associated with MediaStore. MediaStore only appears once in your code:
String imgSaved = MediaStore.Images.Media.insertImage( getContentResolver(), drawView.getDrawingCache(), UUID.randomUUID().toString()+".png", "drawing");
And guess what, the second parameter to the method being invoked is a filepath...0 -
The Corinthian wrote: »Right, You're just being lazy now. You know the error message is "FileNotFoundException" and that it's associated with MediaStore. MediaStore only appears once in your code:
String imgSaved = MediaStore.Images.Media.insertImage( getContentResolver(), drawView.getDrawingCache(), UUID.randomUUID().toString()+".png", "drawing");
And guess what, the second parameter to the method being invoked is a filepath...
I never worked with this MediaStore before now - You say i only use this once in my code - BUT should i be using it elsewhere too??
Any when you say the second parameter being invoked is a filepath?? - is this the drawView.getDrawingCache() ??
Thanks0 -
I never worked with this MediaStore before now - You say i only use this once in my code - BUT should i be using it elsewhere too??
It might still be something else, but we - rather you - should eliminate that possiblity first. And if it is related to how you've used MediaStore, then RTFM!Any when you say the second parameter being invoked is a filepath?? - is this the drawView.getDrawingCache() ??0 -
Advertisement
-
[QUOTE=
It might still be something else, but we - rather you - should eliminate that possiblity first. And if it is related to how you've used MediaStore, then RTFM!
How do you not know it's a filepath? You coded it, so I'd hope you'd know what you were implementing. Even without knowing beforehand though, the PNG file extension that was manually added to it, kind of gives it away.[/QUOTE]
lol - I wud RTFM if i had one - anyways from the tutorial i followed It told me the png was just the file extension which was to be attached to the picture that the user wanted to save....
....Are you saying this is not the case??
Thanks!0 -
The 3rd param is the path you are specifying. Why not catch the exception and look at the message and stack trace?0
-
Actually was in the middle of doing try/catch block - Thanks!0
-
Good stuff. I would suggest trying to fix this yourself rather than just pasting the exception info here.0
-
lol - I wud RTFM if i had one - anyways from the tutorial i followed It told me the png was just the file extension which was to be attached to the picture that the user wanted to save....
String android.provider.MediaStore.Images.Media.insertImage(ContentResolver cr, String imagePath, String name, String description) throws FileNotFoundException Insert an image and create a thumbnail for it. Parameters: cr The content resolver to use imagePath The path to the image to insert name The name of the image description The description of the image Returns: The URL to the newly created image
Which is, oddly enough, documentation. Now check out what the imagePath param is...0 -
He's using the an overload that takes bitmap data as the 2nd param, the path as the 3rd.
EDIT: Maybe not. **** knows what getDrawingCache() returns!0 -
lol - I wud RTFM if i had one0
-
It is OK Folks - the problem was not with the code but the fact i was using the emulator as when i put it on my phone it has worked fine.
Makes Sense???
Thanks Folks!0 -
It is OK Folks - the problem was not with the code but the fact i was using the emulator as when i put it on my phone it has worked fine.
Makes Sense???0 -
The Corinthian wrote: »Yes. Had you consdered investigating what difference between the two was causing the error? Or is your app only ever going to be running on your phone?
I presume that the emulator i was using (Genymotion) did not support the Gallery i was storing the images to??
As i stated I am learning this myself as i going along - alot of stuff i do not initially understand until i see it in action and how it works. I followed a tutorial for the drawing canvas and how to get it working.
I didnt think i was doing too bad so far - still have a good bit to do with app prior to release.
Thanks for your guidance and help!:)0 -
Advertisement
-
I presume that the emulator i was using (Genymotion) did not support the Gallery i was storing the images to??As i stated I am learning this myself as i going along - alot of stuff i do not initially understand until i see it in action and how it works. I followed a tutorial for the drawing canvas and how to get it working.
Don't get me wrong; I recognise you're learning, but I did note that you asked your question a little bit too quickly and then managed to solve it on your own when you finally decided to make an effort. And this isn't the first time.0
Advertisement