Example usage for android.graphics Paint ANTI_ALIAS_FLAG

List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG

Introduction

In this page you can find the example usage for android.graphics Paint ANTI_ALIAS_FLAG.

Prototype

int ANTI_ALIAS_FLAG

To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.

Click Source Link

Document

Paint flag that enables antialiasing when drawing.

Usage

From source file:eu.hydrologis.geopaparazzi.chart.ProfileChartActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.profilechart);

    int backgroundColor = getResources().getColor(R.color.main_background);
    int decorationsColor = getResources().getColor(R.color.main_decorations_dark);
    int textColor = getResources().getColor(R.color.main_text_color_neutral);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        try {//from w ww. ja  v  a  2  s.c om
            long logid = extras.getLong(Constants.ID);

            line = DaoGpsLog.getGpslogAsLine(logid, -1);

        } catch (IOException e) {
            GPLog.error(this, e.getLocalizedMessage(), e);
            e.printStackTrace();
        }

    } else {
        Toast.makeText(this, R.string.an_error_occurred_while_creating_the_chart_, Toast.LENGTH_LONG).show();
    }

    final float f26 = PixelUtils.dpToPix(26);
    final float f10 = PixelUtils.dpToPix(10);
    final SizeMetrics sm = new SizeMetrics(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL);

    xyPlotSpeed = (XYPlot) findViewById(R.id.speed_plot);
    xyPlotElev = (XYPlot) findViewById(R.id.elevation_plot);
    xyPlotSpeed.setOnTouchListener(this);

    infoTextView = (TextView) findViewById(R.id.info_text);
    Button resetButton = (Button) findViewById(R.id.reset_chart_button);
    resetButton.setOnClickListener(this);

    drawerLayout = (DrawerLayout) findViewById(R.id.container_drawer);

    // Disable Hardware Acceleration on the xyPlot view object.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        xyPlotSpeed.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        xyPlotElev.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    /*
     * Setup the Plots
     */
    xyPlotSpeed.setPlotMargins(0, 0, 0, 0);
    xyPlotElev.setPlotMargins(0, 0, 0, 0);

    xyPlotSpeed.setPlotPadding(0, 0, 0, 0);
    xyPlotElev.setPlotPadding(0, 0, 0, 0);

    xyPlotElev.getDomainLabelWidget().setVisible(false);
    xyPlotElev.getRangeLabelWidget().setVisible(false);
    xyPlotElev.getTitleWidget().setVisible(false);

    xyPlotElev.setBorderPaint(null);
    xyPlotElev.setBackgroundPaint(null);

    /* 
     * Setup the Graph Widgets
     */
    XYGraphWidget graphWidgetSpeed = xyPlotSpeed.getGraphWidget();
    XYGraphWidget graphWidgetElev = xyPlotElev.getGraphWidget();

    graphWidgetSpeed.setSize(sm);
    graphWidgetElev.setSize(sm);

    graphWidgetSpeed.setMargins(0, 0, 0, 0);
    graphWidgetElev.setMargins(0, 0, 0, 0);

    graphWidgetSpeed.setPadding(f26, f10, f26, f26);
    graphWidgetElev.setPadding(f26, f10, f26, f26);

    graphWidgetSpeed.setRangeAxisPosition(true, false, 4, "10");
    graphWidgetElev.setRangeAxisPosition(false, false, 4, "10");

    graphWidgetSpeed.setRangeLabelVerticalOffset(-3);
    graphWidgetElev.setRangeLabelVerticalOffset(-3);

    graphWidgetSpeed.setRangeOriginLabelPaint(null);
    graphWidgetElev.setRangeOriginLabelPaint(null);

    graphWidgetSpeed.setRangeLabelWidth(0);
    graphWidgetElev.setRangeLabelWidth(0);

    graphWidgetSpeed.setDomainLabelWidth(0);
    graphWidgetElev.setDomainLabelWidth(0);

    graphWidgetElev.setBackgroundPaint(null);
    graphWidgetElev.setDomainLabelPaint(null);
    graphWidgetElev.setGridBackgroundPaint(null);
    graphWidgetElev.setDomainOriginLabelPaint(null);
    graphWidgetElev.setRangeOriginLinePaint(null);
    graphWidgetElev.setDomainGridLinePaint(null);
    graphWidgetElev.setRangeGridLinePaint(null);

    graphWidgetSpeed.getBackgroundPaint().setColor(backgroundColor);
    graphWidgetSpeed.getGridBackgroundPaint().setColor(backgroundColor);

    graphWidgetSpeed.getRangeOriginLinePaint().setColor(decorationsColor);
    graphWidgetSpeed.getRangeOriginLinePaint().setStrokeWidth(3f);
    graphWidgetSpeed.getDomainOriginLinePaint().setColor(decorationsColor);
    graphWidgetSpeed.getDomainOriginLinePaint().setStrokeWidth(3f);

    graphWidgetSpeed.getRangeGridLinePaint().setColor(decorationsColor);
    graphWidgetSpeed.getRangeGridLinePaint().setStrokeWidth(1f);
    graphWidgetSpeed.getDomainGridLinePaint().setColor(decorationsColor);
    graphWidgetSpeed.getDomainGridLinePaint().setStrokeWidth(1f);

    graphWidgetSpeed.getRangeLabelPaint().setColor(textColor);
    graphWidgetSpeed.getDomainLabelPaint().setColor(textColor);
    graphWidgetSpeed.getDomainOriginLabelPaint().setColor(textColor);
    Paint rangeOriginLabelPaint = graphWidgetSpeed.getRangeOriginLabelPaint();
    if (rangeOriginLabelPaint == null) {
        rangeOriginLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        rangeOriginLabelPaint.setStyle(Paint.Style.STROKE);
        graphWidgetSpeed.setRangeOriginLabelPaint(rangeOriginLabelPaint);
    }
    rangeOriginLabelPaint.setColor(textColor);

    graphWidgetSpeed.getRangeLabelPaint().setTextSize(PixelUtils.dpToPix(8));
    graphWidgetElev.getRangeLabelPaint().setTextSize(PixelUtils.dpToPix(8));

    graphWidgetSpeed.getDomainOriginLabelPaint().setTextSize(PixelUtils.dpToPix(8));
    graphWidgetSpeed.getDomainLabelPaint().setTextSize(PixelUtils.dpToPix(8));

    float textSize = graphWidgetSpeed.getRangeLabelPaint().getTextSize();
    graphWidgetSpeed.setRangeLabelVerticalOffset((textSize / 2) * -1);
    graphWidgetElev.setRangeLabelVerticalOffset(graphWidgetSpeed.getRangeLabelVerticalOffset());

    /*
     * Position the Graph Widgets in the Centre
     */
    graphWidgetSpeed.position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.ABSOLUTE_FROM_CENTER,
            AnchorPosition.CENTER);
    graphWidgetElev.position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.ABSOLUTE_FROM_CENTER,
            AnchorPosition.CENTER);

    /* 
     * Position the Label Widgets
     */
    xyPlotSpeed.getDomainLabelWidget().setWidth(100);
    xyPlotSpeed.getRangeLabelWidget().setWidth(100);
    xyPlotSpeed.getDomainLabelWidget().position(0, XLayoutStyle.RELATIVE_TO_CENTER, 1,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);
    xyPlotSpeed.getRangeLabelWidget().position(1, XLayoutStyle.ABSOLUTE_FROM_LEFT, -20,
            YLayoutStyle.ABSOLUTE_FROM_CENTER, AnchorPosition.LEFT_BOTTOM);

    /*
     *  Setup and Position the speed Legend
     */
    XYLegendWidget legendWidgetSpeed = xyPlotSpeed.getLegendWidget();
    legendWidgetSpeed.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
    legendWidgetSpeed.setPadding(1, 1, 1, 1);
    legendWidgetSpeed.setTableModel(new DynamicTableModel(1, 3));
    legendWidgetSpeed.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE,
            PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
    legendWidgetSpeed.getTextPaint().setColor(textColor);
    legendWidgetSpeed.getTextPaint().setTextSize(PixelUtils.dpToPix(9));
    legendWidgetSpeed.position(PixelUtils.dpToPix(30), XLayoutStyle.ABSOLUTE_FROM_LEFT, f10 + 2,
            YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.LEFT_TOP);

    /*
     *  Setup and Position the elev Legend
     */
    XYLegendWidget legendWidgetElev = xyPlotElev.getLegendWidget();
    legendWidgetElev.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
    legendWidgetElev.setPadding(1, 1, 1, 1);
    legendWidgetElev.setTableModel(new DynamicTableModel(1, 3));
    legendWidgetElev.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE,
            PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE));
    //        legendWidgetElev.getTextPaint().setColor(textColor);
    legendWidgetElev.getTextPaint().setTextSize(PixelUtils.dpToPix(9));
    legendWidgetElev.getTextPaint().setTextAlign(Align.RIGHT);
    legendWidgetElev.setMarginLeft(185);
    legendWidgetElev.position(PixelUtils.dpToPix(30), XLayoutStyle.ABSOLUTE_FROM_RIGHT, f10 + 2,
            YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP);

    // Setup the formatters
    int rgbSpeedLine = Color.rgb(0, 200, 0);
    int rgbSpeedPoints = Color.rgb(0, 100, 0);
    int rgbElevLine = Color.rgb(0, 0, 200);
    int rgbElevPoints = Color.rgb(0, 0, 100);

    seriesSpeedFormat = new LineAndPointFormatter(rgbSpeedLine, rgbSpeedPoints, null, null);
    seriesElevFormat = new LineAndPointFormatter(rgbElevLine, rgbElevPoints, null, null);

}

From source file:org.gateshipone.odyssey.playbackservice.managers.OdysseyNotificationManager.java

public void updateNotification(TrackModel track, PlaybackService.PLAYSTATE state,
        MediaSessionCompat.Token mediaSessionToken) {
    if (track != null) {
        mNotificationBuilder = new NotificationCompat.Builder(mContext);

        // Open application intent
        Intent contentIntent = new Intent(mContext, OdysseyMainActivity.class);
        contentIntent.putExtra(OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW,
                OdysseyMainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW);
        contentIntent.addFlags(//  www  .j a  va2s  .c o  m
                Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY);
        PendingIntent contentPendingIntent = PendingIntent.getActivity(mContext, NOTIFICATION_INTENT_OPENGUI,
                contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setContentIntent(contentPendingIntent);

        // Set pendingintents
        // Previous song action
        Intent prevIntent = new Intent(PlaybackService.ACTION_PREVIOUS);
        PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PREVIOUS,
                prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build();

        // Pause/Play action
        PendingIntent playPauseIntent;
        int playPauseIcon;
        if (state == PlaybackService.PLAYSTATE.PLAYING) {
            Intent pauseIntent = new Intent(PlaybackService.ACTION_PAUSE);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, pauseIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_pause_48dp;
        } else {
            Intent playIntent = new Intent(PlaybackService.ACTION_PLAY);
            playPauseIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_PLAYPAUSE, playIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            playPauseIcon = R.drawable.ic_play_arrow_48dp;
        }
        NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon,
                "PlayPause", playPauseIntent).build();

        // Next song action
        Intent nextIntent = new Intent(PlaybackService.ACTION_NEXT);
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_NEXT,
                nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build();

        // Quit action
        Intent quitIntent = new Intent(PlaybackService.ACTION_QUIT);
        PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mContext, NOTIFICATION_INTENT_QUIT,
                quitIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mNotificationBuilder.setDeleteIntent(quitPendingIntent);

        mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mNotificationBuilder.setSmallIcon(R.drawable.odyssey_notification);
        mNotificationBuilder.addAction(prevAction);
        mNotificationBuilder.addAction(playPauseAction);
        mNotificationBuilder.addAction(nextAction);
        NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle();
        notificationStyle.setShowActionsInCompactView(1, 2);
        notificationStyle.setMediaSession(mediaSessionToken);
        mNotificationBuilder.setStyle(notificationStyle);
        mNotificationBuilder.setContentTitle(track.getTrackName());
        mNotificationBuilder.setContentText(track.getTrackArtistName());

        // Remove unnecessary time info
        mNotificationBuilder.setWhen(0);

        // Cover but only if changed
        if (mLastTrack == null || !track.getTrackAlbumKey().equals(mLastTrack.getTrackAlbumKey())) {
            mLastTrack = track;
            mLastBitmap = null;
        }

        // Only set image if an saved one is available
        if (mLastBitmap != null) {
            mNotificationBuilder.setLargeIcon(mLastBitmap);
        } else {
            /**
             * Create a dummy placeholder image for versions greater android 7 because it
             * does not automatically show the application icon anymore in mediastyle notifications.
             */
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Drawable icon = mContext.getDrawable(R.drawable.notification_placeholder_256dp);

                Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(iconBitmap);
                DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1);

                canvas.setDrawFilter(filter);
                icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                icon.setFilterBitmap(true);

                icon.draw(canvas);
                mNotificationBuilder.setLargeIcon(iconBitmap);

            } else {
                /**
                 * For older android versions set the null icon which will result in a dummy icon
                 * generated from the application icon.
                 */
                mNotificationBuilder.setLargeIcon(null);

            }
        }

        // Build the notification
        mNotification = mNotificationBuilder.build();

        // Check if run from service and check if playing or pause.
        // Pause notification should be dismissible.
        if (mContext instanceof Service) {
            if (state == PlaybackService.PLAYSTATE.PLAYING) {
                ((Service) mContext).startForeground(NOTIFICATION_ID, mNotification);
            } else {
                ((Service) mContext).stopForeground(false);
            }
        }

        // Send the notification away
        mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    }

}

From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr) {
    mUiHandler = new Handler(Looper.getMainLooper(), mMessenger);

    final Resources res = getResources();

    final ViewConfiguration vc = ViewConfiguration.get(ctx);
    mTouchSlop = vc.getScaledTouchSlop() / 2;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mScroller = new OverScroller(ctx);

    int footerLabelColor = ContextCompat.getColor(getContext(), R.color.tlcSleepFooterLabelColor);
    int barItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarItemBg);
    int highlightBarItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarItemBg);
    int barDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepBarDeepItemBg);
    int highlightBarDeepItemBg = ContextCompat.getColor(getContext(), R.color.tlcSleepHighlightBarDeepItemBg);

    mBarItemBgPaint = new Paint();
    mBarItemBgPaint.setColor(barItemBg);
    mHighlightBarItemBgPaint = new Paint();
    mHighlightBarItemBgPaint.setColor(highlightBarItemBg);
    mBarDeepItemBgPaint = new Paint();
    mBarDeepItemBgPaint.setColor(barDeepItemBg);
    mHighlightBarDeepItemBgPaint = new Paint();
    mHighlightBarDeepItemBgPaint.setColor(highlightBarDeepItemBg);

    mFooterBarHeight = res.getDimension(R.dimen.tlcDefFooterBarHeight);

    mViewAreaBgPaint = new Paint();

    mGraphAreaBgPaint = new Paint();
    mGraphAreaBgPaint.setColor(Color.TRANSPARENT);

    mFooterAreaBgPaint = new Paint();
    mFooterAreaBgPaint.setColor(Color.TRANSPARENT);

    mGraphBottomLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mGraphBottomLinePaint.setColor(Color.WHITE);
    mGraphBottomLinePaint.setStrokeWidth(1);

    // labelPaint??
    mLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mLabelFgPaint.setColor(footerLabelColor);
    //        DisplayMetrics dp = getResources().getDisplayMetrics();
    //        float labelSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.tlcDefFooterLabelSize), dp);
    mLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize));

    mHighlightLabelFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mHighlightLabelFgPaint.setColor(Color.WHITE);
    mHighlightLabelFgPaint.setTextSize(res.getDimension(R.dimen.tlcDefFooterLabelSize));

    mBarItemWidth = res.getDimension(R.dimen.tlcDefBarItemWidth);
    mBarItemSpace = res.getDimension(R.dimen.tlcDefBarItemSpace);
    mTopSpaceHeight = res.getDimension(R.dimen.tlcDefTopSpace);

    // SurfaceView requires a background
    if (getBackground() == null) {
        setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    }/*from  w  w w.  ja va 2s. c  om*/

    // Initialize stuff
    setupBackgroundHandler();
    setupTickLabels();

    // Initialize the drawing refs (this will be update when we have
    // the real size of the canvas)
    computeBoundAreas();
}

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

private void init() {
    Resources res = getResources();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);

    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setStyle(Paint.Style.FILL);

    mDotBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotBackgroundPaint.setColor(res.getColor(R.color.chart_margins_color));
    mDotBackgroundPaint.setStyle(Paint.Style.FILL);

    Typeface valueTypeface = Typeface.create("sans-serif-medium", Typeface.NORMAL);
    Typeface timeTimeface = Typeface.create("sans-serif", Typeface.NORMAL);

    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTypeface(valueTypeface);
    mTextPaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
    mTextPaint.setColor(res.getColor(R.color.text_color_white));

    mTimePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTimePaint.setTypeface(timeTimeface);
    mTimePaint.setTextSize(res.getDimension(R.dimen.run_review_overlay_label_text_size));
    mTimePaint.setColor(res.getColor(R.color.text_color_white));

    mCenterLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
    mCenterLinePaint.setStyle(Paint.Style.STROKE);
    mCenterLinePaint.setColor(res.getColor(R.color.text_color_white));

    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.recording_overlay_bar_width));
    int dashSize = res.getDimensionPixelSize(R.dimen.run_review_overlay_dash_size);
    mLinePaint.setPathEffect(new DashPathEffect(new float[] { dashSize, dashSize }, dashSize));
    mLinePaint.setColor(res.getColor(R.color.note_overlay_line_color));
    mLinePaint.setStyle(Paint.Style.STROKE);

    mPath = new Path();

    // TODO: Need to make sure this is at least as detailed as the SensorAppearance number
    // format!//w ww .j  a  va  2 s. co  m
    mTextFormat = res.getString(R.string.run_review_chart_label_format);
    mTimeFormat = ElapsedTimeAxisFormatter.getInstance(getContext());

    mCropBackgroundPaint = new Paint();
    mCropBackgroundPaint.setStyle(Paint.Style.FILL);
    mCropBackgroundPaint.setColor(res.getColor(R.color.text_color_black));
    mCropBackgroundPaint.setAlpha(40);

    mCropVerticalLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCropVerticalLinePaint.setStyle(Paint.Style.STROKE);
    mCropVerticalLinePaint.setStrokeWidth(res.getDimensionPixelSize(R.dimen.chart_grid_line_width));
}

From source file:com.cssweb.android.view.KlineMini.java

public void onDraw(Canvas canvas) {
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(1);/* ww  w  .  j  a va2 s .  c  o m*/

    tPaint = new Paint();
    tPaint.setStyle(Paint.Style.STROKE);
    tPaint.setTypeface(Typeface.DEFAULT_BOLD);
    tPaint.setAntiAlias(true);
    tPaint.setTextSize(dTextSize);
    //
    tips = (int) tPaint.measureText("0");

    try {
        if (actualDataLen == 0) {
            return;
        }
        if (zs)
            axisLabelWidth = (int) Math.max(tPaint.measureText("99999.99"), tPaint.measureText("11000"));
        else
            axisLabelWidth = (int) tPaint.measureText("11000");
        klineWidth = width - axisLabelWidth;
        //?spaceWidth???
        visualKLineCount = (int) ((klineWidth - spaceWidth) / (spaceWidth + shapeWidth));

        if (isSingleMoved == false && isTrackStatus == false) {
            if (actualDataLen > visualKLineCount) {
                actualPos = actualDataLen - visualKLineCount;
                count = visualKLineCount;
            } else {
                actualPos = 0;
                count = actualDataLen;
            }
        }

        calcMaxMin(actualPos);

        if (!isTrackStatus) {
            moveQuote(actualDataLen - 1);
        } else {
            if (trackLineV == 0) {
                trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2);
                isTrackNumber = actualPos + visualPos - 1;
            }
            if (isTrackNumber < 0) {
                isTrackNumber = 0;
            } else if (isTrackNumber > actualDataLen - 1) {
                isTrackNumber = actualDataLen - 1;
            }
            paint.setColor(GlobalColor.clrGrayLine);
            canvas.drawLine(klineX + trackLineV, axisLabelHeight, klineX + trackLineV, height - axisLabelHeight,
                    paint);
            moveQuote(isTrackNumber);
            drawQuoteWin(canvas, quoteData, isTrackNumber);
        }

        //
        axisLabelHeight = Font.getFontHeight(dTextSize);
        klineX = axisLabelWidth;
        klineY = axisLabelHeight;

        klineHeight = height - axisLabelHeight * 2;
        axisX = klineX;

        //
        tPaint.setTextAlign(Paint.Align.LEFT);
        tPaint.setColor(GlobalColor.colorM5);
        canvas.drawText(lblIndicatorName, (float) (klineX + shapeWidth), axisLabelHeight - 5, tPaint);

        float size = tPaint.measureText(lblIndicatorName) + tips;
        tPaint.setColor(GlobalColor.colorM10);
        canvas.drawText(lblIndicatorT1, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint);

        size += tPaint.measureText(lblIndicatorT1) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT2))) {
            //tPaint.setColor(GlobalColor.colorM20);
            tPaint.setARGB(255, 255, 0, 255);
            canvas.drawText(lblIndicatorT2, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint);
        }

        size += tPaint.measureText(lblIndicatorT2) + tips;
        if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) {
            tPaint.setColor(GlobalColor.colorM60);
            canvas.drawText(lblIndicatorT3, (float) (klineX + shapeWidth + size), axisLabelHeight - 5, tPaint);
        }

        //???
        rowHeight = klineHeight / rowNum;
        scale = klineHeight / (highPrice - lowPrice);

        double ratio = (highPrice - lowPrice) / rowNum;
        paint.setColor(GlobalColor.clrLine);
        tPaint.setColor(GlobalColor.colorTicklabel);
        tPaint.setTextAlign(Paint.Align.RIGHT);
        for (int i = 0; i <= rowNum; i++) {
            if (i == rowNum || i == 0) {
                canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint);
            } else {
                Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i,
                        paint);
            }
            if (i != rowNum && isTrackStatus == false) {
                double AxisLabelPrice = highPrice - ratio * i;
                String AxisLabelPriceText;
                if (zs) {
                    AxisLabelPriceText = Utils.dataFormation(Math.round(AxisLabelPrice), 0);
                } else {
                    AxisLabelPriceText = Utils.dataFormation(AxisLabelPrice, stockdigit);
                }
                canvas.drawText(AxisLabelPriceText, klineX - tips / 4,
                        klineY + rowHeight * i + axisLabelHeight / 2, tPaint);
            }
        }

        //
        if (quoteData != null) {
            //axisX = 0;
            for (int i = actualPos; i < (actualPos + count); i++) {
                if (i == 0)
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4));
                else
                    drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(2),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(3),
                            quoteData.getJSONArray("K").getJSONArray(i).getDouble(4),
                            quoteData.getJSONArray("K").getJSONArray(i - 1).getDouble(4));
            }
            if (mainIndicatorType.toUpperCase().equals("MA"))
                drawMA(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                        highVolume, actualDataLen);

            drawTimeAix(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice,
                    highVolume, actualDataLen);
        }

        //?????
        paint.setColor(GlobalColor.clrLine);
        canvas.drawLine(klineX, 0, width, 0, paint);
        canvas.drawLine(klineX, 0, klineX, height - axisLabelHeight, paint);
        canvas.drawLine(width, 0, width, height - axisLabelHeight, paint);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override//  w  ww  . ja  va  2 s  .  c o  m
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("ACE startup.", // Event category (required)
                    "User started ACE.", // Event action (required)
                    "User started ACE.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.raspi.chatapp.util.Notification.java

private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) {
    Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    RectF mInnerRectF = new RectF();
    mInnerRectF.set(0, 0, width, width);
    mInnerRectF.offset(0, 0);/*from w w w. ja va 2 s  .c om*/

    Paint mBgPaint = new Paint();
    mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setStyle(Paint.Style.FILL);
    mBgPaint.setColor(bgColor);

    TextPaint mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(Color.WHITE);
    mTitleTextPaint.setTextSize(width * 0.8f);

    float centerX = mInnerRectF.centerX();
    float centerY = mInnerRectF.centerY();

    int xPos = (int) centerX;
    int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2);

    if (round)
        c.drawOval(mInnerRectF, mBgPaint);
    else
        c.drawRect(mInnerRectF, mBgPaint);
    c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint);

    return b;
}

From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java

/**
 * Construct a new Switch with a default style determined by the given theme attribute,
 * overriding specific style attributes as requested.
 *
 * @param context      The Context that will determine this widget's theming.
 * @param attrs        Specification of attributes that should deviate from the default styling.
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default values for
 *                     the view. Can be 0 to not look for defaults.
 *///from   w w  w. j  a  v  a 2 s . co  m
@SuppressLint("PrivateResource")
public MultiValueSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
    super(MVS_TintContextWrapperAccessor.wrap(context), attrs, defStyleAttr);

    mDrawableManager = AppCompatDrawableManager.get();
    mBackgroundTintHelper = new MVS_AppCompatBackgroundHelperAccessor(this);
    mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);

    TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
            android.support.v7.appcompat.R.styleable.SwitchCompat, defStyleAttr, 0);
    mThumbDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_android_thumb);
    if (mThumbDrawable != null) {
        mThumbDrawable.setCallback(this);
    }
    mTrackDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_track);
    if (mTrackDrawable != null) {
        mTrackDrawable.setCallback(this);
    }

    mPointPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPointPaint.setColor(0x33000000);
    mPointPaint.setStyle(Paint.Style.FILL);
    mPointRadius = getResources().getDisplayMetrics().density * 2;

    mSwitchMinWidth = a
            .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_switchMinWidth, 0);
    mSwitchPadding = a
            .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_switchPadding, 0);
    mSplitTrack = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_splitTrack, false);

    a.recycle();

    a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.MultiValueSwitch, defStyleAttr, 0);
    setMax(a.getInt(R.styleable.MultiValueSwitch_android_max, 2));
    setEntries(a.getTextArray(R.styleable.MultiValueSwitch_android_entries));
    mThumbPosition = getThumbPosition(a.getInt(R.styleable.MultiValueSwitch_android_position, 0));
    setEnabled(a.getBoolean(R.styleable.MultiValueSwitch_android_enabled, true));
    a.recycle();

    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    // Refresh display with current params
    refreshDrawableState();
    setCheckedPosition(getCheckedPosition());
}

From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java

public static void LoadImage(final String url, ImageView image, final String displayname, final boolean rounded,
        boolean fromCache) {
    final WeakReference<ImageView> imageView = new WeakReference<ImageView>(image);
    final Handler uiHandler = new Handler();
    final int FG_COLOR = 0xFFFAFAFA;
    final String name = displayname;

    if (fromCache) {
        Bitmap bitmap = ThumbnailsCacheManager.getBitmapFromDiskCache(url);

        if (bitmap != null) {
            if (rounded) {
                RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory
                        .create(imageView.get().getResources(), bitmap);
                roundedBitmap.setCircular(true);
                imageView.get().setImageDrawable(roundedBitmap);
            } else {
                imageView.get().setImageBitmap(bitmap);
            }/*from  w  ww . j a  v  a 2 s .  co m*/
            imageView.get().setContentDescription(displayname);
            return;
        }
    }

    AsyncHttpURLConnection httpConnection = new AsyncHttpURLConnection("GET", url, "",
            new AsyncHttpURLConnection.AsyncHttpEvents() {
                @Override
                public void onHttpError(String errorMessage) {
                    Log.d("LoadImage", errorMessage);
                }

                @Override
                public void onHttpComplete(String response) {
                    int size = 96;
                    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(bitmap);
                    final String trimmedName = name == null ? "" : name.trim();
                    drawTile(canvas, trimmedName, 0, 0, size, size);
                    ThumbnailsCacheManager.addBitmapToCache(url, bitmap);

                    onHttpComplete(bitmap);
                }

                @Override
                public void onHttpComplete(final Bitmap response) {
                    if (imageView != null && imageView.get() != null) {
                        uiHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                if (imageView.get() != null) {
                                    if (rounded) {
                                        RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory
                                                .create(imageView.get().getResources(), response);
                                        roundedBitmap.setCircular(true);
                                        imageView.get().setImageDrawable(roundedBitmap);
                                    } else {
                                        imageView.get().setImageBitmap(response);
                                    }
                                    imageView.get().setContentDescription(displayname);
                                }

                            }

                        });

                    }
                }

                private boolean drawTile(Canvas canvas, String letter, int tileColor, int left, int top,
                        int right, int bottom) {
                    letter = letter.toUpperCase(Locale.getDefault());
                    Paint tilePaint = new Paint(), textPaint = new Paint();
                    tilePaint.setColor(tileColor);
                    textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
                    textPaint.setColor(FG_COLOR);
                    textPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
                    textPaint.setTextSize((float) ((right - left) * 0.8));
                    Rect rect = new Rect();

                    canvas.drawRect(new Rect(left, top, right, bottom), tilePaint);
                    textPaint.getTextBounds(letter, 0, 1, rect);
                    float width = textPaint.measureText(letter);
                    canvas.drawText(letter, (right + left) / 2 - width / 2,
                            (top + bottom) / 2 + rect.height() / 2, textPaint);
                    return true;
                }

                private boolean drawTile(Canvas canvas, String name, int left, int top, int right, int bottom) {
                    if (name != null) {
                        final String letter = getFirstLetter(name);
                        final int color = ThumbnailsCacheManager.getColorForName(name);
                        drawTile(canvas, letter, color, left, top, right, bottom);
                        return true;
                    }
                    return false;
                }

            });
    httpConnection.setBitmap();
    httpConnection.send();
}

From source file:com.Duo.music.player.LauncherActivity.LauncherActivity.java

@SuppressLint("NewApi")
@Override// ww  w .  ja va 2s . c om
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.AppThemeNoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launcher);

    mContext = this;
    mActivity = this;
    mApp = (Common) mContext.getApplicationContext();
    mHandler = new Handler();

    //Increment the start count. This value will be used to determine when the library should be rescanned.
    int startCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);
    mApp.getSharedPreferences().edit().putInt("START_COUNT", startCount + 1).commit();

    //Save the dimensions of the layout for later use on KitKat devices.
    final RelativeLayout launcherRootView = (RelativeLayout) findViewById(R.id.launcher_root_view);
    launcherRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {

            try {

                int screenDimens[] = new int[2];
                int screenHeight = 0;
                int screenWidth = 0;
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    //API levels 14, 15 and 16.
                    screenDimens = getTrueDeviceResolution();
                    screenWidth = screenDimens[0];
                    screenHeight = screenDimens[1];

                } else {
                    //API levels 17+.
                    Display display = getWindowManager().getDefaultDisplay();
                    DisplayMetrics metrics = new DisplayMetrics();
                    display.getRealMetrics(metrics);
                    screenHeight = metrics.heightPixels;
                    screenWidth = metrics.widthPixels;

                }

                int layoutHeight = launcherRootView.getHeight();
                int layoutWidth = launcherRootView.getWidth();

                int extraHeight = screenHeight - layoutHeight;
                int extraWidth = screenWidth = layoutWidth;

                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT", layoutHeight).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH", layoutWidth).commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_HEIGHT_LAND", layoutWidth - extraHeight)
                        .commit();
                mApp.getSharedPreferences().edit().putInt("KITKAT_WIDTH_LAND", screenHeight).commit();

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    //Build the music library based on the user's scan frequency preferences.
    int scanFrequency = mApp.getSharedPreferences().getInt("SCAN_FREQUENCY", 5);
    int updatedStartCount = mApp.getSharedPreferences().getInt("START_COUNT", 1);

    //Launch the appropriate activity based on the "FIRST RUN" flag.
    if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true) {

        //Create the default Playlists directory if it doesn't exist.
        File playlistsDirectory = new File(Environment.getExternalStorageDirectory() + "/Playlists/");
        if (!playlistsDirectory.exists() || !playlistsDirectory.isDirectory()) {
            playlistsDirectory.mkdir();
        }

        //Disable equalizer for HTC devices by default.
        if (mApp.getSharedPreferences().getBoolean(Common.FIRST_RUN, true) == true
                && Build.PRODUCT.contains("HTC")) {
            mApp.getSharedPreferences().edit().putBoolean("EQUALIZER_ENABLED", false).commit();
        }

        //Send out a test broadcast to initialize the homescreen/lockscreen widgets.
        sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        Intent intent = new Intent(this, WelcomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

    } else if (mApp.isBuildingLibrary()) {
        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_building_library);
        buildingLibraryLayout.setVisibility(View.VISIBLE);

        //Initialize the runnable that will fire once the scan process is complete.
        mHandler.post(scanFinishedCheckerRunnable);

    } else if (mApp.getSharedPreferences().getBoolean("RESCAN_ALBUM_ART", false) == true) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setText(R.string.jams_is_caching_artwork);
        initScanProcess(0);

    } else if ((mApp.getSharedPreferences().getBoolean("REBUILD_LIBRARY", false) == true)
            || (scanFrequency == 0 && mApp.isScanFinished() == false)
            || (scanFrequency == 1 && mApp.isScanFinished() == false && updatedStartCount % 3 == 0)
            || (scanFrequency == 2 && mApp.isScanFinished() == false && updatedStartCount % 5 == 0)
            || (scanFrequency == 3 && mApp.isScanFinished() == false && updatedStartCount % 10 == 0)
            || (scanFrequency == 4 && mApp.isScanFinished() == false && updatedStartCount % 20 == 0)) {

        buildingLibraryMainText = (TextView) findViewById(R.id.building_music_library_text);
        buildingLibraryInfoText = (TextView) findViewById(R.id.building_music_library_info);
        buildingLibraryLayout = (RelativeLayout) findViewById(R.id.building_music_library_layout);

        buildingLibraryInfoText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryInfoText.setPaintFlags(
                buildingLibraryInfoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        buildingLibraryMainText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
        buildingLibraryMainText.setPaintFlags(
                buildingLibraryMainText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

        initScanProcess(1);

    } else {

        //Check if this activity was called from Settings.
        if (getIntent().hasExtra("UPGRADE")) {
            if (getIntent().getExtras().getBoolean("UPGRADE") == true) {
                mExplicitShowTrialFragment = true;
            } else {
                mExplicitShowTrialFragment = false;
            }

        }

        //initInAppBilling();
        launchMainActivity();
    }

    //Fire away a report to Google Analytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled() == true) {
            EasyTracker easyTracker = EasyTracker.getInstance(this);
            easyTracker.send(MapBuilder.createEvent("Jams startup.", // Event category (required)
                    "User started Jams.", // Event action (required)
                    "User started Jams.", // Event label
                    null) // Event value
                    .build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}