Example usage for android.app Fragment getView

List of usage examples for android.app Fragment getView

Introduction

In this page you can find the example usage for android.app Fragment getView.

Prototype

@Nullable
public View getView() 

Source Link

Document

Get the root view for the fragment's layout (the one returned by #onCreateView ), if provided.

Usage

From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java

private static void bindUi(Fragment fragment, PermissionApps permissionApps) {
    final Drawable icon = permissionApps.getIcon();
    final CharSequence label = permissionApps.getLabel();
    final ActionBar ab = fragment.getActivity().getActionBar();
    if (ab != null) {
        ab.setTitle(fragment.getString(R.string.permission_title, label));
    }//from w  w  w. ja v  a 2 s . co m

    final ViewGroup rootView = (ViewGroup) fragment.getView();
    final ImageView iconView = (ImageView) rootView.findViewById(R.id.lb_icon);
    if (iconView != null) {
        // Set the icon as the background instead of the image because ImageView
        // doesn't properly scale vector drawables beyond their intrinsic size
        iconView.setBackground(icon);
    }
    final TextView titleView = (TextView) rootView.findViewById(R.id.lb_title);
    if (titleView != null) {
        titleView.setText(label);
    }
    final TextView breadcrumbView = (TextView) rootView.findViewById(R.id.lb_breadcrumb);
    if (breadcrumbView != null) {
        breadcrumbView.setText(R.string.app_permissions);
    }
}

From source file:dev.nick.accessories.injection.processors.ViewProcessor.java

protected Object parseField(Object container, Field field) {
    BindView bindView = field.getAnnotation(BindView.class);
    int id = checkId(bindView.value());
    View rootView;/*from   w  ww.  j  a va  2  s  .c  om*/
    boolean isProvider = container instanceof BindView.RootViewProvider;
    if (isProvider) {
        BindView.RootViewProvider provider = (BindView.RootViewProvider) container;
        rootView = provider.getRootView();
    } else if (container instanceof Activity) {
        Activity activity = (Activity) container;
        rootView = activity.getWindow().getDecorView();
    } else if (container instanceof Fragment) {
        Fragment fragment = (Fragment) container;
        rootView = fragment.getView();
    } else if (container instanceof android.support.v4.app.Fragment) {
        android.support.v4.app.Fragment fragmentV4 = (android.support.v4.app.Fragment) container;
        rootView = fragmentV4.getView();
    } else if (container instanceof View) {
        rootView = (View) container;
    } else if (container instanceof RecyclerView.ViewHolder) {
        RecyclerView.ViewHolder holder = (RecyclerView.ViewHolder) container;
        rootView = holder.itemView;
    } else {
        throw new IllegalArgumentException("You should impl BindView.RootViewProvider for no-component class");
    }
    Preconditions.checkNotNull(rootView, "No root view detected.");
    return rootView.findViewById(id);
}

From source file:com.lokiy.x.XQuery.java

public XQuery(android.support.v4.app.Fragment fragment) {
    if (fragment != null && fragment.getView() != null) {
        mContainer = fragment.getView();
        target = fragment;/*from  w  w w . j  a v a 2  s  .c  om*/
    } else
        throw new IllegalArgumentException("fragment is null or fragment.getView is null");
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on wipe wallet fragment
 */// w  w w  .  ja v a  2 s. c o m

public static void pressWipeWallet(final MainActivity context, final Fragment to) {
    try {
        if (!wipeWalletOpen) {
            wipeWalletOpen = true;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.main_layout, to, to.getClass().getName());
            fragmentTransaction.commit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = to.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

        } else {
            wipeWalletOpen = false;
            FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            fragmentTransaction.replace(R.id.main_layout, new FragmentSettings(),
                    FragmentSettings.class.getName());
            fragmentTransaction.commit();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Fragment fragment = getFragmentManager().findFragmentById(android.R.id.content);
        if (fragment instanceof PreferenceFragment && fragment.getView() != null) {
            // Set list view padding to 0 so dividers are the full width of the screen.
            fragment.getView().findViewById(android.R.id.list).setPadding(0, 0, 0, 0);
        }//w ww. j a  v a  2 s.  c o m
    }
}

From source file:ca.farrelltonsolar.uicomponents.TabStripAdapter.java

public void removeTab(Class<?> fragmentClass) {
    int position = 0;
    for (TabInfo ti : tabs) {
        if (ti.mClass.equals(fragmentClass)) {
            tabs.remove(position);/*from   w w  w .  j av  a 2 s .  c  o  m*/
            break;
        }
        position++;
    }
    String tag = makeFragmentName(viewPager.getId(), getItemId(position));
    Fragment oldFragment = fragmentManager.findFragmentByTag(tag);
    if (oldFragment != null) {
        //        remove it
        destroyItem(null, position, oldFragment);
        finishUpdate(null);
        viewPager.removeView(oldFragment.getView());
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.remove(oldFragment);
        transaction.commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
    }
}

From source file:com.afollestad.overhear.ui.OverviewScreen.java

/**
 * Sets up the action bar tabs and the view pager.
 *///from   w ww. j  av a 2s  .c  o  m
private void setupTabs() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(5);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getActionBar().setSelectedNavigationItem(position);
        }
    });

    ActionBar.TabListener mTabListener = new ActionBar.TabListener() {
        @Override
        public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

        }

        @Override
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            invalidateOptionsMenu();
            mViewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
            Fragment frag = getFragmentManager().findFragmentByTag("page:" + tab.getPosition());
            if (frag instanceof ListFragment) {
                if (frag.getView() != null)
                    ((ListFragment) frag).getListView().setSelection(0);
            } else if (frag instanceof OverhearGridFragment) {
                if (frag.getView() != null)
                    ((OverhearGridFragment) frag).getListView().setSelection(0);
            }
        }
    };

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++)
        actionBar.addTab(
                actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(mTabListener));
    actionBar.setSelectedNavigationItem(Store.i(this, "focused_tab", 2));
}

From source file:com.codefororlando.transport.MapsActivity.java

private void removeSelectableItemFragment() {
    final Fragment selectableItemFragment = getFragmentManager().findFragmentByTag(ISelectableItemFragment.TAG);
    if (selectableItemFragment != null) {
        final View view = selectableItemFragment.getView();
        if (view == null) {
            return;
        }//from  w  w w  . j a v  a  2s .c o m

        final int animationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        {
            final Animation animation = new TranslateAnimation(0, 0, 0, view.getHeight());
            animation.setDuration(animationDuration);
            animation.setInterpolator(new AccelerateDecelerateInterpolator());
            filterView.startAnimation(animation);
        }
        {
            final FragmentManager fragmentManager = getFragmentManager();
            final Animation animation = new TranslateAnimation(0, 0, 0, view.getHeight());
            animation.setDuration(animationDuration);
            animation.setAnimationListener(new EmptyAnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    try {
                        fragmentManager.beginTransaction().remove(selectableItemFragment)
                                .commitAllowingStateLoss();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            view.startAnimation(animation);
        }
    }
}

From source file:com.tapchatapp.android.app.ui.TapchatFragmentStatePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
        Fragment f = mFragments.get(position);
        if (f != null) {
            int newPos = getItemPosition(f);
            if (position == newPos) {
                if (f.getView() != null && f.getView().getParent() != container) {
                    ((ViewGroup) f.getView().getParent()).removeView(f.getView());
                    container.addView(f.getView());
                }/*w w w. j  a  v  a2s.c  o  m*/
                return f;
            } else {
                mFragments.remove(position);
                mFragments.ensureCapacity(newPos + 1);
                for (int i = mFragments.size(); i < (newPos + 1); i++) {
                    mFragments.add(null);
                }
                mFragments.set(newPos, f);
            }
        }
    }

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG)
        Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
        Fragment.SavedState fss = mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment, getTag(position));

    return fragment;
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private int getParentId(final Fragment fragment) {
    if (fragment.getView() != null && fragment.getView().getParent() != null) {
        return ((View) fragment.getView().getParent()).getId();
    }/*from  ww  w .  j  a  va  2 s .  co  m*/
    return 0;
}