Example usage for android.app Activity invalidateOptionsMenu

List of usage examples for android.app Activity invalidateOptionsMenu

Introduction

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

Prototype

public void invalidateOptionsMenu() 

Source Link

Document

Declare that the options menu has changed, so should be recreated.

Usage

From source file:com.android.settings.profiles.ProfilesSettings.java

private void updateProfilesEnabledState() {
    Activity activity = getActivity();

    mEnabled = Settings.System.getInt(activity.getContentResolver(), Settings.System.SYSTEM_PROFILES_ENABLED,
            1) == 1;//from w  ww.  j  av a 2  s .c  om
    activity.invalidateOptionsMenu();

    mViewPager.setVisibility(mEnabled ? View.VISIBLE : View.GONE);
    mEmptyText.setVisibility(mEnabled ? View.GONE : View.VISIBLE);
}

From source file:com.ultramegasoft.flavordex2.fragment.ViewInfoFragment.java

/**
 * Fills the Views with data./*from   ww  w  . java2 s.  c o  m*/
 *
 * @param data The Cursor set to the correct row
 */
private void populateViews(@NonNull Cursor data) {
    mTxtTitle.setText(mTitle);

    final String maker = data.getString(data.getColumnIndex(Tables.Entries.MAKER));
    final String origin = data.getString(data.getColumnIndex(Tables.Entries.ORIGIN));
    if (TextUtils.isEmpty(maker)) {
        setViewText(mTxtMaker, origin);
        mTxtOrigin.setVisibility(View.GONE);
    } else if (TextUtils.isEmpty(origin)) {
        setViewText(mTxtMaker, maker);
        mTxtOrigin.setVisibility(View.GONE);
    } else {
        setViewText(mTxtMaker, maker);
        setViewText(mTxtOrigin, origin);
        mTxtOrigin.setVisibility(View.VISIBLE);
    }

    setViewText(mTxtPrice, data.getString(data.getColumnIndex(Tables.Entries.PRICE)));

    String date = null;
    final long timestamp = data.getLong(data.getColumnIndex(Tables.Entries.DATE));
    if (timestamp > 0) {
        final String format = getResources().getString(R.string.date_time_format);
        date = new SimpleDateFormat(format, Locale.US).format(new Date(timestamp));
    }

    final String location = data.getString(data.getColumnIndex(Tables.Entries.LOCATION));
    if (TextUtils.isEmpty(location)) {
        setViewText(mTxtLocation, date);
        mTxtDate.setVisibility(View.GONE);
    } else {
        setViewText(mTxtLocation, location);
        setViewText(mTxtDate, date);
        mTxtDate.setVisibility(View.VISIBLE);
    }

    mRatingBar.setRating(mRating);
    mTxtNotes.setText(data.getString(data.getColumnIndex(Tables.Entries.NOTES)));

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

From source file:com.ultramegasoft.flavordex2.fragment.EditInfoFragment.java

@SuppressWarnings("ConstantConditions")
@NonNull/*from   w w w  .  j av  a2 s .com*/
@Override
public Loader onCreateLoader(int id, Bundle args) {
    switch (id) {
    case LOADER_MAIN:
        mIsLoading = true;
        final Activity activity = getActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
            return new DataLoader(activity, mCatId, mEntryId);
        }
    }
    return null;
}

From source file:com.imgtec.hobbyist.fragments.loginsignup.LogInFragment.java

private void setLogsAccessEnabled(boolean enabled) {
    loginError = enabled;/*from   ww w  . j  av a  2s .com*/
    final Activity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.invalidateOptionsMenu();
            }
        });
    }
}

From source file:com.ultramegasoft.flavordex2.fragment.EditInfoFragment.java

@Override
public void onLoadFinished(@NonNull Loader loader, Object data) {
    switch (loader.getId()) {
    case LOADER_MAIN:
        final DataLoader.Holder holder = (DataLoader.Holder) data;
        if (holder != null) {
            if (holder.entry != null) {
                populateFields(holder.entry);
            }//from   w w w . j av a 2s . c o  m
            mFormHelper.setExtras(holder.extras);
        }

        hideLoadingIndicator(true);
        mFormHelper.mTxtTitle.setSelection(mFormHelper.mTxtTitle.getText().length());

        mIsLoading = false;

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

From source file:com.ultramegasoft.flavordex2.fragment.ViewFlavorsFragment.java

/**
 * Enable or disable the RadarView's interactive mode and show or hide the editing layout.
 *
 * @param editMode Whether to enable edit mode
 * @param animate  Whether to animate the edit interface sliding in
 *//*from  ww w.  jav  a2 s. co  m*/
private void setEditMode(boolean editMode, boolean animate) {
    if (animate && mInAnimation == null) {
        mInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.flavor_edit_in);
        mOutAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.flavor_edit_out);
    }

    if (editMode) {
        mEditWidget.setVisibility(View.VISIBLE);
        if (animate) {
            mEditWidget.startAnimation(mInAnimation);
        }
    } else {
        if (mEditWidget != null) {
            if (animate) {
                mEditWidget.startAnimation(mOutAnimation);
            }
            mEditWidget.setVisibility(View.INVISIBLE);
        }
    }

    mRadarView.setInteractive(editMode);
    mEditMode = editMode;

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

From source file:com.ultramegasoft.flavordex2.fragment.AddEntryFragment.java

/**
 * Insert the new entry into the database.
 *//*from   ww  w .j  a v  a 2  s  .c  o m*/
private void saveEntry() {
    if (mIsSaving) {
        return;
    }

    FragmentManager fm = getChildFragmentManager();

    boolean isValid = false;
    final EntryHolder entry = new EntryHolder();
    for (Fragment fragment : fm.getFragments()) {
        if (fragment instanceof EditInfoFragment) {
            isValid = ((EditInfoFragment) fragment).isValid();
            if (!isValid) {
                break;
            }
            ((EditInfoFragment) fragment).getData(entry);
            entry.catName = mCatName;
            continue;
        }
        if (fragment instanceof AddFlavorsFragment) {
            ((AddFlavorsFragment) fragment).getData(entry);
            continue;
        }
        if (fragment instanceof AddPhotosFragment) {
            ((AddPhotosFragment) fragment).getData(entry);
        }
    }

    if (isValid) {
        mIsSaving = true;

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

        fm = getFragmentManager();
        if (fm != null) {
            DataSaverFragment.init(fm, entry);
        }
    } else {
        mPager.setCurrentItem(0);
    }
}

From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java

private void checkUserLikeOrNot() {

    switch (mPhoto.getMediaSource()) {
    case INSTAGRAM:
    case PX500:/*from w w w.  j  a  va  2  s  .c  om*/
        Log.d(TAG, "Do I like this photo? " + mPhoto.isUserLiked()); //$NON-NLS-1$
        mUserLikeThePhoto = mPhoto.isUserLiked();
        getActivity().invalidateOptionsMenu();
        break;
    case FLICKR:
        if (mPhoto.isUserLiked()) {
            // if it's true, it means we've already checked again the
            // server, so we don't need to check again.
            mUserLikeThePhoto = true;
            getActivity().invalidateOptionsMenu();
        } else {
            CheckUserLikePhotoTask task = new CheckUserLikePhotoTask(getActivity());
            task.addTaskDoneListener(new IGeneralTaskDoneListener<Boolean>() {

                @Override
                public void onTaskDone(Boolean result) {
                    mPhoto.setUserLiked(result);
                    Log.d(TAG, "Do I like this photo? " + result.toString()); //$NON-NLS-1$
                    mUserLikeThePhoto = mPhoto.isUserLiked();
                    Activity act = ImageDetailFragment.this.getActivity();
                    if (act != null) {
                        act.invalidateOptionsMenu();
                    }
                }
            });
            task.execute(mPhoto.getId(), mPhoto.getSecret());
        }
        break;
    }
}

From source file:com.gmail.charleszq.picorner.ui.ImageDetailFragment.java

private boolean likePhoto(final MenuItem item) {

    // prepare the animator
    ProgressBar pb = new ProgressBar(getActivity());
    item.setActionView(pb);/*from   w  w  w.  j  a v  a  2s .c  om*/

    switch (mPhoto.getMediaSource()) {
    case PX500:
        if (SPUtil.getPx500OauthTokenSecret(getActivity()) == null) {
            Toast.makeText(getActivity(), getString(R.string.pls_sing_in_first), Toast.LENGTH_SHORT).show();
            return false;
        }
        break;
    case FLICKR:
        if (!SPUtil.isFlickrAuthed(getActivity())) {
            Toast.makeText(getActivity(), getString(R.string.pls_sing_in_first), Toast.LENGTH_SHORT).show();
            return false;
        }
        break;
    case INSTAGRAM:
        if (SPUtil.getInstagramUserId(getActivity()) == null) {
            Toast.makeText(getActivity(), getString(R.string.pls_sing_in_first), Toast.LENGTH_SHORT).show();
            return false;
        }
        break;
    }

    if (mLoadedBitmap == null) {
        return false; // image not loaded yet.
    }

    IGeneralTaskDoneListener<Boolean> lis = new IGeneralTaskDoneListener<Boolean>() {
        @Override
        public void onTaskDone(Boolean result) {
            item.setActionView(null);
            if (result) {
                mUserLikeThePhoto = !mUserLikeThePhoto;
                mPhoto.setUserLiked(mUserLikeThePhoto);
                Activity act = ImageDetailFragment.this.getActivity();
                if (act != null) {
                    act.invalidateOptionsMenu();
                }
                // broadcast messages
                Message msg = new Message(Message.LIKE_PHOTO, mPhoto.getMediaSource(), mPhoto.getId(),
                        mUserLikeThePhoto);
                MessageBus.broadcastMessage(msg);
            } else {
                if (getActivity() != null)
                    Toast.makeText(getActivity(), getString(R.string.msg_like_photo_fail), Toast.LENGTH_SHORT)
                            .show();
            }
        }
    };
    String likeActionString = Boolean.toString(!mUserLikeThePhoto);
    switch (this.mPhoto.getMediaSource()) {
    case FLICKR:
        FlickrLikeTask ftask = new FlickrLikeTask(getActivity(), lis);
        ftask.execute(mPhoto.getId(), likeActionString);
        break;
    case INSTAGRAM:
        InstagramLikePhotoTask igtask = new InstagramLikePhotoTask(getActivity(), lis);
        igtask.execute(mPhoto.getId(), likeActionString);
        break;
    case PX500:
        PxLikePhotoTask pxTask = new PxLikePhotoTask(getActivity());
        pxTask.addTaskDoneListener(lis);
        pxTask.execute(mPhoto.getId(), likeActionString);
        break;
    }
    return true;
}

From source file:com.granita.tasks.ViewTaskFragment.java

@SuppressLint("NewApi")
@Override/*from   w  w  w . j  a  v  a 2  s .  c o m*/
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);
        if (VERSION.SDK_INT >= 11 && activity != null && (mOldStatus != -1 && mOldStatus != newStatus
                || mOldStatus == -1 && TaskFieldAdapters.IS_CLOSED.get(mContentSet))) {
            // new need to update the options menu, because the status of the task has changed
            activity.invalidateOptionsMenu();

        }

        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();
        }
    }
}