2014-04-02 81 views

回答

1

目前沒有內置的解決方案,這有點讓人失望。希望下次更新時,他們會添加一些應該始終存在於GDK中的基本功能。

https://github.com/pif/glass-progress-bar

這個庫是非常功能齊全,讓你做你想要的一切。

+0

感謝勝利者,這看起來像現在一個很不錯的選擇。但我希望下一次GDK更新將包含此功能:) –

1

像下面這樣的東西應該做到這一點:

public static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); 
private Integer pendingAction; 
private Boolean isActionPending = false; 
private final Long TIMEOUT = 2000; //2 seconds 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    if (isActionPending) { 
     //TODO: better error handling 
     return false; 
    } 
    isActionPending = true; 
    pendingAction = item.getItemId(); 
    new Thread(new Runnable() { 
      @Override 
      public void run() { 
       Thread.sleep(TIMEOUT); 
       MAIN_HANDLER.post(
        new Runnable() { 
        @Override 
        public void run() { 
         onDoPendingAction();          
        } 
        } 
       ); 
       } 
}).start(); 

} 
public void onDoPendingAction() { 
    if (!isPending) { 
    return; //event was canceled 
    } 
    switch(pendingAction) { 
    case R.id.some_menu_action: 
     //Whatever you would do. 
     break; 
    /* other actions */ 
    } 
    //TODO: something to indicate teh action finished. 
} 
public void cancelPendingAction() { 
    if (isPending) { 
    isPending = false; 
    //TODO: something to indicate it canceled. 
    } 
} 

添加姿態探測器捕捉TWO_SWIPE_DOWN事件並調用cancelPendingAction();如果你發現它。在這裏獲取手勢檢測代碼。

https://developers.google.com/glass/develop/gdk/input/touch

+0

Thanku的回覆,但我想要的完整功能。你提供的代碼工作,但它的底部缺少進度指示器,我也希望有一個簡單的解決方案。像這樣實施寬限期有點像過度殺傷力的權利? :) –