Let's say,I have a widget that shows the content of my website .
There is a refresh icon png in the left bottom corner of my widget.
Now,I would like the refresh icon rotate itself until I get content from my server.
How can I do ?
Use AsynkTask, start Rotation animation in onPreExecute() and stop animation in onPostExecute() method
You cannot modify the view directly because the view within a widget is placed outside your process (outside your address and memory space).
The widget view is placed within some system process and system makes all the calls to the android.view.View or android.view.ViewGroup directly.
Android allows external processes access these 'embedded' views by using RemoteViews class.
The RemoteViews class represents a set of actions that system should do in order to modify the internal view. For example RemoteViews.setViewVisibility() is an equivalent of View.setVisibility().
Now once you have the above in mind you see that there's no way of overriding view classes in the view hierarchy (because there is no simple enough way of transferring that class override down to a system process and make system use that implementation instead of the "stock" one).
As a solution to your problem you have two views in the view hierarchy.
The one would be the rotating button and the other the button which reacts to touches.
When user touches the button view you then hide it and show the rotating view. Upon server's response you would hide first view and show the button view back again.
Related
I've design the user interface of my app as a collection of views, not activities or fragments. I manage the showing and hiding of views on this collection of views which are right on top of each other.
I believe I chose the wrong design principle to use for my app. The problem I am having is that when I hide a view in order to show another one; the button that resides on the hidden view fires its on-Click listener.
After reading some of the Android Reference documentation, I see that the view tree will navigate down the hierarchy of views in order to consume the touch event. It is then that the on-Click listener of this button is called.
What I need is something to prevent the button from the hidden view to stop calling itself when the user touches the shown view. I know that calling setVisibility(View.INVISIBLE) stops the on-Click listener from being called.
I was thinking of the ViewTreeObserver class that will allow me to create a listener of view hierarchy that somehow allows me to get a handle of all the hidden views in order to call setVisibility(View.INVISIBLE) on the hidden views.
Any ideas or advice
When you do setVisibility(View.INVISIBLE) for a view, it will still present in the layout. So instead of setVisibility(View.INVISIBLE), try setVisibility(View.GONE).
This will remove the view completely from the layout including the onClickListner attached to it.
When you want that view back, you can use setVisibility(View.VISIBLE) to get it back.
Take any view on the UI. It could also be any level of nesting into a page's layout. After double-tapping the view, have that view (or copy) float and popup into the center of the screen like a dialog.
It doesn't need to be a dialog though. The requirement however is that all threads in the current activity (UI and background) cannot be interrupted (not a dialog, not another activity).
My current plan is to dynamically add a floating XML layout like RelativeLayout into the supermost layout of the current page (with/without an overlay on the entire page to block views from being touched). This floating clone will have highest elevation; drop shadows aren't important. The target view is a 3rd-party plugin view called LineChart from MPAndroidChart. I want to copy all of its data into this clone, detach/redirect the original from its accessors and hide it because it's being accessed and fed data (possibly delete it if the clone has data integrity for a copyback).
This is definitely an option, but I wanted to know if there a native (...maybe a plugin) class that has support for popping out any view (while unaffecting current context and not stopping the UI or other threads).
I am creating a custom view(extends WebView). I want to listen the viewable state of the view.
Viewable state means whether or not the view is showing on the screen. I didn't mean the Visibility. Such as, the view is under a ScrollView, when user scroll and the view will be scrolled out of the screen. Its visibility is not change, it's still visible but is not viewable because it is scrolled out of the screen.
Is there anyway to listen the viewable change?
Since WebView inherits from View it seems to me you can override the View methods to monitor what you like. Check developer.android.com's View documentation and check the methods under 'Implementing a Custom View'. For your scrolling example it seems like you can override the onScrollChanged method.
I have found how to create a translucent background for my android app, but so far I haven't found how to interact with what's behind it (the home screen for example).
This post helped me make the app view translucent.
How would one go about allowing the user to interact with what's behind the translucent app? This app is a good example of an app that allows this is the "Transparent Screen" Android app.
A very simple way of understanding stacking of views is to take a book (any book). Think of each page as a view.
Visibility
When you open the book you can see a page (Main View - VISIBLE)
When you turn the current page you can see the next page (INVISIBLE - Main View to show the next view. Remember you are only hiding the view, if you set the visibility to GONE this is equivalent to tearing of the current page to view the next page.)
Touch scenarios
Assume your first page is a wax page (translucent page similar to your translucent view) so you can see the underlying page
When you try to touch a figure on the second page, you are touching the first page although you can see the figure on the second page. It is impossible to touch the figure on the second page through the first page.
Don't be disheartened, since it is a view you will be dealing with and not a paper you can still do what you want to do :)
Implement View.OnTouchListener for both your views
For translucent view any touch events you get, return FALSE in the method onTouch
Android will pass on the touch event to your underlying view.
I got the answer.
Adding line getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
in onCreate in second top activity(which is transparent did the trick).
Above solution has a problem. After using above whole window passes the touch to background. So if you want full control then better extend a layout e.g. Framelayout and override 'onTouchEvent' and get the touch location using event.getX() and event.getY() methods and return false where you want to pass the touch event. It will be passed to parent view.
FLAG_NOT_TOUCH_MODAL will do what you want with the least code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
...
setContentView(R.layout.my_activity_view);
...
}
public static final int FLAG_NOT_TOUCH_MODAL
Window flag: Even when this window is focusable (its {#link
FLAG_NOT_FOCUSABLE is not set), allow any pointer events outside of the window to be sent to the windows behind it. Otherwise it will
consume all pointer events itself, regardless of whether they are
inside of the window.
I have a ListView and each item contains a TextView displaying a number. I'd like to give my users the ability to change this number while staying on the ListView (as opposed to drilling down into a detailed view by clicking on the list item).
What I'm looking to do is to slide in a layout from the bottom of the screen that covers about half of the screen. I'd like this layout to be OVER the Activity behind it (as opposed to being part of that Activity's layout and simply showing it). I'd also like it to be model (or seem modal). Meaning the Activity behind it can not be focused and manipulated. In this layout I will essentially create a calculator.
What I need help with right now is:
1) How to display a layout over the current Activity
2) How make the background (the Activity) modal
Could someone point me to some tutorials/resources and/or give me a few tips?
use an Animation. here is a small tutorial on them: http://developerlife.com/tutorials/?p=343
initially, the view you want to be modal must be placed where you want it to show up(and visibility set to gone).
use a translate animation to visually move the view from below the screen to halfway up the screen. once the animation starts, set visibility to visible
try disabling all views that the user should not be able to interact with after you have started the animation holding the calculator view