I have an Android app that offers syntax highlighting for source code files. It's performing very poorly for large files such as this and freezing the UI for 10+ seconds. I have profiled my app and a method out of my control appears to be taking up a lot of time on the main thread. I would like to implement lazy rendering / 'pagination' so that instead of coloring the whole file when the user loads it, I only color what the user sees at first, and color in uniformly-sized chunks as (s)he scrolls down. What are some approaches I can take to implementing this? Thanks.
Related
I have an application in java swing and geotools. I have displayed a map image and trying to add images as layers to it. When it adds layer it blinks and after some time at the call to addLayer function map image and other few layers disappear for some time. How to stop this? I am loging all the information at the same time in SQLite and then to my own customised file.
I have stopped trying refreshing all after addLayer function call. The all process should work smoothly without blinking and disappearing. Please Help.
The gt-swing module is really only intended for simple demonstrations. If you intend to use it in production you should add in off screen buffering to allow "fast" refreshes of the map without rereading all the displayed data.
I have an ImageView. When user presses button I want to change image (it is animation-list) and run this animation. I used to use setImageResource, but it blocks UI thread and causes lags. I can't predict what image I would set befor user presses button. I tried to preload drawables but it causes OOM, because I have about 30 xmls with animation-list. How can I solve It? To sum up, I want to fastly change image in my ImageView and then start frame animation on it.
I think you are performing a fetch operation on the UI thread for the image(either from storage or network call). That is what is causing the lag.
You might look into using a library to load up your images. There is one that is really easy to implement called Picasso. It's been around for a while too, so it should be easy to see some examples.
It is bad practice to do big jobs on the UI thread as if you do, those big jobs will cause the program to hang (not accept user input or render any new data) until that job is finished.
I am looking to add a widget to our code base that will indicate to developers when they have committed this taboo. My idea, and one I've seen on a number of other applications, is to have some component that is constantly moving at a constant speed, such as a bar that is constantly twirling on the screen. With such a tool, if a developer is working and accidentally does something that is more computationally difficult than he expected on the UI thread, this spinning bar will become choppy, indicating to him, when he does functional testing, that he needs to implement mechanisms that will cause this job to be executed elsewhere.
One odd requirement on this code is that it should be completely non-existent in production builds, and only present in dev builds, since it is a widget not for users, but for developers.
I jumped into the Canvas objects and wrote up a quick component that simply spins a teal bar. The idea is that if a big job is dumped on the UI thread, the bar will stop spinning (since the FX job queue wont continue dispatching) and the bar will jump forward, rather than rotate smoothly (as it does when the program is at rest).
Below is a screen-shot of this first implementation:
(notice the teal bars, which, if you saw our application running, would be rotating slowly but steadily --hopefully anyways)
The issue here (as you might notice) is that our layout's been screwed up. This is because I'm modifying the scene graph from this:
Scene
RootComponent
Content
to
Scene
obnoxiousPane
Canvas
Spinner(s)
RootComponent
Content
Modifying the scene graph in such a way has things like preferred height, mouse events and (presumably) any number of other events getting dispatched to the spinners rather than the content components.
Of course, when we go to production, I would like to have the original scene graph in the version that we give to our users.
So my question is this: How should I go about correcting these problems?
I could go after each of them individually as they come up, writing a lot of custom code to do things like
obnoxiousPane.prefHeightProperty().bind(content.prefHeightProperty)
obnoxiousPane.prefWidthProperty()//...
spinner.setMouseTransparent(true)
spinner.setOtherEventsIProbablyCantEnumerateWithoutSeriousResearchTransparent(true)
Or I could try to go after this problem with reflection, attempting to bind every property in the content pane to the corresponding obnoxiousPane property, but this seems like a bug breeding ground.
Or... what? I'm hoping there's some LightWeight component or ImNotReallyHereProperty that I can leverage to add this development aid.
Thanks for any help!
Your approach seems fundamentally flawed. You shouldn't be stalling the JavaFX application thread.
Instead you should have a concurrent process and update the UI as appropriate as the process starts, progresses and completes.
See this java2s sample for using the JavaFX concurrency and progress indicator facilities for an example of such an alternate approach.
If you want to disable some portion of the UI for a time, nodes have a disabled property which you can set. You can use CSS to style a disabled node so the user has some indication that the thing hasn't just hung and is deliberately disabled.
I am using a RecyclerView to display data that gets polled from a website (=> completely changes at once).
I already created an ItemAnimator class that has the animation I want but I need to know what is the best way to time the animations to wait for the previous one to finish.
This is what I'm trying to achieve: http://www.google.com/design/spec/animation/meaningful-transitions.html#meaningful-transitions-hierarchical-timing
We've had a lot of success using setStartDelay (or setStartOffset, depending on which animators you are using). Have a delay variable that starts at 0, and as you walk through your children creating their animations, set the start delay to the current value and add some increment, such as 100 ms.
I've been working on the exact same animation. I've put it to the side for the time being, but got a pretty good effect at normal speed. When I slowed it down for debugging, I've got a strange bug that causes certain items to be animated multiple times. Also, scrolling up doesn't quite work if the animation hasn't completed, but that isn't a bug likely to be run into at normal speed.
Here's my code: https://github.com/halfjew22/AnimateRecyclerGrid
Essentially, what I did was I looked at the pattern in the Material Animation. Based off of that pattern, I put together a for loop that spawns a runnable that is given coordinates (based off the value in the for loop) and told to animate the view with those coordinates.
Like I said, I didn't quite finish the project, but it works fairly well as an alpha or proof of concept. I know it's been a while since you asked this question, but let me know if you'd like to work on finishing this up together.
Let me know if that helps you out.
I've created a custom RecyclerView adapter class which does more or less what OP wanted to achieve i.e. animates RecyclerView's items sequentially (in order, one after the other).
The adapter class is shared publicly on github as a gist here.
From the description:
"This adapter aims to create a sequential RecyclerView items' animation.
They're appearing in order, top to bottom. The animation works when the RecyclerView is first created and does NOT work when items are scrolled down."
I want to know how to show the loading of an application. Normally (let's say Netbeans IDE,)
the application will show how far it has loaded and how far to load. Also, loading classes as well can be seen in welcome page. How is this is done and how we can show our classes loading and loaded status (in a progress bar) in our applications? Also let's say that we have used Hibernate, and there is a login on first page, it takes time to start but only for the starting (I think it is because that the Hibernate factory is getting started and load its classes). The answer is hoped in Java.
I want to know how to show the loading of an application.
See the java.awt.SplashScreen class. But..
..show how far it has loaded and how far to load.
..with a customized image. Call SplashScreen.createGraphics() to get a Graphics object (from the image defined as a splash in the manifest) which can be drawn on. Draw the progress bar at an appropriate location on the Graphics object. For the progress bar, either use a JProgressBar as already mentioned, or to keep it lean (using pure AWT), draw one big Rectangle to represent the bar, and fill a smaller Rectangle to represent the progress.
See also How to Create a Splash Screen in the Java Tutorial. (Where you can see that image above.)
That sounds for using JProgressBar, combined with Splash Screen or JDialog.
Be sure that JProgressBar must be updated on the Event Dispatch Thread, more about that in Concurrency in Swing,
Then you have two choices as to how to update a JProgressBar correctly - by wrapping code into:
SwingWorker
Runnable/Thread
There is some support built into swing for this. See the tutorial on How to Use Progress Bars to get started.
Here is a very basic code:
JProgressBar progressBar;
progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(33); // put here the percentage you want to display...
progressBar.setStringPainted(true);