@Override
 public void startForResult(int requestCode) {
   if (fragmentSupport_ != null) {
     fragmentSupport_.startActivityForResult(intent, requestCode);
   } else {
     if (fragment_ != null) {
       if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
         fragment_.startActivityForResult(intent, requestCode, lastOptions);
       } else {
         fragment_.startActivityForResult(intent, requestCode);
       }
     } else {
       if (context instanceof Activity) {
         Activity activity = ((Activity) context);
         ActivityCompat.startActivityForResult(activity, intent, requestCode, lastOptions);
       } else {
         if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
           context.startActivity(intent, lastOptions);
         } else {
           context.startActivity(intent);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Start an activity. This method is defined to allow different methods of activity starting for
  * newer versions of Android and for compatibility library.
  *
  * @param intent Intent to start.
  * @param code Request code for the activity
  * @see android.app.Activity#startActivityForResult(Intent, int)
  * @see android.app.Fragment#startActivityForResult(Intent, int)
  */
 protected void startActivityForResult(Intent intent, int code) {
   if (fragment == null) {
     activity.startActivityForResult(intent, code);
   } else {
     fragment.startActivityForResult(intent, code);
   }
 }
Exemplo n.º 3
0
 public static void openCameraFrom(Fragment fragment, @NonNull File imageFile) {
   Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) {
     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
     fragment.startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
   }
 }
Exemplo n.º 4
0
  public static void openGalleryFrom(Fragment fragment) {
    Intent openGalleryIntent =
        new Intent(
            Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    fragment.startActivityForResult(openGalleryIntent, GALLERY_REQUEST_CODE);
  }
Exemplo n.º 5
0
 public static void showSimpleBackForResult(
     Fragment fragment, int requestCode, SimpleBackPage page, Bundle args) {
   Intent intent = new Intent(fragment.getActivity(), SimpleBackActivity.class);
   intent.putExtra(SimpleBackActivity.BUNDLE_KEY_PAGE, page.getValue());
   intent.putExtra(SimpleBackActivity.BUNDLE_KEY_ARGS, args);
   fragment.startActivityForResult(intent, requestCode);
 }
 public void pickImageFromGallery(Fragment fragment) {
   Intent intent =
       new Intent(
           Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
   intent.setType("image/jpeg");
   fragment.startActivityForResult(intent, ACTION_PICK_IMAGE_FROM_GALLERY);
 }
Exemplo n.º 7
0
  public static void openBrowse(Uri uri, Fragment fragment) {
    Intent intent =
        new Intent(
            Intent
                .ACTION_GET_CONTENT); // TODO implement preference that allows to use
                                      // ACTION_OPEN_DOCUMENT
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setDataAndType(uri, "*/*");

    try {
      fragment.startActivityForResult(
          intent, ProtectedFragmentActivity.IMPORT_FILENAME_REQUESTCODE);
    } catch (ActivityNotFoundException e) {
      // No compatible file manager was found.
      Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT)
          .show();
    } catch (SecurityException ex) {
      Toast.makeText(
              fragment.getActivity(),
              String.format(
                  "Sorry, this destination does not accept %s request. Please select a different one.",
                  intent.getAction()),
              Toast.LENGTH_SHORT)
          .show();
    }
  }
Exemplo n.º 8
0
 public static void openChooser(Fragment fragment) {
   try {
     Intent intent = createChooserIntent(fragment.getActivity());
     fragment.startActivityForResult(intent, REQ_SOURCE_CHOOSER);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 9
0
 public static void callCamera(Fragment activity, String outputPath) {
   File filepic = new File(outputPath);
   Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
   Uri fileuri = Uri.fromFile(filepic);
   intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
   intent.putExtra(MediaStore.EXTRA_OUTPUT, fileuri);
   activity.startActivityForResult(intent, SHOW_CAM);
 }
  public static void openGallery(Fragment fragment, int requestCode) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
      Intent getPictureIntent = new Intent();
      getPictureIntent.setType("image/*");
      getPictureIntent.setAction(Intent.ACTION_GET_CONTENT);
      fragment.startActivityForResult(
          Intent.createChooser(
              getPictureIntent, "fragment.getResources().getString(R.string.ask_select_picture)"),
          requestCode);

    } else {
      Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      intent.setType("image/jpeg");
      fragment.startActivityForResult(intent, requestCode);
    }
  }
Exemplo n.º 11
0
 @Override
 public void startForResult(int requestCode) {
   if (fragmentSupport_ != null) {
     fragmentSupport_.startActivityForResult(intent, requestCode);
   } else {
     super.startForResult(requestCode);
   }
 }
  /** Activity result will be lost when the activity has been recreated. To be fixed. */
  public static void startActivityForResult(
      final FragmentActivity fragmentActivity, Intent intent, View view) {
    FragmentManager fm = fragmentActivity.getSupportFragmentManager();
    Fragment tempFragment = TempFragment.newInstance(view.getId());
    fm.beginTransaction().add(tempFragment, tempFragment.toString()).commit();
    fm.executePendingTransactions();

    tempFragment.startActivityForResult(intent, REQUEST_CODE);
  }
Exemplo n.º 13
0
 public static void toTakePhoto(Fragment mFrag, boolean isSave, int toTakePhotorequestCode) {
   Intent getImageByCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   if (isSave) {
     getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(createSaveFile()));
   } else {
     getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(createTempFile()));
   }
   mFrag.startActivityForResult(getImageByCamera, toTakePhotorequestCode);
 }
Exemplo n.º 14
0
 private void doCropPhoto(File f, int outWith, int outHeight) {
   try {
     // 启动gallery去剪辑这个照片
     final Intent intent = getCropImageIntent(Uri.fromFile(f), outWith, outHeight);
     if (fragmentContext != null) fragmentContext.startActivityForResult(intent, CROPED_PHOTO);
     else activityContext.startActivityForResult(intent, CROPED_PHOTO);
   } catch (Exception e) {
     Toast.makeText(activityContext, "图片获取失败", _2000).show();
   }
 }
Exemplo n.º 15
0
 /**
  * 拍照获取图片
  *
  * @param cropImg
  */
 private void doTakePhoto() {
   try {
     final Intent intent = getTakePickIntent(mCurrentPhotoFile);
     if (fragmentContext != null) fragmentContext.startActivityForResult(intent, CAMERA_WITH_DATA);
     else activityContext.startActivityForResult(intent, CAMERA_WITH_DATA);
   } catch (ActivityNotFoundException e) {
     e.printStackTrace();
     Toast.makeText(activityContext, "图片获取失败", _2000).show();
   }
 }
Exemplo n.º 16
0
  /**
   * Opens the storage browser on Android 4.4 or later for opening a file
   *
   * @param fragment
   * @param mimeType can be text/plain for example
   * @param multiple allow file chooser to return multiple files
   * @param requestCode used to identify the result coming back from storage browser
   *     onActivityResult() in your
   */
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public static void openDocument(
      Fragment fragment, String mimeType, boolean multiple, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);

    fragment.startActivityForResult(intent, requestCode);
  }
Exemplo n.º 17
0
 /**
  * Start an activity. This method is defined to allow different methods of activity starting for
  * newer versions of Android and for compatibility library.
  *
  * @param intent Intent to start.
  * @param code Request code for the activity
  * @see android.app.Activity#startActivityForResult(Intent, int)
  * @see android.app.Fragment#startActivityForResult(Intent, int)
  */
 protected void startActivityForResult(Intent intent, int code) {
   if (fragment != null) {
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
       fragment.startActivityForResult(intent, code);
     }
   } else if (supportFragment != null) {
     supportFragment.startActivityForResult(intent, code);
   } else {
     activity.startActivityForResult(intent, code);
   }
 }
Exemplo n.º 18
0
 public void startForResult(int requestCode) {
   if (fragmentSupport_ != null) {
     fragmentSupport_.startActivityForResult(intent_, requestCode);
   } else {
     if (context_ instanceof Activity) {
       ((Activity) context_).startActivityForResult(intent_, requestCode);
     } else {
       context_.startActivity(intent_);
     }
   }
 }
Exemplo n.º 19
0
 /**
  * Opens the storage browser on Android 4.4 or later for saving a file
  *
  * @param fragment
  * @param mimeType can be text/plain for example
  * @param suggestedName a filename desirable for the file to be saved
  * @param requestCode used to identify the result coming back from storage browser
  *     onActivityResult() in your
  */
 @TargetApi(Build.VERSION_CODES.KITKAT)
 public static void saveDocument(
     Fragment fragment, String mimeType, String suggestedName, int requestCode) {
   Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
   intent.addCategory(Intent.CATEGORY_OPENABLE);
   intent.setType(mimeType);
   intent.putExtra(
       "android.content.extra.SHOW_ADVANCED", true); // Note: This is not documented, but works
   intent.putExtra(Intent.EXTRA_TITLE, suggestedName);
   fragment.startActivityForResult(intent, requestCode);
 }
Exemplo n.º 20
0
 // 请求Gallery程序
 private void doPickPhotoFromGallery() {
   try {
     // Launch picker to choose photo for selected contact
     final Intent intent = getPhotoPickIntent();
     if (fragmentContext != null) fragmentContext.startActivityForResult(intent, PHOTO_PICKED);
     else activityContext.startActivityForResult(intent, PHOTO_PICKED);
   } catch (ActivityNotFoundException e) {
     e.printStackTrace();
     Toast.makeText(activityContext, "图片获取失败", _2000).show();
   }
 }
Exemplo n.º 21
0
 public static void startThisActivity(
     Fragment fragment, @NonNull String orderid, @NonNull String sellid, ShopCarInfo shopCarInfo) {
   if (CommonUtil.isLoginAndToLogin(fragment.getActivity(), false)) {
     Intent intent = new Intent(fragment.getActivity(), AddCommonActivity.class);
     intent.putExtra("oid", orderid);
     intent.putExtra("sid", sellid);
     Bundle bundle = new Bundle();
     bundle.putSerializable("goods", shopCarInfo);
     intent.putExtras(bundle);
     fragment.startActivityForResult(intent, 1);
   }
 }
 /**
  * Start a new instance of this activity, showing only the given preference fragment. When
  * launched in this mode, the header list will be hidden and the given preference fragment will be
  * instantiated and fill the entire activity.
  *
  * @param fragmentName The name of the fragment to display.
  * @param args Optional arguments to supply to the fragment.
  * @param resultTo Option fragment that should receive the result of the activity launch.
  * @param resultRequestCode If resultTo is non-null, this is the request code in which to report
  *     the result.
  * @param titleRes Resource ID of string to display for the title of this set of preferences.
  * @param shortTitleRes Resource ID of string to display for the short title of this set of
  *     preferences.
  */
 public void startWithFragment(
     String fragmentName,
     Bundle args,
     Fragment resultTo,
     int resultRequestCode,
     int titleRes,
     int shortTitleRes) {
   Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
   if (resultTo == null) {
     startActivity(intent);
   } else {
     resultTo.startActivityForResult(intent, resultRequestCode);
   }
 }
Exemplo n.º 23
0
  /**
   * Opens the preferred installed file manager on Android and shows a toast if no manager is
   * installed.
   *
   * @param fragment
   * @param last default selected Uri, not supported by all file managers
   * @param mimeType can be text/plain for example
   * @param requestCode requestCode used to identify the result coming back from file manager to
   *     onActivityResult() in your activity
   */
  public static void openFile(Fragment fragment, Uri last, String mimeType, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setData(last);
    intent.setType(mimeType);

    try {
      fragment.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
      // No compatible file manager was found.
      Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT)
          .show();
    }
  }
  public void pickImageFromCamera(Fragment fragment) {
    File file;
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    try {
      file = createImageFile(fragment.getString(R.string.app_name));
      mImageFromCameraPath = file.getAbsolutePath();
      intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    } catch (IOException e) {
      e.printStackTrace();
      mImageFromCameraPath = null;
    }

    fragment.startActivityForResult(intent, ACTION_PICK_IMAGE_FROM_CAMERA);
  }
Exemplo n.º 25
0
 /** * Start the voice input activity manually */
 public void startVoiceRecognition() {
   if (isMicEnabled()) {
     Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
     intent.putExtra(
         RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
     intent.putExtra(RecognizerIntent.EXTRA_PROMPT, context.getString(R.string.speak_now));
     if (mContainerActivity != null) {
       mContainerActivity.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
     } else if (mContainerFragment != null) {
       mContainerFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
     } else if (mContainerSupportFragment != null) {
       mContainerSupportFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
     }
   }
 }
Exemplo n.º 26
0
 /**
  * Fire an intent to start the speech recognition activity. This is fired by the listener on the
  * microphone-button.
  *
  * @param prompt Specify the R.string.string_id resource for the prompt-text during
  *     voice-recognition here
  */
 public void startVoiceRecognitionActivity(Fragment fragment, int prompt) {
   Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
   intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
   intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
   intent.putExtra(RecognizerIntent.EXTRA_PROMPT, ContextManager.getContext().getString(prompt));
   String detailMessage =
       "Error! No Fragment or Activity was registered to handle this voiceinput-request!";
   if (activity != null) {
     activity.startActivityForResult(intent, requestCode);
   } else if (fragment != null) {
     fragment.startActivityForResult(intent, requestCode);
   } else {
     Log.e("Astrid VoiceInputAssistant", detailMessage, new IllegalStateException(detailMessage));
   }
 }
 public void b(int i)
 {
     if (c != null)
     {
         c.startActivityForResult(b, i);
         return;
     }
     if (a instanceof Activity)
     {
         ((Activity)a).startActivityForResult(b, i);
         return;
     } else
     {
         a.startActivity(b);
         return;
     }
 }
Exemplo n.º 28
0
 public static void openGallery(Fragment f) {
   Intent intent = new Intent(Intent.ACTION_PICK, null);
   intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
   f.startActivityForResult(intent, GALLERY);
 }
Exemplo n.º 29
0
 public static void openCamera(Fragment f, String path) {
   Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));
   f.startActivityForResult(intent, CAMERA);
 }
Exemplo n.º 30
0
 public static void openCameraFrom(Fragment fragment) {
   Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) {
     fragment.startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
   }
 }