zoukankan      html  css  js  c++  java
  • Android日语输入法Simeji使用示例

    MainActivity如下:

    package cn.testsimeji;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.app.Activity;
    import android.content.Intent;
    /**
     * Demo描述:
     * simeji使用示例
     * 
     * 注意事项:
     * 1 在配置文件中添加
     *   <action android:name="com.adamrocker.android.simeji.ACTION_INTERCEPT" />
     *   <category android:name="com.adamrocker.android.simeji.REPLACE" />
     *   <category android:name="android.intent.category.DEFAULT" />
     * 2 此处的REPLACE_KEY的设值.不可随意更改.
     * 
     * 官方文档:
     * http://simeji.me/blog/make_mushroom
     */
    public class MainActivity extends Activity {
    	private static final String ACTION_INTERCEPT = "com.adamrocker.android.simeji.ACTION_INTERCEPT";
    	private static final String REPLACE_KEY = "replace_key";
    	private Button mButton;
    	private String rawContent;
    	private String newContent;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
    		init();
    		
    	}
    
    	private void init() {
    		mButton = (Button) findViewById(R.id.button);
    		mButton.setOnClickListener(new OnClickListenerImpl());
    
    		Intent intent = this.getIntent();
    		String action = intent.getAction();
    		if (action != null && ACTION_INTERCEPT.equals(action)) {
                 System.out.println("开始调用文字替换");
                 rawContent=intent.getStringExtra(REPLACE_KEY);
                 System.out.println("rawContent="+rawContent);
    		} else {
    			 System.out.println("没有调用到文字替换");
    		}
    
    	}
    
    	private class OnClickListenerImpl implements OnClickListener {
    		@Override
    		public void onClick(View v) {
    			Intent data = new Intent();
    			newContent="hello everybody";
    			data.putExtra(REPLACE_KEY, newContent);
    			setResult(RESULT_OK, data);
    			finish();
    		}
    
    	}
    
    }
    


     

    main.xml如下:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="replace text" 
            android:layout_centerInParent="true"
            />
    
    </RelativeLayout>


    AndroidManifest.xml如下:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="cn.testsimeji"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="8" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="cn.testsimeji.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                    
                    <action android:name="com.adamrocker.android.simeji.ACTION_INTERCEPT" />
    				<category android:name="com.adamrocker.android.simeji.REPLACE" />
    				<category android:name="android.intent.category.DEFAULT" />
    				
                </intent-filter>
            </activity>
            
            
          
            
        </application>
    
    </manifest>


     

  • 相关阅读:
    极光推送消息——Alias别称方式(Andirod)
    引用极光jar包之后出现控制台日志打印不出来的问题。解决!
    极光推送消息——RegistrationID方式
    Educational Codeforces Round 79 D
    解决报错:ERROR 1005 (HY000): Can't create table 'market.orders' (errno: 150)
    ansible笔记(13):变量(二)
    ansible笔记(12):变量(一)
    zabbix4.2配置邮件+脚本报警:以QQ邮箱为例
    解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.
    ansible笔记(11):tags的用法
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3167674.html
Copyright © 2011-2022 走看看