Example usage for android.app Activity runOnUiThread

List of usage examples for android.app Activity runOnUiThread

Introduction

In this page you can find the example usage for android.app Activity runOnUiThread.

Prototype

public final void runOnUiThread(Runnable action) 

Source Link

Document

Runs the specified action on the UI thread.

Usage

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaShootingFragment.java

@Override
public void onDisconnected(ThetaDevice device) {
    mDevice = null;//from w  ww.  ja va 2  s. co m
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.finish();
            }
        });
    }
}

From source file:org.messic.android.controllers.ExploreController.java

public void getExploreAlbums(final AlbumAdapter adapter, final Activity activity, final ExploreFragment rf,
        boolean refresh, final SwipeRefreshLayout srl) {
    if (albums == null || refresh) {
        final String baseURL = Configuration.getBaseUrl()
                + "/services/albums?songsInfo=true&authorInfo=true&messic_token="
                + Configuration.getLastToken();
        RestJSONClient.get(baseURL, MDMAlbum[].class, new RestJSONClient.RestListener<MDMAlbum[]>() {
            public void response(MDMAlbum[] response) {
                albums = response;// w  ww  .  java  2s. c  o  m
                refreshData(response, adapter, activity, rf, srl);
            }

            public void fail(final Exception e) {
                Log.e("Random", e.getMessage(), e);
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        Toast.makeText(activity, "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();

                    }
                });
            }

        });
    } else {
        if (albums != null) {
            refreshData(albums, adapter, activity, rf, srl);
        }
    }
}

From source file:ru.valle.btc.MainActivityTest.java

private String getText(final Activity activity, final int id) {
    FutureTask<String> task = new FutureTask<>(new Callable<String>() {
        @Override//www . j  ava2s  . c  o  m
        public String call() throws Exception {
            TextView textView = ((TextView) activity.findViewById(id));
            return textView.getVisibility() == View.VISIBLE ? getString(textView) : null;
        }
    });
    activity.runOnUiThread(task);
    try {
        return task.get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

private void switchToDocumentProvider(IDocumentProvider provider) {

    new AsyncTask<IDocumentProvider, Void, Void>() {
        @Override//w  w  w.ja  va  2  s  . co  m
        protected Void doInBackground(IDocumentProvider... provider) {
            // switch document provider:
            // these operations may imply network access and must be run in
            // a different thread
            try {
                documentProvider = provider[0];
                homeDirectory = documentProvider.getRootDirectory();
                currentDirectory = homeDirectory;
                filePaths = currentDirectory.listFiles(FileUtilities.getFileFilter(filterMode));
            } catch (final RuntimeException e) {
                final Activity activity = LibreOfficeUIActivity.this;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e(LOGTAG, e.getMessage(), e.getCause());
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            refreshView();
        }
    }.execute(provider);
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

public void openDirectory(IFile dir) {
    if (dir == null)
        return;/*  www .j  a va 2 s .  c om*/

    new AsyncTask<IFile, Void, Void>() {
        @Override
        protected Void doInBackground(IFile... dir) {
            // get list of files:
            // this operation may imply network access and must be run in
            // a different thread
            currentDirectory = dir[0];
            try {
                filePaths = currentDirectory.listFiles(FileUtilities.getFileFilter(filterMode));
            } catch (final RuntimeException e) {
                final Activity activity = LibreOfficeUIActivity.this;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e(LOGTAG, e.getMessage(), e.getCause());
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            refreshView();
        }
    }.execute(dir);
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

private void share(int position) {

    new AsyncTask<IFile, Void, File>() {
        @Override//from   w  w w  . j  a v a2 s  .c o  m
        protected File doInBackground(IFile... document) {
            // this operation may imply network access and must be run in
            // a different thread
            try {
                return document[0].getDocument();
            } catch (final RuntimeException e) {
                final Activity activity = LibreOfficeUIActivity.this;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e(LOGTAG, e.getMessage(), e.getCause());
                return null;
            }
        }

        @Override
        protected void onPostExecute(File file) {
            if (file != null) {
                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                Uri uri = Uri.fromFile(file);
                sharingIntent.setType(FileUtilities.getMimeType(file.getName()));
                sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, file.getName());
                startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));
            }
        }
    }.execute(filePaths.get(position));
}

From source file:org.messic.android.controllers.RandomController.java

public void getRandomMusic(final SongAdapter adapter, final Activity activity, final RandomFragment rf,
        boolean refresh, final SwipeRefreshLayout srl) {
    if (rlist == null || refresh) {
        final String baseURL = Configuration.getBaseUrl()
                + "/services/randomlists?filterRandomListName=RandomListName-Random&messic_token="
                + Configuration.getLastToken();
        RestJSONClient.get(baseURL, MDMRandomList[].class, new RestJSONClient.RestListener<MDMRandomList[]>() {
            public void response(MDMRandomList[] response) {
                rlist = response;//from  w ww.  java 2s.  c o  m
                refreshData(adapter, activity, rf, srl);
            }

            public void fail(final Exception e) {
                Log.e("Random", e.getMessage(), e);
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        Toast.makeText(activity, "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();

                    }
                });
            }

        });
    } else {
        if (rlist != null) {
            refreshData(adapter, activity, rf, srl);
        }
    }
}

From source file:com.juick.android.JuickMessagesAdapter.java

static private void handleOOM(final Activity activity, OutOfMemoryError e) {
    activity.runOnUiThread(new Runnable() {
        @Override//from w ww .  ja  va2s.co m
        public void run() {
            Toast.makeText(activity, "Out of memory", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

public void open(final IFile document) {
    new AsyncTask<IFile, Void, File>() {
        @Override//from w w w  . jav  a2 s . co m
        protected File doInBackground(IFile... document) {
            // this operation may imply network access and must be run in
            // a different thread
            try {
                return document[0].getDocument();
            } catch (final RuntimeException e) {
                final Activity activity = LibreOfficeUIActivity.this;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e(LOGTAG, e.getMessage(), e.getCause());
                return null;
            }
        }

        @Override
        protected void onPostExecute(File file) {
            if (file != null) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
                String packageName = getApplicationContext().getPackageName();
                ComponentName componentName = new ComponentName(packageName,
                        LibreOfficeMainActivity.class.getName());
                i.setComponent(componentName);

                // these extras allow to rebuild the IFile object in LOMainActivity
                i.putExtra("org.libreoffice.document_provider_id", documentProvider.getId());
                i.putExtra("org.libreoffice.document_uri", document.getUri());

                startActivity(i);
            }
        }
    }.execute(document);
}

From source file:com.filemanager.free.filesystem.FileUtil.java

/**
 * Delete a directory asynchronously.//w  w  w  .ja  v a 2 s.  c om
 *
 * @param activity    The activity calling this method.
 * @param file        The folder name.
 * @param postActions Commands to be executed after success.
 */
public static void rmdirAsynchronously(final Activity activity, final File file, final Runnable postActions,
        final Context context) {
    if (file == null)
        return;
    new Thread() {
        @Override
        public void run() {
            int retryCounter = 5; // MAGIC_NUMBER
            while (!FileUtil.rmdir(file, context) && retryCounter > 0) {
                try {
                    Thread.sleep(100); // MAGIC_NUMBER
                } catch (InterruptedException e) {
                    // do nothing
                }
                retryCounter--;
            }
            if (file.exists()) {
                /*         DialogUtil.displayError(activity, R.string.message_dialog_failed_to_delete_folder, false,
                    file.getAbsolutePath());
                */
            } else {
                activity.runOnUiThread(postActions);
            }

        }
    }.start();
}