public void setupListener() {
   final ViewTreeObserver viewTreeObserver = mView.getViewTreeObserver();
   if (viewTreeObserver != null) {
     viewTreeObserver.addOnGlobalLayoutListener(this);
     viewTreeObserver.addOnGlobalFocusChangeListener(this);
     viewTreeObserver.addOnPreDrawListener(this);
     viewTreeObserver.addOnScrollChangedListener(this);
     viewTreeObserver.addOnTouchModeChangeListener(this);
   }
 }
コード例 #2
0
 private void registerListener(View anchor) {
   if (mSuperScrollListener != null) {
     ViewTreeObserver vto =
         (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
     if (vto != mViewTreeObserver) {
       if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
         mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
       }
       if ((mViewTreeObserver = vto) != null) {
         vto.addOnScrollChangedListener(mSuperScrollListener);
       }
     }
   }
 }
コード例 #3
0
  public void testAccessOnScrollChangedListener() throws Throwable {
    layout(R.layout.scrollview_layout);
    final ScrollView scrollView = (ScrollView) mActivity.findViewById(R.id.scroll_view);

    mViewTreeObserver = scrollView.getViewTreeObserver();

    final MockOnScrollChangedListener listener = new MockOnScrollChangedListener();
    assertFalse(listener.hasCalledOnScrollChanged());
    mViewTreeObserver.addOnScrollChangedListener(listener);

    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_DOWN);
          }
        });
    mInstrumentation.waitForIdleSync();
    new PollingCheck() {
      @Override
      protected boolean check() {
        return listener.hasCalledOnScrollChanged();
      }
    }.run();

    listener.reset();
    assertFalse(listener.hasCalledOnScrollChanged());

    mViewTreeObserver.removeOnScrollChangedListener(listener);
    runTestOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            scrollView.fullScroll(View.FOCUS_UP);
          }
        });
    assertFalse(listener.hasCalledOnScrollChanged());
  }
コード例 #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SdkData.turingApiManager.setRequestWatcher(new HHttpRequestWatcher(this));

    findViewById(R.id.btn_send).setOnClickListener(this);
    findViewById(R.id.image_voice).setOnClickListener(this);
    ((EditText) findViewById(R.id.type_blank)).addTextChangedListener(new HTextWatcher());

    ((RoundButton) findViewById(R.id.btn_voice))
        .setOnTouchListener(
            new RoundButton.OnTouchListener() {
              @Override
              public void onTouchDown() {
                ASRModule.start(
                    new Runnable() {
                      @Override
                      public void run() {
                        sendMsg(ASRModule.output);
                      }
                    });
              }

              @Override
              public void onTouchUp() {
                ASRModule.stop();
              }
            });

    ViewTreeObserver vto = findViewById(R.id.scroll_chatbox).getViewTreeObserver();
    vto.addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            View scrollView = MainActivity.this.findViewById(R.id.scroll_chatbox);
            int height = scrollView.getHeight();
            int scrollValue = lastScrollHeight - height;
            if (scrollValue > 0
                || scrollView.getScrollY() + scrollView.getHeight()
                    != MainActivity.this.findViewById(R.id.layout_chatbox).getHeight())
              scrollView.scrollBy(0, scrollValue);
            else
              scrollView.scrollBy(
                  0,
                  -MainActivity.this.findViewById(R.id.layout_chatbox).getHeight()
                      + scrollY
                      + lastScrollHeight);
            lastScrollHeight = height;
          }
        });
    vto.addOnScrollChangedListener(
        new ViewTreeObserver.OnScrollChangedListener() {
          @Override
          public void onScrollChanged() {
            View scrollView = MainActivity.this.findViewById(R.id.scroll_chatbox);
            scrollY = scrollView.getScrollY();
          }
        });

    findViewById(R.id.scroll_chatbox)
        .setOnTouchListener(
            new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                v.requestFocus();
                return false;
              }
            });

    findViewById(R.id.btn_voice)
        .setOnFocusChangeListener(
            new View.OnFocusChangeListener() {
              @Override
              public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus && !isBtmBarShowing) showBtmBar();
                if (isBtmBarShowing && !hasFocus && !isSendingMsg) hideBtmBar();
              }
            });

    ASRModule.init(this);
    TTSModule.init(this);
  }
package com.actionbarsherlock.internal.widget;
コード例 #6
0
ファイル: zzgb.java プロジェクト: yusato0378/aa
 protected void zza(ViewTreeObserver viewtreeobserver) {
   viewtreeobserver.addOnScrollChangedListener(this);
 }