I'm not exactly sure what's going wrong here, but no matter where I try to force my imageview to be visible, it won't show up unless I call onCreate(null), which is a problem because it basically reinitializes my activity and all the live data is lost.
Basically this imageView is changed everytime someone drops it on the red box in my app, but instead of changing it just dissapears. I have verfied that nowhere in my code is View.Gone ever called and the image should never disappear in the first place.
public void setDragProps(ImageView image, ImageView green, ImageView red){
image.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
default:
return true;
}
}
});
green.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DROP:
Log.d(msg, "Drag ended");
if (dropEventNotHandled(event)) {
v.setVisibility(View.VISIBLE);
}
CharSequence options[] = new CharSequence[]{currentItem.getMenu().get(itemCounter-1).getName(), currentItem.getAddress(), currentItem.getPhone(),currentItem.getRating()};
AlertDialog.Builder builder = new AlertDialog.Builder(TouchActivity.this);
builder.setTitle(currentItem.getName());
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which){
case 1: break;
//case 2: Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
//Uri.parse("google.navigation:q=an+address+city"));
// break;
case 3: break;
case 4: break;
}
}
});
builder.show();
break;
default:
return true;
}
return false;
}
});
red.setOnDragListener(new View.OnDragListener() {
int i = 0;
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DROP:
showNextImage();
v.setVisibility(View.VISIBLE);
onCreate(null);
Log.d(msg, "Drag ended");
if (dropEventNotHandled(event)) {
v.setVisibility(View.VISIBLE);
}
break;
default:
return true;
}
return false;
}
});
image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.i("Touch Listener","Action down triggered");
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(img);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.startDragAndDrop(data, shadowBuilder, img, 100);
} else //noinspection deprecation,deprecation,deprecation
v.startDrag(data, shadowBuilder, img, 0);
default:
Log.i("Touch Listener","default triggered");
v.setVisibility(View.VISIBLE);
}
return true;
}
});
}
Show Next Image:
public void showNextImage() {
DownloadImageTask imageLoader = new DownloadImageTask(img);
if (!currentItem.getMenu().isEmpty() && currentItem.getMenu().size() > itemCounter) {
Log.i("Touch Activity ", "Loading New Image ---> " + currentItem.getMenu().get(itemCounter).getImagePath()+ " From " + currentItem.getName());
imageLoader.execute(currentItem.getMenu().get(itemCounter).getImagePath());
img.setVisibility(View.VISIBLE);
itemCounter++;
} else {
Log.i("Touch Activity ", "Can't find any more images to download from " + currentItem.getName() + ". Loading next restaurant... ");
getNextRestaurant();
}
}
DownloadImageTask:
// This class takes a URL and downloads the image at the url.
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView tempImage;
public boolean doneLoading = false;
public DownloadImageTask(ImageView bmImage) {
this.tempImage = bmImage;
tempImage.setScaleType(ImageView.ScaleType.FIT_XY);
}
protected Bitmap doInBackground(String... urls) {
String inputURL = urls[0];
Bitmap tempBmap = null;
try {
InputStream in = new java.net.URL(inputURL).openStream();
tempBmap = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return tempBmap;
}
protected void onPostExecute(Bitmap result) {
doneLoading = true;
tempImage.setImageBitmap(result);
tempImage.setVisibility(View.VISIBLE);
}
}