/[svn]/jsampler/trunk/src/org/jsampler/android/AHF.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/android/AHF.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (hide annotations) (download)
Thu Dec 15 23:13:30 2011 UTC (12 years, 4 months ago) by iliev
File size: 3975 byte(s)
* Initial support for Android platforms (only sampler channel
  manipulation for now - see the screenshots on the website)

1 iliev 2302 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2011 Grigor Iliev <grigor@grigoriliev.com>
5     *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.android;
24    
25     import org.jsampler.CC;
26     import org.jsampler.android.view.AndroidMainFrame;
27    
28     import android.view.MotionEvent;
29     import android.view.animation.AccelerateInterpolator;
30     import android.view.animation.Animation;
31     import android.view.animation.TranslateAnimation;
32    
33     /**
34     * This class contains some android helper function.
35     * @author Grigor Iliev
36     */
37     public class AHF {
38     private static JSamplerActivity activity = null;
39    
40     public static JSamplerActivity
41     getActivity() { return activity; }
42    
43     public static AndroidMainFrame
44     getMainFrame() { return (AndroidMainFrame)CC.getMainFrame(); }
45    
46     public static void
47     setActivity(JSamplerActivity activity) { AHF.activity = activity; }
48    
49     public static Animation
50     inFromRightAnimation() {
51     Animation inFromRight = new TranslateAnimation (
52     Animation.RELATIVE_TO_PARENT, 1.0f,
53     Animation.RELATIVE_TO_PARENT, 0.0f,
54     Animation.RELATIVE_TO_PARENT, 0.0f,
55     Animation.RELATIVE_TO_PARENT, 0.0f
56     );
57     inFromRight.setDuration(400);
58     inFromRight.setInterpolator(new AccelerateInterpolator());
59     return inFromRight;
60     }
61    
62     public static Animation
63     outToLeftAnimation() {
64     Animation outToLeft = new TranslateAnimation (
65     Animation.RELATIVE_TO_PARENT, 0.0f,
66     Animation.RELATIVE_TO_PARENT, -1.0f,
67     Animation.RELATIVE_TO_PARENT, 0.0f,
68     Animation.RELATIVE_TO_PARENT, 0.0f
69     );
70     outToLeft.setDuration(400);
71     outToLeft.setInterpolator(new AccelerateInterpolator());
72     return outToLeft;
73     }
74    
75     public static Animation
76     inFromLeftAnimation() {
77     Animation inFromLeft = new TranslateAnimation (
78     Animation.RELATIVE_TO_PARENT, -1.0f,
79     Animation.RELATIVE_TO_PARENT, 0.0f,
80     Animation.RELATIVE_TO_PARENT, 0.0f,
81     Animation.RELATIVE_TO_PARENT, 0.0f
82     );
83     inFromLeft.setDuration(400);
84     inFromLeft.setInterpolator(new AccelerateInterpolator());
85     return inFromLeft;
86     }
87    
88     public static Animation
89     outToRightAnimation() {
90     Animation outToRight = new TranslateAnimation (
91     Animation.RELATIVE_TO_PARENT, 0.0f,
92     Animation.RELATIVE_TO_PARENT, 1.0f,
93     Animation.RELATIVE_TO_PARENT, 0.0f,
94     Animation.RELATIVE_TO_PARENT, 0.0f
95     );
96     outToRight.setDuration(400);
97     outToRight.setInterpolator(new AccelerateInterpolator());
98     return outToRight;
99     }
100    
101     public static boolean
102     isMotionHorizontal(MotionEvent e1, MotionEvent e2) {
103     return Math.abs(e1.getX() - e2.getX()) > Math.abs(e1.getY() - e2.getY());
104     }
105    
106     public static boolean
107     isMotionVertical(MotionEvent e1, MotionEvent e2) {
108     return Math.abs(e1.getX() - e2.getX()) < Math.abs(e1.getY() - e2.getY());
109     }
110    
111     public static boolean
112     isMotionLeftToRight(MotionEvent e1, MotionEvent e2, int min) {
113     return isMotionHorizontal(e1, e2) && e2.getX() - e1.getX() > min;
114     }
115    
116     public static boolean
117     isMotionRightToLeft(MotionEvent e1, MotionEvent e2, int min) {
118     return isMotionHorizontal(e1, e2) && e1.getX() - e2.getX() > min;
119     }
120    
121     public static boolean
122     isMotionUp(MotionEvent e1, MotionEvent e2, int min) {
123     return isMotionVertical(e1, e2) && e1.getY() - e2.getY() > min;
124     }
125    
126     public static boolean
127     isMotionDown(MotionEvent e1, MotionEvent e2, int min) {
128     return isMotionVertical(e1, e2) && e2.getY() - e1.getY() > min;
129     }
130     }

  ViewVC Help
Powered by ViewVC