How to edit stickerview text on long click Listener in android

2.2k views Asked by At

I am developing sticker app, where i can add text to Stickerview. I can flip, rotate and delete sticker Text. Now i want to edit the text of StickerView when i do long click on stickerText. Here is the code which add text sticker to screen.

    imgText.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {
            isEffectsVisible = isSttickerVisible = false;
            gridView.setVisibility(View.GONE);
            recycler_Effect.setVisibility(View.GONE);
            recyclerView.setVisibility(View.GONE);
            final Dialog dialog = new Dialog(MainActivity.this);
            // Include dialog.xml file

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(
                    new ColorDrawable(Color.TRANSPARENT));

            dialog.setContentView(R.layout.text_custom_dialog);
            dialog.setCancelable(false);
            // Set dialog title

              et_view = (EditText) dialog.findViewById(R.id.et_view);


            // et_view.setText("" + txtHidden.getText().toString().trim());
               dialog.setTitle("Text Appearance");
              dialog.show();
            mSpinner_text_style = (Spinner) dialog
                    .findViewById(R.id.spinner_text_style);
            mIbtn_color_text = (ImageButton) dialog
                    .findViewById(R.id.ibtn_color_text);

            TextAdapter adapter = new TextAdapter(MainActivity.this,
                    R.layout.spinner_row, style);
            mSpinner_text_style.setAdapter(adapter);

            mSpinner_text_style
                    .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0,
                                                   View arg1, int arg2, long arg3) {
                            // TODO Auto-generated method stub
                            photoEditorApplication.setPosition(arg2);
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });

            mIbtn_color_text.setBackgroundColor(photoEditorApplication.getColor());

            mIbtn_color_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    showColorPickerDialogDemo();

                }
            });


            Button declineButton = (Button) dialog
                    .findViewById(R.id.btn_cancel);
            // if decline button is clicked, close the custom dialog
            declineButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Close dialog
                    dialog.dismiss();
                }
            });

            Button Ok = (Button) dialog.findViewById(R.id.btn_ok);
            // if decline button is clicked, close the custom dialog
            Ok.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    // Close dialog
                    txtHidden = null;

                   txtHidden = new TextView(MainActivity.this);

                    final FrameLayout.LayoutParams params =
                            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                    FrameLayout.LayoutParams.WRAP_CONTENT);
                    txtHidden.setLayoutParams(params);
                    txtHidden.setTextColor(photoEditorApplication.getColor());
                    Typeface face = Typeface.createFromAsset(getAssets(),
                            style[photoEditorApplication.getPosition()]);

                    txtHidden.setTypeface(face);
                    txtHidden.setTextSize(60);

                    String s = et_view.getText().toString().trim();
                    Log.e("et text", s);
                    txtHidden.setText(" " + s + " ");


                    if (txtHidden.getText().toString().trim().length() == 0) {
                        Snackbar snackbar = Snackbar.make(mRootLayout, "Please Enter Text", Snackbar.LENGTH_LONG);
                        snackbar.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));
                        snackbar.show();
                    } else {


  //                            
              Toast.makeText(MainActivity.this,txtHidden.getText()+" 
          niravvvv",Toast.LENGTH_LONG).show();
                        txtHidden.setVisibility(View.INVISIBLE);
                        txtHidden.setDrawingCacheEnabled(false);
                        mainFrame.addView(txtHidden);


                        new CountDownTimer(1000, 1000) {
                            @Override
                            public void onTick(long millisUntilFinished) {

                            }

                            @Override
                            public void onFinish() {

                                txtHidden.setDrawingCacheEnabled(true);
                                txtHidden.buildDrawingCache();
                                sticker_view.setVisibility(View.VISIBLE);
                                sticker_view.setWaterMark(txtHidden.getDrawingCache(), null);

                                dialog.dismiss();
                            }
                        }.start();
                    }

                }
            });

            // ===========================================


        }
    });
2

There are 2 answers

1
Niraj Sanghani On

there are 2 click Listners check below

t1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Clicked", Toast.LENGTH_SHORT).show();
    }
});

t1.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show();
        return true;
    }
});
0
dileep krishnan On

in Stickerview class in onTouch() method long press case u have to call interface (which is in StickerView class) method , that interface u have to implment and override that methods in your Mainactivity