Android Question Wrapped Library Inheritance

jotaele

Member
Licensed User
Hi:

@DonManfred wrapped a library to use emojicons in a EditText.

http://www.b4x.com/android/forum/threads/msemoji-v1-0-0.53787/#content

I go to the github project of the original library and I saw than EmojiEditText inherids the object EditText, but in the wrapped library, the methods of the original library are missing.

B4X:
public class EmojiEditText extends EditText {
   private static final String TAG = EmojiEditText.class.getName();
   private static final String START_CHAR = "[";
   ...
I was reading in another forum, that "he" must add EditText source code for support this methods (and wrap the needed, I supose), but I never wrap a library (but I try a lot of times to do it).

Can anyone tell how we can access to the methods of the EditText object.

I wan't disturb @DonManfred, but its a good info because he is wrapping a lots of libs.

Thanks a lot.
 

DonManfred

Expert
Licensed User
I have exposed ALL public methods of the library in my wrapper.
In the original lib (as you can see) is NO method to get or set the actual cursorposition. So there is nothing i can wrap.

I can show the source-code and you will see that i wrapped all public methods of the library.

But i will check my wrapper if i accidently forgot one or more methods.
 

jotaele

Member
Licensed User
No, there are no such methods. I dont know what i should wrap then... :-/
Ohhhh. :(

I think than only a guru can help. ;)

Sorry, but I don't know how to help you to expose this methods. I am not a Java programmer and I think that only one with knowlegment of Java can help.

---EDIT

Sorry if this is a foolishness :oops:

¿Is it posible that @thedesolatesoul saids that "expose" the methods is something like this? (It´s an example)

And the same for the events?

B4X:
  @Override
  public void setText(CharSequence text, BufferType type) {
     super.setText(text, BufferType.EDITABLE);
  }

  @Override
  public void setSelection(int start, int stop) {
     super.setSelection(start, stop);
  }

  @Override
  public void selectAll() {
     super.selectAll();
  }

...
---END EDIT

I am tried to use custom fonts and another solutions, but no one works for me.

Customs fonts like "emojis font" didn't work, showing a square in the place of the icon. Normal EditText did'n allow to use this icons. I'm surprised.

Thanks anyway for your efforts. I will be trying more options.
 
Last edited:

warwound

Expert
Licensed User
An idea would be to have a getter method that returns the EmojiEditText cast to an EditText:

B4X:
public EditTextWrapper GetEditText(){
    EditTextWrapper wrapper=new EditTextWrapper();
    wrapper.setObject((EditText) getObject());
    return wrapper;
}
It might not even be required to cast the EmojiEditText to an EditText.

Now the user can get the EditText and use the EditText properties and methods they desire.
 

DonManfred

Expert
Licensed User
It is not in the wrapped library. I mean a selectionstart and end. But i was able to do such methods inside my wrrapper and it seems to work.
Actually has anyone tried simply assigning an EmojiEditText to an EditText in b4a
this brought me to the idea to just write such methods even if the wrapped library does not expose them. Thank you @warwound

@jotaele Can you please try this version of the wrapper attached here (v1.0.1)?
Edit: Please try V1.0.2 from the next post...

B4X:
    Private t As Timer
B4X:
    t.Initialize("timer",250)
B4X:
Sub timer_Tick
    'Dim edt As EditText = edtEmoji
    Log(edtEmoji.SelectionStart&"/"&edtEmoji.SelectionEnd)
    'Log(edt.SelectionStart)
End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Interesting.
If using ViewWrapper<moijiedittext) and if moijiedtitext is extended the EditText then i would excpect it would certainly appear in:
getObject().getSelectionStart()
I must revise my statement. It seems that i did not tried it. Dont know what i tried and get errors in eclipse.
But as you see in my previous post i tried it again and i could do such methods...

V1.0.2 also have a SetSelection
 

Attachments

Last edited:

LucaMs

Expert
Licensed User
An idea would be to have a getter method that returns the EmojiEditText cast to an EditText:

B4X:
public EditTextWrapper GetEditText(){
    EditTextWrapper wrapper=new EditTextWrapper();
    wrapper.setObject((EditText) getObject());
    return wrapper;
}
It might not even be required to cast the EmojiEditText to an EditText.

Now the user can get the EditText and use the EditText properties and methods they desire.

I think this is always the best way.

Trying to extend the features of a view (using only B4A), I avoided replicate every method / properties of the basic view (too much stuff!), I have exposed the view in this way.

Of course, I'm not talking about Java. I will devote a whole week to Java, so I may offer many wrapper libraries for free - especially those offered for a fee by DonManfred.
[This is not true and this is NOT a provocation, I'm just kidding :D]
 

jotaele

Member
Licensed User
I must revise my statement. It seems that i did not tried it. Dont know what i tried and get errors in eclipse.
But as you see in my previous post i tried it again and i could do such methods...

V1.0.2 also have a SetSelection
Yes, I tried and now it's working perfect. :)

I can put the icon in the right place now with this code:

B4X:
Dim Start As Int = EmojiEditText1.SelectionStart

EmojiEditText1.Text = EmojiEditText1.Text.SubString2(0, Start) _
        & List1.Get(BotonTransparente.Tag) & " " _
        & EmojiEditText1.Text.SubString(Start)

EmojiEditText1.setSelection2(Start + 1, Start + 1)
I have to do a trick for delete icons (with LastIndexof2, that now appears), but I think that with the text methods will be easy.

I have seen that now a lot of methods (including inheritance EditText) has been exposed.

Well work. I will to upload the new code of the "keyboard" when I have debugged it.

The event's is not working. I think that you supposed that. We can do a workarrond for this.

Thanks to all of you for your ideas. You are a awesome.
 
Last edited:
Top