-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bug: Invalidate View Problem in Galaxy S3 #5
Comments
Hi. Library is superb. But i am also facing the same view invalidating issue as @cagkanciloglu . I tested in galaxy note and galaxy note 2. Could anyone please help how to solve this. Thank you in advance.. |
I'll try to get a Samsung device to reproduce the issue. Could you tell me the OS version on your devices? Thanks |
Hi guys, I guess the problem is while taking screenshot in grabIt.java file in higher resolution mobiles previous screenshot is released to free memory. So i think we need to reduce the size of bitmap created or compress bitmap for high res mobiles alone. Please correct me if i am wrong. Thank you. |
Note is android 4.0.4 and Note II is android 4.1.1. But I guess this problem may occur for most of the high resolution devices. Thanks |
Aravind's theory may be correct. I also tested it on Galaxy S2 its working alright. Btw OS version on my S3 is 4.1.1 |
Flip Complex Layouts demo working alright on S3. Fyi |
I tested on emulator running OS 4.1 with high resolution settings (720 x 1280), but I failed to reproduce it. It doesn't sound like a memory issue as far as I can tell from the video. But I could be wrong on this. I'll ask my friends for a Galaxy Note for further testing. By the way, could you try to pause and resume the activity to see what happens then, by pressing the Home button? |
Nothing happened after resuming the activity. Issue remained. |
Nothing changes while pausing and resuming activity. I will attach my log data printed for a single flip while running in galaxy Note
But for galaxy S2 my logacat data are
You can notice that memory is freed before creating second bitmap for Galaxy note where as it is not in S II. So i guessed that issue is with the size of bitmap. I am sorry if i am wrong. |
Thanks for the detailed report. The GC logs are fine for this scenario. I guess the bug could be caused by some incorrect OpenGL renderer settings for the high resolution. I'll dig into it for more clues |
Thanks. I am eager for your solution.... |
No luck? |
I'm still struggling to reproduce the bug. I went to a Samsung store and tried a GS3 and a Galaxy Note II with the demo app, but found nothing abnormal. One user suggested that the problem is easy to reproduce for certain layout hierarchy. If anyone knows a layout pattern for this issue, please share it to us. Thanks for advance. |
The layout below is similar to the layout in the video. I hope this helps. <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/gallery_flip_item_background_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/galeritestimage" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="@color/transparentBlack"
android:padding="5dp" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/feed_taggeduser_image" />
<TextView
android:id="@+id/gallery_flip_item_place_name_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical"
android:maxLines="2"
android:text="Merve B (Gezgin): "Big Chefs'te Big Burger yedim ve gerçekten adını hak edecek kadar büyüktu :) Merve B (Gezgin): "Big Chefs'te Big Burger yedim ve gerçekten adını hak edecek kadar büyüktu :)"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/gallery_flip_item_place_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/transparentBlack"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/gallery_flip_item_place_icon_imageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="3dp"
android:scaleType="fitXY"
android:src="@drawable/img1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/gallery_flip_item_place_name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Rumeli Hısarı İskele Restaurant"
android:textColor="@color/white"
android:textSize="19sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/feed_checkin_location" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/gallery_flip_item_place_district_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mercan"
android:textColor="@color/white"
android:textSize="11sp" />
<TextView
android:id="@+id/gallery_flip_item_place_city_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İstanbul"
android:textColor="@color/white"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout> |
@cagkanciloglu |
@openaphid |
@cagkanciloglu Thanks. It would be the best way for me to fix the issue. |
https://github.com/cagkanciloglu/FlipViewProblematicLayout Here is the link for the problematic layout. I shot a new video about the problem too, you can find it in "video" folder. I guess I got the problem: it seems it happens when application downloads image for background. After the download when I begin the gesture for flipping, the background image is being released immediately. Maybe you can add a listener so when the gesture ends you release the image. That should do the trick. |
Sorry for my late reply. It seems that FlipView doesn't work well with async content. I'll try to figure out a way to improve it in develop branch first |
The same phenomenon occurs in my program has been. Until now, the results of testing the devices except the device Galaxy Notes 2 and Galaxy S3, Ironically Demo apk 2 and Galaxy Note Galaxy S3 has been working well. Please help me. |
The layout is the same symptoms that occurred.
|
@KyungHo if you met the same problem as @cagkanciloglu showed in http://www.youtube.com/watch?v=rv0pLLCn-8w . I doubt it could be caused by the OpenGL lighting setup in FlipView. But it's hard for me to debug it as it can't be reproduced on my devices (Defy+ and Nexus 7) @cagkanciloglu the issue you found in your followup video. It's actually a new issue, which will be resolved by fixing #37 and #28 |
@cagkanciloglu I migrated your project into the demo app as "Issue #5". I found that its async loading logic is not 100% correct. Please refer to the comments in my commit for more details: https://github.com/openaphid/android-flip/blob/bef17096d3eef18f412916b3c928ca81438c498f/FlipView/Demo/src/com/aphidmobile/flip/demo/issue5/GalleryFlipItem.java You can also download the updated APK: https://github.com/openaphid/android-flip/blob/develop/FlipView/Demo/APK/Aphid-FlipView-Demo.apk BTW: I also found the layout hierarchy is not optimal, you can try to improve it if it's used in your real app. |
i am download your project and importing into my project and it sow errors "R.styleable.FlipViewController_orientation" |
@openaphid We solved the black screen render error on Samsung Galaxy S III device, changing the gluPerspective far plane to a higher number. In FlipRenderer.java, float fovy = 20f;
float eyeZ = height / 2f / (float) Math.tan(TextureUtils.d2r(fovy / 2));
GLU.gluPerspective(gl, fovy, (float) width / (float) height, 0.5f, 5000); //We changed Math.max(2500.0f, eyeZ) to 5000 |
@ZoserLock Thanks a lot. I will merge it into master branch later. |
I've pushed a fix into develop branch. Could you guys test it on a Galaxy S3 for me please? APK: https://github.com/openaphid/android-flip/tree/develop/FlipView/Demo/APK But I still don't get the real reason of the issue. If eyeZ is larger than 2500, zFar should be correctly set to eyeZ by Math.max, which is the case on my Nexus 7. Maybe it's caused by a math rounding issue on certain OpenGL drivers. |
Yep. Setting the value to 5000 solved that issue. But after I have implemented the solution I noticed another bug on S3. While I was sliding through the pages I saw some pages coming full white at first then the actual layout. I don't think It's caused by async content because the page comes with complete white other than this I have high speed internet connection. I shot a video about the bug. It's rather short video but you can see the bug. And sorry for the quality. |
And the layout is almost similar to one you looked early. I just took your relative layout advice and changed view and added cache code for the content image downloader. I can send the layout xml and the Flip Item class too if you want. |
The full white issue seems not related to async content. Please share your code that can reproduce the problem. Is it reproducible on emulator? And what happens if you hold the page when it's full white? |
XML layout <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darkgrey"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/gallery_flip_item_background_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:visibility="visible" />
<ProgressBar
android:id="@+id/gallery_flip_item_background_progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateBehavior="cycle" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/transparentBlack"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/feed_taggeduser_image" />
<TextView
android:id="@+id/gallery_flip_item_place_name_ellipsizingtextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical"
android:maxLines="2"
android:text="Merve B (Gezgin): "Big Chefs'te Big Burger yedim ve gerçekten adını hak edecek kadar büyüktu :) Merve B (Gezgin): "Big Chefs'te Big Burger yedim ve gerçekten adını hak edecek kadar büyüktu :)"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/gallery_flip_item_place_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/transparentBlack"
android:orientation="horizontal"
android:padding="5dp" >
<ProgressBar
android:id="@+id/gallery_flip_item_icon_progressbar"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminate="true"
android:indeterminateBehavior="cycle" />
<ImageView
android:id="@+id/gallery_flip_item_place_icon_imageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="3dp"
android:scaleType="fitXY"
android:visibility="gone" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/gallery_flip_item_place_name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Rumeli Hısarı İskele Restaurant"
android:textColor="@color/white"
android:textSize="19sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="12dp"
android:layout_height="wrap_content"
android:src="@drawable/icon_place_checkin" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/gallery_flip_item_place_district_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mercan"
android:textColor="@color/white"
android:textSize="11sp" />
<TextView
android:id="@+id/gallery_flip_item_place_city_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="İstanbul"
android:textColor="@color/white"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout> |
public class GalleryFlipItem extends LinearLayout
{
/**
* Borrowed from the official BitmapFun tutorial: http://developer.android.com/training/displaying-bitmaps/index.html
*/
private static final class AsyncDrawable extends BitmapDrawable
{
private final WeakReference<ContentPhotosDownloader> taskRef;
public AsyncDrawable(Resources res, Bitmap bitmap, ContentPhotosDownloader task)
{
super(res, bitmap);
this.taskRef = new WeakReference<ContentPhotosDownloader>(task);
}
public static ContentPhotosDownloader getTask(ImageView imageView)
{
Drawable drawable = imageView.getDrawable();
if (drawable instanceof AsyncDrawable)
return ((AsyncDrawable) drawable).taskRef.get();
return null;
}
}
// Change to a static inner class from a normal inner class, otherwise it may holds a strong reference to GalleryFlipItem, which is not a good practise for AsyncTask
private static class ContentPhotosDownloader extends AsyncTask<Void, Void, Bitmap>
{
private final String url;
private final WeakReference<FlipViewController> controllerRef;
// Use WeakReference
private final WeakReference<ImageView> imgViewRef;
private WeakReference<ProgressBar> progressBarRef;
private final int pageIndex;
public ContentPhotosDownloader(String url, ImageView imgView, ProgressBar progressBar, FlipViewController controller, int pageIndex)
{
if (url == null || imgView == null || controller == null)
ContentPhotosDownloader.this.cancel(true);
// Assert.assertNotNull(url);
// Assert.assertNotNull(imgView);
// Assert.assertNotNull(controller);
// progressBar can be null
this.url = url;
this.imgViewRef = new WeakReference<ImageView>(imgView);
this.controllerRef = new WeakReference<FlipViewController>(controller);
this.pageIndex = pageIndex;
if (progressBar != null)
progressBarRef = new WeakReference<ProgressBar>(progressBar);
}
public String getUrl()
{
return url;
}
public int getPageIndex()
{
return pageIndex;
}
private ProgressBar getProgressBar()
{
return progressBarRef != null ? progressBarRef.get() : null;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
ProgressBar bar = getProgressBar();
if (bar != null)
{
bar.setVisibility(View.VISIBLE);
ImageView iv = imgViewRef.get();
if (iv != null)
iv.setVisibility(GONE);
}
}
@Override
protected Bitmap doInBackground(Void... params)
{
// Caching code right here
String filename = String.valueOf(url.hashCode());
File f = new File(ImageDownloader.getCacheDirectory(imgViewRef.get().getContext()), filename);
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inDither = false; // Disable Dithering mode
options.inPurgeable = true; // Tell to gc that whether it needs free memory, the Bitmap can be cleared
options.inInputShareable = true; // Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
options.inTempStorage = new byte[32 * 1024];
bitmap = BitmapFactory.decodeFile(f.getPath(), options);
if (bitmap == null)
{
InputStream is = null;
try
{
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.setConnectTimeout(1000);
conn.connect();
is = new BufferedInputStream(conn.getInputStream());
bitmap = BitmapFactory.decodeStream(is);
// cache the image
String filenameToWrite = String.valueOf(url.hashCode());
File fw = new File(ImageDownloader.getCacheDirectory(imgViewRef.get().getContext()), filenameToWrite);
ImageDownloader.writeFile(bitmap, fw);
return bitmap;
}
catch (IOException e)
{
AphidLog.e(e, "Failed to load bitmap from url: " + url);
}
finally
{
IO.close(is);
}
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result)
{
if (isCancelled())
return;
ImageView imgView = imgViewRef.get();
if (imgView != null && AsyncDrawable.getTask(imgView) == this)
{ // make sure the ImageView instance has not been reused for another page
if (result != null)
{
imgView.setImageBitmap(result);
imgView.setVisibility(View.VISIBLE);
}
ProgressBar bar = getProgressBar();
if (bar != null)
bar.setVisibility(View.GONE);
FlipViewController controller = controllerRef.get();
if (controller != null)
controller.refreshPage(pageIndex);
}
}
}
public GalleryPage mGalleryPage;
private ImageView imgBackground;
private final ProgressBar pd;
private final ProgressBar pdIcon;
private final LinearLayout lnlPlace;
private ImageView imgIcon;
private final TextView txtName;
private final TextView txtDistrict;
private final TextView txtCity;
private final TextView txtBody;
private final Context mContext;
public void refreshView(GalleryPage mGalleryPage, FlipViewController controller, int pageIndex)
{
this.mGalleryPage = mGalleryPage;
txtName.setText(this.mGalleryPage.getTargetPlace().name);
txtDistrict.setText(this.mGalleryPage.getTargetPlace().location.district.name);
txtCity.setText(this.mGalleryPage.getTargetPlace().location.city.name);
txtBody.setText(this.mGalleryPage.getBody());
txtBody.setMaxLines(5);
lnlPlace.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
new MekanDetailActivity.InitForMekanDetailTask(mContext, GalleryFlipItem.this.mGalleryPage.getTargetPlace().id).execute();
}
});
if (shouldStartAsyncLoad(imgIcon, this.mGalleryPage.getTargetPlace().photo.small, pageIndex))
{
ContentPhotosDownloader downloader = new ContentPhotosDownloader(this.mGalleryPage.getTargetPlace().photo.small, imgIcon, pdIcon, controller, pageIndex);
imgIcon.setImageDrawable(new AsyncDrawable(getResources(), null, downloader));
downloader.execute();
}
if (shouldStartAsyncLoad(imgBackground, this.mGalleryPage.getImageURL(), pageIndex))
{
ContentPhotosDownloader downloader = new ContentPhotosDownloader(this.mGalleryPage.getImageURL(), imgBackground, pd, controller, pageIndex);
imgBackground.setImageDrawable(new AsyncDrawable(getResources(), null, downloader));
downloader.execute();
}
}
private boolean shouldStartAsyncLoad(ImageView imageView, String url, int pageIndex)
{
ContentPhotosDownloader downloader = AsyncDrawable.getTask(imageView);
boolean shouldStart = true;
if (downloader != null)
{
if (downloader.getPageIndex() == pageIndex && url.equals(downloader.getUrl()))
shouldStart = false;
else
downloader.cancel(true);
}
return shouldStart;
}
@SuppressWarnings("deprecation")
public GalleryFlipItem(Context context, GalleryPage mGalleryPage, FlipViewController controller, int pageIndex)
{
super(context);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.gallery_flip_item_layout, this);
pd = (ProgressBar) findViewById(R.id.gallery_flip_item_background_progressbar);
pdIcon = (ProgressBar) findViewById(R.id.gallery_flip_item_icon_progressbar);
imgBackground = (ImageView) findViewById(R.id.gallery_flip_item_background_imageview);
lnlPlace = (LinearLayout) findViewById(R.id.gallery_flip_item_place_linearlayout);
imgIcon = (ImageView) findViewById(R.id.gallery_flip_item_place_icon_imageview);
txtName = (TextView) findViewById(R.id.gallery_flip_item_place_name_textview);
txtDistrict = (TextView) findViewById(R.id.gallery_flip_item_place_district_textview);
txtCity = (TextView) findViewById(R.id.gallery_flip_item_place_city_textview);
txtBody = (TextView) findViewById(R.id.gallery_flip_item_place_name_ellipsizingtextview);
// int Measuredwidth = 0;
// int Measuredheight = 0;
// Point size = new Point();
// WindowManager w = ((Activity) context).getWindowManager();
//
// Display d = w.getDefaultDisplay();
// Measuredwidth = d.getWidth();
// Measuredheight = d.getHeight();
//
// // notes: it's not the right approach to make the background fill its parent, using a RelativeLayout could be much better
// imgBackground.setLayoutParams(new LayoutParams(Measuredwidth, Measuredheight));
refreshView(mGalleryPage, controller, pageIndex);
}
} |
No luck? |
I'm afraid the code snippet you shared is not compilable on my side due to its dependencies. May I ask why you mixed a |
Can you tell me the dependencies ? So I can provide them for you. Framelayout doesn't display only one view. It displays a relativelayout and two linearlayouts. I didn't understand your question. |
I only used The things failed to compile at my side:
Apparently pasting codes in comments is not an efficient way to communicate, is it possible to make a minimal app or to add the case into the demos project? |
Hi, I want flip a view that have many button, example one view have 4 button. How do I make it with your library? Thanks, Panda |
I ran in to this issue when working with HTC One (4.1.2) and Galaxy S4 (4.2.2). Though on those devices the parts of the layouts turned white instead of black, it seems like the same issue. Hardcoding the 5000 inside of FlipRenderer did not have any effect. But switching to the dev branch of the library fixed the problem on both devices. |
Yes, switching to the dev branch solved the problem. |
@cagkanciloglu and @FoamyGuy |
Hi @Devendra321 1.Open https://github.com/openaphid/android-flip |
thank you @cagkanciloglu |
some times black screen seen and some time smoothly load the same image.Generally first time loading appear the black screen. How to solve this problem please help. |
Hello. First thank you for library, its really great. While I'm developing an application I came across a bug in Galaxy S3 phones. While flipping the view invalidates itself and causes black screen. This bug can be seen at the demo also. I uploaded a video on you ube about this bug. You can check it. Thank you in advance. http://www.youtube.com/watch?v=rv0pLLCn-8w
The text was updated successfully, but these errors were encountered: