Java tutorial
/* * Copyright 2014 Soichiro Kashima * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.grupp32.activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.View; import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks; import com.github.ksoichiro.android.observablescrollview.ScrollState; import com.github.ksoichiro.android.observablescrollview.Scrollable; import collection.Summoner; public abstract class FlexibleSpaceFragment<S extends Scrollable> extends Fragment implements ObservableScrollViewCallbacks { // Static variables for easier changes public static final String ARG_SCROLL_Y = "ARG_SCROLL_Y"; public static final String ARG_SUMMONER = "ARG_SUMMONER"; public static final String ARG_VERSION = "ARG_VERSION"; /** * Method sets information to a bundle for passing it onto the fragment (in our case TabFragment) * * @param scrollY value for current scroll-axis * @param summoner Summoner-object passed * @param patchVersion patch version passed */ public void setArguments(int scrollY, Summoner summoner, String patchVersion) { if (0 <= scrollY) { // Set information to bundle and set it as arguments Bundle args = new Bundle(); args.putInt(ARG_SCROLL_Y, scrollY); args.putSerializable(ARG_SUMMONER, summoner); args.putString(ARG_VERSION, patchVersion); setArguments(args); } } public void setScrollY(int scrollY, int threshold) { View view = getView(); if (view == null) { return; } Scrollable scrollView = (Scrollable) view.findViewById(R.id.scroll); if (scrollView == null) { return; } scrollView.scrollVerticallyTo(scrollY); } protected void updateFlexibleSpace(int scrollY) { updateFlexibleSpace(scrollY, getView()); } protected abstract void updateFlexibleSpace(int scrollY, View view); @Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (getView() == null) { return; } updateFlexibleSpace(scrollY, getView()); } @Override public final void onDownMotionEvent() { } @Override public final void onUpOrCancelMotionEvent(ScrollState scrollState) { } protected S getScrollable() { View view = getView(); return view == null ? null : (S) view.findViewById(R.id.scroll); } }