can someone tell me how to change specific color to a caldroid calendar - caldroid

I'm working on an islamic app that show hijri calendar and also applying events like adding a specific date, time, event title and subject of that date so I want that when the app starts and displays calendar then the events' dates have different color.
caldroidFragment.setCaldroidListener(new CaldroidListener() {
#SuppressWarnings("deprecation")
#Override
public void onSelectDate(Date date, View view) {
// TODO Auto-generated method stub
// caldroidFragment.setSelectedDates(date, date);
Calendar text=Calendar.getInstance();
text.clear();
// text.set(Calendar.);
int d=(int) date.getDate();
int m=(int) date.getMonth();
int y=(int) date.getYear();
text.set(Calendar.YEAR, y+1900);
text.set(Calendar.MONTH, m);
text.set(Calendar.DATE, d);
hijridate.setText(HijriCalendarDate.getSimpleDate(text, 0));
}
}
enter link description here

You should use setBackgroundDrawableForDates method of caldroid object and pass the map with dates as keys and Drawable as value. Something like this:
import android.graphics.drawable.ColorDrawable;
final Map<Date, Drawable> backgroundForDateMap = new HashMap<>();
final Calendar c = Calendar.getInstance();
// 1. date
c.set(2016, Calendar.MAY, 1);
backgroundForDateMap.put(c.getTime(), new ColorDrawable(Color.GREEN));
// 2. date
c.set(2016, Calendar.MAY, 2);
backgroundForDateMap.put(c.getTime(), new ColorDrawable(Color.YELLOW));
caldroidFragment.setBackgroundDrawableForDates(backgroundForDateMap);

Related

Parse an actual time to TimePicker

I'm new here so bare a bit with me. And yes i tried to google my question but really wasn't shure about the answers i found either.
So here's my problem:
I want to build an App where the User can select a Times from clicking different Buttons, and then calculate the Timedifference between.
The ButtonClick opens the TimePicker Dialog and the Examplecode i found on Microsoft Docs uses always the actual time. What i want is to use the last valid time from parsing the Buttontext. But i have no idea how to pass the ID of the senderbutton to the TimePicker class.
Here's the Eventhandler from the Button:
void TimeSelectOnClick (object sender, EventArgs eventArgs)
{
// Instantiate a TimePickerFragment (defined below)
TimePickerFragment frag = TimePickerFragment.NewInstance (
// Create and pass in a delegate that updates the Activity time display
// with the passed-in time value:
delegate (DateTime time)
{
timeSelectButton.Text = time.ToString("HH:mm");
});
// Launch the TimePicker dialog fragment (defined below):
frag.Show(FragmentManager, TimePickerFragment.TAG);
}
and here's the TimePicker dialog fragment:
// TimePicker dialog fragment
public class TimePickerFragment : DialogFragment, TimePickerDialog.IOnTimeSetListener
{
// TAG used for logging
public static readonly string TAG = "MyTimePickerFragment";
// Initialize handler to an empty delegate to prevent null reference exceptions:
Action<DateTime> timeSelectedHandler = delegate { };
// Factory method used to create a new TimePickerFragment:
public static TimePickerFragment NewInstance(Action<DateTime> onTimeSelected)
{
// Instantiate a new TimePickerFragment:
TimePickerFragment frag = new TimePickerFragment();
// Set its event handler to the passed-in delegate:
frag.timeSelectedHandler = onTimeSelected;
// Return the new TimePickerFragment:
return frag;
}
// Create and return a TimePickerDemo:
public override Dialog OnCreateDialog (Bundle savedInstanceState)
{
//Set the TimePicker default time
//Here i Want to parse the time from the button something like DateTime.Parse(buttonID.Text);
//Either with current time or parsed time... how to pass values from the sender button i have no idea
DateTime currentTime = DateTime.Parse("06:00");
// force 24-hour time format:
bool is24HourFormat = true;
// Instantiate a new TimePickerDemo, passing in the handler, the current
// time to display, and whether or not to use 24 hour format:
TimePickerDialog dialog = new TimePickerDialog
(Activity, this, currentTime.Hour, currentTime.Minute, is24HourFormat);
// Return the created TimePickerDemo:
return dialog;
}
// Called when the user sets the time in the TimePicker:
public void OnTimeSet(TimePicker view, int hourOfDay, int minute)
{
// Get the current time:
DateTime currentTime = DateTime.Now;
// Create a DateTime that contains today's date and the time selected by the user:
DateTime selectedTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, hourOfDay, minute, 0);
// Log the date and selected time:
Log.Debug(TAG, selectedTime.ToLongTimeString());
// Invoke the handler to update the Activity's time display to the selected time:
timeSelectedHandler (selectedTime);
}
}
thanks in advance to anybody here on Stackoverflow! You guys really do a great Job!
Cheers
You could add a property in TimePickerFragment
static string TimeString;
public static TimePickerFragment NewInstance(Action<DateTime> onTimeSelected,string time)
{
// Instantiate a new TimePickerFragment:
TimePickerFragment frag = new TimePickerFragment();
// Set its event handler to the passed-in delegate:
frag.timeSelectedHandler = onTimeSelected;
TimeString = time;
// Return the new TimePickerFragment:
return frag;
}
in Activity
TimePickerFragment frag = TimePickerFragment.NewInstance (
// Create and pass in a delegate that updates the Activity time display
// with the passed-in time value:
delegate (DateTime time)
{
timeSelectButton.Text = time.ToString("HH:mm");
},buttonID.Text);
And you can modify it in any place
TimePickerFragment.TimeString = "xxx";

Mouse Click Events on JTable

I want to get the index of selected row when user double clicks on a row.
Here is my code:
tab.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int selectedRow = tab.getSelectedRow();
try {
String file = rows[selectedRow][2];
String path = "C:\\Users\\raj kumar\\Gallery\\" + file;
JLabel fileLable = new JLabel();
fileLable.setBounds(500, 600, 300, 300);
fileLable.setIcon(new ImageIcon(path));
pan.add(fileLable);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
But the tab.getSelectedRow() returns -1 even though I double clicked the row in the table.
You want to know on which row your mouse points, but you ask which row is selected. So the simple solution is, instead of
int selectedRow = tab.getSelectedRow();
you can use
int row = tab.rowAtPoint(e.getPoint());
to get the wanted row. The Event e has every necessary information you need. The e.getPoint() returns the exact Point your cursor is currently located. And the rowAtPoint() should be self explaining.
This also makes sure that you only work with one row at a time, if this is important to you. I don't know how getSelectedRow() works if multiple rows are selected.

Xamarin Android can't set new event's date

I can create a new Event in calendar, but I can't set the datetime of the event.
I can set the Location, title, description and so on.
When debugging, I can see the variables dtStart and dtEnd corretly (for testing, I'm using the string "15/05/2016 15:00:00" in the format dd/MM/yyyy hh:mm:ss - brasilian pattern)
Thank you for your help!
btnAdicionarAgenda.Click += delegate
{
Intent calIntent = new Intent(Intent.ActionInsert);
calIntent.SetData(CalendarContract.Events.ContentUri);
calIntent.SetType("vnd.android.cursor.item/event");
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Title, calendarTitle);
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Description, calendarDescription);
DateTime dtStart = DateTime.ParseExact(retNotificacao.get("dt_evento"), "dd/MM/yyyy HH:mm:ss",
System.Globalization.CultureInfo.InvariantCulture);
DateTime dtEnd = dtStart.AddHours(1);
long lDtStart = Utils.GetDateTimeMS(dtStart.Year, dtStart.Month, dtStart.Day, dtStart.Hour, dtStart.Minute);
long lDtEnd = Utils.GetDateTimeMS(dtEnd.Year, dtEnd.Month, dtEnd.Day, dtEnd.Hour, dtEnd.Minute);
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtstart, lDtStart);
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtend, lDtEnd);
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.EventTimezone, "UTC");
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "UTC");
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.EventLocation, Session.nmEscolaAluno);
StartActivity(calIntent);
};
Utils.cs:
public static long GetDateTimeMS(int yr, int month, int day, int hr, int min)
{
Calendar c = Calendar.GetInstance(Java.Util.TimeZone.Default);
c.Set(Calendar.DayOfMonth, day);
c.Set(Calendar.HourOfDay, hr);
c.Set(Calendar.Minute, min);
c.Set(Calendar.Month, month);
c.Set(Calendar.Year, yr);
return c.TimeInMillis;
}
Do NOT use Dtstart and Dtend, the documentation and examples that are posted (Google's and Xamarin's) are just wrong.
The string consts should be "EXTRA_EVENT_BEGIN_TIME" and "EXTRA_EVENT_END_TIME".
Change:
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtstart, lDtStart);
calIntent.PutExtra(CalendarContract.Events.InterfaceConsts.Dtend, lDtEnd);
To:
calIntent.PutExtra(CalendarContract.ExtraEventBeginTime, lDtStart);
calIntent.PutExtra(CalendarContract.ExtraEventEndTime, lDtEnd);
Results of "15/05/2016 15:00:00" (plus one hour):
Start msec: 1466028054652
End msec: 1466031654659
Screen cap of event created:

Android Google Maps API v2 onInfoWindowClick triggers on create of activity all listeners

Hi i have a map with a lot of markers. When i add the markers to the map i want to add an onInfoWindowClick Listener to each marker with individual data. I want to load an activety with informations of the marker with the onInfoWindowClick Listener.
The code do not work correct. When the activety is created all the listeners are triggered at the same time and when i click on the infoWindow nothing happens.
private void addMarkerToMap(double lat, double lng, String eventTitle,
String eventDiscribtion) {
Marker currentMarker = myMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng)).title(eventTitle)
.snippet(eventDiscribtion));
onInfoWindowClick(currentMarker);
}
#Override
public void onInfoWindowClick(Marker marker) {
Intent nextScreen = new Intent(MapsActivity.this,
EventActivity.class);
nextScreen.putExtra("userId", "" + userId);
nextScreen.putExtra("eventId", "" + eventId);
startActivityForResult(nextScreen, 0);
}
You would implement the onclick behavior within your GoogleMap Object (myMap)
myMap.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
Intent nextScreen = new Intent(MapsActivity.this,EventActivity.class);
nextScreen.putExtra("userId", "" + userId);
nextScreen.putExtra("eventId", "" + eventId);
startActivityForResult(nextScreen, 0);
}
}
)
check out this post about how to associate information or objects to markers:
http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

JfreeChart limit the number of legend items displayed

I'm in charge of maintaining an application which can draw graphs using JFreeChart.
The application is written in Eclipse-RCP and SWT and use a ChartComposite to display the charts.
The ChartComposite has been partially overridden in order to customize contextual menus depending on the selection:
#Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
chart = createChart(timeSeriesDataset);
chartComposite = new MyChartComposite(this, parent, SWT.NONE, chart, true);
chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
selectionProvider = new GenericObjectSelectionProvider();
getSite().setSelectionProvider(selectionProvider);
// add information to the status line:
selectionProvider.addSelectionChangedListener(statusLineListener);
addDropSupport();// add D'n D support for dropping TimeSeries
}
protected JFreeChart createChart(TimeSeriesCollection ptimeSeriesDataset) {
JFreeChart vChart = ChartFactory.createTimeSeriesChart(null, "time", "values", ptimeSeriesDataset, true,
false, false);
vChart.setBackgroundPaint(Color.white);
XYPlot plot = vChart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
// plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
plot.setRenderer(new /*OptimisedXYLineAndShapeRenderer()*/ StandardXYItemRendererFast());
XYItemRenderer renderer = plot.getRenderer();
renderer.setBaseToolTipGenerator(new MyXYSeriesToolTipGenerator());
renderer.setBaseItemLabelGenerator(new MyXYSeriesItemLabelGenerator());
renderer.setLegendItemLabelGenerator(new MyXYSeriesLegendItemLabelGenerator());
if (renderer instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer;
r.setBaseShapesVisible(false);
r.setBaseShapesFilled(true);
}
SimpleDateFormat dateFormat = getDateFormatAbscissa();
if (dateFormat != null){
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(dateFormat);
}
return vChart;
}
My problem is that when too many variables are added to the chart (a TimeSeriesChart) the caption takes too much space and the graph disappears from the view:
ChartComposite with 2 series
ChartComposite many series
I tried to create a ScrollComposite to scroll in the ChartComposite and the result is a little better; but it only makes it possible to add more items in the caption before the graph disappears again:
ScrolledComposite scrollableChart = new ScrolledComposite(parent, SWT.BORDER|SWT.V_SCROLL);
chartComposite = new MyChartComposite(this, scrollableChart, SWT.NONE, chart, true);
//chartComposite = new MyChartComposite(this, parent, SWT.NONE, chart, true);
//chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
scrollableChart.setContent(chartComposite);
scrollableChart.setExpandVertical(true);
scrollableChart.setExpandHorizontal(true);
scrollableChart.setMinSize(ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH);
My question is: How to provide a real scrollbar to the ChartComposite in order to keep the graph when many series are plotted on the graph?
I was able to sync a slider to the XYSeries in SWT using a ChartComosite and Slider objects through the use of FormData. And every time I move the slider I capture that event and update the chart myself according to my needs.
My use case may be different than yours, but it's worth to take a look to my answer here.
If you have questions regarding my implementation, described in that answer, feel free to ask for details
After several unsuccessful tries, I decided to limit the number of LegendItem shown on the chart.
To change the legend items to display in the LegendTitle I used a slider. The most difficult part was to recreate the a new LegendTitle when using the slider; I am not sure that my solution is optimal or elegant but at least it is working.
To make this possible I needed to listen to series creation (ChartChangeEventType.DATASET_UPDATED) to refresh the LegendTitle and set slider values.
So here is the code:
public class MyExampleChartComposite extends ChartComposite {
// snip
/**
* A slider to choose the legend items to display
*/
private Slider legendSlider;
/**
* Number of legend items to display on the chart
*/
private final static int NUMBER_OF_LEGENDITEMS_TO_DISPLAY = 10;
private void createPartControl(Composite parent, int style) {
JFreeChart chart = createChart();
setChart(chart);
legendSlider = new Slider(parent, SWT.NONE|SWT.H_SCROLL);
legendSlider.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent arg0) {
refreshLegend();
}
});
private JFreeChart createChart() {
chart.addChangeListener(new ChartChangeListener() {
#Override
public void chartChanged(ChartChangeEvent e) {
if (e.getType().equals(ChartChangeEventType.DATASET_UPDATED)) {
refreshLegend();
}
}
});
}
/**
* Refresh the the LegendItems and the slider,
* according to slider selection.
*/
public void refreshLegend() {
// Display LegendItems according to the selection
// display the 10 nearest legend item (current selected element included)
int begin = legendSlider.getSelection() - (NUMBER_OF_LEGENDITEMS_TO_DISPLAY/2);
int end = legendSlider.getSelection() + (NUMBER_OF_LEGENDITEMS_TO_DISPLAY/2 -1);
int seriesEndIndex = Math.max(getSeriesCount()-1, 0);
// if begin is less than 0
// set it to 0, and increase end to display 10 items
if (begin < 0) {
begin = 0;
end = NUMBER_OF_LEGENDITEMS_TO_DISPLAY - 1;
}
// if end is greater than the number of series plotted
// set it to the max possible value and increase begin to
// display 10 items
if (end > seriesEndIndex) {
end = seriesEndIndex;
begin = seriesEndIndex - (NUMBER_OF_LEGENDITEMS_TO_DISPLAY - 1);
}
end = Math.min(seriesEndIndex, end);
begin = Math.max(begin, 0);
// Refresh only if begin != end
if (end != begin) {
refreshLegendItems(begin, end);
refreshLegendSlider();
} else {
// in this case no more series are plotted on the chart
// clear legend
getChart().clearSubtitles();
}
}
/**
* Refresh the LegendTitle.
* Display only LegendItems between beginIndex and toIndex,
* to preserve space for the chart.
* #param beginIndex index of the {#link LegendItemCollection} used as the beginning of the new {#link LegendTitle}
* #param endIndex index of the {#link LegendItemCollection} used as the end of the new {#link LegendTitle}
*/
private void refreshLegendItems(int beginIndex, int endIndex) {
// Last 10 items
final LegendItemCollection result = new LegendItemCollection();
// get the renderer to retrieve legend items
XYPlot plot = getChart().getXYPlot();
XYItemRenderer renderer = plot.getRenderer();
// Number of series displayed on the chart
// Construct the legend
for (int i = beginIndex; i <= endIndex; i++) {
LegendItem item = renderer.getLegendItem(0, i);
result.add(item);
}
// Because the only way to create a new LegendTitle is to
// create a LegendItemSource first
LegendItemSource source = new LegendItemSource() {
LegendItemCollection lic = new LegendItemCollection();
{lic.addAll(result);}
public LegendItemCollection getLegendItems() {
return lic;
}
};
// clear previous legend title
getChart().clearSubtitles();
// Create the new LegendTitle and set its position
LegendTitle legend = new LegendTitle(source);
legend.setHorizontalAlignment(HorizontalAlignment.CENTER);
legend.setVerticalAlignment(VerticalAlignment.CENTER);
legend.setPosition(RectangleEdge.BOTTOM);
legend.setBorder(1.0, 1.0, 1.0, 1.0);
legend.setVisible(true);
// Add the LegendTitle to the graph
getChart().addLegend(legend);
}
/**
* Set values of the slider according to the number of series
* plotted on the graph
*/
private void refreshLegendSlider() {
int max = getSeriesCount() -1;
int selection = Math.min(legendSlider.getSelection(), max);
legendSlider.setValues(selection, 0, max, 1, 1, 1);
}
}

Resources