Code example for Context

Methods: getResources

0
        setContentView(container);
    } 
     
    @SuppressWarnings({"UnusedDeclaration"}) 
    static int dipToPx(Context c, int dip) {
        return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f);
    } 
 
    static class DrawingView extends View {
        private final Paint mPaint;
 
        DrawingView(Context c) {
            super(c);
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            canvas.save();
            canvas.translate(dipToPx(getContext(), 400), dipToPx(getContext(), 200));