Added colors to schedule

This commit is contained in:
Caesar2011
2018-07-30 20:47:05 +02:00
parent ac0e31f6a3
commit bb3dfcedb7
10 changed files with 130 additions and 21 deletions

View File

@@ -39,7 +39,6 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
private WeekView mWeekView;
private Logger log = new Logger(this);
private Modules mModules = null;
private Calendar firstVisibleDay;
public ScheduleFragment() {
// Required empty public constructor
@@ -133,7 +132,9 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
Calendar start = Calendar.getInstance();
start.setTimeInMillis(e.getStartDate());
events.add(new WeekViewEvent(e.getId(), e.getTitle(), start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, start.get(Calendar.DAY_OF_MONTH), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), ende.get(Calendar.YEAR), ende.get(Calendar.MONTH) + 1, ende.get(Calendar.DAY_OF_MONTH), ende.get(Calendar.HOUR_OF_DAY), ende.get(Calendar.MINUTE)));
WeekViewEvent weekViewEvent = new WeekViewEvent(e.getId(), e.getTitle(), start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, start.get(Calendar.DAY_OF_MONTH), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), ende.get(Calendar.YEAR), ende.get(Calendar.MONTH) + 1, ende.get(Calendar.DAY_OF_MONTH), ende.get(Calendar.HOUR_OF_DAY), ende.get(Calendar.MINUTE));
weekViewEvent.setColor(e.getColor());
events.add(weekViewEvent);
}
}
}
@@ -147,7 +148,6 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
@Override
public void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay) {
firstVisibleDay = newFirstVisibleDay;
Calendar newLastVisibleDay = (Calendar) newFirstVisibleDay.clone();
newLastVisibleDay.add(Calendar.HOUR, 24*mWeekView.getNumberOfVisibleDays());
//mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
@@ -161,6 +161,7 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
@Override
public void mOnDoubleTapListener(Calendar time) {
Calendar firstVisibleDay = mWeekView.getFirstVisibleDay();
Calendar c = Calendar.getInstance();
c.set(firstVisibleDay.get(Calendar.YEAR), firstVisibleDay.get(Calendar.MONTH), firstVisibleDay.get(Calendar.DAY_OF_MONTH), 0,0 );
c.add(Calendar.DATE, 2); // die Grenze beim tippen, wann ver nach vorne und wann nach hinten springt

View File

@@ -352,9 +352,10 @@ public class KVVModuleList extends HTTPService {
String id = site.getString("eventId");
String type = site.getString("type");
String title = site.getString("title");
String siteId = site.getString("siteId");
long duration = site.getLong("duration");
long firstTime = site.getJSONObject("firstTime").getLong("time");
events.add(new Event(id, type, title, duration, firstTime));
events.add(new Event(id, type, title, duration, firstTime, siteId));
}
} catch (JSONException e) {
e.printStackTrace();

View File

@@ -1,6 +1,12 @@
package de.sebse.fuplanner.services.KVV.types;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import de.sebse.fuplanner.tools.ColorRGB;
import de.sebse.fuplanner.tools.logging.Logger;
public class Event implements Serializable {
private final String id;
@@ -8,13 +14,15 @@ public class Event implements Serializable {
private final String title;
private final long duration;
private final long firstTime;
private String siteId;
public Event(String id, String type, String title, long duration, long firstTime) {
public Event(String id, String type, String title, long duration, long firstTime, String siteId) {
this.id = id;
this.type = type;
this.title = title;
this.duration = duration;
this.firstTime = firstTime;
this.siteId = siteId;
}
public String getId() {
@@ -37,6 +45,53 @@ public class Event implements Serializable {
return this.firstTime+this.duration;
}
public ColorRGB getColor() {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
byte[] encodedHash;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
encodedHash = digest.digest(siteId.getBytes(StandardCharsets.UTF_8));
} else {
encodedHash = digest.digest(siteId.getBytes());
}
int h = (0xff & encodedHash[0]) + (0xff & encodedHash[1]) * 255;
h = h * 360 / 0xffff;
int s = 0xff & encodedHash[2];
s = s * 100 / 0xffff;
int v = 0xff & encodedHash[3];
v = v * 100 / 0xffff;
// range for more beautiful colors
h = h / 30 * 30;
s = 100;
v = 50;
return hsvToRgb(h/360.0, s/100.0, v/100.0);
}
public static ColorRGB hsvToRgb(double hue, double saturation, double value) {
int h = (int)(hue * 6);
double f = hue * 6 - h;
double p = value * (1 - saturation);
double q = value * (1 - f * saturation);
double t = value * (1 - (1 - f) * saturation);
switch (h) {
case 0: return new ColorRGB(value, t, p);
case 1: return new ColorRGB(q, value, p);
case 2: return new ColorRGB(p, value, t);
case 3: return new ColorRGB(p, q, value);
case 4: return new ColorRGB(t, p, value);
case 5: return new ColorRGB(value, p, q);
default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
}
}
@Override
public String toString() {
return "ID: "+getId()+

View File

@@ -0,0 +1,7 @@
package de.sebse.fuplanner.tools;
import android.graphics.Paint;
public interface Color {
void setPaintColor(Paint paint);
}

View File

@@ -0,0 +1,24 @@
package de.sebse.fuplanner.tools;
import android.graphics.Paint;
public class ColorRGB implements Color {
private final int mRed;
private final int mGreen;
private final int mBlue;
public ColorRGB(int red, int green, int blue) {
this.mRed = red;
this.mGreen = green;
this.mBlue = blue;
}
public ColorRGB(double red, double green, double blue) {
this((int) (red*255), (int) (green*255), (int) (blue*255));
}
@Override
public void setPaintColor(Paint paint) {
paint.setARGB(255, mRed, mGreen, mBlue);
}
}

View File

@@ -0,0 +1,17 @@
package de.sebse.fuplanner.tools;
import android.graphics.Paint;
import android.support.annotation.ColorInt;
public class ColorRes implements Color {
@ColorInt private final int mResId;
public ColorRes(@ColorInt int color) {
this.mResId = color;
}
@Override
public void setPaintColor(Paint paint) {
paint.setColor(mResId);
}
}

View File

@@ -46,6 +46,7 @@ import java.util.List;
import java.util.Locale;
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.tools.ColorRes;
import de.sebse.fuplanner.tools.DateUtils;
import de.sebse.fuplanner.tools.logging.Logger;
@@ -394,7 +395,7 @@ public class WeekView extends View {
bottom > 0
) {
RectF dayRectF = new RectF(left, top, right, bottom - mCurrentOrigin.y);
newEvent.setColor(mNewEventColor);
newEvent.setColor(new ColorRes(mNewEventColor));
mNewEventRect = new EventRect(newEvent, newEvent, dayRectF);
tempEvents.add(newEvent);
WeekView.this.clearEvents();
@@ -1100,7 +1101,10 @@ public class WeekView extends View {
bottom > mHeaderHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom
) {
mEventRects.get(i).rectF = new RectF(left, top, right, bottom);
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
if (mEventRects.get(i).event.getColor() != null)
mEventRects.get(i).event.getColor().setPaintColor(mEventBackgroundPaint);
else
mEventBackgroundPaint.setColor(mDefaultEventColor);
mEventBackgroundPaint.setShader(mEventRects.get(i).event.getShader());
canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
float topToUse = top;
@@ -1153,7 +1157,10 @@ public class WeekView extends View {
bottom > 0
) {
mEventRects.get(i).rectF = new RectF(left, top, right, bottom);
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
if (mEventRects.get(i).event.getColor() != null)
mEventRects.get(i).event.getColor().setPaintColor(mEventBackgroundPaint);
else
mEventBackgroundPaint.setColor(mDefaultEventColor);
mEventBackgroundPaint.setShader(mEventRects.get(i).event.getShader());
canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left);

View File

@@ -1,12 +1,13 @@
package de.sebse.fuplanner.tools.ui.weekview;
import android.graphics.Shader;
import android.support.annotation.ColorInt;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import de.sebse.fuplanner.tools.Color;
import static de.sebse.fuplanner.tools.ui.weekview.WeekViewUtil.isSameDay;
@@ -20,9 +21,7 @@ public class WeekViewEvent {
private Calendar mEndTime;
private String mName;
private String mLocation;
private
@ColorInt
int mColor;
private Color mColor;
private boolean mAllDay;
private Shader mShader;
@@ -237,13 +236,11 @@ public class WeekViewEvent {
this.mLocation = location;
}
public
@ColorInt
int getColor() {
public Color getColor() {
return mColor;
}
public void setColor(int color) {
public void setColor(Color color) {
this.mColor = color;
}
@@ -307,7 +304,7 @@ public class WeekViewEvent {
endTime.set(Calendar.HOUR_OF_DAY, 23);
endTime.set(Calendar.MINUTE, 59);
WeekViewEvent event1 = new WeekViewEvent(this.getIdentifier(), this.getName(), this.getLocation(), this.getStartTime(), endTime, this.isAllDay());
event1.setColor(this.getColor());
event1.setColor(this.mColor);
events.add(event1);
// Add other days.
@@ -321,7 +318,7 @@ public class WeekViewEvent {
endOfOverDay.set(Calendar.HOUR_OF_DAY, 23);
endOfOverDay.set(Calendar.MINUTE, 59);
WeekViewEvent eventMore = new WeekViewEvent(this.getIdentifier(), this.getName(), null, overDay, endOfOverDay, this.isAllDay());
eventMore.setColor(this.getColor());
eventMore.setColor(this.mColor);
events.add(eventMore);
// Add next day.
@@ -333,7 +330,7 @@ public class WeekViewEvent {
startTime.set(Calendar.HOUR_OF_DAY, 0);
startTime.set(Calendar.MINUTE, 0);
WeekViewEvent event2 = new WeekViewEvent(this.getIdentifier(), this.getName(), this.getLocation(), startTime, this.getEndTime(), this.isAllDay());
event2.setColor(this.getColor());
event2.setColor(this.mColor);
events.add(event2);
} else {
events.add(this);

View File

@@ -31,7 +31,7 @@
<string name="past_events">Vergangene Veranstaltungen</string>
<string name="events">Veranstaltungen</string>
<string name="gradebook">Noten</string>
<string name="Current_percentage">Aktuelle Prozentzahl</string>
<string name="current_percentage">Aktuelle Prozentzahl</string>
<string name="offline_mode">Offline-Modus</string>
<string name="refresh_failed">Aktualisieren fehlgeschlagen…</string>
<string name="share_intent">Hey, schau\' dir die neue KVV App an: %1$s</string>

View File

@@ -37,7 +37,7 @@
<string name="past_events">Past Events</string>
<string name="events">Events</string>
<string name="gradebook">Gradebook</string>
<string name="Current_percentage">Current Percentage</string>
<string name="current_percentage">Current Percentage</string>
<string name="offline_mode">Offline Mode</string>
<string name="refresh_failed">Refresh failed…</string>
<string name="share_intent">Hey, check out the new KVV app: %1$s</string>