| /* |
| * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
| * |
| * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 3 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| * |
| * Additional permission under GNU GPL version 3 section 7: |
| * |
| * If you modify this program, or any covered work, by linking or |
| * combining it with the OpenSSL project's OpenSSL library (or a |
| * modified version of that library), containing parts covered by the |
| * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| * grants you additional permission to convey the resulting work. |
| * Corresponding Source for a non-source form of such a combination |
| * shall include the source code for the parts of OpenSSL used as well |
| * as that of the covered work. |
| */ |
| package org.sflphone.fragments; |
| |
| import org.sflphone.R; |
| import org.sflphone.adapters.SectionsPagerAdapter; |
| import org.sflphone.views.PagerSlidingTabStrip; |
| |
| import android.app.Activity; |
| import android.content.Intent; |
| import android.os.Bundle; |
| import android.support.v4.app.Fragment; |
| import android.support.v4.view.ViewPager; |
| import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.ViewGroup; |
| |
| public class HomeFragment extends Fragment { |
| static final String TAG = HomeFragment.class.getSimpleName(); |
| |
| /** |
| * The {@link ViewPager} that will host the section contents. |
| */ |
| ViewPager mViewPager; |
| SectionsPagerAdapter mSectionsPagerAdapter = null; |
| |
| @Override |
| public void onResume() { |
| super.onResume(); |
| getActivity().getActionBar().setTitle(R.string.menu_item_home); |
| } |
| |
| @Override |
| public void onAttach(Activity activity) { |
| super.onAttach(activity); |
| } |
| |
| @Override |
| public void onDetach() { |
| super.onDetach(); |
| } |
| |
| @Override |
| public void onCreate(Bundle savedBundle) { |
| super.onCreate(savedBundle); |
| mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity(), getChildFragmentManager()); |
| } |
| |
| @Override |
| public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_home, container, false); |
| |
| // Set up the ViewPager with the sections adapter. |
| mViewPager = (ViewPager) rootView.findViewById(R.id.pager); |
| mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f)); |
| |
| mViewPager.setOffscreenPageLimit(2); |
| mViewPager.setAdapter(mSectionsPagerAdapter); |
| mViewPager.setCurrentItem(1); |
| |
| final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(rootView.findViewById(R.id.pts_main)); |
| |
| strip.setViewPager(mViewPager); |
| |
| return rootView; |
| } |
| |
| @Override |
| public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| super.onActivityResult(requestCode, resultCode, data); |
| } |
| |
| public class ZoomOutPageTransformer implements ViewPager.PageTransformer { |
| private static final float MIN_ALPHA = .6f; |
| |
| public ZoomOutPageTransformer(float scalingStart) { |
| super(); |
| } |
| |
| @Override |
| public void transformPage(View page, float position) { |
| final float normalizedposition = Math.abs(Math.abs(position) - 1); |
| page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition); |
| } |
| } |
| |
| } |