FileDocCategorySizeDatePackage
RootsFragment.javaAPI DocAndroid 5.1 API13989Thu Mar 12 22:22:40 GMT 2015com.android.documentsui

RootsFragment

public class RootsFragment extends android.app.Fragment
Display list of known storage backend roots.

Fields Summary
private android.widget.ListView
mList
private RootsAdapter
mAdapter
private android.app.LoaderManager.LoaderCallbacks
mCallbacks
private static final String
EXTRA_INCLUDE_APPS
private android.widget.AdapterView.OnItemClickListener
mItemListener
private android.widget.AdapterView.OnItemLongClickListener
mItemLongClickListener
Constructors Summary
Methods Summary
public static com.android.documentsui.RootsFragmentget(android.app.FragmentManager fm)

        return (RootsFragment) fm.findFragmentById(R.id.container_roots);
    
public voidonActivityCreated(android.os.Bundle savedInstanceState)

        super.onActivityCreated(savedInstanceState);

        final Context context = getActivity();
        final RootsCache roots = DocumentsApplication.getRootsCache(context);
        final State state = ((DocumentsActivity) context).getDisplayState();

        mCallbacks = new LoaderCallbacks<Collection<RootInfo>>() {
            @Override
            public Loader<Collection<RootInfo>> onCreateLoader(int id, Bundle args) {
                return new RootsLoader(context, roots, state);
            }

            @Override
            public void onLoadFinished(
                    Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) {
                if (!isAdded()) return;

                final Intent includeApps = getArguments().getParcelable(EXTRA_INCLUDE_APPS);

                mAdapter = new RootsAdapter(context, result, includeApps);
                mList.setAdapter(mAdapter);

                onCurrentRootChanged();
            }

            @Override
            public void onLoaderReset(Loader<Collection<RootInfo>> loader) {
                mAdapter = null;
                mList.setAdapter(null);
            }
        };
    
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)

        final Context context = inflater.getContext();

        final View view = inflater.inflate(R.layout.fragment_roots, container, false);
        mList = (ListView) view.findViewById(android.R.id.list);
        mList.setOnItemClickListener(mItemListener);
        mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        return view;
    
public voidonCurrentRootChanged()

        if (mAdapter == null) return;

        final RootInfo root = ((DocumentsActivity) getActivity()).getCurrentRoot();
        for (int i = 0; i < mAdapter.getCount(); i++) {
            final Object item = mAdapter.getItem(i);
            if (item instanceof RootItem) {
                final RootInfo testRoot = ((RootItem) item).root;
                if (Objects.equals(testRoot, root)) {
                    mList.setItemChecked(i, true);
                    return;
                }
            }
        }
    
public voidonDisplayStateChanged()

        final Context context = getActivity();
        final State state = ((DocumentsActivity) context).getDisplayState();

        if (state.action == ACTION_GET_CONTENT) {
            mList.setOnItemLongClickListener(mItemLongClickListener);
        } else {
            mList.setOnItemLongClickListener(null);
            mList.setLongClickable(false);
        }

        getLoaderManager().restartLoader(2, null, mCallbacks);
    
public voidonResume()

        super.onResume();
        onDisplayStateChanged();
    
public static voidshow(android.app.FragmentManager fm, android.content.Intent includeApps)


           
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_INCLUDE_APPS, includeApps);

        final RootsFragment fragment = new RootsFragment();
        fragment.setArguments(args);

        final FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.container_roots, fragment);
        ft.commitAllowingStateLoss();
    
private voidshowAppDetails(android.content.pm.ResolveInfo ri)

        final Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.fromParts("package", ri.activityInfo.packageName, null));
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivity(intent);