Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rejusting UI with candidateview visible in custom keyboard

I'm working on custome keyboard .I have set setCandidatesViewShown(true) function in onCreateCandidatesView() , problem is the UI doesnt get readjusted properly.

Any assistance would be greatful.. below is what I have done

@Override 
public View onCreateCandidatesView() {      

    LayoutInflater li = (LayoutInflater) getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View wordBar = li.inflate(R.layout.wordbar, null);
    LinearLayout ll = (LinearLayout) wordBar.findViewById(R.id.words);
    Button voiceCmd = (Button) wordBar.findViewById(R.id.voiceword);
    LinearLayout ll1 = null;
    Button voiceCmd1 = null;
    //comment this block in the event of showing only one keyboard so that we can only
    //one autocorrect bar
    if (isLargeScreen) {
        ll1 = (LinearLayout) wordBar.findViewById(R.id.words1);
        voiceCmd1 = (Button) wordBar.findViewById(R.id.voiceword1);
    }

    voiceCmd.setOnClickListener(voiceClickListener);

    mCandidateView = new CandidateView(this);
    mCandidateView.setService(this);
    setCandidatesViewShown(true);
    mCandidateView.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    ll.addView(mCandidateView);             

    return wordBar;

}
like image 341
voidRy Avatar asked Aug 07 '12 06:08

voidRy


1 Answers

I had the same problem. I found the answer on the post by Ced here.

The solution is to add this to your input method service,

@Override public void onComputeInsets(InputMethodService.Insets outInsets) {
    super.onComputeInsets(outInsets);
    if (!isFullscreenMode()) {
        outInsets.contentTopInsets = outInsets.visibleTopInsets;
    }
}

It is intentional that the candidate view does not push the application upwards. From the doc,

Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus.

The hack above increases the "content" area to include the candidate view area. The doc for onComputeInsets will help you understand the concept.

Compute the interesting insets into your UI. The default implementation uses the top of the candidates frame for the visible insets, and the top of the input frame for the content insets.

like image 180
tilish Avatar answered Sep 28 '22 10:09

tilish