Java Question Need help with Samsung Galaxy Note SPen SDK

XverhelstX

Well-Known Member
Licensed User
Longtime User
Cannot instantiate the type ViewGroup

I tried to make a ViewGroup before with a constructor but i always had the same message above.

Tomas

Edit:
Should i use FrameLayout:
http://stackoverflow.com/questions/...w-to-declare-viewgroup-without-layout-xml-fil
B4X:
FrameLayout fl = new FrameLayout(fl.getContext);

Edit 2:

Now i'm trying this:

B4X:
 /**
     * Register the SettingView to the CanvasView.
     */
    public void RegisterSettingView2(PanelWrapper Panel, SettingView sv, boolean bClearAllVisibileInEraserSetting) {
       
       FrameLayout fl = new FrameLayout(ba.applicationContext.getApplicationContext());
        fl.setLayoutParams(new FrameLayout.LayoutParams (Panel.getObject().getWidth(), Panel.getObject().getHeight()));
        
        Panel.setObject(fl);
        getObject().setSettingView(Panel.getObject(), sv, bClearAllVisibileInEraserSetting);
        
    }

Note the (ba.applicationContext.getApplicationContext()); i wasn't able to use fl.getContext as it said
The local variable fl may not have been initialized

Findings:
B4X:
Sub mnuRegister_Click
   pnlCanvas.AddView(cv,0dip,0dip, 100%x, 100%y)
   
   cv.RegisterSettingView2(pnlPen, sv, True)
   'pnlPen.AddView(sv,0dip,0dip, 100%x, 100%y)
   sv.showView(1)

End Sub

Doesn't raise any errors.
'pnlPen.AddView(sv,0dip,0dip, 100%x, 100%y)

uncommenting this raises:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I also checked if fl.getparent() is null which it is also.

Here's the decompiled setSettingView from the jar:

B4X:
  public void setSettingView(ViewGroup paramViewGroup1, ViewGroup paramViewGroup2, boolean paramBoolean)
  {
    super.setSettingView((SettingView)paramViewGroup2);
    this.Q = null;
    this.R = null;
    this.N = paramViewGroup2;
    this.P = paramViewGroup1;
    if (this.P != null)
      this.P.addView(this.N);
    this.S = paramBoolean;
  }
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Try this:
3-3-2. Creating SettingView

To reflect a pen setting value that was changed through a SettingView onto an SCanvasView, you
must connect the SCanvasView to the SettingView. You can easily create a SettingView by using the
createSettingView() method of the SCanvasView as shown below.

B4X:
RelativeLayout settingViewContainer  
= (RelativeLayout) findViewById(R.id.canvas_container); 
boolean bClearAllVisibileInEraserSetting = true; 
 
mSCanvas.createSettingView( settingViewContainer,   
mSettingView,  
bClearAllVisibileInEraserSetting);

Is you canvas added to the activity? No sure how to get the id, may be Reflection could help.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey tds,

I don't know it anymore...
Always receiving a nullpointer after calling any other method.

These codes below don't give me an error, but when i call

B4X:
Sub mnuPen_Click
   cv.CanvasMode = Constants.SCANVAS_MODE_INPUT_TEXT
End Sub

Sub mnuHide_Click
   sv.showView(Constants.SCANVAS_SETTINGVIEW_PEN)
End Sub

i get a nullpointer.

B4X:
/**
     * Register the SettingView to the CanvasView.
     */
    public void RegisterSettingView2(PanelWrapper Panel, SettingView sv, boolean bClearAllVisibileInEraserSetting) {
        RelativeLayout fl = new RelativeLayout(ba.applicationContext.getApplicationContext());
        fl.setLayoutParams(new RelativeLayout.LayoutParams (Panel.getObject().getWidth(), Panel.getObject().getHeight()));
        
        Panel.setObject(fl);
        getObject().setSettingView(fl, sv, bClearAllVisibileInEraserSetting);
        
    }
    
    public void CreateView(PanelWrapper Panel,  boolean bClearAllVisibileInEraserSetting) {
       //Hasmap
       HashMap<String, Integer> settingResourceMap = new HashMap<String, Integer>();
       //settingResourceMap.put(SCanvasConstants.LAYOUT_PEN_SPINNER, R.layout.mspinner);
       
       //Viewgroup
       RelativeLayout fl = new RelativeLayout(ba.applicationContext.getApplicationContext());
        fl.setLayoutParams(new RelativeLayout.LayoutParams (Panel.getObject().getWidth(), Panel.getObject().getHeight()));
        Panel.setObject(fl);
        
        //Create settingview
       getObject().createSettingView(fl, settingResourceMap, bClearAllVisibileInEraserSetting);
    }

I just wish some more input would be given in this library, as a lot of people might be intrested in the smartappchallenge.com


Tomas
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Last edited:

meow

New Member
I don't see the problem. I will try to create such a wrapper myself. When does the competition end?

Apparently it is not possible as SPen library references the resources mapped in the internal resource file while B4A uses it 'outside' after extracting resources. Would be interested to buy B4A if this lib comes. Thanks
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Apparently it is not possible as SPen library references the resources mapped in the internal resource file while B4A uses it 'outside' after extracting resources. Would be interested to buy B4A if this lib comes. Thanks

Actually, it should be possible. I have already managed to display the settingview and draw some strokes on the emulator. (But that was with S Pen2.0).
I did however also managed to display the settingview on 2.1, but the rest lead me to nullpointers.

@Erel, I had some feedback on the Samsung galaxy S Pen forum:
I have had some response from the Samsung Galaxy dev support:


Tomas
 

warwound

Expert
Licensed User
Longtime User
Those Null Pointer Exceptions could well be related to code such as this:

B4X:
RelativeLayout fl = new RelativeLayout(ba.applicationContext.getApplicationContext());

A few bits of code posted in this thread are passing the Application Context rather than the Activity Context.

If the BA object in the library method is an Activity BA object (not a Process BA object) then you should try:

B4X:
RelativeLayout fl = new RelativeLayout(ba.context);

Martin.
 

meow

New Member
I don't see the problem. I will try to create such a wrapper myself. When does the competition end?

Hi
Waiting for this lib to buy Basic4A:sign0060: Could you pl let us know if the lib will be ready this month? Thanks
 
Top