/*
* Calendula - An assistant for personal medication management.
* Copyright (C) 2016 CITIUS - USC
*
* Calendula is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
package es.usc.citius.servando.calendula.util.view;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ImageView;
public class ParallaxImageView extends ImageView {
private int mCurrentTranslation;
public ParallaxImageView(Context context) {
super(context);
}
public ParallaxImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ParallaxImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void updateParallax(){
int[] ls = new int[2];
getLocationOnScreen(ls);
float top = (float)ls[1];
if(top > 0) {
mCurrentTranslation = -(int)(top*1.5);
invalidate();
}
}
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.translate(0, mCurrentTranslation);
super.draw(canvas);
canvas.restore();
}
}