Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Bitmap Canvas Color Gradient linear radial sweep rounded corner Android example


public class MainActivity extends Activity {
//  //www.apache.org/licenses/LICENSE-2.0
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	   private static class SampleView extends View {
	        private Rect    mRect;
	        private GradientDrawable mDrawable;

	        public SampleView(Context context) {
	            super(context);
	            setFocusable(true);

	            mRect = new Rect(0, 0, 220, 120);
	      
/*	            GradientDrawable.Orientation  BL_TR  draw the gradient from the bottom-left to the top-right   
	              BOTTOM_TOP  draw the gradient from the bottom to the top   
	              BR_TL  draw the gradient from the bottom-right to the top-left   
	              LEFT_RIGHT  draw the gradient from the left to the right   
	              RIGHT_LEFT  draw the gradient from the right to the left   
	              TL_BR  draw the gradient from the top-left to the bottom-right   
	              TOP_BOTTOM  draw the gradient from the top to the bottom   
	              TR_BL  draw the gradient from the top-right to the bottom-left   
*/
	            
	            mDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
	                                             new int[] { 0xFFFF0000, 0xFF00FF00,
	                                                 0xFF0000FF });
	            mDrawable.setShape(GradientDrawable.RECTANGLE);
	            mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
	        }
	        
	        static void setCornerRadius(GradientDrawable drawable, float r0,
	                                   float r1, float r2, float r3) {
/*	        	setCornerRadii
	        	Specify radii for each of the 4 corners. For each corner, 
	        	the array contains 2 values, [X_radius, Y_radius]. 
	        	The corners are ordered top-left, top-right, bottom-right, 
	        	bottom-left 
*/
	            drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
	                                                  r2, r2, r3, r3 });
	        }
	        
	        @Override protected void onDraw(Canvas canvas) {
	            
	            mDrawable.setBounds(mRect);

	            float r = 35;
	            
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
	            setCornerRadius(mDrawable, r, r, 0, 0);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            canvas.translate(0, mRect.height() + 10);
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
	            setCornerRadius(mDrawable, 0, 0, r, r);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            canvas.translate(0, mRect.height() + 10);
	            canvas.save();
	            canvas.translate(10, 10);
	            mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
	            setCornerRadius(mDrawable, 0, r, r, 0);
	            mDrawable.draw(canvas);
	            canvas.restore();
	            
	            
	        }
	    }
	}


android/gradient-bitmap-rounded.png

396LW NO topic_id




AD

Další témata ....(Topics)


267

setTesting(boolean) from the type AdRequest is deprecated | settestingboolean-from-the-type-adrequest-is-deprecated


Admob testing on emulator issue.
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);


AdView adView = new AdView(this, AdSize.BANNER, "a14d9..........");//MY_AD_UNIT_ID
AdRequest adRequest = new AdRequest();
		adRequest.setTesting(true); // deprecated

		adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // OK
		adView.loadAd(adRequest);

148

Crop cropped cut bitmap image pictures Android example | crop-cropped-cut-bitmap-image-pictures-android-example


Cut, shear, clip, snip, crop a bitmap, picture, image Android example

public class ApokusActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();

			canvas.drawColor(Color.YELLOW);


			// you need to insert a image flower_blue into res/drawable folder
			paint.setFilterBitmap(true);
			Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
					R.drawable.flower_blue);

			Bitmap croppedBmp = Bitmap.createBitmap(bitmapOrg, 0, 0,
					bitmapOrg.getWidth() / 2, bitmapOrg.getHeight());
			int h = bitmapOrg.getHeight();
			canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			canvas.drawBitmap(croppedBmp, 10, 10 + h + 10, paint);

		}

	}
}



android/crop-bitmap-android.png
380

Android Fragment Examples | android-fragment-examples


Code look up at the Api Demos

android_fragments arguments attributes - three fragments on screen
android/android_fragments_arguments.png

android_fragments_alert_dialog
android/android_fragments_alert_dialog.png

android_fragments_context_menu
android/android_fragments_context_menu.png

android_fragments_custom_animation
android/android_fragments_custom_animation.png

android_fragments_dialog
android/android_fragments_dialog.png

android_fragments_dialog_or_activity
android/android_fragments_dialog_or_activity.png

fragment_hide_show
android/fragment_hide_show.png

fragment_layout
android/fragment_dialog.png

fragments_list_array
android/fragments_list_array.png

fragment_menu
android/fragment_menu.png

android_fragments_get_result_from_fragment and tabs in two rows
android/android_fragments_get_result_from_fragment.png

android_fragments_recive_result
android/android_fragments_recive_result.png

android_fragments_stack
android/android_fragments_stack.png

fragment_tabs
android/fragment_tabs.png





20

How set gray text to EditText Android example | how-set-gray-text-to-edittext-android-example


Example source code for Android development. How set gray text to EditText when EditText is blank.
Hint text to display when the text is empty.
In layout/main.xml insert to EditText row Attribute Name android:hint="Some text"


<EditText
        android:id="@+id/myEdit" 
	android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:hint="Some text"
	android:singleLine="true"
</EditText>	



Programatically you can use method setHint:


// setHint(CharSequence hint) example
(EditText)findViewById(R.id.myEdit).setHint("My text");
// or int resId as method setHint(int resId) 
EditText myEdit = findViewById(R.id.myEdit);
myEdit.setHint(R.string.app_name);



246

Snow Text Effects Paint.NET | snow-text-effects-paint-net


For some graphics you can use Paint.NET editor.
//www.getpaint.net/
How create Snow Effects on Text by 1 minute show this video: