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.

Rounded rect RectF Android example


AD MOB

RectF, drawRoundRect(),

public class MainActivity 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.GREEN);
            
           Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
           Canvas c = new Canvas(b);
           RectF rectF = new RectF();
           rectF.set(5,5,150,150);
           c.drawRoundRect(rectF, 10, 10, paint);
           
            paint.setColor(Color.RED);
           
           canvas.drawBitmap(b, 10,10, paint);
		}

	}
}


draw-rounded-rect-android

397LW NO topic_id




AD

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


315

Importing google-play-service library project to workspace issue | importing-google-play-service-library-project-to-workspace-issue


Try two way in Eclipse IDE:

1.) Import the library project into your Eclipse workspace.
Click File > Import,
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
If project not visible with checkbox try next step as see below.

2.) Click
File > New > Other
select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
253

Play Sound Android Example | play-sound-android-example



import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class SoundManager
{
  private SoundPool soundPool;
  private int[] sm;
  Context context;

  public SoundManager(Context context) {
    this.context = context;
    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    sm = new int[2];
    // fill your sounds
    sm[0] = soundPool.load(context, R.raw.my_sound1, 1);
    sm[1] = soundPool.load(context, R.raw.my_sound2, 1);
  }

  public final void playSound(int sound) {
      AudioManager mgr = (AudioManager)context.getSystemService(
          Context.AUDIO_SERVICE);  
      float streamVolumeCurrent =
          mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
      float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      float volume = streamVolumeCurrent / streamVolumeMax;
      soundPool.play(sm[sound], volume, volume, 1, 0, 1f);
  }

  public final void cleanUpIfEnd() {
    sm = null;
    context = null;
    soundPool.release();
    soundPool = null;
  }
}
396

ADB restart device every time Android Studio | adb-restart-device-every-time


Android Studio ADB restart mobile device from USB every time if RUN of DEBUG button pressed

Try to close the mobile application on your device completely before starting again from Android Studio.
Close every fragment.
The problem occurs when the application has multiple fragments.

Date: 13.07.2020 - 08:23
62

Date Calendar Java Android Example | date-calendar-java-android-example


Calendar cal = new GregorianCalendar(), int year = cal.get(Calendar.YEAR),
ERA, MONTH, DAY_OF_MONTH, DAY_OF_WEEK, Android example code.

public class MainActivity extends Activity {
TextView txtV;
	Context cntx;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        Calendar cal = new GregorianCalendar();

     int era = cal.get(Calendar.ERA);  // 0 B.C. before Christ, 1 Anno Domini              
     txtV.setText(txtV.getText() +"

" + era); int year = cal.get(Calendar.YEAR); // 2011 txtV.setText(txtV.getText() +"
" + year); int month = cal.get(Calendar.MONTH); // 0 is Januar txtV.setText(txtV.getText() +"
" + month); int day = cal.get(Calendar.DAY_OF_MONTH); // 1 to 31 txtV.setText(txtV.getText() +"
" + day); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday ... txtV.setText(txtV.getText() +"
" + dayOfWeek); } }
147

Resize a bitmap image Android example | resize-a-bitmap-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);
            
	         
	         paint.setFilterBitmap(true);
	         Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.flower_blue);
	         int targetWidth  = bitmapOrg.getWidth() * 2;
	         int targetHeight = bitmapOrg.getHeight() * 2;
	         Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
	         RectF rectf = new RectF(0, 0, targetWidth, targetHeight);
	         Canvas c = new Canvas(bmp);
	         Path path = new Path();
	         path.addRect(rectf, Path.Direction.CW);
	         c.clipPath(path);
	         c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()),
	                         new Rect(0, 0, targetWidth, targetHeight), paint);
	         Matrix matrix = new Matrix();
	         matrix.postScale(1f, 1f);
	         Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true);
	         int h = bitmapOrg.getHeight();
           canvas.drawBitmap(bitmapOrg, 10,10, paint);
           canvas.drawBitmap(resizedBitmap, 10,10 + h + 10, paint);
           
		}

	}
}


resize bitmap android


Editace: 2011-11-13 20:49:14
Počet článků v kategorii: 397
Url:rounded-rect-rectf-android-example

AD
11 Share
Share
Tweet