Search in sources :

Example 1 with Application

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);
}
Also used : Application(net.rim.device.api.system.Application) UiApplication(net.rim.device.api.ui.UiApplication)

Example 2 with Application

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HttpConnection(javax.microedition.io.HttpConnection) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Application(net.rim.device.api.system.Application) IOException(java.io.IOException)

Example 3 with Application

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;
    }
}
Also used : Application(net.rim.device.api.system.Application) UiApplication(net.rim.device.api.ui.UiApplication)

Aggregations

Application (net.rim.device.api.system.Application)3 UiApplication (net.rim.device.api.ui.UiApplication)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 HttpConnection (javax.microedition.io.HttpConnection)1