2012年12月4日星期二

macos eclipse 崩溃问题

我操,juno太卡了准备用indigo。用unarchiver解压的导致一进eclipse就崩溃,搞了半天了才知道是unarchiver的问题! 
tar zxvf eclipse-jee-indigo-SR2-macosx-cocoa-x86_64.tar.gz 

2012年11月2日星期五

phonegap-splashscreen

其实就是自定义一个启动页面,不顾完全可以不用这么做,MainActivity就可以充当启动页面来做,这个是官方的例子就顺便学习一下。同时这里也有延迟加载的例子。 

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Splashscreen Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  7.     <script type="text/javascript" charset="utf-8">  
  8.   
  9.     // Wait for Cordova to load  
  10.     //  
  11.     document.addEventListener("deviceready", onDeviceReady, false);  
  12.   
  13.     // Cordova is ready  
  14.     //  
  15.     function onDeviceReady() {  
  16.         //navigator.splashscreen.show();  
  17.         navigator.splashscreen.hide();  
  18.     }  
  19.   
  20.     </script>  
  21.   </head>  
  22.   <body>  
  23.     <h1>Example</h1>  
  24.   </body>  
  25. </html>  


  1. package com.fanfq.phonegap.splashscreen;  
  2.   
  3. import org.apache.cordova.DroidGap;  
  4.   
  5. import android.os.Bundle;  
  6.   
  7. public class MainActivity extends DroidGap {  
  8.     @Override  
  9.     public void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         // The first line 'super.setIntegerProperty' sets the image to be  
  12.         // displayed as the splashscreen. If you have named your image anything  
  13.         // other than splash.png you will have to modify this line. The second  
  14.         // line is the normal 'super.loadUrl' line but it has a second parameter  
  15.         // which is the timeout value for the splash screen. In this example the  
  16.         // splash screen will display for 10 seconds. If you want to dismiss the  
  17.         // splash screen once you get the "deviceready" event you should call  
  18.         // the navigator.splashscreen.hide() method.  
  19.         super.setIntegerProperty("splashscreen", R.drawable.splash);  
  20.         super.loadUrl("file:///android_asset/www/index.html"10000);  
  21.     }  
  22. }  

phonegap-event

监听各类事件,我用的是phonegap2.0.0的版本,越高级的版本支持功能就越多。 

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Event Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="jquery-1.8.1.min.js"></script>  
  7.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  8.     <script type="text/javascript" charset="utf-8">  
  9.   
  10.       
  11.     // Wait for Cordova to load  
  12.     // details plz see http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#Events  
  13.     document.addEventListener("deviceready", onDeviceReadyEvent, false);  
  14.     document.addEventListener("pasue", onPasueEvent, false);  
  15.     document.addEventListener("resume", onResumeEvent, false);  
  16.     document.addEventListener("online", onlineEvent, false);  
  17.     document.addEventListener("offline", offlineEvent, false);  
  18.     document.addEventListener("backbutton", onBackbuttonEvent, false);  
  19.     document.addEventListener("batterycritical", onBatterycriticalEvent, false);  
  20.     document.addEventListener("batterylow", onBatterylowEvent, false);  
  21.     document.addEventListener("batterystatus", onBatterystatusEvent, false);  
  22.     document.addEventListener("menubutton", onMenubuttonEvent, false);  
  23.     document.addEventListener("startcallbutton", onStartcallbuttonEvent, false);  
  24.     document.addEventListener("volumedownbutton", onVolumedownbuttonEvent, false);  
  25.     document.addEventListener("volumeupbutton", onVolumeupbuttonEvent, false);  
  26.   
  27.   
  28.     // Cordova is ready  
  29.     //  
  30.     function onDeviceReadyEvent() {  
  31.         $("#msg").append("==>onDeviceReadyEvent<p/>");  
  32.     }  
  33.       
  34.     function onPasueEvent() {  
  35.         $("#msg").append("==>onPasueEvent<p/>");  
  36.     }  
  37.       
  38.     function onResumeEvent() {  
  39.         $("#msg").append("==>onResumeEvent<p/>");  
  40.     }  
  41.       
  42.     function onlineEvent() {  
  43.         $("#msg").append("==>onlineEvent<p/>");  
  44.     }  
  45.       
  46.     function offlineEvent() {  
  47.         $("#msg").append("==>offlineEvent<p/>");  
  48.     }  
  49.       
  50.     function onBackbuttonEvent() {  
  51.         $("#msg").append("==>onBackbuttonEvent<p/>");  
  52.     }  
  53.       
  54.     function onBatterycriticalEvent() {  
  55.         $("#msg").append("==>onBatterycriticalEvent<p/>");  
  56.     }  
  57.       
  58.     function onBatterylowEvent() {  
  59.         $("#msg").append("==>onBatterylowEvent<p/>");  
  60.     }  
  61.       
  62.     function onBatterystatusEvent() {  
  63.         $("#msg").append("==>onBatterystatusEvent<p/>");  
  64.     }  
  65.       
  66.     function onMenubuttonEvent() {  
  67.         $("#msg").append("==>onMenubuttonEvent<p/>");  
  68.     }  
  69.       
  70.     function onStartcallbuttonEvent() {  
  71.         $("#msg").append("==>onStartcallbuttonEvent<p/>");  
  72.     }  
  73.       
  74.     function onVolumedownbuttonEvent() {  
  75.         $("#msg").append("==>onVolumedownbuttonEvent<p/>");  
  76.     }  
  77.       
  78.     function onVolumeupbuttonEvent() {  
  79.         $("#msg").append("==>onVolumeupbuttonEvent<p/>");  
  80.     }  
  81.   
  82.     </script>  
  83.   </head>  
  84.   <body>  
  85.     <h1>Event Example</h1>  
  86.     <div id="msg"></div>  
  87.   </body>  
  88. </html>  

2012年11月1日星期四

phonegap-notification

phonegap notification 的sample有点坑爹哇,与想象的有点差距其实就是个弹出对话框。 
如图: 
  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Notification Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  7.     <script type="text/javascript" charset="utf-8">  
  8.   
  9.     // Wait for Cordova to load  
  10.     //  
  11.     document.addEventListener("deviceready", onDeviceReady, false);  
  12.   
  13.     // Cordova is ready  
  14.     //  
  15.     function onDeviceReady() {  
  16.         // Empty  
  17.     }  
  18.   
  19.     // alert dialog dismissed  
  20.     function alertDismissed() {  
  21.         // do something  
  22.     }  
  23.   
  24.     // Show a custom alertDismissed  
  25.     //  
  26.     function showAlert() {  
  27.         navigator.notification.alert(  
  28.             'You are the winner!',  // message  
  29.             alertDismissed,         // callback  
  30.             'Game Over',            // title  
  31.             'Done'                  // buttonName  
  32.         );  
  33.     }  
  34.   
  35.     </script>  
  36.   </head>  
  37.   <body>  
  38.     <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>  
  39.   </body>  
  40. </html>  

2012年10月25日星期四

cocos2dx-helloworld

cocos2d就不多介绍了,下载地址 http://www.cocos2d-x.org/ 当前最高的版本是2.0.3支持了ios6的新特性。 

安装cocos2dx, 

fanfq-macbook:Downloads fanfangqing$ cd cocos2d-2.0-x-2.0.3 
fanfq-macbook:cocos2d-2.0-x-2.0.3 fanfangqing$ ls 
AUTHORS create-blackberry-project.vbs 
CHANGELOG document 
CocosDenshion extensions 
README.mdown external 
build-win32.bat install-templates-msvc.bat 
cocos2d-win32.vc2008.sln install-templates-xcode.sh 
cocos2d-win32.vc2010.sln licenses 
cocos2d-win32.vc2012.sln make-all-linux-project.sh 
cocos2dx samples 
create-android-project.bat scripting 
create-android-project.sh template 
create-blackberry-project.sh tools 
fanfq-macbook:cocos2d-2.0-x-2.0.3 fanfangqing$ sudo ./install-templates-xcode.sh 
Password: 
cocos2d-x template installer 



Installing Xcode 4 cocos2d-x iOS template 
---------------------------------------------------- 

...creating destination directory: /Users/fanfangqing/Library/Developer/Xcode/Templates/cocos2d-x/ 
...copying cocos2d files 
...copying CocosDenshion files 
...copying extension files 
...copying template files 
done! 



Installing Xcode 4 Chipmunk iOS template 
---------------------------------------------------- 

...copying Chipmunk files 
done! 



Installing Xcode 4 Box2d iOS template 
---------------------------------------------------- 

...copying Box2D files 
done! 

Hello World for IOS 

打开xocde创建新的工程,会发现左边多了一个cocos2dx的选项。 


创建一个HelloCocos2d工程,run