Java tutorial
//package com.java2s; /* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; public class Main { private static final String MORE_SUGGESTIONS_HINT = "\u2026"; private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); return new BitmapDrawable(res, buffer); } }