List of usage examples for android.app Activity invalidateOptionsMenu
public void invalidateOptionsMenu()
From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java
@SuppressWarnings("ConstantConditions") @NonNull//from w ww . jav a2 s .c o m @Override public Loader<DataLoader.Holder> onCreateLoader(int id, Bundle args) { final Activity activity = getActivity(); if (activity == null) { return null; } mIsLoading = true; activity.invalidateOptionsMenu(); return new DataLoader(activity, mCatId); }
From source file:org.dmfs.tasks.ViewTaskFragment.java
@SuppressLint("NewApi") @Override/*from w ww . j av a 2s . c om*/ public void onContentLoaded(ContentSet contentSet) { if (contentSet.containsKey(Tasks.ACCOUNT_TYPE)) { mListColor = TaskFieldAdapters.LIST_COLOR.get(contentSet); ((Callback) getActivity()).updateColor(darkenColor2(mListColor)); if (VERSION.SDK_INT >= 11) { updateColor((float) mRootView.getScrollY() / ((ActionBarActivity) getActivity()).getSupportActionBar().getHeight()); } Activity activity = getActivity(); int newStatus = TaskFieldAdapters.STATUS.get(contentSet); boolean newPinned = TaskFieldAdapters.PINNED.get(contentSet); if (VERSION.SDK_INT >= 11 && activity != null && (hasNewStatus(newStatus) || wasPinChanged(newPinned))) { // new need to update the options menu, because the status of the task has changed activity.invalidateOptionsMenu(); } mIsPinned = newPinned; mOldStatus = newStatus; if (mModel == null || !TextUtils.equals(mModel.getAccountType(), contentSet.getAsString(Tasks.ACCOUNT_TYPE))) { Sources.loadModelAsync(mAppContext, contentSet.getAsString(Tasks.ACCOUNT_TYPE), this); } else { // the model didn't change, just update the view postUpdateView(); } } }
From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailFragment.java
private void updateView(final Activity activity, final View rootView) { Log.v(TAG, "updateView"); new AsyncTask<Void, Void, PoemCursor>() { @Override//from ww w . ja v a 2 s. com protected PoemCursor doInBackground(Void... params) { if (getArguments().containsKey(ARG_ITEM_ID)) { long poemId = getArguments().getLong(ARG_ITEM_ID); PoemCursor poemCursor = new PoemSelection().id(poemId).query(activity.getContentResolver()); if (poemCursor.moveToFirst()) return poemCursor; poemCursor.close(); } return null; } @Override protected void onPostExecute(PoemCursor poemCursor) { boolean favorite = poemCursor.getIsFavorite(); if (favorite != mIsFavorite) { mIsFavorite = favorite; activity.invalidateOptionsMenu(); } TextView tvTitleView = (TextView) rootView.findViewById(R.id.title); tvTitleView.setText(poemCursor.getTitle()); String preContent = poemCursor.getPreContent(); TextView preContentView = (TextView) rootView.findViewById(R.id.pre_content); preContentView.setVisibility(TextUtils.isEmpty(preContent) ? View.GONE : View.VISIBLE); preContentView.setText(preContent); ((TextView) rootView.findViewById(R.id.content)).setText(poemCursor.getContent()); String poemTypeAndNumber = Poems.getPoemNumberString(activity, poemCursor); TextView tvPoemTypeAndNumber = (TextView) rootView.findViewById(R.id.poem_type_and_number); tvPoemTypeAndNumber.setVisibility(TextUtils.isEmpty(poemTypeAndNumber) ? View.GONE : View.VISIBLE); tvPoemTypeAndNumber.setText(poemTypeAndNumber); String locationDateString = Poems.getLocationDateString(activity, poemCursor); ((TextView) rootView.findViewById(R.id.author)).setText(R.string.author); ((TextView) rootView.findViewById(R.id.location_and_date)).setText(locationDateString); poemCursor.close(); } }.execute(); }
From source file:com.android.settings.applications.CanBeOnSdCardChecker.java
public void updateCurrentTab(int position) { TabInfo tab = mTabs.get(position);//from ww w . j a va 2 s.com mCurTab = tab; // Put things in the correct paused/resumed state. if (mActivityResumed) { mCurTab.build(mInflater, mContentContainer, mRootView); mCurTab.resume(mSortOrder); } else { mCurTab.pause(); } for (int i = 0; i < mTabs.size(); i++) { TabInfo t = mTabs.get(i); if (t != mCurTab) { t.pause(); } } mCurTab.updateStorageUsage(); updateOptionsMenu(); final Activity host = getActivity(); if (host != null) { host.invalidateOptionsMenu(); } }
From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java
@Override public void onLoadFinished(@NonNull Loader<DataLoader.Holder> loader, DataLoader.Holder data) { mIsLoading = false;// ww w .j a va2 s .c om getLoaderManager().destroyLoader(0); hideLoadingIndicator(true); final Activity activity = getActivity(); if (mTxtTitle != null) { mTxtTitle.setText(FlavordexApp.getRealCatName(activity, data.catName)); mTxtTitle.setSelection(mTxtTitle.length()); } mExtraFields = data.extras; mFlavorFields = data.flavors; populateFields(); mRadarView.setData(getRadarData()); if (activity != null) { activity.invalidateOptionsMenu(); } }
From source file:fr.kwiatkowski.apktrack.ui.AppDisplayFragment.java
/** * This method loads the list of installed applications from the database, * or generates it if no data exists.//w w w . j a v a 2 s . c o m */ private List<InstalledApp> _initialize_data() { String where_clause = "_isignored = 0"; // Check whether system apps should be displayed Activity activity = getActivity(); if (activity != null) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity); boolean show_system = pref.getBoolean(SettingsFragment.KEY_PREF_SHOW_SYSTEM, false); if (!show_system) { where_clause += " and _systemapp = 0"; } } List<InstalledApp> installed_apps = InstalledApp.find(InstalledApp.class, where_clause); if (installed_apps.size() == 0 && activity != null) // Database is empty { Log.v(MainActivity.TAG, "Populating database..."); InstalledApp.generate_applist_from_system(activity.getPackageManager()); installed_apps = InstalledApp.find(InstalledApp.class, "_systemapp = 0 AND _isignored = 0"); Log.v(MainActivity.TAG, "...database populated. " + InstalledApp.count(InstalledApp.class) + " records created."); // Enable the "dhow system apps" button now that there may be system apps. activity.invalidateOptionsMenu(); } else if (activity != null) { Log.v(MainActivity.TAG, installed_apps.size() + " records read from the database."); } return installed_apps; }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_sort: return true; case R.id.menuSortNewest: sort = "New"; refreshComments();/*from w w w .j a v a 2 s. c o m*/ activity.invalidateOptionsMenu(); return true; case R.id.menuSortTop: sort = "Top"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.menuSortBest: sort = "Best"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.action_refresh: refreshComments(); return true; case R.id.action_submit: final EditText newGalleryTitle = new EditText(activity); newGalleryTitle.setHint("Title"); newGalleryTitle.setSingleLine(); new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove") .setView(newGalleryTitle) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newGalleryTitle.getText() == null) return; HashMap<String, Object> galleryMap = new HashMap<String, Object>(); galleryMap.put("terms", "1"); galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newGalleryTitle.getText().toString()); newGalleryString = newGalleryTitle.getText().toString(); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET, galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY); fetcher.execute(); } catch (Exception e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_edit: try { final EditText newTitle = new EditText(activity); newTitle.setSingleLine(); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_description); newTitle.setHint(R.string.body_hint_title); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newTitle); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView imageTitle = (TextView) imageLayoutView .findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView .findViewById(R.id.single_image_description); if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) { imageTitle.setText(newTitle.getText().toString()); imageTitle.setVisibility(View.VISIBLE); } else imageTitle.setVisibility(View.GONE); if (newBody.getText() != null && !newBody.getText().toString().equals("")) { imageDescription.setText(newBody.getText().toString()); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); HashMap<String, Object> editImageMap = new HashMap<String, Object>(); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString()); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION, newBody.getText().toString()); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST, editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(), EDITIMAGE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } catch (JSONException e) { Log.e("Error!", "oops, some image fields missing values" + e.toString()); } return true; case R.id.action_download: ImageUtils.downloadImage(this, imageData); return true; case R.id.action_delete: new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title) .setMessage(R.string.dialog_delete_confirmation_summary) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE, null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_copy: ImageUtils.copyImageURL(this, imageData); return true; case R.id.action_share: ImageUtils.shareImage(this, imageData); return true; default: return super.onOptionsItemSelected(item); } }
From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.v(TAG, "onOptionsItemSelected"); if (item.getItemId() == R.id.action_favorite) { final Activity activity = getActivity(); final View rootView = getView(); new AsyncTask<Void, Void, Void>() { @Override//from w ww . j ava 2 s . c o m protected Void doInBackground(Void... params) { // Write the poem favorite field. long poemId = getArguments().getLong(ARG_ITEM_ID); PoemSelection poemSelection = new PoemSelection().id(poemId); PoemCursor cursor = poemSelection.query(activity.getContentResolver()); try { if (cursor.moveToFirst()) { boolean wasFavorite = cursor.getIsFavorite(); boolean isFavorite = !wasFavorite; new PoemContentValues().putIsFavorite(isFavorite).update(activity.getContentResolver(), poemSelection); } } finally { cursor.close(); } return null; } @Override protected void onPostExecute(Void params) { // Reread the poem updateView(activity, rootView); } }.execute(); } else if (item.getItemId() == R.id.action_music) { MusicPlayer.getInstance(getActivity()).toggle(); final Activity activity = getActivity(); mHandler.postDelayed(new Runnable() { @Override public void run() { activity.invalidateOptionsMenu(); } }, 200); } return super.onOptionsItemSelected(item); }
From source file:com.polychrom.cordova.ActionBarPlugin.java
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (!plugin_actions.contains(action)) { return false; }/*w w w .j a v a 2s . co m*/ final Activity ctx = (Activity) cordova; if ("isAvailable".equals(action)) { JSONObject result = new JSONObject(); result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR)); callbackContext.success(result); return true; } final ActionBar bar = ctx.getActionBar(); if (bar == null) { Window window = ctx.getWindow(); if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) { callbackContext .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!"); } else { callbackContext.error("Failed to get ActionBar"); } return true; } if (menu == null) { callbackContext.error("Options menu not initialised"); return true; } final StringBuffer error = new StringBuffer(); JSONObject result = new JSONObject(); if ("isShowing".equals(action)) { result.put("value", bar.isShowing()); } else if ("getHeight".equals(action)) { result.put("value", bar.getHeight()); } else if ("getDisplayOptions".equals(action)) { result.put("value", bar.getDisplayOptions()); } else if ("getNavigationMode".equals(action)) { result.put("value", bar.getNavigationMode()); } else if ("getSelectedNavigationItem".equals(action)) { result.put("value", bar.getSelectedNavigationIndex()); } else if ("getSubtitle".equals(action)) { result.put("value", bar.getSubtitle()); } else if ("getTitle".equals(action)) { result.put("value", bar.getTitle()); } else { try { JSONException exception = new Runnable() { public JSONException exception = null; public void run() { try { // This is a bit of a hack (should be specific to the request, not global) bases = new String[] { removeFilename(webView.getOriginalUrl()), removeFilename(webView.getUrl()) }; if ("show".equals(action)) { bar.show(); } else if ("hide".equals(action)) { bar.hide(); } else if ("setMenu".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } menu_definition = args.getJSONArray(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ctx.invalidateOptionsMenu(); } } else if ("setTabs".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } bar.removeAllTabs(); tab_callbacks.clear(); if (!buildTabs(bar, args.getJSONArray(0))) { error.append("Invalid tab bar definition"); } } else if ("setDisplayHomeAsUpEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHomeAsUp can not be null"); return; } bar.setDisplayHomeAsUpEnabled(args.getBoolean(0)); } else if ("setDisplayOptions".equals(action)) { if (args.isNull(0)) { error.append("options can not be null"); return; } final int options = args.getInt(0); bar.setDisplayOptions(options); } else if ("setDisplayShowHomeEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHome can not be null"); return; } bar.setDisplayShowHomeEnabled(args.getBoolean(0)); } else if ("setDisplayShowTitleEnabled".equals(action)) { if (args.isNull(0)) { error.append("showTitle can not be null"); return; } bar.setDisplayShowTitleEnabled(args.getBoolean(0)); } else if ("setDisplayUseLogoEnabled".equals(action)) { if (args.isNull(0)) { error.append("useLogo can not be null"); return; } bar.setDisplayUseLogoEnabled(args.getBoolean(0)); } else if ("setHomeButtonEnabled".equals(action)) { if (args.isNull(0)) { error.append("enabled can not be null"); return; } bar.setHomeButtonEnabled(args.getBoolean(0)); } else if ("setIcon".equals(action)) { if (args.isNull(0)) { error.append("icon can not be null"); return; } Drawable drawable = getDrawableForURI(args.getString(0)); bar.setIcon(drawable); } else if ("setListNavigation".equals(action)) { JSONArray items = null; if (args.isNull(0) == false) { items = args.getJSONArray(0); } navigation_adapter.setItems(items); bar.setListNavigationCallbacks(navigation_adapter, navigation_listener); } else if ("setLogo".equals(action)) { if (args.isNull(0)) { error.append("logo can not be null"); return; } Drawable drawable = getDrawableForURI(args.getString(0)); bar.setLogo(drawable); } else if ("setNavigationMode".equals(action)) { if (args.isNull(0)) { error.append("mode can not be null"); return; } final int mode = args.getInt(0); bar.setNavigationMode(mode); } else if ("setSelectedNavigationItem".equals(action)) { if (args.isNull(0)) { error.append("position can not be null"); return; } bar.setSelectedNavigationItem(args.getInt(0)); } else if ("setSubtitle".equals(action)) { if (args.isNull(0)) { error.append("subtitle can not be null"); return; } bar.setSubtitle(args.getString(0)); } else if ("setTitle".equals(action)) { if (args.isNull(0)) { error.append("title can not be null"); return; } bar.setTitle(args.getString(0)); } } catch (JSONException e) { exception = e; } finally { synchronized (this) { this.notify(); } } } // Run task synchronously { synchronized (this) { ctx.runOnUiThread(this); this.wait(); } } }.exception; if (exception != null) { throw exception; } } catch (InterruptedException e) { error.append("Function interrupted on UI thread"); } } if (error.length() == 0) { if (result.length() > 0) { callbackContext.success(result); } else { callbackContext.success(); } } else { callbackContext.error(error.toString()); } return true; }
From source file:com.native5.plugins.ActionBarPlugin.java
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (!plugin_actions.contains(action)) { return false; }//from ww w.j a v a2 s .c om final Activity ctx = (Activity) cordova; if ("isAvailable".equals(action)) { JSONObject result = new JSONObject(); result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR)); callbackContext.success(result); return true; } final ActionBar bar = ctx.getActionBar(); if (bar == null) { Window window = ctx.getWindow(); if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) { callbackContext .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!"); } else { callbackContext.error("Failed to get ActionBar"); } return true; } if (menu == null) { callbackContext.error("Options menu not initialised"); return true; } final StringBuffer error = new StringBuffer(); JSONObject result = new JSONObject(); if ("isShowing".equals(action)) { result.put("value", bar.isShowing()); } else if ("getHeight".equals(action)) { result.put("value", bar.getHeight()); } else if ("getDisplayOptions".equals(action)) { result.put("value", bar.getDisplayOptions()); } else if ("getNavigationMode".equals(action)) { result.put("value", bar.getNavigationMode()); } else if ("getSelectedNavigationItem".equals(action)) { result.put("value", bar.getSelectedNavigationIndex()); } else if ("getSubtitle".equals(action)) { result.put("value", bar.getSubtitle()); } else if ("getTitle".equals(action)) { result.put("value", bar.getTitle()); } else { try { JSONException exception = new Runnable() { public JSONException exception = null; public void run() { try { // This is a bit of a hack (should be specific to the request, not global) bases = new String[] { removeFilename(webView.getOriginalUrl()), removeFilename(webView.getUrl()) }; if ("show".equals(action)) { LOG.d("native5-action-bar", "Showing Action Bar"); bar.show(); } else if ("hide".equals(action)) { bar.hide(); } else if ("setMenu".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } menu_definition = args.getJSONArray(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ctx.invalidateOptionsMenu(); } } else if ("setTabs".equals(action)) { if (args.isNull(0)) { error.append("menu can not be null"); return; } bar.removeAllTabs(); tab_callbacks.clear(); if (!buildTabs(bar, args.getJSONArray(0))) { error.append("Invalid tab bar definition"); } } else if ("setDisplayHomeAsUpEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHomeAsUp can not be null"); return; } bar.setDisplayHomeAsUpEnabled(args.getBoolean(0)); } else if ("setDisplayOptions".equals(action)) { if (args.isNull(0)) { error.append("options can not be null"); return; } final int options = args.getInt(0); bar.setDisplayOptions(options); } else if ("setDisplayShowHomeEnabled".equals(action)) { if (args.isNull(0)) { error.append("showHome can not be null"); return; } bar.setDisplayShowHomeEnabled(args.getBoolean(0)); } else if ("setDisplayShowTitleEnabled".equals(action)) { if (args.isNull(0)) { error.append("showTitle can not be null"); return; } bar.setDisplayShowTitleEnabled(args.getBoolean(0)); } else if ("setDisplayUseLogoEnabled".equals(action)) { if (args.isNull(0)) { error.append("useLogo can not be null"); return; } bar.setDisplayUseLogoEnabled(args.getBoolean(0)); } else if ("setHomeButtonEnabled".equals(action)) { if (args.isNull(0)) { error.append("enabled can not be null"); return; } bar.setHomeButtonEnabled(args.getBoolean(0)); } else if ("setIcon".equals(action)) { if (args.isNull(0)) { error.append("icon can not be null"); return; } Drawable drawable = getDrawableForURI(args.getString(0)); bar.setIcon(drawable); } else if ("setListNavigation".equals(action)) { JSONArray items = null; if (args.isNull(0) == false) { items = args.getJSONArray(0); } navigation_adapter.setItems(items); bar.setListNavigationCallbacks(navigation_adapter, navigation_listener); } else if ("setLogo".equals(action)) { String uri = args.getString(0); if (args.isNull(0)) { error.append("logo can not be null"); return; } // try { // InputStream ims = ctx.getAssets().open(uri); Drawable drawable = getDrawableForURI(uri); // Drawable.createFromStream(ims, null); bar.setLogo(drawable); bar.setBackgroundDrawable(getDrawableForURI("images/logo-bg.png")); // } catch (IOException e) { // e.printStackTrace(); // } } else if ("setNavigationMode".equals(action)) { if (args.isNull(0)) { error.append("mode can not be null"); return; } final int mode = args.getInt(0); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } else if ("setSelectedNavigationItem".equals(action)) { if (args.isNull(0)) { error.append("position can not be null"); return; } bar.setSelectedNavigationItem(args.getInt(0)); } else if ("setSelectedTab".equals(action)) { if (args.isNull(0)) { error.append("position can not be null"); return; } LOG.d("setSelectedTab", bar.getTabCount() + ""); bar.selectTab(bar.getTabAt(args.getInt(0))); } else if ("setSubtitle".equals(action)) { if (args.isNull(0)) { error.append("subtitle can not be null"); return; } bar.setSubtitle(args.getString(0)); } else if ("setTitle".equals(action)) { if (args.isNull(0)) { error.append("title can not be null"); return; } bar.setTitle(args.getString(0)); } } catch (JSONException e) { exception = e; } finally { synchronized (this) { this.notify(); } } } // Run task synchronously { synchronized (this) { ctx.runOnUiThread(this); this.wait(); } } }.exception; if (exception != null) { throw exception; } } catch (InterruptedException e) { error.append("Function interrupted on UI thread"); } } if (error.length() == 0) { if (result.length() > 0) { callbackContext.success(result); } else { callbackContext.success(); } } else { callbackContext.error(error.toString()); } return true; }