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.android.settings.beanstalk.service.AlarmService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {/*from www.  j a v  a2 s  .  c  om*/
        startAlarmSound();
    } catch (Exception e) {
        // Do nothing
    }

    Bundle extras = intent.getExtras();
    String names = extras.getString("number");
    String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title)
            .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true)
            .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message)));

    Intent alarmDialog = new Intent();
    alarmDialog.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    alarmDialog.setClass(this, com.android.settings.beanstalk.service.BypassAlarm.class);
    alarmDialog.putExtra("number", names);
    alarmDialog.putExtra("norun", true);

    PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(result);
    mManager.notify(NOTI_ID, builder.build());
    return START_STICKY;
}

From source file:com.bt.heliniumstudentapp.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    loginContext = this;

    getWindow().getDecorView().setBackgroundResource(R.color.indigo);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.indigo));
        setTaskDescription(new ActivityManager.TaskDescription(getString(R.string.app_name),
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),
                ContextCompat.getColor(this, R.color.indigo)));
    }/*from  w w  w . j  a v  a2 s. co m*/

    usernameET = (EditText) findViewById(R.id.et_username_la);
    passwordET = (EditText) findViewById(R.id.et_password_la);
    final Button loginBtn = (Button) findViewById(R.id.btn_login_la);

    usernameET.setText(PreferenceManager.getDefaultSharedPreferences(this).getString("username", ""));

    usernameET.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            loginBtn.setEnabled((usernameET.length() != 0 && passwordET.length() != 0));
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });

    passwordET.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            loginBtn.setEnabled((usernameET.length() != 0 && passwordET.length() != 0));
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });

    View.OnClickListener login = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            refresh();
        }
    };

    loginBtn.setOnClickListener(login);
}

From source file:cn.sqy.contacts.ui.ImageDownloader.java

public ImageDownloader(Context context) {
    tempBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.post_list_thumb_loading);
}

From source file:android.support.v17.leanback.supportleanbackshowcase.cards.CharacterCardView.java

public void updateUi(Card card) {
    TextView primaryText = (TextView) findViewById(R.id.primary_text);
    final ImageView imageView = (ImageView) findViewById(R.id.main_image);

    primaryText.setText(card.getTitle());
    if (card.getLocalImageResourceName() != null) {
        int resourceId = card.getLocalImageResourceId(getContext());
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resourceId);
        RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getContext().getResources(),
                bitmap);/*w  ww  .j a v  a 2s. c o  m*/
        drawable.setAntiAlias(true);
        drawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.android.systemui.ReminderReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    SharedPreferences shared = context.getSharedPreferences(KEY_REMINDER_ACTION, Context.MODE_PRIVATE);

    if (intent.getBooleanExtra("clear", false)) {
        manager.cancel(NOTI_ID);/*from www .j  a  v  a2  s.co  m*/
        // User has set a new reminder but didn't clear
        // This notification until now
        if (!shared.getBoolean("updated", false)) {
            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();
            shared.edit().putString("title", null).commit();
            shared.edit().putString("message", null).commit();
        }
    } else {
        String title = shared.getString("title", null);
        String message = shared.getString("message", null);
        if (title != null && message != null) {
            Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_qs_alarm_on);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setTicker(title)
                    .setContentTitle(title).setContentText(message).setAutoCancel(false).setOngoing(true)
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setSmallIcon(R.drawable.ic_qs_alarm_on)
                    .setLargeIcon(bm).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

            int alertMode = Settings.System.getIntForUser(context.getContentResolver(),
                    Settings.System.REMINDER_ALERT_NOTIFY, 0, UserHandle.USER_CURRENT);
            PendingIntent result = null;
            Intent serviceIntent = new Intent(context, ReminderService.class);
            if (alertMode != 0 && !QuietHoursHelper.inQuietHours(context, Settings.System.QUIET_HOURS_MUTE)) {
                context.startService(serviceIntent);
            }

            // Stop sound on click
            serviceIntent.putExtra("stopSelf", true);
            result = PendingIntent.getService(context, 1, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.setContentIntent(result);

            // Add button for dismissal
            serviceIntent.putExtra("dismissNoti", true);
            result = PendingIntent.getService(context, 0, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_sysbar_null,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_dismiss), result);

            // Add button for reminding later
            serviceIntent.putExtra("time", true);
            result = PendingIntent.getService(context, 2, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_qs_alarm_on,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_later), result);

            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();

            manager.notify(NOTI_ID, builder.build());
        }
    }
    shared.edit().putBoolean("updated", false).commit();
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param context//from ww w  . j  a  v  a2s .  co  m
 */
public CustomView(Context context) {
    super(context);
    blockImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.block); //carichiamo l'immagine in una bitmap

    mBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_132); //carichiamo l'immagine in una bitmap
    bw = mBmp.getWidth(); //larghezza bitmap
    bh = mBmp.getHeight();//altezza   
    mPaint = new Paint(); // pennello
    mPaint.setColor(Color.CYAN);
    mPaint.setAntiAlias(true);
    mRnd = new Random();

}

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

public static NotificationCompat.Builder buildNotificationExtenderAction(Context context) {

    Bitmap tableImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.table_restaurant);

    NotificationCompat.Builder builder = buildNotificationSimpleNBackground(context);
    builder.setSmallIcon(R.drawable.resto_icn);

    // Create a WearableExtender to add functionality for wearables
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
            .setHintHideIcon(false).setBackground(tableImg).addActions(getActionsSample(context));

    return (NotificationCompat.Builder) builder.extend(wearableExtender);
}

From source file:br.com.atarde.portal.MyFirebaseMessagingService.java

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Bitmap rawBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle("Portal A Tarde").setContentText(messageBody).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent).setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(rawBitmap);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

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

public void setImageId(int imageId) {
    this.imageId = imageId;
    imageBitmap = BitmapFactory.decodeResource(getResources(), imageId);
}

From source file:com.rastating.droidbeard.net.SickbeardAsyncTask.java

protected Bitmap getDefaultBanner() {
    return BitmapFactory.decodeResource(Application.getContext().getResources(), R.drawable.banner);
}