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:androidavanzato.wearablenotifications.NotificationPresets.java

private static NotificationCompat.Builder applyBasicOptions(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions, NotificationPreset.BuildOptions options) {
    builder.setContentTitle(options.titlePreset).setContentText(options.textPreset)
            .setSmallIcon(R.mipmap.ic_launcher).setDeleteIntent(
                    NotificationUtil.getExamplePendingIntent(context, R.string.example_notification_deleted));
    options.actionsPreset.apply(context, builder, wearableOptions);
    options.priorityPreset.apply(builder, wearableOptions);
    if (options.includeLargeIcon) {
        builder.setLargeIcon(/*from   w  ww  . j a  va 2s  .  c o m*/
                BitmapFactory.decodeResource(context.getResources(), R.drawable.example_large_icon));
    }
    if (options.isLocalOnly) {
        builder.setLocalOnly(true);
    }
    if (options.hasContentIntent) {
        builder.setContentIntent(
                NotificationUtil.getExamplePendingIntent(context, R.string.content_intent_clicked));
    }
    if (options.vibrate) {
        builder.setVibrate(new long[] { 0, 100, 50, 100 });
    }
    return builder;
}

From source file:com.example.kyle.weatherforecast.MainActivity.java

private void postAlert(int i) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("Weather Alert!").setContentText(WeatherData.outlookArray[i])
            .setSmallIcon(R.drawable.small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), WeatherData.symbolArray[i]))
            .setAutoCancel(true).setTicker("Wrap up warm!")
            // Heads-up and lock screen notifications
            .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_HIGH)
            .setVibrate(new long[] { 100, 100, 100, 200, 200 }).setVibrate(new long[] { 0 })
            .setCategory(Notification.CATEGORY_ALARM);

    NotificationCompat.BigPictureStyle bigStyle = new NotificationCompat.BigPictureStyle();
    bigStyle.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.snow_scene));
    builder.setStyle(bigStyle);/*from w  w  w  . j a  v  a 2s.  c o m*/

    Intent intent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class).addNextIntent(intent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, builder.build());

    notificationId++;
    Log.d(DEBUG_TAG, "ID: " + notificationId);
}

From source file:com.architjn.materialicons.ui.MainActivity.java

private void init() {
    toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);//w w  w  .  j a  v a  2  s .co m
    drawerLayout = (DrawerLayout) findViewById(R.id.main_drawerlayout);
    navigationView = (NavigationView) findViewById(R.id.main_navigationview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((CollapsingToolbarLayout) findViewById(R.id.collapsingtoolbarlayout_main))
            .setTitle(getResources().getString(R.string.theme_title));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(
                getResources().getString(R.string.theme_title),
                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher),
                getResources().getColor(R.color.primaryColor));
        setTaskDescription(taskDescription);
    }
    (findViewById(R.id.fab_main)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this, ApplyIconActivity.class));
        }
    });
    setNav();
    setCards();
}

From source file:com.attiqrao.systemsltd.list_to_do.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));

    // Get notification title from Reminder Database
    ReminderDatabase rb = new ReminderDatabase(context);
    Reminder reminder = rb.getReminder(mReceivedID);
    String mTitle = reminder.getTitle();

    // Create intent to open ReminderEditActivity on notification click
    Intent editIntent = new Intent(context, ReminderEditActivity.class);
    editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
    PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create Notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_icon))
            .setSmallIcon(R.mipmap.ic_icon).setContentTitle(context.getResources().getString(R.string.app_name))
            .setTicker(mTitle).setContentText(mTitle)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).setContentIntent(mClick)
            .setAutoCancel(true).setOnlyAlertOnce(true);

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nManager.notify(mReceivedID, mBuilder.build());
}

From source file:MainActivity.java

@Deprecated
public void showNotification(View view) {
    Intent activityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);

    Notification notification;/*from   w  ww  .ja va2 s  . c  om*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_previous), "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_pause), "Pause",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_next), "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    } else {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(R.mipmap.ic_launcher)
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_previous, "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_pause, "Pause",
                        pendingIntent).build())
                .addAction(
                        new Notification.Action.Builder(android.R.drawable.ic_media_next, "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    }
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java

@Override
protected void onHandleIntent(Intent intent) {
    // initialize

    // extract details
    Server server = intent.getParcelableExtra("server");
    String directory = intent.getStringExtra("directory");
    String filename = intent.getStringExtra("filename");

    // get the json parser from the application
    JsonParser jsonParser = new JsonParser();

    // start the ball rolling...
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setTicker(String.format(getString(R.string.notif_ticker), filename))
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large))
            .setSmallIcon(R.drawable.ic_stat_notif_small)
            .setContentTitle(String.format(getString(R.string.notif_title), filename))
            .setContentText(getString(R.string.notif_content_init))
            // to avoid NPE on android 2.x where content intent is required
            // set an empty content intent
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true);

    // notify user that upload is starting
    mgr.notify(NOTIFICATION_ID, builder.build());

    // reset ticker for any subsequent notifications
    builder.setTicker(null);//from w w w.  java 2s  .  c  om

    AbstractHttpClient client = CustomHTTPClient.getHttpClient();

    // enable digest authentication
    if (server.getUsername() != null && !server.getUsername().equals("")) {
        Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());

        client.getCredentialsProvider().setCredentials(
                new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials);
    }

    final File file = new File(directory, filename);
    final long length = file.length();

    try {
        CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                new CustomMultiPartEntity.ProgressListener() {
                    @Override
                    public void transferred(long num) {
                        // calculate percentage

                        //System.out.println("transferred: " + num);

                        int progress = (int) ((num * 100) / length);

                        builder.setContentText(String.format(getString(R.string.notif_content), progress));

                        mgr.notify(NOTIFICATION_ID, builder.build());
                    }
                });

        multipart.addPart(file.getName(), new FileBody(file));

        HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content");
        httpRequest.setEntity(multipart);

        HttpResponse serverResponse = client.execute(httpRequest);

        BasicResponseHandler handler = new BasicResponseHandler();
        JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject();

        if (!reply.has("outcome")) {
            throw new RuntimeException(getString(R.string.invalid_response));
        } else {
            // remove the 'upload in-progress' notification
            mgr.cancel(NOTIFICATION_ID);

            String outcome = reply.get("outcome").getAsString();

            if (outcome.equals("success")) {

                String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString();

                Intent resultIntent = new Intent(this, UploadCompletedActivity.class);
                // populate it
                resultIntent.putExtra("server", server);
                resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE);
                resultIntent.putExtra("filename", filename);
                resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                // the notification id for the 'completed upload' notification
                // each completed upload will have a different id
                int notifCompletedID = (int) System.currentTimeMillis();

                builder.setContentTitle(getString(R.string.notif_title_uploaded))
                        .setContentText(String.format(getString(R.string.notif_content_uploaded), filename))
                        .setContentIntent(
                                // we set the (2nd param request code to completedID)
                                // see http://tinyurl.com/kkcedju
                                PendingIntent.getActivity(this, notifCompletedID, resultIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                        .setAutoCancel(true).setOngoing(false);

                mgr.notify(notifCompletedID, builder.build());

            } else {
                JsonElement elem = reply.get("failure-description");

                if (elem.isJsonPrimitive()) {
                    throw new RuntimeException(elem.getAsString());
                } else if (elem.isJsonObject())
                    throw new RuntimeException(
                            elem.getAsJsonObject().get("domain-failure-description").getAsString());
            }
        }

    } catch (Exception e) {
        builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false);

        mgr.notify(NOTIFICATION_ID, builder.build());
    }
}

From source file:com.github.sgelb.booket.SearchResultActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_results);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    noResults = (TextView) findViewById(R.id.noResultsTextView);
    defaultThumbnail = BitmapFactory.decodeResource(getResources(), R.drawable.ic_default_cover);

    bookList = new ArrayList<>();
    resultList = (ListView) findViewById(R.id.searchResultsList);
    downloadProgressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
    datasource = new BooksDataSource(this);

    BookInfos bookInfos = new BookInfos();
    bookInfos.execute(createUrl());//w  ww. j av  a 2s.co  m
    adapter = new BookResultAdapter(bookList, this);
    resultList.setAdapter(adapter);

    // Save book in database
    resultList.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

            AlertDialog alert = new AlertDialog.Builder(SearchResultActivity.this).create();
            alert.setTitle(
                    Html.fromHtml(getString(R.string.dialog_save_book, bookList.get(position).getTitle())));
            alert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), new OnClickListener() {
                public void onClick(final DialogInterface dialog, final int which) {
                    saveBook(position);
                }
            });
            alert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new OnClickListener() {
                public void onClick(final DialogInterface dialog, final int which) {
                }
            });
            alert.show();

            return true;
        }
    });

    // Expand list row
    resultList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            adapter.toggleExpand(view, position);
        }
    });

}

From source file:com.appzoneltd.lastmile.customer.deprecated.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from  w w  w.  ja  va 2 s  .  c  o m
private static void generateNotification(Context context, String message) {
    NotificationCompat.Builder notification;
    String title = context.getString(R.string.app_name);
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notification = new NotificationCompat.Builder(context);
    notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    notification.setSmallIcon(R.mipmap.ic_launcher);
    notification.setContentTitle(title);
    notification.setContentText(message);
    Intent notificationIntent = new Intent(context, PushNotificationActivity.class);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setContentIntent(intent);
    notification.setAutoCancel(true);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationManager.notify(1, notification.build());
}

From source file:com.bannisha.yelian.customview.CirclePageIndicator.java

public void setCurrentImageId(int currentImageId) {
    this.currentImageId = currentImageId;
    currentImageBitmap = BitmapFactory.decodeResource(getResources(), currentImageId);
}

From source file:MainActivity.java

private void showNotification() {
    Intent activityIntent = new Intent(this, MainActivity.class);
    activityIntent.setAction(ACTION_STOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);
    final Builder notificationBuilder = new Builder(this).setContentTitle("Flashlight")
            .setContentText("Press to turn off the flashlight").setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setContentIntent(pendingIntent).setVibrate(new long[] { DEFAULT_VIBRATE })
            .setPriority(PRIORITY_MAX);/*from  w ww. ja v  a 2 s .com*/
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}