use of net.rim.device.api.system.Application in project google-authenticator by google.
the class AuthenticatorScreen method startTimer.
private void startTimer() {
if (isTimerSet()) {
stopTimer();
}
Application application = getApplication();
Runnable runnable = this;
boolean repeat = true;
mTimer = application.invokeLater(runnable, REFRESH_INTERVAL, repeat);
}
use of net.rim.device.api.system.Application in project google-authenticator by google.
the class UpdateTask method run.
/**
* {@inheritDoc}
*/
public void run() {
try {
// Visit the original download URL and read the JAD;
// if the MIDlet-Version has changed, invoke the callback.
String url = Build.DOWNLOAD_URL;
String applicationVersion = getApplicationVersion();
String userAgent = getUserAgent();
String language = getLanguage();
for (int redirectCount = 0; redirectCount < 10; redirectCount++) {
HttpConnection c = null;
InputStream s = null;
try {
c = connect(url);
c.setRequestMethod(HttpConnection.GET);
c.setRequestProperty("User-Agent", userAgent);
c.setRequestProperty("Accept-Language", language);
int responseCode = c.getResponseCode();
if (responseCode == HttpConnection.HTTP_MOVED_PERM || responseCode == HttpConnection.HTTP_MOVED_TEMP) {
String location = c.getHeaderField("Location");
if (location != null) {
url = location;
continue;
} else {
throw new IOException("Location header missing");
}
} else if (responseCode != HttpConnection.HTTP_OK) {
throw new IOException("Unexpected response code: " + responseCode);
}
s = c.openInputStream();
String enc = getEncoding(c);
Reader reader = new InputStreamReader(s, enc);
final String version = getMIDletVersion(reader);
if (version == null) {
throw new IOException("MIDlet-Version not found");
} else if (!version.equals(applicationVersion)) {
Application application = Application.getApplication();
application.invokeLater(new Runnable() {
public void run() {
mCallback.onUpdate(version);
}
});
} else {
// Already running latest version
}
} finally {
if (s != null) {
s.close();
}
if (c != null) {
c.close();
}
}
}
} catch (Exception e) {
System.out.println(e);
}
}
use of net.rim.device.api.system.Application in project google-authenticator by google.
the class AuthenticatorScreen method stopTimer.
private void stopTimer() {
if (isTimerSet()) {
Application application = getApplication();
application.cancelInvokeLater(mTimer);
mTimer = -1;
}
}
Aggregations