spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Android QuickContactBadge with letters like Android Lollipop


I use a function to generate these images.

public static Bitmap
generateCircleBitmap(Context context, int
circleColor, float diameterDP, String text){
    final int textColor = 0xffffffff;

    DisplayMetrics metrics =
Resources.getSystem().getDisplayMetrics();
    float diameterPixels = diameterDP *
(metrics.densityDpi / 160f);
    float radiusPixels = diameterPixels/2;

    // Create the bitmap
    Bitmap output = Bitmap.createBitmap((int)
diameterPixels, (int) diameterPixels,
            Bitmap.Config.ARGB_8888);

    // Create the canvas to draw on
    Canvas canvas = new Canvas(output);
    canvas.drawARGB(0, 0, 0, 0);

    // Draw the circle
    final Paint paintC = new Paint();
    paintC.setAntiAlias(true);
    paintC.setColor(circleColor);
    canvas.drawCircle(radiusPixels, radiusPixels,
radiusPixels, paintC);

    // Draw the text
    if (text != null && text.length() >
0) {
        final Paint paintT = new Paint();
        paintT.setColor(textColor);
        paintT.setAntiAlias(true);
        paintT.setTextSize(radiusPixels * 2);
        Typeface typeFace =
Typeface.createFromAsset(context.getAssets(),"fonts/Roboto-Thin.ttf");
        paintT.setTypeface(typeFace);
        final Rect textBounds = new Rect();
        paintT.getTextBounds(text, 0,
text.length(), textBounds);
        canvas.drawText(text, radiusPixels -
textBounds.exactCenterX(), radiusPixels -
textBounds.exactCenterY(), paintT);
    }

    return output;
}

I pass the contact's name into the following getMaterialColor function to select a color.

private static List<Integer>
materialColors = Arrays.asList(
        0xffe57373,
        0xfff06292,
        0xffba68c8,
        0xff9575cd,
        0xff7986cb,
        0xff64b5f6,
        0xff4fc3f7,
        0xff4dd0e1,
        0xff4db6ac,
        0xff81c784,
        0xffaed581,
        0xffff8a65,
        0xffd4e157,
        0xffffd54f,
        0xffffb74d,
        0xffa1887f,
        0xff90a4ae
);

public static int getMaterialColor(Object key) {
    return material.get(Math.abs(key.hashCode()) %
materialColors.size());
}

Categories : Android

Related to : Android QuickContactBadge with letters like Android Lollipop
Android Lollipop preference
It' s simple. Just apply the Theme.AppCompat.xxx to your activity and put your PreferenceFragment in that activity if you use the Api level >= 11. EDIT for the lastest supoort libary appcompat-v7, google provides AppCompatDelegate to do the trick, here is the sample code from google.

Categories : Android
Cannot get foreground activity name in Android Lollipop 5.0 only
getRunningTasks() This method was deprecated in API level 21. As of LOLLIPOP, this method is no longer available to third party applications: the introduction of document-centric recents means it can leak person information to the caller. For backwards compatibility, it will still return a small subset of its data: at least the caller's own tasks, and possibly some other tasks such a

Categories : Android
Lollipop .setPackage("com.android.phone")
The package name of Lollipop's dialer is com.google.android.dialer (on Nexus devices at least). If you really want to hardcode the package name, you may have to detect which dialer is available on the device.

Categories : Android
Android 5 Lollipop SQLite Performance
Sqlite 3.8 introduced the Next Generation Query Planner. It may make different choices, but is supposed to be better. (I'm assuming here that the query plans for your query differ in a significant way between sqlite versions. You've only posted one of them.) Allow me to quote an excerpt from the docs on the new planner, "Hazards of upgrading to NGQP": But as with any query planner change, up

Categories : Android
Android lollipop error code -505 during installation app
Let me guess - you your apps were made with adobe air? It's a bug google introduced with lollipop. Its related to the SHA1 generation from some certificates. See: http://www.zdnet.com/android-lollipop-users-warn-of-unusable-devices-after-upgrading-7000035977/ https://forums.adobe.com/message/6942812#6942812 https://code.google.com/p/android/issues/detail?d=79089 https://code.google.com/p/andro

Categories : Android
Recently Add
Wait for all requests in Android Volley
android scrollview not working
Android: How to prevent a Wifi disconnect on DHCP renewal?
Using HorizontalScrollView for gallery - no pictures inside
-bash: export: not a valid identifier
m3u8 Video stops with MediaPlayer: Error (1,-1004)
java.lang.IndexOutOfBoundsException at ListView android
Facebook REST calls for mobile cross-platform app
How to returning image from camera intent and placing in google maps api v2 as thumbnail
How can I add a row to a ListView in one Fragment by clicking the button in another Fragment?
Using MediaController on Android 5
Is TCP packet filtering possible on mobile platforms?
Spinner from editext android
Incomplete file downloaded in android using DataInputStream
How do I delete a row form SQLite DB via ListView and refresh list view?
Change action bar to toolbar, and now I am having force closes. What am I doing wrong here?
Adding buttons below GraphView, all inside a Fragment
Get rotation and display in degrees
What methods are available to execute things in the background
Data Persistence Android
Intent not delivered correctly
Android Studio 1.0 RC 1 Gradle build issues - Could not run build action using Gradle installation
otto eventbus for android behaves differently in release build
How get item ID from ListFragment in android?
Receive bluetooth connection changes after reboot
Encrypting plain-text passwords and passing variables to xml for display in android
android html5 video fullscreenchange not called on entering fullscreen
Want to create API for my android application done using Intel XDK
Gps not getting location
Spannable Text is not working in Dialog Fragment
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.