Example usage for android.support.v4.app FragmentManager findFragmentByTag

List of usage examples for android.support.v4.app FragmentManager findFragmentByTag

Introduction

In this page you can find the example usage for android.support.v4.app FragmentManager findFragmentByTag.

Prototype

public abstract Fragment findFragmentByTag(String tag);

Source Link

Document

Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction.

Usage

From source file:com.mindorks.framework.mvp.ui.main.MainActivity.java

@Override
public void onFragmentDetached(String tag) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment fragment = fragmentManager.findFragmentByTag(tag);
    if (fragment != null) {
        fragmentManager.beginTransaction().disallowAddToBackStack()
                .setCustomAnimations(R.anim.slide_left, R.anim.slide_right).remove(fragment).commitNow();
        if (mDrawer != null)
            mDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }//from  w w  w . j  ava  2 s  . co m
}

From source file:com.google.android.apps.iosched.ui.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!EulaHelper.hasAcceptedEula(this)) {
        EulaHelper.showEula(false, this);
    }// w ww .j  ava  2 s.c om

    AnalyticsUtils.getInstance(this).trackPageView("/Home");

    setContentView(R.layout.activity_home);
    getActivityHelper().setupActionBar(null, 0);

    FragmentManager fm = getSupportFragmentManager();

    mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream);

    mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm
            .findFragmentByTag(SyncStatusUpdaterFragment.TAG);
    if (mSyncStatusUpdaterFragment == null) {
        mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment();
        fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit();

        triggerRefresh();
    }
}

From source file:com.google.android.apps.iosched2.ui.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SetupHelper.loadCurrentSetup(this);

    setContentView(R.layout.activity_home);
    getActivityHelper().setupActionBar(null, 0);

    FragmentManager fm = getSupportFragmentManager();

    mTagStreamFragment = (TagStreamFragment) fm.findFragmentById(R.id.fragment_tag_stream);

    mSyncStatusUpdaterFragment = (SyncStatusUpdaterFragment) fm
            .findFragmentByTag(SyncStatusUpdaterFragment.TAG);
    if (mSyncStatusUpdaterFragment == null) {
        mSyncStatusUpdaterFragment = new SyncStatusUpdaterFragment();
        fm.beginTransaction().add(mSyncStatusUpdaterFragment, SyncStatusUpdaterFragment.TAG).commit();
        triggerRefresh();// w  ww . jav  a2  s . c  o m
    }

}

From source file:com.dm.wallpaper.board.fragments.LatestFragment.java

@Override
public void onFinished(boolean success) {
    if (getActivity() == null)
        return;/* w w w .java2 s  .co  m*/
    if (getActivity().isFinishing())
        return;
    if (!success)
        return;

    FragmentManager fm = getActivity().getSupportFragmentManager();
    Fragment fragment = fm.findFragmentByTag(Extras.TAG_COLLECTION);
    if (fragment != null && fragment instanceof CollectionFragment) {
        ((CollectionFragment) fragment).refreshWallpapers();
        ((CollectionFragment) fragment).refreshCategories();
    }
}

From source file:com.oceansky.yellow.app.ArtistActivity.java

@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artist);

    mHandler = new Handler();

    FragmentManager fm = getSupportFragmentManager();
    mActiveFragment = (ArtistFragment) fm.findFragmentByTag(TAG_FRAGMENT);

    if (savedInstanceState == null) {
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = getIntent().getExtras();
    } else {/*w  ww  .  ja v a  2  s  .  co m*/
        mHero = Utils.dequeueBitmap(BITMAP_ARTIST_HERO);
        mInitialIntent = savedInstanceState.getBundle(EXTRA_RESTORE_INTENT);
    }

    if (mActiveFragment == null) {
        mActiveFragment = new ArtistFragment();
        fm.beginTransaction().add(R.id.container, mActiveFragment, TAG_FRAGMENT).commit();
    }

    try {
        mActiveFragment.setArguments(mHero, mInitialIntent);
    } catch (IllegalStateException e) {
        Log.e(TAG, "Invalid artist!", e);
    }

    // Remove the activity title as we don't want it here
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setTitle("");
    }

    mIsEntering = true;

    if (Utils.hasLollipop()) {
        setEnterSharedElementCallback(new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                View fab = mActiveFragment.findViewById(R.id.fabPlay);
                fab.setVisibility(View.VISIBLE);

                // get the center for the clipping circle
                int cx = fab.getMeasuredWidth() / 2;
                int cy = fab.getMeasuredHeight() / 2;

                // get the final radius for the clipping circle
                final int finalRadius = fab.getWidth();

                // create and start the animator for this view
                // (the start radius is zero)
                Animator anim;
                if (mIsEntering) {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, 0, finalRadius);
                } else {
                    anim = ViewAnimationUtils.createCircularReveal(fab, cx, cy, finalRadius, 0);
                }
                anim.setInterpolator(new DecelerateInterpolator());
                anim.start();

                fab.setTranslationX(-fab.getMeasuredWidth() / 4.0f);
                fab.setTranslationY(-fab.getMeasuredHeight() / 4.0f);
                fab.animate().translationX(0.0f).translationY(0.0f)
                        .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                        .setInterpolator(new DecelerateInterpolator()).start();

                final View artistName = mActiveFragment.findViewById(R.id.tvArtist);
                if (artistName != null) {
                    cx = artistName.getMeasuredWidth() / 4;
                    cy = artistName.getMeasuredHeight() / 2;
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    final int radius = Utils.getEnclosingCircleRadius(artistName, cx, cy);

                    if (mIsEntering) {
                        artistName.setVisibility(View.INVISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, 0, radius, duration, 300);
                    } else {
                        artistName.setVisibility(View.VISIBLE);
                        Utils.animateCircleReveal(artistName, cx, cy, radius, 0, duration, 0);
                    }
                }
            }
        });
    }

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

From source file:android.support.v17.leanback.app.GuidedStepSupportFragment.java

/**
 * Returns the current GuidedStepSupportFragment on the fragment transaction stack.
 * @return The current GuidedStepSupportFragment, if any, on the fragment transaction stack.
 *///from   w w w.j  a  va 2s. c o  m
public static GuidedStepSupportFragment getCurrentGuidedStepSupportFragment(FragmentManager fm) {
    Fragment f = fm.findFragmentByTag(TAG_LEAN_BACK_ACTIONS_FRAGMENT);
    if (f instanceof GuidedStepSupportFragment) {
        return (GuidedStepSupportFragment) f;
    }
    return null;
}

From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java

@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;/*from ww w.j a v a2  s. c  om*/
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_intent_chooser_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
        holder.divider.setVisibility(View.VISIBLE);
    }

    holder.icon.setImageDrawable(DrawableHelper.getAppIcon(mContext, mApps.get(position).getApp()));
    holder.name.setText(mApps.get(position).getApp().loadLabel(mContext.getPackageManager()).toString());

    if (position == mApps.size() - 1) {
        holder.divider.setVisibility(View.GONE);
    }

    if (mApps.get(position).getType() == IntentChooser.TYPE_SUPPORTED) {
        holder.type.setTextColor(ColorHelper.getAttributeColor(mContext, android.R.attr.textColorSecondary));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_supported));
    } else if (mApps.get(position).getType() == IntentChooser.TYPE_RECOMMENDED) {
        holder.type.setTextColor(ColorHelper.getAttributeColor(mContext, R.attr.colorAccent));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_recommended));
    } else {
        holder.type.setTextColor(Color.parseColor("#F44336"));
        holder.type.setText(mContext.getResources().getString(R.string.intent_email_not_supported));
    }

    holder.container.setOnClickListener(v -> {
        ActivityInfo app = mApps.get(position).getApp().activityInfo;
        if (mApps.get(position).getType() == IntentChooser.TYPE_RECOMMENDED
                || mApps.get(position).getType() == IntentChooser.TYPE_SUPPORTED) {
            ComponentName name = new ComponentName(app.applicationInfo.packageName, app.name);
            sendRequest(name);

            FragmentManager fm = ((AppCompatActivity) mContext).getSupportFragmentManager();
            if (fm != null) {
                DialogFragment dialog = (DialogFragment) fm.findFragmentByTag(IntentChooserFragment.TAG);
                if (dialog != null) {
                    dialog.dismiss();
                }
            }
            return;
        }

        Toast.makeText(mContext, R.string.intent_email_not_supported_message, Toast.LENGTH_LONG).show();
    });

    return view;
}

From source file:com.dudka.rich.streamingmusicplayer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Fresco.initialize(this);

    FragmentManager fm = getSupportFragmentManager();
    musicPlayerUI = (FragmentMusicPlayerUI) fm.findFragmentByTag(fragmentTag);

    if (savedInstanceState == null) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.fragment_container, FragmentMusicPlayerUI.newInstance(), fragmentTag);
        ft.commit();//from  www.  j a  v  a2s .  c  o m
        fm.executePendingTransactions();
        musicPlayerUI = (FragmentMusicPlayerUI) fm.findFragmentByTag(fragmentTag);
    }

    boolean changingConfig = false;

    if (savedInstanceState != null) {
        changingConfig = savedInstanceState.getBoolean(IS_CHANGING_CONFIGURATIONS);
        isPlaying = savedInstanceState.getBoolean("isPlaying");
        songName = savedInstanceState.getString("songName");
        artistName = savedInstanceState.getString("artistName", artistName);
        coverImage = savedInstanceState.getString("coverImage", coverImage);
    }

    if (!changingConfig)
        handleVolley();
}

From source file:com.edicon.firebase.devs.firepix.NewPostActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_post);

    // find the retained fragment on activity restarts
    FragmentManager fm = getSupportFragmentManager();
    mTaskFragment = (NewPostUploadTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT);

    // create the fragment and data the first time
    if (mTaskFragment == null) {
        // add the fragment
        mTaskFragment = new NewPostUploadTaskFragment();
        fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit();
    }//from www.j  av a2  s .c  om

    mImageView = (ImageView) findViewById(R.id.new_post_picture);

    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showImagePicker();
        }
    });
    Bitmap selectedBitmap = mTaskFragment.getSelectedBitmap();
    Bitmap thumbnail = mTaskFragment.getThumbnail();
    if (selectedBitmap != null) {
        mImageView.setImageBitmap(selectedBitmap);
        mResizedBitmap = selectedBitmap;
    }
    if (thumbnail != null) {
        mThumbnail = thumbnail;
    }
    final EditText descriptionText = (EditText) findViewById(R.id.new_post_text);

    mSubmitButton = (Button) findViewById(R.id.new_post_submit);
    mSubmitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (mResizedBitmap == null) {
                Toast.makeText(NewPostActivity.this, "Select an image first.", Toast.LENGTH_SHORT).show();
                return;
            }
            String postText = descriptionText.getText().toString();
            if (TextUtils.isEmpty(postText)) {
                descriptionText.setError(getString(R.string.error_required_field));
                return;
            }
            showProgressDialog(getString(R.string.post_upload_progress_message));
            mSubmitButton.setEnabled(false);

            Long timestamp = System.currentTimeMillis();

            String bitmapPath = "/" + FirebaseUtil.getCurrentUserId() + "/full/" + timestamp.toString() + "/";
            String thumbnailPath = "/" + FirebaseUtil.getCurrentUserId() + "/thumb/" + timestamp.toString()
                    + "/";
            mTaskFragment.uploadPost(mResizedBitmap, bitmapPath, mThumbnail, thumbnailPath,
                    mFileUri.getLastPathSegment(), postText);
        }
    });
}

From source file:com.example.android.supportv7.app.ActionBarFragmentMenu.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_bar_fragment_menu);

    // Make sure the two menu fragments are created.
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    mFragment1 = (MenuFragment) fm.findFragmentByTag("f1");
    if (mFragment1 == null) {
        mFragment1 = new MenuFragment();
        ft.add(mFragment1, "f1");
    }// www .j a  va2 s  .  c o  m
    mFragment2 = (Menu2Fragment) fm.findFragmentByTag("f2");
    if (mFragment2 == null) {
        mFragment2 = new Menu2Fragment();
        ft.add(mFragment2, "f2");
    }
    ft.commit();

    // Watch check box clicks.
    mCheckBox1 = (CheckBox) findViewById(R.id.menu1);
    mCheckBox1.setOnClickListener(mClickListener);
    mCheckBox2 = (CheckBox) findViewById(R.id.menu2);
    mCheckBox2.setOnClickListener(mClickListener);
    mCheckBox3 = (CheckBox) findViewById(R.id.menu3);
    mCheckBox3.setOnClickListener(mClickListener);
    mHasOptionsMenu = (CheckBox) findViewById(R.id.has_options_menu);
    mHasOptionsMenu.setOnClickListener(mClickListener);
    mMenuVisibility = (CheckBox) findViewById(R.id.menu_visibility);
    mMenuVisibility.setOnClickListener(mClickListener);

    // Make sure fragments start out with correct visibility.
    updateFragmentVisibility();
}