Reduce sensitivity of the channel gallery view.

Higher scroll speeds are reduced stronger.
This commit is contained in:
Thomas Martitz 2011-03-04 21:26:49 +01:00 committed by Sebastian Kaspari
parent 7120bb48ea
commit db91a85676
2 changed files with 26 additions and 1 deletions

View File

@ -48,7 +48,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Gallery
<org.yaaic.model.ChannelList
android:id="@+id/deck"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

View File

@ -0,0 +1,25 @@
package org.yaaic.model;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Gallery;
public class ChannelList extends Gallery
{
public ChannelList(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
/* Reduce sensitivity based on f(x) = x * 0.925^y with y = (|x/500| - 1)
* The goal is to reduce higher velocities stronger than low ones
* 500 is the base, i.e. it will not reduced. */
final float fexp = Math.abs(velocityX / 500.0f) - 1;
velocityX *= Math.pow(0.925, fexp);
return super.onFling(e1, e2, velocityX, velocityY);
}
}