I am going to try and wrap this (CircularButton) from here
https://github.com/Alexrs95/Circula...alexrs/circularbutton/lib/CircularButton.java
Found it on the android-arsenal.com website. Will in all probability call on wrapper Doctor @DonManfred's help to work through this ....that is if you don't mind....
I wrote a small tutorial for @Johan Schoeman then... Then i thought this could be interesting to more than just Johan.
So here we go:
1.Original
The content of the zip from Github
2.Find the main source folder
Find the folder from the LIB (if there are lib and demo) where the res-folder is
3. use Rgenerator
copy RGenerator.exe to this folder and run it (you find rgenerator.exe in forum)
4.Cleanup
remove not used parts
5.spacer
6.Start of a new Eclipse-project
This is basically a copy of my HTMLTextView library. This is the base of all wraps i do usually...
Note: Some parts of the file in de\donmanfred\ still needs to be updated to match "the current wrapper"
So i prepare a new project directory structure
Copy the folder Circularbutton to your Eclipse workspace
in eclipse do a import of a available project, select the path of your workspace\Circularbutton
Finish
Now you are in eclipse
After you have imported and opened your project we see some errors
We will start with the R.java
Use the Quickfix "Import 'BA' (anywheresoftware.b4a)"
Next the system says the the r.java should get the right package.
Add the suggested packagedeclaration
Save the r.java. The errors should gone for this file now.
Looking at the Errors we see an indicator for an higher android-version
than we refer to at start (the base is using android SDK 8)
So we change the Build-Paths and select a newer android.jar
In this case i usually use android 15 (4.0.3+ or so) but for this wrapper we need to set
android-sdk\platforms\android-16\android.jar
After setting this error disappears too...
I already said earlier that my wraps usually are based on HTMLTextView library.
Some artefacts still are in the new wrappe we are writing
To know what we need to change and to what
we look at the java file from the lib (in this case it is just one). Here we find information
of what object it goes...
public class CircularButton extends ImageView {
This lib is an CircularButton which is based on an ImageView.
So basically it is a VIEW too.
in the file de\donmanfred\Circularbutton.java
we start to edit
public class htmltv implements DesignerCustomView {
will get changed to the new class we want
public class CircularButtonWrapper implements DesignerCustomView {
we now use the quickfix to let eclipse rename the file correct.
Now:
private HtmlTextView mtext;
this is the relict we need to adapt
we start with a new definition using the right objecttype
private CircularButton cb;
and use the quickfix to import
after replacing all occurencies of mtext with cb
we still have the line
cb = new HtmlTextView(ba.context);
change it to
cb = new CircularButton(ba.context);
to match the right objectdeclaration
As we are extending a view here we use a viewwrapper
here
changing
B4X:
public class CircularButtonWrapper implements DesignerCustomView {
B4X:
public class CircularButtonWrapper extends ViewWrapper<CircularButton> implements DesignerCustomView {
Use the quickfix to import anywheresoftware.b4a.objects.ViewWrapper;
from the libs github page we know that we need to allow changes
Button color
button.setButtonColor(Color.BLACK);
Shadow color
button.setShadowColor(Color.BLUE);
in fact we need at least two methods to do this
B4X:
public void setButtonColor(int color) {
}
public void setShadowColor(int color) {
}
now we fill life into it
B4X:
public void setButtonColor(int color) {
cb.setButtonColor(color);
}
public void setShadowColor(int color) {
cb.setShadowColor(color);
}
we need a helper more...
B4X:
public void setImageBitmap(Bitmap bm) {
cb.setImageBitmap(bm);
cb.invalidate();
}
now the a little bit tricky parts
in the lib we see
B4X:
public CircularButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void init(Context context, AttributeSet attrs) {
setScaleType(ScaleType.CENTER_INSIDE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mButtonPaint.setStyle(Paint.Style.FILL);
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularButton);
buttonColor = a.getColor(R.styleable.CircularButton_buttonColor, buttonColor);
shadowColor = a.getColor(R.styleable.CircularButton_shadowColor, shadowColor);
a.recycle();
}
setButtonColor(buttonColor);
}
into the xml definition of the styleable object Circularbutton.
We dont want to use xml-files. So we try to replace them.
Only two properties are available. We replace them with hardcoded values (leaving the defaults for now)
B4X:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void init(Context context, AttributeSet attrs) {
setScaleType(ScaleType.CENTER_INSIDE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mButtonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mButtonPaint.setStyle(Paint.Style.FILL);
setButtonColor(buttonColor);
}
back to the "own" file
Adapting
B4X:
@Version(1.00f)
@ShortName("Circularbutton")
Now we are in a stage with no errors. As i´m writing this text here i am not sure if it works...
Let´s try it
and click on compile... when you have a look at this BIG xml-file you see that we need to exclude the original references....
Add
,me.alexrs
^ comma
at the end of the -b4aignore line... me.alexxrs is the classpath of the original-library we are wrapping.
compile again
Now the xml looks much better. no not needed references.
At this point i will do a test b4a-project (10.Example.zip)
Last but not least: A spoiler
Attachments
-
1.Original.zip179.4 KB · Views: 957
-
2.Find the main source folder.zip3.4 KB · Views: 851
-
3. use Rgenerator.zip3.1 KB · Views: 877
-
4.Cleanup.zip2.9 KB · Views: 813
-
5.Start of a new Eclipse-project.zip13.4 KB · Views: 800
-
6.Working in Eclipse.zip91.7 KB · Views: 849
-
7.New Wrapper.zip20.1 KB · Views: 869
-
9.Resulting Library.zip5.2 KB · Views: 810
-
10.Example CircularButtonEx.zip12.1 KB · Views: 824