Android Open Source - Planets-App Fragment Planets






From Project

Back to project page Planets-App.

License

The source code is released under:

Apache License

If you think the Android project Planets-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andrewq.planets;
/*  ww  w .  j a va2 s  .c  om*/
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.analytics.tracking.android.EasyTracker;

public class FragmentPlanets extends Fragment {

    private ViewPager viewPager;
    private PagerTitleStrip pagerTitleStrip;

    public FragmentPlanets() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        EasyTracker.getInstance(getActivity()).activityStart(getActivity());  // Add this method.
    }

    @Override
    public void onStop() {
        super.onStop();
        EasyTracker.getInstance(getActivity()).activityStop(getActivity());  // Add this method.
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        viewPager = (ViewPager) getView().findViewById(R.id.pager);
        viewPager.setAdapter(new MyAdapter(getFragmentManager()));

        pagerTitleStrip = (PagerTitleStrip) getView().findViewById(R.id.pager_title_strip);

        SharedPreferences getPrefs = PreferenceManager
                .getDefaultSharedPreferences(this.getActivity());
        int theme_chooser = Integer.parseInt(getPrefs.getString("prefSetTheme", "1"));
        pagerTitleStrip.setTextColor(Color.parseColor("#ffffff"));

        if (theme_chooser == 1) {
            //Red
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#ff4646"));
        } else if (theme_chooser == 2) {
            //Orange
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#fdba35"));
        } else if (theme_chooser == 3) {
            //Blue
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#33b5e5"));
        } else if (theme_chooser == 4) {
            //Green
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#9acc04"));
        } else if (theme_chooser == 5) {
            //Purple
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#aa65cc"));
        } else {
            //Black
            pagerTitleStrip.setBackgroundColor(Color.parseColor("#767676"));
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_planets, container, false);
    }
}

class MyAdapter extends FragmentStatePagerAdapter {

    public MyAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int arg0) {
        Fragment fragment = null;
        if (arg0 == 0) {
            fragment = new FragmentA();
        }
        if (arg0 == 1) {
            fragment = new FragmentB();
        }
        if (arg0 == 2) {
            fragment = new FragmentC();
        }
        if (arg0 == 3) {
            fragment = new FragmentD();
        }
        if (arg0 == 4) {
            fragment = new FragmentE();
        }
        if (arg0 == 5) {
            fragment = new FragmentF();
        }
        if (arg0 == 6) {
            fragment = new FragmentG();
        }
        if (arg0 == 7) {
            fragment = new FragmentH();
        }
        if (arg0 == 8) {
            fragment = new FragmentI();
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return 9;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (position == 0) {
            return "Sun";
        }
        if (position == 1) {
            return "Mercury";
        }
        if (position == 2) {
            return "Venus";
        }
        if (position == 3) {
            return "Earth";
        }
        if (position == 4) {
            return "Mars";
        }
        if (position == 5) {
            return "Jupiter";
        }
        if (position == 6) {
            return "Saturn";
        }
        if (position == 7) {
            return "Uranus";
        }
        if (position == 8) {
            return "Neptune";
        }
        return null;
    }
}




Java Source Code List

com.andrewq.planets.CustomAdapter.java
com.andrewq.planets.Deimos.java
com.andrewq.planets.EclairMotionEvent.java
com.andrewq.planets.FragmentA.java
com.andrewq.planets.FragmentB.java
com.andrewq.planets.FragmentC.java
com.andrewq.planets.FragmentD.java
com.andrewq.planets.FragmentE.java
com.andrewq.planets.FragmentF.java
com.andrewq.planets.FragmentG.java
com.andrewq.planets.FragmentH.java
com.andrewq.planets.FragmentHome.java
com.andrewq.planets.FragmentI.java
com.andrewq.planets.FragmentPlanets.java
com.andrewq.planets.ImageGallery.java
com.andrewq.planets.Phobos.java
com.andrewq.planets.RandomQuotes.java
com.andrewq.planets.RowItem.java
com.andrewq.planets.SatelliteEarth.java
com.andrewq.planets.Settings.java
com.andrewq.planets.SunGLActivity.java
com.andrewq.planets.SunRenderer.java
com.andrewq.planets.TouchImageView.java
com.andrewq.planets.VenusRenderer.java
com.andrewq.planets.WrapMotionEvent.java
com.obsidian.planets.Main.java