Esempio n. 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_art, container, false);

    final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    Activity parentActivity = getActivity();
    if (parentActivity instanceof ObservableScrollViewCallbacks) {
      // Scroll to the specified offset after layout
      Bundle args = getArguments();
      if (args != null && args.containsKey(ARG_SCROLL_Y)) {
        final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
        ScrollUtils.addOnGlobalLayoutListener(
            scrollView,
            new Runnable() {
              @Override
              public void run() {
                scrollView.scrollTo(0, scrollY);
              }
            });
      }
      scrollView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity);
    }
    return view;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =
        inflater.inflate(R.layout.fragment_flexiblespacewithimagelistview, container, false);

    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.scroll);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(getActivity());
    final int flexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    AbsListView.LayoutParams lp =
        new AbsListView.LayoutParams(
            AbsListView.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);

    // This is required to disable header's list selector effect
    paddingView.setClickable(true);

    listView.addHeaderView(paddingView);
    setDummyData(listView);
    // TouchInterceptionViewGroup should be a parent view other than ViewPager.
    // This is a workaround for the issue #117:
    // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
    listView.setTouchInterceptionViewGroup((ViewGroup) view.findViewById(R.id.fragment_root));

    // Scroll to the specified offset after layout
    Bundle args = getArguments();
    if (args != null && args.containsKey(ARG_SCROLL_Y)) {
      final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
      ScrollUtils.addOnGlobalLayoutListener(
          listView,
          new Runnable() {
            @SuppressLint("NewApi")
            @Override
            public void run() {
              int offset = scrollY % flexibleSpaceImageHeight;
              listView.setSelectionFromTop(0, -offset);
            }
          });
      updateFlexibleSpace(scrollY, view);
    } else {
      updateFlexibleSpace(0, view);
    }

    listView.setScrollViewCallbacks(this);

    updateFlexibleSpace(0, view);

    return view;
  }
  @Override
  public void initialize(Context context, ActivityDetailsBinding binding) {
    /* STORES CONTEXT */
    this.context = context;

    /* STORES BINDING */
    this.binding = binding;

    /* INITIALIZE VIEWS */
    binding.setAdvertisement(advertisement);

    Picasso.with(context)
        .load(advertisement.getImageLarge())
        .placeholder(R.mipmap.ic_image)
        .centerCrop()
        .fit()
        .into(binding.ivAdvertisement);

    binding.svActivityDetails.setScrollViewCallbacks(new ObservableScrollListener());
    ScrollUtils.addOnGlobalLayoutListener(binding.getRoot(), new GlobalLayoutListener());

    /* DEFINES VARIABLES USED TO CREATE TOOLBAR ANIMATION ON SCROLL */
    flexibleSpaceHeight =
        context.getResources().getDimensionPixelSize(R.dimen.activity_details_image_height);
    toolbarColor = ContextCompat.getColor(context, R.color.color_primary);
    titleColor = ContextCompat.getColor(context, R.color.white);
    statusBarColor = ContextCompat.getColor(context, R.color.black);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      /* CREATES THE LINK TO THE TRANSITION ANIMATION */
      ViewCompat.setTransitionName(binding.ivAdvertisement, CallManager.TRANSITION_IMAGE);
      ViewCompat.setTransitionName(
          binding.viewAdvertisementInfo.rlViewAdvertisementInfo, CallManager.TRANSITION_DETAILS);

      /* MAKES STATUS BAR TRANSPARENT */
      detailsView.initializeStatusBar();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    cid = intent.getStringExtra("cid");
    uid = intent.getStringExtra("uid");
    tit = intent.getStringExtra("tit");
    setContentView(R.layout.activity_flexiblespacewithimagewithviewpagertab);
    ImageView image = (ImageView) findViewById(R.id.image);
    image.setImageResource(Util.bgrd(Integer.parseInt(cid)));
    mPagerAdapter = new NavigationAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mFlexibleSpaceHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mTabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height);

    TextView titleView = (TextView) findViewById(R.id.title);
    titleView.setText(tit);

    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);
    mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.white));
    mSlidingTabLayout.setDistributeEvenly(true);
    mSlidingTabLayout.setViewPager(mPager);

    // Initialize the first Fragment's state when layout is completed.
    ScrollUtils.addOnGlobalLayoutListener(
        mSlidingTabLayout,
        new Runnable() {
          @Override
          public void run() {
            translateTab(0, false);
          }
        });
  }
Esempio n. 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_profile);

    mFlexibleSpaceImageHeight =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mFlexibleSpaceShowFabOffset =
        getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
    mActionBarSize = getActionBarSize();
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    mScrollView = (ObservableScrollView) findViewById(R.id.scroll);
    mScrollView.setScrollViewCallbacks(this);
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mFab = findViewById(R.id.fab);
    mFab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), EditProfile.class);
            startActivity(intent);
          }
        });
    mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);

    ScrollUtils.addOnGlobalLayoutListener(
        mScrollView,
        new Runnable() {
          @Override
          public void run() {
            mScrollView.scrollTo(0, mFlexibleSpaceImageHeight - mActionBarSize);

            // If you'd like to start from scrollY == 0, don't write like this:
            // mScrollView.scrollTo(0, 0);
            // The initial scrollY is 0, so it won't invoke onScrollChanged().
            // To do this, use the following:
            // onScrollChanged(0, false, false);

            // You can also achieve it with the following codes.
            // This causes scroll change from 1 to 0.
            mScrollView.scrollTo(0, 1);
            mScrollView.scrollTo(0, 0);
          }
        });

    File path =
        new File(Environment.getExternalStorageDirectory(), "/weHappening/profile_image.png");
    Bitmap b = null;
    if (path.exists()) {
      try {
        b = BitmapFactory.decodeStream(new FileInputStream(path));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
      CircularImageView img = (CircularImageView) findViewById(R.id.imgPicker);
      img.setImageBitmap(b);
    } else {
      CircularImageView img = (CircularImageView) findViewById(R.id.imgPicker);
      img.setImageDrawable(getResources().getDrawable(R.drawable.ic_person));
    }
  }