Is it possible to add a text overlay to videos? - java

I am an iOS developer and I have written an app for a client, it is a fitness (Crossfit) timer app, it films you on your workout and adds real time overlays and rep counts to the finished video. It was a fairly challenging project to complete and I was just wondering if the same thing would be possible on Android?
Essentially what I need to know is, is it possible to overlay text that changes (e.g a timer counting up in seconds) onto a recorded video?
If anyone has written an app that does this I would be grateful to see code snippets as Java is not my forte!
Thanks!

If you want to just display text over video and not add it into video file, it's really easy using FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<VideoView
android:id="#+id/VideoView"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<TextView
android:text="TEXT"
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
and text will be displayed over video.
If you want to add text into original video file, it will not be that simple. You need external tools to handle this, for example FFMPEG. this links give you more info about this topic: How to add text on video recording? and How to embed text while recording video in Android?

Yes it is possible, I have followed this tutorial and it is pretty efficient :
http://www.wowza.com/forums/content.php?432-How-to-add-graphic-overlays-to-live-streams-with-Wowza-Transcoder
That is for live stream and for videos you can use those softwares: Openshot or Kdenlive.

Related

How to make scrollable long image page?

I am making activity showing TOS(Terms of Service) contents.
TOS text content is written very long single image, which should be scrolled. And confirm button is located below it.
Is there any best practice to make it?
I used ScrollView to scroll contents.
ScrollView contains ImageView and ImageButton.
First, I insert very long TOS content image by android:src attribute.
But, xxxhdpi image file is about 1MB size and height is about 18000 thus the app crashed (it shows 'canvas trying to draw too large bitmap' error)
After that, I try using image library which are Glide and Picasso. Using them, the error doesn't occur but image quality got degraded.
I searched and tried many solution to keep resolution and render speed but failed.
I think trying to use smaller image is better solution, but in emulator scroll speed and behavior was very strange when used src attribute to draw image.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView">
<FrameLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
<ImageButton
android:id="#+id/textview"
some code... />
</FrameLayout>
</ScrollView>
I am not sure if using single long image with scrollView to show TOS contents is correct or not. And not sure if it is possible to handle long image properly with ImageView.
Respectfully, you're making life difficult for yourself.
Having the TOS in image form only is unusual; the 'correct' approach is to have your TOS in text form, which would also be fastest to code.
If the TOS is composed elsewhere, and you don't wish to re-type it, then possibly feed the image to an online OCR service and see what comes back?
Alternately, use a WebView component connecting to a web server serving a page with only the TOS image. (But this is a bad idea, because now you'll need to set-up and maintain a web-server!)
Try to put image to drawable-nodpi folder
If you are using Glide try to use .thumbnail() attr
Add to Android manifest largeHeap attr
And at least decrease size of big image

Pinterest Style in Displaying Images with UIL

Pinterest Style of Displaying Images is exceptional, and this adds beauty to your app. After a couple of research I found out that there are great libraries out there that can display images like Pinterest do but not sure if this is compatible with UIL.
I am using the Universal-Image-Loader in displaying my images. In the image shown below I got my images displayed in that manner with some views together with it. It is undeniably true that UIL library handles phone memory greatly in displaying a lot the images. I'd like to know if it is possible to display my images like the Pinterest's but still using UIL as the generator. What are the possible resolve to this approach? Or maybe another library that only handles the display and compatible with UIL.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="4dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="4dip"
android:padding="4dip" />
Update:
I tried using the StaggeredGridView but the layout can't be cast to GridView.
<com.origamilabs.library.views.StaggeredGridView
xmlns:tools="http://schemas.android.com/tools"
xmlns:staggered="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
staggered:numColumns="3"
staggered:drawSelectorOnTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Hey Check out my implementation of Pinterest type view using Staggered GridView and Universal-Image-Loader here.

Dynamically defining how an icon is drawn

I want to have a "comments" button on my Android e-reader app that displays the number of comments currently posted inside the icon... so basically I want a comment bubble with a number inside it.
I could have multiple drawables, each being the bubble with a different number inside of it, and use a switch statement to choose which one to load each time based on the int number_of_comments field of the element being displayed. This approach seems a little wasteful though, and in any case I have a feeling there's a more elegant way to do it.
Any ideas?
You can do better. You can have a textview on top of the image view and keep updating its value everytime a new comment is added. You can define the overlap in xml like below and adjust your code logic accordingly to increase the comment count. For now I have just set up a dummy text Hello to show on top of the ImageView. You can add your comment count using the TextView's setText method.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImageSouce" />
<TextView
android:id="#+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/myImageView"
android:layout_alignTop="#+id/myImageView"
android:layout_alignRight="#+id/myImageView"
android:layout_alignBottom="#+id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
Hope this helps...
check out this 3rd party created widget
Android ViewBadger
You can use it to create the little number bubbles that you are looking for I think. This gives you the benefit of not having modify your layouts so much to achieve what you are trying to get.
Here is the sample code to apply a "badge"
View target = findViewById(R.id.target_view);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();

Help making a "launcher screen" for my app, and making it look right across devices

I posted a question here before: Good way to make a launcher screen for sub-apps within your app?, and then started working on other parts of the app, and now I'm back to the same thing.
I want to make a nice screen with icons that the user can press, with room for more icons at a later date. Or maybe something different, I'm not sure.
Here's a current screenshot of what it looks like:
It looks pretty bad there, on my phone it looks better, with less space between the apps (this is a friend's phone), but ideally I want it to look good on all devices.
My XML code for this is as follows:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="20dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#FF6699FF"
/>
Any tips/suggestions are appreciated, I want to make this look good.
I'm not sure what format to store the icons in, right now they're just large (400x400 or so) png files.
If your icons are just squares you might want to use a compressed format like jpg or gif to reduce your app's file size.

What would be a method for creating a number counter in Android?

I want to create a scrolling counter that rises at a rate I give it for an Android app, I feel like there is no Android widget that does this well in the SDK and I wanted some idea how this should be accomplished, or even better an open source project around this idea.
Picture example:
This might not be a perfect answer, but at least a starting point. Discounting the animation and general fanciness, you can get most of the way there just by decorating a TextView with some fancy XML. I'll share what I did a few years ago to make a similar-looking screen area for a tip calculator:
Here's the XML. Each single digit is one TextView so you can change them individually. I'm showing two here but obviously there were 5 for the screenshot below.
<TextView
android:id="#+id/tv1"
android:layout_width="60dip"
android:layout_height="140dip"
android:background="#drawable/gradient"
android:textSize="64sp"
android:gravity="center"
android:typeface="serif"
android:textColor="#FFFFFF"
/>
<TextView
android:id="#+id/tv2"
android:layout_width="60dip"
android:layout_height="140dip"
android:background="#drawable/gradient"
android:textSize="64sp"
android:gravity="center"
android:typeface="serif"
android:textColor="#FFFFFF"
/>
And the "drawable/gradient" I created as a separate drawable file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dip"
android:color="#fbbb"
/>
<solid android:color="#600000"/>
<layout_margin android:layout_margin="1dip"/>
<gradient
android:startColor="#000000"
android:centerColor="#6D6D6D"
android:endColor="#000000"
android:angle="270"
/>
Here's the final result (inside a linearlayout):
In Addition to raggedToad's answer: You can use the ViewAnimator class to add animations to your counter. Its easy to use. You can extend it, add all the digit textviews in onCreate(). Implement a method increment that handles the increment operation. Just call showNext to flip to the next view.
I'm pretty sure that this particular counter in your screenshot has some short animations (about 5 or 10 frames) for each transition from one number to the next. Maybe there are also some more for showing rapid transitions without actually stopping at the particular number with more blurring.
So the main task would be creating the graphics. Then it's just a matter of displaying the right frame at the right time.
There's an open source project that does the exact thing you are trying to do.
Check: http://code.google.com/p/android-wheel/

Categories