Example usage for java.util Observer Observer

List of usage examples for java.util Observer Observer

Introduction

In this page you can find the example usage for java.util Observer Observer.

Prototype

Observer

Source Link

Usage

From source file:com.vidinoti.pixlive.PixLive.java

private void synchronize(ArrayList<String> tags, final CallbackContext callbackContext) {
    final ArrayList<VDARPrior> priors = new ArrayList<VDARPrior>();

    for (String s : tags) {
        priors.add(new VDARTagPrior(s));
    }//w w w  .  j  ava2 s.c  o  m

    VDARSDKController.getInstance().addNewAfterLoadingTask(new Runnable() {
        @Override
        public void run() {
            VDARRemoteController.getInstance().syncRemoteContextsAsynchronouslyWithPriors(priors,
                    new Observer() {
                        @Override
                        public void update(Observable observable, Object data) {
                            VDARRemoteController.ObserverUpdateInfo info = (VDARRemoteController.ObserverUpdateInfo) data;

                            if (info.isCompleted()) {
                                if (info.getError() == null) {
                                    JSONArray ctx = new JSONArray(info.getFetchedContexts());
                                    if (!isWebViewDestroyed()) {
                                        callbackContext.success(ctx);
                                    }
                                } else {
                                    if (!isWebViewDestroyed()) {
                                        callbackContext.error(info.getError());
                                    }
                                }
                            }
                        }
                    });
        }
    });
}

From source file:org.talend.osgi.hook.OsgiLoaderTest.java

@Test
public void CheckTriggerMissingJarObservableWithProperGAV() throws IOException, BundleException {
    final Boolean[] observerCalled = new Boolean[1];
    observerCalled[0] = false;// w  ww.ja  v  a2  s . c om
    Observer observer = new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            if (arg != null && arg instanceof JarMissingEvent) {
                JarMissingEvent jarMissingEvent = (JarMissingEvent) arg;
                String expectedMvnUriStr = "mvn:org.talend.libraries/bar/6.0.0";
                try {
                    if (!jarMissingEvent.getMvnUri().toASCIIString()
                            .equals("mvn:org.talend.studio/any-existing/1.0.0")) {

                        if (jarMissingEvent.getMvnUri().toASCIIString().equals(expectedMvnUriStr)) {
                            observerCalled[0] = true;
                        } else {
                            throw new RuntimeException(
                                    "Missing jar observer did not receive the expected maven uri " //$NON-NLS-1$
                                            + jarMissingEvent.getMvnUri().toASCIIString() + " != " //$NON-NLS-1$
                                            + expectedMvnUriStr);
                        }
                    } // else ignor this bundle
                } catch (URISyntaxException e) {
                    throw new RuntimeException(e);
                }
            } else {// notification is not expected so thrown an exception for the test to fail
                throw new RuntimeException("Missing jar observer did not receive the proper event :" + arg);
            }
        }
    };

    setupMissingJarLoadingObserver(observer);

    Bundle bundleNoJar = osgiBundle.getBundleContext().installBundle(BUNDLE_NO_LIB_FOLDER_URL);
    try {
        bundleNoJar.getResource("foo");
        assertTrue("Observer should have been called", observerCalled[0]); //$NON-NLS-1$
    } finally {
        bundleNoJar.uninstall();
        unsetupMissingJarLoadingObserver(observer);
    }
    bundleNoJar = Platform.getBundle(BUNDLE_NO_LIB);
    assertNull(bundleNoJar);
}

From source file:org.talend.osgi.hook.OsgiLoaderTest.java

@Test
public void CheckAccessinClassInFragmentLibAndNoNotificationExpected() throws IOException, BundleException,
        ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException,
        NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
    Bundle fragmentBundle = osgiBundle.getBundleContext().installBundle(FRAGMENT_WITH_LIB_FOLDER_URL);
    Bundle bundleNoJar = osgiBundle.getBundleContext().installBundle(BUNDLE_NO_LIB_FOLDER_URL);
    Bundle bundle = osgiBundle.getBundleContext().installBundle(BUNDLE_CALLING_LIB_FOLDER_URL);
    final Boolean[] observerCalled = new Boolean[1];
    observerCalled[0] = false;//from   ww  w.java  2 s  . c o  m
    Observer observer = new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            if (arg != null && arg instanceof JarMissingEvent) {
                JarMissingEvent jarMissingEvent = (JarMissingEvent) arg;
                try {
                    if (jarMissingEvent.getMvnUri().toASCIIString()
                            .equals("mvn:org.talend.studio/any-existing/1.0.0")) {
                        observerCalled[0] = true;
                    } // else ignor this bundle
                } catch (URISyntaxException e) {
                    throw new RuntimeException(e);
                }
            } else {// notification is not expected so thrown an exception for the test to fail
                throw new RuntimeException("Missing jar observer did not receive the proper event :" + arg);
            }
        }
    };
    setupMissingJarLoadingObserver(observer);

    try {
        callBundleMethodToCallLibApi(bundle);
        assertFalse("Objserver should never be called", observerCalled[0]);
    } finally {
        bundle.uninstall();
        bundleNoJar.uninstall();
        fragmentBundle.uninstall();
    }
    bundle = Platform.getBundle(BUNDLE_CALLING_LIB);
    assertNull(bundle);
    bundleNoJar = Platform.getBundle(BUNDLE_NO_LIB);
    assertNull(bundleNoJar);
    fragmentBundle = Platform.getBundle(FRAGMENT_WITH_LIB);
    assertNull(fragmentBundle);
}

From source file:de.da_sense.moses.client.AvailableFragment.java

/**
 * FIXME: The ProgressDialog doesn't show up. Handles installing APK from
 * the Server./*from   ww w  .  j a v  a2  s  .  c  o m*/
 * 
 * @param app
 *            the App to download and install
 */
protected void handleInstallApp(ExternalApplication app) {

    final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance());

    Log.d(TAG, "progressDialog = " + progressDialog);

    final ApkDownloadManager downloader = new ApkDownloadManager(app,
            WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(),
            new ExecutableForObject() {
                @Override
                public void execute(final Object o) {
                    if (o instanceof Integer) {
                        WelcomeActivity.getInstance().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (totalSize == -1) {
                                    totalSize = (Integer) o / 1024;
                                    progressDialog.setMax(totalSize);
                                } else {
                                    progressDialog.incrementProgressBy(
                                            ((Integer) o / 1024) - progressDialog.getProgress());
                                }
                            }
                        });
                        /*
                         * They were : Runnable runnable = new Runnable() {
                         * Integer temporary = (Integer) o / 1024;
                         * 
                         * @Override public void run() { if (totalSize ==
                         * -1) { totalSize = temporary;
                         * progressDialog.setMax(totalSize); } else {
                         * progressDialog .incrementProgressBy( temporary -
                         * progressDialog.getProgress()); } } };
                         * getActivity().runOnUiThread(runnable);
                         */
                    }
                }
            });

    progressDialog.setTitle(getString(R.string.downloadingApp));
    progressDialog.setMessage(getString(R.string.pleaseWait));
    progressDialog.setMax(0);
    progressDialog.setProgress(0);
    progressDialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            downloader.cancel();
        }
    });

    progressDialog.setCancelable(true);
    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (progressDialog.isShowing())
                progressDialog.cancel();
        }
    });
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    Observer observer = new Observer() {
        @Override
        public void update(Observable observable, Object data) {
            if (downloader.getState() == ApkDownloadManager.State.ERROR) {
                // error downloading
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorDownloading(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) {
                // error with connection
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorNoConnection(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) {
                // success
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult());
            }
        }
    };
    downloader.addObserver(observer);
    totalSize = -1;
    // progressDialog.show(); FIXME: commented out in case it throws an
    // error
    downloader.start();
}

From source file:de.da_sense.moses.client.AvailableFragment.java

/**
 * Install an APK file on the device./*  w ww.ja  va  2s .  com*/
 * 
 * @param originalApk
 *            the APK file
 * @param externalAppRef
 *            the reference to the app on the MoSeS server
 */
private void installDownloadedApk(final File originalApk, final ExternalApplication externalAppRef) {
    final ApkInstallManager installer = new ApkInstallManager(originalApk, externalAppRef,
            mActivity.getApplicationContext());
    installer.addObserver(new Observer() {
        @Override
        public void update(Observable observable, Object data) {
            if (installer.getState() == ApkInstallManager.State.ERROR) {
                // nothing?
            } else if (installer.getState() == ApkInstallManager.State.INSTALLATION_CANCELLED) {
                // TODO: how to handle if the user cancels the installation?
            } else if (installer.getState() == ApkInstallManager.State.INSTALLATION_COMPLETED) {
                new APKInstalled(externalAppRef.getID());
                try {
                    InstalledExternalApplication extApp = ApkInstallManager.registerInstalledApk(originalApk,
                            externalAppRef, WelcomeActivity.getInstance().getApplicationContext(), false);
                    extApp.setUpdateAvailable(false);

                } catch (IOException e) {
                    Log.e("MoSeS.Install",
                            "Problems with extracting package name from " + "apk, or problems with the "
                                    + "InstalledExternalApplicationsManager after " + "installing an app");
                }
            }
        }
    });
    installer.start();
}

From source file:org.talend.osgi.hook.OsgiLoaderTest.java

@Test
public void CheckNoExistingJarClassLoadGeneratesMissingJarObservableCallButNoJarReturned() throws IOException,
        BundleException, SecurityException, IllegalArgumentException, ClassNotFoundException,
        InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    final Boolean[] observerCalled = new Boolean[1];
    observerCalled[0] = false;//from   w w w . jav  a2 s . c  o m
    Observer observer = new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            observerCalled[0] = true;
        }
    };
    setupMissingJarLoadingObserver(observer);
    Bundle bundleNoJar = osgiBundle.getBundleContext().installBundle(BUNDLE_NO_LIB_FOLDER_URL);
    Bundle bundle = osgiBundle.getBundleContext().installBundle(BUNDLE_CALLING_LIB_FOLDER_URL);
    try {
        try {
            // this forces the bundle classloader to be initialised
            bundleNoJar.getResource("foo"); //$NON-NLS-1$
            callBundleMethodToCallLibApi(bundle);
            fail("Bundle start should have thrown an exception cause no lib is provided"); //$NON-NLS-1$
        } catch (InvocationTargetException be) {
            if (!(be.getCause() instanceof NoClassDefFoundError)) {
                throw be;
            } // else do nothing cause this is an expected exception
        }
        // check finding of existing jar in fragment
        assertTrue(observerCalled[0]);

    } finally {
        bundle.uninstall();
        bundleNoJar.uninstall();
        unsetupMissingJarLoadingObserver(observer);
    }
    bundle = Platform.getBundle(BUNDLE_CALLING_LIB);
    assertNull(bundle);
    bundleNoJar = Platform.getBundle(BUNDLE_NO_LIB);
    assertNull(bundleNoJar);
}

From source file:com.ywesee.amiko.MainActivity.java

/**
 * This function creates the main layout, called when splashscreen is over
 *//*from   w ww  . j a va  2s  .co  m*/
public void createMainLayout() {
    //
    setContentView(R.layout.activity_main);

    // Initialize views
    mSuggestView = getLayoutInflater().inflate(R.layout.suggest_view, null);
    mShowView = getLayoutInflater().inflate(R.layout.show_view, null);

    // Sets current view
    mCurrentView = mSuggestView;

    // Setup webviews
    // Add views to viewholder
    mViewHolder = (ViewGroup) findViewById(R.id.main_layout);
    mViewHolder.addView(mSuggestView);
    mViewHolder.addView(mShowView);

    setLayoutTransition();

    mBottomNavigationView = findViewById(R.id.bottom_navigation);
    setupBottomNavigationViewListener();

    // Define and load webview
    ExpertInfoView mExpertInfoView = new ExpertInfoView(this, (WebView) findViewById(R.id.fach_info_view));
    mExpertInfoView.adjustZoom();

    mWebView = mExpertInfoView.getWebView();
    setFindListener(mWebView);
    setupGestureDetector(mWebView);

    // Set up observer to JS messages
    JSInterface jsinterface = mExpertInfoView.getJSInterface();
    jsinterface.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            String s = (String) arg;
            if (s.equals("notify_interaction")) {
                // Remove softkeyboard
                hideSoftKeyboard(100);
                // Take screenshot and start email activity after 500ms (wait for the keyboard to disappear)
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        sendFeedbackScreenshot(MainActivity.this, 2);
                    }
                }, 500);
            } else {
                if (s.equals("delete_all")) {
                    mMedInteractionBasket.clearBasket();
                } else {
                    mMedInteractionBasket.deleteFromBasket(s);
                }
                //
                // TODO: please comment this "hack"
                //
                Handler mainHandler = new Handler(getMainLooper());
                mainHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mMedInteractionBasket.updateInteractionsHtml();
                        String html_str = mMedInteractionBasket.getInteractionsHtml();
                        mWebView.loadDataWithBaseURL("file:///android_res/drawable/", html_str, "text/html",
                                "utf-8", null);
                    }
                });
            }
        }
    });

    // Initialize suggestion listview
    mListView = (ListView) findViewById(R.id.suggestView);
    mListView.setClickable(true);

    // Set visibility of views
    mSuggestView.setVisibility(View.VISIBLE);
    mShowView.setVisibility(View.GONE);

    // Setup initial view
    setCurrentView(mSuggestView, false);
    // Reset it
    resetView(false);
}

From source file:fm.audiobox.tests.unit.models.PlaylistsTests.java

/**
 * Test fingerprints succeed on local playlist.
 *
 * @throws IOException the iO exception/*from  w w  w .  ja  v a2 s  . c o m*/
 */
@Test
public void testFingerprintsSucceedOnLocalPlaylist() throws IOException {
    final Playlist pls = Playlists.getLocalPlaylist(c);

    pls.addObserver(new Observer() {

        @Override
        public void update(Observable o, Object arg) {
            assertSame(o, pls);
            assertTrue(arg instanceof ModelEvent);
            ModelEvent e = (ModelEvent) arg;
            assertTrue(e.source instanceof MediaFile);
            assertTrue(e.target instanceof EventedModelList);
        }

    });

    List<? extends MediaFile> mfs = pls.getFingerprints(c);
    assertNotNull(mfs);
    assertFalse(mfs.isEmpty());

    for (MediaFile m : mfs) {
        assertNotNull(m.getToken());
        assertNotNull(m.getHash());
        assertNull(m.getTitle());
    }
}

From source file:com.t3.client.ui.T3Frame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (TabletopTool.getPlayer().isGM()) {
            int result = TabletopTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(TabletopTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }/*from ww w .  j  av a 2 s  .c  o  m*/
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    @Override
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate TabletopTool!
                        } else {
                            TabletopTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!TabletopTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

public void closingMaintenance() {
    if (AppPreferences.getSaveReminder()) {
        if (MapTool.getPlayer().isGM()) {
            int result = MapTool.confirmImpl(I18N.getText("msg.title.saveCampaign"),
                    JOptionPane.YES_NO_CANCEL_OPTION, "msg.confirm.saveCampaign", (Object[]) null);
            //            int result = JOptionPane.showConfirmDialog(MapTool.getFrame(), I18N.getText("msg.confirm.saveCampaign"), I18N.getText("msg.title.saveCampaign"), JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
                return;
            }//  ww w.jav a 2  s  .  co  m
            if (result == JOptionPane.YES_OPTION) {
                final Observer callback = new Observer() {
                    public void update(java.util.Observable o, Object arg) {
                        if (arg instanceof String) {
                            // There was an error during the save -- don't terminate MapTool!
                        } else {
                            MapTool.getFrame().close();
                        }
                    }
                };
                ActionEvent ae = new ActionEvent(callback, 0, "close");
                AppActions.SAVE_CAMPAIGN.actionPerformed(ae);
                return;
            }
        } else {
            if (!MapTool.confirm("msg.confirm.disconnecting")) {
                return;
            }
        }
    }
    close();
}