Facebook
From domateo, 9 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 954
  1. package com.example.trojkat2d;
  2.  
  3.  
  4. import android.support.v7.app.ActionBarActivity;
  5. import android.graphics.Color;
  6. import android.graphics.Path;
  7. import android.graphics.drawable.Drawable;
  8. import android.graphics.drawable.ShapeDrawable;
  9. import android.graphics.drawable.shapes.PathShape;
  10. import android.os.Bundle;
  11. import android.view.Menu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.widget.Button;
  15. import android.widget.CheckBox;
  16. import android.widget.ImageView;
  17.  
  18. public class MainActivity extends ActionBarActivity {
  19.  
  20.         @Override
  21.         protected void onCreate(Bundle savedInstanceState) {
  22.                 super.onCreate(savedInstanceState);
  23.                 setContentView(R.layout.activity_main);
  24.                
  25.                 final Button pathButton = (Button) findViewById(R.id.button1);
  26.                 pathButton.setOnClickListener(new View.OnClickListener() {
  27.                         public void onClick(View v) {
  28.                                                
  29.                                 // Zdefiniowanie trojkata
  30.                                 Path p = new Path();
  31.                                 p.moveTo(50, 0);
  32.                                 p.lineTo(100,100);
  33.                                 p.lineTo(0,100);
  34.                                 p.lineTo(50,0);    
  35.                                 ShapeDrawable d = new ShapeDrawable(new PathShape(p, 100, 100));
  36.                                 d.setIntrinsicHeight(100);
  37.                                 d.setIntrinsicWidth(100);
  38.                                 d.getPaint().setColor(Color.BLUE);
  39.                                 final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
  40.                         if (checkBox.isChecked()) {
  41.                                 d.getPaint().setColor(Color.RED);
  42.                                 setShapeByDrawable(d);
  43.                         }
  44.                                 setShapeByDrawable(d);
  45.                         }
  46.                        
  47.                 });
  48.         }
  49.  
  50.         @Override
  51.         public boolean onCreateOptionsMenu(Menu menu) {
  52.                 // Inflate the menu; this adds items to the action bar if it is present.
  53.                 getMenuInflater().inflate(R.menu.main, menu);
  54.                 return true;
  55.         }
  56.  
  57.         @Override
  58.         public boolean onOptionsItemSelected(MenuItem item) {
  59.                 // Handle action bar item clicks here. The action bar will
  60.                 // automatically handle clicks on the Home/Up button, so long
  61.                 // as you specify a parent activity in AndroidManifest.xml.
  62.                 int id = item.getItemId();
  63.                 if (id == R.id.action_settings) {
  64.                         return true;
  65.                 }
  66.                 return super.onOptionsItemSelected(item);
  67.         }
  68.         private void setShapeByDrawable(Drawable drawable) {
  69.                 ImageView reusableImageView = (ImageView) findViewById(R.id.imageView1);
  70.                 reusableImageView.setImageDrawable(drawable);
  71.         }
  72. }
  73.  

Replies to trojkat rss

Title Name Language When
Re: trojkat activity_main.xml domateo xml 9 Years ago.