I have learned that you cant add events to the default calendarview (it just gets handled in the user's default calendar) so I am using caldroid https://github.com/roomorama/Caldroid/blob/master/README.md which has been pretty helpful with documentation so far, but I am lost when it comes to one thing.
What I want to do is change the color of any date that has an event. The documentation says to make a drawable and put it in the cell, but I am even more lost on how to do that, so I think changing the color of the cell would be easier.
My current code looks like this
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.text.format.DateUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.roomorama.caldroid.CaldroidFragment;
import com.roomorama.caldroid.CaldroidListener;
import java.util.Calendar;
import java.util.Date;
public class CalendarActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendarLayout, caldroidFragment);
t.commit();
final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
Toast.makeText(getApplicationContext(), date.toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + date.toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onCaldroidViewCreated() {
Toast.makeText(getApplicationContext(),
"Caldroid view is created",
Toast.LENGTH_SHORT).show();
}
};
caldroidFragment.setCaldroidListener(listener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_calendar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have checked here Change Color of cell of grid here Using an intent to edit calendar event doesn't work here Caldroid does not refresh and here I want to change font color of events on calendar and I am not sure what to do.
I know I can change the color of a date with caldroidFragment.setBackgroundResourceForDate(R.color.blue, blueDate); but I am not sure how to make that correspond to a date which has an event. If anyone can help me out, it would be greatly appreciated. Also, happy mothers day!
I have just stumbled across this code and am in the process of implementing it.
@Override public void onSelectDate(Date date, View view) { Toast.makeText(getApplicationContext(), formatter.format(date), Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + formatter.format(date),
Toast.LENGTH_SHORT).show();Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", System.currentTimeMillis());
intent.putExtra("endTime", System.currentTimeMillis()+60000);
intent.putExtra("title", "hiii");
startActivity(intent);
caldroidFragment.refreshView();
}
@Override
public void onCaldroidViewCreated() {
if (caldroidFragment.getLeftArrowButton() != null) {
Toast.makeText(getApplicationContext(),
"Caldroid view is created", Toast.LENGTH_SHORT)
.show();
}
}
};final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
Toast.makeText(getApplicationContext(), formatter.format(date),
Toast.LENGTH_SHORT).show();
}
@Override
public void onChangeMonth(int month, int year) {
String text = "month: " + month + " year: " + year;
Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT).show();
}
@Override
public void onLongClickDate(Date date, View view) {
Toast.makeText(getApplicationContext(),
"Long click " + formatter.format(date),
Toast.LENGTH_SHORT).show();Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", System.currentTimeMillis());
intent.putExtra("endTime", System.currentTimeMillis()+60000);
intent.putExtra("title", "hiii");
startActivity(intent);
caldroidFragment.refreshView();
}
@Override
public void onCaldroidViewCreated() {
if (caldroidFragment.getLeftArrowButton() != null) {
Toast.makeText(getApplicationContext(),
"Caldroid view is created", Toast.LENGTH_SHORT)
.show();
}
}
};