Advertisement
Guest User

Untitled

a guest
Nov 16th, 2012
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.46 KB | None | 0 0
  1. From The Activity onCreate:
  2.  
  3. paintLayout = (RelativeLayout) findViewById(R.id.paintLayout);
  4.         paint = (RelativeLayout) findViewById(R.id.paint);
  5.         final ImageView imageviewPaint = (ImageView) findViewById(R.id.imageViewPaint);
  6.  
  7.         upperTab = (RelativeLayout) findViewById(R.id.UpperTabPaint);
  8.         optionsTab = (RelativeLayout) findViewById(R.id.OptionsTab);
  9.         new Handler().postDelayed(new Runnable() {
  10.  
  11.             @Override
  12.             public void run() {
  13.                 int a = upperTab.getLayoutParams().height;
  14.                 int b = optionsTab.getLayoutParams().height;
  15.                 Display display = getWindowManager().getDefaultDisplay();
  16.                 width = display.getWidth(); // ia widthu si heightu la layoutu pe care se va desena...
  17.                 height = (display.getHeight()) - (a + b);
  18.                 LogService.log("in run delayed", "+++++++++++++++++++WIDTH/HEight: " + width + "||" + height);
  19.                 myView = new CustomImage(PaintActivity.this);
  20.                 paint.addView(myView); // se pune pe layoutu d desenat View-u (CustomImage.java)
  21.                 String imagePath = (String) getIntent().getExtras().get("sel" + "ectedImagePath");// se ia locatia pozei
  22.                 LogService.log("PaintActivity", "Imagepath: " + imagePath);
  23.                 try {
  24.                     fis = new FileInputStream(imagePath);
  25.                 } catch (FileNotFoundException e) {
  26.                     e.printStackTrace();
  27.                 }
  28.                 try {
  29.                     mBitmap = loadBitmap(fis.getFD());// se incarca bitmapu
  30.                     targetConfig = mBitmap.getConfig();// se ia configuratia pozei
  31.                     int picWidth = mBitmap.getWidth();
  32.                     float picHeight = mBitmap.getHeight();
  33.                     float ratio = picWidth / (float) width;
  34.                     int newheight = (int) (picHeight / ratio);
  35.  
  36.                     bitmap = getResizedBitmap(mBitmap, newheight, width, targetConfig);// rescaleaza bitmapu
  37.                     LogService.log("-----bitmap", "bitmap= " + bitmap.getConfig());
  38.                     LogService.log("-----mBitmap", "mBitmap= " + mBitmap.getConfig());
  39.                 } catch (IOException e) {
  40.                     // TODO Auto-generated catch block
  41.                     e.printStackTrace();
  42.                 }
  43.                 try {
  44.                     LogService.log("PaintActivity", "Bitmap = " + mBitmap);
  45.                     bitmapgol = Bitmap.createBitmap(width, height, targetConfig);// creaza bitmap gol
  46.                     imageviewPaint.setImageBitmap(bitmap);// se pune pe ImageView imaginea de background
  47.                     myView.setBitmap(bitmapgol, targetConfig); // se pune bitmapu gol pe View-ul meu (CustomImage)
  48.                     paint.bringToFront();
  49.                     paintLayout.bringChildToFront(paint);
  50.                 } catch (Exception e) {
  51.                     // TODO Auto-generated catch block
  52.                     e.printStackTrace();
  53.                 }
  54.                 mPaint = new Paint();
  55.                 mPaint.setAntiAlias(true);
  56.                 mPaint.setDither(true);
  57.                 mPaint.setColor(0xFF000000);
  58.                 mPaint.setStyle(Paint.Style.STROKE);
  59.                 mPaint.setStrokeJoin(Paint.Join.ROUND);
  60.                 mPaint.setStrokeCap(Paint.Cap.ROUND);
  61.                 mPaint.setStrokeWidth(50);
  62.                 myView.setPaint(mPaint);
  63.  
  64.             }
  65.         }, 50);
  66.  
  67.  
  68. The xml:
  69.  
  70. <?xml version="1.0" encoding="utf-8"?>
  71. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  72.     android:layout_width="match_parent"
  73.     android:layout_height="match_parent"
  74.     android:orientation="vertical" >
  75.  
  76.     <RelativeLayout
  77.         android:id="@+id/UpperTabPaint"
  78.         android:layout_width="match_parent"
  79.         android:layout_height="50dp"
  80.         android:layout_alignParentLeft="true"
  81.         android:layout_alignParentTop="true"
  82.         android:background="@color/flock_blue" >
  83.  
  84.         <ImageButton
  85.             android:id="@+id/backDrawBtn"
  86.             android:layout_width="wrap_content"
  87.             android:layout_height="wrap_content"
  88.             android:layout_alignParentLeft="true"
  89.             android:layout_alignParentTop="true"
  90.             android:layout_marginLeft="10dp"
  91.             android:layout_marginTop="15dp"
  92.             android:background="#0000"
  93.             android:src="@drawable/backdraw" />
  94.  
  95.         <ImageButton
  96.             android:id="@+id/chooser2"
  97.             android:layout_width="wrap_content"
  98.             android:layout_height="wrap_content"
  99.             android:layout_alignParentRight="true"
  100.             android:layout_alignParentTop="true"
  101.             android:layout_marginRight="20dp"
  102.             android:layout_marginTop="10dp"
  103.             android:background="#0000"
  104.             android:src="@drawable/chooser" />
  105.     </RelativeLayout>
  106.  
  107.     <RelativeLayout
  108.         android:id="@+id/OptionsTab"
  109.         android:layout_width="match_parent"
  110.         android:layout_height="50dp"
  111.         android:layout_alignParentBottom="true"
  112.         android:layout_alignParentLeft="true"
  113.         android:background="@color/flock_blue" >
  114.  
  115.         <TextView
  116.             android:id="@+id/drtools"
  117.             android:layout_width="wrap_content"
  118.             android:layout_height="wrap_content"
  119.             android:layout_alignParentLeft="true"
  120.             android:layout_centerVertical="true"
  121.             android:text="@string/drawtool"
  122.             android:textColor="@color/white"
  123.             android:textSize="20dp" />
  124.  
  125.         <ImageButton
  126.             android:id="@+id/textBtn"
  127.             android:layout_width="wrap_content"
  128.             android:layout_height="match_parent"
  129.             android:layout_alignParentBottom="true"
  130.             android:layout_toRightOf="@+id/drtools"
  131.             android:background="#0000"
  132.             android:src="@drawable/text" />
  133.  
  134.         <ImageButton
  135.             android:id="@+id/penBtn"
  136.             android:layout_width="wrap_content"
  137.             android:layout_height="match_parent"
  138.             android:layout_alignParentBottom="true"
  139.             android:layout_toRightOf="@+id/textBtn"
  140.             android:background="#0000"
  141.             android:src="@drawable/pen" />
  142.  
  143.         <ImageButton
  144.             android:id="@+id/objBtn"
  145.             android:layout_width="wrap_content"
  146.             android:layout_height="match_parent"
  147.             android:layout_alignParentTop="true"
  148.             android:layout_marginBottom="1dp"
  149.             android:layout_toRightOf="@+id/penBtn"
  150.             android:background="#0000"
  151.             android:src="@drawable/obj" />
  152.  
  153.         <ImageButton
  154.             android:id="@+id/eraseBtn"
  155.             android:layout_width="wrap_content"
  156.             android:layout_height="match_parent"
  157.             android:layout_alignParentTop="true"
  158.             android:layout_toRightOf="@+id/objBtn"
  159.             android:background="#0000"
  160.             android:src="@drawable/erase" />
  161.  
  162.  
  163.  
  164.  
  165.         <Button
  166.             android:id="@+id/cancelBtn"
  167.             android:layout_width="45dp"
  168.             android:layout_height="wrap_content"
  169.             android:layout_alignParentBottom="true"
  170.             android:layout_alignParentRight="true"
  171.             android:layout_alignParentTop="true"
  172.             android:background="@drawable/button_selector"
  173.             android:text="@string/cancel" />
  174.  
  175.  
  176.  
  177.         <Button
  178.             android:id="@+id/saveBtn"
  179.             android:layout_width="45dp"
  180.             android:layout_height="wrap_content"
  181.             android:layout_alignParentBottom="true"
  182.             android:layout_alignParentTop="true"
  183.             android:layout_toLeftOf="@+id/cancelBtn"
  184.             android:background="@drawable/button_selector"
  185.             android:text="@string/save" />
  186.  
  187.  
  188.  
  189.         <Button
  190.             android:id="@+id/sendBtn"
  191.             android:layout_width="45dp"
  192.             android:layout_height="wrap_content"
  193.             android:layout_alignParentBottom="true"
  194.             android:layout_alignParentTop="true"
  195.             android:layout_toLeftOf="@+id/saveBtn"
  196.             android:background="@drawable/button_selector"
  197.             android:text="@string/send" />
  198.  
  199.         <SeekBar
  200.             android:id="@+id/brushsizeBar"
  201.             android:layout_width="match_parent"
  202.             android:layout_height="wrap_content"
  203.             android:layout_centerVertical="true"
  204.             android:layout_toLeftOf="@id/sendBtn"
  205.             android:layout_toRightOf="@+id/brushsizeTV" />
  206.  
  207.         <ImageButton
  208.             android:id="@+id/button1"
  209.             android:layout_width="wrap_content"
  210.             android:layout_height="match_parent"
  211.             android:layout_alignParentBottom="true"
  212.             android:layout_toRightOf="@+id/eraseBtn"
  213.             android:background="#0000"
  214.             android:src="@drawable/colorpicker" />
  215.  
  216.         <TextView
  217.             android:id="@+id/brushsizeTV"
  218.             android:layout_width="wrap_content"
  219.             android:layout_height="wrap_content"
  220.             android:layout_centerVertical="true"
  221.             android:layout_toRightOf="@+id/button1"
  222.             android:text="@string/brsize"
  223.             android:textColor="@color/white"
  224.             android:textSize="20dp" />
  225.     </RelativeLayout>
  226.  
  227.     <RelativeLayout
  228.         android:id="@+id/paintLayout"
  229.         android:layout_width="0dp"
  230.         android:layout_height="0dp"
  231.         android:layout_above="@+id/OptionsTab"
  232.         android:layout_alignParentLeft="true"
  233.         android:layout_alignParentRight="true"
  234.         android:layout_below="@+id/UpperTabPaint"
  235.         android:layout_centerHorizontal="true"
  236.         android:background="@color/digg_blue" >
  237.  
  238.         <ImageView
  239.             android:id="@+id/imageViewPaint"
  240.             android:layout_width="match_parent"
  241.             android:layout_height="match_parent"
  242.             android:layout_alignParentTop="true"
  243.             android:layout_centerHorizontal="true"
  244.             android:src="@drawable/loading" />
  245.  
  246.         <RelativeLayout
  247.             android:id="@+id/paint"
  248.             android:layout_width="match_parent"
  249.             android:layout_height="match_parent"
  250.             android:layout_above="@+id/OptionsTab"
  251.             android:layout_alignParentLeft="true"
  252.             android:layout_alignParentRight="true"
  253.             android:layout_below="@+id/UpperTabPaint"
  254.             android:layout_centerHorizontal="true" >
  255.         </RelativeLayout>
  256.     </RelativeLayout>
  257.  
  258. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement