Java Code Examples for android.app.Activity#invalidateOptionsMenu()

The following examples show how to use android.app.Activity#invalidateOptionsMenu() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void logOut(final ZooFragment fragment) {
    final Activity activity = fragment.getActivity();
    final AccountRemoveTask task = new AccountRemoveTask(activity) {
        @Override
        protected void onPostExecute(final Void result) {
            super.onPostExecute(result);

            //Make sure that the currently-shown menu will update:
            ZooFragment.setCachedLoggedIn(false);

            //TODO: This doesn't actually seem to cause the (various) child fragments'
            //onPrepareOptionsMenu() methods to be called. Maybe it doesn't work with
            //nested child fragments.
            if (activity instanceof FragmentActivity) {
                final FragmentActivity fragmentActivity = (FragmentActivity) activity;
                fragmentActivity.supportInvalidateOptionsMenu();
            } else {
                activity.invalidateOptionsMenu();
            }
        }
    };
    task.execute();
}
 
Example 2
@Override public void onResume() {
    super.onResume();

    Activity activity = getActivity();
    String title = getTitle();
    if (activity != null && !TextUtils.isEmpty(title)) {
        activity.setTitle(title);
        activity.invalidateOptionsMenu();

        ImageManager.with(activity).setWallpaper(Wallpaper.ofCurrentPlace().lightend());
    }

    showProgressBar();
    listener = CareBehaviorTemplateListController.instance().setCallback(this);
    CareBehaviorTemplateListController.instance().listBehaviorTemplates();
}
 
Example 3
@Override
public void stopTransition() {
    for (int i = 0, size = mTransittingMenuItems.size(); i < size; i++) {
        mTransittingMenuItems.get(i).end();
    }
    if (menuItemList == null) {
        return;
    }
    for (int i = 0, size = menuItemList.size(); i < size; i++) {
        menuItemList.get(i).setActionView(null);
    }
    mTransittingMenuItems.clear();
    if (mInvalidateOptionOnStopTransition) {
        Activity activity = getActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
        }
    }
    mStarted = false;
}
 
Example 4
@Override
public void onResume() {
    super.onResume();

    Activity activity = getActivity();
    if (activity != null) {
        activity.setTitle(getTitle());
        activity.invalidateOptionsMenu();

        Window window = activity.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }
}
 
Example 5
Source Project: arcusandroid   File: BaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(@NonNull Activity activity) {
    logger.debug("Attaching fragment " + this.getClass().getSimpleName());

    super.onAttach(activity);
    activity.invalidateOptionsMenu();
}
 
Example 6
Source Project: arcusandroid   File: BaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
protected void setTitle() {
    String title = getTitle();
    if (TextUtils.isEmpty(title)) {
        return;
    }

    Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    activity.setTitle(title);
    activity.invalidateOptionsMenu();
}
 
Example 7
Source Project: tapchat-android   File: MainFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Subscribe public void onServiceStateChanged(ServiceStateChangedEvent event) {
    mTabsAdapter.notifyDataSetChanged();

    final TitlePageIndicator tabs = (TitlePageIndicator) getView().findViewById(R.id.pager_tabs);
    tabs.notifyDataSetChanged();

    final ViewPager viewPager = (ViewPager) getView().findViewById(R.id.pager);

    View view = getView();
    if (view != null) {
        boolean showNoConnections = (mTabsAdapter.isLoaded() && mTabsAdapter.getCount() == 0);
        boolean showPager = mTabsAdapter.getCount() > 0;
        view.findViewById(R.id.no_connections).setVisibility(showNoConnections ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.pager).setVisibility(showPager ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.pager_tabs).setVisibility(showPager ? View.VISIBLE : View.GONE);
    }

    Activity activity = getActivity();
    if (activity != null) {
        activity.invalidateOptionsMenu();
    }

    // FIXME: Fix ViewPager to do this properly above.
    if (mPendingSelectItem >= 0 && mTabsAdapter.getCount() > mPendingSelectItem) {
        viewPager.setCurrentItem(mPendingSelectItem);
        mPendingSelectItem = -1;
    }
}
 
Example 8
/**
 * This method loads the list of installed applications from the database,
 * or generates it if no data exists.
 */
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;
}
 
Example 9
Source Project: UTubeTV   File: VideoPlayer.java    License: The Unlicense 5 votes vote down vote up
private void playerShown(PlayerParams playerParams) {
  // action bar menu needs to update
  Activity host = (Activity) mVideoBox.getContext();
  if (host != null)
    host.invalidateOptionsMenu();

  mVideoFragment.setVideo(playerParams);

  // actionbar subtitle needs a refresh when new video starts playing, so it's not just open/close events
  // that need state changed messages

  if (mListener != null)
    mListener.stateChanged();
}
 
Example 10
@Override
public void showBehaviors(List<CareBehaviorModel> templates) {
    this.templates=templates;
    updateNewCards();

    Activity activity = getActivity();
    if (activity != null) {
        activity.invalidateOptionsMenu();
    }
}
 
Example 11
@Override public void editTemplate(final CareBehaviorModel editingModel, final CareBehaviorTemplateModel templateModel) {
    String title = editingModel.getName();
    if (TextUtils.isEmpty(title)) {
        title = StringUtils.EMPTY_STRING;
    }

    careBehaviorName.setText(title);
    Activity activity = getActivity();
    if (activity != null) {
        activity.invalidateOptionsMenu();
        if (title.length() > MAX_LENGTH_NAME) {
            title = String.format("%s...", title.substring(0, MAX_LENGTH_NAME - 1));
        }
        activity.setTitle(title);
    }

    careBehaviorSaveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(careBehaviorName.getText())) {
                editingModel.setName(careBehaviorName.getText().toString());
                BackstackManager.getInstance().navigateBack();
            }
            else {
                careBehaviorName.setError(getString(R.string.care_behavior_edit_name_error, careBehaviorName.getHint()));
            }
        }
    });
}
 
Example 12
Source Project: FileManager   File: PasteTaskExecutor.java    License: Apache License 2.0 5 votes vote down vote up
private void next() {
    Activity activity = mActivityReference.get();
    if (activity != null) {
        if (mExisting.isEmpty()) {
            if (mToProcess.isEmpty()) {
                ClipBoard.clear();
            }
            else {
                String[] array =  new String[mToProcess.size()];
                for (int i = 0; i < mToProcess.size(); i++) {
                    array[i] = mToProcess.get(i);
                }

                mToProcess.toArray(array);
                PasteTask task = new PasteTask(activity, mLocation);
                task.execute(array);
            }
        } else {
            String key = mExisting.keySet().iterator().next();
            current = mExisting.get(key);
            mExisting.remove(key);

            final Dialog dialog = new FileExistsDialog(activity, current, key,
                    this, this, this, this, this);
            if (!activity.isFinishing()) {
                dialog.show();
            }
        }
        activity.invalidateOptionsMenu();
    }
}
 
Example 13
Source Project: FileManager   File: PasteTask.java    License: Apache License 2.0 5 votes vote down vote up
private void finish(final List<String> failed) {
    if (this.dialog != null) {
        this.dialog.dismiss();
    }

    final Activity activity = this.activity.get();

    if (ClipBoard.isMove()) {
        if (success) {
            Toast.makeText(activity,
                    activity.getString(R.string.movesuccsess),
                    Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(activity, activity.getString(R.string.movefail),
                    Toast.LENGTH_SHORT).show();
        }
    } else {
        if (success) {
            Toast.makeText(activity,
                    activity.getString(R.string.copysuccsess),
                    Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(activity, activity.getString(R.string.copyfail),
                    Toast.LENGTH_SHORT).show();
        }
    }

    ClipBoard.unlock();
    ClipBoard.clear();
    activity.invalidateOptionsMenu();

    if (!failed.isEmpty()) {
        Toast.makeText(activity, activity.getString(R.string.cantopenfile),
                Toast.LENGTH_SHORT).show();
        if (!activity.isFinishing()) {
            dialog.show();
        }
    }
}
 
Example 14
Source Project: tindroid   File: MessagesFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    final Activity activity = getActivity();
    if (activity == null) {
        return false;
    }

    int id = item.getItemId();
    switch (id) {
        case R.id.action_clear:
            mTopic.delMessages(false).thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
                @Override
                public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
                    runMessagesLoader(mTopicName);
                    return null;
                }
            }, mFailureListener);
            return true;

        case R.id.action_unmute:
        case R.id.action_mute:
            mTopic.updateMuted(!mTopic.isMuted());
            activity.invalidateOptionsMenu();
            return true;

        case R.id.action_leave:
        case R.id.action_delete:
            showDeleteTopicConfirmationDialog(activity, id == R.id.action_delete);
            return true;

        case R.id.action_offline:
            Cache.getTinode().reconnectNow(true,false, false);
            break;
        default:
            return super.onOptionsItemSelected(item);
    }

    return true;
}
 
Example 15
private void finish(final List<String> failed) {
    if (this.dialog != null) {
        this.dialog.dismiss();
    }

    final Activity activity = this.activity.get();

    if (ClipBoard.isMove()) {
        if (success)
            Toast.makeText(activity,
                    activity.getString(R.string.movesuccsess),
                    Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(activity, activity.getString(R.string.movefail),
                    Toast.LENGTH_SHORT).show();
    } else {
        if (success)
            Toast.makeText(activity,
                    activity.getString(R.string.copysuccsess),
                    Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(activity, activity.getString(R.string.copyfail),
                    Toast.LENGTH_SHORT).show();
    }

    ClipBoard.unlock();
    ClipBoard.clear();
    activity.invalidateOptionsMenu();

    if (!failed.isEmpty()) {
        Toast.makeText(activity, activity.getString(R.string.cantopenfile),
                Toast.LENGTH_SHORT).show();
        if (!activity.isFinishing()) {
            dialog.show();
        }
    }
}
 
Example 16
Source Project: letv   File: ActivityCompatHoneycomb.java    License: Apache License 2.0 4 votes vote down vote up
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 17
public static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 18
Source Project: island   File: AppListFragment.java    License: Apache License 2.0 4 votes vote down vote up
private void invalidateOptionsMenu() {
	final Activity activity = getActivity();
	if (activity != null) activity.invalidateOptionsMenu();
}
 
Example 19
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 20
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}