Search in sources :

Example 66 with FragmentManager

use of android.app.FragmentManager in project android-percent-support-lib-sample by JulienGenoud.

the class MainActivity method onNavigationDrawerItemSelected.

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, PlaceholderFragment.newInstance(position + 1)).commit();
}
Also used : FragmentManager(android.app.FragmentManager)

Example 67 with FragmentManager

use of android.app.FragmentManager in project android_frameworks_base by crdroidandroid.

the class OpenExternalDirectoryActivity method showFragment.

/**
     * Validates the given path (volume + directory) and display the appropriate dialog asking the
     * user to grant access to it.
     */
private static boolean showFragment(OpenExternalDirectoryActivity activity, int userId, StorageVolume storageVolume, String directoryName) {
    if (DEBUG)
        Log.d(TAG, "showFragment() for volume " + storageVolume.dump() + ", directory " + directoryName + ", and user " + userId);
    final boolean isRoot = directoryName.equals(DIRECTORY_ROOT);
    final boolean isPrimary = storageVolume.isPrimary();
    if (isRoot && isPrimary) {
        if (DEBUG)
            Log.d(TAG, "root access requested on primary volume");
        return false;
    }
    final File volumeRoot = storageVolume.getPathFile();
    File file;
    try {
        file = isRoot ? volumeRoot : new File(volumeRoot, directoryName).getCanonicalFile();
    } catch (IOException e) {
        Log.e(TAG, "Could not get canonical file for volume " + storageVolume.dump() + " and directory " + directoryName);
        logInvalidScopedAccessRequest(activity, SCOPED_DIRECTORY_ACCESS_ERROR);
        return false;
    }
    final StorageManager sm = (StorageManager) activity.getSystemService(Context.STORAGE_SERVICE);
    final String root, directory;
    if (isRoot) {
        root = volumeRoot.getAbsolutePath();
        directory = ".";
    } else {
        root = file.getParent();
        directory = file.getName();
        // Verify directory is valid.
        if (TextUtils.isEmpty(directory) || !isStandardDirectory(directory)) {
            if (DEBUG)
                Log.d(TAG, "Directory '" + directory + "' is not standard (full path: '" + file.getAbsolutePath() + "')");
            logInvalidScopedAccessRequest(activity, SCOPED_DIRECTORY_ACCESS_INVALID_DIRECTORY);
            return false;
        }
    }
    // Gets volume label and converted path.
    String volumeLabel = null;
    String volumeUuid = null;
    final List<VolumeInfo> volumes = sm.getVolumes();
    if (DEBUG)
        Log.d(TAG, "Number of volumes: " + volumes.size());
    File internalRoot = null;
    boolean found = true;
    for (VolumeInfo volume : volumes) {
        if (isRightVolume(volume, root, userId)) {
            found = true;
            internalRoot = volume.getInternalPathForUser(userId);
            // Must convert path before calling getDocIdForFileCreateNewDir()
            if (DEBUG)
                Log.d(TAG, "Converting " + root + " to " + internalRoot);
            file = isRoot ? internalRoot : new File(internalRoot, directory);
            volumeUuid = storageVolume.getUuid();
            volumeLabel = sm.getBestVolumeDescription(volume);
            if (TextUtils.isEmpty(volumeLabel)) {
                volumeLabel = storageVolume.getDescription(activity);
            }
            if (TextUtils.isEmpty(volumeLabel)) {
                volumeLabel = activity.getString(android.R.string.unknownName);
                Log.w(TAG, "No volume description  for " + volume + "; using " + volumeLabel);
            }
            break;
        }
    }
    if (internalRoot == null) {
        // Should not happen on normal circumstances, unless app crafted an invalid volume
        // using reflection or the list of mounted volumes changed.
        Log.e(TAG, "Didn't find right volume for '" + storageVolume.dump() + "' on " + volumes);
        return false;
    }
    // Checks if the user has granted the permission already.
    final Intent intent = getIntentForExistingPermission(activity, isRoot, internalRoot, file);
    if (intent != null) {
        logValidScopedAccessRequest(activity, directory, SCOPED_DIRECTORY_ACCESS_ALREADY_GRANTED);
        activity.setResult(RESULT_OK, intent);
        activity.finish();
        return true;
    }
    if (!found) {
        Log.e(TAG, "Could not get volume for " + file);
        logInvalidScopedAccessRequest(activity, SCOPED_DIRECTORY_ACCESS_ERROR);
        return false;
    }
    // Gets the package label.
    final String appLabel = getAppLabel(activity);
    if (appLabel == null) {
        // Error already logged.
        return false;
    }
    // Sets args that will be retrieve on onCreate()
    final Bundle args = new Bundle();
    args.putString(EXTRA_FILE, file.getAbsolutePath());
    args.putString(EXTRA_VOLUME_LABEL, volumeLabel);
    args.putString(EXTRA_VOLUME_UUID, volumeUuid);
    args.putString(EXTRA_APP_LABEL, appLabel);
    args.putBoolean(EXTRA_IS_ROOT, isRoot);
    args.putBoolean(EXTRA_IS_PRIMARY, isPrimary);
    final FragmentManager fm = activity.getFragmentManager();
    final FragmentTransaction ft = fm.beginTransaction();
    final OpenExternalDirectoryDialogFragment fragment = new OpenExternalDirectoryDialogFragment();
    fragment.setArguments(args);
    ft.add(fragment, FM_TAG);
    ft.commitAllowingStateLoss();
    return true;
}
Also used : FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) Bundle(android.os.Bundle) StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File)

Example 68 with FragmentManager

use of android.app.FragmentManager in project android_frameworks_base by crdroidandroid.

the class FilesActivity method refreshDirectory.

@Override
void refreshDirectory(int anim) {
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();
    assert (!mSearchManager.isSearching());
    if (cwd == null) {
        DirectoryFragment.showRecentsOpen(fm, anim);
    } else {
        // Normal boring directory
        DirectoryFragment.showDirectory(fm, root, cwd, anim);
    }
}
Also used : FragmentManager(android.app.FragmentManager) RootInfo(com.android.documentsui.model.RootInfo) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 69 with FragmentManager

use of android.app.FragmentManager in project android_frameworks_base by crdroidandroid.

the class DocumentsActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final DocumentInfo cwd = getCurrentDirectory();
    boolean picking = mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE || mState.action == ACTION_PICK_COPY_DESTINATION;
    if (picking) {
        // May already be hidden because the root
        // doesn't support search.
        mSearchManager.showMenu(false);
    }
    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem fileSize = menu.findItem(R.id.menu_file_size);
    createDir.setVisible(picking);
    createDir.setEnabled(canCreateDirectory());
    // No display options in recent directories
    boolean inRecents = cwd == null;
    if (picking && inRecents) {
        grid.setVisible(false);
        list.setVisible(false);
    }
    fileSize.setVisible(fileSize.isVisible() && !picking);
    if (mState.action == ACTION_CREATE) {
        final FragmentManager fm = getFragmentManager();
        SaveFragment.get(fm).prepareForDirectory(cwd);
    }
    Menus.disableHiddenItems(menu);
    return true;
}
Also used : FragmentManager(android.app.FragmentManager) MenuItem(android.view.MenuItem) DocumentInfo(com.android.documentsui.model.DocumentInfo)

Example 70 with FragmentManager

use of android.app.FragmentManager in project android_frameworks_base by crdroidandroid.

the class MediaRouteDialogPresenter method showDialogFragment.

public static DialogFragment showDialogFragment(Activity activity, int routeTypes, View.OnClickListener extendedSettingsClickListener) {
    final MediaRouter router = (MediaRouter) activity.getSystemService(Context.MEDIA_ROUTER_SERVICE);
    final FragmentManager fm = activity.getFragmentManager();
    MediaRouter.RouteInfo route = router.getSelectedRoute();
    if (route.isDefault() || !route.matchesTypes(routeTypes)) {
        if (fm.findFragmentByTag(CHOOSER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route chooser dialog already showing!");
            return null;
        }
        MediaRouteChooserDialogFragment f = new MediaRouteChooserDialogFragment();
        f.setRouteTypes(routeTypes);
        f.setExtendedSettingsClickListener(extendedSettingsClickListener);
        f.show(fm, CHOOSER_FRAGMENT_TAG);
        return f;
    } else {
        if (fm.findFragmentByTag(CONTROLLER_FRAGMENT_TAG) != null) {
            Log.w(TAG, "showDialog(): Route controller dialog already showing!");
            return null;
        }
        MediaRouteControllerDialogFragment f = new MediaRouteControllerDialogFragment();
        f.show(fm, CONTROLLER_FRAGMENT_TAG);
        return f;
    }
}
Also used : FragmentManager(android.app.FragmentManager) MediaRouter(android.media.MediaRouter)

Aggregations

FragmentManager (android.app.FragmentManager)177 FragmentTransaction (android.app.FragmentTransaction)84 Fragment (android.app.Fragment)51 Bundle (android.os.Bundle)22 DocumentInfo (com.android.documentsui.model.DocumentInfo)20 DialogFragment (android.app.DialogFragment)15 RootInfo (com.android.documentsui.model.RootInfo)15 ActionBar (android.support.v7.app.ActionBar)12 Intent (android.content.Intent)11 File (java.io.File)6 MediaRouter (android.media.MediaRouter)5 Uri (android.net.Uri)5 StorageManager (android.os.storage.StorageManager)5 VolumeInfo (android.os.storage.VolumeInfo)5 MenuItem (android.view.MenuItem)5 IOException (java.io.IOException)5 Toolbar (android.support.v7.widget.Toolbar)4 View (android.view.View)4 DialogInterface (android.content.DialogInterface)3 ViewGroup (android.view.ViewGroup)3