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

The following examples show how to use android.app.Activity#invalidateOptionsMenu() . 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
Source File: MenuItemTransition.java    From android-transition with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: LoginUtils.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: CareListBehaviorFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: CareBehaviorsFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void showBehaviors(List<CareBehaviorModel> templates) {
    this.templates=templates;
    updateNewCards();

    Activity activity = getActivity();
    if (activity != null) {
        activity.invalidateOptionsMenu();
    }
}
 
Example 5
Source File: PasteTask.java    From SimpleExplorer with GNU General Public License v3.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 6
Source File: MessagesFragment.java    From tindroid with 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 7
Source File: PasteTask.java    From FileManager with 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 8
Source File: PasteTaskExecutor.java    From FileManager with 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 9
Source File: AccountBillingInfoFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: CareBehaviorNameEditorFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: VideoPlayer.java    From UTubeTV with 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 12
Source File: AppDisplayFragment.java    From ApkTrack with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: MainFragment.java    From tapchat-android with 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 14
Source File: BaseFragment.java    From arcusandroid with 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 15
Source File: BaseFragment.java    From arcusandroid with 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 16
Source File: ActivityCompatHoneycomb.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 17
Source File: ActivityCompatHoneycomb.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 18
Source File: AppListFragment.java    From island with Apache License 2.0 4 votes vote down vote up
private void invalidateOptionsMenu() {
	final Activity activity = getActivity();
	if (activity != null) activity.invalidateOptionsMenu();
}
 
Example 19
Source File: ActivityCompat.java    From Ansole with GNU General Public License v2.0 4 votes vote down vote up
public static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}
 
Example 20
Source File: ActivityCompatHoneycomb.java    From letv with Apache License 2.0 4 votes vote down vote up
static void invalidateOptionsMenu(Activity activity) {
    activity.invalidateOptionsMenu();
}