Ejemplo n.º 1
0
  private void setDateField() {
    Calendar now = Calendar.getInstance();
    final DatePickerDialog dpd =
        DatePickerDialog.newInstance(
            new DatePickerDialog.OnDateSetListener() {
              @Override
              public void onDateSet(
                  DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
                Calendar newDate = Calendar.getInstance();
                newDate.set(year, monthOfYear, dayOfMonth);
                mFechaAnterior.setText(mDateFormatter.format(newDate.getTime()));
              }
            },
            now.get(Calendar.YEAR),
            now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH));

    mFechaAnterior.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) dpd.show(getFragmentManager(), "DatePickerDialog");
          }
        });

    dpd.setOnDismissListener(
        new DialogInterface.OnDismissListener() {
          @Override
          public void onDismiss(DialogInterface dialog) {
            mUltimoPago.requestFocus();
          }
        });
  }
  private void showDatePicker() {
    Calendar now = Calendar.getInstance();
    DatePickerDialog dpd =
        DatePickerDialog.newInstance(
            this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));

    dpd.show(getFragmentManager(), this.getResources().getString(R.string.date_of_birth));
  }
Ejemplo n.º 3
0
 public void transactionDateRangePickerFragment(DatePickerDialog.OnDateSetListener listener) {
   Calendar now = Calendar.getInstance();
   DatePickerDialog dpd =
       DatePickerDialog.newInstance(
           listener,
           now.get(Calendar.YEAR),
           now.get(Calendar.MONTH),
           now.get(Calendar.DAY_OF_MONTH));
   dpd.show(getFragmentManager(), "DatePicker");
 }
Ejemplo n.º 4
0
  @OnClick(R.id.date_of_birth)
  void DatePicker() {
    now = Calendar.getInstance();
    com.wdullaer.materialdatetimepicker.date.DatePickerDialog datePickerDialog;

    datePickerDialog =
        com.wdullaer.materialdatetimepicker.date.DatePickerDialog.newInstance(
            this, defaultYear, defaultMonth, defaultDate);
    datePickerDialog.show(getActivity().getFragmentManager(), DATE_TAG);
  }
Ejemplo n.º 5
0
 public static void goToday() {
   cal.setTime(new Date(System.currentTimeMillis()));
   UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK));
   ScheduleFragment.setWeekUnix((int) (System.currentTimeMillis() / 1000));
   UpdateSchedule.scroll = true;
   ScheduleFragment.createList();
   dialog =
       DatePickerDialog.newInstance(
           new DayPicker(),
           cal.get(Calendar.YEAR),
           cal.get(Calendar.MONTH),
           cal.get(Calendar.DAY_OF_MONTH));
 }
 @Override
 public void onClick(View view) {
   if (view == etDate) {
     Calendar now = Calendar.getInstance();
     DatePickerDialog dpd =
         DatePickerDialog.newInstance(
             ThemGiaoDichActivity.this,
             now.get(Calendar.YEAR),
             now.get(Calendar.MONTH),
             now.get(Calendar.DAY_OF_MONTH));
     dpd.show(getFragmentManager(), "Datepickerdialog");
   }
   if (view == btnSave) {
     setData();
     finish();
   }
   if (view == etGroup) {
     Intent intent = new Intent(ThemGiaoDichActivity.this, DanhMucActivity.class);
     startActivityForResult(intent, 2);
   }
 }
Ejemplo n.º 7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();
    assert (actionBar != null);
    actionBar.setDisplayShowTitleEnabled(false);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.getMenu().getItem(0).setChecked(true);

    // Sets the name and id in the header bar
    settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
    View headerLayout = navigationView.getHeaderView(0);
    TextView name = (TextView) headerLayout.findViewById(R.id.student_name);
    TextView id = (TextView) headerLayout.findViewById(R.id.student_id);
    name.setText(settings.getString("name", ""));
    id.setText(settings.getString("id", ""));

    progressBar = (ProgressBar) findViewById(R.id.progressBar);

    datePickerButton = (LinearLayout) findViewById(R.id.date_picker_button);
    UpdateSchedule.datePickerWeek = (TextView) findViewById(R.id.date_picker_week);
    UpdateSchedule.datePickerStudent = (TextView) findViewById(R.id.date_picker_student);
    datePickerButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            dialog.show(getFragmentManager(), "DatePickerDialog");
          }
        });

    cal = Calendar.getInstance();
    cal.setFirstDayOfWeek(Calendar.MONDAY);
    UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK));

    // TODO: Figure out the colors
    dialog =
        DatePickerDialog.newInstance(
            new DayPicker(),
            cal.get(Calendar.YEAR),
            cal.get(Calendar.MONTH),
            cal.get(Calendar.DAY_OF_MONTH));
    dialog.vibrate(false);

    resources = getResources();
    fragmentManager = getFragmentManager();

    replaceFragment(currentFragment);

    SharedPreferences.Editor editor = settings.edit();

    try {
      if (settings.getInt("version", 0)
          < getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {

        editor.putInt(
            "version", getPackageManager().getPackageInfo(getPackageName(), 0).versionCode);
        editor.apply();

        MaterialDialog.Builder update =
            new MaterialDialog.Builder(this)
                .title(R.string.update)
                .content(R.string.update_text)
                .positiveText(R.string.ok);
        update.show();
      }
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }

    if (settings.getInt("tutorial", 0) < StartActivity.TUTORIAL_VERSION) {

      editor.putInt("tutorial", StartActivity.TUTORIAL_VERSION);
      editor.apply();

      MaterialDialog.Builder tutorial =
          new MaterialDialog.Builder(this)
              .title(R.string.tutorial)
              .content(Html.fromHtml(getString(R.string.tutorial_text)))
              .positiveText(R.string.ok);
      tutorial.show();
    }

    if (!settings.getString("friends", "").equals("")) {

      Gson gson = new Gson();
      Type type = new TypeToken<List<FriendInfo>>() {}.getType();

      FriendsFragment.friendArrayList.clear();
      List<FriendInfo> friendList = gson.fromJson(settings.getString("friends", ""), type);

      for (int i = 0; i < friendList.size(); i++) {

        if (friendList.get(i).name != null && friendList.get(i).code != null) {

          FriendsFragment.friendArrayList.add(friendList.get(i));
        } else {
          Log.w("Friends", "Found null entry, skipping!");
        }
      }
    }

    invalidateOptionsMenu();
    editCallback =
        new MaterialDialog.InputCallback() {

          @Override
          public void onInput(@NonNull MaterialDialog materialDialog, CharSequence charSequence) {

            FriendsFragment.friendArrayList.get(editPosition).name = charSequence.toString();
            Collections.sort(FriendsFragment.friendArrayList, MainActivity.nameSorter);
            FriendsFragment.fa.notifyDataSetChanged();

            Gson gson = new Gson();
            String jsonFriends = gson.toJson(FriendsFragment.friendArrayList);

            SharedPreferences settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
            SharedPreferences.Editor editor = settings.edit();

            editor.putString("friends", jsonFriends);
            editor.apply();
          }
        };
    edit =
        new MaterialDialog.Builder(this)
            .title(getText(R.string.edit))
            .inputType(InputType.TYPE_CLASS_TEXT)
            .neutralText(R.string.cancel)
            .negativeText(R.string.remove)
            .onNegative(
                new MaterialDialog.SingleButtonCallback() {

                  @Override
                  public void onClick(
                      @NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {

                    FriendsFragment.friendArrayList.remove(editPosition);
                    Collections.sort(FriendsFragment.friendArrayList, MainActivity.nameSorter);
                    FriendsFragment.fa.notifyDataSetChanged();

                    Gson gson = new Gson();
                    String jsonFriends = gson.toJson(FriendsFragment.friendArrayList);

                    SharedPreferences settings = getSharedPreferences(StartActivity.PREFS_NAME, 0);
                    SharedPreferences.Editor editor = settings.edit();

                    editor.putString("friends", jsonFriends);
                    editor.apply();
                  }
                });
  }