@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    setContentView(R.layout.activity_account_book_custom_view);

    mViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager);

    View view = mViewPager.getRootView();
    TextView title = (TextView) view.findViewById(R.id.logo_white);
    title.setTypeface(CoCoinUtil.getInstance().typefaceLatoLight);
    title.setText(SettingManager.getInstance().getAccountBookName());

    mViewPager.getPagerTitleStrip().setTypeface(CoCoinUtil.GetTypeface(), Typeface.NORMAL);
    mViewPager.getPagerTitleStrip().setVisibility(View.INVISIBLE);

    setTitle("");

    toolbar = mViewPager.getToolbar();

    if (toolbar != null) {
      setSupportActionBar(toolbar);

      final ActionBar actionBar = getSupportActionBar();
      if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setHomeButtonEnabled(true);
      }
    }

    View logo = findViewById(R.id.logo_white);
    if (logo != null) {
      logo.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mViewPager.notifyHeaderChanged();
            }
          });
    }

    customViewFragmentAdapter = new CustomViewFragmentAdapter(getSupportFragmentManager());
    mViewPager.getViewPager().setOffscreenPageLimit(1);
    mViewPager.getViewPager().setAdapter(customViewFragmentAdapter);
    mViewPager.getPagerTitleStrip().setViewPager(mViewPager.getViewPager());

    mViewPager.setMaterialViewPagerListener(
        new MaterialViewPager.Listener() {
          @Override
          public HeaderDesign getHeaderDesign(int page) {
            return HeaderDesign.fromColorAndDrawable(
                CoCoinUtil.GetTagColor(-3), CoCoinUtil.GetTagDrawable(-3));
          }
        });
  }
Ejemplo n.º 2
0
 public static List<CoCoinRecord> queryRecordByRemark(String remark) {
   List<CoCoinRecord> list = new LinkedList<>();
   for (CoCoinRecord coCoinRecord : RECORDS) {
     if (CoCoinUtil.IsStringRelation(coCoinRecord.getRemark(), remark)) {
       list.add(coCoinRecord);
     }
   }
   return list;
 }
Ejemplo n.º 3
0
 public static int getCurrentMonthExpense() {
   Calendar calendar = Calendar.getInstance();
   Calendar left = CoCoinUtil.GetThisMonthLeftRange(calendar);
   int monthSum = 0;
   for (int i = RECORDS.size() - 1; i >= 0; i--) {
     if (RECORDS.get(i).getCalendar().before(left)) break;
     monthSum += RECORDS.get(i).getMoney();
   }
   return monthSum;
 }
Ejemplo n.º 4
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    fragmentPosition = FragmentPagerItem.getPosition(getArguments());
    button0 = (RadioButton) view.findViewById(R.id.button0);
    button1 = (RadioButton) view.findViewById(R.id.button1);
    button2 = (RadioButton) view.findViewById(R.id.button2);
    button3 = (RadioButton) view.findViewById(R.id.button3);
    ly = (LinearLayout) view.findViewById(R.id.buttonLy);
    passwordTip = (TextView) view.findViewById(R.id.password_tip);
    passwordTip.setTypeface(CoCoinUtil.GetTypeface());
    switch (fragmentPosition) {
      case 0:
        if (SettingManager.getInstance().getFirstTime()) {
          passwordTip.setText(
              CoCoinApplication.getAppContext()
                  .getResources()
                  .getString(R.string.first_time_set_password));
        } else {
          passwordTip.setText(
              CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_0));
        }
        break;
      case 1:
        if (SettingManager.getInstance().getFirstTime()) {
          passwordTip.setText(
              CoCoinApplication.getAppContext()
                  .getResources()
                  .getString(R.string.first_time_set_password_again));
        } else {
          passwordTip.setText(
              CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_1));
        }
        break;
      case 2:
        passwordTip.setText(
            CoCoinApplication.getAppContext().getResources().getString(R.string.password_tip_2));
        break;
      default:
        break;
    }
  }
Ejemplo n.º 5
0
  private void buttonClickOperation(boolean longClick, int position) {
    switch (CURRENT_STATE) {
      case NEW_PASSWORD:
        if (CoCoinUtil.ClickButtonDelete(position)) {
          if (longClick) {
            ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE)).init();
            newPassword = "";
          } else {
            ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE))
                .clear(newPassword.length() - 1);
            if (newPassword.length() != 0)
              newPassword = newPassword.substring(0, newPassword.length() - 1);
          }
        } else if (CoCoinUtil.ClickButtonCommit(position)) {

        } else {
          ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE))
              .set(newPassword.length());
          newPassword += CoCoinUtil.BUTTONS[position];
          if (newPassword.length() == 4) {
            // finish the new password input
            CURRENT_STATE = PASSWORD_AGAIN;
            viewPager.setCurrentItem(PASSWORD_AGAIN, true);
          }
        }
        break;
      case PASSWORD_AGAIN:
        if (CoCoinUtil.ClickButtonDelete(position)) {
          if (longClick) {
            ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE)).init();
            againPassword = "";
          } else {
            ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE))
                .clear(againPassword.length() - 1);
            if (againPassword.length() != 0)
              againPassword = againPassword.substring(0, againPassword.length() - 1);
          }
        } else if (CoCoinUtil.ClickButtonCommit(position)) {

        } else {
          ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE))
              .set(againPassword.length());
          againPassword += CoCoinUtil.BUTTONS[position];
          if (againPassword.length() == 4) {
            // if the password again is equal to the new password
            if (againPassword.equals(newPassword)) {
              CURRENT_STATE = -1;
              showToast(2);
              SettingManager.getInstance().setPassword(newPassword);
              SettingManager.getInstance().setFirstTime(false);
              if (SettingManager.getInstance().getLoggenOn()) {
                User currentUser =
                    BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
                currentUser.setAccountBookPassword(newPassword);
                currentUser.update(
                    CoCoinApplication.getAppContext(),
                    currentUser.getObjectId(),
                    new UpdateListener() {
                      @Override
                      public void onSuccess() {
                        Log.d("Saver", "Set password successfully.");
                      }

                      @Override
                      public void onFailure(int code, String msg) {
                        Log.d("Saver", "Set password failed.");
                      }
                    });
              }
              final Handler handler = new Handler();
              handler.postDelayed(
                  new Runnable() {
                    @Override
                    public void run() {
                      finish();
                    }
                  },
                  1000);
            } else {
              ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE)).clear(4);
              ((PasswordChangeFragment) passwordAdapter.getItem(CURRENT_STATE - 1)).init();
              CURRENT_STATE = NEW_PASSWORD;
              viewPager.setCurrentItem(NEW_PASSWORD, true);
              newPassword = "";
              againPassword = "";
              showToast(1);
            }
          }
        }
        break;
      default:
        break;
    }
  }