Convert Kotlin WeekView Class to Java Code
import android.content.Context; import android.graphics.Paint; import android.graphics.PointF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.text.TextPaint; import android.util.AttributeSet; import android.util.TypedValue; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; import android.widget.OverScroller;
import androidx.annotation.ColorInt; import androidx.core.content.ContextCompat; import androidx.core.view.GestureDetectorCompat; import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutLinearInInterpolator;
import java.util.ArrayList; import java.util.Calendar; import java.util.List;
class WeekView extends View {
private final DrawPerformanceTester drawPerformanceTester = new DrawPerformanceTester(false);
private Calendar mHomeDate;
private Calendar minDate;
private Calendar maxDate;
private final TextPaint timeTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint mHeaderWeekDayTitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint mHeaderWeekDaySubtitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint mHeaderWeekDayTitleTodayTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint mHeaderWeekDaySubtitleTodayTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint mEventTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
private final TextPaint sideTitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint sideSubtitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final TextPaint allDaySideTitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final Paint mEmptyEventPaint = new Paint();
private final Paint mHeaderBackgroundPaint = new Paint();
private final Paint mDayBackgroundPaint = new Paint();
private final Paint mHourSeparatorPaint = new Paint();
private final Paint mTodayColumnBackgroundPaint = new Paint();
private final Paint mFutureBackgroundPaint = new Paint();
private final Paint mPastBackgroundPaint = new Paint();
private final Paint mFutureWeekendBackgroundPaint = new Paint();
private final Paint mPastWeekendBackgroundPaint = new Paint();
private final Paint mNowLinePaint = new Paint();
private final Paint mEventBackgroundPaint = new Paint();
private final Paint mNewEventBackgroundPaint = new Paint();
private boolean containsAllDayEvent;
private float timeTextWidth;
private float timeTextHeight;
private float headerWeekDayTitleTextHeight;
private float headerHeight;
private float headerWeekDaySubtitleTextHeight;
private GestureDetectorCompat mGestureDetector;
private OverScroller mScroller;
private final PointF mCurrentOrigin = new PointF(0f, 0f);
private Direction mCurrentScrollDirection = Direction.NONE;
private float widthPerDay;
private float mHeaderColumnWidth;
private List
public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// Initialize the view
init();
}
private void init() {
// Set up the paint objects and other UI elements
// ...
// Set up the gesture detectors and scroller
// ...
}
}
原文地址: https://www.cveoy.top/t/topic/fvGt 著作权归作者所有。请勿转载和采集!