Skip to content

Commit

Permalink
Improve tap detection on interactive clock
Browse files Browse the repository at this point in the history
  • Loading branch information
falzonv committed Mar 2, 2024
1 parent 846f00e commit 7c8e595
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX,
// Ignore the gesture if the applications drawer is opened
if(drawer.getVisibility() == View.VISIBLE) return false ;

// Ignore incomplete gestures (may happen due to the interactive clock)
if((event1 == null) || (event2 == null)) return false ;

// Calculate the traveled distances on both axes
float x_distance = event1.getX() - event2.getX() ;
float y_distance = event1.getY() - event2.getY() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,33 @@ public boolean onTouch(View view, MotionEvent event)
int x = Math.round(event.getX()) ;
int y = Math.round(event.getY()) ;

// If the touch was in the time area, try to start the selected clock app
if(rect_time.contains(x, y) && (event.getAction() == MotionEvent.ACTION_DOWN))
return Utils.searchAndStartApplication(this, settings, Constants.CLOCK_APP) ;
// If the touch starts and ends in the time area, try to start the selected clock app
if(rect_time.contains(x, y))
{
if(event.getAction() == MotionEvent.ACTION_DOWN) return true ;
if(event.getAction() == MotionEvent.ACTION_UP)
return Utils.searchAndStartApplication(this, settings, Constants.CLOCK_APP) ;
}

// If the touch was in the date area, try to start the default calendar
if(rect_date.contains(x, y) && (event.getAction() == MotionEvent.ACTION_DOWN))
// If the touch starts and ends in the time area, try to start the default calendar
if(rect_date.contains(x, y))
{
try
{
Intent calendarIntent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALENDAR) ;
calendarIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
getContext().startActivity(calendarIntent) ;
return true ;
}
catch(ActivityNotFoundException|NullPointerException exception)
{
Utils.displayLongToast(getContext(), getContext().getString(R.string.error_app_not_found, "{calendar}")) ;
return false ;
}
if(event.getAction() == MotionEvent.ACTION_DOWN) return true ;
if(event.getAction() == MotionEvent.ACTION_UP)
{
try
{
Intent calendarIntent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALENDAR) ;
calendarIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
getContext().startActivity(calendarIntent) ;
return true ;
}
catch(ActivityNotFoundException|NullPointerException exception)
{
Utils.displayLongToast(getContext(), getContext().getString(R.string.error_app_not_found, "{calendar}")) ;
return false ;
}
}
}

// Do not handle touchs outside the date/time areas
Expand Down

0 comments on commit 7c8e595

Please sign in to comment.