I've created a sample project that demonstrates the issue. I've tried to 
make it as simple as possible.

When executing the app, There will be a single instance of the compound 
component which includes two letters, one over the other. (A/Q) For clarity 
sake, the 'A' is Yellow and the 'Q' is gray. Long-press on the 'A' and you 
will bring up the soft keyboard. As you select letters from the soft 
keyboard, the letter 'A' should change. 

My continued thanks for those who are reviewing this.

Main Activity:

package com.test.zbionic;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;

public class ZBionicActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

View view;
view = new CompoundComponent(this, 'Q');
view.setId(10001);
RelativeLayout.LayoutParams layout;

layout = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);

view.setLayoutParams(layout);

RelativeLayout rl = (RelativeLayout) findViewById(R.id.layoutTest);
rl.addView(view);
}

public class CompoundComponent extends LinearLayout {

private TextView textview1;
private TextView textview2;

public CompoundComponent(Context context, char code) {
super(context);

buildComponent(context, code);

}

private void buildComponent(Context context, char code) {

// Set up the layout parameters
this.setOrientation(VERTICAL);
this.setPadding(1, 2, 1, 2);
this.setOnLongClickListener(mLongClickListener);

textview1 = new TextView(context);
textview1.setGravity(Gravity.CENTER_HORIZONTAL);
textview1.setTextSize(20);
textview1.setTextColor(Color.YELLOW);
textview1.setText("A");
addView(textview1, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

textview2 = new TextView(context);
textview2.setGravity(Gravity.CENTER_HORIZONTAL);
textview2.setTextSize(20);
addView(textview2, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

this.setFocusable(true);
this.setFocusableInTouchMode(true);
this.setMinimumWidth(15);
textview2.setText(Character.toString(code));
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

Log.d("Bionic Testing", "keyCode: " + Integer.toString(keyCode));

if (event.getAction() == KeyEvent.ACTION_DOWN) {

KeyCharacterMap kcm = null;
kcm = KeyCharacterMap.load(event.getDeviceId());

char c = kcm.getDisplayLabel(keyCode);

if (Character.isLetter(c)) {
textview1.setText(Character.toString(c).toUpperCase());
return true;
}
else {
return super.onKeyDown(keyCode, event);
}
}
else {
return super.onKeyDown(keyCode, event);
}
}

public View.OnLongClickListener mLongClickListener = new 
View.OnLongClickListener() {

@Override
public boolean onLongClick(View v) {

Log.d("Bionic Testing", "onLongClick");

softKeyboardResults rr = new softKeyboardResults(v.getContext());

Configuration config = CompoundComponent.this.getResources()
.getConfiguration();
if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES
|| config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_UNDEFINED) 
{
InputMethodManager imm = (InputMethodManager) v
.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(CompoundComponent.this,
InputMethodManager.SHOW_IMPLICIT, rr);
}
return false;
}

};

class softKeyboardResults extends ResultReceiver {

Context mContext;

public softKeyboardResults(Context context) {
super(getHandler());

Log.d("Bionic Testing", "Creating softKeyboardResults");
mContext = context;
}

@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);

Log.d("Bionic Testing", "resultCode: "
+ Integer.toString(resultCode));

switch (resultCode) {
case InputMethodManager.RESULT_HIDDEN:
case InputMethodManager.RESULT_SHOWN:
case InputMethodManager.RESULT_UNCHANGED_SHOWN:
break;
case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
InputMethodManager imm = (InputMethodManager) mContext
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(CompoundComponent.this,
InputMethodManager.SHOW_FORCED);
break;
default:
break;
}
}

}
}

}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android";
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout
android:id="@+id/layoutTest"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="5px"
android:background="#FF000000" />

</LinearLayout>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.test.zbionic"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="3" />

    <application android:icon="@drawable/icon" 
android:label="@string/app_name">
        <activity android:name=".ZBionicActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to