@AfterViews
 void init() {
   mAdapter = new AlbumAdapter(getChildFragmentManager());
   mPager.setAdapter(mAdapter);
   mIndicator.setViewPager(mPager, mCurrentPage);
   mIndicator.setFades(false);
   updateImages(mAlbum.images);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mFragmentsListOne = getFragmentsListOne();
    mFragmentsListTwo = getFragmentsListTwo();
    mAdapterOne = new ViewPagerAdapterOne(getFragmentManager(), mFragmentsListOne);
    mAdapterTwo = new ViewPagerAdapterTwo(getFragmentManager(), mFragmentsListTwo);
    mViewPager = (ViewPager) findViewById(R.id.mpager);
    mViewPager.setAdapter(mAdapterOne);
    indicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(mViewPager);
    indicator.setFades(false);
    indicator.setSelectedColor(Color.WHITE);

    mPlanetTitles = new String[] {"Blue", "Red"};
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(
        new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.drawable.ic_drawer,
            R.string.drawer_open,
            R.string.drawer_close) {
          public void onDrawerClosed(View view) {
            getActionBar().setTitle("DrawerPagerSample");
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle("Drawer Open");
          }
        };
    mDrawerList.setItemChecked(0, true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DatabaseHelper dbHelper = new DatabaseHelper(this);
    try {
      dbHelper.createDataBase();
      dbHelper.openDataBase(false);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    copyOldData();
    dbHelper.close();
    dialogLanguage();
    setLocale(this);
    if (savedInstanceState != null) {
      position = savedInstanceState.getInt("position");
    }

    setContentView(R.layout.activity_main);

    mPager = (ViewPager) findViewById(R.id.ViewPager_mainPager);
    mPager.setOffscreenPageLimit(2);
    mPager.setAdapter(new MFragmentAdapter(getSupportFragmentManager()));
    UnderlinePageIndicator indicator =
        (UnderlinePageIndicator) findViewById(R.id.CirclePageIndicator_indicator);
    indicator.setViewPager(mPager);
    SharedPreferences pref = getSharedPreferences("reset", 0);
    position = pref.getInt("position", 0);
    mPager.setCurrentItem(position);

    testIndicatorIcon = (ImageView) findViewById(R.id.indicator_Test);
    contentIndicatorIcon = (ImageView) findViewById(R.id.indicator_Content);
    schoolInidcatorIcon = (ImageView) findViewById(R.id.indicator_Schools);
    setTitleButtons();

    testIndicatorIcon.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mPager.setCurrentItem(0);
            setTitleButtons();
          }
        });
    contentIndicatorIcon.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mPager.setCurrentItem(1);
            setTitleButtons();
          }
        });
    schoolInidcatorIcon.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mPager.setCurrentItem(2);
            setTitleButtons();
          }
        });

    indicator.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {

            setTitleButtons();
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
  }
Esempio n. 4
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View res = inflater.inflate(R.layout.tour_container, container, false);
    final UnderlinePageIndicator pageIndicator =
        (UnderlinePageIndicator) res.findViewById(R.id.pageIndicator);
    pageIndicator.setFades(false);
    pageIndicator.setSelectedColor(0xffbfbfbf);

    openAppButton = res.findViewById(R.id.openAppButton);
    openAppButton.setOnClickListener(
        secure(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (application.getKernel().getActivationController() == null) {
                  application
                      .getKernel()
                      .setActivationController(new ActivationController(application));
                }
                if (application.getKernel().getActivationController().getCurrentState()
                    == ActivationController.STATE_PHONE_CONFIRM) {
                  try {
                    final Phonenumber.PhoneNumber numberUtil =
                        PhoneNumberUtil.getInstance()
                            .parse(
                                "+"
                                    + application
                                        .getKernel()
                                        .getActivationController()
                                        .getAutoPhone(),
                                "us");

                    AlertDialog.Builder builder =
                        new AlertDialog.Builder(getActivity())
                            .setMessage(
                                getStringSafe(R.string.st_auth_confirm_phone)
                                    .replace("\\n", "\n")
                                    .replace(
                                        "{0}",
                                        BidiFormatter.getInstance()
                                            .unicodeWrap(
                                                PhoneNumberUtil.getInstance()
                                                    .format(
                                                        numberUtil,
                                                        PhoneNumberUtil.PhoneNumberFormat
                                                            .INTERNATIONAL))));
                    builder
                        .setPositiveButton(
                            R.string.st_yes,
                            secure(
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                    if (application.getKernel().getActivationController() != null) {
                                      if (application
                                              .getKernel()
                                              .getActivationController()
                                              .getCurrentState()
                                          == ActivationController.STATE_PHONE_CONFIRM) {
                                        application
                                            .getKernel()
                                            .getActivationController()
                                            .doConfirmPhone();
                                      }
                                    }
                                    getRootController().openApp();
                                  }
                                }))
                        .setNegativeButton(
                            R.string.st_edit,
                            secure(
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialogInterface, int i) {
                                    if (application.getKernel().getActivationController() != null) {
                                      if (application
                                              .getKernel()
                                              .getActivationController()
                                              .getCurrentState()
                                          == ActivationController.STATE_PHONE_CONFIRM) {
                                        application
                                            .getKernel()
                                            .getActivationController()
                                            .doEditPhone();
                                      }
                                    }
                                    getRootController().openApp();
                                  }
                                }));
                    AlertDialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.show();
                  } catch (NumberParseException e) {
                    application.getKernel().getActivationController().doEditPhone();
                    getRootController().openApp();
                  }
                } else {
                  getRootController().openApp();
                }
              }
            }));
    // dynamicBg = res.findViewById(R.id.dynamicBg);
    // bottomView = dynamicBg;
    indicator0 = res.findViewById(R.id.intro0);
    indicator1 = res.findViewById(R.id.intro1);
    indicator2 = res.findViewById(R.id.intro2);
    indicator3 = res.findViewById(R.id.intro3);
    indicator4 = res.findViewById(R.id.intro4);
    indicator5 = res.findViewById(R.id.intro5);

    indicatorContainer = res.findViewById(R.id.iconContainer);

    indicator0.setVisibility(View.VISIBLE);
    indicator1.setVisibility(View.GONE);
    indicator2.setVisibility(View.GONE);
    indicator3.setVisibility(View.GONE);
    indicator4.setVisibility(View.GONE);
    indicator5.setVisibility(View.GONE);

    if (application.isRTL()) {
      indicators =
          new View[] {indicator5, indicator4, indicator3, indicator2, indicator1, indicator0};
    } else {
      indicators =
          new View[] {indicator0, indicator1, indicator2, indicator3, indicator4, indicator5};
    }

    pager = (ViewPager) res.findViewById(R.id.tourText);
    final String[] messages;
    if (application.isRTL()) {
      messages =
          new String[] {
            getStringSafe(R.string.st_tour_page6),
            getStringSafe(R.string.st_tour_page5),
            getStringSafe(R.string.st_tour_page4),
            getStringSafe(R.string.st_tour_page3),
            getStringSafe(R.string.st_tour_page2),
            getStringSafe(R.string.st_tour_page1),
          };
    } else {
      messages =
          new String[] {
            getStringSafe(R.string.st_tour_page1),
            getStringSafe(R.string.st_tour_page2),
            getStringSafe(R.string.st_tour_page3),
            getStringSafe(R.string.st_tour_page4),
            getStringSafe(R.string.st_tour_page5),
            getStringSafe(R.string.st_tour_page6)
          };
    }

    final String[] titles;
    if (application.isRTL()) {
      titles =
          new String[] {
            getStringSafe(R.string.st_tour_page6_title),
            getStringSafe(R.string.st_tour_page5_title),
            getStringSafe(R.string.st_tour_page4_title),
            getStringSafe(R.string.st_tour_page3_title),
            getStringSafe(R.string.st_tour_page2_title),
            getStringSafe(R.string.st_tour_page1_title),
          };
    } else {
      titles =
          new String[] {
            getStringSafe(R.string.st_tour_page1_title),
            getStringSafe(R.string.st_tour_page2_title),
            getStringSafe(R.string.st_tour_page3_title),
            getStringSafe(R.string.st_tour_page4_title),
            getStringSafe(R.string.st_tour_page5_title),
            getStringSafe(R.string.st_tour_page6_title)
          };
    }
    final int[] colors;
    if (application.isRTL()) {
      colors = new int[] {0x2f92e8, 0x5dc326, 0xfac800, 0xf99117, 0xf75b2f, 0xbfbfbf};
    } else {
      colors = new int[] {0xbfbfbf, 0xf75b2f, 0xf99117, 0xfac800, 0x5dc326, 0x2f92e8};
    }
    pager.setAdapter(
        new PagerAdapter() {
          @Override
          public int getCount() {
            return 6;
          }

          @Override
          public boolean isViewFromObject(View view, Object o) {
            return o == view;
          }

          @Override
          public Object instantiateItem(ViewGroup container, int position) {
            View res = getLayoutInflater(null).inflate(R.layout.tour_item, container, false);
            ((TextView) res.findViewById(R.id.title)).setText(titles[position]);
            ((TextView) res.findViewById(R.id.message)).setText(html(messages[position]));
            container.addView(res);
            return res;
          }

          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
          }
        });
    pageIndicator.setViewPager(pager);
    pageIndicator.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          private int interpolateColors(int a, int b, float v) {
            int aRed = (a & 0xFF0000) >> 16;
            int aGreen = (a & 0xFF00) >> 8;
            int aBlue = a & 0xFF;

            int bRed = (b & 0xFF0000) >> 16;
            int bGreen = (b & 0xFF00) >> 8;
            int bBlue = b & 0xFF;

            int cRed = (int) (aRed * v + bRed * (1 - v));
            int cGreen = (int) (aGreen * v + bGreen * (1 - v));
            int cBlue = (int) (aBlue * v + bBlue * (1 - v));

            return 0xFF000000 | (cRed << 16) | (cGreen << 8) | cBlue;
          }

          private Drawable interpolateDrawables(Drawable a, Drawable b, float v) {
            a.setAlpha((int) (255 * v));
            b.setAlpha((int) (255 * (1 - v)));
            return new LayerDrawable(new Drawable[] {a, b});
          }

          @Override
          public void onPageScrolled(int i, float v, int i2) {
            if (i2 > 0) {
              int color = interpolateColors(colors[i], colors[i + 1], 1 - v);
              pageIndicator.setSelectedColor(color);
              // dynamicBg.setBackgroundDrawable(interpolateDrawables(backgrounds[i], backgrounds[i
              // + 1], 1 - v));
            } else {
              //                    if (i > 0) {
              //                        dynamicBg.setBackgroundDrawable(new
              // ColorDrawable(colors[viewPager.getCurrentItem()] | 0xFF000000));
              //                    } else {
              //                        dynamicBg.setBackgroundDrawable(new
              // ColorDrawable(0xffbfbfbf));
              //                    }
              // dynamicBg.setBackgroundDrawable(backgrounds[pager.getCurrentItem()]);
            }
          }

          @Override
          public void onPageSelected(int index) {
            //                if (index == 0) {
            //                    hideView(dynamicBg);
            //                } else {
            //                    showView(dynamicBg);
            //                }
            for (int i = 0; i < indicators.length; i++) {
              if (i == index) {
                showView(indicators[i]);
              } else {
                goneView(indicators[i]);
              }
            }

            sendEvent("page_view", index + "");
          }

          @Override
          public void onPageScrollStateChanged(int i) {}
        });

    if (application.isRTL()) {
      pager.setCurrentItem(5);
    } else {
      pager.setCurrentItem(0);
    }

    // dynamicBg.setBackgroundDrawable(backgrounds[pager.getCurrentItem()]);

    updateOrientation();

    return res;
  }