How to share a recyclerview background image and text as one - android-recyclerview

I created a recyclerview for the purpose of sharing messages. Each item in the recyclerView has a different image(.png) background set as flower background with text set on it with TextView. It shows well. But whenever I clicked shareImage icon only image is shared.
Screenshot from recyclerview. This is how I want it to be
This is what I've got to share, the image and text are separated!
What I want to achieve?
I want to automatically crop and share but background image and text I set on it as a card.
This is what I did that didn't work
myHolder.mShareImage.setOnClickListener(v -> {
Drawable drawable= myHolder.mImageView.getDrawable();
Bitmap bitmap=((BitmapDrawable)drawable).getBitmap();
try {
File file = new File(mContext.getApplicationContext().getExternalCacheDir(), File.separator +models.get(i).getTitle()+models.get(i).getIcon()+".png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
file.setReadable(true, false);
final Intent shareImagerIntent = new Intent(android.content.Intent.ACTION_SEND);
shareImagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri photoURI = FileProvider.getUriForFile(mContext.getApplicationContext(), BuildConfig.APPLICATION_ID +".provider", file);
shareImagerIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareImagerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareImagerIntent.setType("*/*");
shareImagerIntent.putExtra(Intent.EXTRA_TEXT, models.get(i).getTitle());
mContext.startActivity(Intent.createChooser(shareImagerIntent, "Share image via"));
} catch (Exception e) {
e.printStackTrace();
}
});

Related

Convert text and current background image of recyclerview to image and save it to device

in my adapter i have add this code
holder.binding.saveButton.setOnClickListener {
mediaPlayer.start()
if (ContextCompat.checkSelfPermission(holder.itemView.context,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(holder.itemView.context as Activity,
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
REQUEST_WRITE_STORAGE)
} else {
val parentView = holder.itemView.findViewById<LinearLayout>(R.id.itemViewe)
parentView.isDrawingCacheEnabled = true
val bitmap = parentView.getDrawingCache()
// Create a file to save the image
val imagesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
val image = File.createTempFile("your_image_name", ".jpg", imagesDir)
// Compress the bitmap and save it to the file
val stream = FileOutputStream(image)
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
stream.flush()
stream.close()
// Clear the drawing cache
parentView.destroyDrawingCache()
// Add the image to the system gallery
val values = ContentValues()
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
values.put(MediaStore.MediaColumns.DATA, image.absolutePath)
holder.itemView.context.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
// Show a toast message to indicate that the image has been saved
Toast.makeText(holder.itemView.context, "Status Saved", Toast.LENGTH_SHORT).show()
}
}
when click on save button in recyclerview show permisiion to allow and after show toast status saved but in gallery its not showing ..... in my case my device android version 11 so image show in gallery but in version 12 when save button clicked show toast and show blank in gallery not full image.
it work on some version and not work in other versions but i want to work it for all device how can i do it

Codename One Drag & Drop blackens dialog background

I'm developing an app that uses drag & drop operations. The drag & drop part includes four containers as drop targets and two draggable labels.
The app works as expected in the simulator, but when I install it on my Android phone, the background of the dialog (otherwise white) turns black for a swift moment as soon as the draggable components (labels) are released (then gets back to the original light color).
In the theme builder, I have set the background of the dialog to an almost white color (unselected, selected, pressed, disabled), but that doesn't show any effect.
Is there any turnaround to keep the background color stable? Any help would be appreciated.
Here is the relevant code excerpt:
Dialog dialog_W1 = new Dialog();
dialog_W1.setScrollableY(true);
dialog_W1.setLayout(new BoxLayout(2));
dialog_W1.setScrollableY(true);
dialog_W1.setTitle("Acerte o bichinho");
Image img_Cat = Image.createImage("/cat.png");
ScaleImageLabel label_Scaled_Image = new ScaleImageLabel(img_Cat);
label_Scaled_Image.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
label_Scaled_Image.setUIID("NewLabel");
Label label_1 = new Label("ga");
Label label_2 = new Label("to");
label_1.setUIID("LabelWord");
label_2.setUIID("LabelWord");
label_1.setDraggable(true);
label_2.setDraggable(true);
Container c_1 = new Container();
Container c_2 = new Container();
Container c_3 = new Container();
Container c_4 = new Container();
c_1.setDropTarget(true);
c_2.setDropTarget(true);
c_3.setDropTarget(true);
c_4.setDropTarget(true);
c_1.setLayout(new BoxLayout(2));
c_2.setLayout(new BoxLayout(2));
c_3.setLayout(new BoxLayout(2));
c_4.setLayout(new BoxLayout(2));
c_1.setUIID("Container_1");
c_2.setUIID("Container_1");
c_3.setUIID("Container_2");
c_4.setUIID("Container_2");
c_3.add(label_2);
c_4.add(label_1);
GridLayout gl = new GridLayout(2,2);
Container container_0 = new Container(gl);
container_0.add(c_1);
container_0.add(c_2);
container_0.add(c_3);
container_0.add(c_4);
ArrayList <Container> list_Containers = new ArrayList<>();
list_Containers.add(c_1);
list_Containers.add(c_2);
list_Containers.add(c_3);
list_Containers.add(c_4);
ArrayList <Label> list_Labels = new ArrayList<>();
list_Labels.add(label_1);
list_Labels.add(label_2);
for (Label label : list_Labels) {
label.addDragOverListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
for (Container c : list_Containers) {
int int_C = c.getComponentCount();
if (int_C == 1) {
c.setDropTarget(false);
} else if (int_C == 0) {
c.setDropTarget(true);
}
}
}
});
}
I suggest showing the Dialog as a modless dialog instead of using the show method use showModless() or similar.
Odd things like this can happen because of the EDT nesting inherent in modal dialogs, normally we don't recommend using dialog for anything more than simple notifications. When we use drag and drop from a dialog like component we use InteractionDialog.

Create moving background in live wallpaper using rajawali

I'm creating a live wallpaper using rajawali. I load an object on it (with this code: Rajawali object rotation match to camera) and now I want to set moving image in background for it. Has anyone advice for me?
I created Plane:
mPlane1 = new Plane();
Material material1 = new Material();
try {
material1.addTexture(new Texture("cloud2", R.drawable.cloud2));
} catch (TextureException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
material1.setColorInfluence(0);
mPlane1.setMaterial(material1);
mPlane1.setRotY(180);
mPlane1.setTransparent(true);
mPlane1.setPosition(Vector3.X);
mPlane1.setPosition(-1.6f, 1.2, 1.6);
getCurrentScene().addChild(mPlane1);
and translate it with TranslateAnimation3D:
plane1Anim = new TranslateAnimation3D(Vector3.X);
plane1Anim.setRepeatMode(RepeatMode.INFINITE);
plane1Anim.setTransformable3D(mPlane1);
plane1Anim.setDuration(16000);
getCurrentScene().registerAnimation(plane1Anim);
plane1Anim.play();

Android ViewPager and Camera Preview issue on Gingerbread

I did extensive documentation study on ViewPagers and on Camera apps, infact everything works quite fine, except for a major issue on GingerBread, which I haven't found any question about on S.O. so I'll try asking this one...
In my application there is a ViewPager (support library v4) which shows two fragments:
One, will call it the main fragment, the one showing when the activity starts, certain information are shown to the user, including an imageview, which is initially empty and hidden.
By swyping to the next fragment, the user sees the camera preview, which gets created when the activity is created (even if it not showing until the swype) and the button to take a picture.
When the picture is taken, the view is programmatically taken back to the main fragment, the
imageview is loaded with the new photo and unhidden so the user can see the image mixed with the other preexisting information.
If the user does not like picture, he can swype back again to the camera fragment and take another one, and so all over until he is satisfied with the result.
For this reason, before flipping back to the main fragment, I call mCamera.restartPreview() and ensure the camera is ready should the user swype back.
Everything works smoothly and fine on Android 4.x, but when I test this on a 2.3.3 (API Level 10) the camera preview remains in foreground when the main fragment is called back, and hides the view. You can see, and even scroll, the remainder of the view, in the portion of teh screen where the camerafragment shows the buttons, but the rest is overlapped by the camera preview.
Here is the code of the relevant functions:
CameraFragment onPictureTaken()
private PictureCallback mPicture = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Log.d(TAG, "Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Log.e(TAG, "FILE " +pictureFile.getAbsoluteFile().toString());
Bitmap bitmap = rotated(data);
bitmap.compress(CompressFormat.JPEG, PICTURE_QUALITY, fos);
bitmap.recycle(); //devo davvero chiamarla esplicitamente ??
mediaFile = pictureFile;
mPreview.restartPreview();
// go back to newpin activity to show it
((NewPinActivity) myActivity).newPin.setMedia(mediaFile.getAbsoluteFile().toString());
((NewPinActivity) myActivity).takeBack();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
}
}
};
and the mainfragment takeBack() method
public void takeBack(){
mViewPager.setCurrentItem(0, true);
String mainFragTag = "android:switcher:"+R.id.newpinpager+":0";
Fragment fragMain = this.getSupportFragmentManager().findFragmentByTag(mainFragTag);
try {
((NewPinMainFragment)fragMain).showPhoto(newPin.getMedia());
} catch (NullPointerException e){
}
}
Does anybody have a clue if this is an issue with the ViewPager and GingerBread or with the CameraPreview and Gingerbread or what ?
I found the answer by myself, I'll post it here in case it's going to be useful to others.
Apparently the problem was cause by the smoothscroll option of setCurrentItem method.
The issue was fixed by changing
mViewPager.setCurrentItem(0, true);
to
mViewPager.setCurrentItem(0, false);

Image Opacity in PdfSharp.NET

I'm using PDFSharp.NET library to watermark a list of PDFs file. Everything works fine, the website has a lot of samples.
http://www.pdfsharp.net/wiki/Graphics-sample.ashx
The last thing I need is to add the Company Logo, which is big, in the middle of the PDF Page.
I can use a PNG, so that areas which are set as transparent do not "cover" the PDF page".
The pdf is not generated using PDFSharp, but is an "Image" PDF.
For this reason, what I need, is, in addition to the transparency, which works, be able some how to set the Image Opacity!
The code to place the image is this one:
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
XImage image = XImage.FromFile(mypath);
gfx.DrawImage(image, pwidth/2-image.PixelWidth/2, pheight/2 image.PixelHeight/2);
gfx.Dispose();
Anyone has already faced with that?
I don't know how to alter the opacity of an image while drawing it using PDFsharp (and I'm afraid this can't be done).
So instead I would just open the logo (PNG) with an image processor and set the opacity there.
I was looking in to this aswell now for making a watermark (companyLogo) to place over pdf sheets. The code below lets you change the opacity.
PDFSharp can not change the image opacity. What you can do is change the image you feed to PDF sharp. This has already been answered so I am just sharing my code of doing so.
private void DrawGraphics()
{
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
Image myTransparenImage = SetImageOpacity(Image.FromFile("MyPath"), (float)opacityYouwant); // opacityYouWant has to be a value between 0.0 and 1.0
XImage image = XImage.FromBitmapSource(Convert(myTransparenImage));
gfx.DrawImage(image, pwidth / 2 - image.PixelWidth / 2, pheight / 2 image.PixelHeight / 2);
gfx.Dispose();
}
public Image SetImageOpacity(Image image, float opacity)
{
try
{
//create a Bitmap the size of the image provided
Bitmap bmp = new Bitmap(image.Width, image.Height);
//create a graphics object from the image
using (Graphics gfx = Graphics.FromImage(bmp))
{
//create a color matrix object
ColorMatrix matrix = new ColorMatrix();
//set the opacity
matrix.Matrix33 = opacity;
//create image attributes
ImageAttributes attributes = new ImageAttributes();
//set the color(opacity) of the image
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
//now draw the image
gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
return bmp;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
public BitmapImage Convert(Image img)
{
using (var memory = new MemoryStream())
{
img.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}