How to send image from activity to fragment - java

I have little problem with my Android app.
First i take a photo by a camera and save it as Bitmap. Next thing i want to do is display this image in new fragment as ImageView. I don't know how to send this photo from activity to fragment.
Could you help how to do that?

You are taking the photo in the activity, so the fastest way to figure out this problem is saving your image in cache and reading directly form its path in the fragment code.
Did you try this?

I see two solutions:
Since you are taking a picture in one Activity and want to get it in a Fragment (which has an Activity), you could put the bitmap path on bundle on the Take Picture activity (bundle.putString("bitmapPath", bitmap.getPath())) and read this bundle on the Show Picture Activity Fragment (getActivity().getExtras().get("bitmapPath")).
You could use a public static variable to keep bitmap path after you saving it.

Related

How do i preview a TextView?

Good day,
I am trying to add a textview preview to my app. For example, i created a news app with card view and I want to have a few lines on the first screen and then it expands the full story in a new activity onclick.
I have already set up the new activity part but I just need the preview on the first screen
You should have all the News data available on your first Activity - NewsActivity.
In that case you just
Limit number of lines of preview TextView with attribute android:maxLines="3"
Then on click on TextView you would open another activity with an Intent and inside the Intent pass whole News object that corresponds to data displayed in preview TextView. Remember that News object should be implement Serializable or Parcelable interfaces to be passed with intent.
Retrieve data from an Intent and display it in the second Activity - NewsDetailsActivity

How can i show large image in the starting of activity with minimum time?

In my wallpaper android app I have first activity in which user selects any one image and go to the next activity, and in second activity I show preview of image. It is loading and taking long time. How can I reduce the loading time? on the same network obviously.
how can I preload this image?
I used Glide as well as Picasso no difference in loading time.
Simple use cases with Glide's generated API will look something like this:
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
GlideApp.with(this).load("IMAGE URL").into(imageView);

What Android code mimics the screenshot function (volume down and power button simultaneously)?

I am looking for a way to take screenshots of android device programmatically. I have looked at several solutions in stackoverflow that involve taking a screenshot of the running activity. I want to mimic the behavior that is by default triggered in Android by pressing volume down and power button simultaneously. Please note, I don't want to take screenshot of my own activity or running activity. I want to, for example, launch a dialog activity with a button, and when the button is clicked, I finish my activity and start a background task that will take a screenshot of the visible section including status-bar, like holding volume-down and power does. How do I achieve this?
If you are taking a screenshot of another Activity you will somehow have to get a reference to the View that encompasses the section of the screen you want to screenshot OR just capture the entire screen. If it is the entire screen you can get that with
// get the top level view from the activity in this context
View theView = getWindow().getDecorView();
Then to capture that View as a Bitmap you can use
// Take the Screen shot of a View
public static Bitmap takeScreenshot(final View theView) {
theView.setDrawingCacheEnabled(true);
return theView.getDrawingCache();
}
// Release the drawing cache after you have captured the Bitmap
// from takeScreenshot()
public static void clearScreenshotCache(final View theView) {
theView.setDrawingCacheEnabled(false);
}
From there you can save the Bitmap into a JPEG or PNG by calling .compress on the Bitmap.
As for running a task on a background thread there's enough documentation on several ways to do that like here.
Hope that gets you started!

Display Images in ImageAdapter (GridView) while downloading

I'm making an application that reads a bunch of images URL on a JSON string. With a new thread the app downloads the images to a specific directory. Then there is a "gallery" based on a GridView with an ImageAdapter that displays all the files. The thing is that it takes too long the first time to download all the images.
My goal is to display the images while they are downloading. Right now the user has to go back and then enter again in the gallery to view the new images. Until all the images are downloaded.
If someone has a workaround for this, let me know.
Thanks..
Once your images are downloaded call notifydatasetchanged on the adapter. This can be done either after every image or a set of images.
Edit : Assuming you are calling the thread in MainActivity and the adapter is being called in the Display Activity , you can have the downloading thread call a listener, defined in the Display activity which calls notifydatasetchanged.
Also I am hoping each image is downloaded in a separate thread :-)

Modifying single list items

I have a ListView, displaying some items, containing an ImageView filled with a standard image at first and a line of text.
What I wanna do is downloading one thumb after another with an AsyncTask and step for step change the standard image with the downloaded one. How to realise this?
The ListView contents are managed by an enhanced ArrayAdapter.
greetz
EnflamedSoul
If I understand you correctly you're interested in a LazyList. This example shows a stub for the image, then downloads some thumbnails as the user scrolls down and caches these onto an SD card. The next time the images will be loaded from the SD card.
Lazy load of images in ListView
I personally used Fedor's example and it worked well.

Categories