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

[Draft] Feature/noid/month multiselect #797

Open
wants to merge 6 commits into
base: master
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
34 changes: 33 additions & 1 deletion src/com/android/calendar/AllInOneActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import com.android.calendar.selectcalendars.SelectVisibleCalendarsFragment;

import java.io.File;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
Expand Down Expand Up @@ -183,6 +185,7 @@ public void onAnimationStart(android.animation.Animator animation) {
private int mCalendarControlsAnimationTime;
private int mControlsAnimateWidth;
private int mControlsAnimateHeight;
private int mDaysToShowOverride;
private long mViewEventId = -1;
private long mIntentEventStartMillis = -1;
private long mIntentEventEndMillis = -1;
Expand Down Expand Up @@ -1057,7 +1060,12 @@ private void setMainPane(
case ViewType.WEEK:
default:
mNavigationView.getMenu().findItem(R.id.week_menu_item).setChecked(true);
frag = new DayFragment(timeMillis, Utils.getDaysPerWeek(this));
int daysToShow=Utils.getDaysPerWeek(this);
if(mDaysToShowOverride > 0){
daysToShow = mDaysToShowOverride;
mDaysToShowOverride = -1;
}
frag = new DayFragment(timeMillis, daysToShow);
if (mIsTabletConfig) {
mToolbar.setTitle(R.string.week_view);
}
Expand Down Expand Up @@ -1231,13 +1239,37 @@ public long getSupportedEventTypes() {
@Override
public void handleEvent(EventInfo event) {
long displayTime = -1;

if (event.eventType == EventType.GO_TO) {
if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
mBackToPreviousView = true;
} else if (event.viewType != mController.getPreviousViewType()
&& event.viewType != ViewType.EDIT) {
// Clear the flag is change to a different view type
mBackToPreviousView = false;


}

if( event.extraLong == (CalendarController.EXTRA_GOTO_DATE_RANGE | CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) ){

Calendar c = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c.setTimeInMillis(event.startTime.toMillis(false));
c2.setTimeInMillis(event.endTime.toMillis(false));

// Normalize days, let them start at midnight
c.set(Calendar.SECOND, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.SECOND, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.HOUR_OF_DAY, 0);

long days = (c2.getTimeInMillis()- c.getTimeInMillis()) / (24 * 60 * 60 * 1000);

mDaysToShowOverride = (int) days + 1;
mBackToPreviousView=true;
}

setMainPane(
Expand Down
2 changes: 2 additions & 0 deletions src/com/android/calendar/CalendarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class CalendarController {
public static final long EXTRA_GOTO_TIME = 2;
public static final long EXTRA_GOTO_BACK_TO_PREVIOUS = 4;
public static final long EXTRA_GOTO_TODAY = 8;
public static final long EXTRA_GOTO_DATE_RANGE = 9;

private static final boolean DEBUG = false;
private static final String TAG = "CalendarController";
private static WeakHashMap<Context, WeakReference<CalendarController>> instances =
Expand Down
151 changes: 149 additions & 2 deletions src/com/android/calendar/month/MonthByWeekAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Handler;
import android.os.Message;
import android.text.format.Time;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.HapticFeedbackConstants;
Expand Down Expand Up @@ -66,9 +67,18 @@ public class MonthByWeekAdapter extends SimpleWeeksAdapter {
protected ArrayList<ArrayList<Event>> mEventDayList = new ArrayList<ArrayList<Event>>();
protected ArrayList<Event> mEvents = null;
MonthWeekEventsView mClickedView;
MonthWeekEventsView mDoSelectionTapUpStart;
float mDoSelectionTapUpOffset;
private final int SELECTION_ABOVE = -1;
private final int SELECTION_BELOW = 1;
private final int SELECTION_SAMEROW = 0;
private final int LIMIT_SELECTION = 14;
int mSelectionAboveBelow = SELECTION_SAMEROW;
int mAdditionalWeeksOffset = 0;
MonthWeekEventsView mSingleTapUpView;
MonthWeekEventsView mLongClickedView;
float mClickedXLocation; // Used to find which day was clicked
float mClickedYLocation; // Used to find which day was clicked
// Perform the tap animation in a runnable to allow a delay before showing the tap color.
// This is done to prevent a click animation when a fling is done.
private final Runnable mDoClick = new Runnable() {
Expand Down Expand Up @@ -97,13 +107,60 @@ public void run() {
Log.d(TAG, "Touched day at Row=" + mSingleTapUpView.mWeek + " day=" + day.toString());
}
if (day != null) {
onDayTapped(day);
onDayTapped(day, null);
}
clearClickedView(mSingleTapUpView);
mSingleTapUpView = null;
}
}
};

private final Runnable mDoSelectionTapUp = new Runnable() {
@Override
public void run() {
if (mDoSelectionTapUpStart != null) {

Time start = mDoSelectionTapUpStart.getDayFromLocation(mClickedXLocation);
Time end = mDoSelectionTapUpStart.getDayFromLocation(mDoSelectionTapUpOffset);

if(mSelectionAboveBelow == SELECTION_ABOVE) {
end = start;
start = mDoSelectionTapUpStart.getDayFromLocation(mDoSelectionTapUpOffset);
int fullWeeksBetweenStartAndEndRow = Math.abs(mAdditionalWeeksOffset)+1;
int daysBetweeen = fullWeeksBetweenStartAndEndRow*7;
start.set(start.toMillis(false)-(daysBetweeen*24*60*60*1000));

//if the selection is larger than the limit, show only LIMIT_SELECTION days, starting with the earliest date in the selection
if((end.toMillis(false)-start.toMillis(false)) > LIMIT_SELECTION*24*60*60*1000){
start.set(end.toMillis(false)-(LIMIT_SELECTION*24*60*60*1000));
}
}

if(mSelectionAboveBelow == SELECTION_BELOW) {
int goDaysBackwards = 7*Math.abs(mAdditionalWeeksOffset);
end.set(end.toMillis(false)+(goDaysBackwards*24*60*60*1000));

//if the selection is larger than the limit, show only LIMIT_SELECTION days, starting with the earliest date in the selection
if((end.toMillis(false)-start.toMillis(false)) > LIMIT_SELECTION*24*60*60*1000){
end.set(start.toMillis(false)+(LIMIT_SELECTION*24*60*60*1000));
}
}

//Switch start&end when they are selected backwards on the same row
if(mSelectionAboveBelow == SELECTION_SAMEROW && start.toMillis(false)>=end.toMillis(false)) {
// We dont need LIMIT_SELECTION here, because we are on the same row. So max of 7 days anyway.
onDayTapped(end, start);
} else {
onDayTapped(start, end);
}


clearClickedView(mDoSelectionTapUpStart);
mDoSelectionTapUpStart = null;
mDoSelectionTapUpOffset = 0;
}
}
};
long mClickTime; // Used to calculate minimum click animation time
private boolean mAnimateToday = false;
private long mAnimateTime = 0;
Expand Down Expand Up @@ -313,8 +370,20 @@ protected void refresh() {
}

@Override
protected void onDayTapped(Time day) {
protected void onDayTapped(Time day, Time day_end) {
if(day_end == null){
Log.e(TAG, "day not set");
day_end = day;
}
setDayParameters(day);
if(day != day_end){
Log.e(TAG, "day set");
mController.sendEvent(mContext, EventType.GO_TO, day, day_end, -1,
ViewType.WEEK, CalendarController.EXTRA_GOTO_DATE_RANGE | CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS, null, null);

return;
}

if (mShowAgendaWithMonth || mIsMiniMonth) {
// If agenda view is visible with month view , refresh the views
// with the selected day's info
Expand Down Expand Up @@ -347,6 +416,13 @@ public boolean onTouch(View v, MotionEvent event) {

int action = event.getAction();

DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels/7;
int init_cell = (int) (mClickedXLocation / width);
MonthWeekEventsView mwev = (MonthWeekEventsView) v;
mwev.mSelectedDayIndexes = new ArrayList<Integer>();


// Event was tapped - switch to the detailed view making sure the click animation
// is done first.
if (mGestureDetector.onTouchEvent(event)) {
Expand All @@ -359,21 +435,86 @@ public boolean onTouch(View v, MotionEvent event) {
} else {
// Animate a click - on down: show the selected day in the "clicked" color.
// On Up/scroll/move/cancel: hide the "clicked" color.
int offset = (int) (event.getX() % width);
int cell = (int) (event.getX() / width);
switch (action) {
case MotionEvent.ACTION_DOWN:
mClickedView = (MonthWeekEventsView) v;
mClickedXLocation = event.getX();
mClickedYLocation = event.getY();
mClickTime = System.currentTimeMillis();
mListView.postDelayed(mDoClick, mOnDownDelay);
mSelectionAboveBelow = SELECTION_SAMEROW;
mAdditionalWeeksOffset = 0;
break;
case MotionEvent.ACTION_UP:
mwev.invalidate();
mListView.unblockScroll();
Log.e(TAG, "Open cells: "+((cell-init_cell)+1));

long delay = System.currentTimeMillis() - mClickTime;

int indexOfEnd = mListView.indexOfChild(v)+mwev.mSelectedDayIndexes.size();
int dayheigth = mListView.getChildAt(indexOfEnd).getHeight();
float offsetFromInitialCell = event.getY();
float rest = offsetFromInitialCell % dayheigth;
mAdditionalWeeksOffset = (int) ((offsetFromInitialCell-rest)/dayheigth);

if(offsetFromInitialCell<0){
Log.e(TAG, "Released above row! Additional full weeks:"+mAdditionalWeeksOffset);
mSelectionAboveBelow = SELECTION_ABOVE;
}

if(offsetFromInitialCell>dayheigth){
Log.e(TAG, "Released below row! Additional full weeks:"+mAdditionalWeeksOffset);
mSelectionAboveBelow = SELECTION_BELOW;
}

mDoSelectionTapUpStart = (MonthWeekEventsView) v;
mDoSelectionTapUpOffset = event.getX();

mListView.postDelayed(mDoSelectionTapUp, delay > mTotalClickDelay ? 0 : mTotalClickDelay - delay);

/*Time day = mSingleTapUpView.getDayFromLocation(event.getX());
setDayParameters(day);
mController.sendEvent(mContext, EventType.GO_TO, day, day, -1,
ViewType.DETAIL,
CalendarController.EXTRA_GOTO_DATE
| CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS, null, null);
*/

//Time day = mSingleTapUpView.getDayFromLocation(mClickedXLocation);
//Time day_n = mSingleTapUpView.getDayFromLocation(event.getX());
//mController.sendEvent(mContext, EventType.GO_TO, day, day_n, -1, ViewType.WEEK, CalendarController.EXTRA_GOTO_DATE, null, null);
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_CANCEL:
clearClickedView((MonthWeekEventsView) v);
break;
case MonthListView.MOTION_EVENT_MOVE_LISTBLOCKED:
//this "new" event allows the event to be handled, so that we can properly draw the selection.
//if we dont change the event, the selection still works, but since the event is not propagated,
//the selection does not update in the ui.
case MotionEvent.ACTION_MOVE:
// No need to cancel on vertical movement, ACTION_SCROLL will do that.
mwev.invalidate();
if (Math.abs(event.getY() - mClickedYLocation) > 15) {
//Log.e(TAG, "Vertical! "+event.getY()+" "+mClickedYLocation);
}
if (Math.abs(event.getX() - mClickedXLocation) > mMovedPixelToCancel) {
//Log.e(TAG, "Horizontal! Initial Cell: "+ init_cell +"offset:"+offset+" abs: "+event.getX() + " cell: "+(cell-init_cell));

if(init_cell<cell){
for (int i = init_cell; i <=cell; i++) {
mwev.mSelectedDayIndexes.add(i);
}
}else{
for (int i = cell; i <=init_cell; i++) {
mwev.mSelectedDayIndexes.add(i);
}
}
if( mwev.mSelectedDayIndexes.size()!=0){
mListView.blockScroll();
}
clearClickedView((MonthWeekEventsView) v);
}
break;
Expand All @@ -386,6 +527,12 @@ public boolean onTouch(View v, MotionEvent event) {
return false;
}

private void selectCellViaOffset(int offset){
ViewGroup container = (ViewGroup)mClickedView.getParent();
View nextView = container.getChildAt(container.indexOfChild(mClickedView)+offset);

mClickedView.setClickedDay(mClickedXLocation);
}
// Clear the visual cues of the click animation and related running code.
private void clearClickedView(MonthWeekEventsView v) {
mListView.removeCallbacks(mDoClick);
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/calendar/month/MonthByWeekFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
} else {
mLoader = (CursorLoader) getLoaderManager().initLoader(0, null, this);
}
mAdapter.setListView(mListView);
mAdapter.setListView((MonthListView)mListView);
}

@Override
Expand Down
24 changes: 24 additions & 0 deletions src/com/android/calendar/month/MonthListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.SystemClock;
import android.text.format.Time;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
Expand All @@ -44,11 +45,16 @@ public class MonthListView extends ListView {
private static int FLING_VELOCITY_DIVIDER = 500;
private static int FLING_TIME = 1000;


public static final int MOTION_EVENT_MOVE_LISTBLOCKED = MotionEvent.ACTION_MOVE *-1;

// disposable variable used for time calculations
protected Time mTempTime;
private long mDownActionTime;
private final Rect mFirstViewRect = new Rect();

public boolean mBlockScroll = false;

Context mListContext;

// Updates the time zone when it changes
Expand Down Expand Up @@ -91,6 +97,16 @@ private void init(Context c) {
}
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if(mBlockScroll && ev.getAction() == MotionEvent.ACTION_MOVE){
// return true;
ev.setAction(MOTION_EVENT_MOVE_LISTBLOCKED);
super.dispatchTouchEvent(ev);
}
return super.dispatchTouchEvent(ev);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
return processEvent(ev) || super.onTouchEvent(ev);
Expand Down Expand Up @@ -194,4 +210,12 @@ private int getUpperRightJulianDay() {
}
return child.getFirstJulianDay() + SimpleDayPickerFragment.DAYS_PER_WEEK - 1;
}

public void blockScroll(){
mBlockScroll=true;
}

public void unblockScroll(){
mBlockScroll=false;
}
}
Loading