I am using a Class that implements GoogleMap.InfoWindowAdapter.
I want to show an image loaded from internet inside the info window:
#Override
public View getInfoContents(final Marker m) {
//Carga layout personalizado.
View v = inflater.inflate(R.layout.info_windows_origen, null);
String info = m.getTitle();
String direccion = m.getSnippet();
String url = m.getSnippet();
((TextView)v.findViewById(R.id.info_window_nombre)).setText("PUNTO DE PARTIDA");
((TextView)v.findViewById(R.id.info_window_placas)).setText(info);
((TextView)v.findViewById(R.id.info_window_estado)).setText(direccion);
ImageView imgProfile =(ImageView)v.findViewById(R.id.info_window_imagen);
SharedPreferences prefs =
getApplicationContext().getSharedPreferences(MISDATOS, Context.MODE_PRIVATE);
String imagen = prefs.getString("imagen", "por_defecto#email.com");
Log.d("BOTON ORIGEN ","mi imagen "+urlProfileImg+imagen);
Picasso.with(getApplicationContext()).load(urlProfileImg+imagen).fit().into(imgProfile);
return v;
}
I have checked both, the image URL and the image name, and both are correct, but the image is not shown.
Be sure you have internet permission in the manifest.
Try removing fit
Posting the url you are providing would be easier to work with
Related
Glide won't load the images I have linked with the products on my recycler view. The images should be pulled from my PHP MySQL database. Not really sure what I did wrong. Please help
I've tried a few solutions I found on the web but none of them worked for me.
private String image;
The above is the string identifier from my product list
//loading the image
Glide.with(mCtx)
.load(product.getImage())
.into(holder.imageView);
holder.textViewPlateNumber.setText(product.getPlatenumber());
holder.textView1.setText(product.getMake());
holder.textView2.setText(product.getModel());
holder.textView3.setText(product.getYear());
holder.textViewName.setText(product.getName());
holder.textDate.setText(product.getDate());
holder.recyclerid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String platenumber = productList.get(position).getPlatenumber();
String make = productList.get(position).getMake();
String model = productList.get(position).getModel();
String year = productList.get(position).getYear();
String name = productList.get(position).getName();
String date = productList.get(position).getDate();
String vin = productList.get(position).getVin();
String displacement = productList.get(position).getDisplacement();
String fueltype = productList.get(position).getFueltype();
String transmission = productList.get(position).getTransmission();
String mileage = productList.get(position).getMileage();
String ownerorcompany =
productList.get(position).getOwnerorcompany();
String homeorcompanyaddress =
productList.get(position).getHomeorcompanyaddress();
String contactnumber =
productList.get(position).getContactnumber();
String emailaddress = productList.get(position).getEmailaddress();
String facebook = productList.get(position).getFacebook();
String image = productList.get(position).getImage();
The above is the code I used to show the images of each item off my adapter.
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/car_avatar"
app:civ_border_color="#color/cta"
app:civ_border_width="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline17"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The above is how the image should be laid out in my xml file. The rest of the items saved on my php sql show up on the list except the images. Here is what my php file looks like:
$vehicle = array();
while ($row=mysqli_fetch_array($sql)) {
$temp = array();
$temp['id'] = $row['VehicleID'];
$temp['platenumber'] = $row['PlateNumber'];
$temp['make'] = $row['Make'];
$temp['model'] = $row['Model'];
$temp['year'] = $row['Year'];
$temp['name'] = $row['OwnerorCompany'];
$temp['date'] = $row['AddDate'];
$temp['image'] = $row['vehicleImage'];
$temp['vin'] = $row['Vin'];
$temp['displacement'] = $row['Displacement'];
$temp['fueltype'] = $row['FuelType'];
$temp['transmission'] = $row['Transmission'];
$temp['mileage'] = $row['Mileage'];
$temp['ownerorcompany'] = $row['OwnerorCompany'];
$temp['homeorcompanyaddress'] = $row['HomeorCompanyAddress'];
$temp['contactnumber'] = $row['ContactNumber'];
$temp['emailaddress'] = $row['EmailAddress'];
$temp['facebook'] = $row['FacebookID'];
array_push($vehicle, $temp);
}
echo json_encode($vehicle);
//}
?>
And this is how the images are saved on my database:
$photo = $_POST['photo'];
$id=uniqid();
$path = "vehicle_upload/$id.jpeg";
$finalpath = "http://192.168.0.10/widevalueautoInc
2/server/api/".$path;
When I run the app, all goes well except the images not showing up on the list. This is the java code I used to save the image and the size.
private void addVehicle(String stringImage) {
}
public String getStringImage(Bitmap bitmap){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] imageByteArray = byteArrayOutputStream.toByteArray();
String encodedImage = Base64.encodeToString(imageByteArray,
Base64.DEFAULT);
return encodedImage;
}
}
remove circular imageview and use default image view, to use circle crop .. use Glide circle crop function....
Glide.with(context).load("dddd").apply(RequestOptions.circleCropTransform()).into(imageview);
Just make a common method as below in your utility class as below :
public static void setCircularImageToGlide(final Context context, final CircularImageView imageView, String imageUrl) {
Glide.with(context).load("" + imageUrl).asBitmap().placeholder(R.drawable.ic_photo_placeholder).transform(new CircleTransform(context)).into(new BitmapImageViewTarget(imageView) {
#Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
}
I have passed CircularImageView as an argument to method single you are using CircularImageView instead of simple ImageView.
Call it as below wherever you need to set image in to your CircularImageView as below :
CommonUtil.setCircularImageToGlide(YOUR_CONTEXT, YOUR_CIRCULAR_IMAGE_VIEW, "" + YOUR_IMAGE_URL);
Am using below dependency :
implementation 'com.github.bumptech.glide:glide:3.7.0'
I've to read a stream from a rss feed on an Android application.
All work fine, but i'm not able to get the complete url, from the tag, because it's a selfclosed tag
somethings like
This's the xml page (i can't edit it) Xml source page
and this is the code to populate to create the single objet that I need
String titolo, descrizione, descrizione_breve, img, data, icona;
Notizia SitoDaAggiungere;
for (int i = 0; i < nodi.getLength(); i++) {
Node nodoItem = nodi.item(i);
if (nodoItem.getNodeType() == Node.ELEMENT_NODE) {
Element elemento = (Element) nodoItem;
titolo = elemento.getElementsByTagName("title").item(0).getTextContent();
descrizione_breve = elemento.getElementsByTagName("summary").item(0).getTextContent();
descrizione = elemento.getElementsByTagName("content").item(0).getTextContent();
img = elemento.getElementsByTagName("pic1").item(0).getTextContent();
data = elemento.getElementsByTagName("updated").item(0).getTextContent();
icona = elemento.getElementsByTagName("pic").item(0).getTextContent();
String link_sito = elemento.getElementsByTagName("link").item(0).getTextContent(); // <-- no error, but an empty string
SitoDaAggiungere = new Notizia(titolo, descrizione, descrizione_breve, data, img, icona, link_sito);
InserisciSito(SitoDaAggiungere);
}
}
Someone can help me?
thank's a lot!
finally I do it!!!
this's the code to get the url
String link_sito = elemento.getElementsByTagName("link").item(0).getAttributes().item(0).getTextContent();
now I simply use it to create the new objet
I have an image url I parse form json that I want to load into an android widget onto the homescreen. Right now I am trying to do it this way but its wrong:
ImageDownloadTask imageD = new ImageDownloadTask(image);
views.setImageViewBitmap(R.id.image, imageD.execute(image));
image is a string holding a url to an image that needs to be downloaded and I am trying to set it to R.id.image
I found another stack question and tried this as a result:
views.setBitmap(R.id.image, "setImageBitmap",BitmapFactory.decodeStream(new URL(image).openStream()));
And when I use that nothing in the app loads at all, none of the text views get set.
My third try was this:
//get beer data
JSONObject o = new JSONObject(result);
String name = getName(o);
String image = getImage(o);
String abv = getABV(o);
String ibu = getIBU(o);
String glass = getGlass(o);
String beerBreweryName = getBreweryName(o);
String beerBreweryStyle = getBreweryStyle(o);
String beerDescription = getDescription(o);
InputStream in = new java.net.URL(image).openStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
views.setTextViewText(R.id.beerTitle, name);
views.setTextViewText(R.id.beerBreweryName, beerBreweryName);
views.setTextViewText(R.id.beerStyleName, beerBreweryStyle);
views.setImageViewBitmap(R.id.image, bitmap);
This gave the same result as the last attempt, it would not even set any text views....
Just tried another attempt after one of the answers posted below:
RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_test);
//get beer data
JSONObject o = new JSONObject(result);
String name = getName(o);
String imageURL = getImage(o);
String abv = getABV(o);
String ibu = getIBU(o);
String glass = getGlass(o);
String beerBreweryName = getBreweryName(o);
String beerBreweryStyle = getBreweryStyle(o);
String beerDescription = getDescription(o);
Log.d("widgetImage" , imageURL);
views.setImageViewUri(R.id.image, Uri.parse(imageURL));
views.setTextViewText(R.id.beerTitle, name);
views.setTextViewText(R.id.beerBreweryName, beerBreweryName);
views.setTextViewText(R.id.beerStyleName, beerBreweryStyle);
mgr.updateAppWidget(appWidgetIds, views);
This attempt lets all the text views load, but no image ever shows up.
The way to do this reliably is to use setImageViewURI on the remote ImageView. The trick is that the URI you give it is a content:// URI which then points back to a content provider that you export from your application. In your content provider you can do anything you need to do to supply the image bytes.
For example, in your manifest:
<provider android:name=".ImageContentProvider" android:authorities="com.example.test" android:exported="true" />
And your provider:
public class ImageContentProvider extends ContentProvider {
// (Removed overrides that do nothing)
#Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
List<String> segs = uri.getPathSegments();
// Download the image content here, get the info you need from segs
return ParcelFileDescriptor.open(new File(path), ParcelFileDescriptor.MODE_READ_ONLY);
}
}
And then your URL is something like:
content://com.example.test/something-you-can-define/here
This is necessary because your remote image view is not running in your process. You are much more limited in what you can do because everything must be serialized across the process boundary. The URI can serialize just fine but if you try to send a megabyte of image data with setImageViewBitmap, it's probably going to fail (depending on available device memory).
Got a lot of help from multiple sources for this question. The big problem for me why a bunch of the attempts I tried listed above seemed to lock the widget app and not load anything is because I can not download the image and set it in a UI thread.
To accomplish this I had to move everything to the do in background of my async task and not in the onPostExecute.
I am new to Android, I am developing an app, where in I search the youtube using the
....
YouTubeService service = new YouTubeService('blah','blah')
....
VideoFeed videoFeed = service.query(query, VideoFeed.class);
List<VideoEntry> videos = videoFeed.getEntries();
YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
String webPlayerUrl = mediaGroup.getPlayer().getUrl();
......
ytv.setWebPlayerUrl(webPlayerUrl);
.....
List<String> thumbnails = new LinkedList<String>();
for (MediaThumbnail mediaThumbnail : mediaGroup.getThumbnails()) {
thumbnails.add(mediaThumbnail.getUrl());
}
....
In the Adapter, I used this
mWebView.loadUrl(torvideo.getWebPlayerUrl());
But I get a full screen youtube image in the webview and a scroll able list of similar videos.
However What I want is a thumbnail which looks similar to youtube search result (Small Image, title of the video and few more details.
Can you please suggest me, which view or a sample code, so that I can use the thumbnails list I got it from mediagroup object to display in my app?
Edit/Update:
I have used
public class ResultViewAdapter extends BaseAdapter {
........
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
final LayoutInflater li = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = li.inflate(R.layout.activity_result_list, null);
}
TORYouTubeVideo torvideo = (TORYouTubeVideo) getItem(position);
TextView textView = (TextView) row.findViewById(R.id.textView1);
textView.setText(torvideo.getVideoTitle());
InputStream is = (InputStream) new URL(torvideo.getThumbnails().get(0)).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
ImageView imageView = (ImageView) row.findViewById(R.id.imageView1);
imageView.setImageDrawable(d);
return row;
}
But still I cannot see the images in my list view and Only see an empty scrollable list
Thanks
Answering my question again!!
Moved this part
InputStream is = (InputStream) new URL(torvideo.getThumbnails().get(0)).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
To the same async task where my youtube query is happening and I am able to see the image now!
(It was the issue with mainThread)
Looks like long way to go with Android!! :P
Thanks
Help please!
In my application I use Android-UiTableView ( thiagolocatelli / android-uitableview ) and AQuery ( androidquery / androidquery )
My task is to make the loading of data from json array and load image from URL.
Load a list without pictures I was able to:
jgall = json.getJSONArray("gall");
int z = 0;
for(int i = 0; i < jgall.length(); i++){
JSONObject c = jgall.getJSONObject(i);
tableView.addBasicItem(c.getString("name"), c.getString("place"));
}
I try to show a customized view and nothing happens
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout) mInflater.inflate(R.layout.custom_view,null);
String iurl = c.getString("img");
aq.id(R.id.img).image(iurl, false, true);
ViewItem viewItem = new ViewItem(view);
tableView.addViewItem(viewItem);
Tell me it's real to make using Android-UiTableView? if so! how?
I have done this by modifying the library code myself.
I have added the following constructor at UITableView.java:
public void addBasicItem(Drawable drawable, String title, String summary) {
mItemList.add(new BasicItem(drawable, title, summary));
}
And the following at BasicItem.java:
public Drawable getDDrawable() {
return dDrawable;
}
public BasicItem(Drawable ddrawable, String _title, String _subtitle) {
this.dDrawable = ddrawable;
this.mTitle = _title;
this.mSubtitle = _subtitle;
}
And once again modified the setupBasicItem method at UITableView.java file:
((ImageView) view.findViewById(R.id.image)).setBackgroundDrawable(item.getDDrawable());
Finally, at your code add the following:
URL newurl = new URL("http://www.example.com/example.png");
Bitmap bmp = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());
Drawable drawable = new android.graphics.drawable.BitmapDrawable(getResources(),bmp);
tableView.addBasicItem(drawable, "Title", "SubTitle");
Hope it helps, cause it works for me.