I have a WebView.
When loading stuff that takes a long time, I want the WebView to be overlaid with a loading dialog that looks like the progress dialog in phones - the one with the circular spinning thing, and darken the screen area that is not covered by the dialog.
Additionally, I want to make it impossible for the user to click on anything on the WebView until it is ready.
How do I achieve this effect in Java 8?
when you need the loading call this
private void inUrFace(){
Dialog<Void> dialog = new Dialog<>();
dialog.initModality(Modality.WINDOW_MODAL);
dialog.initOwner(stage);//stage here is the stage of your webview
dialog.initStyle(StageStyle.TRANSPARENT);
Label loader = new Label("LOADING");
loader.setContentDisplay(ContentDisplay.DOWN);
loader.setGraphic(new ProgressIndicator());
dialog.getDialogPane().setGraphic(loader);
DropShadow ds = new DropShadow();
ds.setOffsetX(1.3); ds.setOffsetY(1.3); ds.setColor(Color.DARKGRAY);
dialog.getDialogPane().setEffect(ds);
dialog.showAndWait();}
double check the code. should give you something of that sort.
Related
I can't see my Vaadin Dialog which I'm trying to add on a simple Vertical Layout
Here is my code:
Dialog d = new Dialog(new Label("Simple label"));
d.setCloseOnEsc(false);
d.setCloseOnOutsideClick(false);
Button cancelBtn = new Button("Cancel", event -> {
d.close();
});
d.add(cancelBtn);
add(d);
I hope anyone can help me :)
Dialog::open
A Dialog is a specific component - it is not normally rendered within the given container, but opens as a popup. Therefore, it has special semantics to make it to render - after creating a dialog, you have to call dialog.open() to make it display.
This is also not specific to Vaadin - in many frameworks, dialogs (and other popups) are displayed in a special manner - it's somewhat of a pattern.
I am having trouble with buttons.
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("assets/uiskin.json"));
Table table = new Table();
table.setDebug(true);
table.setFillParent(true);
stage.addActor(table);
Button button = new Button(skin, "default");
table.add(button);
The code above creates a button with the proper text in center of the screen, but input is broken. When I click on the button, it does not register input. However when I click ABOVE the button, it registers input. What am I doing wrong?
Regarding the code that you posted, you will need to set the input processor to the stage. By doing this, libGDX will use this as a Listener to register events that happen. Try adding this to your block of code:
Gdx.input.setInputProcessor(stage);
Also, if you are not planning on adding other Actors to your Stage, I would just add the Button directly to the Stage.
I have this.setVolumeControlStream(AudioManager.STREAM_MUSIC); at the start of all activities in my application so when the user presses the volume up or down buttons, he controls the media volume.
I have a popup window in my program and when that appears the user can no longer control the volume.
Looking at similar questions it seems that setting up onKeyup/down listeners can interfere with the process - but I have not set any up - the only listeners I have for the popup window are setOnClickListeners for the buttons and a setOnDismissListener for the window.
How can I fix this?
Looks like you have to call setOwnerActivity on the Dialog object.
Documentation from the method:
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.
While not tested, this should do the trick. There is also the possibility to use setVolumeControlStream.
I had been creating the popup window with
my_popup_window = new PopupWindow(layout, x, y, true);
I then change it to this...
my_popup_window = new PopupWindow(layout);
my_popup_window.setWidth(x);
my_popup_window.setHeight(y);
and the volume control started to work again. I don't understand why - but it worked.
I just do this pop.setFocusable(false). and it worked.
though the Mick's answer didn't work for me, this is for posterity.
//Declaration
PopupWindow mWindow;
...
//Constructor
mWindow = new PopupWindow(context);
...
//Prepare to Show
mWindow.setContentView();
mWindow.setBackgroundDrawable();
mWindow.setFocusable(false);
...
setting setFocusable to false helped my activity capture onKeyDown() again.
I want to make an activity that can be opened above ANY app.
Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the background you see the launcher:
BUT, I want the app will go above any app like this: (made in photoshop):
I did see this question Creating a system overlay window (always on top), but in ICS there is no functionallity to the layout.
Furthermore, I want to give a dialog box from my app without minimizing the other app...
there are plenty of apps that show a floating view on top of everything like : airbrowser , LilyPad , Stick it , AirTerm , Smart Taskbar , aircalc ...
anyway , in order to achieve this feature , you must have a special permission called "android.permission.SYSTEM_ALERT_WINDOW" , and use something like that:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().width;
param.height=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
// TODO if you wish to let the view stay when leaving the app, make sure you have a foreground service running.
I'm one of the developers of the Tooleap SDK, and we also dealt with this issue.
Basically, you don't need to use the SYSTEM_ALERT_WINDOW to display an activity on top of another one. You can just display a regular "shrinked" Activity with a transparent background.
To make a "shrinked Activity, change the activity window layout params of height and width:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = ...;
params.y = ...;
params.width = ...;
params.height = ...;
this.getWindow().setAttributes(params);
To make a transparent background add to your activity definition in the manifest file:
android:theme="#android:style/Theme.Translucent"
That way, you can create the illusion of a floating activity:
Note that only the foreground activity will be resumed, while the background one is paused. But for most apps this shouldn't be an issue.
Now all that remains is when to launch the floating activity.
Here is an example of a "floating" calculator app using a regular activity. Note that the activity below the calculator belongs to another app.
What I would like to have is an activity indicator, which is displayed after my app is up and running, but while GWT is making AJAX calls.
For example have a look at following site : http://www.foodtrucksmap.com/#
Any ideas on how to achieve it?
You can use an activity indicator from here, they are animated gifs so you can display one like this:
<g:Image ui:field="activityImage"/>
MyResources resources = GWT.create(MyResources.class);
this.activityImage.setResource(resources.activityImage());
and in your resources interface you would set the image:
public interface MyResources extends ClientBundle{
// use the actual path to your image
#Source("../resources/images/activityImage.gif")
ImageResource activityImage();
}
When you make your async calls:
loadingImage.setVisible(true);
and in the callback:
loadingImage.setVisible(false);
I had to deal with the same kind of stuff few days back. The way I did was, created an Icon and Overlayed on the map.
Icon icon = Icon.newInstance("loading.gif"); // load you gif as icon
MarkerOptions options = MarkerOptions.newInstance();
options.setIcon(icon);
Marker indicator = new Marker(point, options);
So before the Async call and after you map is up, just add the icon to the map using
map.addOverlay(indicator);
and after the Async call remove the overlay using
map.removeOverlay(indicator);
I am not sure how correct this approach is, but this is what I did and it worked.