Created
May 13, 2015 10:48
-
-
Save alorma/52e5f733ae99dd687b71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.worldline.evasdk.view.utils; | |
import android.support.v4.view.ViewCompat; | |
import android.view.MotionEvent; | |
import android.view.View; | |
/** | |
* Created by a557114 on 07/05/2015. | |
*/ | |
public class ElevationUtils { | |
public static void addTouchElevation(final View itemView) { | |
final int elevationDefault = (int) ViewCompat.getElevation(itemView); | |
if (elevationDefault > 0) { | |
final int elevationSelected = elevationDefault * 2; | |
itemView.setOnTouchListener(new View.OnTouchListener() { | |
@Override | |
public boolean onTouch(View v, MotionEvent event) { | |
if (event != null) { | |
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { | |
ViewCompat.setElevation(itemView, elevationSelected); | |
} else { | |
if (ViewCompat.getElevation(itemView) != elevationDefault) { | |
ViewCompat.setElevation(itemView, elevationDefault); | |
} | |
} | |
} | |
return false; | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment