Search in sources :

Example 61 with FragmentTransaction

use of android.app.FragmentTransaction 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 62 with FragmentTransaction

use of android.app.FragmentTransaction in project XobotOS by xamarin.

the class ActionBarImpl method selectTab.

@Override
public void selectTab(Tab tab) {
    if (getNavigationMode() != NAVIGATION_MODE_TABS) {
        mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
        return;
    }
    final FragmentTransaction trans = mActivity.getFragmentManager().beginTransaction().disallowAddToBackStack();
    if (mSelectedTab == tab) {
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
            mTabScrollView.animateToTab(tab.getPosition());
        }
    } else {
        mTabScrollView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
        }
        mSelectedTab = (TabImpl) tab;
        if (mSelectedTab != null) {
            mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
        }
    }
    if (!trans.isEmpty()) {
        trans.commit();
    }
}
Also used : FragmentTransaction(android.app.FragmentTransaction)

Example 63 with FragmentTransaction

use of android.app.FragmentTransaction in project Etar-Calendar by Etar-Group.

the class SelectVisibleCalendarsActivity method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    dynamicTheme.onCreate(this);
    setContentView(R.layout.simple_frame_layout);
    mController = CalendarController.getInstance(this);
    mFragment = (SelectVisibleCalendarsFragment) getFragmentManager().findFragmentById(R.id.main_frame);
    if (mFragment == null) {
        mFragment = new SelectVisibleCalendarsFragment(R.layout.calendar_sync_item);
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.main_frame, mFragment);
        ft.show(mFragment);
        ft.commit();
    }
}
Also used : FragmentTransaction(android.app.FragmentTransaction)

Example 64 with FragmentTransaction

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

the class BiDiTestActivity method onListItemClick.

private void onListItemClick(ListView lv, View v, int position, long id) {
    // Show the test
    Map<String, Object> map = (Map<String, Object>) lv.getItemAtPosition(position);
    int fragmentId = (Integer) map.get(KEY_FRAGMENT_ID);
    Fragment fragment = getFragmentManager().findFragmentById(fragmentId);
    if (fragment == null) {
        try {
            // Create an instance of the test
            Class<? extends Fragment> clazz = (Class<? extends Fragment>) map.get(KEY_CLASS);
            fragment = clazz.newInstance();
            // Replace the old test fragment with the new one
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.replace(R.id.testframe, fragment);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.commit();
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
    }
}
Also used : FragmentTransaction(android.app.FragmentTransaction) HashMap(java.util.HashMap) Map(java.util.Map) Fragment(android.app.Fragment)

Example 65 with FragmentTransaction

use of android.app.FragmentTransaction in project Etar-Calendar by Etar-Group.

the class SearchActivity method deleteEvent.

private void deleteEvent(long eventId, long startMillis, long endMillis) {
    mDeleteEventHelper.delete(startMillis, endMillis, eventId, -1);
    if (mIsMultipane && mEventInfoFragment != null && eventId == mCurrentEventId) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.remove(mEventInfoFragment);
        ft.commit();
        mEventInfoFragment = null;
        mCurrentEventId = -1;
    }
}
Also used : FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction)

Aggregations

FragmentTransaction (android.app.FragmentTransaction)245 Fragment (android.app.Fragment)65 FragmentManager (android.app.FragmentManager)64 Bundle (android.os.Bundle)41 DialogFragment (android.app.DialogFragment)20 Intent (android.content.Intent)18 FragmentActivity (android.support.v4.app.FragmentActivity)16 PreferenceFragment (android.support.v14.preference.PreferenceFragment)7 View (android.view.View)7 HashMap (java.util.HashMap)7 File (java.io.File)6 SuppressLint (android.annotation.SuppressLint)5 StorageManager (android.os.storage.StorageManager)5 VolumeInfo (android.os.storage.VolumeInfo)5 Fade (android.transition.Fade)5 TextView (android.widget.TextView)5 Selection (com.android.documentsui.dirlist.MultiSelectManager.Selection)5 IOException (java.io.IOException)5 Uri (android.net.Uri)4 Map (java.util.Map)4