Java tutorial
/* * Copyright (c) 2014. FarrelltonSolar * * 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 ca.farrelltonsolar.classic; import android.app.Fragment; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import fr.castorflex.android.verticalviewpager.VerticalViewPager; /** * Created by Graham on 03/01/2015. */ public class MonthPager extends Fragment { private static final float MIN_SCALE = 0.85f; private static final float MIN_ALPHA = 0.65f; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View theView = inflater.inflate(R.layout.day_logs_chart_pager, container, false); VerticalViewPager verticalViewPager = (VerticalViewPager) theView.findViewById(R.id.verticalviewpager); verticalViewPager.setAdapter(getAdapter()); verticalViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.pagemargin)); verticalViewPager .setPageMarginDrawable(new ColorDrawable(getResources().getColor(android.R.color.holo_green_dark))); verticalViewPager.setPageTransformer(true, new ViewPager.PageTransformer() { @Override public void transformPage(View view, float position) { int pageWidth = view.getWidth(); int pageHeight = view.getHeight(); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. view.setAlpha(0); } else if (position <= 1) { // [-1,1] // Modify the default slide transition to shrink the page as well float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); float vertMargin = pageHeight * (1 - scaleFactor) / 2; float horzMargin = pageWidth * (1 - scaleFactor) / 2; if (position < 0) { view.setTranslationY(vertMargin - horzMargin / 2); } else { view.setTranslationY(-vertMargin + horzMargin / 2); } // Scale the page down (between MIN_SCALE and 1) view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); // Fade the page relative to its size. view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); } else { // (1,+Infinity] // This page is way off-screen to the right. view.setAlpha(0); } } }); return theView; } protected android.support.v4.view.PagerAdapter getAdapter() { return null; } }