I'm doing a live wallpaper. However, what is initially shown depends on the number of home screens.
While onOffsetsChanged() allows you to calculate the number of home screens, it gets called only if the user scrolls the homescreen.
So is there a way to get the current xStep and xOffSet without calling onOffSetsChanged()?
Edit: I may not need to know that per se. Here's what I'm doing: I'm basically drawing a portion of the bitmap. The portion shown depends on the current homescreen.
Edit 2: so to explain what I'm trying to do---I'm basically trying to mimick the scrolling wallpaper effect but with a video. The point is that the portion shown depends on the current homescreen. Here's the problem: So the user selects the wallpaper. OnSurfaceCreated() is called, followed by onSurfaceChanged(). However, onOffSetsChanged() is never called until the user tries to scroll the homescreens. That's the problem. You don't know what part of the bitmap/video to display until the user scrolls the screen. (So Josh's suggestion doesn't work. The part of the video that's displayed may be wrong---until the user scrolls the screen and we get the correct onOffSetsChanged() values.)
Your edit doesn't really explain why you need to know how many screens there are. You can draw the center portion of your bitmap initially, then when xOffset changes to something like 0, draw the leftmost portion of your bitmap. What's the issue?
Related
I am with a really serious help and want to know if you can help me.
As App Inventor has some 'Capacity Issues' I cannot create lots of Screens in my project. So, one of my screens is a 'Dynamic One', which receives a StartValue from another one and acts according to this value.
This 'Dynamic Screen' has one Canvas and Two ImageSprites. Depending on which value this Screen receives, a different background image is used in the Canvas component and I have to move the two image Sprites to different positions in the Canvas. I did this because these two ImageSprites are buttons in specific parts of the image that will open an ActivityStarter that runs the youtube application in a given URL. The ImageSprites positions, the canvas background and video that will played when the canvas is pressed will depend of course on the input.
My problem here is that I cannot move these sprites this way (dynamicaly depending on StartValue the Screen receives), it simply doesn't work (I think it is a bug). I tried everything, setting ImageSprite.x, ImageSprite.y, use functions ImageSprite.Moveto, ImageSprite.PointTowards, it simply doesn't work if the Screen receives an StartValue.
If I am on 'Blocks' tab and click with right button on the function ImageSprite.MoveTo and select 'Do It', the ImageSprites can be moved. Also, if I access the 'Design' tab and inform which Background will be used in Canvas, the ImageSprites are also moved without problems (I don't want this scenario, I want the background changing depending on StartValue).
Below is my 'Blocks' Tab, what is wrong here? is this a bug? can you please help me with this issue? how can I move the ImageSprites on a Canvas depending on which StartValue a screen receives?
I don't know how to explain this.
But take Android desktop as an example.
When you move your finger, you move the whole desktop, until a point that you're on the next desktop. So as you can see, if you move the screen, for about 51% to the right, when you leave your finger off the screen, it will go to the right screen, and if you just moved the screen 40ish percent, it will be back on the same screen.
How is this pattern called?
Some sort of "predicting" users movements.
Maybe you are talking about the Location Within pattern:
Problem:
You must describe the location within a series of screens which
contain alternate views, or which continue the display of a set of
content.
Solution:
When several screens of similar or continuous information are
presented with an organic access method, an indicator is usually
required so the user understands their position within the system.
Other sources might call such a thing "carousel" or "slideshow".
Updated answer:
After reading more carefully, "Location Within" might only reference the page position indicators that show which screen is currently in view. Perhaps just the Slideshow or Film Strip patterns describe more exactly what you mean.
As FoamyGuy pointed out in a comment, ViewPager is the way to implement "slideshows" in Android.
Additionally, ViewPagerIndicator provides flexible options to display the page position indicators ("Location Within" pattern)
I'm working on my Live Wallpaper and I want it to scroll with the screen like a normal wallpaper does. I know I need to use onOffsetsChanged() but which parameter will tell me the direction that the home screen is being swiped? It seems like xOffset always returns a positive value no matter which way the screen slides.
Thank you.
The direction alone will not help you: you need to know the exact offset, because the user may have jumped several screens at once (e.g. by using a pop-up that displays mini-versions of all the home screens).
Generally speaking, you want to save the xPixel value you get in onOffsetsChanged, then use this to translate your canvas.
See my two answers below:
onOffsetsChanged: move Bitmap
android live wallpaper rescaling
I'm new to Android application development and I'm currently experimenting with various UI ideas. In the image below, you can see a vertically scrolling list of horizontally scrolling galleries (and also textviews as you can see). I'm also doing some matrix and camera transformations which I will come to in a minute.
For the background of the list elements, I use green. Blue is the background of the galleries, and red is the background for the images. These are just for my benefit of learning.
The galleries being used are extended classes where I overrode the drawChild method to perform a canvas scale operation in order for the image closest to the center (width) to be larger than the others.
The list view going vertically, I overrode the drawChild method and used the camera rotations from lack of depth dimension in the canvas functionality. The items in the list are scaled down and rotated relative to their position's proximity to the center (height).
I understood that scrolling and clicking would not necessarily follow along with the image transforms, but it appears as though the parent Gallery class's drawing is constrained to the original coordinates as well (see photo below).
I would love to hear any insight any of you have regarding how I can change the coordinates of the galleries in what is rendered via gallery scroll and the touch responsiveness of said gallery.
Images in the gallery are not same dimensions, so don't let that throw you in looking at the image below
Thanks in advance!
Ben
link to image (could not embed)
-- Update:
I was using my test application UI and noticed that when I got the UI to the point of the linked image and then I touched the top portion of the next row in the list, the gallery updated to display the proper representation. So, I added a call to clearFocus() in the drawChild method and that resulted in more accurate drawing. It does seem a tad slower, and since I'm on the Incredible, I'm worried it is a bloated solution.
In any event, I would still appreciate any thoughts you have regarding the best way to have the views display properly and how to translate the touch events in the gallery's new displayed area to its touchable coordinates so that scrolling on the actual images works when the gallery has moved.
Thanks!
As I updated earlier, the issue of the graphics of the gallery not fully refreshing was resolved by calling clearFocus in drawChild method for the ListView extending class.
The problem with registering the touch events turned out to be where I had used an example for the basis of my experimental program which called a pre-translation on the matrix used for painting. Once I removed that call and adjusted the post-translate call to compensate not having the pre-translate call any longer, I was able to scroll through the galleries regardless of their position, size or rotation (around x axis).
I am relatively new to Android. I am working on an application wherein
i want to display digital signals. But the problem is once I occupy
the available screen width how to i add a scrolling feature to
continue viewing the signal. Also i am drawing the signal using using
drawLine(), so what co-ordinates should i set for drawing the lines
when scrolling is enabled? Can somebody please give a simple example
where a line extends more than the available screen width and you can
scroll through to see the remaining line.
Thanx in advance.
I've written a few of these before in other languages, so I can ive you the principles, rather than an example. I'm assuming you have some sort of buttons to the left and right that allows the user to scroll through the data, and that your signal data is stored in an array. You will be able to determine how much data you can fit into one screen width based on whatever scaling factor you are using. Say your screen can display ten values at a time, then you simple store the starting point in your signal array and use that as the left most point to display on your screen. Then all you have to do is show the next ten values in your array. When the user selects the button to move left or right through the data simply increment or decrement the starting point. If you are streaming in your signal, then the stream can increment the starting point whenever you receive a new piece of data. A redraw after each start value change will give the impression of scrolling. Watch out for start and end conditions (i.e. you don't want to scroll until you have at least a full screen of data). All you are doing is creating a window onto the data you have.
Hope this helps.