List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:com.tealeaf.TeaLeaf.java
public Bitmap getBitmapFromView(EditText view) { //Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) { //has background drawable, then draw it on the canvas bgDrawable.draw(canvas);/*from www . j a v a 2 s .co m*/ } // draw the view on the canvas view.draw(canvas); Paint p = new Paint(); p.setColor(Color.BLACK); p.setTextSize(24); canvas.drawText("'ello mate", 0, 0, p); //return the bitmap return returnedBitmap; }
From source file:eu.hydrologis.geopaparazzi.chart.ProfileChartActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.profilechart); int backgroundColor = getResources().getColor(R.color.main_background); int decorationsColor = getResources().getColor(R.color.main_decorations_dark); int textColor = getResources().getColor(R.color.main_text_color_neutral); Bundle extras = getIntent().getExtras(); if (extras != null) { try {//from w w w.j ava2 s . co m long logid = extras.getLong(Constants.ID); line = DaoGpsLog.getGpslogAsLine(logid, -1); } catch (IOException e) { GPLog.error(this, e.getLocalizedMessage(), e); e.printStackTrace(); } } else { Toast.makeText(this, R.string.an_error_occurred_while_creating_the_chart_, Toast.LENGTH_LONG).show(); } final float f26 = PixelUtils.dpToPix(26); final float f10 = PixelUtils.dpToPix(10); final SizeMetrics sm = new SizeMetrics(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL); xyPlotSpeed = (XYPlot) findViewById(R.id.speed_plot); xyPlotElev = (XYPlot) findViewById(R.id.elevation_plot); xyPlotSpeed.setOnTouchListener(this); infoTextView = (TextView) findViewById(R.id.info_text); Button resetButton = (Button) findViewById(R.id.reset_chart_button); resetButton.setOnClickListener(this); drawerLayout = (DrawerLayout) findViewById(R.id.container_drawer); // Disable Hardware Acceleration on the xyPlot view object. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { xyPlotSpeed.setLayerType(View.LAYER_TYPE_SOFTWARE, null); xyPlotElev.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } /* * Setup the Plots */ xyPlotSpeed.setPlotMargins(0, 0, 0, 0); xyPlotElev.setPlotMargins(0, 0, 0, 0); xyPlotSpeed.setPlotPadding(0, 0, 0, 0); xyPlotElev.setPlotPadding(0, 0, 0, 0); xyPlotElev.getDomainLabelWidget().setVisible(false); xyPlotElev.getRangeLabelWidget().setVisible(false); xyPlotElev.getTitleWidget().setVisible(false); xyPlotElev.setBorderPaint(null); xyPlotElev.setBackgroundPaint(null); /* * Setup the Graph Widgets */ XYGraphWidget graphWidgetSpeed = xyPlotSpeed.getGraphWidget(); XYGraphWidget graphWidgetElev = xyPlotElev.getGraphWidget(); graphWidgetSpeed.setSize(sm); graphWidgetElev.setSize(sm); graphWidgetSpeed.setMargins(0, 0, 0, 0); graphWidgetElev.setMargins(0, 0, 0, 0); graphWidgetSpeed.setPadding(f26, f10, f26, f26); graphWidgetElev.setPadding(f26, f10, f26, f26); graphWidgetSpeed.setRangeAxisPosition(true, false, 4, "10"); graphWidgetElev.setRangeAxisPosition(false, false, 4, "10"); graphWidgetSpeed.setRangeLabelVerticalOffset(-3); graphWidgetElev.setRangeLabelVerticalOffset(-3); graphWidgetSpeed.setRangeOriginLabelPaint(null); graphWidgetElev.setRangeOriginLabelPaint(null); graphWidgetSpeed.setRangeLabelWidth(0); graphWidgetElev.setRangeLabelWidth(0); graphWidgetSpeed.setDomainLabelWidth(0); graphWidgetElev.setDomainLabelWidth(0); graphWidgetElev.setBackgroundPaint(null); graphWidgetElev.setDomainLabelPaint(null); graphWidgetElev.setGridBackgroundPaint(null); graphWidgetElev.setDomainOriginLabelPaint(null); graphWidgetElev.setRangeOriginLinePaint(null); graphWidgetElev.setDomainGridLinePaint(null); graphWidgetElev.setRangeGridLinePaint(null); graphWidgetSpeed.getBackgroundPaint().setColor(backgroundColor); graphWidgetSpeed.getGridBackgroundPaint().setColor(backgroundColor); graphWidgetSpeed.getRangeOriginLinePaint().setColor(decorationsColor); graphWidgetSpeed.getRangeOriginLinePaint().setStrokeWidth(3f); graphWidgetSpeed.getDomainOriginLinePaint().setColor(decorationsColor); graphWidgetSpeed.getDomainOriginLinePaint().setStrokeWidth(3f); graphWidgetSpeed.getRangeGridLinePaint().setColor(decorationsColor); graphWidgetSpeed.getRangeGridLinePaint().setStrokeWidth(1f); graphWidgetSpeed.getDomainGridLinePaint().setColor(decorationsColor); graphWidgetSpeed.getDomainGridLinePaint().setStrokeWidth(1f); graphWidgetSpeed.getRangeLabelPaint().setColor(textColor); graphWidgetSpeed.getDomainLabelPaint().setColor(textColor); graphWidgetSpeed.getDomainOriginLabelPaint().setColor(textColor); Paint rangeOriginLabelPaint = graphWidgetSpeed.getRangeOriginLabelPaint(); if (rangeOriginLabelPaint == null) { rangeOriginLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); rangeOriginLabelPaint.setStyle(Paint.Style.STROKE); graphWidgetSpeed.setRangeOriginLabelPaint(rangeOriginLabelPaint); } rangeOriginLabelPaint.setColor(textColor); graphWidgetSpeed.getRangeLabelPaint().setTextSize(PixelUtils.dpToPix(8)); graphWidgetElev.getRangeLabelPaint().setTextSize(PixelUtils.dpToPix(8)); graphWidgetSpeed.getDomainOriginLabelPaint().setTextSize(PixelUtils.dpToPix(8)); graphWidgetSpeed.getDomainLabelPaint().setTextSize(PixelUtils.dpToPix(8)); float textSize = graphWidgetSpeed.getRangeLabelPaint().getTextSize(); graphWidgetSpeed.setRangeLabelVerticalOffset((textSize / 2) * -1); graphWidgetElev.setRangeLabelVerticalOffset(graphWidgetSpeed.getRangeLabelVerticalOffset()); /* * Position the Graph Widgets in the Centre */ graphWidgetSpeed.position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.ABSOLUTE_FROM_CENTER, AnchorPosition.CENTER); graphWidgetElev.position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.ABSOLUTE_FROM_CENTER, AnchorPosition.CENTER); /* * Position the Label Widgets */ xyPlotSpeed.getDomainLabelWidget().setWidth(100); xyPlotSpeed.getRangeLabelWidget().setWidth(100); xyPlotSpeed.getDomainLabelWidget().position(0, XLayoutStyle.RELATIVE_TO_CENTER, 1, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.BOTTOM_MIDDLE); xyPlotSpeed.getRangeLabelWidget().position(1, XLayoutStyle.ABSOLUTE_FROM_LEFT, -20, YLayoutStyle.ABSOLUTE_FROM_CENTER, AnchorPosition.LEFT_BOTTOM); /* * Setup and Position the speed Legend */ XYLegendWidget legendWidgetSpeed = xyPlotSpeed.getLegendWidget(); legendWidgetSpeed.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE)); legendWidgetSpeed.setPadding(1, 1, 1, 1); legendWidgetSpeed.setTableModel(new DynamicTableModel(1, 3)); legendWidgetSpeed.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE)); legendWidgetSpeed.getTextPaint().setColor(textColor); legendWidgetSpeed.getTextPaint().setTextSize(PixelUtils.dpToPix(9)); legendWidgetSpeed.position(PixelUtils.dpToPix(30), XLayoutStyle.ABSOLUTE_FROM_LEFT, f10 + 2, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.LEFT_TOP); /* * Setup and Position the elev Legend */ XYLegendWidget legendWidgetElev = xyPlotElev.getLegendWidget(); legendWidgetElev.setSize(new SizeMetrics(100, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE)); legendWidgetElev.setPadding(1, 1, 1, 1); legendWidgetElev.setTableModel(new DynamicTableModel(1, 3)); legendWidgetElev.setIconSizeMetrics(new SizeMetrics(PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE, PixelUtils.dpToPix(10), SizeLayoutType.ABSOLUTE)); // legendWidgetElev.getTextPaint().setColor(textColor); legendWidgetElev.getTextPaint().setTextSize(PixelUtils.dpToPix(9)); legendWidgetElev.getTextPaint().setTextAlign(Align.RIGHT); legendWidgetElev.setMarginLeft(185); legendWidgetElev.position(PixelUtils.dpToPix(30), XLayoutStyle.ABSOLUTE_FROM_RIGHT, f10 + 2, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP); // Setup the formatters int rgbSpeedLine = Color.rgb(0, 200, 0); int rgbSpeedPoints = Color.rgb(0, 100, 0); int rgbElevLine = Color.rgb(0, 0, 200); int rgbElevPoints = Color.rgb(0, 0, 100); seriesSpeedFormat = new LineAndPointFormatter(rgbSpeedLine, rgbSpeedPoints, null, null); seriesElevFormat = new LineAndPointFormatter(rgbElevLine, rgbElevPoints, null, null); }
From source file:com.example.psumaps.MapView.java
private void drawMarker(LatLng point, String str) { // Creating an instance of MarkerOptions MarkerOptions markerOptions = new MarkerOptions(); //IconGenerator tc = new IconGenerator(this); //Bitmap bmp = tc.makeIcon("hello"); Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bubble_white);// get the image same as your EditText int h = bitmap.getHeight() * 2; int w = bitmap.getWidth() * 2; bitmap = convertToMutable(bitmap);// converting the bitmap to mutable Bitmap incrsize = Bitmap.createScaledBitmap(bitmap, w, h, false); Canvas cs = new Canvas(incrsize); Paint pt = new Paint(); pt.setColor(Color.BLACK); //Typeface tf = Typeface.create("Helvetica",Typeface.BOLD); pt.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String iam = str.toUpperCase(Locale.getDefault()); pt.setTextSize(25);//from www . j a v a2 s . com cs.drawText(iam, 0, iam.length(), (h / 2) + 10, (w / 2) / 2, pt); //pt.setColor(Color.RED); //cs.drawText("this is praki", 0, 13, h / 2, w / 3, pt); // Setting latitude and longitude for the marker markerOptions.position(point).title(str).icon(BitmapDescriptorFactory.fromBitmap(incrsize)); // Adding marker on the Google Map map.addMarker(markerOptions); }
From source file:de.gebatzens.sia.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(SIAApp.SIA_APP.school.getTheme()); super.onCreate(savedInstanceState); Log.w("ggvp", "CREATE NEW MAINACTIVITY"); //Debug.startMethodTracing("sia3"); SIAApp.SIA_APP.activity = this; savedState = savedInstanceState;/*w ww . j a v a 2s .c o m*/ final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments; Intent intent = getIntent(); if (intent != null && intent.getStringExtra("fragment") != null) { FragmentData frag = fragments .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0); SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag)); } if (intent != null && intent.getBooleanExtra("reload", false)) { SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); intent.removeExtra("reload"); } setContentView(R.layout.activity_main); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); mContent = getFragment(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData()); if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) { ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm); summerNavigationPalm.setImageResource(R.drawable.summer_palm); ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image); summerBackgroundImage.setImageResource(R.drawable.summer_background); } mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_refresh: ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true); SIAApp.SIA_APP.refreshAsync(new Runnable() { @Override public void run() { ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)) .setRefreshing(false); } }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex())); return true; case R.id.action_settings: Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); return true; case R.id.action_addToCalendar: showExamDialog(); return true; case R.id.action_help: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(getApplication().getString(R.string.help)); builder.setMessage(getApplication().getString(R.string.exam_explain)); builder.setPositiveButton(getApplication().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } return false; } }); updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.addDrawerListener(mDrawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); mNavigationHeader = navigationView.getHeaderView(0); mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text); mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name); mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture); mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage()); mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link); mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View viewIn) { mDrawerLayout.closeDrawers(); Intent linkIntent = new Intent(Intent.ACTION_VIEW); linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website)); startActivity(linkIntent); } }); final Menu menu = navigationView.getMenu(); menu.clear(); for (int i = 0; i < fragments.size(); i++) { MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name); item.setIcon(fragments.get(i).getIconRes()); } menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings); menu.setGroupCheckable(R.id.fragments, true, true); menu.setGroupCheckable(R.id.settings, false, false); final Menu navMenu = navigationView.getMenu(); selectedItem = SIAApp.SIA_APP.getFragmentIndex(); if (selectedItem != -1) navMenu.getItem(selectedItem).setChecked(true); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { if (menuItem.getItemId() == R.id.settings_item) { mDrawerLayout.closeDrawers(); Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, 1); } else { final int index = menuItem.getOrder(); if (SIAApp.SIA_APP.getFragmentIndex() != index) { SIAApp.SIA_APP.setFragmentIndex(index); menuItem.setChecked(true); updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString()); mContent = getFragment(); Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out); fadeOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.setVisibility(View.INVISIBLE); if (fragments.get(index).getData() == null) SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index)); //removeAllFragments(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment"); transaction.commit(); snowView.updateSnow(); } @Override public void onAnimationRepeat(Animation animation) { } }); FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment); contentFrame.startAnimation(fadeOut); mDrawerLayout.closeDrawers(); } else { mDrawerLayout.closeDrawers(); } } return true; } }); if (Build.VERSION.SDK_INT >= 25) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); shortcutManager.removeAllDynamicShortcuts(); for (int i = 0; i < fragments.size(); i++) { Drawable drawable = getDrawable(fragments.get(i).getIconRes()); Bitmap icon; if (drawable instanceof VectorDrawable) { icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(icon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } else { icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes()); } Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(connectedIcon); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#f5f5f5")); canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint); paint.setColorFilter( new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP)); canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f), paint); Intent newTaskIntent = new Intent(this, MainActivity.class); newTaskIntent.setAction(Intent.ACTION_MAIN); newTaskIntent.putExtra("fragment", fragments.get(i).type.toString()); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name) .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name) .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build(); shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut)); } } if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) { if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) { TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3) .show(getSupportFragmentManager(), "upgrade_dialog"); } SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply(); } snowView = (SnowView) findViewById(R.id.snow_view); shareToolbar = (Toolbar) findViewById(R.id.share_toolbar); shareToolbar.getMenu().clear(); shareToolbar.inflateMenu(R.menu.share_toolbar_menu); shareToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleShareToolbar(false); for (Shareable s : MainActivity.this.shared) { s.setMarked(false); } MainActivity.this.shared.clear(); mContent.updateFragment(); } }); shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleShareToolbar(false); HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>(); for (Shareable s : MainActivity.this.shared) { ArrayList<Shareable> list = dates.get(s.getDate()); if (list == null) { list = new ArrayList<Shareable>(); dates.put(s.getDate(), list); } list.add(s); s.setMarked(false); } MainActivity.this.shared.clear(); List<Date> dateList = new ArrayList<Date>(dates.keySet()); Collections.sort(dateList); String content = ""; for (Date key : dateList) { content += SubstListAdapter.translateDay(key) + "\n\n"; Collections.sort(dates.get(key)); for (Shareable s : dates.get(key)) { content += s.getShareContent() + "\n"; } content += "\n"; } content = content.substring(0, content.length() - 1); mContent.updateFragment(); if (item.getItemId() == R.id.action_copy) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.entries), content); clipboard.setPrimaryClip(clip); } else if (item.getItemId() == R.id.action_share) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, content); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); } return true; } }); if (shared.size() > 0) { shareToolbar.setVisibility(View.VISIBLE); updateShareToolbarText(); } // if a fragment is opened via a notification or a shortcut reset the shared entries // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment if (intent != null && intent.hasExtra("fragment")) { resetShareToolbar(); intent.removeExtra("fragment"); } }
From source file:de.madvertise.android.sdk.MadvertiseView.java
/** * Draw the ad background for a text banner * * @param canvas/*w w w .ja v a 2 s . c o m*/ * @param rectangle * @param backgroundColor * @param mTextColor */ private void drawTextBannerBackground(final Canvas canvas, final Rect rectangle, final int backgroundColor, int shineColor) { Paint paint = new Paint(); paint.setColor(backgroundColor); paint.setAntiAlias(true); canvas.drawRect(rectangle, paint); int upperColor = Color.argb(GRADIENT_TOP_ALPHA, Color.red(shineColor), Color.green(shineColor), Color.blue(shineColor)); int[] gradientColors = { upperColor, shineColor }; GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, gradientColors); int stop = (int) (rectangle.height() * GRADIENT_STOP) + rectangle.top; gradientDrawable.setBounds(rectangle.left, rectangle.top, rectangle.right, stop); gradientDrawable.draw(canvas); Rect shadowRect = new Rect(rectangle.left, stop, rectangle.right, rectangle.bottom); Paint shadowPaint = new Paint(); shadowPaint.setColor(shineColor); canvas.drawRect(shadowRect, shadowPaint); }
From source file:net.exclaimindustries.geohashdroid.util.KnownLocation.java
@NonNull private Bitmap buildMarkerBitmap(@NonNull Context c) { // Oh, this is going to be FUN. int dim = c.getResources().getDimensionPixelSize(R.dimen.known_location_marker_canvas_size); float radius = c.getResources().getDimension(R.dimen.known_location_pin_head_radius); Bitmap bitmap = Bitmap.createBitmap(dim, dim, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);// ww w.ja va 2s. c o m KnownLocationPinData pinData = new KnownLocationPinData(c, mLocation); // Draw the pin line first. That goes from the bottom-center up to // wherever the radius and length take us. float topX = Double.valueOf((dim / 2) + (pinData.getLength() * Math.cos(pinData.getAngle()))).floatValue(); float topY = Double.valueOf(dim - (pinData.getLength() * Math.sin(pinData.getAngle()))).floatValue(); paint.setStrokeWidth(c.getResources().getDimension(R.dimen.known_location_stroke)); paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK); canvas.drawLine(dim / 2, dim, topX, topY, paint); // On the top of that line, fill in a circle. paint.setColor(pinData.getColor()); paint.setStyle(Paint.Style.FILL); canvas.drawCircle(topX, topY, radius, paint); // And outline it. paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(topX, topY, radius, paint); return bitmap; }
From source file:com.tct.mail.browse.MessageHeaderView.java
/** * Frames the input bitmap in a circle.//from w w w .j a v a2 s. c o m */ private static Bitmap frameBitmapInCircle(Bitmap input) { if (input == null) { return null; } // Crop the image if not squared. int inputWidth = input.getWidth(); int inputHeight = input.getHeight(); int targetX, targetY, targetSize; if (inputWidth >= inputHeight) { targetX = inputWidth / 2 - inputHeight / 2; targetY = 0; targetSize = inputHeight; } else { targetX = 0; targetY = inputHeight / 2 - inputWidth / 2; targetSize = inputWidth; } // Create an output bitmap and a canvas to draw on it. Bitmap output = Bitmap.createBitmap(targetSize, targetSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); // Create a black paint to draw the mask. Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.BLACK); // Draw a circle. canvas.drawCircle(targetSize / 2, targetSize / 2, targetSize / 2, paint); // Replace the black parts of the mask with the input image. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(input, targetX /* left */, targetY /* top */, paint); return output; }
From source file:com.yk.notification.util.BitmapUtil.java
/** * ??// w w w .j av a 2 s. co m * * @param bitmap * Bitmap * @return Bitmap */ public static Bitmap getRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2; top = 0; bottom = width; left = 0; right = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, src, dst, paint); return output; }
From source file:org.mozilla.gecko.GeckoAppShell.java
static private Bitmap getLauncherIcon(Bitmap aSource) { final int kOffset = 6; final int kRadius = 5; int kIconSize; int kOverlaySize; switch (getDpi()) { case DisplayMetrics.DENSITY_MEDIUM: kIconSize = 48;//ww w . ja va 2 s . c om kOverlaySize = 32; break; case DisplayMetrics.DENSITY_XHIGH: kIconSize = 96; kOverlaySize = 48; break; case DisplayMetrics.DENSITY_HIGH: default: kIconSize = 72; kOverlaySize = 32; } Bitmap bitmap = Bitmap.createBitmap(kIconSize, kIconSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // draw a base color Paint paint = new Paint(); if (aSource == null) { float[] hsv = new float[3]; hsv[0] = 32.0f; hsv[1] = 1.0f; hsv[2] = 1.0f; paint.setColor(Color.HSVToColor(hsv)); canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint); } else { int color = BitmapUtils.getDominantColor(aSource); paint.setColor(color); canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint); paint.setColor(Color.argb(100, 255, 255, 255)); canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius, kRadius, paint); } // draw the overlay Bitmap overlay = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_bg); canvas.drawBitmap(overlay, null, new Rect(0, 0, kIconSize, kIconSize), null); // draw the bitmap if (aSource == null) aSource = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_star); if (aSource.getWidth() < kOverlaySize || aSource.getHeight() < kOverlaySize) { canvas.drawBitmap(aSource, null, new Rect(kIconSize / 2 - kOverlaySize / 2, kIconSize / 2 - kOverlaySize / 2, kIconSize / 2 + kOverlaySize / 2, kIconSize / 2 + kOverlaySize / 2), null); } else { canvas.drawBitmap(aSource, null, new Rect(kIconSize / 2 - aSource.getWidth() / 2, kIconSize / 2 - aSource.getHeight() / 2, kIconSize / 2 + aSource.getWidth() / 2, kIconSize / 2 + aSource.getHeight() / 2), null); } return bitmap; }