Android : Slide a view from Right

Today I will be writing about a very short post post on how to animate a view to slide in from Right side of the screen.

In order to achieve this we will be using the Object Animator class of Android. We will be using translate property on X axis so that it translates from Right to Left.

Another class that we will be using shall be Layout Transition. This is responsible for animating the layout changes. For ex: If you require to do some animations when a view is being added, removed or being changed, then you will have to use this class only.

Lets have a look at few lines of the code :


ValueAnimator anim = ObjectAnimator.ofFloat(v, "translationX", start,end);
anim.setInterpolator(interpolator);
anim.setDuration(duration);

 

In the above code we are translating it on X axis from a start position to end position. To translate from Right the start position will be something greater than equal to the width of screen and end position shall be 0.

Below I am posting the complete source code:

SlideFromRightAnimation.java

 

Now how to use the above class:

final ViewGroup vg = Parent View group
final View v = View which you want to animate
LayoutTransition tr = new LayoutTransition();
SlideFromRightAnimation sfr = new SlideFromRightAnimation(this, 0);
tr.setAnimator(LayoutTransition.APPEARING, sfr.getAnimator(v));
tr.setDuration(500);
tr.setStartDelay(LayoutTransition.APPEARING, 0);
vg.setLayoutTransition(tr);
vg.addView(v);

Now its done, when your view will be added it should come in from Right side.

Now lets see, how it will show up once integrated. Here I integrated it in one of my projects.

Android Vimeo , Get user videos

Vimeo-Icon

Hello everyone, in today post I shall be showing how to get the Vimeo videos of user using the api.
For various operations Vimeo provides methods, and it is this method that we pass as parameter to the api, for various features that we want to integrate.

Consider the URL below:
http://vimeo.com/api/rest/v2?format=json&method=vimeo.videos.getAll&user_id=brellow

The above URL contains 3 parameters :
1.) format :- This specifies in which format we need the response, here we are using JSON.
2.) method :- This is the operation that we are performing, here since we want a list of all video we are using, vimeo.videos.getAll. For a complete list of method you can refer here.
3.) user_id :- This is the user for whom we want the video, I just picked a random user from site.

If you will call the above URL as it is, it will not work, since Vimeo uses OAuth to authenticate all the requests. For this we will have to generate an OAuth token.

  1. Register Your app at : https://developer.vimeo.com/apps/new
  2. Once done, go to Authentication tab and copy Client Identifier and Secret key.
  3. Download scribe library.
  4. Download Apache commons codec.
  5. Fetch token in your java code using, OAuthService Builder class.
  6. Sign the Request and get the response.
  7. Have a look at this class for the code.
  8. Download complete project to test.

Well I have simplified it as much as I can, thanks to the scribe class for making integration so easy.

If you liked my post please do share.