Search in sources :

Example 21 with FragmentManager

use of android.app.FragmentManager in project WordPress-Android by wordpress-mobile.

the class EditorFragment method onMediaTapped.

public void onMediaTapped(final String mediaId, final MediaType mediaType, final JSONObject meta, String uploadStatus) {
    if (mediaType == null || !isAdded()) {
        return;
    }
    switch(uploadStatus) {
        case "uploading":
            // Display 'cancel upload' dialog
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.stop_upload_dialog_title));
            builder.setPositiveButton(R.string.stop_upload_button, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    mEditorFragmentListener.onMediaUploadCancelClicked(mediaId, true);
                    mWebView.post(new Runnable() {

                        @Override
                        public void run() {
                            switch(mediaType) {
                                case IMAGE:
                                    mWebView.execJavaScriptFromString("ZSSEditor.removeImage(" + mediaId + ");");
                                    break;
                                case VIDEO:
                                    mWebView.execJavaScriptFromString("ZSSEditor.removeVideo(" + mediaId + ");");
                            }
                            mUploadingMedia.remove(mediaId);
                        }
                    });
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
            break;
        case "failed":
            // Retry media upload
            mEditorFragmentListener.onMediaRetryClicked(mediaId);
            mWebView.post(new Runnable() {

                @Override
                public void run() {
                    switch(mediaType) {
                        case IMAGE:
                            mWebView.execJavaScriptFromString("ZSSEditor.unmarkImageUploadFailed(" + mediaId + ");");
                            break;
                        case VIDEO:
                            mWebView.execJavaScriptFromString("ZSSEditor.unmarkVideoUploadFailed(" + mediaId + ");");
                    }
                    mFailedMediaIds.remove(mediaId);
                    mUploadingMedia.put(mediaId, mediaType);
                }
            });
            break;
        default:
            if (!mediaType.equals(MediaType.IMAGE)) {
                return;
            }
            // Only show image options fragment for image taps
            FragmentManager fragmentManager = getFragmentManager();
            if (fragmentManager.findFragmentByTag(ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG) != null) {
                return;
            }
            mEditorFragmentListener.onTrackableEvent(TrackableEvent.IMAGE_EDITED);
            ImageSettingsDialogFragment imageSettingsDialogFragment = new ImageSettingsDialogFragment();
            imageSettingsDialogFragment.setTargetFragment(this, ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_REQUEST_CODE);
            Bundle dialogBundle = new Bundle();
            dialogBundle.putString("maxWidth", mBlogSettingMaxImageWidth);
            dialogBundle.putBoolean("featuredImageSupported", mFeaturedImageSupported);
            // Request and add an authorization header for HTTPS images
            // Use https:// when requesting the auth header, in case the image is incorrectly using http://.
            // If an auth header is returned, force https:// for the actual HTTP request.
            HashMap<String, String> headerMap = new HashMap<>();
            if (mCustomHttpHeaders != null) {
                headerMap.putAll(mCustomHttpHeaders);
            }
            try {
                final String imageSrc = meta.getString("src");
                String authHeader = mEditorFragmentListener.onAuthHeaderRequested(UrlUtils.makeHttps(imageSrc));
                if (authHeader.length() > 0) {
                    meta.put("src", UrlUtils.makeHttps(imageSrc));
                    headerMap.put("Authorization", authHeader);
                }
            } catch (JSONException e) {
                AppLog.e(T.EDITOR, "Could not retrieve image url from JSON metadata");
            }
            dialogBundle.putSerializable("headerMap", headerMap);
            dialogBundle.putString("imageMeta", meta.toString());
            String imageId = JSONUtils.getString(meta, "attachment_id");
            if (!imageId.isEmpty()) {
                dialogBundle.putBoolean("isFeatured", mFeaturedImageId == Integer.parseInt(imageId));
            }
            imageSettingsDialogFragment.setArguments(dialogBundle);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            fragmentTransaction.add(android.R.id.content, imageSettingsDialogFragment, ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG).addToBackStack(null).commit();
            mWebView.notifyVisibilityChanged(false);
            break;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(android.os.Bundle) JSONException(org.json.JSONException) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint) FragmentManager(android.app.FragmentManager) OnClickListener(android.content.DialogInterface.OnClickListener) FragmentTransaction(android.app.FragmentTransaction)

Example 22 with FragmentManager

use of android.app.FragmentManager in project mechanoid by robotoworks.

the class OperationManager method create.

public static OperationManager create(Activity activity, OperationManagerCallbacks callbacks, boolean enableLogging) {
    String tag = "Tags." + callbacks.getClass().getName();
    OperationManager operationManager = null;
    FragmentManager fm = activity.getFragmentManager();
    PersistenceFragment frag = (PersistenceFragment) fm.findFragmentByTag(tag);
    if (frag == null) {
        if (enableLogging) {
            Log.d(TAG, String.format("[Create Fragment] tag:%s", tag));
        }
        frag = new PersistenceFragment();
        operationManager = new OperationManager(callbacks, enableLogging);
        frag.setOperationManager(operationManager);
        fm.beginTransaction().add(frag, tag).commit();
    } else {
        if (enableLogging) {
            Log.d(TAG, String.format("[Recover Fragment] tag:%s", tag));
        }
        operationManager = (OperationManager) frag.getOperationManager();
        if (operationManager == null) {
            if (enableLogging) {
                Log.d(TAG, String.format("[Create Manager] tag:%s", tag));
            }
            operationManager = new OperationManager(callbacks, enableLogging);
            frag.setOperationManager(operationManager);
        } else {
            if (enableLogging) {
                Log.d(TAG, String.format("[Recover Manager] tag:%s", tag));
            }
            operationManager.mCallbacks = callbacks;
        }
    }
    return operationManager;
}
Also used : FragmentManager(android.app.FragmentManager)

Example 23 with FragmentManager

use of android.app.FragmentManager in project UltimateAndroid by cymcsg.

the class PercentSampleActivity 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 24 with FragmentManager

use of android.app.FragmentManager in project AndroidDynamicLoader by mmin18.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    int error = 0;
    // must be load at the first start
    do {
        site = intent.getParcelableExtra("_site");
        if (site == null) {
            // #201
            error = 201;
            break;
        }
        fragmentName = intent.getStringExtra("_fragment");
        if (TextUtils.isEmpty(fragmentName)) {
            // #202
            error = 202;
            break;
        }
        String code = intent.getStringExtra("_code");
        if (TextUtils.isEmpty(code)) {
            loaded = true;
            break;
        }
        file = site.getFile(code);
        if (file == null) {
            // #205
            error = 205;
            break;
        }
        classLoader = MyClassLoader.getClassLoader(site, file);
        loaded = classLoader != null;
        if (!loaded) {
            // #210
            error = 210;
            break;
        }
    } while (false);
    super.onCreate(savedInstanceState);
    rootView = new FrameLayout(this);
    rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    rootView.setId(android.R.id.primary);
    setContentView(rootView);
    if (!loaded) {
        TextView text = new TextView(this);
        text.setText("无法载入页面" + (error == 0 ? "" : " #" + error));
        text.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        rootView.addView(text);
        return;
    }
    // the fragment will be restored by framework
    if (savedInstanceState != null)
        return;
    Fragment fragment = null;
    try {
        fragment = (Fragment) getClassLoader().loadClass(fragmentName).newInstance();
    } catch (Exception e) {
        loaded = false;
        classLoader = null;
        // #211
        error = 211;
        TextView text = new TextView(this);
        text.setText("无法载入页面 #" + error);
        text.append("\n" + e);
        text.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
        rootView.addView(text);
        return;
    }
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(android.R.id.primary, fragment);
    ft.commit();
}
Also used : ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) Fragment(android.app.Fragment) FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView)

Example 25 with FragmentManager

use of android.app.FragmentManager in project AndroidDynamicLoader by mmin18.

the class FragmentDeveloper method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout rootView = new FrameLayout(this);
    rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    rootView.setId(android.R.id.primary);
    setContentView(rootView);
    if (savedInstanceState == null) {
        Fragment f = new SampleFragment();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(android.R.id.primary, f);
        ft.commit();
    }
}
Also used : FragmentManager(android.app.FragmentManager) SampleFragment(com.dianping.example.fragment.SampleFragment) FragmentTransaction(android.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) Fragment(android.app.Fragment) SampleFragment(com.dianping.example.fragment.SampleFragment)

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