Partial Screen Refresh in Android - android

I have a Activity which has 2 components
Image view
Text view
Here the image in the image view is changed using a timer. This works fine. The text is scrolling text is marquee. Individually these works fine.
My problem is when the image gets changed it also reset the marquee string.
Is there any way to avoid this?
Is there any way to refresh the display partially in android.
Edit
File imgFolder = new File(config.AppDataDir+config.MainImagesDir);
if(imgFolder.isDirectory()) {
File[] imageList = imgFolder.listFiles();
if(imageList!=null) {
if(imageList.length>0) {
if(imageList[currentImageNum].exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imageList[currentImageNum++].getAbsolutePath());
ImageHolder.setImageBitmap(myBitmap);
}
if(currentImageNum>=imageList.length)
currentImageNum =0;
}
}
}
Thanks

Normally, changing the source of an ImageView should not have any implications on other views. Most probably when changing the image you are doing something that is reflected on the TextView too.

Related

Change image after click on ImageView

everyone. After clicking on an ImageView, I would like to change it depending on what kind of drawable is currently displayed. To do this, I compare the currently set image in the ImageView with one from the drawable folder. Unfortunately, it is currently the case that only the else branch is executed. The image changes after the first click, but then it no longer switches. What am I doing wrong?
bookmark_site.setOnClickListener{
vibrator.vibrate(50);
var draw = bookmark_site.drawable.constantState
if(draw == ContextCompat.getDrawable(this,R.drawable.ic_baseline_bookmark_filled_24)?.constantState)
{
bookmark_site.setImageDrawable(resources.getDrawable(R.drawable.ic_outline_bookmark_border_outline_24))
}
else{
//Only this two is ever executed
bookmark_site.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_bookmark_filled_24))
}
}
you can't base on constantState, its not desired to compare drawables as there is a different instance for every drawable, thus your if isn't true never ever. in fact there is no way for getting resource of drawable already set for ImageView. most convenient way would be to keep some boolean flag outside onClick method informing that image is switched or not. optionally you may keep this flag "inside" ImageView using setTag(...) method
bookmark_site.setOnClickListener{
vibrator.vibrate(50);
val switched = bookmark_site.tag != null
bookmark_site.setImageResource(
if (switched) R.drawable.ic_outline_bookmark_border_outline_24
else R.drawable.ic_baseline_bookmark_filled_24
)
bookmark_site.tag = if (switched) null else "SWITCHED"
}
you should keep category or tag along with the image in the model class and then change the image on the basis of that tag or category.

Android: Bottom Sheet text view not updating

Here is my code:
public void openBottomSheet(long id) {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
_bottomSheet.setState(BottomSheetBehavior.STATE_EXPANDED);
_bottomSheet.setPeekHeight(140);
coordinatorLayout.requestLayout();
Item item = _selected.getItem(id);
final String titleText = item.getTitleText();
_bottomSheetTitle.setText(titleText);
coordinatorLayout.requestLayout();
int imageResource = (id > 5) ? R.drawable.ic_closed : R.drawable.ic_open;
_bottomSheetState.setBackgroundResource(imageResource);
coordinatorLayout.requestLayout();
coordinatorLayout.invalidate();
}
Firstly, I'm broadly having the issue described at https://code.google.com/p/android/issues/detail?id=205226 where they suggested requestLayout() was the solution.
And it does sort of fix it. However, I am finding the first time I open the bottom sheet (by clicking some other element in the UI) the text does not load. The second, third, fourth and so on time, the text does update. So it's just on that initial load that it's not quite working.
The image resource seems to load fine on the first attempt. It's just the textview not updating.
Does anyone have any suggestions?
Edit
I've tried putting the requestLayout() in a number of places to see if it would make a difference.

Not Getting Thumb with Genres - Universal Music Player

I am using UMP example provided by Google, I have not made any change in my code, even I have not tried anything out of the box, I just imported your project into my work-space and checked it on my device, and found that I am not getting Thumb with Genres (Songs by genre) and List of Genres...
Whereas I supposed to get Thumb from our JSON, here is what I have tried (but no success) -
holder.mImageView.setImageBitmap(description.getIconBitmap());
UPDATE # 1 AS PER SUGGESTED BY #NageshSusarla here
holder.mTitleView.setText(description.getTitle());
holder.mDescriptionView.setText(description.getSubtitle());
AlbumArtCache cache = AlbumArtCache.getInstance();
Bitmap art = cache.getIconImage(url);
if (art == null) {
cache.fetch(url, new AlbumArtCache.FetchListener() {
#Override
public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
if (artUrl.equals(url)) {
holder.mImageView.setImageBitmap(icon);
}
}
});
} else {
holder.mImageView.setImageBitmap(bitmap);
}
holder.mImageView.setImageBitmap(description.getIconBitmap());
and getting Cannot resolve symbol 'url'
The icon bitmap may not have been set. It's best to use the AlbumartCache to fetch the icon and then set it on the imageView. The url to be passed to AlbumArtCache.getInstance().fetch(url,..) is description.getIconUri().toString()
The reason you may not be seeing it in uAmp is because of the tint being applied to it. You can remove the tint from media_list_item.xml to try out the changes.
Aside: This is indeed by design and the icon is only shown at the bottom when a user selects the item to be played.
This is by design. To keep the navigation cleaner, we decided to not
show the MediaItem icon on the local browsing UI. Other browsing UI's
may show it, like Android Auto and Android Wear.
I think you should check it in issues of android-UniversalMusicPlayer. Take a look at comment given by mangini here.
If you want to change uAmp to show the MediaDescription.getIconUri,
set the holder.mImageView at this.

WebView appears as plain white box after the second time it's been initialised

EDIT: tl;dr: WebView appears as white box, even though I appear to be setting it up correctly, and indeed it does work the first two times, but fails subsequently)
EDIT: Video showing the problem in action...
I have the following bit of code which inflates a view (Which contains a WebView) from the xml which defines it:
private void createCard(ViewGroup cvFrame, Card card) {
//... setup vairables...
cvFrame.clearDisappearingChildren();
cvFrame.clearAnimation();
try {
View cv = LayoutInflater.from(getBaseContext()).inflate(R.layout.card_back_view,
cvFrame, true);
cv.setBackgroundDrawable(Drawable.createFromStream(mngr.open(deckName + "_Card_back.png"), deckName));
TextView suit = (TextView)cv.findViewWithTag("card_back_suit");
//...setup text view for suit, this code works fine every time...
WebView title = (WebView)cv.findViewWithTag("card_back_title");
//This WebView doesn't appear to be the one which actually appears on screen (I can change settings till I'm blue in the face, with no effect)
if (title != null) {
title.setBackgroundColor(0x00000000);
title.loadData(titleText, "text/html", "UTF-8");
} else {
Log.e("CardView", "Error can't find title WebView");
}
} catch (IOException e) {
Log.e("CardView", "Error making cards: ", e);
}
}
When this method is called as part of the onCreate method in my Activity, the WebView contains the correct code, and is suitably transparent.
I have a gesture listener which replaces the contents of the ViewGroup with different content (It animates the top card off to the left, replaces the contents of the top card with card 2, puts the top card back, then replaces card 2 with card 3)
//Gesture listener event
ViewGroup cvFrame = (ViewGroup)findViewById(R.id.firstCard);
cardLoc++
cvFrame.startAnimation(slideLeft);
(onAnimationEnd code)
public void onAnimationEnd(Animation animation) {
if (animation == slideLeft) {
ViewGroup cvFrameOldFront = (ViewGroup)findViewById(R.id.firstCard);
ViewGroup cvFrameNewFront = (ViewGroup)findViewById(R.id.secondCard);
createCard(cvFrameOldFront, cards.get((cardLoc)%cards.size()));
createCard(cvFrameNewFront, cards.get((cardLoc+1)%cards.size()));
TranslateAnimation slideBack = new TranslateAnimation(0,0,0,0);
slideBack.setDuration(1);
slideBack.setFillAfter(true);
cvFrameOldFront.startAnimation(slideBack);
}
}
When the animation has happened and I replace the contents of the cards, the TextView suit is replaced fine and the code definitely passes through the code to replace the WebView contents, but for some reason I end up with a white rectangle the size and shape of the WebView, no content, no transparency.
If I change the WebView to a TextView, it's contents is replaced fine, so it's an issue that occurs only with the WebView control :S
Can anyone tell me why / suggest a fix?
It turns out the WebView doesn't get cleared down when using the LayoutInflater to replace the contents of a ViewGroup. The other controls all seem to get removed (or at least the findViewWithTag() returns the right reference for every other control). I've just added in the line cvFrame.removeAllViews() immediately before the LayoutInflater does it's stuff and that fixed the issue.
If anyone has any better explanation for this I'll throw the points their way otherwise they will just go into the ether...
By calling findViewById, you are getting a reference on the previously loaded webview do you ?
so the loadData call that fails is the second one you make on a single webview instance.
you may want to check this :
Android WebView - 1st LoadData() works fine, subsequent calls do not update display
It appears that loadData() won't load data twice... you may want to try WebView.loadDataWithBaseUri()
Hope that helps.
I had a similar problem loading several WebViews content.
It was because of a misusing of the pauseTimers function
The situation was : the first webView weren't needed anymore, conscientiously I wanted to pause it before to release it. Calling onPause() and pauseTimers()
pauseTimers being common to any web views, it broke every use of webviews occuring after that, there were displaying only white rectangles.
Maybe its not your problem here, but it's worth checking your not calling WebView.pauseTimers() somewhere.
To confirm your answer, the source code for LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot) does in fact internally calls root.addView() which attaches the newly inflated view at the end of the root's children instead of replacing them.
So the mystery now is why did your call to findViewWithTag() is returning the expected objects for your other widgets (which would be the top, most recently created instances), but for your WebView it was returning something else.
Is it possible that there is another object in your layout XML which shares the same "card_back_title" tag?
I was also wondering why you didn't use the more common findViewById() instead, but I am not sure whether it would make a difference.

Using an image as the parent Activity (interface)

Is it possible to use an image as the background of the main Activity? (load screen). I then want to put buttons over the image. If this is possible could anyone tell me how I would load the image into my main Activity? Or send me to a site that would go over this?
Thanks :)
I use the following to set a background image for an Activity..
View view = getWindow().getDecorView();
int orientation = getResources().getConfiguration().orientation;
if (Configuration.ORIENTATION_LANDSCAPE == orientation) {
view.setBackgroundResource (R.drawable.bground_land);
} else {
view.setBackgroundResource (R.drawable.bground_port);
}
bground_land.jpg and bground_port.jpg are images in my project's /res/drawable directory.

Categories

Resources