Android Question Wrapped Library Inheritance

Discussion in 'Android Questions' started by jotaele, Jun 11, 2015.

  1. jotaele

    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.

    Code:
    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.
     
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    He will have to expose each method individually.
    The source is requieed to inherit the docs/comments.
     
    Peter Simpson and NJDude like this.
  3. jotaele

    jotaele Member Licensed User

    Thanks a lot.

    I hope he understands that you said.
     
  4. DonManfred

    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.
     
  5. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Yes, but given that the library itself extends EditText, are all the methods of the EditText exposed?
    You can get the cursor positions using EditText.getSelectionStart() and EditText.getSelectionEnd().
     
    NJDude likes this.
  6. DonManfred

    DonManfred Expert Licensed User

    No, they are not available in the library if i remember correctly. And i tried to use it using the ViewWrapper<moijiedittext> but the methods does not appear.
     
  7. thedesolatesoul

    thedesolatesoul 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()
     
    NJDude likes this.
  8. DonManfred

    DonManfred Expert Licensed User

    i have expected the same. But it was marked red from ecplise
     
  9. DonManfred

    DonManfred Expert Licensed User

    maybe is IS in the lib but set to private... I only wrapped public methods... Will check later.
     
  10. jotaele

    jotaele Member Licensed User

    You are amazing. Both of you.

    Thanks a lot.
     
  11. warwound

    warwound Expert Licensed User

    Have you tried extending the EditTextWrapper class?
     
  12. thedesolatesoul

    thedesolatesoul Expert Licensed User

    He cant. Its not generic like TextViewWrapper.
     
    Last edited: Jun 11, 2015
    Peter Simpson and NJDude like this.
  13. DonManfred

    DonManfred Expert Licensed User

    No, there are no such methods. I dont know what i should wrap then... :-/
     
  14. jotaele

    jotaele Member Licensed User

    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?

    Code:
    @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: Jun 13, 2015
  15. warwound

    warwound Expert Licensed User

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

    Code:
    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.
     
  16. warwound

    warwound Expert Licensed User

    Actually has anyone tried simply assigning an EmojiEditText to an EditText in b4a:

    Code:
    Dim EditText1 As EditText=EmojiEditText1
     
    KZero, jotaele and DonManfred like this.
  17. DonManfred

    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.
    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...

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

    DonManfred Expert 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
     

    Attached Files:

    Last edited: Jun 14, 2015
    inakigarm and Peter Simpson like this.
  19. LucaMs

    LucaMs Expert Licensed User


    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]
     
  20. jotaele

    jotaele Member Licensed User

    Yes, I tried and now it's working perfect. :)

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

    Code:
    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: Jun 14, 2015
Loading...