谷歌源码输入法修改版(支持拖动,放大缩小)

不想写太多麻烦,就贴一些关键代码。我的资源里有源码

http://download.csdn.net/detail/songqiang2011/9911435

1.在PinyinIME类

获取输入法的弹出窗,在onCreateInputView()修改输入法的位置和宽高。

public void setPinyinWindow(){
        if(pinyinWin == null){
            pinyinWin = super.getWindow().getWindow();
        }
        WindowManager.LayoutParams param = pinyinWin.getAttributes();
        //一定要修过类型,不然修过的参数无效
        param.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        param.width = mEnvironment.getScreenWidth();
        param.height = mEnvironment.getScreenHeight()-100;
        param.x = winX;
        param.y = winY;
        pinyinWin.setBackgroundDrawable(new ColorDrawable(Color.BLUE));
        pinyinWin.setAttributes(param);
    }

2.在 Environment 参数类里面修改宽高参数

private int mScreenWidth = 700; // 屏幕的宽度
private int mScreenHeight = 375; // 屏幕的高度

3.skb_qwerty.xml 添加一个move键,图标自己做

   <row  width="10.205%p">
    <key label="move" icon="@drawable/move_icon" icon_popup="@drawable/move_popup_icon" width="10.286%p" code="-10"/>
    <keys splitter="|" labels="A|S|D|F|G|H|J|K|L"
      codes="29|47|32|34|35|36|38|39|50"/>
  </row>

4. SkbContainer 软键盘类的触摸事件onTouchEvent()

把pinyinIME类set到skbcontainer类里面

public void setPinyinIME(PinyinIME pinyinIME){
        this.pinyinIME = pinyinIME;
    }

监听移动触摸事件

if( mSoftKeyDown!=null && mSoftKeyDown.getKeyCode() == -10){
            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                return movePinyinWin(event);
            }
        }

修改软键盘窗口的 坐标位置

public boolean movePinyinWin(MotionEvent e){
        WindowManager.LayoutParams param = pinyinIME.pinyinWin.getAttributes();
        int winX = param.x;
        int chax = (int)(e.getRawX()) - prex;
        int chay = prey - (int)(e.getRawY());
        if((chax>0 && winX+chax>1920/2) || (chax<0 && winX+chax<-1920/2)){
            return false;
        }
        if(prex != 0 || prey != 0){
            param.x += chax;
            param.y += chay;
            pinyinIME.setWinXY(param.x, param.y);
            pinyinIME.pinyinWin.setAttributes(param);
        }
        prex = (int)(e.getRawX());
        prey = (int)(e.getRawY());
        return true;
    }


猜你喜欢

转载自blog.csdn.net/songqiang2011/article/details/76150085
今日推荐