drawBitmap, clipPath, UNION, DIFFERENCE, INTERSECT, REPLACE, XOR Android example
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.YELLOW);
Bitmap b = Bitmap.createBitmap(200, 200,
Bitmap.Config.ARGB_8888);
// you need to insert a image flower_blue into res/drawable folder
paint.setFilterBitmap(true);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.flower_blue);
canvas.drawBitmap(bitmapOrg, 10, 10, paint);
int width, height;
Canvas c = new Canvas(b);
paint.setAlpha(255); //0x80
c.translate(0, 30);
c.drawBitmap(bitmapOrg, new Matrix(), paint);
paint.setColor(Color.BLUE);
Path mPath = new Path();
mPath.addCircle(50, 50, 50, Path.Direction.CCW);
//c.clipPath(mPath, Region.Op.UNION);
//c.clipPath(mPath, Region.Op.DIFFERENCE);
c.clipPath(mPath, Region.Op.INTERSECT);
//c.clipPath(mPath, Region.Op.REPLACE);
//c.clipPath(mPath, Region.Op.XOR);
paint.setColor(Color.GREEN);
paint.setAntiAlias(true);
c.drawCircle(30, 20, 30, paint);
int h = bitmapOrg.getHeight();
//canvas.drawBitmap(bitmapOrg, 10, 10, paint);
canvas.drawBitmap(b, 0, 10 + h + 10, paint);
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
How start certain Activity if user clicked to ListView item
Start Activity from list – launches other activities from list - latest variant!!!!
Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml
Start Activity from list – launches other activities from list - latest variant!!!!
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.main);
ListView mlistView = (ListView) findViewById(R.id.idListView);
mlistView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[] {"Game", "Help", "Home site"}));
mlistView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text Game, Help, Home
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
String sText = ((TextView) view).getText().toString();
Intent intent = null;
if(sText.equals("Game"))
intent = new Intent(getBaseContext(),
Game.class);
//else if(sText.equals("Help")) ..........
if(intent != null)
startActivity(intent);
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml
<activity android:name=".Game" android:label="GameLabel">
</activity>
package cz.okhelp.listview;
import android.app.Activity;
import android.os.Bundle;
public class Game extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you have to create game.xml
setContentView(R.layout.game);
}
}
main.xml
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageViewObrazekGeometrie"
android:layout_width="360dp"
android:layout_height="777dp"
android:src="@drawable/geometrie_vzorecky" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
- download any mobile styles for example //www.artodia.com/phpbb-styles/mobile/
- unzip style into your forum style folder for example all art_mobile folder copy into 0:/myweb/forum/styles/
- folow instalation istructions //www.artodia.com/phpbb-styles/mobile/tutorials/mobile-detection/
- check url result on https://www.google.com/webmasters/tools/mobile-friendly
- unzip style into your forum style folder for example all art_mobile folder copy into 0:/myweb/forum/styles/
- folow instalation istructions //www.artodia.com/phpbb-styles/mobile/tutorials/mobile-detection/
- check url result on https://www.google.com/webmasters/tools/mobile-friendly
If you change android:versionCode="224" and android:versionName="2.2.4" in AndroidManifest.xml you have to change this in build.gradle file too.
Click on build.gradle in package explorer tree change your new version name and code:
Click on build.gradle in package explorer tree change your new version name and code:
defaultConfig {
applicationId "cz.okhelp.pocasiwidget"
minSdkVersion 11
targetSdkVersion 23
versionCode 224
versionName "2.2.4"
}
do while Java example
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
// first cycle is always executed
do {
System.out.println("Loop: " + i);
System.out.println(arrayOfString[i]);
i++;
}while ( i == -1 );
}
}
/*
Loop: 0
Hello
*/
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
do {
System.out.println("Loop: " + i);
System.out.println(arrayOfString[i]);
i++;
}while ( i < arrayOfString.length );
}
}
/*
Loop: 0
Hello
Loop: 1
people
Loop: 2
hello
Loop: 3
world!
*/
Editace: 2011-11-16 17:52:26
Počet článků v kategorii: 396
Url:drawbitmap-clippath-union-difference-intersect-replace-xor-android-example