Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04d50204 authored by satok's avatar satok
Browse files

Show Subtype Icon properly in the system status bar

- Added API for getting the current subtype
- Added functions for show/hide status icon

Change-Id: Ifcaad00f7f4c658cdb3af367387476bbf316eb19
parent 267e9168
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -218267,6 +218267,17 @@
<parameter name="completions" type="android.view.inputmethod.CompletionInfo[]">
</parameter>
</method>
<method name="getCurrentInputMethodSubtype"
 return="android.view.inputmethod.InputMethodSubtype"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getEnabledInputMethodList"
 return="java.util.List&lt;android.view.inputmethod.InputMethodInfo&gt;"
 abstract="false"
+12 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewRoot;
import android.view.inputmethod.InputMethodSubtype;

import com.android.internal.os.HandlerCaller;
import com.android.internal.view.IInputConnectionWrapper;
@@ -1411,6 +1412,17 @@ public final class InputMethodManager {
        }
    }

    public InputMethodSubtype getCurrentInputMethodSubtype() {
        synchronized (mH) {
            try {
                return mService.getCurrentInputMethodSubtype();
            } catch (RemoteException e) {
                Log.w(TAG, "IME died: " + mCurId, e);
                return null;
            }
        }
    }

    void doDump(FileDescriptor fd, PrintWriter fout, String[] args) {
        final Printer p = new PrintWriterPrinter(fout);
        p.println("Input method client state for " + this + ":");
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.view;

import android.os.ResultReceiver;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.inputmethod.EditorInfo;
import com.android.internal.view.InputBindResult;
import com.android.internal.view.IInputContext;
@@ -54,6 +55,7 @@ interface IInputMethodManager {
    void hideMySoftInput(in IBinder token, int flags);
    void showMySoftInput(in IBinder token, int flags);
    void updateStatusIcon(in IBinder token, String packageName, int iconId);
    InputMethodSubtype getCurrentInputMethodSubtype();
    
    boolean setInputMethodEnabled(String id, boolean enabled);
}
+93 −5
Original line number Diff line number Diff line
@@ -17,25 +17,38 @@
package com.android.systemui.statusbar.tablet;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.view.View;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.view.View;
import android.widget.ImageView;

import com.android.server.InputMethodManagerService;
import com.android.systemui.R;

import java.util.List;

public class InputMethodButton extends ImageView {

    private static final String  TAG = "StatusBar/InputMethodButton";

    private boolean mKeyboardShown;
    private ImageView mIcon;
    // other services we wish to talk to
    InputMethodManager mImm;
    private InputMethodManager mImm;

    public InputMethodButton(Context context, AttributeSet attrs) {
        super(context, attrs);

        mKeyboardShown = false;
        // IME hookup
        mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        
        // TODO: read the current icon & visibility state directly from the service

        // TODO: register for notifications about changes to visibility & subtype from service
@@ -47,5 +60,80 @@ public class InputMethodButton extends ImageView {
            }
        });
    }

    protected void onAttachedToWindow() {
        mIcon = (ImageView) findViewById(R.id.imeButton);
        refreshStatusIcon(mKeyboardShown);
    }

    private InputMethodInfo getCurrentInputMethodInfo() {
        String curInputMethodId = Settings.Secure.getString(getContext()
                .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
        List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
        if (curInputMethodId != null) {
            for (InputMethodInfo imi: imis) {
                if (imi.getId().equals(curInputMethodId)) {
                    return imi;
                }
            }
        }
        return null;
    }

    private Drawable getCurrentSubtypeIcon() {
        final PackageManager pm = getContext().getPackageManager();
        InputMethodInfo imi = getCurrentInputMethodInfo();
        InputMethodSubtype subtype = mImm.getCurrentInputMethodSubtype();
        Drawable icon = null;
        if (imi != null) {
            if (subtype != null) {
                return pm.getDrawable(imi.getPackageName(), subtype.getIconResId(),
                        imi.getServiceInfo().applicationInfo);
            } else if (imi.getSubtypes().size() > 0) {
                return pm.getDrawable(imi.getPackageName(),
                        imi.getSubtypes().get(0).getIconResId(),
                        imi.getServiceInfo().applicationInfo);
            } else {
                try {
                    return pm.getApplicationInfo(imi.getPackageName(), 0).loadIcon(pm);
                } catch (PackageManager.NameNotFoundException e) {
                    Log.w(TAG, "Current IME cann't be found: " + imi.getPackageName());
                }
            }
        }
        return null;
    }

    private void refreshStatusIcon(boolean keyboardShown) {
        if (!keyboardShown) {
            setVisibility(View.INVISIBLE);
            return;
        } else {
            setVisibility(View.VISIBLE);
        }
        Drawable icon = getCurrentSubtypeIcon();
        if (icon == null) {
            mIcon.setImageResource(R.drawable.ic_sysbar_ime_default);
        } else {
            mIcon.setImageDrawable(icon);
        }
    }

    private void postRefreshStatusIcon() {
        getHandler().post(new Runnable() {
            public void run() {
                refreshStatusIcon(mKeyboardShown);
            }
        });
    }

    public void showSoftInput() {
        mKeyboardShown = true;
        postRefreshStatusIcon();
    }

    public void hideSoftInput() {
        mKeyboardShown = false;
        postRefreshStatusIcon();
    }
}