private void initializeCalendar() { calendario.setOnDateChangedListener(listener); calendario.setShowOtherDates(MaterialCalendarView.SHOW_ALL); Calendar calendar = Calendar.getInstance(); calendario.setSelectedDate(calendar.getTime()); /*calendar.set(calendar.get(Calendar.YEAR), Calendar.JANUARY, 1); calendario.setMinimumDate(calendar.getTime()); calendar.set(calendar.get(Calendar.YEAR), Calendar.DECEMBER, 31); calendario.setMaximumDate(calendar.getTime());*/ calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -2); OneDayDecorator diaDecor = new OneDayDecorator(); ArrayList<CalendarDay> dates = new ArrayList<>(); CalendarDay cal = CalendarDay.from(calendar); dates.add(cal); // calendario.addDecorator(new EventDecorator(0xffcccccc, dates)); diaDecor.setDate(new Date(calendar.getTimeInMillis())); calendario.addDecorator(diaDecor); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_basic); ButterKnife.bind(this); widget.setOnDateChangedListener(this); widget.setOnMonthChangedListener(this); }
private void initView() { calendarView = (MaterialCalendarView) findViewById(R.id.calendarView); newSchDate = (TextView) findViewById(R.id.new_sch_date); timePicker = (TimePicker) findViewById(R.id.timePicker); newSchTime = (TextView) findViewById(R.id.new_sch_time); timePicker.setOnTimeChangedListener(this); calendarView.setOnDateChangedListener(this); calendarView.setOnMonthChangedListener(this); spinner = (Spinner) findViewById(R.id.spinner_location); setCourseNames(); schContentsNew = (EditText) findViewById(R.id.sch_contents_new); }
private String getSelectedDatesString() { CalendarDay date = calendarView.getSelectedDate(); if (date == null) { return FORMATTER.format(new Date()); } return FORMATTER.format(date.getDate()); }
public static void refreshNote(CalendarDay calendarDay) { date = String.valueOf(formatter.format(calendarDay.getDate())); add_note.setVisibility(View.VISIBLE); sched_title.setVisibility(View.VISIBLE); sched_details.setVisibility(View.GONE); note_edit_delete.setVisibility(View.GONE); if (GuideProfileFragment.notes.size() > 0) { note = getNoteByDate(date); if (note != null) { add_note.setVisibility(View.GONE); note_edit_delete.setVisibility(View.VISIBLE); sched_details.setVisibility(View.VISIBLE); sched_title.setText(note.note_title); sched_details.setText(note.note_detail); edit_note.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { showAlertDialog("Edit Note", "edit"); } }); delete_note.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.guia_dialog); builder.setTitle("Warning!"); builder.setMessage("\nAre you sure you want to delete note?\n"); builder.setNegativeButton("No", null); builder.setPositiveButton( "Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { JSONParser.getInstance(context) .deleteNote(Constants.deleteNote + note.note_id); } }); builder.show(); } }); } else { sched_title.setText("Nothing to do " + date); } } else { sched_title.setText("Nothing to do " + date); } calendar.removeDecorators(); markDates(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); widget = (MaterialCalendarView) findViewById(R.id.calendar); widget.setShowOtherDates(MaterialCalendarView.SHOW_DEFAULTS); Calendar calendar = Calendar.getInstance(); widget.setSelectedDate(calendar.getTime()); widget.setSelectionColor(R.color.colorAccent); // // widget.addDecorators( // new MySelectorDecorator(this), // oneDayDecorator // ); widget.setOnDateChangedListener(this); new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor()); }
public static void markDates() { HashSet<CalendarDay> dates = new HashSet<CalendarDay>(); for (int i = 0; i < GuideProfileFragment.notes.size(); i++) { try { dates.add(new CalendarDay(formatter.parse(GuideProfileFragment.notes.get(i).note_date))); } catch (ParseException e) { e.printStackTrace(); } if (i == GuideProfileFragment.notes.size() - 1) { calendar.addDecorator(new EventDecorator(Color.RED, dates)); } } }
@Nullable @Override public View onCreateView( final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.calendar, container, false); this.inflater = inflater; calendar = (MaterialCalendarView) view.findViewById(R.id.calendarView); sched_title = (TextView) view.findViewById(R.id.sched_title); sched_details = (TextView) view.findViewById(R.id.sched_details); add_note = (ImageView) view.findViewById(R.id.add_note); edit_note = (ImageView) view.findViewById(R.id.note_edit); delete_note = (ImageView) view.findViewById(R.id.note_delete); note_edit_delete = (LinearLayout) view.findViewById(R.id.note_edit_delete); context = getContext(); markDates(); calendar.setOnDateChangedListener( new OnDateChangedListener() { @Override public void onDateChanged( MaterialCalendarView materialCalendarView, @Nullable CalendarDay calendarDay) { // sched_details.setText(formatter.format(calendarDay.getDate())); refreshNote(calendarDay); } }); add_note.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { showAlertDialog("Create Note", "add"); } }); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample_dark_toolbar); ButterKnife.bind(this); widget.addDecorators( new MySelectorDecorator(this), new HighlightWeekendsDecorator(), oneDayDecorator); new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor()); // new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor()); // Remove line to test RTL support // getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); // Handle Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create a few sample profile // NOTE you have to define the loader logic too. See the CustomApplication for more details final IProfile profile = new ProfileDrawerItem() .withName("Minny") .withEmail("*****@*****.**") .withIcon( "https://scontent.fbkk1-1.fna.fbcdn.net/hphotos-xal1/v/t1.0-9/6599_936554129769340_1064584668432410236_n.jpg?oh=ee89ac6349e1165aaf977c27d610d1aa&oe=57449387") .withIdentifier(100); final IProfile profile2 = new ProfileDrawerItem() .withName("Bernat Borras") .withEmail("*****@*****.**") .withIcon(Uri.parse("https://avatars3.githubusercontent.com/u/887462?v=3&s=460")) .withIdentifier(101); final IProfile profile3 = new ProfileDrawerItem() .withName("Max Muster") .withEmail("*****@*****.**") .withIcon(R.drawable.profile2) .withIdentifier(102); final IProfile profile4 = new ProfileDrawerItem() .withName("Felix House") .withEmail("*****@*****.**") .withIcon(R.drawable.profile3) .withIdentifier(103); final IProfile profile5 = new ProfileDrawerItem() .withName("Mr. X") .withEmail("*****@*****.**") .withIcon(R.drawable.profile4) .withIdentifier(104); final IProfile profile6 = new ProfileDrawerItem() .withName("Batman") .withEmail("*****@*****.**") .withIcon(R.drawable.profile5) .withIdentifier(105); // Create the AccountHeader headerResult = new AccountHeaderBuilder() .withActivity(this) .withHeaderBackground(R.drawable.header) .addProfiles( profile, /*profile2, profile3, profile4, profile5, profile6,*/ // don't ask but google uses 14dp for the add account icon in gmail but 20dp for the // normal icons (like manage account) new ProfileSettingDrawerItem() .withName("Add Account") .withDescription("Add new GitHub Account") .withIcon( new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus) .actionBar() .paddingDp(5) .colorRes(R.color.material_drawer_primary_text)) .withIdentifier(PROFILE_SETTING), new ProfileSettingDrawerItem() .withName("Manage Account") .withIcon(GoogleMaterial.Icon.gmd_settings)) .withOnAccountHeaderListener( new AccountHeader.OnAccountHeaderListener() { @Override public boolean onProfileChanged(View view, IProfile profile, boolean current) { // sample usage of the onProfileChanged listener // if the clicked item has the identifier 1 add a new profile ;) if (profile instanceof IDrawerItem && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) { int count = 100 + headerResult.getProfiles().size() + 1; IProfile newProfile = new ProfileDrawerItem() .withNameShown(true) .withName("Batman" + count) .withEmail("batman" + count + "@gmail.com") .withIcon(R.drawable.profile5) .withIdentifier(count); if (headerResult.getProfiles() != null) { // we know that there are 2 setting elements. set the new profile above them // ;) headerResult.addProfile(newProfile, headerResult.getProfiles().size() - 2); } else { headerResult.addProfiles(newProfile); } } // false if you have not consumed the event and it should close the drawer return false; } }) .withSavedInstance(savedInstanceState) .build(); // Create the drawer result = new DrawerBuilder() .withActivity(this) .withToolbar(toolbar) .withHasStableIds(true) .withAccountHeader( headerResult) // set the AccountHeader we created earlier for the header .addDrawerItems( new PrimaryDrawerItem() .withName(R.string.drawer_item_profile_header) .withDescription(R.string.drawer_item_profile_header_desc) .withIcon(GoogleMaterial.Icon.gmd_face) .withIdentifier(1) .withSelectable(false), new PrimaryDrawerItem() .withName(R.string.drawer_item_Menstr_header) .withDescription(R.string.drawer_item_Menstr_header_desc) .withIcon(GoogleMaterial.Icon.gmd_favorite) .withIdentifier(2) .withSelectable(false), new PrimaryDrawerItem() .withName(R.string.drawer_item_Pregnant_header) .withDescription(R.string.drawer_item_Pregnant_header_desc) .withIcon(GoogleMaterial.Icon.gmd_alarm) .withIdentifier(3) .withSelectable(false), new PrimaryDrawerItem() .withName(R.string.drawer_item_Contracation_header) .withDescription(R.string.drawer_item_Contracation_header_desc) .withIcon(GoogleMaterial.Icon.gmd_favorite_outline) .withIdentifier(4) .withSelectable(false) /*new PrimaryDrawerItem().withName(R.string.drawer_item_compact_header).withDescription(R.string.drawer_item_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(1).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_action_bar_drawer).withDescription(R.string.drawer_item_action_bar_drawer_desc).withIcon(FontAwesome.Icon.faw_home).withIdentifier(2).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_multi_drawer).withDescription(R.string.drawer_item_multi_drawer_desc).withIcon(FontAwesome.Icon.faw_gamepad).withIdentifier(3).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_non_translucent_status_drawer).withDescription(R.string.drawer_item_non_translucent_status_drawer_desc).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(4).withSelectable(false).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)), new PrimaryDrawerItem().withName(R.string.drawer_item_advanced_drawer).withDescription(R.string.drawer_item_advanced_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_adb).withIdentifier(5).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_keyboard_util_drawer).withDescription(R.string.drawer_item_keyboard_util_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_labels).withIdentifier(6).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_embedded_drawer).withDescription(R.string.drawer_item_embedded_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery).withIdentifier(7).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_fullscreen_drawer).withDescription(R.string.drawer_item_fullscreen_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_labels).withIdentifier(8).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_custom_container_drawer).withDescription(R.string.drawer_item_custom_container_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_my_location).withIdentifier(9).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_menu_drawer).withDescription(R.string.drawer_item_menu_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_filter_list).withIdentifier(10).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_mini_drawer).withDescription(R.string.drawer_item_mini_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery_charging).withIdentifier(11).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_disc_full).withIdentifier(12).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_collapsing_toolbar_drawer).withDescription(R.string.drawer_item_collapsing_toolbar_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_camera_rear).withIdentifier(13).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_persistent_compact_header).withDescription(R.string.drawer_item_persistent_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_brightness_5).withIdentifier(14).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_crossfade_drawer_layout_drawer).withDescription(R.string.drawer_item_crossfade_drawer_layout_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_format_bold).withIdentifier(15).withSelectable(false), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName("Collapsable").withIcon(GoogleMaterial.Icon.gmd_collection_case_play).withIdentifier(19).withSelectable(false), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github).withIdentifier(20).withSelectable(false), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(GoogleMaterial.Icon.gmd_format_color_fill).withIdentifier(21).withTag("Bullhorn"), new DividerDrawerItem(), new SwitchDrawerItem().withName("Switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new SwitchDrawerItem().withName("Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false), new ToggleDrawerItem().withName("Toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new DividerDrawerItem(), new SecondarySwitchDrawerItem().withName("Secondary switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new SecondarySwitchDrawerItem().withName("Secondary Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false), new SecondaryToggleDrawerItem().withName("Secondary toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener)*/ ) // add the items we want to use with our Drawer .withOnDrawerItemClickListener( new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { // check if the drawerItem is set. // there are different reasons for the drawerItem to be null // --> click on the header // --> click on the footer // those items don't contain a drawerItem if (drawerItem != null) { Intent intent = null; if (drawerItem.getIdentifier() == 1) { intent = new Intent(DrawerActivity.this, Profile.class); } else if (drawerItem.getIdentifier() == 2) { intent = new Intent(DrawerActivity.this, Menstruation.class); } else if (drawerItem.getIdentifier() == 3) { intent = new Intent(DrawerActivity.this, Pregnant.class); } else if (drawerItem.getIdentifier() == 4) { intent = new Intent(DrawerActivity.this, Contracaption.class); } else if (drawerItem.getIdentifier() == 5) { intent = new Intent(DrawerActivity.this, AdvancedActivity.class); } else if (drawerItem.getIdentifier() == 6) { intent = new Intent(DrawerActivity.this, KeyboardUtilActivity.class); } else if (drawerItem.getIdentifier() == 7) { intent = new Intent(DrawerActivity.this, EmbeddedDrawerActivity.class); } else if (drawerItem.getIdentifier() == 8) { intent = new Intent(DrawerActivity.this, FullscreenDrawerActivity.class); } else if (drawerItem.getIdentifier() == 9) { intent = new Intent(DrawerActivity.this, CustomContainerActivity.class); } else if (drawerItem.getIdentifier() == 10) { intent = new Intent(DrawerActivity.this, MenuDrawerActivity.class); } else if (drawerItem.getIdentifier() == 11) { intent = new Intent(DrawerActivity.this, MiniDrawerActivity.class); } else if (drawerItem.getIdentifier() == 12) { intent = new Intent(DrawerActivity.this, FragmentActivity.class); } else if (drawerItem.getIdentifier() == 13) { intent = new Intent(DrawerActivity.this, CollapsingToolbarActivity.class); } else if (drawerItem.getIdentifier() == 14) { intent = new Intent(DrawerActivity.this, PersistentDrawerActivity.class); } else if (drawerItem.getIdentifier() == 15) { intent = new Intent(DrawerActivity.this, CrossfadeDrawerLayoutActvitiy.class); } else if (drawerItem.getIdentifier() == 19) { // showcase a simple collapsable functionality if (opened) { // remove the items which are hidden result.removeItems(2000, 2001); } else { int curPos = result.getPosition(drawerItem); result.addItemsAtPosition( curPos, new SecondaryDrawerItem() .withName("CollapsableItem") .withLevel(2) .withIcon(GoogleMaterial.Icon.gmd_8tracks) .withIdentifier(2000), new SecondaryDrawerItem() .withName("CollapsableItem 2") .withLevel(2) .withIcon(GoogleMaterial.Icon.gmd_8tracks) .withIdentifier(2001)); } opened = !opened; return true; } else if (drawerItem.getIdentifier() == 20) { intent = new LibsBuilder() .withFields(R.string.class.getFields()) .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR) .intent(DrawerActivity.this); } if (intent != null) { DrawerActivity.this.startActivity(intent); } } return false; } }) .withSavedInstance(savedInstanceState) .withShowDrawerOnFirstLaunch(true) .build(); // if you have many different types of DrawerItems you can magically pre-cache those items to // get a better scroll performance // make sure to init the cache after the DrawerBuilder was created as this will first clear the // cache to make sure no old elements are in RecyclerViewCacheUtil.getInstance().withCacheSize(2).init(result); // only set the active selection or active profile if we do not recreate the activity if (savedInstanceState == null) { // set the selection to the item with the identifier 11 result.setSelection(21, false); // set the active profile headerResult.setActiveProfile(profile); } result.updateBadge(4, new StringHolder(10 + "")); }
private void setTotal() { CalendarDay date = calendarView.getSelectedDate(); promise_date = new SimpleDateFormat("yyMMdd").format(date.getDate()).toString(); total = promise_date + promise_time; /* format : '%y%m%d%I%i' */ }
private void selectDate(final Date date) { mMaterialCalendarView.setCurrentDate(date); mMaterialCalendarView.setSelectedDate(date); }