Automate Animation according to time - android

I was working on an app and thought to create some animation in the splash screen of the app same as Google Doodle.
Animations would be according to time, I have sets of FestivalName , start and end date of the festivals like Christmas, new year etc. Start and end date will trigger the animation automatically.
I tried Airbnb's Lottie to do so. But storing all the animations files in assests is increasing the apk size by almost 5-6 mb. I tried to Optimize this by just storing 1 animation file and changing the file by a script. So whenever I need to change the animation , I run the below from root folder and the animations are changed.
Here is the script :
#!/bin/bash
rm -rf app/src/main/assets/animation.json
curl "$1" > app/src/main/assets/animation.json
It takes the parameter as a link which have the animation and download the file in assets file.
Animation Link
This approach increases only 716kb. But This doesn't seems to be automated, I want to know any other best approach for this which should be automated.

If you use the file name method, it will automatically put the serialization task and composition in a cache. So, you can just call that function with no listeners when you want to start getting it ready for the cache then call it again when you actually need it.

Related

Efficient implementation of File Explorer - Android

I'm creating a simple file explorer on Android Studio, and I wonder which one of the following implementations is the best:
My solution:
I have an activity called MainActivity that displays my list of files, and each time the user clicks on a directory, it creates a new MainActivity (and the onCreate method gets the new list of files, ...).
Correction:
In a correction from a tutorial, I found that when the user clicks on a directory, instead of starting a new activity, the code keeps the current one and changes everything (clear the list and fill it with new files, change the title...).
Is there a solution that is better than the other ? Is it more efficient to keep always the same activity ?
Thanks for any help.
Keep a single activity no question about it !
When a user clicks an item you build your data-source based on the newly selected path. Make sure to distinct between files and directories. Then simply call notifyDataSetChanged and thats it !
To query the file system there are two ways:
The easy - use Java File.listFiles()
The hard - run shell command Runtime.getRuntime().exec( "ls -la" ) and parse response.
There are many open source projects on github for the subject. Example:
Amaze File Manager

Multiple IntentService calls vs single service with multiple parallel threads

I have two operations that I need to perform on 400 large image files. The files are being downloaded over a private network to folderA.
Operation 1: move the files from folderA to folderB
Operation 2: resize each file
The thing is I have a small time window for moving the files from folderA to folderB, in fact as soon as a photo hits folderA it needs to be in folderB. What is my best approach for doing this? Right now I am considering two avenues.
Approach 1 (what I have now, too slow):
Use a FileObserver to track when photos are in folderA
Use an IntentService to: get image from folderA, resize image, then save new image to folderB
Approach 2 (wondering):
Use a FileObserver to track when photos are in folderA
Use a service with a custom Handler that allows parallel threads and for each photo, create a new thread to do: get image from folderA, resize image, then save new image to folderB
Approach 3:
Use a FileObserver to track when photos are in folderA
Use an IntentService to: for-each file, first move the file from folderA to folderB; then start another IntentService to resize the file.
I already know that approach 1 is not fast enough as it is the one I am now using. So, between approach 2 and 3, which one is faster and why? For example we are talking about 400 large image files. Does the OS impose limits on how many concurrent threads a single service can have? Should I worry about increasing thread pool? How about in case 3 where I am using two services (MoveIntentService and ResizeIntentService), how do I tell android to run “all” the calls to MoveService before the calls to ResizeService?
I understand that ResizeIntentService queues all the calls. But I am okay with that. I just need for MoveIntentService to move the files very very very quickly.
Also, although I say 400 files, I don't really know how many files and so I cannot wait for folderB to be full before I start the resize portion. I am also aware of the case where I can use a single IntentService to first move a file and then start a thread to resize the file.
Again, is it cheap to move a file in android (i.e. pointer versus actual re-copy)? I am here assuming that it is very cheap to move a file relative to resizing a file.
BTW both folderA and folderB are some level under Environment.getExternalStorageDirectory()

I Want to use variable in cucumber feature file

There are scenarios in feature files wherein I've use the text "Foo" and on click its open a new page. this text sometime changes to "Foo1" or "Foo2" or to something else. to avoid line by line change in feature file for "Foo" to "Foo1" or "Foo2" is there any way that I can globally declare variable in top/bottom of the feature file where I can set the required text in variable on fly and I shall start executing my test instantly?
This change exist in many feature files and around 1000 lines in feature file. To get solution for this, I try on setting environment variables but I couldn't reach all the way till end this issue to solve. So can anyone help me on this?
Thanks in advance
What if you do the replacement in your step implementation instead? Then you could have the desired value in a separate file or pass it as arguments. That way you don't need to hard code the values.
Could scenario outlines help you in any way or is the value only changing depending on external changes?
My first thought was scenario outlines like #homaxto said.
Then I thought you might want to affect it by which system you are connected to. You can do this through configuration. I have done this with Fig_Newton.
You can either set an environment varaible or use one in the commandline. Or you can use #hook type tags. With a hook tag, you can have a tag at the top of a feature file that you can use to set a variable that affects how the steps operate (but it needs to be handled inside the step).

Calabash Android: Is it possible, in a feature file, to call certain previous lines of the same feature file (re-use previous steps)?

Is it possible, in a feature file, to call certain previous lines of the same feature file?
Without using some steps of same feature file again you can use combined steps.
Ex :
Think you need to delete an order and go to home screen several times in a same feature file and for that think you need to call this 4 lines
Then I touch order cart delete order button
Then I should see delete item alert in oder cart and select YES option
Then I wait for 1 seconds
Then I go to home screen
So you need to call this 4 lines in 4 times in the same file. Instead of that you can define a new step in a ruby file like this
Then /^I delete order from ordercart$/ do
steps %{
Then I touch order cart delete order button
Then I should see delete item alert in oder cart and select YES option
Then I wait for 1 seconds
Then I go to home screen
}
end
And now you can directly delete an order using single line calling in feature file
Then I delete order from ordercart
Now you need only 4 lines instead of 16 lines and also it is easy to maintain the new changes to the code when you need in the future.
check out the 'step' command in cucumber.
In my experience though, it's a better practice to use conventional ruby method definitions and and call those from your step definitions. Steps calling other steps can get really messy.

Smart way of uploading files based on changes

My app has to watch for file changes to a directory and upload a copy whenever a change is made. To do this, I've employed the use of a FileObserver. I have it upload on Creation, Move To, Close Write, and Modify. The problem lies with modify. Modify is called every time a change is written to disk which, if a file is large (being copied or a lot changed) isn't atomic so it fires hundreds of Modify events, this makes my app freak out because it's trying to upload so many times and it crashes. My first thought was to remove the modify event so that it'll only upload when Close Write is called. Unfortunately, this isn't always called. So I'm kinda stuck with Modify. So my question is this: is there a best practice when it comes to detecting the end of a file modification? I need to upload this file when it's done being modified, not while. How would you go about doing this? How can I discover when the last Modify event is fired. Do I have to make a complex timer system, or is there an easier way. (If there isn't, could you tell my the best practice of making such a timer system?)
I know I've asked a lot, but I'd appreciate any brainstorming and ideas.
Thanks!
Edit: So I've found something weird. At least on Android 4.2, Open never fires, therefore close never fires. Just an FYI.
Use a worker thread that test the file for changes every x seconds and if it is changed, then send the updated version to wherever you need. To avoid sending a file that is being written test for File.isOpen or use a boolean value to keep track of occurring changes.
If the files are text based, you could maybe diff the original file and the modified file and only upload the file if the number of different lines are sufficiently large.
With a bit of luck, one might do something like track the time between modification events, assuming that they're received more-or-less consistently…
last-notification = now;
notification-interval = 1 s; /* some default */
listen for (file closed);
listen for (file modified);
alarm at (now + notification-interval);
on (file modified) =
cancel alarm;
notification-interval = max ( notification-interval
| [now - last-notification] );
alarm at (now + 2 × notification-interval);
on (file closed) =
cancel alarm;
do upload;
on (alarm) =
if (file is open?) then alarm at (now + 2 × notification-interval);
else (signal file closed)

Categories

Resources