List of usage examples for android.graphics BitmapFactory decodeResource
public static Bitmap decodeResource(Resources res, int id)
From source file:com.marianhello.bgloc.LocationService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { log.info("Received start startId: {} intent: {}", startId, intent); if (provider != null) { provider.onDestroy();// www .j a v a2 s.com } if (intent == null) { //service has been probably restarted so we need to load config from db ConfigurationDAO dao = DAOFactory.createConfigurationDAO(this); try { config = dao.retrieveConfiguration(); } catch (JSONException e) { log.error("Config exception: {}", e.getMessage()); config = new Config(); //using default config } } else { if (intent.hasExtra("config")) { config = intent.getParcelableExtra("config"); } else { config = new Config(); //using default config } } log.debug("Will start service with: {}", config.toString()); LocationProviderFactory spf = new LocationProviderFactory(this); provider = spf.getInstance(config.getLocationProvider()); if (config.getStartForeground()) { // Build a Notification required for running service in foreground. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(config.getNotificationTitle()); builder.setContentText(config.getNotificationText()); if (config.getSmallNotificationIcon() != null) { builder.setSmallIcon(getDrawableResource(config.getSmallNotificationIcon())); } else { builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); } if (config.getLargeNotificationIcon() != null) { builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(), getDrawableResource(config.getLargeNotificationIcon()))); } if (config.getNotificationIconColor() != null) { builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor())); } // Add an onclick handler to the notification Context context = getApplicationContext(); String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(contentIntent); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } provider.startRecording(); //We want this service to continue running until it is explicitly stopped return START_STICKY; }
From source file:fm.krui.kruifm.TrackUpdateHandler.java
/** * Downloads album art from passed URL using the last.fm api. * @param url Web safe location of image as URL. * @return Bitmap of the image requested *//*www .j a v a 2 s .co m*/ protected Bitmap downloadAlbumArt(String url) { Bitmap bitmap; // Check if an album art URL was returned. If there's no location, there's no point in wasting resources trying to download nothing. if (artUrl.equals("*NO_ART*") == false) { // Download the image from URL try { HttpURLConnection connection; connection = (HttpURLConnection) new URL(url).openConnection(); connection.connect(); InputStream input = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(input); return bitmap; } catch (MalformedURLException e) { Log.e(TAG, "Malformed URL detected when downloading album art: "); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "Failed to process album art: "); e.printStackTrace(); } } // If the download fails or image doesn't exist, display the default KRUI background image. bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.krui_background_logo); return bitmap; }
From source file:com.chintans.venturebox.util.Utils.java
public static void showNotification(Context context, PackageInfo[] infosRom, PackageInfo[] infosGapps) { Resources resources = context.getResources(); if (infosRom != null) { sPackageInfosRom = infosRom;// ww w. ja va 2 s . c o m } else { infosRom = sPackageInfosRom; } if (infosGapps != null) { sPackageInfosGapps = infosGapps; } else { infosGapps = sPackageInfosGapps; } Intent intent = new Intent(context, MainActivity.class); NotificationInfo fileInfo = new NotificationInfo(); fileInfo.mNotificationId = Updater.NOTIFICATION_ID; fileInfo.mPackageInfosRom = infosRom; fileInfo.mPackageInfosGapps = infosGapps; intent.putExtra(FILES_INFO, fileInfo); PendingIntent pIntent = PendingIntent.getActivity(context, Updater.NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(resources.getString(R.string.new_system_update)) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.ic_launcher)) .setContentIntent(pIntent); String contextText = ""; if (infosRom.length + infosGapps.length == 1) { String filename = infosRom.length == 1 ? infosRom[0].getFilename() : infosGapps[0].getFilename(); contextText = resources.getString(R.string.new_package_name, new Object[] { filename }); } else { contextText = resources.getString(R.string.new_packages, new Object[] { infosRom.length + infosGapps.length }); } builder.setContentText(contextText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(context.getResources().getString(R.string.new_system_update)); if (infosRom.length + infosGapps.length > 1) { inboxStyle.addLine(contextText); } for (int i = 0; i < infosRom.length; i++) { inboxStyle.addLine(infosRom[i].getFilename()); } for (int i = 0; i < infosGapps.length; i++) { inboxStyle.addLine(infosGapps[i].getFilename()); } inboxStyle.setSummaryText(resources.getString(R.string.app_name)); builder.setStyle(inboxStyle); Notification notif = builder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Service.NOTIFICATION_SERVICE); notif.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(Updater.NOTIFICATION_ID, notif); }
From source file:com.vendsy.bartsy.venue.BartsyApplication.java
private void generateNotification(final String title, final String body, final int count) { mHandler.post(new Runnable() { public void run() { // Get app icon bitmap and scale to fit in notification Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); largeIcon = Bitmap.createScaledBitmap(largeIcon, NOTIFICATION_IMAGE_SIZE, NOTIFICATION_IMAGE_SIZE, true);/* w w w.ja va 2 s. c o m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setContentText(body); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setNumber(count); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Play default notification sound mBuilder.setDefaults(Notification.DEFAULT_SOUND); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } }); }
From source file:com.cm.android.beercellar.ui.ImageGridFragment.java
private void insertSeedData() { new android.os.AsyncTask<Object, Void, Void>() { @Override//from w w w . ja v a2s. c om protected Void doInBackground(Object... params) { String seedDataSet = getActivity() .getSharedPreferences(Utils.SHARED_PREF_NAME, Context.MODE_PRIVATE) .getString("SEED_DATA_SET", "N"); if (seedDataSet.equals("N")) { FileOutputStream out1 = null; FileOutputStream out2 = null; Bitmap bm1 = null; Bitmap bm2 = null; NotesDbAdapter dbHelper = null; long rowId = Math.abs(new Random(System.currentTimeMillis()).nextLong()); try { String imageAbsolutePath = Utils.getExternalImageStorageDir(getActivity()) .getAbsolutePath(); String thumbnailAbsolutePath = Utils.getExternalThumbnailStorageDir(getActivity()) .getAbsolutePath(); bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.beer_label_icon); File imageFile = new File(imageAbsolutePath, rowId + Utils.PICTURES_EXTENSION); out1 = new FileOutputStream(imageFile); bm1.compress(Bitmap.CompressFormat.PNG, 100, out1); bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.beer_label_icon); File thumbnailFile = new File(thumbnailAbsolutePath, rowId + Utils.PICTURES_EXTENSION); out2 = new FileOutputStream(thumbnailFile); bm2.compress(Bitmap.CompressFormat.PNG, 100, out2); Note note = new Note(); note.id = rowId; note.beer = "Belgian Style Pale Ale"; note.rating = "4.0"; note.textExtract = "Chimay Blanche, Chimay Brewery, Chimay, Belgium"; note.notes = "Trappist beer"; //default to Y note.share = "Y"; note.picture = rowId + Utils.PICTURES_EXTENSION; dbHelper = new NotesDbAdapter(getActivity()); dbHelper.open(); dbHelper.createNote(note); //finally getActivity().getSharedPreferences(Utils.SHARED_PREF_NAME, Context.MODE_PRIVATE).edit() .putString("SEED_DATA_SET", "Y").commit(); } catch (Exception e) { //do nothing } finally { try { out1.flush(); out1.close(); bm1.recycle(); out2.flush(); out2.close(); bm2.recycle(); if (dbHelper != null) dbHelper.close(); } catch (Exception e) {//do nothing} } } } return null; } @Override protected void onPostExecute(Void aVoid) { mAdapter.notifyDataSetChanged(); } }.execute(); }
From source file:dev.memento.MementoBrowser.java
/** Called when the activity is first created. */ @Override/* w ww . j av a 2s .c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); mUserAgent = getApplicationContext().getText(R.string.user_agent).toString(); // Set the date and time format SimpleDateTime.mDateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); SimpleDateTime.mTimeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext()); mDateChosenButton = (Button) findViewById(R.id.dateChosen); mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed); // Launch the DatePicker dialog box mDateChosenButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_DATE); } }); // Set the current date mToday = new SimpleDateTime(); // Handle change in orientation gracefully if (savedInstanceState == null) { mCurrentUrl = getApplicationContext().getText(R.string.homepage).toString(); mOriginalUrl = mCurrentUrl; setChosenDate(mToday); setDisplayedDate(mToday); mMementos = new MementoList(); } else { mCurrentUrl = savedInstanceState.getString("mCurrentUrl"); mDateChosen = (SimpleDateTime) savedInstanceState.getSerializable("mDateChosen"); mDateDisplayed = (SimpleDateTime) savedInstanceState.getSerializable("mDateDisplayed"); setChosenDate(mDateChosen); setDisplayedDate(mDateDisplayed); } mTimegateUris = getResources().getStringArray(R.array.listTimegates); // Add some favicons of web archives used by proxy server mFavicons = new HashMap<String, Bitmap>(); mFavicons.put("ia", BitmapFactory.decodeResource(getResources(), R.drawable.ia_favicon)); mFavicons.put("webcite", BitmapFactory.decodeResource(getResources(), R.drawable.webcite_favicon)); mFavicons.put("national-archives", BitmapFactory.decodeResource(getResources(), R.drawable.national_archives_favicon)); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mProgressBar.setVisibility(View.GONE); mLocation = (TextView) findViewById(R.id.locationEditText); mLocation.setSelectAllOnFocus(true); mLocation.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // Replace title with URL when focus is lost if (hasFocus) mLocation.setText(mCurrentUrl); else if (mPageTitle.length() > 0) mLocation.setText(mPageTitle); } }); mLocation.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //Log.d(LOG_TAG, "keyCode = " + keyCode + " event = " + event.getAction()); // Go to URL if user presses Go button if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { mOriginalUrl = fixUrl(mLocation.getText().toString()); // Access live version if date is today or in the future if (mToday.compareTo(mDateChosen) <= 0) { Log.d(LOG_TAG, "Browsing to " + mOriginalUrl); mWebview.loadUrl(mOriginalUrl); // Clear since we are visiting a different page in the present mMementos.clear(); } else makeMementoRequests(); // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return true; } return false; } }); // TEST /* Context context = getBaseContext(); Drawable image = getImage(context, "http://web.archive.org/favicon.ico"); if (image == null) { System.out.println("image is null !!"); } else { //image.setBounds(5, 5, 5, 5); //ImageView imgView = new ImageView(context); //ImageView imgView = (ImageView)findViewById(R.id.imagetest); //imgView.setImageDrawable(image); mLocation.setCompoundDrawablesWithIntrinsicBounds(image, null, null, null); } */ mNextButton = (Button) findViewById(R.id.next); mNextButton.setEnabled(false); mNextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to next Memento // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) { Log.d(LOG_TAG, "Could not find next Memento after date " + mDateDisplayed); return; } else mMementos.setCurrentIndex(index); } // Locate the next Memento in the list Memento nextMemento = mMementos.getNext(); if (nextMemento == null) { Log.d(LOG_TAG, "Still could not find next Memento!"); Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); } else { SimpleDateTime date = nextMemento.getDateTime(); setChosenDate(nextMemento.getDateTime()); showToast("Time travelling to next Memento on " + mDateChosen.dateFormatted()); mDateDisplayed = date; String redirectUrl = nextMemento.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); // Just in case it wasn't already enabled mPreviousButton.setEnabled(true); // If this is the last memento, disable button if (mMementos.isLast(date)) mNextButton.setEnabled(false); } } }); mPreviousButton = (Button) findViewById(R.id.previous); mPreviousButton.setEnabled(false); mPreviousButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to previous Memento // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndex(mDateDisplayed); if (index < 0) { Log.d(LOG_TAG, "Could not find previous Memento before date " + mDateDisplayed); return; } else mMementos.setCurrentIndex(index); } // Locate the prev Memento in the list Memento prevMemento = mMementos.getPrevious(); if (prevMemento == null) { Log.d(LOG_TAG, "Still could not find previous Memento!"); Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); } else { SimpleDateTime date = prevMemento.getDateTime(); setChosenDate(date); showToast("Time travelling to previous Memento on " + mDateChosen.dateFormatted()); mDateDisplayed = date; String redirectUrl = prevMemento.getUrl(); Log.d(LOG_TAG, "Sending browser to " + redirectUrl); mWebview.loadUrl(redirectUrl); // Just in case it wasn't already enabled mNextButton.setEnabled(true); // If this is the first memento, disable button if (mMementos.isFirst(date)) mPreviousButton.setEnabled(false); } } }); mWebview = (WebView) findViewById(R.id.webview); mWebview.setWebViewClient(new MementoWebViewClient()); mWebview.setWebChromeClient(new MementoWebChromClient()); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.loadUrl(mCurrentUrl); mWebview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Set focus here so focus is removed from the location text field // which will change the URL into the page's title. // There really should be a better way to do this, but it's a general // problem that other developers have ran into as well: // http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782?pli=1 if (mLocation.hasFocus()) { mWebview.requestFocus(); return true; } // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return false; } }); //testMementos(); }
From source file:com.bt.heliniumstudentapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainContext = this; HeliniumStudentApp.setLocale(this); if (!isOnline() && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { //TODO Keep app running and display empty ScheduleFragment with retry option Toast.makeText(this, getResources().getString(R.string.error_conn_no) + ". " + getResources().getString(R.string.database_no) + ".", Toast.LENGTH_LONG).show(); finish();//from w w w . j ava 2 s .c om } else if ((PreferenceManager.getDefaultSharedPreferences(this).getString("username", null) == null || PreferenceManager.getDefaultSharedPreferences(this).getString("password", null) == null) && PreferenceManager.getDefaultSharedPreferences(this).getString("schedule_0", null) == null) { startActivity(new Intent(this, LoginActivity.class)); finish(); } else { setContentView(R.layout.activity_main); toolbarTB = (Toolbar) findViewById(R.id.tb_toolbar_am); drawerDL = (DrawerLayout) findViewById(R.id.dl_drawer_am); drawerNV = (NavigationView) findViewById(R.id.nv_drawer_am); containerFL = findViewById(R.id.fl_container_am); containerLL = findViewById(R.id.ll_container_am); statusLL = findViewById(R.id.ll_status_am); weekTV = (TextView) findViewById(R.id.tv_week_am); yearTV = (TextView) findViewById(R.id.tv_year_am); prevIV = (ImageView) findViewById(R.id.iv_prev_am); historyIV = (ImageView) findViewById(R.id.iv_select_am); nextIV = (ImageView) findViewById(R.id.iv_next_am); setColors( Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_theme", "0")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_primary", "4")), Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this) .getString("pref_customization_color_accent", "14"))); setSupportActionBar(toolbarTB); toolbarTB.setBackgroundColor(ContextCompat.getColor(this, primaryColor)); drawerDLtoggle = new ActionBarDrawerToggle(this, drawerDL, toolbarTB, 0, 0); drawerDLtoggle.setDrawerIndicatorEnabled(false); Drawable navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_menu); navigationIcon.setColorFilter(ContextCompat.getColor(this, primaryTextColor), PorterDuff.Mode.SRC_ATOP); drawerDLtoggle.setHomeAsUpIndicator(navigationIcon); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); ((ProgressBar) findViewById(R.id.pb_progressbar_am)).getIndeterminateDrawable().setColorFilter( ContextCompat.getColor(this, accentPrimaryColor), android.graphics.PorterDuff.Mode.MULTIPLY); weekTV.setTextColor(ContextCompat.getColor(this, primaryTextColor)); yearTV.setTextColor(ContextCompat.getColor(this, secondaryTextColor)); prevIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); historyIV.setColorFilter(ContextCompat.getColor(this, accentTextColor)); nextIV.setColorFilter(ContextCompat.getColor(this, primaryTextColor)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (themeColor == R.color.theme_dark) getWindow().setStatusBarColor(ContextCompat.getColor(this, themeColor)); else getWindow().setStatusBarColor(ContextCompat.getColor(this, themeDisabledTextColor)); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), ContextCompat.getColor(this, themeColor))); ((GradientDrawable) ((RippleDrawable) prevIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); //FIXME Improve this ridiculous workaround ((GradientDrawable) ((RippleDrawable) historyIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) ((RippleDrawable) nextIV.getBackground()).getDrawable(0)) .setColor(ContextCompat.getColor(this, primaryColor)); } else { ((GradientDrawable) prevIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); ((GradientDrawable) historyIV.getBackground()) .setColor(ContextCompat.getColor(this, accentPrimaryColor)); ((GradientDrawable) nextIV.getBackground()).setColor(ContextCompat.getColor(this, primaryColor)); } final ColorStateList drawerItemColorStateList = new ColorStateList( new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }, new int[] { ContextCompat.getColor(this, accentSecondaryColor), ContextCompat.getColor(this, themeSecondaryTextColor) }); FM = getSupportFragmentManager(); FM.beginTransaction().replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); drawerDL.setBackgroundResource(themeColor); drawerNV.setBackgroundResource(themeColor); containerLL.setBackgroundResource(primaryColor); drawerNV.setItemIconTintList(drawerItemColorStateList); drawerNV.setItemTextColor(drawerItemColorStateList); drawerNV.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) { drawerDL.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { switch (menuItem.getItemId()) { case R.id.i_schedule_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("SCHEDULE")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE") .commit(); } break; case R.id.i_grades_md: menuItem.setChecked(true); if (!FM.findFragmentById(R.id.fl_container_am).getTag().equals("GRADES")) { weekTV.setText(""); yearTV.setText(""); prevIV.setOnClickListener(null); historyIV.setOnClickListener(null); nextIV.setOnClickListener(null); FM.beginTransaction() .replace(R.id.fl_container_am, new GradesFragment(), "GRADES").commit(); } break; case R.id.i_settings_md: startActivity(new Intent(mainContext, SettingsActivity.class)); break; case R.id.i_logout_md: if (isOnline()) { final AlertDialog.Builder logoutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); logoutDialogBuilder.setTitle(R.string.logout); logoutDialogBuilder.setMessage(R.string.logout_confirm); logoutDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ScheduleFragment.scheduleJson = null; GradesFragment.gradesHtml = null; PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("username", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("password", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_general_class", "0").apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_0", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("schedule_start_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_schedule_version_1", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("html_grades", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext) .edit().putString("pref_grades_version", null).apply(); new Handler().postDelayed(new Runnable() { @Override public void run() { finish(); startActivity( new Intent(mainContext, MainActivity.class)); } }, HeliniumStudentApp.DELAY_RESTART); } }); logoutDialogBuilder.setNegativeButton(android.R.string.no, null); final AlertDialog logoutDialog = logoutDialogBuilder.create(); logoutDialog.setCanceledOnTouchOutside(true); logoutDialog.show(); logoutDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); logoutDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor( ContextCompat.getColor(mainContext, accentSecondaryColor)); } else { Toast.makeText(mainContext, R.string.error_conn_no, Toast.LENGTH_SHORT).show(); } break; case R.id.i_about_md: final AlertDialog.Builder aboutDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, themeDialog)); aboutDialogBuilder.setTitle(R.string.about); aboutDialogBuilder.setMessage(getResources().getString(R.string.app_name) + "\n\nCopyright (C) 2016 Bastiaan Teeuwen <bastiaan.teeuwen170@gmail.com>\n\n" + "This program is free software; you can redistribute it and/or " + "modify it under the terms of the GNU General Public License " + "as published by the Free Software Foundation; version 2 " + "of the License, or (at your option) any later version.\n\n" + "This program is distributed in the hope that it will be useful, " + "but WITHOUT ANY WARRANTY; without even the implied warranty of " + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " + "GNU General Public License for more details.\n\n" + "You should have received a copy of the GNU General Public License " + "along with this program; if not, write to the Free Software " + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."); aboutDialogBuilder.setNeutralButton(R.string.website, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_WEBSITE))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setPositiveButton(R.string.github, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(HeliniumStudentApp.URL_GITHUB))); } catch (ActivityNotFoundException e) { Toast.makeText(mainContext, "Couldn't find a browser", Toast.LENGTH_SHORT).show(); } } }); aboutDialogBuilder.setNegativeButton(android.R.string.cancel, null); final AlertDialog aboutDialog = aboutDialogBuilder.create(); aboutDialog.setCanceledOnTouchOutside(true); aboutDialog.show(); ((TextView) aboutDialog.findViewById(android.R.id.message)).setTextSize(12); aboutDialog.getButton(AlertDialog.BUTTON_NEUTRAL) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); aboutDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mainContext, accentSecondaryColor)); break; } } }, HeliniumStudentApp.DELAY_DRAWER); return true; } }); } }
From source file:com.cnlms.wear.NotificationHelper.java
public static void raiseNotificationStackWithSummary(final Context context) { raiseNotification(context,//ww w . j a v a 2s . c o m defaultBuilder(context) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_notification_clear_all)) .setStyle(new NotificationCompat.InboxStyle().addLine("Can Elmas Did you...") .addLine("Chris Cornell Did you...").setBigContentTitle("2 New Messages") .setSummaryText("Summary")) .setGroup(GROUP_KEY).setGroupSummary(true)); }
From source file:com.by_syk.lib.nanoiconpack.dialog.IconDialog.java
private void returnPickIcon() { Bitmap bitmap = null;/*from ww w . j a v a 2s . c om*/ try { bitmap = BitmapFactory.decodeResource(getResources(), iconBean.getId()); } catch (Exception e) { e.printStackTrace(); } Intent intent = new Intent(); if (bitmap != null) { intent.putExtra("icon", bitmap); intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", iconBean.getId()); intent.setData(Uri.parse("android.resource://" + getContext().getPackageName() + "/" + String.valueOf(iconBean.getId()))); getActivity().setResult(Activity.RESULT_OK, intent); } else { getActivity().setResult(Activity.RESULT_CANCELED, intent); } getActivity().finish(); }
From source file:com.samknows.measurement.activity.SamKnowsMapActivity.java
public void addMarkers() { GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); try {/*from w w w . j a v a2s. c o m*/ JSONObject jsonObject; String dtime_formatted = ""; String result = ""; for (int i = 0; i < 20; i++) { GPSPlace GPSPlace_result = readArchiveItem(i); geoPoint = GPSPlace_result.geopoint; result = GPSPlace_result.result; Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.measurement_icon); Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888); Canvas tempCanvas = new Canvas(bmResult); // tempCanvas.scale(0.5f,0.5f); tempCanvas.drawBitmap(bmpOriginal, 0, 0, null); int index = i + 1; map.addMarker(new MarkerOptions().position(geoPoint).snippet(result).title("" + index) .icon(BitmapDescriptorFactory.fromBitmap(bmResult))); map.setInfoWindowAdapter(new MapPopup(getLayoutInflater())); map.setOnInfoWindowClickListener(this); List<LatLng> points = new ArrayList<LatLng>(); int totalPonts = 30; // number of corners of the pseudo-circle for (int c = 0; c < totalPonts; c++) { points.add(getPoint(geoPoint, 30, c * 2 * Math.PI / totalPonts)); } map.addPolygon(new PolygonOptions().addAll(points).fillColor(0x0550A050).strokeWidth(2) .strokeColor(0x100A050)); } } catch (Exception e1) { e1.printStackTrace(); } if (geoPoint != null) { CameraPosition camPos = new CameraPosition.Builder().target(geoPoint).zoom(18f).build(); CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos); map.moveCamera(camUpdate); } }