List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.irccloud.android.activity.PastebinEditorActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC));//from w ww . jav a 2 s.c om cloud.recycle(); } setContentView(R.layout.activity_pastebineditor); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { if (!getWindow().isFloating()) { getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } paste = (EditText) findViewById(R.id.paste); filename = (EditText) findViewById(R.id.filename); message = (EditText) findViewById(R.id.message); messages_count = (TextView) findViewById(R.id.messages_count); if (savedInstanceState != null && savedInstanceState.containsKey("message")) message.setText(savedInstanceState.getString("message")); if (savedInstanceState != null && savedInstanceState.containsKey("paste_id")) pasteID = savedInstanceState.getString("paste_id"); else if (getIntent() != null && getIntent().hasExtra("paste_id")) pasteID = getIntent().getStringExtra("paste_id"); if (savedInstanceState != null && savedInstanceState.containsKey("paste_contents")) pastecontents = savedInstanceState.getString("paste_contents"); else if (getIntent() != null && getIntent().hasExtra("paste_contents")) pastecontents = getIntent().getStringExtra("paste_contents"); paste.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { int count = 0; String lines[] = editable.toString().split("\n"); for (String line : lines) { count += Math.ceil(line.length() / 1080.0f); } messages_count.setText("Text will be sent as " + count + " message" + (count == 1 ? "" : "s")); } }); paste.setText(pastecontents); if (savedInstanceState != null && savedInstanceState.containsKey("filename")) filename.setText(savedInstanceState.getString("filename")); else if (getIntent() != null && getIntent().hasExtra("filename")) filename.setText(getIntent().getStringExtra("filename")); tabHost = (TabLayout) findViewById(android.R.id.tabhost); ViewCompat.setElevation(toolbar, ViewCompat.getElevation(tabHost)); if (pasteID != null) { tabHost.setVisibility(View.GONE); message.setVisibility(View.GONE); findViewById(R.id.message_heading).setVisibility(View.GONE); } else { tabHost.setTabGravity(TabLayout.GRAVITY_FILL); tabHost.setTabMode(TabLayout.MODE_FIXED); tabHost.addTab(tabHost.newTab().setText("Pastebin")); tabHost.addTab(tabHost.newTab().setText("Messages")); tabHost.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { current_tab = tab.getPosition(); if (current_tab == 0) { filename.setVisibility(View.VISIBLE); message.setVisibility(View.VISIBLE); messages_count.setVisibility(View.GONE); findViewById(R.id.filename_heading).setVisibility(View.VISIBLE); findViewById(R.id.message_heading).setVisibility(View.VISIBLE); } else { filename.setVisibility(View.GONE); message.setVisibility(View.GONE); messages_count.setVisibility(View.VISIBLE); findViewById(R.id.filename_heading).setVisibility(View.GONE); findViewById(R.id.message_heading).setVisibility(View.GONE); } } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); if (savedInstanceState != null && savedInstanceState.containsKey("tab")) tabHost.getTabAt(savedInstanceState.getInt("tab")).select(); } NetworkConnection.getInstance().addHandler(this); if (pasteID != null && (pastecontents == null || pastecontents.length() == 0)) { new FetchPastebinTask().execute((Void) null); } if (pasteID != null) { setTitle(R.string.title_activity_pastebin_editor_edit); toolbar.setBackgroundResource(R.drawable.actionbar); } else { setTitle(R.string.title_activity_pastebin_editor); } supportInvalidateOptionsMenu(); result(RESULT_CANCELED); }
From source file:br.com.GUI.avaliacoes.AcompanhamentoAvaliacao.java
public void preencherInterface(final ArrayList<Avaliacoes> busca) { ArrayList<RowItemAvaliacao> data = new ArrayList<RowItemAvaliacao>(); Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.prancheta); for (Avaliacoes a : busca) { RowItemAvaliacao item = new RowItemAvaliacao(bmp, a.getUsuarioAluno(), a.getDataAvaliacao(), a.getHoraAvaliacao(), a.getResultado()); data.add(item);//from w ww. ja v a2s. c o m } CustomAdapterAvaliacoes adapter = new CustomAdapterAvaliacoes(getActivity(), data); lstListaAvaliacoesRealizadas.setAdapter(adapter); lstListaAvaliacoesRealizadas.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent i = new Intent(getActivity(), VisualizarAvaliacao.class); i.putExtra("codAvaliacao", busca.get(arg2).getCodAvaliacao()); startActivity(i); } }); }
From source file:com.yi4all.rupics.ImageDetailActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_detail_pager); util = new DownloadUtil(); default_image = BitmapFactory.decodeResource(getResources(), R.drawable.download_32); no_image = BitmapFactory.decodeResource(getResources(), R.drawable.no_image); // Fetch screen height and width, to use as our max size when loading // images as this // activity runs full screen final DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int height = displayMetrics.heightPixels; final int width = displayMetrics.widthPixels; // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { SCREEN_WIDTH = width;/* w w w . java 2 s.c o m*/ SCREEN_HEIGHT = height; issue = (IssueModel) getIntent().getSerializableExtra("issue"); // Set up activity to go full screen getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); initBtn(); refreshData(); }
From source file:com.appdevper.mediaplayer.activity.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);/* www . j av a2 s. c o m*/ } // mMediaBrowser = new MediaBrowserCompat(this, // new ComponentName(this, MusicService.class), mConnectionCallback, null); Intent intent = new Intent(this, MusicService.class); bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); }
From source file:com.secretlisa.lib.utils.BaseImageLoader.java
private void forceDownload(String url, ImageView imageView) { if (url == null) { imageView.setImageDrawable(null); return;/*from w w w . j a va 2s. c o m*/ } if (cancelPotentialDownload(url, imageView)) { BitmapDownloaderTask task = null; task = new BitmapDownloaderTask(imageView, url); Object obj = imageView.getTag(); int resId = -1; Bitmap bitmapDefault = null; if (obj != null) { resId = (Integer) obj; bitmapDefault = BitmapFactory.decodeResource(imageView.getResources(), resId); } DownloadedDrawable downloadedDrawable = new DownloadedDrawable(bitmapDefault, task); imageView.setImageDrawable(downloadedDrawable); // imageView.setBackgroundColor(Color.WHITE); // imageView.setBackgroundResource(R.drawable.wallpaper_bg); imageView.setMinimumHeight(156); task.execute(); } }
From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "Received start id " + startId + ": " + intent); if (intent != null) { config = (Config) intent.getParcelableExtra("config"); activity = intent.getStringExtra("activity"); Log.d(TAG, "Got activity" + activity); // Build a Notification required for running service in foreground. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(config.getNotificationTitle()); builder.setContentText(config.getNotificationText()); builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); if (config.getNotificationIcon() != null) { builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon())); builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(), getPluginResource(config.getLargeNotificationIcon()))); }//from w ww . j a va2 s. com if (config.getNotificationIconColor() != null) { builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor())); } setClickEvent(builder); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } Log.i(TAG, config.toString()); Log.i(TAG, "- activity: " + activity); //We want this service to continue running until it is explicitly stopped return START_STICKY; }
From source file:com.versul.newbornswatcher.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// ww w . j a va 2s.c om */ private void sendNotification(String message) { 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); Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.eye); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_large)) .setContentTitle("Newborns Watcher").setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.alobha.challenger.business.gmc.NotificationGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param challenge GCM challenge received. *///ww w. j ava 2 s . c o m private void sendNotification(Challenge challenge) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("challenge_id", challenge.id); intent.setAction("ShowNotification"); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.inner_logo); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.inner_logo).setLargeIcon(largeIcon) .setContentTitle(getString(R.string.app_name)) .setContentText("You were challenged by " + challenge.owner.first_name).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.alchemiasoft.book.service.SuggestionService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG_LOG, "Starting a new book suggestion..."); final ContentResolver cr = getContentResolver(); final Cursor c = cr.query(BookDB.Book.CONTENT_URI, null, SELECTION, SELECT_NOT_OWNED, null); Book book = null;/*from w ww . j a va 2s. co m*/ try { if (c.moveToNext()) { book = Book.oneFrom(c); } } finally { c.close(); } // Showing a notification if a not owned book is found if (book != null) { Log.d(TAG_LOG, "Found book that can be suggested: " + book); final String content = getString(R.string.content_book_suggestion, book.getTitle(), book.getAuthor()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.title_book_suggestion)).setContentText(content); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(content)); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); // ONLY 4 WEARABLE(s) final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // SECOND PAGE WITH BOOK DESCRIPTION wearableExtender .addPage(new NotificationCompat.Builder(this).setContentTitle(getString(R.string.description)) .setStyle(new NotificationCompat.BigTextStyle().bigText(book.getDescrition())).build()); wearableExtender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background)); // ACTION TO PURCHASE A BOOK FROM A WEARABLE final PendingIntent purchaseIntent = PendingIntent.getService(this, 0, BookActionService.IntentBuilder .buy(this, book).notificationId(ID_SUGGESTION).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_buy, getString(R.string.action_buy), purchaseIntent).build()); // ACTION TO ADD NOTES VIA VOICE REPLY final RemoteInput input = BookActionService.RemoteInputBuilder.create(this) .options(R.array.note_options).build(); final PendingIntent notesIntent = PendingIntent .getService( this, 0, BookActionService.IntentBuilder.addNote(this, book) .notificationId(ID_SUGGESTION).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_notes, getString(R.string.action_notes), notesIntent).addRemoteInput(input).build()); // Finally extending the notification builder.extend(wearableExtender); // Sending the notification NotificationManagerCompat.from(this).notify(ID_SUGGESTION, builder.build()); } // Completing the Wakeful Intent SuggestionReceiver.completeWakefulIntent(intent); }
From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java
private void sendNotification(String messageTitle, String messageBody) { Intent intent = MainActivity.makeIntent(this); intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(messageTitle); bigTextStyle.bigText(messageBody);/*from w w w.j a va2s . c o m*/ Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle) .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true) .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200) .setPriority(Notification.PRIORITY_MAX); //for vibration Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); long time = new Date().getTime(); String tmpStr = String.valueOf(time); String last4Str = tmpStr.substring(tmpStr.length() - 5); int notificationId = Integer.valueOf(last4Str); notificationManager.notify(notificationId, notificationBuilder.build()); }