Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResource.

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:com.achep.acdisplay.App.java

@Override
public void onCreate() {
    mAccessManager = new AccessManager(this);

    AppHeap.getInstance().init(this);
    Config.getInstance().init(this);
    Blacklist.getInstance().init(this);
    SmileyParser.init(this);

    // Init the main notification listener.
    NotificationPresenter.getInstance()//from   w w w  .j  ava2 s . c o  m
            .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null);

    super.onCreate();

    // Check the main switch.
    String divider = getString(R.string.settings_multi_list_divider);
    Config config = Config.getInstance();
    if (config.isEnabled()) {
        StringBuilder sb = new StringBuilder();
        boolean foundAny = false;

        PermissionGroup pg = getAccessManager().getMasterPermissions();
        for (Permission permission : pg.permissions) {
            if (!permission.isActive()) {
                if (foundAny) {
                    sb.append(divider);
                } else
                    foundAny = true;
                sb.append(getString(permission.getTitleResource()));
            }
        }

        if (foundAny) {
            String list = sb.toString();
            list = list.charAt(0) + list.substring(1).toLowerCase();

            ConfigBase.Option option = config.getOption(Config.KEY_ENABLED);
            option.write(config, this, false, null);

            final int id = App.ID_NOTIFY_APP_AUTO_DISABLED;
            PendingIntent pendingIntent = PendingIntent.getActivity(this, id,
                    new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
            NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                    .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(getString(R.string.permissions_auto_disabled))
                    .setContentIntent(pendingIntent).setLargeIcon(largeIcon)
                    .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts)
                    .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR);

            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(id, builder.build());
        }
    }
    // Check the keyguard (without the notification).
    if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) {
        ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD);
        option.write(config, this, false, null);
    }

    // Launch keyguard and (or) active mode on
    // app launch.
    KeyguardService.handleState(this);
    ActiveModeService.handleState(this);
    SensorsDumpService.handleState(this);
}

From source file:ar.fiuba.jobify.JobifyChat.java

/**
 * Called when message is received.// w  ww. j a va 2  s  . c  o m
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        String body = remoteMessage.getData() + "";
        Log.d(TAG, "Message data payload: " + body);
        JsonParser parser = new JsonParser();
        //JsonObject message = parser.parse(body).getAsJsonObject();
        JSONObject message = null;
        try {
            message = new JSONObject(body);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (message.has("mensaje")) {

            long sender = 0, receiver = 0;
            try {
                receiver = message.getJSONObject("mensaje").getLong("to");
                sender = message.getJSONObject("mensaje").getLong("from");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0)
                    .getLong(getString(R.string.stored_connected_user_id), -1);
            //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id)));

            if (receiver != currentId) {
                // la app no esta abierta
                return;
            }

            if (!(ConversacionActivity.activityVisible && ConversacionActivity.corresponsalID == sender)) {
                NotificationCompat.Builder mBuilder = null;
                try {
                    mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nuevo mensaje")
                            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true)
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.mensaje))
                            .setSmallIcon(R.drawable.logo_v2_j_square)
                            .setContentText(message.getJSONObject("mensaje").getString("message"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                //ConversacionActivity.

                Intent resultIntent = new Intent(this, ConversacionActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
                stackBuilder.addParentStack(ConversacionActivity.class);

                // Adds the Intent that starts the Activity to the top of the stack
                stackBuilder.addNextIntent(resultIntent);
                resultIntent.putExtra(ConversacionActivity.CORRESPONSAL_ID_MESSAGE, (long) sender);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mBuilder.setContentIntent(resultPendingIntent);

                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);

                Random r = new Random();
                mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build());

            }
            // notify chat
            try {
                EventBus.getDefault().post(new MessageEvent(message.getJSONObject("mensaje")));
            } catch (JSONException e) {
                e.printStackTrace();
            }

        } else if (message.has("solicitud")) {

            long receiver = 0;
            try {
                receiver = message.getJSONObject("solicitud").getLong("toId");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            long currentId = getSharedPreferences(getString(R.string.shared_pref_connected_user), 0)
                    .getLong(getString(R.string.stored_connected_user_id), -1);
            //Log.d("MYTAG", editor.g getLong( getString(R.string.stored_connected_user_id)));

            if (receiver != currentId) {
                // la app no esta abierta
                return;
            }

            NotificationCompat.Builder mBuilder = null;
            try {
                mBuilder = new NotificationCompat.Builder(this).setContentTitle("Nueva solicitud")
                        .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark).setAutoCancel(true)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.solicitud))
                        .setSmallIcon(R.drawable.logo_v2_j_square)
                        .setContentText(message.getJSONObject("solicitud").getString("fromNombre"));
            } catch (JSONException e) {
                e.printStackTrace();
            }

            Intent resultIntent = new Intent(this, UserListActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(UserListActivity.class);

            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(resultIntent);
            resultIntent.putExtra(UserListActivity.LIST_MODE_MESSAGE, UserListActivity.MODE_SOLICITUDES);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);

            Random r = new Random();
            mNotificationManager.notify(r.nextInt(1000000000), mBuilder.build());

        }
        // if this is a notification:
        // TODO
        // here we call the callback to the activity

        // if this is a message:

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}

From source file:com.bullmobi.message.App.java

@Override
public void onCreate() {
    mAccessManager = new AccessManager(this);

    AppHeap.getInstance().init(this);
    Config.getInstance().init(this);
    Blacklist.getInstance().init(this);
    SmileyParser.init(this);

    // Init the main notification listener.
    NotificationPresenter.getInstance()/*from  w w w.  ja va2  s  .  c o m*/
            .setOnNotificationPostedListener(Config.getInstance().isEnabled() ? Presenter.getInstance() : null);

    super.onCreate();

    // Check the main switch.
    String divider = getString(R.string.settings_multi_list_divider);
    Config config = Config.getInstance();
    if (config.isEnabled()) {
        StringBuilder sb = new StringBuilder();
        boolean foundAny = false;

        PermissionGroup pg = getAccessManager().getMasterPermissions();
        for (Permission permission : pg.permissions) {
            if (!permission.isActive()) {
                if (foundAny) {
                    sb.append(divider);
                } else
                    foundAny = true;
                sb.append(getString(permission.getTitleResource()));
            }
        }

        if (foundAny) {
            String list = sb.toString();
            list = list.charAt(0) + list.substring(1).toLowerCase();

            ConfigBase.Option option = config.getOption(Config.KEY_ENABLED);
            option.write(config, this, false, null);

            final int id = App.ID_NOTIFY_APP_AUTO_DISABLED;
            PendingIntent pendingIntent = PendingIntent.getActivity(this, id,
                    new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
            NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                    .bigText(getString(R.string.permissions_auto_disabled)).setSummaryText(list);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(getString(R.string.permissions_auto_disabled))
                    .setContentIntent(pendingIntent).setLargeIcon(largeIcon)
                    .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts)
                    .setPriority(Notification.PRIORITY_HIGH).setColor(App.ACCENT_COLOR);

            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(id, builder.build());
        }
    }
    // Check the keyguard (without the notification).
    if (config.isKeyguardEnabled() && !getAccessManager().getKeyguardPermissions().isActive()) {
        ConfigBase.Option option = config.getOption(Config.KEY_KEYGUARD);
        option.write(config, this, false, null);
    }

    // Launch keyguard and (or) active mode on
    // app launch.
    KeyguardService.handleState(this);
    ActiveModeService.handleState(this);
    SensorsDumpService.handleState(this);
}

From source file:com.benext.thibault.appsample.notification.builder.NotificationBuilder.java

public static NotificationCompat.Builder buildNotificationExtenderPages(Context context) {

    ArrayList<Notification> pages = new ArrayList<>();

    // Create first page notification
    Bitmap tableImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto);
    Notification page1 = new NotificationCompat.Builder(context).extend(
            new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true).setBackground(tableImg))
            .build();/*from   w  ww.j a v a 2 s .co m*/

    pages.add(page1);

    // Create second page notification
    Spannable meatTitle = new SpannableString(context.getString(R.string.menu_meats));
    meatTitle.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, meatTitle.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    NotificationCompat.InboxStyle secondPageStyle = new NotificationCompat.InboxStyle();
    secondPageStyle.setBigContentTitle("Page 2").setSummaryText("")
            .addLine(getSpannableString(context, R.string.menu_starters, Typeface.BOLD))
            .addLine(context.getString(R.string.menu_starters_content1))
            .addLine(context.getString(R.string.menu_starters_content2))
            .addLine(getSpannableString(context, R.string.menu_meats, Typeface.BOLD))
            .addLine(context.getString(R.string.menu_meats_content1))
            .addLine(context.getString(R.string.menu_meats_content2));

    Notification page2 = new NotificationCompat.Builder(context)
            .extend(new NotificationCompat.WearableExtender().setBackground(
                    BitmapFactory.decodeResource(context.getResources(), R.drawable.table_restaurant)))
            .setStyle(secondPageStyle).build();

    pages.add(page2);

    // Create builder for the main notification
    Bitmap restoImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.resto);
    return (NotificationCompat.Builder) buildNotificationSimpleNBackground(context)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(restoImg))
            .extend(new NotificationCompat.WearableExtender().addPages(pages));
}

From source file:com.android.tripgenie.auto.MessagingService.java

private void sendNotificationForConversation(int conversationId, String sender, String message,
        long timestamp) {
    String contentTitle;/*from   www.  ja  va 2s  .c  o  m*/
    if (message.indexOf(" is ") > 0) {
        contentTitle = message.substring(0, message.indexOf(" is "));
    } else {
        contentTitle = message;
    }

    // A pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReadIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    /// Add the code to create the UnreadConversation

    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId,
            getMessageReplyIntent(conversationId), PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    UnreadConversation.Builder unreadConversationBuilder = new UnreadConversation.Builder(contentTitle)
            .setLatestTimestamp(timestamp).setReadPendingIntent(readPendingIntent)
            .setReplyAction(replyIntent, remoteInput);

    // Note: Add messages from oldest to newest to the UnreadConversation.Builder
    // Since we are sending a single message here we simply add the message.
    // In a real world application there could be multiple messages which should be ordered
    // and added from oldest to newest.
    unreadConversationBuilder.addMessage(message);
    /// End create UnreadConversation

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
                    R.drawable.android_contact))
            .setContentText(message)
            //.setWhen(timestamp)
            .setOngoing(true).setContentTitle(contentTitle).setContentIntent(readPendingIntent)
            /// Extend the notification with CarExtender.
            .extend(new CarExtender().setUnreadConversation(unreadConversationBuilder.build()))
    /// End
    ;

    Log.d(TAG, "Sending notification " + conversationId + " conversation: " + message);

    NotificationManagerCompat.from(this).notify(conversationId, builder.build());
}

From source file:com.keylesspalace.tusky.util.NotificationManager.java

/**
 * Takes a given Mastodon notification and either creates a new Android notification or updates
 * the state of the existing notification to reflect the new interaction.
 *
 * @param context  to access application preferences and services
 * @param notifyId an arbitrary number to reference this notification for any future action
 * @param body     a new Mastodon notification
 *//*from ww w  .  j a  v  a 2s . c o  m*/
public static void make(final Context context, final int notifyId, Notification body) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences notificationPreferences = context.getSharedPreferences("Notifications",
            Context.MODE_PRIVATE);

    if (!filterNotification(preferences, body)) {
        return;
    }

    createNotificationChannels(context);

    String rawCurrentNotifications = notificationPreferences.getString("current", "[]");
    JSONArray currentNotifications;

    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }

    boolean alreadyContains = false;

    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.account.getDisplayName())) {
                alreadyContains = true;
            }
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    if (!alreadyContains) {
        currentNotifications.put(body.account.getDisplayName());
    }

    notificationPreferences.edit().putString("current", currentNotifications.toString()).apply();

    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.putExtra("tab_position", 1);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent deleteIntent = new Intent(context, NotificationClearBroadcastReceiver.class);
    PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getChannelId(body))
            .setSmallIcon(R.drawable.ic_notify).setContentIntent(resultPendingIntent)
            .setDeleteIntent(deletePendingIntent).setColor(ContextCompat.getColor(context, (R.color.primary)))
            .setDefaults(0); // So it doesn't ring twice, notify only in Target callback

    setupPreferences(preferences, builder);

    if (currentNotifications.length() == 1) {
        builder.setContentTitle(titleForType(context, body))
                .setContentText(truncateWithEllipses(bodyForType(body), 40));

        //load the avatar synchronously
        Bitmap accountAvatar;
        try {
            accountAvatar = Picasso.with(context).load(body.account.avatar)
                    .transform(new RoundedTransformation(7, 0)).get();
        } catch (IOException e) {
            Log.d(TAG, "error loading account avatar", e);
            accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
        }

        builder.setLargeIcon(accountAvatar);

    } else {
        try {
            String format = context.getString(R.string.notification_title_summary);
            String title = String.format(format, currentNotifications.length());
            String text = truncateWithEllipses(joinNames(context, currentNotifications), 40);
            builder.setContentTitle(title).setContentText(text);
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE);
        builder.setCategory(android.app.Notification.CATEGORY_SOCIAL);
    }

    android.app.NotificationManager notificationManager = (android.app.NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    //noinspection ConstantConditions
    notificationManager.notify(notifyId, builder.build());
}

From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//  w w  w .j a va2 s. c  o  m
 */
private void sendNotification(String message) {
    Activity currentAct = UnityPlayer.currentActivity;
    Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class;
    Intent intent = new Intent(this, activityToOpen);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1);
        if (notificationIcon == -1) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }
        int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
        if (notificationLargeIcon == -1) {
            Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
            return;
        }

        String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
        if (pushNotifName == null) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }

        if (notifManager == null)
            notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance);
            channel.setDescription("CotC Channel");
            notifManager.createNotificationChannel(channel);
            notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel");
        } else
            notificationBuilder = new NotificationCompat.Builder(this);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH);
        if (notificationLargeIcon != -1)
            notificationBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

        notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
    } catch (Exception e) {
        Log.w(TAG, "Failed to handle push notification", e);
    }
}

From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java

/**
 * @param canvas/*w  w w .j a  va2s.c o m*/
 */

@Override
protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);
    if (mViewPager == null) {
        return;
    }
    final int count = mViewPager.getAdapter().getCount();
    if (count == 0) {
        return;
    }

    if (mCurrentPage >= count) {
        setCurrentItem(count - 1);
        return;
    }
    float dx = -1;
    Bitmap imageChildDefault = BitmapFactory.decodeResource(mContext.getResources(), drawableDefaultId);
    Bitmap imageChildSelected = BitmapFactory.decodeResource(mContext.getResources(), drawableSelectedId);
    Bitmap imageToDraw;
    int imageSize = imageChildDefault.getWidth();
    int canvasWidth = canvas.getWidth();
    int circlesWith = (imageSize * count) + imageSpacing * (count - 1);
    int startingPoint = (canvasWidth - circlesWith) / 2;
    for (int i = 0; i < count; i++) {

        if (i == 0) {
            dx = 0;
        }
        /**
         * position images indicator on the center
         */
        if (mCentered) {
            dx = startingPoint + i * (imageSize + imageSpacing);
        }

        if (mCurrentPage == i) {
            imageToDraw = imageChildSelected;

        } else {
            imageToDraw = imageChildDefault;
        }
        canvas.drawBitmap(imageToDraw, dx, 0, null);

        /**
         * position images indicator from the left
         */
        if (!mCentered) {
            dx += imageChildDefault.getWidth() + imageSpacing;
        }
    }
}

From source file:com.adam.aslfms.service.ScrobblingService.java

@Override
public void onCreate() {
    settings = new AppSettings(this);
    mDb = new ScrobblesDatabase(this);
    mDb.open();/*w ww  . j a  v  a  2 s.c om*/
    mNetManager = new NetworkerManager(this, mDb);

    int sdk = Build.VERSION.SDK_INT;
    if (sdk == Build.VERSION_CODES.GINGERBREAD || sdk == Build.VERSION_CODES.GINGERBREAD_MR1) {
        if (settings.isOnGoingEnabled(Util.checkPower(mCtx))) {
            if (mCurrentTrack != null) {
                String ar = mCurrentTrack.getArtist();
                String tr = mCurrentTrack.getTrack();
                String api = mCurrentTrack.getMusicAPI().readAPIname();

                // Heart intent
                Intent heartIntent = new Intent(mCtx, ScrobblingService.class);
                heartIntent.setAction(ScrobblingService.ACTION_HEART);
                PendingIntent heartPendingIntent = PendingIntent.getService(mCtx, 0, heartIntent, 0);
                NotificationCompat.Action heartAction = new NotificationCompat.Action.Builder(
                        R.mipmap.ic_status_wail_love_track, "", heartPendingIntent).build();

                Intent targetIntent = new Intent(mCtx, SettingsActivity.class);
                PendingIntent contentIntent = PendingIntent.getActivity(mCtx, 0, targetIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx).setContentTitle(tr)
                        .setSmallIcon(R.mipmap.ic_notify).setContentText(ar + " :" + api)
                        .setPriority(NotificationCompat.PRIORITY_MIN).addAction(heartAction)
                        .setContentIntent(contentIntent);

                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
                    builder.setLargeIcon(
                            BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher));
                }

                this.startForeground(14619, builder.build());
                if (!settings.isNotifyEnabled(Util.checkPower(mCtx))) {
                    Intent iNoti = new Intent(mCtx, ForegroundHide.class);
                    this.startService(iNoti);
                }
            }
        } else {
            this.stopForeground(true); // TODO: test if this conflicts/stops scrobbles
        }
    }
}