Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dagger_act);
    ButterKnife.bind(this);

    LoginFragment loginFragment =
        (LoginFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);

    if (loginFragment == null) {
      loginFragment = LoginFragment.newInstance();

      ActivityUtils.addFragmentToActivity(
          getSupportFragmentManager(), loginFragment, R.id.content_frame);
    }

    //        new LoginPresenter(loginFragment);
    DaggerLoginComponent.builder()
        .loginPresenterModule(new LoginPresenterModule(loginFragment))
        .build()
        .inject(this);
  }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.toolbar_fade_in_activity);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbarTab = (Toolbar) findViewById(R.id.toolbar_tab);
    mTabLayout = (SlidingTabLayout) findViewById(R.id.tab_layout);
    mPager = (ViewPager) findViewById(R.id.page);
    mMainLayout = (MyScrollView) findViewById(R.id.main_layout);

    mBackgrounds = new String[] {"#616161", "#9E9E9E", "#F5F5F5"};
    mFragmentList = new ArrayList<>();

    setSupportActionBar(mToolbar);
    // 显示回退按钮
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    for (int i = 0; i < mBackgrounds.length; i++) {
      Fragment fragment = TextFragment.newInstance("Fragment" + i, mBackgrounds[i]);
      mFragmentList.add(fragment);
    }

    mPager.setAdapter(new TagPageAdapter(getSupportFragmentManager()));
    mTabLayout.setViewPager(mPager);
    mMainLayout.setScrollViewListener(
        new MyScrollView.ScrollViewListener() {
          @Override
          public void onScrollChanged(int y) {
            if (y >= 0 && y <= 255) {
              mToolbar.setBackgroundColor(Color.argb(y, 0, 0, 255));
            }
            int[] toolbarLocation = new int[2];
            int[] toolbarTaglocation = new int[2];
            mToolbarTab.getLocationOnScreen(toolbarTaglocation);
            mToolbar.getLocationOnScreen(toolbarLocation);
            Log.d(TAG, toolbarTaglocation[1] + "");
            //
            if (toolbarLocation[1] + mToolbar.getHeight() == toolbarTaglocation[1]) {
              Toast.makeText(mContext, "贴合", Toast.LENGTH_SHORT).show();
              mToolbar.setBackgroundColor(Color.argb(255, 0, 0, 255));
            }
          }
        });

    // 滑动停靠
    GestureDetector.OnGestureListener test =
        new GestureDetector.SimpleOnGestureListener() {
          @Override
          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // return super.onFling(e1, e2, velocityX, velocityY);
            // 判断上滑还是下滑
            if (e1 == null) {
              return false;
            }
            Log.d(TAG, "e1:" + e1.getY() + " e2:" + e2.getY());
            if (e2.getY() - e1.getY() > 100) {
              Log.d(TAG, "Filing Down");
              Toast.makeText(mContext, "Filing Down", Toast.LENGTH_SHORT).show();
            } else {
              Log.d(TAG, "Filing Up");
              // Toast.makeText(mContext, "Filing Up", Toast.LENGTH_SHORT).show();
              mMainLayout.smoothScrollTo(0, mToolbarTab.getTop() - mToolbar.getBottom());
              return true;
            }

            return false;
          }
        };
    final GestureDetector gestureDetector = new GestureDetector(mContext, test);

    // 如果是向上快速滑动,直接贴边后继续向上滑
    mMainLayout.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            //                int[] toolbarLocation = new int[2];
            //                int[] toolbarTaglocation = new int[2];
            //                mToolbarTab.getLocationOnScreen(toolbarTaglocation);
            //                mToolbar.getLocationOnScreen(toolbarLocation);
            //                //
            //                if (toolbarLocation[1] + mToolbar.getHeight() ==
            // toolbarTaglocation[1]) {
            //                    Toast.makeText(mContext, "贴合", Toast.LENGTH_SHORT).show();
            //                    mToolbar.setBackgroundColor(Color.argb(255, 0, 0, 255));
            //                }

            //                int[] location = new int[2];
            //                mToolbarTab.getLocationOnScreen(location);
            //                //mMainLayout.smoothScrollTo(location[0], mToolbarBottonY);
            //                //mMainLayout.scrollTo(location[0], mToolbarBottonY);
            //                //
            //                if (mToolbar.getBottom() == location[1]) {
            //                    Toast.makeText(mContext, "贴合", Toast.LENGTH_SHORT).show();
            //                    mToolbar.setBackgroundColor(Color.argb(255, 0, 0, 255));
            //                }

            return gestureDetector.onTouchEvent(event);
            // return true; //停止滚动
          }
        });
  }