当前位置: 首页>>代码示例>>Java>>正文


Java Animation类代码示例

本文整理汇总了Java中com.codename1.ui.animations.Animation的典型用法代码示例。如果您正苦于以下问题:Java Animation类的具体用法?Java Animation怎么用?Java Animation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Animation类属于com.codename1.ui.animations包,在下文中一共展示了Animation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeSplash

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
protected void beforeSplash(Form f) {
    // If the resource file changes the names of components this call will break notifying you that you should fix the code
    super.beforeSplash(f);
    final List l = findCarosel(f);
    f.registerAnimated(new Animation() {
        private long lastTime = System.currentTimeMillis();
        public boolean animate() {
            long t = System.currentTimeMillis();
            if(t - lastTime >= 200) {
                int i = l.getSelectedIndex();
                i++;
                if(i >= l.getModel().getSize()) {
                    i = 0;
                }
                l.setSelectedIndex(i);
                lastTime = t;
            }
            return false;
        }

        public void paint(Graphics g) {
        }
    });
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:25,代码来源:StateMachine.java

示例2: getCurrent

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Return the form currently displayed on the screen or null if no form is
 * currently displayed.
 *
 * @return the form currently displayed on the screen or null if no form is
 * currently displayed
 */
public Form getCurrent(){
    Form current = impl.getCurrentForm();
    if(current != null && current instanceof Dialog) {
        if(((Dialog)current).isMenu() || ((Dialog)current).isDisposed()) {
            Form p = current.getPreviousForm();
            if(p != null) {
                return p;
            }

            // we are in the middle of a transition so we should extract the next form
            if(animationQueue != null) {
                int size = animationQueue.size();
                for(int iter = 0 ; iter < size ; iter++) {
                    Animation o = animationQueue.get(iter);
                    if(o instanceof Transition) {
                        return (Form)((Transition)o).getDestination();
                    }
                }
            }
        }
    }
    return current;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:31,代码来源:Display.java

示例3: repaint

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Invoked to add an element to the paintQueue
 * 
 * @param cmp component or animation to push into the paint queue
 */
public void repaint(Animation cmp) {
    synchronized (displayLock) {
        for (int iter = 0; iter < paintQueueFill; iter++) {
            Animation ani = paintQueue[iter];
            if (ani == cmp) {
                return;
            }
        }
        // overcrowding the queue don't try to grow the array!
        if (paintQueueFill >= paintQueue.length) {
            System.out.println("Warning paint queue size exceeded, please watch the amount of repaint calls");
            return;
        }

        paintQueue[paintQueueFill] = cmp;
        paintQueueFill++;
        displayLock.notify();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:CodenameOneImplementation.java

示例4: registerAnimated

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * The given component is interested in animating its appearance and will start
 * receiving callbacks when it is visible in the form allowing it to animate
 * its appearance. This method would not register a compnent instance more than once
 * 
 * @param cmp component that would be animated
 */
public void registerAnimated(Animation cmp) {
    if (animatableComponents == null) {
        animatableComponents = new ArrayList<Animation>();
    }
    if (!animatableComponents.contains(cmp)) {
        animatableComponents.add(cmp);
    }
    Display.getInstance().notifyDisplay();
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:Form.java

示例5: registerAnimatedInternal

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Identical to the none-internal version, the difference between the internal/none-internal
 * is that it references a different vector that is unaffected by the user actions.
 * That is why we can dynamically register/deregister without interfering with user interaction.
 */
void registerAnimatedInternal(Animation cmp) {
    if (internalAnimatableComponents == null) {
        internalAnimatableComponents = new ArrayList<Animation>();
    }
    if (!internalAnimatableComponents.contains(cmp)) {
        internalAnimatableComponents.add(cmp);
    }
    Display.getInstance().notifyDisplay();
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:15,代码来源:Form.java

示例6: loopAnimations

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
private void loopAnimations(ArrayList<Animation> v, ArrayList<Animation> notIn) {
    // we don't save size() in a varible since the animate method may deregister
    // the animation thus invalidating the size
    for (int iter = 0; iter < v.size(); iter++) {
        Animation c = (Animation) v.get(iter);
        if (c == null || notIn != null && notIn.contains(c)) {
            continue;
        }
        if (c.animate()) {
            if (c instanceof Component) {
                Rectangle rect = ((Component) c).getDirtyRegion();
                if (rect != null) {
                    Dimension d = rect.getSize();

                    // this probably can't happen but we got a really weird partial stack trace to this
                    // method and this check doesn't hurt
                    if (d != null) {
                        ((Component) c).repaint(rect.getX(), rect.getY(), d.getWidth(), d.getHeight());
                    }
                } else {
                    ((Component) c).repaint();
                }
            } else {
                Display.getInstance().repaint(c);
            }
        }
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:29,代码来源:Form.java

示例7: getCurrentUpcomingForm

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
private Form getCurrentUpcomingForm(boolean includeMenus) {
    Form upcoming = null;

    // we are in the middle of a transition so we should extract the next form
    if(animationQueue != null) {
        int size = animationQueue.size();
        for(int iter = 0 ; iter < size ; iter++) {
            Animation o = animationQueue.get(iter);
            if(o instanceof Transition) {
                upcoming = (Form)((Transition)o).getDestination();
            }
        }
    }
    if(upcoming == null) {
        if(includeMenus){
            Form f = impl.getCurrentForm();
            if(f instanceof Dialog) {
                if(((Dialog)f).isDisposed()) {
                    return getCurrent();
                }
            }
            return f;
        }else{
            return getCurrent();
        }
    }
    return upcoming;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:29,代码来源:Display.java

示例8: cancelRepaint

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Removes an entry from the paint queue if it exists, this is important for cases
 * in which a component was repainted and immediately removed from its parent container
 * afterwards. This happens sometimes in cases where a replace() operation changes 
 * a component to a new component that has an animation() the animation might have triggered
 * a repaint before the removeComponent method was invoked
 * 
 * @param cmp the component to 
 */
public void cancelRepaint(Animation cmp) {
    synchronized (displayLock) {
        for (int iter = 0; iter < paintQueueFill; iter++) {
            if (paintQueue[iter] == cmp) {
                paintQueue[iter] = null;
                return;
            }
        }

    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:21,代码来源:CodenameOneImplementation.java

示例9: repaint

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Invoked to add an element to the paintQueue
 * 
 * @param cmp component or animation to push into the paint queue
 */
public void repaint(Animation cmp) {
    synchronized (displayLock) {
        for (int iter = 0; iter < paintQueueFill; iter++) {
            Animation ani = paintQueue[iter];
            if (ani == cmp) {
                return;
            }
            //no need to paint a Component if one of its parent is already in the queue
            if(ani instanceof Container && cmp instanceof Component){
                Component parent = ((Component)cmp).getParent();
                while (parent != null) {
                    if (parent == ani) {
                        return;
                    }
                    parent = parent.getParent();
                }
            }
        }
        // overcrowding the queue don't try to grow the array!
        if (paintQueueFill >= paintQueue.length) {
            System.out.println("Warning paint queue size exceeded, please watch the amount of repaint calls");
            return;
        }

        paintQueue[paintQueueFill] = cmp;
        paintQueueFill++;
        displayLock.notify();
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:35,代码来源:CodenameOneImplementation.java

示例10: animateTo

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
private void animateTo(final boolean value, final int position) {
    int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
    if(Display.getInstance().getDisplayWidth() > 480) {
        // is retina
        switchButtonPadInt *= 2;
    }
    final Motion current = Motion.createEaseInOutMotion(Math.abs(position), switchMaskImage.getWidth() - 2*switchButtonPadInt, 100);
    current.start();
    deltaX = position;
    getComponentForm().registerAnimated(new Animation() {
        public boolean animate() {
            deltaX = current.getValue();
            if(value) {
                deltaX *= -1;
            }
            dragged = true;
            if(current.isFinished()) {
                dragged = false;
                Form f = getComponentForm();
                if(f != null) {
                    f.deregisterAnimated(this);
                }
                OnOffSwitch.this.setValue(value);
            }
            repaint();
            return false;
        }

        public void paint(Graphics g) {
        }
    });
    dragged = true;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:34,代码来源:OnOffSwitch.java

示例11: execute

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Executes the chart demo.
 * @param context the context
 * @return the built intent
 */
public Form execute() {
  String[] titles = new String[] { "sin", "cos" };
  List<double[]> x = new ArrayList<double[]>();
  List<double[]> values = new ArrayList<double[]>();
  int step = 4;
  int count = 360 / step + 1;
  x.add(new double[count]);
  x.add(new double[count]);
  double[] sinValues = new double[count];
  double[] cosValues = new double[count];
  values.add(sinValues);
  values.add(cosValues);
  for (int i = 0; i < count; i++) {
    int angle = i * step;
    x.get(0)[i] = angle;
    x.get(1)[i] = angle;
    double rAngle = Math.toRadians(angle);
    sinValues[i] = Math.sin(rAngle);
    cosValues[i] = Math.cos(rAngle);
  }
  int [] colors = new int[] { ColorUtil.BLUE, ColorUtil.CYAN };
  PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT };
  final XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
  setChartSettings(renderer, "Trigonometric functions", "X (in degrees)", "Y", 0, 360, -1, 1,
      ColorUtil.GRAY, ColorUtil.LTGRAY);
  
  int strWidth = smallFont.stringWidth("360") / 2;
  int numXLabels = Display.getInstance().getDisplayWidth() / (strWidth + 20);
  renderer.setXLabels(numXLabels);
  renderer.setYLabels(10);
  renderer.setXAxisMin(0);
  renderer.setXAxisMax(50);
  
  final Motion m = Motion.createLinearMotion(0, 310, 10000);
  
  
  final LineChart chart = new LineChart(buildDataset(titles, x, values), renderer);
  final ChartComponent cmp = new ChartComponent(chart);
  Form out = wrap("", cmp);
  out.registerAnimated(new Animation() {

      public boolean animate() {
          if (m.isFinished()) {
              return false;
          } else {
              renderer.setXAxisMin(m.getValue());
              renderer.setXAxisMax(m.getValue()+50);
              cmp.repaint();
              return true;
          }
      }

      public void paint(Graphics g) {
          
      }
      
  });
  m.start();
  return out;
  
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:67,代码来源:TrigonometricFunctionsChart.java

示例12: deregisterAnimatedInternal

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Identical to the none-internal version, the difference between the internal/none-internal
 * is that it references a different vector that is unaffected by the user actions.
 * That is why we can dynamically register/deregister without interfearing with user interaction.
 */
void deregisterAnimatedInternal(Animation cmp) {
    if (internalAnimatableComponents != null) {
        internalAnimatableComponents.remove(cmp);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:11,代码来源:Form.java

示例13: deregisterAnimated

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Indicate that cmp would no longer like to receive animation events
 * 
 * @param cmp component that would no longer receive animation events
 */
public void deregisterAnimated(Animation cmp) {
    if (animatableComponents != null) {
        animatableComponents.remove(cmp);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:11,代码来源:Form.java

示例14: paintDirty

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Invoked by the EDT to paint the dirty regions
 */
public void paintDirty() {
    int size = 0;
    synchronized (displayLock) {
        size = paintQueueFill;
        Animation[] array = paintQueue;
        paintQueue = paintQueueTemp;
        paintQueueTemp = array;
        paintQueueFill = 0;
    }
    if (size > 0) {
        Graphics wrapper = getCodenameOneGraphics();
        int dwidth = getDisplayWidth();
        int dheight = getDisplayHeight();
        int topX = dwidth;
        int topY = dheight;
        int bottomX = 0;
        int bottomY = 0;
        for (int iter = 0; iter < size; iter++) {
            Animation ani = paintQueueTemp[iter];
            
            // might happen due to paint queue removal
            if(ani == null) {
                continue;
            }
            paintQueueTemp[iter] = null;
            wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());
            wrapper.setClip(0, 0, dwidth, dheight);
            if (ani instanceof Component) {
                Component cmp = (Component) ani;
                Rectangle dirty = cmp.getDirtyRegion();
                if (dirty != null) {
                    Dimension d = dirty.getSize();
                    wrapper.setClip(dirty.getX(), dirty.getY(), d.getWidth(), d.getHeight());
                    cmp.setDirtyRegion(null);
                }

                cmp.paintComponent(wrapper);
                getPaintableBounds(cmp, paintDirtyTmpRect);
                int cmpAbsX = paintDirtyTmpRect.getX();
                topX = Math.min(cmpAbsX, topX);
                bottomX = Math.max(cmpAbsX + paintDirtyTmpRect.getWidth(), bottomX);
                int cmpAbsY = paintDirtyTmpRect.getY();
                topY = Math.min(cmpAbsY, topY);
                bottomY = Math.max(cmpAbsY + paintDirtyTmpRect.getHeight(), bottomY);
            } else {
                bottomX = dwidth;
                bottomY = dheight;
                topX = 0;
                topY = 0;
                ani.paint(wrapper);
            }
        }

        paintOverlay(wrapper);
        //Log.p("Flushing graphics : "+topX+","+topY+","+bottomX+","+bottomY);
        flushGraphics(topX, topY, bottomX - topX, bottomY - topY);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:62,代码来源:CodenameOneImplementation.java

示例15: paintDirty

import com.codename1.ui.animations.Animation; //导入依赖的package包/类
/**
 * Invoked by the EDT to paint the dirty regions
 */
public void paintDirty() {
    int size = 0;
    synchronized (displayLock) {
        size = paintQueueFill;
        Animation[] array = paintQueue;
        paintQueue = paintQueueTemp;
        paintQueueTemp = array;
        paintQueueFill = 0;
    }
    if (size > 0) {
        Graphics wrapper = getCodenameOneGraphics();
        int dwidth = getDisplayWidth();
        int dheight = getDisplayHeight();
        int topX = dwidth;
        int topY = dheight;
        int bottomX = 0;
        int bottomY = 0;
        for (int iter = 0; iter < size; iter++) {
            Animation ani = paintQueueTemp[iter];
            
            // might happen due to paint queue removal
            if(ani == null) {
                continue;
            }
            paintQueueTemp[iter] = null;
            wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());
            wrapper.setClip(0, 0, dwidth, dheight);
            if (ani instanceof Component) {
                Component cmp = (Component) ani;
                Rectangle dirty = cmp.getDirtyRegion();
                if (dirty != null) {
                    Dimension d = dirty.getSize();
                    wrapper.setClip(dirty.getX(), dirty.getY(), d.getWidth(), d.getHeight());
                    cmp.setDirtyRegion(null);
                }

                cmp.paintComponent(wrapper);
                int cmpAbsX = cmp.getAbsoluteX() + cmp.getScrollX();
                topX = Math.min(cmpAbsX, topX);
                bottomX = Math.max(cmpAbsX + cmp.getWidth(), bottomX);
                int cmpAbsY = cmp.getAbsoluteY() + cmp.getScrollY();
                topY = Math.min(cmpAbsY, topY);
                bottomY = Math.max(cmpAbsY + cmp.getHeight(), bottomY);
            } else {
                bottomX = dwidth;
                bottomY = dheight;
                topX = 0;
                topY = 0;
                ani.paint(wrapper);
            }
        }

        paintOverlay(wrapper);
        Log.p("Flushing graphics : "+topX+","+topY+","+bottomX+","+bottomY);
        flushGraphics(topX, topY, bottomX - topX, bottomY - topY);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:61,代码来源:CodenameOneImplementation.java


注:本文中的com.codename1.ui.animations.Animation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。