Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 31 | package org.sflphone.fragments; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 32 | |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 33 | import android.support.v4.app.Fragment; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 34 | import org.sflphone.R; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 35 | import org.sflphone.adapters.SectionsPagerAdapter; |
| 36 | import org.sflphone.views.PagerSlidingTabStrip; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 37 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 38 | import android.app.Activity; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 39 | import android.content.Intent; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 40 | import android.os.Bundle; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 41 | import android.support.v4.view.ViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 42 | import android.view.LayoutInflater; |
| 43 | import android.view.View; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 44 | import android.view.ViewGroup; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 45 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 46 | public class HomeFragment extends Fragment { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 47 | static final String TAG = HomeFragment.class.getSimpleName(); |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 48 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 49 | /** |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 50 | * The {@link ViewPager} that will host the section contents. |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 51 | */ |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 52 | ViewPager mViewPager; |
Alexandre Lision | 9b56a29 | 2014-01-23 15:20:15 -0500 | [diff] [blame] | 53 | SectionsPagerAdapter mSectionsPagerAdapter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 54 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 55 | @Override |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 56 | public void onResume() { |
| 57 | super.onResume(); |
| 58 | getActivity().getActionBar().setTitle(R.string.menu_item_home); |
| 59 | } |
| 60 | |
| 61 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 62 | public void onAttach(Activity activity) { |
| 63 | super.onAttach(activity); |
Alexandre Lision | 573045c | 2013-09-11 17:20:25 -0400 | [diff] [blame] | 64 | } |
| 65 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 66 | @Override |
| 67 | public void onDetach() { |
| 68 | super.onDetach(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 69 | } |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 70 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 71 | @Override |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 72 | public void onCreate(Bundle savedBundle) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 73 | super.onCreate(savedBundle); |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 74 | mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity(), getChildFragmentManager()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 75 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 76 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 77 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 78 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 79 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_home, container, false); |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 80 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 81 | // Set up the ViewPager with the sections adapter. |
| 82 | mViewPager = (ViewPager) rootView.findViewById(R.id.pager); |
| 83 | mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f)); |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 84 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 85 | mViewPager.setOffscreenPageLimit(2); |
| 86 | mViewPager.setAdapter(mSectionsPagerAdapter); |
| 87 | mViewPager.setCurrentItem(1); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 88 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 89 | final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(rootView.findViewById(R.id.pts_main)); |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 90 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 91 | strip.setViewPager(mViewPager); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 92 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 93 | return rootView; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 94 | } |
Alexandre Lision | ebeb366 | 2013-09-17 16:20:54 -0400 | [diff] [blame] | 95 | |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 96 | @Override |
| 97 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 98 | super.onActivityResult(requestCode, resultCode, data); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 99 | } |
Alexandre Lision | 658999c | 2013-12-13 14:42:45 -0500 | [diff] [blame] | 100 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 101 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer { |
| 102 | private static final float MIN_ALPHA = .6f; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 103 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 104 | public ZoomOutPageTransformer(float scalingStart) { |
| 105 | super(); |
| 106 | } |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 107 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 108 | @Override |
| 109 | public void transformPage(View page, float position) { |
| 110 | final float normalizedposition = Math.abs(Math.abs(position) - 1); |
| 111 | page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 112 | } |
| 113 | } |
Alexandre Lision | e2839d5 | 2013-10-01 09:37:37 -0400 | [diff] [blame] | 114 | |
Alexandre Lision | 9b56a29 | 2014-01-23 15:20:15 -0500 | [diff] [blame] | 115 | public SectionsPagerAdapter getSectionsPagerAdapter() { |
| 116 | return mSectionsPagerAdapter; |
| 117 | } |
| 118 | |
| 119 | public ViewPager getViewPager() { |
| 120 | return mViewPager; |
| 121 | } |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 122 | } |