We're having a hard time taking the first step in using a native library in NativeScript.
It's a Map library so I assume it has something to do with registering a new custom UI, but what gets me is the weird xml syntax.
The follow screenshots are from this page : https://developers.arcgis.com/android/latest/guide/develop-your-first-map-app.htm
Native instructions are for Android Studio :
The dependencies (Gradle) :
It also has a weird dependency for Java 8 features :
And lastly, the basic usage, which seems to require lots of platform specific native events :
For now we're only interested in an Android Proof of Concept, but eventually make and release a multi-platform plugin.
I know it's a lot of instructions and things asked for just one question, but here are our main confusions :
1) How to add the custom element to a NativeScript xml? Do we just set up the gradle imports and just add the following element directly? Also i'm assuming the android:id is unnecessary and we can just use id
<com.esri.arcgisruntime.mapping.view.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.esri.arcgisruntime.mapping.view.MapView>
2) How to access the above element by its ID via Javascript? More specifically how to get it using VUE? Native Example :
import com.esri.arcgisruntime.mapping.view.MapView;
MapView = findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 34.056295, -117.195800, 16);
mMapView.setMap(map);
3) Are there any other steps we need to take into consideration? Specially considering we intend into making this into a full plugin eventually. Or is this more straightforward/simple than I'm making it?
Ignore the XML example from the SDK docs, that is specific to Android's XML markup.
You have to create a new class (let's call it MapView), extending the base class View (from tns-core-modules/ui/core/view), in the createNativeView callback return instance of com.esri.arcgisruntime.mapping.view.MapView. That's should be it, now you can register the MapView class and use it in your Vue template.
Useful docs:
Building Plugins
Marshalling Java to JS
Related
i try to use the List View from this template
http://codecanyon.net/item/material-design-ui-android-template-app/9858746
i get the source code
but i need the steps of how i can implement the list view in android studio ?
you should follow the documentation of the template , as the vendor states :
You can easily implement components from Android UI template just by
following our huge and well organized documentation.
I'm trying to create a cross platform app using Xamarin.Forms. As far as I know, the UI will be created from the code and the .axml file will be generated automatically.
Can I modify the .axml file to edit the UI? I tried editing but all that comes up is what is written in the code. ie: hello forms
UPDATE
public static Page GetMainPage ()
{
return new simplerow ();
}
In Xamarin.Forms you can create your pages from markup definitions that are shared across all platforms.
Typically you will write all your content pages using Xamarin.Forms, however you can mix-and-match native pages into an application should you so wish.
These shared common pages, written in Xamarin.Forms, will reside maybe in a PCL project, or a Shared Project so these can then be re-used in the platform-specific projects, each targeting a specific platform OS.
You can write these common pages, either in code, or in XAML. You can even choose to write some pages one way, and some the other if you so choose.
A Xamarin.Forms page is processed at runtime through the interpretation of the page composition that has been created.
Each control that is specified on a page, has its own platform specific renderer, behind the scenes, that will produce output that is targetted to that OS.
When writing Xamarin.Forms pages, for-the-most, you will start to learn a new way of creating pages that is abstracted from the intricacies of creating mobile applications on each different platform OS.
There is therefore no editable .axml that is generated etc as you will write your pages using Xamarin.Forms markup and controls, and even your own or other custom-controls to produce your own application pages.
The following link shows some examples of how to write XAML pages.
The following link shows some examples of how to write from code-behind pages.
Along with the previous answer re: .xaml instead of .axml, you need to remember to change the startup code in app.cs to use your new .xaml form. Replace the "new ContentPage {...};" with "new MyForm();" (where "MyForm" is the name of your shiny new XAML form).
EDIT: Downloaded the project from the dropbox link. Comments below...
I see several issues here. I think you may need to go through the walkthroughs and sample applications provided by Xamarin to get up to speed with the concepts behind XF apps.
First, you are trying to use an Activity as your application's page. In a Xamarin Forms app, it must be a View of some sort, not a platform-specific visual such as Activity.
Second, remove the "test.xml" file from your Android project's Resources/layout folder; while XAML files are indeed XML, they have an 1) have a file extension of .xaml and 2) belong in the shared project.
Here's what you need to do to get your project working: (I'm assuming you're using VS here, under Xamarin Studio, it's slightly different.)
Right-click your "testforms" shared project
Click Add from the context menu and select "New Item"
In the dialog that appears, select "Forms XAML Page" and in the Name area enter a name (such as "MyForm")
(If you're using XS, choose "New File" and "Forms ContentPage")
This will add two files to your project: a XAML file containing your layout (e.g.: MyForm.xaml), and a code-behind file (e.g.: MyForm.xaml.cs).
Open the XAML file, and modify the Label element so that the Text attribute is
Text = "Hello, World!"
Modify the body of GetMainPage in your App.cs to the following:
return new MyForm();
Run the app
Hope this helps!
You got it wrong. Forms are created either through code or XAML. No axml or anything persistent is generated at platform level, everything is done in runtime(XAML is sort of compiled at compile time).
So, modify either code or XAML if you wish to change something. Or, if you need something more demanding, than consider either subclassing an existing Renderer or create you own.
I use eclipse for android development, and I find it very annoying that every time I create an activity or add new views to my activity, I need to create the references to views in my layout. I am looking for some kind of eclipse plugin that can generate the calls to findViewById() from the layout. I couldn't really find anything because I didn't know what it would be named. It would be very useful and time saving if that kind of plugin existed.
EDIT: The answers you gave are great. Can these tools also add more references to an existing activity so I don't have to manually do that when I add a view to the layout?
You can use https://github.com/JakeWharton/butterknife library for View Injections.
You can also get eclipse plugin https://marketplace.eclipse.org/content/lazy-android for the same.
But the ButterKnife library is frequently being contributed by android devs than the mentioned eclipse plugin. With this library, you can also avoid instantiating listeners yourself by just using like,
#OnClick(R.id.submit) void submit() {
// TODO call server...
}
For View injections, simply,
#InjectView(R.id.user) EditText username;
#InjectView(R.id.pass) EditText password;
So, it will compile as,
username = (EditText) findViewById(R.id.user);
password = (EditText) findViewById(R.id.pass);
Try the morcinek code generator. Its really simple to use.
This are the steps to install the plugin:
http://tmorcinek.wordpress.com/2011/11/30/eclipse-plugin-for-automatic-generation-of-activity-code-from-xml-layout-file/
After install process you may want to configurate a package to get the classes built by the generator, on the IDE -> Window -> Preferences on Bookmark Android Code Generator you can change that parameter.
The plugin does need a better interface for custom activities, still you could get the code, its really simple to make the changes you need, at least the inline listeners.
This solution doesnt work to modify classes you already have, that would be a really good improvement... i'll give it a try in a couple days with more time.
I included paypal sdk in the app and set the product name and price as shown in the attached image.
Is it possible to change the title of the paypal PaymentActivity class . ?
I used the entire code for paypal from this link
.Please suggest whether we could change the title to any text ,(I want to change the text that is marked in Red Circle)?
Jeff here from the PayPal Mobile SDK team.
The PayPal Android SDK doesn't support modifying any of the SDK activities. We don't plan to allow the ability to modify titles, as this would be an inconsistent user experience. However, we're open to feedback from users, so please feel free to file issues in GitHub if you have feature requests!
Couple observations, apparently:
The activity of off which you have put screenshot is PaymentMethodActivity (according to Hierarchy Viewer)
PayPal SDK uses ABS
According to the sample app provided in PayPal SDK page, onBuyPressed() launches PaymentActivity with startActivityForResult():
Now, according to SDK references, PaymentActivity does not provide any API for setting custom title. The page lists setTitle() as a part of "Methods inherited from class android.app.Activity", but does not give any details on how to extend PaymentActivity so that one could leverage those APIs.
So, currently, there is no way to use a custom title.
I personally would not bother to change the title on that screen as it clearly depicts itself as a PayPal screen (as one would see their homepage on a browser), but if you really want a custom title, you may need to file a new issue on their GitHub page.
Your AndroidManifest.xml file should have an entry for the PaymentActivity that looks like this:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
All you should have to do is add the label attribute to that to change the title:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" android:label="#string/some_title" />
For other potentially useful attributes, refer to the activity tag documentation.
Note: I'm assuming here that the PayPal SDK will allow you to override the title. That is, I would expect it to only set a default title if none is given explicitly.
Edit: Unfortunately, the assumption above has proven to be incorrect. Diving a little deeper, it turns out every activity in the PayPal SDK always sets its title in the onCreate() method. That's actually a little surprising, because that means that PayPal isn't leveraging Android's built-in support for localisation and resources. Although I suppose it does allow them to offer developers the SDK as a jar, which doesn't support bundling Android resources.
In any case, since the various activities haven't been declared final, you could simply try to extend them and set the title after the super has done its work:
public class TitlePaymentMethodActivity extends PaymentMethodActivity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Custom Title")
// or:
setTitle(R.string.custom_title);
}
}
After that, you'll have to change the manifest to point to your TitlePaymentMethodActivity, in stead of directly to the activity in the SDK. Do note that this approach may break at any point, if PayPal decides to finalize the activity classes. With that in mind, I suggest you follow #shoe rat's recommendation and file a request with PayPal for 'official' support.
How can I use an Android Library Project, and overwrite certain classes in the "final project".
In other words, I want to reference a library project, and at the same time, change some of the code..
Probably not quite what Android Library projects are all about but you could achieve that by using the interface and class inheritance features of the java language itself.
Library project seem to deal well with merging/overriding resources from the parent in the child and letting you use one codebase with varying app package names.
Given your updated comment about using library projects to have one edition of the app that uses AdMob and one that doesnt, I've revised this answer...
Assuming you dont mind packaging the AdMob library (~138KB) in with your full/paid edition, the simplest thing to do would be to extend an Applcation class and therein declare an enum and a static method to decide whether AdMob ads should be shown.
public class Application extends android.app.Application
{
public enum EditionType { LITE, FULL};
public static int getAdVisibilityForEdition(Context ctx)
{
if (EditionType.valueOf(ctx.getString(R.string.edition)) == EditionType.FULL)
{
return View.GONE;
}
return View.VISIBLE;
}
}
You'll add this class to the library project only. In all three of the projects you'll need to add an entry to /res/Strings.xml as such:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="edition">LITE</string>
</resources>
It doesnt matter what the value of this string is in the library project, but you'll vary it in the paid vs. ad supported editions using FULL and LITE respectively.
Finally, to make your activities responsive to these values call something like this in your onCreate() or onResume():
View ad = (View)this.findViewById(R.id.your_adMob_view_id)
ad.setVisibility(Application.getAdVisibilityForEdition
(this.getApplicationContext()));
This will work fine with AdMob as the AdMob code wont actually try to get an Ad if the view is not visible.
If you really dont want to have the extra 138K for the AdMob jar and the manifest permissions needed for it in the full edition, there are more elegant ways to do this but would involve using some kind of wrapper around the AdMob stuff and either varying the xml layouts between the editions (to include the AdMob view or not) or inject the AdMob view into the layout programatically.
Hope that helps.