Android Open Source - PTPageView P T Page Controls Activity






From Project

Back to project page PTPageView.

License

The source code is released under:

MIT License

If you think the Android project PTPageView 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.ttpho.ptpagecontrols;
//from   ww  w  .  j  a va  2s  . co  m
import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ttpho.ptpageview.PTPageView;

public class PTPageControlsActivity extends FragmentActivity implements
    OnPageChangeListener {
  private PTPageView ptPageView;
  private List<Fragment> fragments = new ArrayList<Fragment>();
  private static List<String> strColors = null;
  private int COUNT = 5;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_ptpage_controls);

    ptPageView = (PTPageView) findViewById(R.id.ptPageView);
    // square type
    ptPageView.setSizeItem(100, 50);

    ViewPager pager = (ViewPager) findViewById(R.id.pager);

    for (int i = 0; i < COUNT; i++) {
      fragments.add(MyFragment.newInstance(String.valueOf(i)));
    }

    FragmentManager fm = getSupportFragmentManager();
    pager.setAdapter(new MyPageAdapter(fm, fragments));
    pager.setOnPageChangeListener(this);
  }

  class MyPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;

    public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
      super(fm);
      this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
      return this.fragments.get(position);
    }

    @Override
    public int getCount() {
      return this.fragments.size();
    }
  }

  public static class MyFragment extends Fragment {
    public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";

    public static final MyFragment newInstance(String message) {
      MyFragment f = new MyFragment();
      Bundle bdl = new Bundle();
      bdl.putString(EXTRA_MESSAGE, message);
      f.setArguments(bdl);
      return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      String message = getArguments().getString(EXTRA_MESSAGE);
      View v = inflater.inflate(R.layout.fragment_page, container, false);
      TextView messageTextView = (TextView) v.findViewById(R.id.txtTitle);
      messageTextView.setText(message);

      int indexPage = Integer.valueOf(message);

      messageTextView.setTextColor(Color.parseColor(getListColors().get(
          indexPage)));
      return v;
    }
  }

  @Override
  public void onPageScrollStateChanged(int arg0) {

  }

  @Override
  public void onPageScrolled(int arg0, float arg1, int arg2) {

  }

  @Override
  public void onPageSelected(int arg0) {
    ptPageView.setState(arg0);
  }

  public static List<String> getListColors() {
    if (strColors == null || strColors.isEmpty()) {
      strColors = new ArrayList<String>();
      strColors.add("#1abc9c");
      strColors.add("#f1c40f");
      strColors.add("#27ae60");
      strColors.add("#e74c3c");
      strColors.add("#8e44ad");
    }
    return strColors;
  }

}




Java Source Code List

com.ttpho.ptpagecontrols.PTPageControlsActivity.java
com.ttpho.ptpageview.PTPageView.java