List of usage examples for android.graphics Paint ANTI_ALIAS_FLAG
int ANTI_ALIAS_FLAG
To view the source code for android.graphics Paint ANTI_ALIAS_FLAG.
Click Source Link
From source file:org.gateshipone.malp.application.background.NotificationManager.java
public synchronized void updateNotification(MPDTrack track, MPDCurrentStatus.MPD_PLAYBACK_STATE state) { if (track != null) { mNotificationBuilder = new NotificationCompat.Builder(mService); // Open application intent Intent contentIntent = new Intent(mService, MainActivity.class); contentIntent.putExtra(MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW, MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW); contentIntent.addFlags(/*from w w w .j ava 2 s . c om*/ 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(mService, INTENT_OPENGUI, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setContentIntent(contentPendingIntent); // Set pendingintents // Previous song action Intent prevIntent = new Intent(BackgroundService.ACTION_PREVIOUS); PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mService, 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 == MPDCurrentStatus.MPD_PLAYBACK_STATE.MPD_PLAYING) { Intent pauseIntent = new Intent(BackgroundService.ACTION_PAUSE); playPauseIntent = PendingIntent.getBroadcast(mService, INTENT_PLAYPAUSE, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT); playPauseIcon = R.drawable.ic_pause_48dp; } else { Intent playIntent = new Intent(BackgroundService.ACTION_PLAY); playPauseIntent = PendingIntent.getBroadcast(mService, 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(); // Stop action Intent stopIntent = new Intent(BackgroundService.ACTION_STOP); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(mService, INTENT_STOP, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopActon = new NotificationCompat.Action.Builder( R.drawable.ic_stop_black_48dp, "Stop", stopPendingIntent).build(); // Next song action Intent nextIntent = new Intent(BackgroundService.ACTION_NEXT); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mService, 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(BackgroundService.ACTION_QUIT_BACKGROUND_SERVICE); PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mService, INTENT_QUIT, quitIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setDeleteIntent(quitPendingIntent); mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotificationBuilder.setSmallIcon(R.drawable.ic_notification_24dp); mNotificationBuilder.addAction(prevAction); mNotificationBuilder.addAction(playPauseAction); mNotificationBuilder.addAction(stopActon); mNotificationBuilder.addAction(nextAction); NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle(); notificationStyle.setShowActionsInCompactView(1, 2); mNotificationBuilder.setStyle(notificationStyle); String title; if (track.getTrackTitle().isEmpty()) { title = FormatHelper.getFilenameFromPath(track.getPath()); } else { title = track.getTrackTitle(); } mNotificationBuilder.setContentTitle(title); String secondRow; if (!track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) { secondRow = track.getTrackArtist() + mService.getString(R.string.track_item_separator) + track.getTrackAlbum(); } else if (track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) { secondRow = track.getTrackAlbum(); } else if (track.getTrackAlbum().isEmpty() && !track.getTrackArtist().isEmpty()) { secondRow = track.getTrackArtist(); } else { secondRow = track.getPath(); } // Set the media session metadata updateMetadata(track, state); mNotificationBuilder.setContentText(secondRow); // Remove unnecessary time info mNotificationBuilder.setWhen(0); // Cover but only if changed if (mNotification == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum())) { mLastTrack = track; mLastBitmap = null; mCoverLoader.getImage(mLastTrack, true); } // 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 = mService.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(); // Send the notification away mNotificationManager.notify(NOTIFICATION_ID, mNotification); } }
From source file:org.appspot.apprtc.util.ThumbnailsCacheManager.java
public static void LoadImage(final String url, LoadImageCallback callback, final Resources resources, final String displayname, final boolean rounded, boolean fromCache) { final LoadImageCallback mCallback = callback; 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(resources, bitmap); roundedBitmap.setCircular(true); mCallback.onImageLoaded(roundedBitmap.getBitmap()); } else { mCallback.onImageLoaded(bitmap); }/* w w w . j a va 2 s . c o m*/ 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 = 256; 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 (mCallback != null) { uiHandler.post(new Runnable() { @Override public void run() { if (rounded) { RoundedBitmapDrawable roundedBitmap = RoundedBitmapDrawableFactory .create(resources, response); roundedBitmap.setCircular(true); mCallback.onImageLoaded(roundedBitmap.getBitmap()); } else { mCallback.onImageLoaded(response); } } }); } } 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.codetroopers.shakemytours.ui.activity.TripActivity.java
private Bitmap createMarker(int radius, int strokeWidth, String letter, int strokeColor, int backgroundColor) { int width = (radius * 2) + (strokeWidth * 2); Bitmap marker = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(marker); Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); strokePaint.setColor(strokeColor);/*from w w w. j a v a 2 s.c o m*/ strokePaint.setShadowLayer(strokeWidth, 1.0f, 1.0f, Color.BLACK); canvas.drawCircle(width / 2, width / 2, radius, strokePaint); Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); backgroundPaint.setColor(backgroundColor); canvas.drawCircle(width / 2, width / 2, radius - strokeWidth, backgroundPaint); if (letter != null) { Rect result = new Rect(); Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.map_marker_text_size)); textPaint.setColor(strokeColor); textPaint.getTextBounds(letter, 0, letter.length(), result); int yOffset = result.height() / 2; canvas.drawText(letter, width / 2, (width / 2) + yOffset, textPaint); } return marker; }
From source file:com.ruesga.rview.widget.TagEditTextView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mHandler = new Handler(mTagMessenger); mTriggerTagCreationThreshold = CREATE_CHIP_DEFAULT_DELAYED_TIMEOUT; Resources.Theme theme = ctx.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TagEditTextView, defStyleAttr, 0); mReadOnly = a.getBoolean(R.styleable.TagEditTextView_readonly, false); mDefaultTagMode = TAG_MODE.HASH;/*from w ww. j ava 2 s . c o m*/ // Create the internal EditText that holds the tag logic mTagEdit = mReadOnly ? new TagEditText(ctx, attrs, defStyleAttr) : new TagEditText(ctx, attrs); mTagEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0)); mTagEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); mTagEdit.addTextChangedListener(mEditListener); mTagEdit.setTextIsSelectable(false); mTagEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); mTagEdit.setOnFocusChangeListener((v, hasFocus) -> { // Remove any pending message mHandler.removeMessages(MESSAGE_CREATE_CHIP); }); mTagEdit.setCustomSelectionActionModeCallback(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } }); addView(mTagEdit); // Configure the window mode for landscape orientation, to disallow hide the // EditText control, and show characters instead of chips int orientation = ctx.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (ctx instanceof Activity) { Window window = ((Activity) ctx).getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); mTagEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); } } } // Save the keyListener for later restore mEditModeKeyListener = mTagEdit.getKeyListener(); // Initialize resources for chips mChipBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint.setTextSize(mTagEdit.getTextSize() * (mReadOnly ? 1 : 0.8f)); if (CHIP_TYPEFACE != null) { mChipFgPaint.setTypeface(CHIP_TYPEFACE); } mChipFgPaint.setTextAlign(Paint.Align.LEFT); // Calculate the width area used to remove the tag in the chip mChipRemoveAreaWidth = (int) (mChipFgPaint.measureText(CHIP_REMOVE_TEXT) + 0.5f); if (ONE_PIXEL <= 0) { Resources res = getResources(); ONE_PIXEL = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()); } int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.TagEditTextView_supportUserTags: setSupportsUserTags(a.getBoolean(attr, false)); break; case R.styleable.TagEditTextView_chipBackgroundColor: mChipBackgroundColor = a.getColor(attr, mChipBackgroundColor); break; case R.styleable.TagEditTextView_chipTextColor: mChipFgPaint.setColor(a.getColor(attr, Color.WHITE)); break; } } a.recycle(); }
From source file:org.akop.crosswords.view.CrosswordView.java
public CrosswordView(Context context, AttributeSet attrs) { super(context, attrs); if (!isInEditMode()) { setLayerType(View.LAYER_TYPE_HARDWARE, null); }/* w w w. j a v a 2 s .co m*/ // Set drawing defaults Resources r = context.getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int cellFillColor = NORMAL_CELL_FILL_COLOR; int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR; int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR; int selectedWordFillColor = SELECTED_WORD_FILL_COLOR; int selectedCellFillColor = SELECTED_CELL_FILL_COLOR; int textColor = TEXT_COLOR; int cellStrokeColor = CELL_STROKE_COLOR; int circleStrokeColor = CIRCLE_STROKE_COLOR; float numberTextSize = NUMBER_TEXT_SIZE * dm.scaledDensity; float answerTextSize = ANSWER_TEXT_SIZE * dm.scaledDensity; mCellSize = CELL_SIZE * dm.density; mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density; mAnswerTextPadding = ANSWER_TEXT_PADDING * dm.density; // Read supplied attributes if (attrs != null) { Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.Crossword, 0, 0); mCellSize = a.getDimension(R.styleable.Crossword_cellSize, mCellSize); mNumberTextPadding = a.getDimension(R.styleable.Crossword_numberTextPadding, mNumberTextPadding); numberTextSize = a.getDimension(R.styleable.Crossword_numberTextSize, numberTextSize); mAnswerTextPadding = a.getDimension(R.styleable.Crossword_answerTextPadding, mAnswerTextPadding); answerTextSize = a.getDimension(R.styleable.Crossword_answerTextSize, answerTextSize); cellFillColor = a.getColor(R.styleable.Crossword_defaultCellFillColor, cellFillColor); cheatedCellFillColor = a.getColor(R.styleable.Crossword_cheatedCellFillColor, cheatedCellFillColor); mistakeCellFillColor = a.getColor(R.styleable.Crossword_mistakeCellFillColor, mistakeCellFillColor); selectedWordFillColor = a.getColor(R.styleable.Crossword_selectedWordFillColor, selectedWordFillColor); selectedCellFillColor = a.getColor(R.styleable.Crossword_selectedCellFillColor, selectedCellFillColor); cellStrokeColor = a.getColor(R.styleable.Crossword_cellStrokeColor, cellStrokeColor); circleStrokeColor = a.getColor(R.styleable.Crossword_circleStrokeColor, circleStrokeColor); textColor = a.getColor(R.styleable.Crossword_textColor, textColor); a.recycle(); } mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION; // Init paints mCellFillPaint = new Paint(); mCellFillPaint.setColor(cellFillColor); mCellFillPaint.setStyle(Paint.Style.FILL); mCheatedCellFillPaint = new Paint(); mCheatedCellFillPaint.setColor(cheatedCellFillColor); mCheatedCellFillPaint.setStyle(Paint.Style.FILL); mMistakeCellFillPaint = new Paint(); mMistakeCellFillPaint.setColor(mistakeCellFillColor); mMistakeCellFillPaint.setStyle(Paint.Style.FILL); mSelectedWordFillPaint = new Paint(); mSelectedWordFillPaint.setColor(selectedWordFillColor); mSelectedWordFillPaint.setStyle(Paint.Style.FILL); mSelectedCellFillPaint = new Paint(); mSelectedCellFillPaint.setColor(selectedCellFillColor); mSelectedCellFillPaint.setStyle(Paint.Style.FILL); mCellStrokePaint = new Paint(); mCellStrokePaint.setColor(cellStrokeColor); mCellStrokePaint.setStyle(Paint.Style.STROKE); // mCellStrokePaint.setStrokeWidth(1); mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCircleStrokePaint.setColor(circleStrokeColor); mCircleStrokePaint.setStyle(Paint.Style.STROKE); mCircleStrokePaint.setStrokeWidth(1); mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberTextPaint.setColor(textColor); mNumberTextPaint.setTextAlign(Paint.Align.CENTER); mNumberTextPaint.setTextSize(numberTextSize); mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mNumberStrokePaint.setColor(cellFillColor); mNumberStrokePaint.setTextAlign(Paint.Align.CENTER); mNumberStrokePaint.setTextSize(numberTextSize); mNumberStrokePaint.setStyle(Paint.Style.STROKE); mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * dm.scaledDensity); mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mAnswerTextPaint.setColor(textColor); mAnswerTextPaint.setTextSize(answerTextSize); mAnswerTextPaint.setTextAlign(Paint.Align.CENTER); // http://www.google.com/fonts/specimen/Kalam Typeface typeface = Typeface.createFromAsset(context.getAssets(), "kalam-regular.ttf"); mAnswerTextPaint.setTypeface(typeface); // Init rest of the values mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth(); mPuzzleCells = EMPTY_CELLS; mPuzzleWidth = 0; mPuzzleHeight = 0; mAllowedChars = EMPTY_CHARS; mRenderScale = 0; mBitmapOffset = new PointF(); mCenteredOffset = new PointF(); mTranslationBounds = new RectF(); mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); mGestureDetector = new GestureDetector(context, new GestureListener()); mContentRect = new RectF(); mPuzzleRect = new RectF(); mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(context, null, true); mZoomer = new Zoomer(context); setFocusableInTouchMode(true); setOnKeyListener(this); }
From source file:com.cssweb.android.view.TrendView.java
private void drawChart(Canvas canvas) throws JSONException { Log.i("@@@@@@@@@draw tick@@@@@@@@@@", quoteArray + ">>>>>>>>>"); //Log.i("@@@@@@@@@@@@@@@@@@@", quoteArray.length()+">>>>>>>>>"); if (quoteArray == null || quoteArray.isNull(0)) return;/*from w w w . java2s. co m*/ canvas.drawColor(GlobalColor.clearSCREEN); paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1); mpaint = new Paint(); mpaint.setTypeface(Typeface.DEFAULT_BOLD); mpaint.setAntiAlias(true); mpaint.setTextAlign(Paint.Align.LEFT); mpaint.setStyle(Paint.Style.STROKE); mpaint.setTextSize(dTextSize); /** * ? */ closeLeft = Utils.dataFormation(high, stockdigit); closeRight = "00.00%"; LSpace = (int) (Math.max(mpaint.measureText(closeLeft), mpaint.measureText(String.valueOf(Math.round(highvolume))))); //??? //RSpace = (int)(paint.measureText(closeRight) + 10); RSpace = 0; axisLabelHeight = Font.getFontHeight(dTextSize); graphicsQuoteWidth = width - LSpace - RSpace; SPACE = graphicsQuoteWidth / MINUTES; topTitleHeight = axisLabelHeight; graphicsQuoteHeight = height - axisLabelHeight - topTitleHeight; price_row_num = 2;//(int)graphicsQuoteHeight/3/25; volume_row_num = price_row_num; price_row_height = graphicsQuoteHeight / price_row_num / 3; volume_row_height = price_row_height; calc_zf(); title1 = ":"; title7 = ":"; title8 = quoteArray.getJSONArray(isTrackNumber).getString(3); title2 = Utils.dataFormation(quoteArray.getJSONArray(isTrackNumber).getDouble(0), stockdigit); mpaint.setColor(GlobalColor.colorLabelName); canvas.drawText(title7 + title8.substring(11, 16), LSpace, axisLabelHeight - 5, mpaint); canvas.drawText(title1, LSpace + mpaint.measureText(":00:0000"), axisLabelHeight - 5, mpaint); if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) == 0) { mpaint.setColor(GlobalColor.colorPriceEqual); } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) > close) { mpaint.setColor(GlobalColor.colorpriceUp); } else if (quoteArray.getJSONArray(isTrackNumber).getDouble(0) < close) { mpaint.setColor(GlobalColor.colorPriceDown); } else { mpaint.setColor(GlobalColor.colorPriceEqual); } canvas.drawText(title2, LSpace + mpaint.measureText(":00:0000:"), axisLabelHeight - 5, mpaint); if (!this.isZs()) { if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange) || "hk".equals(exchange)) { } else { mpaint.setColor(GlobalColor.colorLabelName); title9 = "?:"; canvas.drawText(title9, LSpace + mpaint.measureText(":00:000000:" + title2), axisLabelHeight - 5, mpaint); double avePrice = 0; double cjje = quoteArray.getJSONArray(isTrackNumber).getDouble(2); int scaleCount = 1; scaleCount = Utils.getCoefficient(exchange, stockcode); double cjsl = quoteArray.getJSONArray(isTrackNumber).getDouble(1) * scaleCount; if (cjsl > 0) { avePrice = cjje / cjsl; } else { avePrice = jrkp; } if (avePrice == 0) { mpaint.setColor(GlobalColor.colorPriceEqual); } else if (avePrice > close) { mpaint.setColor(GlobalColor.colorpriceUp); } else if (avePrice < close) { mpaint.setColor(GlobalColor.colorPriceDown); } else { mpaint.setColor(GlobalColor.colorPriceEqual); } canvas.drawText(Utils.dataFormation(avePrice, stockdigit), LSpace + mpaint.measureText(":00:000000:" + title2 + "?:"), axisLabelHeight - 5, mpaint); } } if (isZs()) { if (close == 0) close = 1000; } else { if (close == 0) close = 1; } low = Math.min(low, close); //upPrice = close * (1+max_zf); //downPrice = close * (1-max_zf); paint.setColor(GlobalColor.clrLine); canvas.drawLine(LSpace + graphicsQuoteWidth, topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); // upQuoteX = LSpace; upQuoteY = topTitleHeight; upQuoteWidth = (int) graphicsQuoteWidth; upQuoteHeight = price_row_num * price_row_height; for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, upQuoteX, upQuoteY + price_row_height * i, upQuoteX + upQuoteWidth, upQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } else Graphics.drawDashline(canvas, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY, upQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, upQuoteY + upQuoteHeight, paint); } //scale = close * max_zf / price_row_num; scale = Arith.div(close * max_zf, price_row_num, stockdigit + 1); mpaint.setTextAlign(Paint.Align.RIGHT); mpaint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.dataFormation(close, stockdigit), upQuoteX, upQuoteY + upQuoteHeight + axisLabelHeight / 2, mpaint); mpaint.setColor(GlobalColor.colorpriceUp); for (int i = 1; i <= price_row_num; i++) { AxisLabelPrice = close + scale * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX, upQuoteY + upQuoteHeight - price_row_height * i + axisLabelHeight / 2, mpaint); } // downQuoteX = LSpace; downQuoteY = topTitleHeight + upQuoteHeight; downQuoteWidth = (int) graphicsQuoteWidth; downQuoteHeight = upQuoteHeight; paint.setColor(GlobalColor.clrLine); for (int i = 0; i < price_row_num; i++) { if (i == 0) { canvas.drawLine(downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } else Graphics.drawDashline(canvas, downQuoteX, downQuoteY + price_row_height * i, downQuoteX + downQuoteWidth, downQuoteY + price_row_height * i, paint); } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight + 1, paint); } else Graphics.drawDashline(canvas, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY, downQuoteX + MINUTES / DIVIDE_COUNT * SPACE * i, downQuoteY + downQuoteHeight, paint); } mpaint.setColor(GlobalColor.colorPriceDown); for (int i = 1; i < price_row_num; i++) { AxisLabelPrice = close - scale * i; canvas.drawText(Utils.dataFormation(AxisLabelPrice, stockdigit), upQuoteX, upQuoteY + upQuoteHeight + price_row_height * i + axisLabelHeight / 2, mpaint); } // // added by hujun for 20110511??? if (actualDataLen > 0 && !this.isOpenFund()) { if ("cf".equals(exchange) || "dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { scale = upQuoteHeight / (close * max_zf); paint.setColor(GlobalColor.colorFZLine); int quotelen = quoteArray.length(); double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; x1 = upQuoteX; double lastnewp = 0; double nownewp = 0; nownewp = quoteArray.getJSONArray(0).getDouble(0); if (nownewp == 0) nownewp = close; if (nownewp >= close) { temp = (nownewp - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; nownewp = quoteArray.getJSONArray(i).getDouble(0); if (nownewp == 0) nownewp = lastnewp; if (nownewp >= close) { temp = (nownewp - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(0); double avePrice = cjje; double lastavg = 0; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; double xl = quoteArray.getJSONArray(0).getDouble(1); double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1) - quoteArray.getJSONArray(i - 1).getDouble(1)); if (mathpjj == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1); } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } else { scale = upQuoteHeight / (close * max_zf); paint.setColor(GlobalColor.colorFZLine); int quotelen = quoteArray.length(); double x1 = 0; double y1 = 0; double x2 = 0; double y2 = 0; double temp = 0; x1 = upQuoteX; double lastnewp = 0; double nownewp = 0; nownewp = quoteArray.getJSONArray(0).getDouble(0); if (nownewp == 0) nownewp = close; if (nownewp >= close) { temp = (nownewp - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; nownewp = quoteArray.getJSONArray(i).getDouble(0); if (nownewp == 0) nownewp = lastnewp; if (nownewp >= close) { temp = (nownewp - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - nownewp) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } lastnewp = nownewp; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for if (this.isZs()) { // ? ?? if ("sz".equals(exchange) || "sh".equals(exchange)) { if (("000001".equals(stockcode) || "399001".equals(stockcode)) && !quoteData.isNull("data2")) { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double avePrice = quoteData.getJSONArray("data2").getJSONArray(0).getDouble(0); if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } int len = quoteData.getJSONArray("data2").length(); for (int i = 1; i < len; i++) { if ("15:00".equals(quoteData.getJSONArray("data2").getJSONArray(i).getString(1) .substring(11, 16))) { } else { x2 = upQuoteX + SPACE * i; avePrice = quoteData.getJSONArray("data2").getJSONArray(i).getDouble(0); if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } } // end for } else { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(0); double avePrice = cjje; double lastavg = 0; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; double xl = quoteArray.getJSONArray(0).getDouble(1); double mathpjj = quoteArray.getJSONArray(0).getDouble(0) * xl; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; mathpjj += quoteArray.getJSONArray(i).getDouble(0) * (quoteArray.getJSONArray(i).getDouble(1) - quoteArray.getJSONArray(i - 1).getDouble(1)); if (mathpjj == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = mathpjj / quoteArray.getJSONArray(i).getDouble(1); } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } } } else { paint.setColor(GlobalColor.colorFZAvePriceLine); x1 = upQuoteX; double cjje = quoteArray.getJSONArray(0).getDouble(2); int scaleCount = 1; scaleCount = Utils.getCoefficient(exchange, stockcode); double cjsl = quoteArray.getJSONArray(0).getDouble(1) * scaleCount; double avePrice = cjje / cjsl; double lastavg = 0; if (cjsl == 0) avePrice = close; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y1 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y1 = topTitleHeight + upQuoteHeight + temp; } lastavg = avePrice; for (int i = 1; i < quotelen; i++) { x2 = upQuoteX + SPACE * i; cjje = quoteArray.getJSONArray(i).getDouble(2); cjsl = quoteArray.getJSONArray(i).getDouble(1) * scaleCount; // ? if (cjsl == 0) { if (lastavg == 0) { avePrice = close; } else { avePrice = lastavg; } } else { avePrice = cjje / cjsl; } lastavg = avePrice; if (avePrice > high) { avePrice = high; } if (avePrice < low) { avePrice = low; } if (avePrice >= close) { temp = (avePrice - close) * scale; y2 = topTitleHeight + upQuoteHeight - temp; } else { temp = (close - avePrice) * scale; y2 = topTitleHeight + upQuoteHeight + temp; } canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); x1 = x2; y1 = y2; } // end for } } } // ?? volumeX = LSpace; volumeY = topTitleHeight + upQuoteHeight + downQuoteHeight; volumeWidth = (int) graphicsQuoteWidth; volumeHeight = graphicsQuoteHeight - upQuoteHeight - downQuoteHeight; volume_row_height = volumeHeight / volume_row_num; paint.setColor(GlobalColor.clrLine); for (int i = 0; i <= volume_row_num; i++) { if (i == 0) { canvas.drawLine(volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } else { if (i != volume_row_num) Graphics.drawDashline(canvas, volumeX, volumeY + volume_row_height * i, volumeX + volumeWidth, volumeY + volume_row_height * i, paint); } } for (int i = 0; i < DIVIDE_COUNT; i++) { if (i == 0) { canvas.drawLine(volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } else Graphics.drawDashline(canvas, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY, volumeX + MINUTES / DIVIDE_COUNT * SPACE * i, volumeY + volumeHeight, paint); } if (this.isZs()) { //highVolume = TickUtil.gethighAmount(quoteData.getJSONArray("data")); highVolume = highamount; } else { //highVolume = TickUtil.gethighVolume(quoteData.getJSONArray("data")); highVolume = highvolume; } if (highVolume == 0) { if (this.isZs()) { // ? highVolume = volume_row_num * 4 * 100; // ???48highVolume=32 } else { highVolume = volume_row_num * 4 * 100; // ???48highVolume=32 } } if (highVolume < volume_row_num + 1) highVolume = volume_row_num + 1; scale = highVolume / volume_row_num; int volumeLabelY = volumeY + Font.getFontHeight(dTextSize) / 2; mpaint.setColor(GlobalColor.clr_tick_volume); for (int i = 0; i <= volume_row_num; i++) { if (i != volume_row_num) { AxisLabelVolume = highVolume - scale * i; if (this.isZs()) AxisLabelVolume = Math.round(AxisLabelVolume / 10000); else AxisLabelVolume = Math.round(AxisLabelVolume); canvas.drawText(String.valueOf((int) AxisLabelVolume), upQuoteX, volumeLabelY + volume_row_height * i, mpaint); } } // ?? if (actualDataLen > 0) { scale = volumeHeight / highVolume; paint.setColor(GlobalColor.colorVolumeLine); double prevVol = 0; double temp = 0; for (int i = 0; i < actualDataLen; i++) { if (this.isZs()) temp = (quoteArray.getJSONArray(i).getDouble(2) - prevVol) * scale; else temp = (quoteArray.getJSONArray(i).getDouble(1) - prevVol) * scale; float x1 = volumeX + SPACE * i; float y1 = (float) (volumeY + volumeHeight - temp); float x2 = x1; float y2 = volumeY + volumeHeight; canvas.drawLine((int) x1, (int) y1, (int) x2, (int) y2, paint); if (this.isZs()) prevVol = quoteArray.getJSONArray(i).getDouble(2); else prevVol = quoteArray.getJSONArray(i).getDouble(1); } } drawTimeX(canvas); // paint.setColor(GlobalColor.clrLine); canvas.drawLine(LSpace, graphicsQuoteHeight + topTitleHeight, LSpace + graphicsQuoteWidth, graphicsQuoteHeight + topTitleHeight, paint); if (isTrackStatus) { canvas.save(); //?? paint.setColor(GlobalColor.colorLine); canvas.drawLine(trackLineV, topTitleHeight, trackLineV, graphicsQuoteHeight + topTitleHeight, paint); canvas.restore(); } }
From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java
/** * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone * number, and if there is a photo also adds the call action icon. *//* w w w .j av a 2 s .c o m*/ private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) { final Resources r = mContext.getResources(); final float density = r.getDisplayMetrics().density; Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity)).getBitmap(); Bitmap icon = generateQuickContactIcon(photo); Canvas canvas = new Canvas(icon); // Copy in the photo Paint photoPaint = new Paint(); photoPaint.setDither(true); photoPaint.setFilterBitmap(true); Rect dst = new Rect(0, 0, mIconSize, mIconSize); // Create an overlay for the phone number type CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel); if (overlay != null) { TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size)); textPaint.setColor(ContextCompat.getColor(mContext, R.color.textColorIconOverlay)); textPaint.setShadowLayer(4f, 0, 2f, ContextCompat.getColor(mContext, R.color.textColorIconOverlayShadow)); final FontMetricsInt fmi = textPaint.getFontMetricsInt(); // First fill in a darker background around the text to be drawn final Paint workPaint = new Paint(); workPaint.setColor(mOverlayTextBackgroundColor); workPaint.setStyle(Paint.Style.FILL); final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding); final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2; dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize); canvas.drawRect(dst, workPaint); overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END); final float textWidth = textPaint.measureText(overlay, 0, overlay.length()); canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2, mIconSize - fmi.descent - textPadding, textPaint); } // Draw the phone action icon as an overlay Rect src = new Rect(0, 0, phoneIcon.getWidth(), phoneIcon.getHeight()); int iconWidth = icon.getWidth(); dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density))); canvas.drawBitmap(phoneIcon, src, dst, photoPaint); canvas.setBitmap(null); return icon; }
From source file:in.sc9.discreteslider.DiscreteSlider.java
public DiscreteSlider(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setFocusable(true);//w ww . ja v a 2 s . com setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSlider, defStyleAttr, R.style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSlider_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSlider_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); mIndicatorTextFromArray = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorTextFromArray, mIndicatorTextFromArray); int indexMax = R.styleable.DiscreteSlider_dsb_max; int indexMin = R.styleable.DiscreteSlider_dsb_min; int indexValue = R.styleable.DiscreteSlider_dsb_value; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mIndicatorFormatter = a.getString(R.styleable.DiscreteSlider_dsb_indicatorFormatter); mDiscretePointsEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsEnabled, false); mDiscretePointsShowAlways = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsShowAlways, false); ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_rippleColor); int discretePointColor = a.getColor(R.styleable.DiscreteSlider_dsb_discretePointsColor, Color.RED); mtextColor = a.getColor(R.styleable.DiscreteSlider_dsb_textColor, Color.BLACK); mTextSize = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextSize); mTextPaddingTop = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextPaddingTop); textStyle = a.getInt(R.styleable.DiscreteSlider_dsb_TextStyle, textStyle); boolean editMode = isInEditMode(); if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR }); } if (editMode) { discretePointColor = Color.RED; mtextColor = Color.BLACK; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); mThumb = new ThumbDrawable(progressColor, thumbSize); mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); textArray = new String[((mMax - mMin) + 1)]; int j = mMin; for (int i = 0; i < ((mMax - mMin) + 1); i++) { if (j <= mMax) { textArray[i] = j + ""; j++; } else break; } if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax)); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); mDiscretePoints = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscretePoints.setColor(discretePointColor); mDiscretePoints.setStyle(Paint.Style.FILL); mDiscretePointsTran = new Paint(Paint.ANTI_ALIAS_FLAG); mDiscretePointsTran.setColor(Color.TRANSPARENT); mDiscretePointsTran.setStyle(Paint.Style.FILL_AND_STROKE); position = new RectF(); }
From source file:com.marlonjones.voidlauncher.allapps.AllAppsGridAdapter.java
public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) { Resources res = launcher.getResources(); mLauncher = launcher;//from w w w . ja va 2 s . c om mApps = apps; mEmptySearchMessage = res.getString(R.string.all_apps_loading_message); mGridSizer = new GridSpanSizer(); mGridLayoutMgr = new AppsGridLayoutManager(launcher); mGridLayoutMgr.setSpanSizeLookup(mGridSizer); mItemDecoration = new GridItemDecoration(); mLayoutInflater = LayoutInflater.from(launcher); mIconClickListener = iconClickListener; mIconLongClickListener = iconLongClickListener; mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset); mIsRtl = Utilities.isRtl(res); mSectionTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size)); mSectionTextPaint.setColor(Utilities.getColorAccent(launcher)); }
From source file:org.telegram.ui.ThemePreviewActivity.java
@Override public View createView(Context context) { page1 = new FrameLayout(context); ActionBarMenu menu = actionBar.createMenu(); final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override/*w ww . j a v a 2 s.c om*/ public void onSearchExpand() { } @Override public boolean canCollapseSearch() { return true; } @Override public void onSearchCollapse() { } @Override public void onTextChanged(EditText editText) { } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); actionBar.setBackButtonDrawable(new MenuDrawable()); actionBar.setAddToContainer(false); actionBar.setTitle(LocaleController.getString("ThemePreview", R.string.ThemePreview)); page1 = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar.getMeasuredHeight(); if (actionBar.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); measureChildWithMargins(floatingButton, widthMeasureSpec, 0, heightMeasureSpec, 0); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0); } return result; } }; page1.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page1.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); floatingButton = new ImageView(context); floatingButton.setScaleType(ImageView.ScaleType.CENTER); Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground)); if (Build.VERSION.SDK_INT < 21) { Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate(); shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY)); CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0); combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56)); drawable = combinedDrawable; } floatingButton.setBackgroundDrawable(drawable); floatingButton.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY)); floatingButton.setImageResource(R.drawable.floating_pencil); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); floatingButton.setStateListAnimator(animator); floatingButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } page1.addView(floatingButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); dialogsAdapter = new DialogsAdapter(context); listView.setAdapter(dialogsAdapter); page2 = new SizeNotifierFrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); measureChildWithMargins(actionBar2, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar2.getMeasuredHeight(); if (actionBar2.getVisibility() == VISIBLE) { heightSize -= actionBarHeight; } FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView2.getLayoutParams(); layoutParams.topMargin = actionBarHeight; listView2.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); } @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar2 && parentLayout != null) { parentLayout.drawHeaderShadow(canvas, actionBar2.getVisibility() == VISIBLE ? actionBar2.getMeasuredHeight() : 0); } return result; } }; page2.setBackgroundImage(Theme.getCachedWallpaper()); actionBar2 = createActionBar(context); actionBar2.setBackButtonDrawable(new BackDrawable(false)); actionBar2.setTitle("Reinhardt"); actionBar2.setSubtitle(LocaleController.formatDateOnline(System.currentTimeMillis() / 1000 - 60 * 60)); page2.addView(actionBar2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); listView2 = new RecyclerListView(context); listView2.setVerticalScrollBarEnabled(true); listView2.setItemAnimator(null); listView2.setLayoutAnimation(null); listView2.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4)); listView2.setClipToPadding(false); listView2.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true)); listView2.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT); page2.addView(listView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); messagesAdapter = new MessagesAdapter(context); listView2.setAdapter(messagesAdapter); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; final ViewPager viewPager = new ViewPager(context); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { dotsContainer.invalidate(); } @Override public void onPageScrollStateChanged(int state) { } }); viewPager.setAdapter(new PagerAdapter() { @Override public int getCount() { return 2; } @Override public boolean isViewFromObject(View view, Object object) { return object == view; } @Override public int getItemPosition(Object object) { return POSITION_UNCHANGED; } @Override public Object instantiateItem(ViewGroup container, int position) { View view = position == 0 ? page1 : page2; container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { if (observer != null) { super.unregisterDataSetObserver(observer); } } }); AndroidUtilities.setViewPagerEdgeEffectColor(viewPager, Theme.getColor(Theme.key_actionBarDefault)); frameLayout.addView(viewPager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48)); View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); frameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48)); FrameLayout bottomLayout = new FrameLayout(context); bottomLayout.setBackgroundColor(0xffffffff); frameLayout.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM)); dotsContainer = new View(context) { private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); @Override protected void onDraw(Canvas canvas) { int selected = viewPager.getCurrentItem(); for (int a = 0; a < 2; a++) { paint.setColor(a == selected ? 0xff999999 : 0xffcccccc); canvas.drawCircle(AndroidUtilities.dp(3 + 15 * a), AndroidUtilities.dp(4), AndroidUtilities.dp(3), paint); } } }; bottomLayout.addView(dotsContainer, LayoutHelper.createFrame(22, 8, Gravity.CENTER)); TextView cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Theme.applyPreviousTheme(); parentLayout.rebuildAllFragmentViews(false); finishFragment(); } }); TextView doneButton = new TextView(context); doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButton.setTextColor(0xff19a7e8); doneButton.setGravity(Gravity.CENTER); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x2f000000, 0)); doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); doneButton.setText(LocaleController.getString("ApplyTheme", R.string.ApplyTheme).toUpperCase()); doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { applied = true; parentLayout.rebuildAllFragmentViews(false); Theme.applyThemeFile(themeFile, applyingTheme.name, false); finishFragment(); } }); return fragmentView; }