Android 3.x+ Wishes

Roger Garstang

Well-Known Member
Licensed User
Longtime User
After playing in Eclipse for a bit I have a few things I noticed:

1. I like that you added the ability now to specify which menu items get added to the action bar. They appear to be drawing different than standard though (See Images below where Eclipse/Java version fits 3 buttons while B4A only fits 2)

My Code to add them is:

B4X:
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem mnu1 = menu.add(0, 1, 1, "Print Labels");
    if (android.os.Build.VERSION.SDK_INT > 10) mnu1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    MenuItem mnu2 = menu.add(0, 2, 2, "Transfers");
    MenuItem mnu3 = menu.add(0, 3, 3, "Upload");
    if (android.os.Build.VERSION.SDK_INT > 10) mnu3.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    MenuItem mnu4 = menu.add(0, 4, 4, "Download");
    if (android.os.Build.VERSION.SDK_INT > 10) mnu4.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    MenuItem mnu5 = menu.add(0, 5, 5, "Registration");
    MenuItem mnu6 = menu.add(0, 6, 6, "Setup");
    return true;
}

2. A cool addition would also be the Home/App Button (Also pictured below in Upper Left of Java version. I add it and process the event with (Currently I just make it behave as Back, but it can do anything):

B4X:
if (android.os.Build.VERSION.SDK_INT > 10) getActionBar().setDisplayHomeAsUpEnabled(true);

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
      case android.R.id.home:
         finish();
         break;
   }
   return true;
}

3. I have come to love XML Layouts...almost makes me feel like I wasted time developing my View Manager Class since they do the same thing and much more. In the Java version below I just have a simple relative layout within a scrollview layout. Each text auto expands to a MaxLength and MaxEMS along with paddings, margins, etc. I even use sort of a hack to get some advanced IME type functionality using android:digits to limit chars in fields that are not Numeric and it works fine. Next is handled automatically, the keyboard is set to android:windowSoftInputMode="stateUnchanged", and Done is handled with a simple setOnEditorActionListener. All states are automatically saved since all views I give an ID to are in the R file and the default onCreate automatically restores them.

Now, I guess the big question is...how much of this can come over to B4A? We modify the Main XML file, so we work with XML. We create the R file with our resources, so we make use of it already too. What about adding the ability of creating our Layouts in XML? Maybe another LoadLayout that can read from XML? Perhaps we add the XML files like other files, but it parses it and adds our ids to the R file then we have some type of method to get the views by an ID or something like in regular JAVA? Add the ability to specify Font sizes in SP, width sizes in EMS and MaxEMS, etc...even if it is just in the XML capabilities. More options for the R file like right clicking text fields and adding them as a String Resource like Eclipse can and easy access to them.
 

Attachments

  • JAVAversion2.png
    JAVAversion2.png
    49.3 KB · Views: 230
  • B4Aversion2.png
    B4Aversion2.png
    43.1 KB · Views: 232

Roger Garstang

Well-Known Member
Licensed User
Longtime User
3. It shouldn't be difficult to create a library that loads XML layouts. Basic4android way of creating the UI is different so it will not be added to the core functionality.

Thought about that a little bit. The XML would have to be included at build time though and not dynamic. By code using a library to get layouts not in B4A would be cool though. I really like the Relative layout. I think I may try my hand at a library that creates one of those. A couple ways to go about it...I could create the views in the library too which would give more capabilities, but having them usable in B4A would be better. Might need some advice on handling interactions. I could either set them up and pass them back as B4A views if that is possible, or pass them in and edit the layout parameters for them, etc. You need IDs for this layout too...do the views in B4A have an ID or would that need created?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I'm no Pro at JAVA and hated using it in college seeing it going nowhere. Now it is everywhere. Without Eclipse having the inline help and dropdowns I'd never get anything done. It is a lot more work to code in it too. I've begun instead using it to write libraries for things missing in B4A. I have started a Relative Layout Library and a Camera library since the one in B4A doesn't work how I want/need.
 
Top