当前位置:  编程技术>移动开发
本页文章导读:
    ▪[官方Demo]ScreenTransitionsDemo 银幕跳转        [官方Demo]ScreenTransitionsDemo 屏幕跳转 ScreenTransitionsDemo.java   /* * ScreenTransitionsDemo.java * * Copyright �1998-2010 Research In Motion Ltd. * * Note: For the sake of simplicity, this sample application may not leverage * res.........
    ▪ 稽查边缘及计算高度        检查边缘及计算高度 private boolean checkBounds(TextView v, MotionEvent event) {     // 全局视图最外层一个View (the View that holds the UI)     View globalView = ...; // the main view of activity/application     DisplayMetri.........
    ▪ 在程序中,打开google手机自带google 地图       在程序中,打开google手机自带google map Uri uri = Uri.parse("http://maps.google.com/maps?q=(%E6%A5%BC%E5%A4%96%E6%A5%BC)&z=21"); Intent intent = new Intent(Intent.ACTION_VIEW,uri); ComponentName comp = new ComponentName("com.google.andr.........

[1][官方Demo]ScreenTransitionsDemo 银幕跳转
    来源: 互联网  发布时间: 2014-02-18
[官方Demo]ScreenTransitionsDemo 屏幕跳转

ScreenTransitionsDemo.java

 

/*
 * ScreenTransitionsDemo.java
 *
 * Copyright �1998-2010 Research In Motion Ltd.
 * 
 * Note: For the sake of simplicity, this sample application may not leverage
 * resource bundles and resource strings.  However, it is STRONGLY recommended
 * that application developers make use of the localization features available
 * within the BlackBerry development platform to ensure a seamless application
 * experience across a variety of languages and geographies.  For more information
 * on localizing your application, please refer to the BlackBerry Java Development
 * Environment Development Guide associated with this release.
 */

package com.rim.samples.device.ui.screentransitionsdemo;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;


/**
 * A sample application to demonstrate the use of the TransitionContext class to 
 * create screen transitions.
 */
public final class ScreenTransitionsDemo extends UiApplication
{  
    private boolean _threadRunning;
    private boolean _pauseThread;
    private TransitionThread _tt;
    
    
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        ScreenTransitionsDemo app = new ScreenTransitionsDemo();
        app.enterEventDispatcher();                
    }


    /**
     * Creates a new ScreenTransitionsDemo object
     */
    public ScreenTransitionsDemo()
    {        
        pushScreen(new ScreenTransitionsDemoScreen());
    }
    
    
   /**
    * Pauses or resumes the screen transitions thread
    */
    public void startOrStopThread()
    {        
        if(_threadRunning == false)
        {            
            _tt = new TransitionThread();
            _tt.start();
            
            _threadRunning = true;
            
        }
        else
        {
            if(_pauseThread)
            {
                _pauseThread = false;                
            }
            else
            {
                _pauseThread = true;
            }                
        }            
    }
       

    /**
     * MainScreen class for the ScreenTransitionsDemo application 
     */
    final class ScreenTransitionsDemoScreen extends MainScreen 
    {
        /**
         * Creates a new ScreenTransitionsDemoScreen object
         */
        ScreenTransitionsDemoScreen()
        {            
            setTitle("Screen Transitions Demo");
            
            add(new LabelField("Click trackball or screen to start and stop animation", Field.NON_FOCUSABLE));               
        }        
        
        
       /**
        * @see Screen#invokeAction(int)
        */
        protected boolean invokeAction(int action)
        {
            switch( action )
            {
                case ACTION_INVOKE: 
                {
                    startOrStopThread();                
                    return true;
                }
            }
            return super.invokeAction(action);
        } 
        
       /**
        * @see Screen#TouchEvent(TouchEvent)
        */
        public boolean touchEvent(TouchEvent event)
        {
            if(event.getEvent() == TouchEvent.UNCLICK)
            {                
                invokeAction(ACTION_INVOKE);
                return true;                
            }
            return super.touchEvent(event);
        }            
    }   
    
    
    /**
     * A thread class to present a sequence of screen transitions
     */
    final class TransitionThread extends Thread
    {        
        public static final int SLIDE = 0;
        public static final int FADE = 1;    
        public static final int WIPE = 2;    
        public static final int ZOOM = 3;    
        
        boolean _pushed;      
        
        /**
         * Default constructor
         */
        TransitionThread()
        {            
        }
        
        
        /**
         * @see Runnable#run()
         */
        public void run()
        {       
            int type = 0;         
            
            while(true)
            {         
                while(_pauseThread)
                {
                    try
                    {
                        // Sleep so we don't spin
                        sleep(500);     
                    }
                    catch(InterruptedException e)
                    {                        
                    }
                }                
                
                if(!_pushed)
                {
                    // Push a screen to demonstrate a screen transition                    
                    push(type);
                    snooze();
                }
                if(!_pauseThread)
                {
                    pop();
                }
                
                // Set the transition type for the next iteration
                if(type == 3)
                {
                    type = 0;
                }
                else
                {
                    type ++;
                }                          
            }                              
        }
        
        
        /**
         * Removes a TransitionScreen from the stack
         */
        void pop()
        {        
            synchronized(UiApplication.getEventLock())
            {                    
                Screen activeScreen = getActiveScreen();                
                popScreen(activeScreen);     
                _pushed = false;                               
            }          
        }
        
        
        /**
         * Creates a TransitionContext object for both pushing and popping a
         * screen pushes a TransitionScreen onto the stack.
         * @param type Represents the type of screen transitions to execute
         */
        void push(int type)
        {                           
            TransitionScreen screen = null;
            TransitionContext transitionContextIn;
            TransitionContext transitionContextOut;
            UiEngineInstance engine = Ui.getUiEngineInstance();
            switch(type)
            {
                case SLIDE:                        
                    screen = new TransitionScreen("Slider", Color.BEIGE);   
                                     
                    transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_UP);              
                    
                    transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_SLIDE);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_DOWN);                                                            
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);                
                                                                                
                    engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                    engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
                    break;
                case FADE:
                    screen = new TransitionScreen("Fade", Color.TEAL);  
                                      
                    transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_FADE);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000); 
                    
                    transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_FADE);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);                    
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);   
                                       
                    engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                    engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
                    break;
                case WIPE:
                    screen = new TransitionScreen("Wipe", Color.LIGHTBLUE);   
                                     
                    transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_WIPE);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_LEFT);      
                                        
                    transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_WIPE);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION, TransitionContext.DIRECTION_RIGHT);  
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT);   
                                                      
                    engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                    engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
                    break;
                case ZOOM:
                    screen = new TransitionScreen("Zoom", Color.LIGHTGREEN);  
                                      
                    transitionContextIn = new TransitionContext(TransitionContext.TRANSITION_ZOOM);
                    transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION, 1000);                    
                    
                    transitionContextOut = new TransitionContext(TransitionContext.TRANSITION_ZOOM);
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION, 1000); 
                    transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND, TransitionContext.KIND_OUT); 
                    
                    engine.setTransition(null, screen, UiEngineInstance.TRIGGER_PUSH, transitionContextIn);
                    engine.setTransition(screen, null, UiEngineInstance.TRIGGER_POP, transitionContextOut);
                    break;
            }
            
            synchronized(UiApplication.getEventLock())
            {
                pushScreen(screen);    
                _pushed = true;                      
            }           
        }
        
        
       /**
        * Causes this thread to pause between transitions
        */
        private void snooze()
        {
            try
            {
                sleep(2000);
            }
            catch(Exception e)
            {
                System.out.println(e.toString());
            }
        }
    }
}

 

 

TransitionScreen.java

 

/*
 * TransitionScreen.java
 *
 * Copyright �1998-2010 Research In Motion Ltd.
 * 
 * Note: For the sake of simplicity, this sample application may not leverage
 * resource bundles and resource strings.  However, it is STRONGLY recommended
 * that application developers make use of the localization features available
 * within the BlackBerry development platform to ensure a seamless application
 * experience across a variety of languages and geographies.  For more information
 * on localizing your application, please refer to the BlackBerry Java Development
 * Environment Development Guide associated with this release.
 */

package com.rim.samples.device.ui.screentransitionsdemo;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;


/**
 * A screen to display a Bitmap in a BitmapField, used to demonstrate screen transitions
 */
public class TransitionScreen extends MainScreen
{   
    /**
     * Creates a new TransitionScreen object
     */
    public TransitionScreen(String title, int color)
    {        
        setTitle(title);
        VerticalFieldManager manager = (VerticalFieldManager)getMainManager();
        manager.setBackground(BackgroundFactory.createSolidBackground(color));                        
    } 
    
        
   /**
    * @see Screen#invokeAction(int)
    */
    protected boolean invokeAction(int action)
    {
        switch( action )
        {
            case ACTION_INVOKE: 
            {
                ScreenTransitionsDemo app = (ScreenTransitionsDemo)UiApplication.getUiApplication();
                app.startOrStopThread();
                return true;
            }
        }
        return super.invokeAction(action);
    }
    
    
   /**
    * @see Screen#TouchEvent(TouchEvent)
    */
    public boolean touchEvent(TouchEvent event)
    {
        if(event.getEvent() == TouchEvent.UNCLICK)
        {            
            invokeAction(ACTION_INVOKE);
            return true;
        }
        return super.touchEvent(event);
    } 
}

 \

 

 

 

 

 


    
[2] 稽查边缘及计算高度
    来源: 互联网  发布时间: 2014-02-18
检查边缘及计算高度

private boolean checkBounds(TextView v, MotionEvent event) { 
    // 全局视图最外层一个View (the View that holds the UI) 
    View globalView = ...; // the main view of activity/application 
    DisplayMetrics dm = new DisplayMetrics(); 
    this.getWindowManager().getDefaultDisplay().getMetrics(dm); 
    int topOffset = dm.heightPixels - globalView.getMeasuredHeight(); 
 
        int[] origin = new int[2]; 
        v.getLocationOnScreen(origin); 
 
    final int x = origin[0]; 
    final int y = origin[1] - topOffset; 
 
 
        if ((event.getX() > x) && (event.getX() < (x + v.getMeasuredWidth()))) { 
            if ((event.getY() > y) && (event.getY() < (y + v.getMeasuredHeight()))) { 
                return true; 
            } 
        } 
    return false; 

这个呢设计了计算notification高度


    
[3] 在程序中,打开google手机自带google 地图
    来源: 互联网  发布时间: 2014-02-18
在程序中,打开google手机自带google map
Uri uri = Uri.parse("http://maps.google.com/maps?q=(%E6%A5%BC%E5%A4%96%E6%A5%BC)&z=21");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
ComponentName comp = new ComponentName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
intent.setComponent(comp);
startActivity(intent);

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3