コード例 #1
0
  public void initShareIntent() {
    String path =
        MediaStore.Images.Media.insertImage(
            mContext.getContentResolver(), mBitmap, "Image Description", null);

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    // shareIntent.setType("image/*");
    try {

      shareIntent.putExtra(
          Intent.EXTRA_TEXT, mCharacter.getName() + "\n" + mCharacter.getDescription());
      Uri bmpUri = Uri.parse(path);
      shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
      // startActivity(Intent.createChooser(shareIntent, "How do you want to share?"));

      // return shareIntent;
    } catch (NullPointerException e) {
      // return  shareIntent;
      startActivity(Intent.createChooser(shareIntent, "How do you want to share?"));
    }
  }
コード例 #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContext = getActivity();

    final View view = inflater.inflate(R.layout.fragment_detail_info, container, false);

    Intent intent = getActivity().getIntent();

    int hero_id = -2;
    if (intent != null) {
      hero_id = intent.getIntExtra(MainActivityFragment.TAG_HERO_ID, -1);
    }

    HeroesDBAdapter adapter = new HeroesDBAdapter(getActivity());
    adapter.open();

    try {
      mCharacter = adapter.getItem(hero_id);
    } catch (EmptyCursorException e) {
      Log.e(LOG_TAG, " EmptyCursorException");
      Crashlytics.log(Log.ERROR, LOG_TAG, " EmptyCursorException");
      e.printStackTrace();
    }

    ImagePipeline imagePipeline = Fresco.getImagePipeline();

    final ImageItem imageItem = mCharacter.getThumbnail();
    Uri uri = Uri.parse(imageItem.toString());

    ImageRequest imageRequest =
        ImageRequestBuilder.newBuilderWithSource(uri)
            .setRequestPriority(Priority.HIGH)
            .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
            .build();

    DataSource<CloseableReference<CloseableImage>> dataSource =
        imagePipeline.fetchDecodedImage(imageRequest, getActivity());

    try {
      dataSource.subscribe(
          new BaseBitmapDataSubscriber() {
            @Override
            public void onNewResultImpl(@Nullable Bitmap bitmap) {
              if (bitmap == null) {
                Crashlytics.log(
                    Log.ERROR, LOG_TAG, "Bitmap data source returned success, but bitmap null.");

                return;
              } else {
                mBitmap = bitmap;
                ImageView imageView = (ImageView) view.findViewById(R.id.imageView_detail);
                imageView.setImageBitmap(mBitmap);
              }
            }

            @Override
            public void onFailureImpl(DataSource dataSource) {
              Crashlytics.log(Log.ERROR, LOG_TAG, "Bitmap data source returned error");
            }
          },
          CallerThreadExecutor.getInstance());
    } finally {
      if (dataSource != null) {
        dataSource.close();
      }
    }

    TextView textView = (TextView) view.findViewById(R.id.heroe_name);
    textView.setText(mCharacter.getName());

    textView = (TextView) view.findViewById(R.id.heroe_description);
    textView.setText(mCharacter.getDescription());

    adapter.close();

    return view;
  }