Search in sources :

Example 51 with FragmentManager

use of android.app.FragmentManager in project PhotoNoter by yydcdut.

the class GalleryActivity method onNavigationItemSelected.

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.nav_gallery) {
        FragmentManager fragmentManager = getFragmentManager();
        if (mMediaPhotoFragment == null) {
            mMediaPhotoFragment = MediaPhotoFragment.newInstance();
        }
        fragmentManager.beginTransaction().replace(R.id.layout_photo, mMediaPhotoFragment).commit();
    } else if (id == R.id.nav_file) {
    //            FragmentManager fragmentManager = getSupportFragmentManager();
    //            if (mFilePhotoFragment == null) {
    //                mFilePhotoFragment = FilePhotoFragment.newInstance();
    //            }
    //            fragmentManager.beginTransaction().replace(R.id.layout_photo, mFilePhotoFragment).commit();
    }
    mDrawerLayout.closeDrawer(GravityCompat.START);
    return true;
}
Also used : FragmentManager(android.app.FragmentManager)

Example 52 with FragmentManager

use of android.app.FragmentManager in project PhotoNoter by yydcdut.

the class GalleryActivity method initUiAndListener.

@Override
public void initUiAndListener() {
    initToolBar();
    initDrawer();
    int color = ThemeHelper.getPrimaryColor(this);
    setDrawerStatusBar(color);
    initThirdGalleryAppAdapter(mGalleryPresenter.getGalleryAppList());
    FragmentManager fragmentManager = getFragmentManager();
    mMediaPhotoFragment = MediaPhotoFragment.newInstance();
    fragmentManager.beginTransaction().replace(R.id.layout_photo, mMediaPhotoFragment).commit();
}
Also used : FragmentManager(android.app.FragmentManager)

Example 53 with FragmentManager

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

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 54 with FragmentManager

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

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 55 with FragmentManager

use of android.app.FragmentManager in project Space-Station-Tracker by Kiarasht.

the class Preferences method onCreate.

/**
     * Start the settings fragment and do it only if one already doesn't exists. The preference
     * activity only hosts the standalone fragment.
     *
     * @param savedInstanceState if it's null, then we need to create the fragment
     */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_general);
    if (savedInstanceState == null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        SettingsFragment settingsFragment = new SettingsFragment();
        fragmentTransaction.add(android.R.id.content, settingsFragment, "SETTINGS_FRAGMENT");
        fragmentTransaction.commit();
    }
}
Also used : FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction)

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