blob: c5a073c467c8976fd98e0591be339569505ccafe [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
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 Lision064e1e02013-10-01 16:18:42 -040031package org.sflphone.fragments;
alisionf76de3b2013-04-16 15:35:22 -040032
Alexandre Lision064e1e02013-10-01 16:18:42 -040033import org.sflphone.R;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050034import org.sflphone.adapters.SectionsPagerAdapter;
35import org.sflphone.views.PagerSlidingTabStrip;
Alexandre Lision064e1e02013-10-01 16:18:42 -040036
alisionf76de3b2013-04-16 15:35:22 -040037import android.app.Activity;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040038import android.content.Intent;
alisionf76de3b2013-04-16 15:35:22 -040039import android.os.Bundle;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050040import android.app.Fragment;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050041import android.support.v4.view.ViewPager;
alisionf76de3b2013-04-16 15:35:22 -040042import android.view.LayoutInflater;
43import android.view.View;
Alexandre Lision064e1e02013-10-01 16:18:42 -040044import android.view.ViewGroup;
alisionf76de3b2013-04-16 15:35:22 -040045
alisionb1763882013-06-18 17:30:51 -040046public class HomeFragment extends Fragment {
Alexandre Lisionf02190d2013-12-12 17:26:12 -050047 static final String TAG = HomeFragment.class.getSimpleName();
Alexandre Lision658999c2013-12-13 14:42:45 -050048
alision9f7a6ec2013-05-24 16:26:26 -040049 /**
Alexandre Lisionf02190d2013-12-12 17:26:12 -050050 * The {@link ViewPager} that will host the section contents.
alision9f7a6ec2013-05-24 16:26:26 -040051 */
Alexandre Lisionf02190d2013-12-12 17:26:12 -050052 ViewPager mViewPager;
53 SectionsPagerAdapter mSectionsPagerAdapter = null;
alisionf76de3b2013-04-16 15:35:22 -040054
alision9f7a6ec2013-05-24 16:26:26 -040055 @Override
Alexandre Lision658999c2013-12-13 14:42:45 -050056 public void onResume() {
57 super.onResume();
58 getActivity().getActionBar().setTitle(R.string.menu_item_home);
59 }
60
61 @Override
alision9f7a6ec2013-05-24 16:26:26 -040062 public void onAttach(Activity activity) {
63 super.onAttach(activity);
Alexandre Lision573045c2013-09-11 17:20:25 -040064 }
65
alision9f7a6ec2013-05-24 16:26:26 -040066 @Override
67 public void onDetach() {
68 super.onDetach();
alision9f7a6ec2013-05-24 16:26:26 -040069 }
Alexandre Lision658999c2013-12-13 14:42:45 -050070
alision9f7a6ec2013-05-24 16:26:26 -040071 @Override
Alexandre Lision658999c2013-12-13 14:42:45 -050072 public void onCreate(Bundle savedBundle) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -050073 super.onCreate(savedBundle);
Alexandre Lisiona8b78722013-12-13 10:18:33 -050074 mSectionsPagerAdapter = new SectionsPagerAdapter(getActivity(), getChildFragmentManager());
alision9f7a6ec2013-05-24 16:26:26 -040075 }
alision371b77e2013-04-23 14:51:26 -040076
alision9f7a6ec2013-05-24 16:26:26 -040077 @Override
alision9f7a6ec2013-05-24 16:26:26 -040078 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -050079 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_home, container, false);
Alexandre Lision658999c2013-12-13 14:42:45 -050080
Alexandre Lisionf02190d2013-12-12 17:26:12 -050081 // 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 Lision658999c2013-12-13 14:42:45 -050084
Alexandre Lisionf02190d2013-12-12 17:26:12 -050085 mViewPager.setOffscreenPageLimit(2);
86 mViewPager.setAdapter(mSectionsPagerAdapter);
87 mViewPager.setCurrentItem(1);
alision43a9b362013-05-01 16:30:15 -040088
Alexandre Lisionf02190d2013-12-12 17:26:12 -050089 final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(rootView.findViewById(R.id.pts_main));
Alexandre Lision6d75d062013-09-13 14:18:34 -040090
Alexandre Lisionf02190d2013-12-12 17:26:12 -050091 strip.setViewPager(mViewPager);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040092
Alexandre Lisionf02190d2013-12-12 17:26:12 -050093 return rootView;
alision9f7a6ec2013-05-24 16:26:26 -040094 }
Alexandre Lisionebeb3662013-09-17 16:20:54 -040095
Alexandre Lisionf1850c02013-09-23 14:19:34 -040096 @Override
97 public void onActivityResult(int requestCode, int resultCode, Intent data) {
98 super.onActivityResult(requestCode, resultCode, data);
Alexandre Lisionf02190d2013-12-12 17:26:12 -050099 }
Alexandre Lision658999c2013-12-13 14:42:45 -0500100
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500101 public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
102 private static final float MIN_ALPHA = .6f;
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400103
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500104 public ZoomOutPageTransformer(float scalingStart) {
105 super();
106 }
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400107
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500108 @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 Lisionf1850c02013-09-23 14:19:34 -0400112 }
113 }
Alexandre Lisione2839d52013-10-01 09:37:37 -0400114
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500115}