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.architjn.materialicons.ui.fragments.HomeFragment.java

private void init() {
    setHasOptionsMenu(true);// w w  w. j a  v  a 2 s. c o m
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar_main);
    setActionBar(toolbar);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    ((CollapsingToolbarLayout) mainView.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));
        getActivity().setTaskDescription(taskDescription);
    }
    (mainView.findViewById(R.id.fab_main)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((HomeActivity) getActivity()).switchFragment(new ApplyIconFragment(), true);
        }
    });
    getHomeActivity().setNav(toolbar);
    setCards();
}

From source file:com.android.mms.ui.ConversationListItem.java

public ConversationListItem(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (sDefaultContactImage == null) {
        Resources res = context.getResources();
        Bitmap defaultImage = BitmapFactory.decodeResource(res, R.drawable.ic_contact_picture);
        sDefaultContactImage = RoundedBitmapDrawableFactory.create(res, defaultImage);
        sDefaultContactImage.setAntiAlias(true);
        sDefaultContactImage//w  w  w  .  j av a  2s . c  o m
                .setCornerRadius(Math.max(defaultImage.getWidth() / 2, defaultImage.getHeight() / 2));
    }
}

From source file:com.appjma.appdeployer.AppsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.apps_fragment, container, false);

    mListView = (ListView) view.findViewById(android.R.id.list);
    mProgressBar = view.findViewById(android.R.id.progress);
    mEmptyView = view.findViewById(android.R.id.empty);
    mErrorReporter = new ErrorReporter(getActivity(), view, AppContract.Apps.CONTENT_URI);

    mListView.setOnItemClickListener(this);

    Bitmap placeHolder = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder);
    mRemoteImageLoader = RemoteImageLoader.createUsingDp(getActivity(), placeHolder, IMAGE_SIZE_DP,
            IMAGE_SIZE_DP);// www  .jav a2 s  .  c  om

    mAdapter = new AppsAdapter(getActivity(), mRemoteImageLoader, this);
    mListView.setAdapter(mAdapter);

    mDownloadHelper = new DownloadHelper(getActivity(), DownloadService.ACTION_SYNC, this,
            AppContract.Apps.CONTENT_URI);
    LoaderManager lm = getLoaderManager();
    lm.initLoader(LOADER_APPS, null, this);

    setHasOptionsMenu(true);

    return view;
}

From source file:de.dmxcontrol.device.EntityDevice.java

public static Bitmap getDefaultIcon(Context context) {

    File imgFile = new File(FileManager.ImageStorageName + File.separator + defaultDeviceIcon);
    if (imgFile.isFile()) {
        if (imgFile.exists()) {
            return BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        }/*from w w  w .j  ava 2  s.c  om*/
    }

    // Replace this icon with something else
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
}

From source file:com.appsaur.tarucassist.AlarmReceiver.java

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

    // Get notification title from Reminder Database
    ScheduleReminderDataSource scheduleReminderDataSource = new ScheduleReminderDataSource(context);
    StudentScheduleDataSource studentScheduleDataSource = new StudentScheduleDataSource(context);
    studentScheduleDataSource.open();//from w  ww .  ja  v  a  2s.  c  o m
    ScheduleReminder scheduleReminder = scheduleReminderDataSource.getScheduleReminder(mReceivedID);
    String mTitle = scheduleReminder.getTitle();
    int scheduleId = scheduleReminder.getScheduleId();
    mCalendar = Calendar.getInstance();

    String scheduleDate = studentScheduleDataSource.getCancelledScheduleById(scheduleId,
            BaseActivity.dateFormat.format(mCalendar.getTime()));

    if (!scheduleDate.equals(""))
        mTitle = mTitle + " - Cancelled";

    // Create intent to open ReminderEditActivity on notification click
    Intent editIntent = new Intent(context, ViewScheduleActivity.class);
    editIntent.putExtra(BaseActivity.KEY_SCHEDULE_ID, Integer.toString(scheduleId));
    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_launcher))
            .setSmallIcon(R.drawable.ic_timetable_white)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setTicker(mTitle)
            .setContentText(mTitle).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(mClick).setAutoCancel(true).setOnlyAlertOnce(true);

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

}

From source file:com.cfc.needblood.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///www  . j  a  v a 2 s .  c  o  m
private static void generateNotification(Context context, String message) {
    long when = System.currentTimeMillis();

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Change the icons to conform Android's design guildeline
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bd_icon))
            .setTicker(message).setWhen(when).setAutoCancel(true)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.notification_message));

    Notification notification = builder.build();

    notificationManager.notify(0, notification);

    // Notification sound, comment out if do not need
    Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, ringtone);
    r.play();
}

From source file:com.bayapps.android.robophish.ui.BaseActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LogHelper.d(TAG, "Activity onCreate");

    if (Build.VERSION.SDK_INT >= 21) {
        // Since our app icon has the same color as colorPrimary, our entry in the Recent Apps
        // list gets weird. We need to change either the icon or the color
        // of the TaskDescription.
        ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getTitle().toString(),
                BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white),
                ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
        setTaskDescription(taskDesc);//from   w  ww . j  a va  2 s  . c o  m
    }

    // Connect a media browser just to get the media session token. There are other ways
    // this can be done, for example by sharing the session token directly.
    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                //mInformationTextView.setText(getString(R.string.gcm_send_message));
            } else {
                //mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };

    // Registering BroadcastReceiver
    registerReceiver();

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
}

From source file:com.beepscore.android.sunshine.gcm.MyGcmListenerService.java

/**
 *  Put the message into a notification and post it on this Android device.
 *  This is just one simple example of what you might choose to do with a GCM message.
 *
 * @param message The alert message to be posted.
 *//* www .j  a va  2 s.c om*/
private void sendNotification(String message) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    // Notifications using both a large and a small icon (which yours should!) need the large
    // icon as a bitmap.
    // Create largeIcon from the resource ID
    Bitmap largeIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.art_storm);

    // Generally, you want to set the small icon to the app icon,
    // so that users understand what app is triggering this notification.

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.art_clear).setLargeIcon(largeIcon).setContentTitle("Weather Alert!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setPriority(NotificationCompat.PRIORITY_HIGH);
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.alucas.snorlax.module.feature.gym.EjectNotification.java

private Notification createNotification(final int pokemonNumber, final String pokemonName, final String gymName,
        final Double gymLatitude, final Double gymLongitude) {
    final Uri posURI = Uri.parse("geo:" + gymLatitude + "," + gymLongitude + "?q=" + gymLatitude + ","
            + gymLongitude + "(" + gymName + ")");
    final Intent posIntent = new Intent(Intent.ACTION_VIEW, posURI).setPackage("com.google.android.apps.maps");
    final PendingIntent posPendingIntent = PendingIntent.getActivity(mPokemonGoContext, 0, posIntent, 0);

    return new NotificationCompat.Builder(mSnorlaxContext)
            .setSmallIcon(/*from  w  ww .  ja va2  s .  c om*/
                    R.drawable.ic_eject)
            .setLargeIcon(Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(mResources,
                            Resource.getPokemonResourceId(mSnorlaxContext, mResources, pokemonNumber)),
                    Resource.getLargeIconWidth(mResources), Resource.getLargeIconHeight(mResources), false))
            .setContentTitle(mSnorlaxContext.getString(R.string.notification_gym_eject_title, pokemonName))
            .setContentText(mSnorlaxContext.getString(R.string.notification_gym_eject_content, gymName))
            .setColor(ContextCompat.getColor(mSnorlaxContext, R.color.red_700)).setAutoCancel(true)
            .setContentIntent(posPendingIntent).setVibrate(new long[] { 0, 1000 })
            .setPriority(Notification.PRIORITY_MAX).setCategory(NotificationCompat.CATEGORY_ALARM).build();
}

From source file:net.olejon.mdapp.MessageIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    final Context mContext = this;

    final MyTools mTools = new MyTools(mContext);

    RequestQueue requestQueue = Volley.newRequestQueue(mContext);

    int projectVersionCode = mTools.getProjectVersionCode();

    String device = mTools.getDevice();

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website_uri) + "api/1/message/?version_code=" + projectVersionCode
                    + "&device=" + device,
            new Response.Listener<JSONObject>() {
                @SuppressLint("InlinedApi")
                @Override// ww w.  ja  v  a  2s.  c  om
                public void onResponse(JSONObject response) {
                    try {
                        final long id = response.getLong("id");
                        final String title = response.getString("title");
                        final String message = response.getString("message");
                        final String bigMessage = response.getString("big_message");
                        final String button = response.getString("button");
                        final String uri = response.getString("uri");

                        final long lastId = mTools.getSharedPreferencesLong("MESSAGE_LAST_ID");

                        mTools.setSharedPreferencesLong("MESSAGE_LAST_ID", id);

                        if (lastId != 0 && id != lastId) {
                            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                                    R.drawable.ic_launcher);

                            NotificationManagerCompat notificationManager = NotificationManagerCompat
                                    .from(mContext);
                            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
                                    mContext);

                            notificationBuilder.setWhen(mTools.getCurrentTime()).setAutoCancel(true)
                                    .setPriority(Notification.PRIORITY_HIGH)
                                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                                    .setCategory(Notification.CATEGORY_MESSAGE).setLargeIcon(bitmap)
                                    .setSmallIcon(R.drawable.ic_local_hospital_white_24dp)
                                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                                    .setLights(Color.BLUE, 1000, 2000).setTicker(message).setContentTitle(title)
                                    .setContentText(message)
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMessage));

                            if (!uri.equals("")) {
                                Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                                PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0,
                                        launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                                notificationBuilder.setContentIntent(launchPendingIntent).addAction(
                                        R.drawable.ic_local_hospital_white_24dp, button, launchPendingIntent);
                            }

                            notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
                        }
                    } catch (Exception e) {
                        Log.e("MessageIntentService", Log.getStackTraceString(e));
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("MessageIntentService", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);
}