2014-04-02 3 views
0

StandOutWindow 라이브러리를 사용하고 있습니다. 설정 화면에서 스위치가 켜져 있습니다 (켜기/끄기). 스위치를 켜면 팝업과 알림이 표시됩니다. 스위치를 끄면 팝업이 표시되지 않습니다. 알림을 클릭하면 팝업이 숨겨지고 스위치가 "꺼짐"상태가됩니다. 이제 팝업 만 숨겨집니다. 스위치는 또한 "ON"상태입니다. 스위치를 끌 수있는 방법. getPersistentNotificationIntent에 코드를 쓰려고했지만 시도 할 수 없습니다.StandOutWindow android에서 이벤트 닫기 알림을 받습니까?

public class TogglePopup extends StandOutWindow { 
    public View view; 

    @Override 
    public String getAppName() { 
     return "JSDict"; 
    } 

    @Override 
    public int getAppIcon() { 
     return android.R.drawable.ic_menu_close_clear_cancel; 
    } 

    @SuppressLint("NewApi") 
    @Override 
    public void createAndAttachView(int id, final FrameLayout frame) { 
     // create a new layout from body.xml 
     final LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 
     view = inflater.inflate(R.layout.popup_toggle, frame, true); 
     ToggleButton toggle = (ToggleButton) view 
       .findViewById(R.id.toggle_popup); 
     toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      public void onCheckedChanged(CompoundButton buttonView, 
        boolean isChecked) { 

       LinearLayout viewLinear = (LinearLayout) view 
         .findViewById(R.id.toggle_popup_background); 

       if (isChecked) { 
        // The toggle is enabled 
        viewLinear 
          .setBackgroundResource(R.drawable.popup_toggle_on); 

        ComponentName service = getApplicationContext() 
          .startService(
            new Intent(getApplicationContext(), 
              ClipboardMonitor.class)); 
        StandOutWindow.closeAll(getApplicationContext(), 
          ClipboardMonitor.class); 
        StandOutWindow.show(getApplicationContext(), 
          ClipboardMonitor.class, StandOutWindow.DEFAULT_ID); 
       } else { 
        // The toggle is disabled 
        viewLinear 
          .setBackgroundResource(R.drawable.popup_toggle_off); 

        getApplicationContext().stopService(
          new Intent(getApplicationContext(), 
            ClipboardMonitor.class)); 
        StandOutWindow.closeAll(getApplicationContext(), 
          ClipboardMonitor.class); 
       } 
      } 
     }); 
    } 

    // the window will be centered 
    @Override 
    public StandOutLayoutParams getParams(int id, Window window) { 
     return new StandOutLayoutParams(id, 250, 300, 
       StandOutLayoutParams.CENTER, StandOutLayoutParams.CENTER); 
    } 

    // move the window by dragging the view 
    @Override 
    public int getFlags(int id) { 
     return super.getFlags(id) | StandOutFlags.FLAG_BODY_MOVE_ENABLE 
       | StandOutFlags.FLAG_WINDOW_FOCUSABLE_DISABLE; 
    } 

    @Override 
    public String getPersistentNotificationMessage(int id) { 
     return "Click to close the JSDict"; 
    } 

    @Override 
    public Intent getPersistentNotificationIntent(int id) { 
     return StandOutWindow.getCloseIntent(this, TogglePopup.class, id); 
     /* 
     * StandOutWindow.show(this, WidgetsWindow.class, 
     * StandOutWindow.DEFAULT_ID); 
     */ 
    } 

} 

답변

0

뛰어난 서비스를위한 하나의 지속적인 알림이있을 필요가있다, 또는 다른 안드로이드가 (5 초마다 발생) 메모리 부족에 대한 서비스를 죽일 것이다 : 다음은 내 코드입니다. 각각의 새 창에 대해 새로운 영구 통지가 있다는 사실에 착각합니다. 여러 유형이없는 한 사용자가 열리는 창의 수에 관계없이 하나의 영구 통지 만 받게됩니다. 여러 유형이 문제인 경우 단일 서비스에서 여러 유형을 구현하는 방법에 대해서는 FloatingFolders를 살펴보십시오.