Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't access stickers at position which is saved like rotated,resized #14

Open
adirohilla22 opened this issue Oct 21, 2016 · 26 comments
Open

Comments

@adirohilla22
Copy link

i am saving that stickers page so that i can also retrieve it later and can edit elements to existing one on page like i have saved some rotated stickers on a page but now i want to edit that page like want to change position of that rotated image or can add some more image but problem is that when i open old saved page that is having stickers it is giving me in middle and in proper default form ,not in form i edited in past
1476860268168
screenshot_20161019-122654

@pravindodia
Copy link

You need to save the matrix and save that and while resuming back you have to redraw them so they are on the last saved location

@ashishsakarkar2020
Copy link

did you find a solution for this?

@pravindodia
Copy link

Yes I have saved the StickerView Matrix, Bitmap as uri, and from matrix i can retrieve the coordinates and re position again on resume or on new activity wherever i want.

@Ram8948
Copy link

Ram8948 commented Feb 17, 2017

@pravindodia how to save matrix?

@pravindodia
Copy link

pravindodia commented Feb 18, 2017

when you save the object to get the matrix from the Sticker view like StickerView.getmatrix().getvalues.

If you need a sample code, just let me know.

@Ram8948
Copy link

Ram8948 commented Feb 18, 2017

i have saved StickerPropertyModel . and use code like that: --

public void setBitmap(Bitmap bitmap, StickerPropertyModel model)
{
matrix.reset();
this.mBitmap = bitmap;
setDiagonalLength();
initBitmaps();
int w = mBitmap.getWidth();
int h = mBitmap.getHeight();
System.out.println("...width....."+w+" ---Height--"+h);
oringinWidth = w;
float scale = model.getScaling() * mScreenwidth / mBitmap.getWidth();
if (scale > MAX_SCALE) {
scale = MAX_SCALE;
} else if (scale < MIN_SCALE) {
scale = MIN_SCALE;
}
float degree = (float) Math.toDegrees(model.getDegree());
matrix.postRotate(-degree, w >> 1, h >> 1);
matrix.postScale(scale, scale, w >> 1, h >> 1);
float midX = model.getxLocation() * mScreenwidth;
float midY = model.getyLocation() * mScreenwidth;
System.out.println("..1...midX...."+midX+" midY "+midY);
midX = midX - (w * scale) / 2-model.getOffsetX();
midY = midY - (h * scale) / 2-model.getOffsetY();
matrix.setTranslate(-w/2f, -h/2f);
matrix.postRotate(-degree, w >> 1, h >> 1);
matrix.postTranslate(midX,midY);
matrix.postScale(scale, scale, w >> 1, h >> 1);
invalidate();
}

but my problem is unable to set saved bitmap to saved matrix position .
please help me on
matrix.postRotate
matrix.postScale
matrix.postTranslate

@pravindodia
Copy link

pravindodia commented Feb 19, 2017

@Ram8948
Please check the sample code below

To Save the Parameters needed. for which i modified the StickerView

 
          for (View item : mViews) {
                   
                    ViewStateModel viewStateModel = new ViewStateModel();
                    viewStateModel.setmValues(getMatrixValues(((StickerView) item).getMatrix()));
                    viewStateModel.setViewStateId(((StickerView) item).getStickerId());
                    viewStateModel.setSaved(true);
                    viewStateModel.setStartTime(((StickerView) item).getShowPosition());
                    viewStateModel.setStopTime(((StickerView) item).getHidePosition());
                    viewStateModel.setSticker(((StickerView) item).getStickerRes());
                    mViewState.add(viewStateModel);
                }

Now to restore it back you can do this.

for (ViewStateModel item :
                    mViewList) {
                final StickerView stickerView = new StickerView(this);
                if (item.isSaved()) {
                    stickerView.getMatrix().setValues(item.getmValues());
                    stickerView.setId((int) item.getViewStateId());
                    stickerView.setSaved(item.isSaved());
                    stickerView.setImageResource(item.getSticker());
                }
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                lp.height = (int) newVideoHeight;
                lp.width = (int) newVideoWidth;
                lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                canvasview.addView(stickerView, lp); //canvasview is contentrootview to which we are going to add the stickers.
                mViews.add(stickerView);
                stickerView.setInEdit(false);
                stickerView.setLockMode(true);
            }

You might have to modify the stickerview to set and get the values you want.

let me know if you want to know what is the model i have used.

Hope you understand and help you to understand your requirement.

Thanks

@dark1991
Copy link

Could you explans how to use calculate in StickerView method to get this infor?

@Ram8948
Copy link

Ram8948 commented Feb 20, 2018

i have saved scaling ,translation ,rotation position from calculate method. now how to restore it back

@pravindodia
Copy link

@Ram8948
Please refer to the code above or share your code to help you with your query.

@Ram8948
Copy link

Ram8948 commented Feb 20, 2018

i want to save matrix data for long time ,but in future if matrix reference is lost than what i can do?
i am using calculate method to save scaling, rotation, translation data

@pravindodia
Copy link

@Ram8948

  1. How would the Matrix get lost if you have saved it properly ?
  2. The code to save Matrix data is given above, if you need help to understand then ask your specific question as your question is more general and already been answered above.
  3. if you need specific help for your project please share your snippet and I can try to help you.

Please be a bit brief for some response from other people who want to help. short and general questions are difficult to answer.

@Kaunain26
Copy link

@pravindodia can we add these stickers in scrollview?

@pravindodia
Copy link

@pravindodia can we add these stickers in scrollview?

@Kaunain26 you can but it will not not editable in scollview, or even if you make it editable it will not be a good User Experience.

@Kaunain26
Copy link

@pravindodia can we add these stickers in scrollview?

@Kaunain26 you can but it will not not editable in scollview, or even if you make it editable it will not be a good User Experience.

Actually my requirement is a scroll view. I am creating a notes app in which users can add stickers in it. So if the user scrolls the view then I don't think sticker could go down.

@pravindodia
Copy link

@pravindodia can we add these stickers in scrollview?

@Kaunain26 you can but it will not not editable in scollview, or even if you make it editable it will not be a good User Experience.

Actually my requirement is a scroll view. I am creating a notes app in which users can add stickers in it. So if the user scrolls the view then I don't think sticker could go down.

@Kaunain26 it can but you have to handle that in parent view and use a separate view for create/edit stickerview and then insert the sticker in parent view with scroll and it will work.

@Kaunain26
Copy link

Kaunain26 commented May 7, 2024

@pravindodia can we add these stickers in scrollview?

@Kaunain26 you can but it will not not editable in scollview, or even if you make it editable it will not be a good User Experience.

Actually my requirement is a scroll view. I am creating a notes app in which users can add stickers in it. So if the user scrolls the view then I don't think sticker could go down.

@Kaunain26 it can but you have to handle that in parent view and use a separate view for create/edit stickerview and then insert the sticker in parent view with scroll and it will work.

                    `
  <?xml version="1.0" encoding="utf-8"?>
        <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
         xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">


<RelativeLayout
    android:id="@+id/rl_content_root"
    android:layout_width="match_parent"
    android:layout_height="2000dp">


</RelativeLayout>

          </androidx.core.widget.NestedScrollView>

`

I tried to modify it like this , i made parent scrollView and added relativeLayout in that parent . But in this way sticker is not getting added. can u help?

@Kaunain26
Copy link

Kaunain26 commented May 7, 2024

@pravindodia

                     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_content_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">


<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="2000dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_background"/>

</androidx.core.widget.NestedScrollView>

</RelativeLayout>

this modified XML is working fine.

I just did opposite of the above give code of mine

Is this correct... in this way stickers are coming on the view.

@pravindodia
Copy link

This is the wrong approach, what I am saying is your sticker will be in scroll view and if you want to edit the sticker then there should be different view which is sticker view
The way you have planned will not work

@Kaunain26
Copy link

This is the wrong approach, what I am saying is your sticker will be in scroll view and if you want to edit the sticker then there should be different view which is sticker view The way you have planned will not work

sorry but i am not getting it. Can you plz give me a code example if you are free.

@pravindodia
Copy link

Sorry For what I am telling I cannot give you a sample code
but I can try to explain here for example

As you said you are creating a notes app
So there are 2 view

  1. note view
  2. note edit view

so not both can have scroll view in it.

Main View (Any Layout you want)
Then Scroll view or main layout can be scroll view
Then your Notes including sticker view(Not editable its like an image(sticker))

When you want to edit the sticker view from not edit view,
Move to different Activity and Edit sticker view layouts do your work and return when done.

That's it.
I am not sure If I made my self clear, but I cannot be more clear than this. Sorry.

@Kaunain26
Copy link

Kaunain26 commented May 7, 2024

@pravindodia Thank you so much for your quick replies, whatever you are saying i understood and I achieved 50% of my requirement. But the problem is Sticker view is not able to move properly in Scrollview. It started colliding the view , I mean started scrolling both at the same time when trying to move the sticker.

So what i am thinking is it possible to add a one more sticker view which will be outside of this parent nestedScrollview ( this parent nestedScrollView already contains the stickerView.) So user interaction will be with the sticker view which is outside the parent nestedScrollview and when user will move or edit the sticker then same time it update the other sticker view which is inside the parent nestedScrollView.

This idea i got from your above comment only. It's little bit different. I don't know it is possible or not.

@Kaunain26
Copy link

@Ram8948 Please check the sample code below

To Save the Parameters needed. for which i modified the StickerView

      for (View item : mViews) {
               
                ViewStateModel viewStateModel = new ViewStateModel();
                viewStateModel.setmValues(getMatrixValues(((StickerView) item).getMatrix()));
                viewStateModel.setViewStateId(((StickerView) item).getStickerId());
                viewStateModel.setSaved(true);
                viewStateModel.setStartTime(((StickerView) item).getShowPosition());
                viewStateModel.setStopTime(((StickerView) item).getHidePosition());
                viewStateModel.setSticker(((StickerView) item).getStickerRes());
                mViewState.add(viewStateModel);
            }

Now to restore it back you can do this.

for (ViewStateModel item :
mViewList) {
final StickerView stickerView = new StickerView(this);
if (item.isSaved()) {
stickerView.getMatrix().setValues(item.getmValues());
stickerView.setId((int) item.getViewStateId());
stickerView.setSaved(item.isSaved());
stickerView.setImageResource(item.getSticker());
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
lp.height = (int) newVideoHeight;
lp.width = (int) newVideoWidth;
lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
canvasview.addView(stickerView, lp); //canvasview is contentrootview to which we are going to add the stickers.
mViews.add(stickerView);
stickerView.setInEdit(false);
stickerView.setLockMode(true);
}
You might have to modify the stickerview to set and get the values you want.

let me know if you want to know what is the model i have used.

Hope you understand and help you to understand your requirement.

Thanks

hey @pravindodia can you provide the code, that you modified in StickerView to get the values and what model you used.

@pravindodia
Copy link

@Kaunain26 sorry but I did this project 8 years ago and so I don't have the code.

@Kaunain26
Copy link

Kaunain26 commented May 8, 2024

(getMatrixValues(((StickerView) item).getMatrix()))

(getMatrixValues(((StickerView) item).getMatrix())) can you explain this plz. How you are getting the matrix value.

When i am trying to get this sticker.getMatrix() then everytime it's value is same.

@pravindodia
Copy link

(getMatrixValues(((StickerView) item).getMatrix()))

(getMatrixValues(((StickerView) item).getMatrix())) can you explain this plz. How you are getting the matrix value.

When i am trying to get this sticker.getMatrix() then everytime it's value is same.

StickerView item is modified to save and get matrix values , its parent class already has that methods which you can override. and you can get and set the values as you require.
The value is changed when its location is changed on StickerView
For example
you have a text and an image
both will have its own matrix value and it will same if they both are on the sample place, if the location is changed then the value changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants