I am developing a GWT application that render a text on a canvas. I want to resize the canvas whenever browser window resized. The problem is if I used Window.addResizeHandler, the rendering process with each resize will be very slow. So I need a way to resize the canvas only when the user release the mouse button after finishing resize. Is there anyway to do that?
You could add a delay, so that the resize is only processed after the window hasn't been resized for some number of milliseconds:
Window.addResizeHandler(new ResizeHandler() {
Timer resizeTimer = new Timer() {
#Override
public void run() {
doComplexLayoutCalculations();
}
};
#Override
public void onResize(ResizeEvent event) {
resizeTimer.cancel();
resizeTimer.schedule(250);
}
});
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
Scheduler.get().scheduleDeferred(
new Scheduler.ScheduledCommand() {
public void execute() {
// layout stuff
}
});
}
});
Related
I want my dialog to stick to the start but it always comes in the center.
i will give you example==>
Following is the code -->Onclick image -->Dialog Appears==>
Dialog dialog; //your dialog declaration
//
//
//
oncreate(){
imageView = (ImageView) findViewById(R.id.customProfileGridImg);
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.START |Gravity.TOP; //change direction as per your requirement
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.show();
}
});
}
There is a bug in my code: When I release the mouse out of the screen, the unity can't detect "GetMouseButtonUp", and when I move the released mouse back to the screen, it detects the "GetMouseButton" which should not.
So when the mouse out of the screen, I want simulate send a mouse up event to let the unity detect "GetMouseButtonUp".
How to simulate a mouse event?
Pseudo code
bool mouseIsDown = false;
public void Update()
{
Rect screenRect = new Rect(-Screen.width/2, -Screen.height/2, Screen.width, Screen.height);
If(screenRect.Contains(Input.mousePosition))
{
if(mouseIsDown && !Input.GetMouseButton(0))
OnMouseUp();
if(Input.GetMouseButton(0))
{
OnMouse();
if(!mouseIsDown)
{
OnMouseDown();
mouseIsDown = true;
}
}
}
}
public void OnMouseDown()
{
// Do something
}
public void OnMouse()
{
// Do something
}
public void OnMouseUp()
{
// Do something
}
I am not sure if I correctly understand your question. But, you can use these functions the same way you would use the Start() Update() Awake() etc. functions
void OnMouseUp () {
}
void OnMouseDown (){
}
Just like new google guidelines I want to hide actionbar on listview scroll.
I have succeeded in implementing the same but if I scroll slowly the actionbar flickers. How can provide smooth animation on its show and hide.
This is my code
lv.setOnScrollListener(new OnScrollListener() {
private int mLast;
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
if (mLast < firstVisibleItem) {
if (getSupportActionBar().isShowing()) {
getSupportActionBar().hide();
}
}
if (mLast > firstVisibleItem) {
if (!getSupportActionBar().isShowing()) {
getSupportActionBar().show();
}
}
mLast = firstVisibleItem;
}
});
I have even tried putting these value for listview
android:clipToPadding="false"
But it just doesn't seem to work.
I have a clickhandler for a button. I want the screen scrolls to an anchor like
Anchor a = new Anchor();
a.setName("stopHere");
(...)
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// Do somethings
(...)
// Scroll to Anchor "stopHere"
?????
}
});
How can I do it?
This is similar when using an anchor click to go to stopHere point , but I wan do it next the button is clicked.
Thanks.
The method Element#scrollIntoView() should do what you want:
final Anchor a = new Anchor();
a.setName("stopHere");
button.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event)
{
a.getElement().scrollIntoView();
}
}
Or use Window#scrollTo(int, int)
final Anchor a = new Anchor();
a.setName("stopHere");
button.addClickHandler(new ClickHandler()
{
#Override
public void onClick(ClickEvent event)
{
Window.scrollTo(a.getAbsoluteLeft(), a.getAbsoluteTop());
}
}
I am programatically showing the soft keyboard when a layout is loaded on a button click.
I am showing the softkeyboard only when the textfield has focus. It works fine. But when I call the same method at another place in the code(not a button click) then the soft keyboard does not show up. Below is my code. Please point out where I went wrong.
public void showNewView() {
setContentView(R.layout.activity_main);
this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
isRegisterScreen = true;
final EditText text1 = (EditText) findViewById(R.id.label1);
final EditText text2 = (EditText) findViewById(R.id.label2);
final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
text1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(labelText, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(text1.getWindowToken(), 0);
}
}
});
text2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
inputManager.showSoftInput(text2, InputMethodManager.SHOW_IMPLICIT);
}else{
inputManager.hideSoftInputFromWindow(phoneText.getWindowToken(), 0);
}
}
});
text1.requestFocus();
}