public static void showAuthErrorView(Activity activity, int titleResId, int messageResId) {
    final String ALERT_TAG = "alert_ask_credentials";
    if (activity.isFinishing()) {
      return;
    }

    // WP.com errors will show the sign in activity
    if (WordPress.getCurrentBlog() == null
        || (WordPress.getCurrentBlog() != null && WordPress.getCurrentBlog().isDotcomFlag())) {
      Intent signInIntent = new Intent(activity, SignInActivity.class);
      signInIntent.putExtra(SignInActivity.ARG_IS_AUTH_ERROR, true);
      signInIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      activity.startActivityForResult(signInIntent, SignInActivity.REQUEST_CODE);
      return;
    }

    // abort if the dialog is already visible
    if (activity.getFragmentManager().findFragmentByTag(ALERT_TAG) != null) {
      return;
    }

    FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
    AuthErrorDialogFragment authAlert = new AuthErrorDialogFragment();
    authAlert.setWPComTitleMessage(titleResId, messageResId);
    ft.add(authAlert, ALERT_TAG);
    ft.commitAllowingStateLoss();
  }
Example #2
1
 @SuppressLint("ValidFragment")
 public static void startFilterEntry(final Activity activity) {
   new DialogFragment() {
     public Dialog onCreateDialog(Bundle savedInstanceState) {
       final EditText filterInput = new EditText(activity);
       filterInput.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER);
       ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
           .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
       return new AlertDialog.Builder(activity)
           .setView(filterInput)
           .setPositiveButton(
               android.R.string.ok,
               new OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int which) {
                   String filterText = filterInput.getText().toString();
                   if (activity instanceof Filterable)
                     ((Filterable) activity).filterItems(filterText);
                 }
               })
           .setNegativeButton(android.R.string.cancel, null)
           .create();
     };
   }.show(activity.getFragmentManager(), "filterentry");
 }
  /**
   * @param activity The context (normally the UI context)
   * @return boolean True if successfully connected
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private final boolean servicesConnected(Activity activity) {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
      Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              resultCode, activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
      // Can Google Play service provide an error dialog
      if (errorDialog != null) {

        PackageInfo pInfo;
        try {
          pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
          // only version 11 and above support ErrorDialogFragment
          if (pInfo.versionCode >= Build.VERSION_CODES.HONEYCOMB) {
            ErrorDialogFragment errorFragment = new ErrorDialogFragment();
            // Set the dialog in the DialogFragment
            errorFragment.setDialog(errorDialog);
            // Show the error dialog in the DialogFragment
            errorFragment.show(activity.getFragmentManager(), serviceDescription_);
          }
        } catch (NameNotFoundException e) {
          Log.w(serviceDescription_, "Unable to determine version", e);
        }
      } else {
        Log.e(serviceDescription_, "Failed to get Map Service" + resultCode);
      }
      return false;
    } else {
      Log.d(serviceDescription_, "Google Play services is available.");
      return true;
    }
  }
  /**
   * Sets an OnToastButtonClickListener to the button in a a BUTTON type SuperCardToast. <br>
   * IMPORTANT: On Devices > API 11 any listener passed will automaticly be saved to a retained
   * Fragment for preservation on orientation changes. <br>
   *
   * @param onToastButtonClickListener Use OnToastButtonClickListenerHolder for orientation change
   *     support
   */
  public void setOnToastButtonClickListener(
      OnToastButtonClickListenerHolder onToastButtonClickListener) {

    mToastButton.setOnClickListener(onToastButtonClickListener);

    this.mClickListenerTag = onToastButtonClickListener.getTag();

    /** On devices > API 11 save listener to retained Fragment */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

      final Activity activity = (Activity) mContext;

      FragmentManager fragmentManager = activity.getFragmentManager();

      FragmentRetainer fragmentRetainer =
          (FragmentRetainer) fragmentManager.findFragmentByTag(FRAGMENTRETAINER_ID);

      if (fragmentRetainer == null) {

        fragmentRetainer = new FragmentRetainer();
        fragmentManager.beginTransaction().add(fragmentRetainer, FRAGMENTRETAINER_ID).commit();
      }

      fragmentRetainer.addClickListenerToList(onToastButtonClickListener);
    }
  }
 public static void showMe(Activity activity, Uri uri) {
   TrackInfoFragment trackInfoFragment = new TrackInfoFragment();
   Bundle bundle = new Bundle();
   bundle.putString("uri", uri.toString());
   trackInfoFragment.setArguments(bundle);
   trackInfoFragment.show(activity.getFragmentManager(), "TrackInfo");
 }
Example #6
0
  /**
   * Display the info of this photo.
   *
   * @param activity the triggering activity
   * @param eyePhoto the photo for which the image should be displayed.
   */
  public static void displayImageInfo(
      @NonNull final Activity activity, @NonNull final EyePhoto eyePhoto) {
    StringBuilder message = new StringBuilder();
    message.append(
        formatImageInfoLine(activity, R.string.imageinfo_line_filename, eyePhoto.getFilename()));
    message.append(
        formatImageInfoLine(activity, R.string.imageinfo_line_filedate, eyePhoto.getDateString()));

    try {
      JpegMetadata metadata = JpegSynchronizationUtil.getJpegMetadata(eyePhoto.getAbsolutePath());

      if (metadata.getPerson() != null && metadata.getPerson().length() > 0) {
        message.append(
            formatImageInfoLine(activity, R.string.imageinfo_line_name, metadata.getPerson()));
      }
      if (metadata.getComment() != null && metadata.getComment().length() > 0) {
        message.append(
            formatImageInfoLine(activity, R.string.imageinfo_line_comment, metadata.getComment()));
      }
    } catch (Exception e) {
      // cannot append metadata.
    }

    Bundle bundle = new Bundle();
    bundle.putCharSequence(PARAM_MESSAGE, Html.fromHtml(message.toString()));
    bundle.putString(PARAM_TITLE, activity.getString(R.string.title_dialog_image_info));
    bundle.putInt(PARAM_ICON, R.drawable.ic_title_info);
    DialogFragment fragment = new DisplayMessageDialogFragment();
    fragment.setArguments(bundle);
    fragment.show(activity.getFragmentManager(), fragment.getClass().toString());
  }
 public static void singleFragmentActivityAddFragmentToContentView(
     Activity fragmentActivity, Fragment fragment) {
   FragmentManager fm = fragmentActivity.getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   ft.add(CONTENT_VIEW_ID, fragment);
   ft.commit();
 }
  /**
   * Create a new instance of {@link BraintreeFragment} using the client token and add it to the
   * {@link Activity}'s {@link FragmentManager}.
   *
   * @param activity The {@link Activity} to add the {@link Fragment} to.
   * @param authorization The tokenization key or client token to use.
   * @return {@link BraintreeFragment}
   * @throws InvalidArgumentException If the tokenization key or client token is not valid or cannot
   *     be parsed.
   */
  public static BraintreeFragment newInstance(Activity activity, String authorization)
      throws InvalidArgumentException {
    FragmentManager fm = activity.getFragmentManager();

    String integrationType = "custom";
    try {
      if (Class.forName("com.braintreepayments.api.BraintreePaymentActivity")
          .isInstance(activity)) {
        integrationType = "dropin";
      }
    } catch (ClassNotFoundException ignored) {
    }

    BraintreeFragment braintreeFragment = (BraintreeFragment) fm.findFragmentByTag(TAG);
    if (braintreeFragment == null) {
      braintreeFragment = new BraintreeFragment();
      Bundle bundle = new Bundle();

      try {
        Authorization auth = Authorization.fromString(authorization);
        bundle.putParcelable(EXTRA_AUTHORIZATION_TOKEN, auth);
      } catch (InvalidArgumentException e) {
        throw new InvalidArgumentException("Tokenization Key or client token was invalid.");
      }

      bundle.putString(EXTRA_INTEGRATION_TYPE, integrationType);
      braintreeFragment.setArguments(bundle);
      fm.beginTransaction().add(braintreeFragment, TAG).commit();
    }

    return braintreeFragment;
  }
 private void createFragment(Activity activity) {
   // Use a fragment to ensure the background manager gets detached properly.
   BackgroundFragment fragment =
       (BackgroundFragment) activity.getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
   if (fragment == null) {
     fragment = new BackgroundFragment();
     activity.getFragmentManager().beginTransaction().add(fragment, FRAGMENT_TAG).commit();
   } else {
     if (fragment.getBackgroundManager() != null) {
       throw new IllegalStateException(
           "Created duplicated BackgroundManager for same "
               + "activity, please use getInstance() instead");
     }
   }
   fragment.setBackgroundManager(this);
 }
Example #10
0
 protected void onPostExecute(ArrayList<MeliProduct> result) {
   super.onPostExecute(result);
   ProductListFragment fragment =
       (ProductListFragment) activityContext.getFragmentManager().findFragmentByTag("list");
   if (fragment != null) {
     fragment.setItems(result);
   }
 }
 public TabsAdapter(Activity activity, ViewPager pager) {
   super(activity.getFragmentManager());
   mContext = activity;
   mActionBar = activity.getActionBar();
   mViewPager = pager;
   mViewPager.setAdapter(this);
   mViewPager.setOnPageChangeListener(this);
 }
Example #12
0
 /**
  * Attaches the fragment to the activity.
  *
  * @param activity activity the fragment is added to
  * @param tag tag to add the fragment
  * @param visible true if the activity should have visible called
  */
 private static void startFragmentHelper(
     Activity activity, Fragment fragment, String tag, boolean visible) {
   if (visible) {
     ActivityController.of(activity).visible();
   }
   FragmentManager fragmentManager = activity.getFragmentManager();
   fragmentManager.beginTransaction().add(fragment, tag).commit();
 }
 private void showErrorDialog(int errorCode, Activity activity) {
   // Create a fragment for the error dialog
   ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
   // Pass the error that should be displayed
   Bundle args = new Bundle();
   args.putInt(DIALOG_ERROR, errorCode);
   dialogFragment.setArguments(args);
   dialogFragment.show(activity.getFragmentManager(), "errordialog");
 }
Example #14
0
 /**
  * Helper method
  *
  * @param parent FragmentActivity
  * @return
  */
 public static CameraDialog showDialog(Activity parent /* add parameters here if you need */) {
   CameraDialog dialog = newInstance(/* add parameters here if you need */ );
   try {
     dialog.show(parent.getFragmentManager(), TAG);
   } catch (IllegalStateException e) {
     dialog = null;
   }
   return dialog;
 }
Example #15
0
 @Override
 public void replaceToDetailFragment(int id) {
   FragmentManager fragmentManager = activity.getFragmentManager();
   DetailFragment detailFragment = DetailFragment.newInstance(id);
   fragmentManager
       .beginTransaction()
       .replace(R.id.fragment_container, detailFragment)
       .addToBackStack(null)
       .commit();
 }
Example #16
0
 public static void showWiFiDialog(Activity activity) {
   FragmentManager fm = activity.getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   Fragment prev = fm.findFragmentByTag("dialog_wifi");
   if (prev != null) {
     ft.remove(prev);
   }
   ft.addToBackStack(null);
   WiFiDialog.newInstance(isWiFiEnabled(activity)).show(ft, "dialog_wifi");
 }
Example #17
0
  public static void showAbout(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog().show(ft, "dialog_about");
  }
 private void startFragmentOrActivityForResult(
     Intent pickIntent, int requestCode, int fragmentId) {
   if (fragmentId == 0) {
     mParent.startActivityForResult(pickIntent, requestCode);
   } else {
     Fragment cFrag = mParent.getFragmentManager().findFragmentById(fragmentId);
     if (cFrag != null) {
       mParent.startActivityFromFragment(cFrag, pickIntent, requestCode);
     }
   }
 }
 public static void dialogFragmentShowDialogFragment(
     Activity fragmentActivity, DialogFragment dialogFragment) {
   FragmentManager fm = fragmentActivity.getFragmentManager();
   String tag = dialogFragment.getClass().getName();
   FragmentTransaction ft = fm.beginTransaction();
   Fragment f = fm.findFragmentByTag(tag);
   if (f != null) {
     ft.remove(f);
   }
   dialogFragment.show(ft, tag);
 }
  @Override
  protected void onClick() {
    super.onClick();
    NumberPickerDialog dialog =
        NumberPickerDialog.newInstance(mValue, "Select flash count", new int[] {0, 10});

    Activity activity = (Activity) getContext();
    activity.getFragmentManager().beginTransaction().add(dialog, "number_picker").commit();

    dialog.setListener(listener);
  }
Example #21
0
  @Override
  public void showEntryDetail(int userid, int logId) {
    Log.d(DEBUG_TAG, String.format(Locale.US, "starting activity for logid %s", logId));

    Activity activity = getActivity();
    Fragment fragment = EntryFragment.newInstance(userid, logId);
    FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();

    transaction.replace(R.id.fragment_container, fragment);
    transaction.addToBackStack(null);
    transaction.commit();
  }
  @Override
  protected void onAttachedToActivity() {
    super.onAttachedToActivity();

    Activity activity = (Activity) getContext();
    ColorPickerDialog colorcalendar =
        (ColorPickerDialog) activity.getFragmentManager().findFragmentByTag(getFragmentTag());
    if (colorcalendar != null) {
      // re-bind listener to fragment
      colorcalendar.setOnColorSelectedListener(listener);
    }
  }
  @Override
  public void onAttached() {
    super.onAttached();

    Activity activity = (Activity) getContext();
    NumberPickerDialog numberPicker =
        (NumberPickerDialog) activity.getFragmentManager().findFragmentByTag(getFragmentTag());
    if (numberPicker != null) {
      // re-bind listener to fragment
      numberPicker.setListener(listener);
    }
  }
  private void doAuthorization(OAuth2Properties config, final Callback<String> callback)
      throws UnsupportedEncodingException, MalformedURLException {

    URL baseURL = config.getBaseURL();
    URL authzEndpoint = appendToBaseURL(baseURL, config.getAuthzEndpoint());
    Uri redirectURL = Uri.parse(config.getRedirectURL());
    ArrayList<String> scopes = new ArrayList<String>(config.getScopes());
    String clientId = config.getClientId();

    String query = "?scope=%s&redirect_uri=%s&client_id=%s&state=%s&response_type=code";
    query =
        String.format(
            query,
            formatScopes(scopes),
            URLEncoder.encode(redirectURL.toString(), "UTF-8"),
            clientId,
            state);

    if (config.getAdditionalAuthorizationParams() != null
        && config.getAdditionalAuthorizationParams().size() > 0) {
      for (Pair<String, String> param : config.getAdditionalAuthorizationParams()) {
        query +=
            String.format(
                "&%s=%s",
                URLEncoder.encode(param.first, "UTF-8"), URLEncoder.encode(param.second, "UTF-8"));
      }
    }

    URL authURL = new URL(authzEndpoint.toString() + query);

    final OAuthWebViewDialog dialog =
        OAuthWebViewDialog.newInstance(authURL, redirectURL, headerText);
    dialog.setReceiver(
        new OAuthWebViewDialog.OAuthReceiver() {
          @Override
          public void receiveOAuthCode(String code) {
            dialog.removeReceive();
            dialog.dismiss();
            callback.onSuccess(code);
          }

          @Override
          public void receiveOAuthError(final String error) {
            dialog.removeReceive();
            dialog.dismiss();
            callback.onFailure(new OAuth2AuthorizationException(error));
          }
        });

    dialog.setStyle(fakeR.getId("style", "Theme_Light_NoTitleBar"), 0);
    dialog.show(activity.getFragmentManager(), "TAG");
  }
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   try {
     FragmentManager fm = activity.getFragmentManager();
     mListener = (ExchangeErrorDialogListener) fm.findFragmentByTag("DASHBOARD_FRAGMENT");
   } catch (ClassCastException e) {
     throw new ClassCastException(
         activity.toString() + "must implement ExchangeErrorDialogListener Interface");
   } catch (NullPointerException e) {
     throw new NullPointerException(activity.toString() + "DashboardFragment is not initialized");
   }
 }
 /**
  * Get the BackgroundManager associated with the Activity.
  *
  * <p>The BackgroundManager will be created on-demand for each individual Activity. Subsequent
  * calls will return the same BackgroundManager created for this Activity.
  */
 public static BackgroundManager getInstance(Activity activity) {
   BackgroundFragment fragment =
       (BackgroundFragment) activity.getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
   if (fragment != null) {
     BackgroundManager manager = fragment.getBackgroundManager();
     if (manager != null) {
       return manager;
     }
     // manager is null: this is a fragment restored by FragmentManager,
     // fall through to create a BackgroundManager attach to it.
   }
   return new BackgroundManager(activity);
 }
  public static Fragment CreateFragmentInstance(Context ctx) {
    Activity activity = (Activity) ctx;

    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    MoveFragment fragment = new MoveFragment();
    fragment.mActivity = activity;
    ft.add(R.id.activity_a_main_layout_id, fragment, FTAG);
    ft.commit();

    return fragment;
  }
  public static void changeInputField(View view, Brick.BrickField brickField) {

    Activity activity = (Activity) view.getContext();

    FormulaEditorFragment formulaEditorFragment =
        (FormulaEditorFragment)
            activity.getFragmentManager().findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG);

    if (formulaEditorFragment == null) {
      return;
    }
    formulaEditorFragment.setInputFormula(brickField, SET_FORMULA_ON_SWITCH_EDIT_TEXT);
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {

    mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);

    if (mFragment == null) {
      mFragment = (Fragment) Fragment.instantiate(mActivity, mFragmentClass.getName());
      ft.add(R.id.fragmentContainer, mFragment, mTag);
    } else {
      ft.attach(mFragment);
    }
  }
 public static void fragmentActivitySetFragmentVisible(
     Activity fragmentActivity, boolean visible, Fragment... fragments) {
   FragmentManager fm = fragmentActivity.getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   for (Fragment fragment : fragments) {
     if (visible) {
       ft.show(fragment);
     } else {
       ft.hide(fragment);
     }
   }
   ft.commit();
 }