cancel
Showing results for 
Search instead for 
Did you mean: 

New class in MyStringAdapter.

former_member193863
Participant
0 Kudos

Hello experts, I try implement new class RfidTagReaderAPI in MyStringAdapter, but I dint know if I do it correct, after installing the application in devices with new class my application is crash, why?

/*

* MyStringEditAdapter.java

*/

package com.sap.mobile.platform.client.openui.extensions;

import android.content.Context;

import android.graphics.Color;

import android.view.Gravity;

import android.view.View;

import android.widget.EditText;

import com.getac.lib.rfidreader.RfidTagReaderAPI; //LR

import com.sap.mobile.platform.client.openui.adapters.StringEditAdapter;

import com.sap.mobile.platform.client.openui.models.StringEditModel;

import com.sap.mobile.platform.client.openui.utils.Helpers;

import com.sap.mobile.platform.core.openui.AutosizeBehavior;

public class MyStringEditAdapter extends StringEditAdapter

{

    /** Core model */

StringEditModel _model;

    /** App context */

    Context _context;

    /** Text view */

    EditText _textView;

    /** Allows auto height */

    boolean _autoHeight;

    /** Carriage return */

    boolean _carriageReturn;

    /** Word Wrapt */

    boolean _wordWrap;

  

    private EditText mTV;

    /*

     * (non-Javadoc)

     *

     * @see

     * com.sap.mobile.platform.client.openui.adapters.StringDisplayAdapter#initialize(com.sap.mobile.platform.client

     * .openui.models.StringDisplayModel, android.content.Context)

     */

@Override

    public void initialize(StringEditModel model, Context context)

    {

_model = model;

_context = context;

_carriageReturn = _model.isCarriageReturnAllowed();

_wordWrap = _model.isWordWrapAllowed();

_autoHeight = _model.isAutosizeSupported();

    }

    /*

     * (non-Javadoc)

     *

     * @see com.sap.mobile.platform.client.openui.adapters.FieldAdapter#getView()

     */

@Override

    public View getView()

    {

_textView = new EditText(_context);

_textView.setText(_model.getValue());

//_textView.setText("AS242ASD");//LR

_textView.setText(RfidTagReaderAPI.Read15693TagID());//LR

_textView.setTextColor(Color.RED); //LR

_textView.setGravity(Gravity.CENTER_VERTICAL);

if (!canHandleAutosizing())

{

_textView.setSingleLine();

}

_textView.setOnFocusChangeListener(new View.OnFocusChangeListener()

{

@Override

public void onFocusChange(View v, boolean hasFocus)

{

if (!hasFocus)

{

  _model.processInput(_textView.getText()+"AS242342".toString());//LR

}

}// end onFocuschange

});// end setOnFocusChangeListener

return _textView;

    }

    /**

     * Can we handle autosizing?

     *

     * @return if we can handle autosizing

     */

    public boolean canHandleAutosizing()

    {

if (_autoHeight && (_wordWrap || _carriageReturn))

{

return true;

}

return false;

    }

@Override

    public AutosizeBehavior getAutosizeBehavior()

    {

if (canHandleAutosizing())

{

return AutosizeBehavior.Autosize_FillVisible;

}

return AutosizeBehavior.Autosize_None;

    }

    public void valueChanged(String[] args)

    //public void valueChanged(String value) //LR

    {

String model = "AO837248927";//LR

_textView.setText(_model.getValue()+"");//LR

    }

@Override

    public boolean isAgentryDisplayingLabel()

    {

return true;

    }

@Override

    public int getContentHeightForAutosizing(int width)

    {

int height = Helpers.AutosizeUtils.heightForMultiLineText(_textView, width, _carriageReturn, _wordWrap);

return height;

    }

  

    public void onResume() {

        super.onResume();

        RfidTagReaderAPI.InitRFIDReader();

        RfidTagReaderAPI.Set14443ATagModel();

    }

    @Override

    public void onPause() {

        super.onPause();

        RfidTagReaderAPI.FinalRFIDReader();

    }

}

Tags edited by: Michael Appleby

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Lukas,

My suggestion would be to approach the Open UI control to be similar to that of the barcode scan field.  I would override the StringEditAdapter as you have done but for my field display both a text input area as well as a button.  The button would call the RFID reader read function and then populate the returned value into the text field which would pass back through to Agentry.

I would have also expected to see you call the RfidTagReaderAPI.InitRFIDReader(); methond as part of the initialize function to setup the connection to the RFID reader.  Then when the button on click is called you are ready to call RfidTagReaderAPI.Read15693TagID() to get the value from the RFID reader.

One thing you will need to deal with is what do you want to happen if the RFID reader gets a read on more than one tag at a time?

For the RFID readers that Agentry supports, if more than one tag is found they are simply concatenated together and returned as a long string value that we then parse in Agentry and act accordingly.

Hopefully this will help.

Good Luck!

--Bill

former_member193863
Participant
0 Kudos

Hi Bill, thank you for your respond. I write the simple application on android devices, and this works fine for me. But how I can implement this to MyStringEditAdapter?

package com.getac.app.rfidtest;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.TextView;

import com.getac.lib.rfidreader.RfidTagReaderAPI;

public class MainActivity extends Activity {

    private TextView mTV;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mTV = (TextView)findViewById(R.id.text1);

        findViewById(R.id.button1).setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mTV.setText(RfidTagReaderAPI.Read14443ATagID());

            }

        });

    }

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.activity_main, menu);

        return true;

    }

    @Override

    protected void onResume() {

        super.onResume();

        RfidTagReaderAPI.InitRFIDReader();

        RfidTagReaderAPI.Set14443ATagModel();

    }

    @Override

    protected void onPause() {

        super.onPause();

        RfidTagReaderAPI.FinalRFIDReader();

    }

}

former_member193863
Participant
0 Kudos

Hi Bill, you have any ideas?

BR

Lukas

former_member193863
Participant
0 Kudos

Hi, I want to make up post, about logs from logcat:

09-19 09:54:02.682: E/AndroidRuntime(29799): FATAL EXCEPTION: main

09-19 09:54:02.682: E/AndroidRuntime(29799): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.syclo.agentry.client.android/com.syclo.agentry.client.android.ui.screensets.WizardScreenSetActivity}: java.lang.NullPointerException: java.lang.NullPointerException

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.getac.lib.rfidreader.RfidTagReaderAPI.send_command(RfidTagReaderAPI.java:161)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.getac.lib.rfidreader.RfidTagReaderAPI.Read15693TagID(RfidTagReaderAPI.java:292)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.sap.mobile.platform.client.openui.extensions.MyStringEditAdapter.getView(MyStringEditAdapter.java:65)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.extension.ExtensionWidget.createContentView(ExtensionWidget.java:86)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.Widget.initialize(Widget.java:326)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.extension.ExtensionWidget.initialize(ExtensionWidget.java:73)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.screensets.widgets.WidgetInterop.initialize(WidgetInterop.java:63)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.ModelControllerInterop.onUIInitialized(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.ModelControllerInterop.onUIInitialized(ModelControllerInterop.java:67)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.AgentryActivityWithModelController.onPostCreate(AgentryActivityWithModelController.java:508)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1142)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2042)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.access$600(ActivityThread.java:130)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.os.Handler.dispatchMessage(Handler.java:99)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.os.Looper.loop(Looper.java:137)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.main(ActivityThread.java:4745)

09-19 09:54:02.682: E/AndroidRuntime(29799): at java.lang.reflect.Method.invokeNative(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): at java.lang.reflect.Method.invoke(Method.java:511)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

09-19 09:54:02.682: E/AndroidRuntime(29799): at dalvik.system.NativeStart.main(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.access$600(ActivityThread.java:130)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.os.Handler.dispatchMessage(Handler.java:99)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.os.Looper.loop(Looper.java:137)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.ActivityThread.main(ActivityThread.java:4745)

09-19 09:54:02.682: E/AndroidRuntime(29799): at java.lang.reflect.Method.invokeNative(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): at java.lang.reflect.Method.invoke(Method.java:511)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

09-19 09:54:02.682: E/AndroidRuntime(29799): at dalvik.system.NativeStart.main(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): Caused by: java.lang.NullPointerException: java.lang.NullPointerException

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.getac.lib.rfidreader.RfidTagReaderAPI.send_command(RfidTagReaderAPI.java:161)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.getac.lib.rfidreader.RfidTagReaderAPI.Read15693TagID(RfidTagReaderAPI.java:292)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.sap.mobile.platform.client.openui.extensions.MyStringEditAdapter.getView(MyStringEditAdapter.java:65)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.extension.ExtensionWidget.createContentView(ExtensionWidget.java:86)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.Widget.initialize(Widget.java:326)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.screensets.widgets.extension.ExtensionWidget.initialize(ExtensionWidget.java:73)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.screensets.widgets.WidgetInterop.initialize(WidgetInterop.java:63)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.ModelControllerInterop.onUIInitialized(Native Method)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.core.mvc.ModelControllerInterop.onUIInitialized(ModelControllerInterop.java:67)

09-19 09:54:02.682: E/AndroidRuntime(29799): at com.syclo.agentry.client.android.ui.AgentryActivityWithModelController.onPostCreate(AgentryActivityWithModelController.java:508)

09-19 09:54:02.682: E/AndroidRuntime(29799): at android.app.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Lukas,

I would start by basing my control on the sample MyStringEditAdapter file contained in the Sample project file.  Within that, you will have the basic framework for the OpenUI control. 

I would plugin your specific code to call the RFID methods in the initialize and methods and look to add the button (probably using a layout and inflating it) along with the appropriate method for the onclick to call the RFID read method.

Use the Eclipse/Android built in debugging tools to step through the code and see where you are running into problems.

--Bill

former_member193863
Participant
0 Kudos

Hi Bill, thank you, I try do this.

BR

Lukas

former_member193863
Participant
0 Kudos

Hi, solution was, extension initialize method of the RFID reader.

BR

Lukas

Answers (1)

Answers (1)

former_member193863
Participant
0 Kudos

Hello, any ideas?

BR

Lukas

agentry_src
Active Contributor
0 Kudos

Hi Lukas,

What kind of application are you working with?  Perhaps more details on your situation will get more responses.

Regards, Mike

SAP Customer Experience Group - CEG

former_member193863
Participant
0 Kudos

Hi Michael, I working with OpenUI, on GETAC devices, I try implement to Agentry application RFID reader, in one field. OS on this devices is Android 4.1

BR

Lukas

agentry_src
Active Contributor
0 Kudos

If one of the Agentry folks do not show up shortly, I will ping them to take a look at the issue you are facing.  I would recommend adding the tag 'agentry' to your posts on that topic in the future.  I have already done so for this Discussion, but if I could not figure out that it was related to Agentry, I suspect they did not either.  'openui' is another tag you should have used.

Cheers, Mike

former_member193863
Participant
0 Kudos

Hi, I will use tags. And thank you for the ping.

BR

Lukas