Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add activity for generating events #407

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
android:name=".AsynchronousActivity"
android:label="@string/title_activity_asynchronous" >
</activity>
<activity
android:name=".TestActivity"
android:label="@string/title_activity_event_generator" >
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void onClick(View v) {
startActivity(intent);
}
});

findViewById(R.id.buttonEventGenerator).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, AsynchronousActivity.class);
startActivity(intent);
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.alamkanak.weekview.sample;

import android.graphics.Color;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;

import com.alamkanak.weekview.WeekView;
import com.alamkanak.weekview.WeekViewEvent;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
* Created by alam on 1/3/16.
*/
public class TestActivity extends BaseActivity implements WeekView.EmptyViewClickListener {

private List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
private long count = 1;
private String[] colors = new String[]{
"#59dbe0",
"#f57f68",
"#87d288",
"#f8b552"
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWeekView().setEmptyViewClickListener(this);
getWeekView().setEmptyViewLongPressListener(this);
}

@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {

List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if (eventMatches(event, newYear, newMonth)) {
matchedEvents.add(event);
}
}

return matchedEvents;
}

private boolean eventMatches(WeekViewEvent event, int year, int month) {
return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month - 1) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month - 1);
}

@Override
public void onEmptyViewClicked(Calendar time) {
time.set(Calendar.MINUTE, 0);
time.set(Calendar.SECOND, 0);
time.set(Calendar.MILLISECOND, 0);
WeekViewEvent newEvent = new WeekViewEvent(count, "Event " + count, time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), time.get(Calendar.YEAR), time.get(Calendar.MONTH) + 1, time.get(Calendar.DAY_OF_MONTH), time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE));
Calendar endTime = newEvent.getEndTime();

int random = (int )(Math.random() * 3 + 1);

endTime.add(Calendar.HOUR, random == 1 ? 2 : 1);
newEvent.setEndTime(endTime);
newEvent.setColor(Color.parseColor(colors[((int) (count % 4))]));
this.events.add(newEvent);
count++;
getWeekView().notifyDatasetChanged();
}

@Override
public void onEventClick(WeekViewEvent event, RectF eventRect) {
onEmptyViewClicked(event.getStartTime());
}

@Override
public void onEmptyViewLongPress(Calendar time) {
String json = "[";
for (WeekViewEvent event : events) {
json += String.format(
"{" +
"\"name\": \"%s\"," +
"\"dayOfMonth\": %d," +
"\"startTime\": \"%02d:%02d\"," +
"\"endTime\": \"%02d:%02d\"," +
"\"color\": \"%s\"" +
"},",
event.getName(),
event.getStartTime().get(Calendar.DAY_OF_MONTH),
event.getStartTime().get(Calendar.HOUR_OF_DAY), event.getStartTime().get(Calendar.MINUTE),
event.getEndTime().get(Calendar.HOUR_OF_DAY), event.getEndTime().get(Calendar.MINUTE),
String.format("#%06X", (0xFFFFFF & event.getColor()))
);
}
json += "]";
Log.d("TEST", json);
super.onEmptyViewLongPress(time);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public interface MyJsonService {

@GET("/4ccqb")
@GET("/3isor")
void listEvents(Callback<List<Event>> eventsCallback);

}
8 changes: 8 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@
android:text="@string/title_activity_asynchronous"
style="@style/Button"/>


<Button
android:id="@+id/buttonEventGenerator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_activity_event_generator"
style="@style/Button"/>

</LinearLayout>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="title_activity_basic">Basic Example</string>
<string name="title_activity_asynchronous">Asynchronous Events</string>
<string name="async_error">Could not download events from the internet</string>
<string name="title_activity_event_generator">Event Generator</string>
</resources>