The past few months I've been on a mission to implement widget support in my home screen replacement for Android, and it's proving rather difficult. I can now add and remove widgets to/from the home screen, but they can't be resized or moved yet. Currently what I'm trying to achieve is to resize them. To do this I have every widget embedded in a View, over which I put an overlay to make sure the touch events don't get caught by the widget underneath it (which caused trouble in past attempts).
What I have now is this layout for the container; http://www.hastebin.com/uwocaxukel.xml
The widget is put in the FrameLayout with id widgetContainer. As you can see in the screenshot below there is an orange dot in the middle of every border.
Now what I've always tried to do so far is catch touch events, figure out whether the user is trying to drag one of the borders (MotionEvent.ACTION_MOVE), and if he is, change the required properties in the LayoutParams object and call this.requestLayout () on the view. This is finicky, and less than ideal. Very often the touch events would stop registering because the user dragged faster than the view could refresh = user is no longer on the view which is listening for touch events, or the border would be too thin to hit.
So far it's all been very finicky. But there are other apps which seem to do this pretty much perfectly. Is there a library, a class I've overlooked, or something else I can use to achieve my goal?
This is an example of something that kind of worked, but was very finicky and just not remotely user-friendly; https://github.com/RobinJ1995/be.robinj.ubuntu/blob/869d48af2e7a3d8f0332f84edd2a8cd28564424a/UbuntuLauncher/app/src/main/java/be/robinj/ubuntu/widgets/WidgetHostView.java#L75
Related
I have a RecyclerView which has a several View Holders and some of them are horizontally scrolling. To improve the usability of my application, I need to detect the scroll based on angle (say 30 degrees to X axis) and depending on that, assign that to child's Horizontal scroll or let it's parent's vertical scroll handle it.
From #suragch's answer https://stackoverflow.com/a/46862320/10165076, I understood we can intercept the touch event of the parentView, but I have a hard time coding that. If you can please help me here, it would be much appreciated.
Edit: Going further deep into usability, I need this to work smoothly even when the parent view is moving with the momentum of the fling.
Of the apps that I know, the Play Store app handles this perfectly, I tried to search for a solution online, but none of them could provide an approach that works as well as the Play Store does.
I have created an overlay menu that is a rectangle.
It displays on top of everything else while active. All other apps, the home screen, etc.
If you click anywhere outside of this rectangle your click hits
whatever is visible.
If you click the red part it allows you to drag the menu around the
screen. Clicking the green part performs some function.
I have created this rectangle from inflating layout xml. The rectangle itself is a relativeLayout and the green and red parts are both imageView children.
Since I'm unable to move the relativeView off screen and since the background needs to be clickable my only solution was to calculate margins and apply them to the relative view to imitate the desired effect.
However, the code to calculate these margins is almost 50 lines and fairly complex and hard to understand at a glance if someone else needs to refactor. I can post the code but I don't believe it's relevant to the actual problem's context.
Is there a much simpler way to do this that I'm missing? Is my approach wrong?
I hope this simple project may help you Android Floating Widget
I'm trying to create an universalish tab widget in libGDX. It contains a button bar and a pane bar and a pane view.
Lets assume the tabwidget is as big as the screen, and we have 3 tabs. The buttonbar takes up the top part of the screen, and the panes are in the bottom part. The paneView is a WidgetGroup for event handling, it is as big as the tabwidget minus the buttonBar.
Everything works just fine until I add an a scrollpane as a tab widget. Since this scrollPane calls:
event.stop();
the subsequent events are not called.
Since events "bubble" up through actors, the lowest level actor is handled first calling the event handlers of its parents and siblings upwards. This means the scrollpane is always handled before the tabwidget.
Is there a way to intert the order of the input listeners? Have the tab input be handled first and then the scrollpane input? Or will I have to reimplement the scrollpane handlers to get around this issue?
I think that the way you want to implement this is rather impossible - how actors would know if the fling gesture you are performing is addressed to which?
The resolution that comes to my mind is to
Create new stage being input processor (if it will be second inputProcessor you will need InputMultiplexer )
Implement GestureDetector and then detect horizontal swipes and react with moving group - read this tutorial to get more information
In my opinion it is generally not good idea to modify libgdx sources but of course you can do it (by downloading LibGDX from Github and import it as project you will have access to all sources) although in this case it is definitely unnecessary.
I am designing my activity screen using eclipse but whenever I move an object e.g. a button it snaps around and I find it hard to position things where i want them.
Is there some setting I can change as as soon as I add a second button it snaps the other button to another position it is so annoying!
Also if I have an image button why can't i resize this, even with a normal button if i try to make it larger it just fits to the text and wont make the button bigger or it just flicks to a random place on the activity?
thanks
Probably you're trying to place components freely in the View but you're not considering the LayoutManager behavior. If you try to position your component in a LinearLayout, for example, the components will be placed following its rules, and these components will not stay where you drop them.
Try to understand better how the layouts works on Android. But for now, the AbsoluteLayout or RelativeLayout may be what you're looking for.
About the components size, you'll need to understand better how to use layout properties for these components. See the question How to size buttons for more information.
I have to develop a touch screen application based on swing for the GUI part.
The application will have to be displayed on different screen, one 15" 4/3 screen and one 20".
What kind of layout stategy should i go for, to keep the same proportion in my components from one screen to another ?
The application will have a kind of status bar at the top displaying some information coming from a server, a menu bar at the bottom, the main central part of the application will display graphs, and on the right an area that will display the same information as the graphs, but in digital format. Buttons from the menu bar and labels in display/status bar have to be quite big as the users that will play with the screen may wear gloves...
Thanks you for help.
any specific layout manager is not gonna do the trick....Handling the window size is not a problem as that can be taken care of (use ToolKit for that). Only problem is that u gotta make sure that, the component sizes are not fixed, cos when screen size changes that gotta change as well. This is a peculiar problem, lot of trail and testing may be required.