Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From The Activity onCreate:
- paintLayout = (RelativeLayout) findViewById(R.id.paintLayout);
- paint = (RelativeLayout) findViewById(R.id.paint);
- final ImageView imageviewPaint = (ImageView) findViewById(R.id.imageViewPaint);
- upperTab = (RelativeLayout) findViewById(R.id.UpperTabPaint);
- optionsTab = (RelativeLayout) findViewById(R.id.OptionsTab);
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- int a = upperTab.getLayoutParams().height;
- int b = optionsTab.getLayoutParams().height;
- Display display = getWindowManager().getDefaultDisplay();
- width = display.getWidth(); // ia widthu si heightu la layoutu pe care se va desena...
- height = (display.getHeight()) - (a + b);
- LogService.log("in run delayed", "+++++++++++++++++++WIDTH/HEight: " + width + "||" + height);
- myView = new CustomImage(PaintActivity.this);
- paint.addView(myView); // se pune pe layoutu d desenat View-u (CustomImage.java)
- String imagePath = (String) getIntent().getExtras().get("sel" + "ectedImagePath");// se ia locatia pozei
- LogService.log("PaintActivity", "Imagepath: " + imagePath);
- try {
- fis = new FileInputStream(imagePath);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- try {
- mBitmap = loadBitmap(fis.getFD());// se incarca bitmapu
- targetConfig = mBitmap.getConfig();// se ia configuratia pozei
- int picWidth = mBitmap.getWidth();
- float picHeight = mBitmap.getHeight();
- float ratio = picWidth / (float) width;
- int newheight = (int) (picHeight / ratio);
- bitmap = getResizedBitmap(mBitmap, newheight, width, targetConfig);// rescaleaza bitmapu
- LogService.log("-----bitmap", "bitmap= " + bitmap.getConfig());
- LogService.log("-----mBitmap", "mBitmap= " + mBitmap.getConfig());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- LogService.log("PaintActivity", "Bitmap = " + mBitmap);
- bitmapgol = Bitmap.createBitmap(width, height, targetConfig);// creaza bitmap gol
- imageviewPaint.setImageBitmap(bitmap);// se pune pe ImageView imaginea de background
- myView.setBitmap(bitmapgol, targetConfig); // se pune bitmapu gol pe View-ul meu (CustomImage)
- paint.bringToFront();
- paintLayout.bringChildToFront(paint);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- mPaint = new Paint();
- mPaint.setAntiAlias(true);
- mPaint.setDither(true);
- mPaint.setColor(0xFF000000);
- mPaint.setStyle(Paint.Style.STROKE);
- mPaint.setStrokeJoin(Paint.Join.ROUND);
- mPaint.setStrokeCap(Paint.Cap.ROUND);
- mPaint.setStrokeWidth(50);
- myView.setPaint(mPaint);
- }
- }, 50);
- The xml:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <RelativeLayout
- android:id="@+id/UpperTabPaint"
- android:layout_width="match_parent"
- android:layout_height="50dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:background="@color/flock_blue" >
- <ImageButton
- android:id="@+id/backDrawBtn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginLeft="10dp"
- android:layout_marginTop="15dp"
- android:background="#0000"
- android:src="@drawable/backdraw" />
- <ImageButton
- android:id="@+id/chooser2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:layout_marginRight="20dp"
- android:layout_marginTop="10dp"
- android:background="#0000"
- android:src="@drawable/chooser" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/OptionsTab"
- android:layout_width="match_parent"
- android:layout_height="50dp"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:background="@color/flock_blue" >
- <TextView
- android:id="@+id/drtools"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_centerVertical="true"
- android:text="@string/drawtool"
- android:textColor="@color/white"
- android:textSize="20dp" />
- <ImageButton
- android:id="@+id/textBtn"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentBottom="true"
- android:layout_toRightOf="@+id/drtools"
- android:background="#0000"
- android:src="@drawable/text" />
- <ImageButton
- android:id="@+id/penBtn"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentBottom="true"
- android:layout_toRightOf="@+id/textBtn"
- android:background="#0000"
- android:src="@drawable/pen" />
- <ImageButton
- android:id="@+id/objBtn"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentTop="true"
- android:layout_marginBottom="1dp"
- android:layout_toRightOf="@+id/penBtn"
- android:background="#0000"
- android:src="@drawable/obj" />
- <ImageButton
- android:id="@+id/eraseBtn"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentTop="true"
- android:layout_toRightOf="@+id/objBtn"
- android:background="#0000"
- android:src="@drawable/erase" />
- <Button
- android:id="@+id/cancelBtn"
- android:layout_width="45dp"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:background="@drawable/button_selector"
- android:text="@string/cancel" />
- <Button
- android:id="@+id/saveBtn"
- android:layout_width="45dp"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@+id/cancelBtn"
- android:background="@drawable/button_selector"
- android:text="@string/save" />
- <Button
- android:id="@+id/sendBtn"
- android:layout_width="45dp"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentTop="true"
- android:layout_toLeftOf="@+id/saveBtn"
- android:background="@drawable/button_selector"
- android:text="@string/send" />
- <SeekBar
- android:id="@+id/brushsizeBar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_toLeftOf="@id/sendBtn"
- android:layout_toRightOf="@+id/brushsizeTV" />
- <ImageButton
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_alignParentBottom="true"
- android:layout_toRightOf="@+id/eraseBtn"
- android:background="#0000"
- android:src="@drawable/colorpicker" />
- <TextView
- android:id="@+id/brushsizeTV"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_toRightOf="@+id/button1"
- android:text="@string/brsize"
- android:textColor="@color/white"
- android:textSize="20dp" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/paintLayout"
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_above="@+id/OptionsTab"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:layout_below="@+id/UpperTabPaint"
- android:layout_centerHorizontal="true"
- android:background="@color/digg_blue" >
- <ImageView
- android:id="@+id/imageViewPaint"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:src="@drawable/loading" />
- <RelativeLayout
- android:id="@+id/paint"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_above="@+id/OptionsTab"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:layout_below="@+id/UpperTabPaint"
- android:layout_centerHorizontal="true" >
- </RelativeLayout>
- </RelativeLayout>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement