I want to create an offline map application in Android. I found that it is possible by using Mobile Atlas creator with Open Street Map. Later I found that Mobile Atlas creator is not supporting Open Street Map (Mapink option while creating zip file). I want to know the correct procedure to create an offlin Map. I would be very thankful for you if u provide me a tutorial link.. Thank you
This is how I did this:
create an Osmdroid ZIP atlas, using Mobile Atlas Creator
rename the your zip file "tiles.zip"
create in the phone storage a folder named osmdroid and copy the zip file there
import in your android project the Osmdroid library (latest version at this moment 'org.osmdroid:osmdroid-android:5.1#aar' )
in your activity xml file add: <org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
in your java file add this:
private MapView mapView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapView.setUseDataConnection(false);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
}
It should work :)
Related
I'm trying to implement a multi-module app structure with navigation between modules. The challenge Im having is doing this with a structure that contains nested fragment containers.
Background:
The design uses a single activity.The main activity layout comprises of an actionbar and fragment container. This container is used to host the different 'main' module fragment.
<androidx.fragment.app.FragmentContainerView
android:id="#+id/frg_main_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph_app" />
Each module has a single 'parent' like fragment with a fragment container and bottomNavbar. This fragment container is used to host the detail fragments of each module and is the home fragment in the modules nav graph.
<androidx.fragment.app.FragmentContainerView
android:id="#+id/frg_home_contacts_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="false"
app:navGraph="#navigation/nav_graph_contacts" />
The app module contains a top level nav graph linking each modules parent fragment (these are not nested graphs or the modules nav graph, as the module's detail fragments are not used in the apps container view).
Each module has a bottom level nav graph linking the detail fragments of that module. This is used in conjunction with the bottomNavbar to navigate between module fragments [works].
For example, the goal is to have a button, on the home screen of the home module, that when clicked moves the user to a screen within another module, such as the contacts list screen in the Contact module.
There are two actions:
Navigate the Main container to the new module home fragment. (managed by the navContorller in the App)
Navigate the module container to the new details fragment. (managed by the navController in the module)
Presently I'm working with interfaces and trying to inject (hilt) into the main activity to achieve no.1. However, I'm always running into issues that the home module cant see the apps nav_graph or there are missing dependencies (i.e. it wants the dependency to get the nav_graph). I believe a simlar process should work between fragments for no.2
Concept reference: https://itnext.io/multi-module-navigation-in-android-63cb9924ffbd
This following code is functional when R.id.nav_graph_home but for links outside the module i.e. R.id.nav_graph_contacts it isnt.
interface HomeModuleNavInterface {
fun gotoContacts(navController: NavController)
}
class HomeModuleNavContract : HomeModuleNavInterface {
override fun gotoContacts(navController: NavController) {
navController.navigate(R.id.nav_graph_contacts)
}
}
#Module
#InstallIn(SingletonComponent::class)
class HomeNavigator {
#Singleton
#Provides
fun providesHomeNavInterface(): HomeModuleNavContract = HomeModuleNavContract()
}
class FragmentHomeNavigation : Fragment(R.layout.fragment_home_navigation) {
...
#Inject
lateinit var homeModuleNavigation: HomeModuleNavContract
...
btnContact.setOnCLickListener{
homeModuleNavigation.gotoContacts(findNavController())
}
}
Any suggestions or direction is appreciated. Thanks.
I want to use GIF file as a splash screen. I used A smart splash screen for React Native apps.
GIF is not supported in react-native (Android) by default. Check here for more info.
Hey you can use lottie :)
Website : https://airbnb.design/lottie/
Github : https://github.com/airbnb/lottie-android
Lottie Gif : https://www.lottiefiles.com/
You can try use GLIDE and make asGif()
Glide.with(ctx)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
https://github.com/bumptech/glide
Here is how I did it:
Create an XML file and locate it under android/app/src/main/res/layout and name it splash.xml for example.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ImageView
android:id="#+id/gif_logo_image"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
/>
</RelativeLayout>
Include Glide package from here.
Drop your GIF image under android/app/src/main/res/drawable and name it splash_logo.gif for example.
In MainActivity.java update onCreate method to load your GIF image and show it in the ImageView you included in the layout.
#Override
protected void onCreate( #Nullable Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.splash );
ImageView logoGIFImage = (ImageView) findViewById(R.id.gif_logo_image);
Glide.with(this).load(R.drawable.splash_logo).into(logoGIFImage);
}
I just started a Xamarin.Forms application and I want to add a background image to my XAML.
I added the attribute but it does not appear when I run it!!
Here is the images.
APP
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new Page();
}
XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.Page"
BackgroundImage="bg.png">
SO, how do I fix it?
Add your bg.png file in each of your native projects, since you are currently using a Android emulator start with your Xamarin.Android project:
Android - Place images in the Resources/drawable directory with Build Action: AndroidResource
ref: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/
Example: In your Xamarin.Android project, add bg.png as shown:
Check the Build Action of that image and ensure that it is assigned AndroidResource. Rebuild and re-test.
In Xamarin.forms
The images should be placed in the following folders
iOS, Android - Resources folder
Windows/UWP, Windows Phone - Assets folder
Then the build action(rt click img->properties) of the images should be changed as follows
iOS - BundleResource Windows Phone - Content
Android - AndroidResource Windows/UWP - Content
If Still the image is not displayed, try changing the Copy to Output Directory to Copy if newer in image Properties
If you want to add background image in XAML file for the entire page in Xamarin project, then use the BackgroundImage property and add your image to the Android project under Resources -> drawable folder and for iOS Resources folder.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PhoneDailerDemo"
x:Class="PhoneDailerDemo.MainPage"
BackgroundImage="image3.jpg">
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<StackLayout Padding="100">
//..........
</StackLayout>
</ContentPage>
Reducing the size of the image worked for me.
Another way (source) you can achieve this, is by setting the image's build action (in file properties) as Embedded Resource.
Then, using a converter markup-extension you will be able to use it directly in XAML and won't have to copy or link the files in each platform specific project.
Here's the converter you should add to you portable project:
[ContentProperty(nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
static readonly Assembly CurrentAssembly =
typeof(ImageResourceExtension).GetType().Assembly;
public const string Assets = nameof(Assets);
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (string.IsNullOrWhiteSpace(Source))
return null;
// Do your translation lookup here, using whatever method you require
var source = $"{CurrentAssembly.GetName().Name}.{Assets}.{Source}";
var imageSource = ImageSource.FromResource(source, CurrentAssembly);
return imageSource;
}
}
Then in your XAML:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WorkingWithImages;assembly=WorkingWithImages"
x:Class="WorkingWithImages.EmbeddedImagesXaml">
<Image Source="{local:ImageResource Background.jpg}"}
</ContentPage>
Image files can be added to each application project and referenced from Xamarin.Forms shared code. To use a single image across all apps, the same filename must be used on every platform, and it should be a valid Android resource name (ie. only lowercase letters, numerals, the underscore, and the period are allowed).
iOS - Place images in the Resources folder with Build Action: BundleResource . Retina versions of the image should also be supplied - two and three times the resolution with a #2x or #3x suffixes on the filename before the file extension (eg. myimage#2x.png).
Android - Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi , drawable-hdpi , and drawable-xhdpi ).
Windows Phone - Place images in the application's root directory with Build Action: Content .
Windows/UWP - Place images in the application's root directory with Build Action: Content .
You can read more at Working with Images
Loading and displaying images in Xamarin.Forms
I would like to use a native extension (ANE) in Flash CS5.5. I saved the ANE as a SWC and added it to my project, but this error keeps on coming up:
Error message:
1172: Definition qnx.events:InvokeEvent could not be found.
ActionScript:
import qnx.events.InvokeEvent;
import qnx.invoke.*;
//NOTE: THIS MUST BE THE FIRST THING SET IN YOUR APPLICATION CONSTRUCTOR
InvokeManager.invokeManager.addEventListener(InvokeEvent.INVOKE, onInvoke );
function onInvoke( event:InvokeEvent ):void
{
if( InvokeManager.invokeManager.startupMode == InvokeStartupMode.INVOKE )
{
//invoked as an application/target.
var mydata:InvokeRequest = InvokeManager.invokeManager.startupRequest;
}
else if( InvokeManager.invokeManager.startupMode == InvokeStartupMode.VIEWER )
{
//invoked as a viewer
var myotherdata:InvokeViewerRequest = InvokeManager.invokeManager.startupViewerRequest;
}
else
{
//launched by the pressing on the icon on the home screen.
}
}
Is there anything missing in the code?
I never used an ANE/SWC before, so any help is welcome.
I uploaded the files. Would be great if someone could take a look at them:
Download: http://www.sendspace.com/file/gjqp1w
Thanks.
How are you packaging the application? This error generally means the extension is not being packaged correctly with the application.
I believe from CS5.5 you still have to use the adt command line to specify the location of the ANE file when packaging, so if you're just exporting from CS5.5 you'll get this error.
Something like the following:
adt -package
-target ipa-ad-hoc
-storetype pkcs12 -keystore ../AppleDistribution.p12
-provisioning-profile AppleDistribution.mobileprofile
myApp.ipa
myApp-app.xml
myApp.swf icons Default.png
-extdir extensionsDir
Additionally you have to make sure you add the extensions id to you application descriptor:
<extensions>
<extensionID>com.extension.id</extensionID>
</extensions>
I have an Adobe AIR ANE that builds and runs fine on iOS. I want to run this app in the AIR simulator, but with an actionscript version of the native ANE.
Reading the docs, it seems like a default profile would be perfect for this.
I added the default profile to the extension.xml file. I added a AS implementation of the native interface to every project in my workspace. I have made methods static/not static, etc. I have tried everything but I keep getting this error:
ArgumentError: Error #3500: The extension context does not have a method with the name
I am at a complete loss. Here are the relevant files:
extension.xml
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
<id>com.novel.analytics.ext.ApsalarNativeInterface</id>
<versionNumber>0.0.0</versionNumber>
<platforms>
<platform name="iPhone-ARM">
<applicationDeployment>
<nativeLibrary>libApsalarNativeInterface.a</nativeLibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
<platform name="default">
<applicationDeployment/>
</platform>
</platforms>
</extension>
My AS implementation:
package com.novel.analytics.ext
{
public class ApsalarNativeInterface
{
public function ApsalarNativeInterface()
{
}
private static function initExtension():void
{
}
public function initApsalar(apiKey:String, secret:String):void
{
}
}
}
my native interface:
package com.novel.analytics
{
import flash.external.ExtensionContext;
public class ApsalarInterface
{
private static const EXTENSION_ID : String = "com.novel.analytics.ext.ApsalarNativeInterface";
private var context : ExtensionContext;
public function ApsalarInterface()
{
this.context = ExtensionContext.createExtensionContext(EXTENSION_ID, null);
}
public function initApsalar(apiKey:String, secret:String):void
{
context.call("initApsalar", apiKey, secret);
}
}
}
Here is my adt command line (library.swf is the lib that contains the two above files:
/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adt -package -target ane ../../$PRODUCT_NAME.ane extension.xml -swc NativeInterface.swc -platform iPhone-ARM -C . library.swf -platform default -C . library.swf
Like I said, I am at a complete loss on this one.
Sorry for the much delayed response, but I think you'd benefit from checking out this wonderful tutorial:
http://www.digitalprimates.net/author/nweber/2012/04/10/building-a-native-extension-part-3/
Based on your code snippets above, it looks like you're trying to define your pure-ActionScript implementation in a different package, with a different classname. Seems you actually want to use the same package+class+method names and just store it in a different library (so it's bundled as its own SWF). Then you tell ADT how to bundle things.