I want to disable a button before calling a method.
In other words, I want to execute some codes as linear.
Here is the code
#Listen("onClick = #kodIsteButtonId")
public void kodIste() {
k = kd.findKisiByKullaniciadi(kullaniciadiId.getValue());
if (k == null) {
Messagebox.show("Böyle bir kullanıcı bulunamadı!", "Hata Mesajı",
0, Messagebox.ERROR);
} else {
kodIsteButtonId.setDisabled(true);
countDown(10, 6, k);
}
}
private void countDown(int fromToZero, int sleepTime, Kisiler k) {
tempPassword = rasgeleYeniSifre();
sendEposta(k.getEposta(), tempPassword);
alert("Güvenlik kodu e-postanıza gönderildi.");
while (fromToZero > 0) {
try {
Thread.sleep(sleepTime * 1000);
} catch (Exception e) {
e.printStackTrace();
}
fromToZero--;
}
sifreAlButtonId.setDisabled(false);
clearButtonId.setDisabled(false);
kodId.setDisabled(false);
}
When I click the button I want to see it disabled.
But after running the countDown() method, it is still enabled.
What could be the reason?
The reason is that the button disable the moment you get an answer back from the server.
For your case this is the moment that public void kodIste() is finished.
The most easiest solution is to use the autodisable :
<button autodisable="self" />
This disable and enable the button automaticly.
If you want to control when the button has to enable itself again you can do :
<button autodisable="+self" />
Documentation can be found here.
Related
I'm tryng to handle a click event that does not clicked on a sprite.
My first aproach would be handling normal JS events:
class EditorListener {
constructor(editor) {
...
if(window) {
window.addEventListener('click', this.onWindowClick.bind(this));
}
}
onWindowClick(event) {
if(event.target && event.target.tagName == 'CANVAS') {
Events.fire(EventType.CLICK_NOWHERE);
}
}
}
...
The problem is that this is called when I click sprites.
The goal is to simply close a dialog when I click nowhere.
Tap anywhere and run the function:
game.input.onTap.add(onTap, this);
function onTap(pointer)
{
}
Tap on these objects and run the function onDown
// enable input for some objects
yourObject1.inputEnabled = true;
yourObject2.inputEnabled = true;
yourObject1.events.onInputDown.add(onDown, this);
yourObject2.events.onInputDown.add(onDown, this);
function onDown(object, pointer)
{
// on down function
}
I have a modal Navigation page with an image which acts like a button;
<Image Source ="share.png" HeightRequest="32" WidthRequest="32">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="On_Share" />
</Image.GestureRecognizers>
</Image>
And the method behind;
async void On_Share(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
var message = "Share this";
var title = "Share";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title}, new ShareOptions { ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } });
}
else
{
NoInternetLabel.IsVisible = true;
}
}
I'm getting the error when I try to click on the share image/button. I've put breakpoints into the first line of the On_Share method & they're not being hit.
Warning: Attempt to present <UIActivityViewController: 0x141b60f70> on <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x1419a0920> whose view is not in the window hierarchy!
Please note this works fine in Android, I'm only seeing issues in iOS. I'm not sure what is going on - I'm not trying to present any other windows or anything when I click the image. Regardless, the error appears before the process reaches the beginning of the On_Share method. What am I missing here?
EDIT: The method does get hit now, and I'm still getting the error. It must be trying to send up the share sheet and failing...
There was a problem with the Share plugin in the end - we resolved it by making part of the code recursive.
the GetVisibleViewController used to look like this;
UIViewController GetVisibleViewController()
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
if (rootController.PresentedViewController == null)
return rootController;
if (rootController.PresentedViewController is UINavigationController)
{
return ((UINavigationController)rootController.PresentedViewController).VisibleViewController;
}
if (rootController.PresentedViewController is UITabBarController)
{
return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
}
return rootController.PresentedViewController;
}
whereas it needed to cycle through to find the top UIViewController;
UIViewController GetVisibleViewController(UIViewController controller = null)
{
controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;
if (controller.PresentedViewController == null)
return controller;
if (controller.PresentedViewController is UINavigationController)
{
return ((UINavigationController)controller.PresentedViewController).VisibleViewController;
}
if (controller.PresentedViewController is UITabBarController)
{
return ((UITabBarController)controller.PresentedViewController).SelectedViewController;
}
return GetVisibleViewController(controller.PresentedViewController);
}
I've raised the issue and submitted a pull request on the github
I would like to freeze Vaadin CountdownClock component and/or count down text before Count Down is ended on click button. Can you help me to understand, which listeners or events can I establish/fire? After stop count down I would like to know if Count down is 0 or it was stopped.
There is code for button and reset Count Down.
// button for stop count down table
stopCountDown.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
#Override
public void buttonClick(ClickEvent event) {
try {
countDownClock.setImmediate(true);
// hide count down clock, better would to freeze the text
countDownClock.setVisible(false);
// force stop count down
countDownClockEndEvent.countDownEnded(countDownClock);
LOGGER.info("Inside click listener of stopCountDown button." + countDownClock.getState().);
// TODO manage confirmation - get the actual course and realize conversion
}
catch (Exception ex) {
LOGGER.error("Exception inside refresh table listener", ex);
showNotification("Error:" + ex.getLocalizedMessage(), Type.ERROR_MESSAGE);
}
}
});
Count Down establish:
private void resetTimer() {
countDownClock = new CountdownClock();
ratesVerticalRight.addComponent(countDownClock);
countDownClock.setEnabled(false);
countDownClockEndEvent = new EndEventListener() {
//#Override
public void countDownEnded(CountdownClock clock) {
LOGGER.info("Inside countDownEnded.");
showNotification(
"Time is out or confirmed <br />"
+ "next try... <br />", Type.HUMANIZED_MESSAGE);
}
};
countDownClock.addEndEventListener(countDownClockEndEvent);
System.out.println("State of clock: " + countDownClock.getState().enabled);
countDownClock.setEnabled(true);
//event.getButton().setEnabled(false);
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, 3);
countDownClock.setDate(c.getTime());
countDownClock.setFormat("<span style='font: bold 20px Arial; margin: 10px'>"
+ "Countdown in %s.%ts seconds.</span>");
}
I am currentlky trying to hide and show my application in Fullscreen.
I started a new FullScreenActivity according to the Eclipse templates.
This is the code I use to show / Hide the ActionBar + NotificationBar
public void hide() {
if ((mFlags & FLAG_FULLSCREEN) != 0) {
mActivity.getSupportActionBar().hide();
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(false);
mVisible = false;
}
public void show() {
if ((mFlags & FLAG_FULLSCREEN) != 0) {
mActivity.getSupportActionBar().show();
mActivity.getWindow().setFlags(0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(true);
mVisible = true;
}
It kinda work but my big issue is that the ActionBar is overlapped by notifications:
Any idea on what is wrong?
Self answer:
I had to remove these lines that were automatically generated in the template:
if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) {
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
me again,
I have a current page containing a usercontrol which lists buildings.
Here is a screenshot: http://i40.tinypic.com/2eusoyt.png
Now, my mentor asked me to build a button which allows the user the make the page show the properties in 2 columns.
How did I try this?
I tried putting the following in my Page_load:
if (ViewState["numberOfColumns"] != null)
{
numberOfColumns= Int32.Parse(ViewState["numberOfColumns"].ToString());
}
else
{
ViewState["numberOfColumns"] = 1;
numberOfColumns= 1;
}
Then behind the button view I put this code:
protected void btnView_Click(object sender, EventArgs e)
{
switch(numberOfColumns)
{
case 1:
numberOfColumns= 2;
ViewState["numberOfColumns"] = numberOfColumns;
break;
case 2:
numberOfColumns= 1;
ViewState["numberOfColumns"] = numberOfColumns;
break;
}
}
But as I guessed this method needs one postback to set the sessionvariable, and another one to execute the pageload with the latest value.
I know there should be "a proper way" of doing this, but I can't find it.
Any direct you guys could point me would be greatly appreciated.
Thanks in advance, Christophe
Okay,
This is how I did it.
The method building the output of the user control was called directly after the snippet above. It's called "GetProperties()".
So the problem was/is that according to the page cycle, .net first executes the Page_Load, and as last the control events.
So what I did was put the call to getProperties() for the first time (when IsPostback = false) in an if. So when you visit the page once, it will load the method, and after that no longer.
So, then I put the methodcall in my button, because when you click the button IsPostback = true.
This worked. Snippets below:
protected void Page_Load(object sender, EventArgs e)
{
//some generic stuff
if (!IsPostBack)
{
ViewState["kolommen"] = 1;
AantalKolommen = 1;
GetProperties(_tkth, _categorie, _verkochtverhuurd);
}
}
And behind the button I did the following:
protected void btnView_Click(object sender, EventArgs e)
{
switch (Int32.Parse(ViewState["kolommen"].ToString()))
{
case 1:
AantalKolommen = 2;
ViewState["kolommen"] = 2;
break;
case 2:
AantalKolommen = 1;
ViewState["kolommen"] = 1;
break;
}
GetProperties(_tkth, _categorie, _verkochtverhuurd);
}
This works like a charm. Altho, I'd still like to know if this