How to know the status of the pages in a ViewPager - java

I'm implementing a image gallery with a ViewPager.
Each page load a image from Internet and put it in a ImageView.
The gallery also have a share button (external to the ViewPager).
I want to disable the button when the image is loading and re-enable it when the image is visible.
How can I know the status of the current page (if the image is beeing displayed or not) from the Activity containing the ViewPager?
Thanks

You can override setPrimaryItem function
public void setPrimaryItem(android.view.ViewGroup container,
int position, Object object) {
super.setPrimaryItem(container, position, object);
//check if image is loaded here
};

Related

Loading an image inside a bottom navigation bar item icon using an URL

I'm trying to load a profile image using the firebase storage url inside an item's icon of a bottom navigation bar, here's my code:
Glide.with(getApplicationContext()).asBitmap().load(profilePicUrl)
.into(new CustomTarget<Bitmap>() {
#Override
public void onResourceReady(#NonNull Bitmap resource, #Nullable Transition<? super Bitmap> transition) {
Drawable profileImage = new BitmapDrawable(getResources(), resource);
bottomNav.getMenu().getItem(4).setIcon(profileImage);
}
#Override
public void onLoadCleared(#Nullable Drawable placeholder) {
}
});
The profilePicUrl does work, I already use it to for another image view. However when I run the app, the dimensions of the icon changes corresponding to the picture that I'm trying to load but there's no image inside, here's how it looks.
Menus do not support coloured images
You can not use a coloured image in these places and a bit more also:
In bottom navigation
In navigation drawer
In popup menu
etc...
Basically which ever view uses a menu file for its resource, cannot have a coloured image. That is why you don't see it. To test it yourself, take a colourful image in your drawable and set it as an icon for the bottom navigation. You notice that it comes the same way. This proves it
Edits
This post gives some info on how to do it
You can do it this way:
mBottomNav.setItemIconTintList(null);

In Android Studio How to make Validation for imageview?

How to make validation in android studio for image view.
E.g. I have button when i click on button it open a gallery and i select image it comes in image view but how to set that if someone not upload image it will show message till not upload image in image view
Thanks.
The uri or bitmap that you use to save the image, use it in sharedPreferences. So that when the default value is null user will get the message but when you add a new image it will overwrite the default value of sharedPreferences and hide the messgae.

Using Adapter and Item Holder, Hide views from List View

I want to show my text view as shown in Image Below, for which i have to
remove other Views (as I have taken a Text View, Image View and a Video View
in a single XML). I am using Item Holder to show my Text View, and
want to hide Video View and Image View together.
I m trying to code but it is not working.
itemHolder.textViewMessage = (TextView) convertView
.findViewById(R.id.messageDetail);
if (itemHolder.textViewMessage != null && messageBean.getMessage()!=null)
{
itemHolder.textViewMessage.setText(messageBean.getMessage()); // here i am showing my text messages.
itemHolder.imageview2.setVisibility(View.GONE);
itemHolder.videoView.setVisibility(View.GONE);
}
[1]: http://i.stack.imgur.com/PsKTL.png
[2]: http://i.stack.imgur.com/XYCMb.png
In images given above, I don't need extra space below text.
Here Image View and Video View are showing extra space, which
I want to get Invisible.
Here view.gone not Working

Cannot setImageResource

I'm trying to build an android app to stream online radio.
Currently it starts to shape up and works like this: When I click on a gridview item in MainActivity, it starts the AndroidMediaPlayer activity that streams a fixed url and shows a fixed image that doesn't represent the users selection.
Code: https://github.com/sthlmj/IORadio/tree/clickable-funktionen/app/src/main/java/se/mookito/ioradio
Now I am trying to make it work properly, so that if I click on a certain gridview item, the image and the stream url should play according to the selection. I started by trying to get the picture to be displayed correctly by trying to pass clicked position from the MainActivity
of the items ArrayList in MyAdapter via intent so that I can setImageResource on the second activity AndroidMediaPlayer according to selected image from the first activity MainActivity.
In the second activity I tried to get the intent data:
//Selected image id
int position = i.getExtras().getInt("id");
MyAdapter myAdapter = new MyAdapter(this);
//Set image id
ImageView imageView = (ImageView) findViewById(R.id.mp3Image);
imageView.setImageResource(myAdapter.items.get(position));
But I got: 'setImageResource(int)' in 'android.widget.ImageView' cannot be applied to '(se.mookito.ioradio.MyAdapter.Item)'
Call imageView.setImageResource(myAdapter.items.get(position).drawableId); instead.

Handling screen orientation changes

My app functions like this: an imageView that can be visible in portrait or landscape, and the user can swipe between images to change the image in the imageView. The issue is that if you swipe to select a different image and then rotate the device to landscape it shows the original image the user selected, not the current image that was being displayed in the imageView. I am wondering how I can get the id of the current image before it is rotated, and then set it for when it is in landscape. Would it be in the onPause method, or is there a onConfigurationChanged method I could use for this?
See here: http://developer.android.com/training/basics/activity-lifecycle/recreating.html
According to the documentation, the activity is destroyed when the orientation changes. In order to save additional state information in such an event, you can override the onSaveInstanceState() method and add key-value pairs to the bundle object, like so:
public void onSaveInstanceState(Bundle savedInstanceState){
savedInstanceState.putInt("CurrentImageId", [current image id here]);
super.onSaveInstanceState(Bundle savedInstanceState);
}
Then, when the application is restored after the orientation change, you can retrieve the current image's id by overriding either the onCreate(Bundle savedInstanceState) method or the onRestoreInstanceState(Bundle savedInstanceState) method:
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int currentImageId = savedInstanceState.getInt("CurrentImageId");
//Set the current image here, after retrieving the id
}
Of course, I don't know exactly how you're identifying your images, so I can't tell you exactly how to set/retrieve the current image's id.
Try to add android:configChanges="orientation" below <activity> in your AndroidManifest.xml

Categories

Resources