Hi,
I want to use Clock component's event when Clock.Timer in my extension but i don't want to show it as a event handler block in my extension, i just want to use it to trigger other event so can anybody tell me how can i do it?
You can use the TimerInternal
class, which allows you to add timers to your component / extension:
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package com.google.appinventor.components.runtime.util;
import com.google.appinventor.components.runtime.AlarmHandler;
import android.os.Handler;
/**
* Helper class for components containing timers, such as Timer and Sprite.
*
*/
public final class TimerInternal implements Runnable {
// Android message handler used as a timer
private Handler handler;
This file has been truncated. show original
See here an example with the Sprite
class:
if (!(container instanceof Canvas)) {
throw new IllegalArgumentError("Sprite constructor called with container " + container);
}
this.canvas = (Canvas) container;
this.canvas.addSprite(this);
// Maintain a list of collisions.
registeredCollisions = new HashSet<Sprite>();
// Set in motion.
timerInternal = new TimerInternal(this, DEFAULT_ENABLED, DEFAULT_INTERVAL, handler);
this.form = container.$form();
// Set default property values.
OriginAtCenter(DEFAULT_ORIGIN_AT_CENTER);
Heading(0); // Default initial heading
Enabled(DEFAULT_ENABLED);
Interval(DEFAULT_INTERVAL);
Speed(DEFAULT_SPEED);
Visible(DEFAULT_VISIBLE);
qy >= yTop && qy < yTop + Height();
}
// Convenience methods for dealing with hitting the screen edge and collisions
// AlarmHandler implementation
/**
* Moves and redraws sprite, registering changes.
*/
public void alarm() {
// This check on initialized is currently redundant, since registerChange()
// checks it too.
if (initialized && speed != 0) {
updateCoordinates();
registerChange();
}
}
// Component implementation
Note, you will need to implement the AlarmHandler
interface in your class.
Havent you already opened a thread here?
Hello, I have imported a runtime.clock component, I want to use its timer event but want to name is as other onAnimationEnd @SimpleEvent public void onAnimationEnd(AndroidViewComponent component) { clock.Timer(){ d(); clock.TimerEnabled(false);...
Reading time: 1 mins 🕑
Likes: 2 ❤
2 Likes