Large Image Scrolling Using Low Level Touch Events

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby pskink » Fri Apr 09, 2010 8:46 am

which image do you mean?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby alejo » Fri Apr 09, 2010 6:36 pm

I've been trying to solve it... with very little success, yet.

So, your code works perfectly fine when loading and drawing the grid.
The problem comes when I try to load a 1100x1600 image, I remove the translation, so that it snaps to the upper left corner and it works like a charm on any device, but on milestone.
I've been playing with the emulator and it looks as if milestone was actually zooming the image by itself. I need to modify the image Width at Scrolltest.java to 1600x2100 if I want to see the whole image loaded.

Unfortunately, this would cause an empty space to be loaded on other devices with different screen resolution.
alejo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Mar 31, 2010 9:08 am

Postby ajvan » Mon Apr 12, 2010 12:38 pm

Hi everybody,
i have one question..is it possible to have some other components on the display beside canvas (for example buttons, textboxes on the top of the screen, or at the end of the screen, or even both, like text, canvas (scrollable), button?)
thanks
ajvan
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Mar 13, 2010 10:36 am

Postby appguy » Sat Apr 24, 2010 10:19 pm

This was an awesome tutorial. Thanks so much! Do you have a similar sample for zooming in and out for a large image?
appguy
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Apr 24, 2010 10:17 pm

Postby TylerDurden » Mon May 03, 2010 8:15 am

hi guys,

first of all, anndev is really greate source for android development.

iam using the scroller.java and modified the component to let them draw only the area that is visible.
Its hard for me to describe, my english isnt that good.

So basicly i have a virtual heigt and width, and only paint the area (painting rects, text ...)
to the visisble area, so i can have really big content with the same speed as smaller content.

but now i noticed that the scrolling isnt smooth, its like the app launcher on the nexus => its stutter.

Any ideas ?

here are some code samples, i really hope anyone can help me... i played with threads and the surfaceView but nothing helps...

My Start Actvivity called "Home"

public void onDraw(Canvas canvas, Matrix matrix)
{
// a simple class that draws
this.mCurrentPage.Render(this, GetVisisbleArea(), canvas);
}

private Rect GetVisisbleArea() {
Rect result = new Rect();
result.top = Home.mScroll.mScroller.getCurrY() * -1;
result.bottom = result.top + Home.DISPLAY_HEIGHT;
result.left = 0;
result.right = Home.WIDTH;
return result;
}

Thanks a lot!!!!!
TylerDurden
Freshman
Freshman
 
Posts: 4
Joined: Mon May 03, 2010 8:06 am

Postby pskink » Mon May 03, 2010 8:37 am

TylerDurden wrote:private Rect GetVisisbleArea() {
Rect result = new Rect();


don't create new Rect each time you call GetVisisbleArea(), make it a field
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby pskink » Mon May 03, 2010 9:13 am

TylerDurden wrote:public void onDraw(Canvas canvas, Matrix matrix)


also, if you want to get translation and scale use provided matrix param (but don't change it in any way!)
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby TylerDurden » Mon May 03, 2010 10:24 am

Thanks a lot, i will try this and post a reply tonight. (in 7 hours ;))

Have a nice day!!

see you later
TylerDurden
Freshman
Freshman
 
Posts: 4
Joined: Mon May 03, 2010 8:06 am

Postby TylerDurden » Wed May 05, 2010 7:51 am

Hi pskink,

ive changed that and now its much smoother. Thanks a lot and have a great day!!

Regards,
Denis
TylerDurden
Freshman
Freshman
 
Posts: 4
Joined: Mon May 03, 2010 8:06 am

Postby TylerDurden » Wed May 05, 2010 5:28 pm

its me again ;)

ive notice that the onLongPress method isnt called.
how i can make this work ?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void onLongPress(MotionEvent e) {
  2.  
  3.  
  4.  
  5.                 Toast.makeText(this.mContext, "LongPress", Toast.LENGTH_LONG);
  6.  
  7.                
  8.  
  9.         }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
TylerDurden
Freshman
Freshman
 
Posts: 4
Joined: Mon May 03, 2010 8:06 am

Postby at_198x » Wed May 12, 2010 3:43 am

Sorry if my question is stupid, but when i use BitmapFactory to load an image with 1200x700 resolution, i found out the bitmap is smaller than my image. I use System.out.println() to check the width and height of bitmap and it's only 800x467, in both landscape and portrait. How can i get the actual resolution of an image in code?
at_198x
Developer
Developer
 
Posts: 29
Joined: Tue Apr 27, 2010 4:48 am

Re: Large Image Scrolling Using Low Level Touch Events

Postby at_198x » Fri May 21, 2010 3:33 pm

Does no one can help me?
at_198x
Developer
Developer
 
Posts: 29
Joined: Tue Apr 27, 2010 4:48 am

Re:

Postby ekimia » Mon May 24, 2010 11:32 pm

ajvan wrote:Hi everybody,
i have one question..is it possible to have some other components on the display beside canvas (for example buttons, textboxes on the top of the screen, or at the end of the screen, or even both, like text, canvas (scrollable), button?)
thanks


Im also interested in this, im making a map application and want to have little icons for the user to press which will bring up information.
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Re: Large Image Scrolling Using Low Level Touch Events

Postby missme » Wed Jun 09, 2010 5:15 am

I use a 3.2M image;
It has a error;
06-09 04:11:36.230: WARN/dalvikvm(238): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-09 04:11:36.239: ERROR/AndroidRuntime(238): Uncaught handler: thread main exiting due to uncaught exception
06-09 04:11:36.280: ERROR/AndroidRuntime(238): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.nativeCreate(Native Method)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at org.image.scroller.LargeImageScroller$SampleView.<init>(LargeImageScroller.java:62)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at org.image.scroller.LargeImageScroller.onCreate(LargeImageScroller.java:38)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.os.Looper.loop(Looper.java:123)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at java.lang.reflect.Method.invoke(Method.java:521)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at dalvik.system.NativeStart.main(Native Method)
missme
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Sep 11, 2009 12:00 pm

Re: Large Image Scrolling Using Low Level Touch Events

Postby ekimia » Tue Jul 06, 2010 7:11 pm

The image you are using is maxing out the memory. Its possible to use a 3.2M if the system has enough resources.

missme wrote:I use a 3.2M image;
It has a error;
06-09 04:11:36.230: WARN/dalvikvm(238): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
06-09 04:11:36.239: ERROR/AndroidRuntime(238): Uncaught handler: thread main exiting due to uncaught exception
06-09 04:11:36.280: ERROR/AndroidRuntime(238): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.nativeCreate(Native Method)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at org.image.scroller.LargeImageScroller$SampleView.<init>(LargeImageScroller.java:62)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at org.image.scroller.LargeImageScroller.onCreate(LargeImageScroller.java:38)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.os.Looper.loop(Looper.java:123)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at java.lang.reflect.Method.invoke(Method.java:521)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-09 04:11:36.280: ERROR/AndroidRuntime(238): at dalvik.system.NativeStart.main(Native Method)
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests