Tachyon icon indicating copy to clipboard operation
Tachyon copied to clipboard

"Now" line

Open riki-dexter opened this issue 6 years ago • 1 comments

Can you add the "now" line like in this example? https://ibb.co/B63F51C Thanks

riki-dexter avatar Feb 14 '20 15:02 riki-dexter

Here is some code to add a simple now line

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.linkedin.android.tachyon.DayView;

import java.util.Date;

public class MyDayView extends DayView {
    Paint paint;
    public MyDayView(@NonNull Context context) {
        super(context);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(0xffff0000);
    }

    public MyDayView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(0xffff0000);
    }

    public MyDayView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(0xffff0000);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        Date d = new Date();
        int h = d.getHours();
        int min = d.getMinutes();
        float hourTop = getHourTop(h);
        float hourBottom = getHourBottom(h);
        float pixelsPerMin = (hourBottom-hourTop)/60.0f;
        int y = (int) (hourTop+(pixelsPerMin * min))+2;
        canvas.drawLine(0,y,canvas.getWidth(),y,paint);
    }
}

h3r3t1c avatar Sep 10 '20 03:09 h3r3t1c