示例#1
0
  public void showSelectDayDialog() {
    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
    final Activity a = getActivity();

    final Calendar cCal = Calendar.getInstance();
    cCal.add(Calendar.DAY_OF_YEAR, viewPager.getCurrentItem() - 500);

    DialogFragment ds =
        new DialogFragment() {
          @Override
          public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new DatePickerDialog(
                a,
                new DatePickerDialog.OnDateSetListener() {

                  @Override
                  public void onDateSet(
                      DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar nCal = Calendar.getInstance();
                    nCal.set(Calendar.YEAR, year);
                    nCal.set(Calendar.MONTH, monthOfYear);
                    nCal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    long timeDelta = nCal.getTimeInMillis() - cCal.getTimeInMillis();
                    int dayDelta = (int) (timeDelta / (60000 * 60 * 24));
                    viewPager.setCurrentItem(viewPager.getCurrentItem() + dayDelta);
                  }
                },
                cCal.get(Calendar.YEAR),
                cCal.get(Calendar.MONTH),
                cCal.get(Calendar.DAY_OF_MONTH));
          }
        };
    ds.show(getActivity().getFragmentManager(), "datepicker");
  }
示例#2
0
 public void restoreCurrentPage() {
   ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
   try {
     pager.setCurrentItem(getStoredPage());
   } catch (NullPointerException e) {
     // Ewiges Leid mit dem Emulator
   }
 }
示例#3
0
 public void storeCurrentPage() {
   try {
     ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
     SharedPreferences.Editor editor =
         getActivity().getSharedPreferences("plan", Context.MODE_PRIVATE).edit();
     editor.putInt("currentPage", pager.getCurrentItem());
     editor.apply();
   } catch (NullPointerException e) {
     // Passiert ständig im Emulator
   }
 }
示例#4
0
  public boolean backPressed() {
    ViewPager pager = getViewPager();

    int currentItem = pager.getCurrentItem();

    if (currentItem != 500) {
      if (currentItem > 500) pager.setCurrentItem(currentItem - 1);
      if (currentItem < 500) pager.setCurrentItem(currentItem + 1);
    } else {
      getActivity().finish();
    }

    return false;
  }
示例#5
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_main, container, false);

    FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
    PlanFragmentAdapter.fab = fab;
    PlanFragmentAdapter.fabAnimator = new FABAnimator(fab);
    PlanFragmentAdapter.fab.setImageDrawable(
        new IconicsDrawable(this.getContext())
            .icon(GoogleMaterial.Icon.gmd_undo)
            .color(Color.WHITE)
            .sizeDp(40));

    planPagerAdapter = new PlanPagerAdapter(this.getChildFragmentManager(), this.getContext());
    setAdapter();

    ClickablePagerTabStrip pagerTabStrip =
        (ClickablePagerTabStrip) view.findViewById(R.id.tabstrip);
    pagerTabStrip.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            showSelectDayDialog();
          }
        });

    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
            pager.setCurrentItem(500);
          }
        });

    ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
    pager.addOnPageChangeListener(this);

    return view;
  }
示例#6
0
 public void setAdapter() {
   ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
   pager.setAdapter(planPagerAdapter);
   pager.setOffscreenPageLimit(5);
   restoreCurrentPage();
 }