Skip to content

Instantly share code, notes, and snippets.

View iammert's full-sized avatar
🎧
Focusing

Mert Şimşek iammert

🎧
Focusing
View GitHub Profile
private Paint mBackgroundAmbientPaint;
private Paint mBackgroundPaintFilled;
private Paint mBackgroundPaintNotFilled;
private Paint mPaintHourText;
private Paint mPaintMinuteText;
private Typeface mTypefaceRobotoThin;
private Typeface mTypefaceRobotoLight;
mTypefaceRobotoThin = Typeface.createFromAsset(getAssets(), "robotothin.ttf");
mTypefaceRobotoLight = Typeface.createFromAsset(getAssets(), "robotolight.ttf");
mBackgroundPaintFilled = new Paint();
mBackgroundPaintFilled.setColor(getResources().getColor(R.color.color_bg));
mBackgroundPaintNotFilled = new Paint();
mBackgroundPaintNotFilled.setColor(getResources().getColor(R.color.color_gray));
mPaintHourText = new Paint();
private int mWidth;
private int mHeight;
private float mCenterX;
private float mCenterY;
...
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
//Formül -- > ((mTime/60f) * mHeight).
//Mavi dikdörtgeni çiziyoruz.
canvas.drawRect(0, mHeight - (mTime.minute / 60f) * mHeight, canvas.getWidth(), canvas.getHeight(), mBackgroundPaintFilled);
//Gri dikdörtgeni çiziyoruz.
canvas.drawRect(0, 0, canvas.getWidth(), mHeight - (mTime.minute / 60f) * mHeight, mBackgroundPaintNotFilled);
//Yazacağımız saatin genişliğini ve yüksekliğini alıyoruz ve saate ortalıyoruz.
Rect hourBound = new Rect();
mPaintHourText.getTextBounds(mHour, 0, mHour.length(), hourBound);
canvas.drawText(mHour, mCenterX - (hourBound.width() / 2f), mCenterY + (hourBound.height() / 2f), mPaintHourText);
//Yazacağımız dakikanın genişliğini ve yüksekliğini hesaplayıp saatin yanına yazıyoruz.
Rect minuteBound = new Rect();
mPaintMinuteText.getTextBounds(mMinute, 0, mMinute.length(), minuteBound);
canvas.drawText(mMinute, mCenterX + (mCenterX / 2f), mCenterY + (minuteBound.height() / 2f), mPaintMinuteText);
public class Engine {
public Engine() {
}
public void turnOn(){
//Engine turned on here.
}
public void turnOff(){
public class Car {
private Engine engine;
public Car() {
engine = new Engine();
}
public void start(){
engine.turnOn();
public class Main {
public static void main(String[] args){
Car car = new Car();
car.start();
car.stop();
}
}
public class Car {
private Engine engine;
public Car(Engine engine) {
this.engine = engine;
}
public void start(){
engine.turnOn();
public class Car {
private LPGEngine engine;
public Car(LPGEngine engine) {
this.engine = engine;
}
public void start(){
engine.turnOn();