Не получается получить текст из редактируемого текста, когда вы намеренно делитесь изображением и текстом в приложении Whats

fullscreenadapter.java Вот следующий код, я не могу поделиться текстом из текстового поля редактирования с изображением, когда я просто добавляю жестко закодированную строку, это добавит заголовок к изображению, но ничего с текстовым полем редактирования.

 package com.mobdev.birthdaycakesquotes;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

import android.graphics.drawable.Drawable;
import android.net.Uri;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;

import android.widget.TextView;

import java.io.File;

import java.io.FileOutputStream;




 public class Fullscreenadapter extends PagerAdapter {
private Integer[] Image;
private int _resource;
private Activity _activity;
private LayoutInflater inflater;
private  String images;int pos;private static final float BYTES_PER_PX = 4.0f;
TextView t1,t2;  ImageView imgDisplay,shareimage;EditText quote;String text;
public Fullscreenadapter(Activity activity,
                         Integer[] image) {
    this._activity = activity;
    this.Image=image;
}

@Override
public int getCount() {
    return this.Image.length;
}

@Override
public Object instantiateItem(ViewGroup container, final int position) {


    inflater = (LayoutInflater) _activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View viewLayout = inflater.inflate(R.layout.fullscreenlayoutdesign, container,
            false);

    imgDisplay = (ImageView) viewLayout.findViewById(R.id.show);
    shareimage=(ImageView)viewLayout.findViewById(R.id.share);
    t1=(TextView)viewLayout.findViewById(R.id.currentposition);
    t2=(TextView)viewLayout.findViewById(R.id.totalimage);

цитата =(EditText)viewLayout.findViewById(R.id.quotetext);

    Bitmap bm = BitmapFactory.decodeResource(_activity.getResources(),Image[position]);
    imgDisplay.setImageBitmap(bm);
    t1.setText(String.valueOf(position));
    t2.setText(String.valueOf(Image.length));
    shareimage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

. Текст =quote.getText() ToString ();

            Bitmap bitmap =getBitmapFromView(imgDisplay);
            try {
                File file = new File(_activity.getExternalCacheDir(),"sw.jpg");
                FileOutputStream fOut = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
                fOut.flush();
                fOut.close();
                file.setReadable(true, false);
                final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

intent.putExtra (Intent.EXTRA_TEXT, текст);

                intent.setType("image/*");
                _activity.startActivity(Intent.createChooser(intent, "Share image via"));
            } catch (Exception e) {
                e.printStackTrace();
            }


        }
    });
    ((ViewPager) container).addView(viewLayout);
    return viewLayout;
}

private Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable =view.getBackground();
  /*  if (bgDrawable!=null) {
        //has background drawable, then draw it on the canvas
        bgDrawable.draw(canvas);
    }   else{
        //does not have background drawable, then draw white background on the canvas
        canvas.drawColor(Color.WHITE);
    }*/
    view.draw(canvas);
    return returnedBitmap;
}
/*
private void loadImage() {
    if(readBitmapInfo() > MemUtils.megabytesFree()) {
        subSampleImage(32);
    } else {
        imgDisplay.setImageResource(Image[pos]);
    }
}

private float readBitmapInfo() {
    final Resources res = _activity.getResources();
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, Image[pos], options);
    final float imageHeight = options.outHeight;
    final float imageWidth = options.outWidth;
    final String imageMimeType = options.outMimeType;

    Log.d("ScaleBeforeLoad", "w, h, type: " + imageWidth + ", " + imageHeight + ", " + imageMimeType);
    Log.d("ScaleBeforeLoad", "estimated memory required in MB: " + imageWidth * imageHeight * BYTES_PER_PX / MemUtils.BYTES_IN_MB);

    return imageWidth * imageHeight * BYTES_PER_PX / MemUtils.BYTES_IN_MB;
}

private void subSampleImage(int powerOf2) {
    if(powerOf2 < 1 || powerOf2 > 32) {
        Log.e("ScaleBeforeLoad", "trying to appply upscale or excessive downscale: " + powerOf2);
        return;
    }

    final Resources res =_activity.getResources();
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inSampleSize = powerOf2;
    final Bitmap bmp = BitmapFactory.decodeResource(res, Image[pos], options);

    imgDisplay.setImageBitmap(bmp);
}*/
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
    return view.equals(object);
}
}

0 ответов

Другие вопросы по тегам