Posts

Android程式設計-畫面的切換(1)

Image
實務來說 ,Android程式會有數個畫面,每個畫面都是一個使用情境,透過Google找相關程式的 撰寫方法,大致上都得到一個方向:透過多個Activities, 以Intent方法來切換不同的Activity。 這種做法基本上是可行的, 只是使用此種方法切換Activity進而造成畫面切換時,可以觀察到畫面切換的過程中有一個非常明顯的停頓, 很 不自然。 依照我所使用的App經驗來看,我看到的畫面切換都非常的平順,加上不同activities間的參數傳遞也是一個頭痛的問題。因此之故,我開始 針對Android的畫面切換上窮碧落下黃泉式地找出心中所想要的畫面切換方式,做法如下: 圖 1. 第一個畫面 圖2. 第二個畫面  做法的關鍵是我們不再使用setContentView(R.id.layout.activity_main)來帶出畫面,程式的作法是用LayoutInflater來 挖出畫面中的View,做法如下:          final  View view1 = inflater.inflate(R.layout. activity_main ,  null ); //找出第一個視窗          final  View view2 = inflater.inflate(R.layout. main2 ,  null ); //找出第二個視窗 這2行程式把二個畫面的View分別找出來,一旦有 了View物件,setContentView的 另一個多載形式找入View物件被用上來:  setContentView(view1);  //顯示第一個視窗 由於畫面的元件分佈在不同的View裏,因此,要抓取在不同View裏的物件方法如下:  Button button1 = (Button) view1.findViewById(R.id. button1 ); //找出View1中的按鈕  Button button2 = (Button) view2.findViewById(R.id...

VMWare ESXi 5安裝Apple Mac OSX(山獅)

Image
最近產生了一個想法,如果學生想學Apple的iOS 程式設計該怎麼辦?買Mac嗎?金主呢?用虛擬機器是一個 好想法,在這 樣的想法支持下開始了實現的過程: 上VMware網站下載ESXi 5(免費,會給授權CODE),完成安裝ESXi 5。 下載並安裝ESXi 5 Mac OS X Unlocker http://www.insanelymac.com/forum/topic/267296-esxi-5-mac-os-x-unlocker/#entry1745191 安裝Mountain Lion,價格 590元,很佛心來的,http://www.apple.com/tw/osx/。 細節… Mac OSX Mountain Lion in VMware ESXi 5 box: 以下是使用Real VNC Viewer連線的畫面,使用此方式可允許多人同時登入Mac OSX,這對一些沒有Mac硬 體的人是一個很好的解決方案,我預計讓學生使用此方式來體驗XCode, 學習開發Apple iOS的應用程式。 一開始映入眼簾的是登入畫面: 登入: 夢幻畫面出現: 註:裝虛擬機器的硬體等級要高一些,核心數要多,記憶體要多,硬碟最好是固態硬碟 ,參考Apple的Mac Pro,呼~~,可以買一台重機了。

Mac OS Snow leopard(雪豹)升級到Mountain Lion(山獅)過程

先將Snow leopard升級到10.6.8,做法是下載升級包並安裝,升級包網址 http://support.apple.com/kb/DL1399 安裝山獅,AppStore 購買或從其他來源獲得。 

Google地圖標註與自訂圖示標註

Image
(前言 待補) 自訂標示圖案 改二個地方: 1.Map.html <script>    var m1 = new google.maps.LatLng(24.1564125, 120.6779761); //台中市北區英才路102巷61號    var m2 = new google.maps.LatLng(24.1564069, 120.676978); //台中市北區大雅路100號    var marker;    var map;    var image = 'taxi-icon.png';//image變數指向計程車圖示檔案,圖示檔案請放在相同目錄      function mark(lat, log){//標註座標函式,由C#端呼叫,傳進經度與緯度…        var m = new google.maps.LatLng(lat, log);        marker = new google.maps.Marker({          map:map, draggable:true,          position: m,          icon: image //指定標示圖案為image        }); 2.在目錄中放入圖案檔(用GOOGLE找可用的圖片檔) 參考資料: https://developers.google.com/maps/documentation/javascript/overlays#Markers [C#端程式碼] public Form1(){   InitializeComponent();   if (File.Exists(AppDomain.CurrentDomain.BaseDirectory +...

SCJP題庫第244題

Given: 1. public class TestSeven extends Thread{ 2.   private static int x; 3.   public synchronized void doThings(){ 4.     int current = x; 5.     current++; 6.     x = current; 7.   } 8.   public void run(){ 9.     doThings(); 10. } 11.} Which statement is true? A. Compilation fails. B. An exception is thrown at runtime. C. Synchronizing the run() method would make the class thread-safe. D. The data in variable "x" are protected from concurrent access problems. E. Declaring the doThings() method as static would make the class thread-safe. F. Wrapping the statements within doThings() in a synchronized(new Object()){} block would make the class thread-safe. Ans: E 解說 : E是說若宣告doThings方法為靜態的方法將使得該類別為"執行緒安全"。 thread-safe是說不管執行緒如何執行,都不會破壞掉類別資料完整性。 若方法是物件的成員,則多個執行緒就可以執行多個版本的 doThings方法,好像多人一起操作一個共同的整數資料x(因為x是靜態的/類別的,只有一...

SCJP題庫第243題

  Given that Triangle implements Runnable, and:   31. void go() throws Exception{ 32.     Thread t = new Thread(new Triangle()); 33.     t.start(); 34.     for(int x=1; x<100000; x++){ 35.      //insert code here 36.     if(x%100 == 0) System.out.print("g"); 37. }} 38. public void run(){ 39.   try{ 40.     for(int x=1; x<100000; x++){ 41.       //insert the same code here 42.        if(x%100 == 0) System.out.print("t"); 43.     } 44. }catch(Exception e){} 45.} Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.) A. Thread.wait(); B. Thread.join(); C. Thread.yield(); D. Thread.sleep(1); E. Thread.notify(); Ans: CD 解說:在第35行和41行插入...

SCJP題庫第242題

  Given: public class NamedCounter{    private final String name;    private int count;    public NamedCounter(String name){this.name = name;}    public String getName(){return name;}    public void increment(){count++;}    public int getCount(){return count;}    public void reset(){count = 0;} }     Which three changes should be made to adapt this class to be used safely by multiple threads? (Choose three.) A. declare reset() using the synchronized keyword B. declare getName() using the synchronized keyword C. declare getCount() using the synchronized keyword D. declare the constructor using the synchronized keyword E. declare increment() using the synchronized keyword Ans: ACE 解說 : 題目問那三個改變應該被做出來,以調整這個類別可以在多執行緒的環境上被安全地使用? 多執行緒使用類別中的變數若有變更的情況,應該對所有這個變數的存取(讀或寫)方法以同步的方式設定。 此題count在reset與increment方法有被變更值的情況,因此連同getCount這三個方法都要變成同步的方法。