Splash screen prism xamarin.forms - xamarin.forms

I would like to create a splash screen in my xamarin.forms application which is using the prism.autofac.forms nuget package. Basically I want to create the same splash screen for each platform. Currently my Android application looks like this
[Activity(Label = "MyApp", Theme = "#style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.Toolbar;
TabLayoutResource = Resource.Layout.Tabbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
LoadApplication(new Application(new DroidInitializer()));
}
}
and the application looks like this:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Application : PrismApplication
{
public Application(IPlatformInitializer initializer) : base(initializer)
{
NavigationService.NavigateHomeAsync();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>("Navigation");
containerRegistry.RegisterForNavigation<MainPage>("Index");
containerRegistry.RegisterForNavigation<HomePage>();
}
protected override void OnInitialized()
{
InitializeComponent();
}
}
Where should I implement and show the splash screen? I want to NavigateHome when all registering are finished.

Splash screens should be implemented in the platform projects.
For iOS the recommended solution is to use a storyboard for it, https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac
For Android I use to create a theme for the splash screen, https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
You can make them look the same, but you have to do it on each platform.

Related

Problem seen creating View-ViewModel lookup table - you have more than one View registered for the ViewModels

I started an Xamarin.Froms project with MvvmCross. I followed the documentation on the offical MvvmCross website to start the Android project with Xamarin.Forms. Here is my code in my Core project:
public class App : MvxApplication
{
public App()
{
}
public override void Initialize()
{
base.Initialize();
Mvx.IoCProvider.RegisterSingleton(new NavigationStack());
Mvx.IoCProvider.RegisterSingleton<IMvxAppStart>(new MvxAppStart<MainViewModel>(this, Mvx.IoCProvider.Resolve<IMvxNavigationService>()));
}
}
public class MainViewModel : BaseViewModel
{
public MainViewModel(NavigationStack navigationStack) : base(navigationStack)
{
}
}
Code that's in my Forms project:
MainView.xaml:
<views:MvxContentPage x:TypeArguments="viewModels:MainViewModel"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
xmlns:mvx="clr-namespace:MvvmCross.Forms.Bindings;assembly=MvvmCross.Forms"
xmlns:viewModels="clr-namespace:MyApp.Core.ViewModels;assembly=MyApp.Core"
x:Class="MyApp.Forms.Views.MainView">
<ContentPage.Content>
<StackLayout Margin="10">
<Label Text="Subtotal" />
</StackLayout>
</ContentPage.Content>
</views:MvxContentPage>
MainView.xaml.cs:
public partial class MainView : MvxContentPage<MainViewModel>
{
public MainView()
{
InitializeComponent();
}
}
In my Android project:
[Activity(
Label = "MyApp.Droid",
Theme = "#style/MyTheme",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : MvxFormsAppCompatActivity<MvxFormsAndroidSetup<Core.App, Forms.App>, Core.App, Forms.App>
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
}
}
It compiles, but when I launch the app I get the exception:
MvvmCross.Exceptions.MvxException: Problem seen creating
View-ViewModel lookup table - you have more than one View registered
for the ViewModels: 2*MainViewModel (MainActivity,MainView)
If your ViewModel is called MainViewModel and your Forms page is too, you might get a name conflict because MvvmCross will have 2 view to viewmodel lookups. You can prevent this by naming your Activity differently like "FormsActivity.cs".
You could also rename your MainViewModel to MvxMainViewModel(whatever you like), then this exception will disappear.

Using FirebaseUI for firebase recyclerView in android

i am a new comer in android development and facing some problems using firebase ui.
i wanted to retrieve data from my firebase database and show it on my recyclerView.
but i am constantly getting an error while making FirebaseRecyclerAdapter.
Here is My Code Sample:
public class UsersActivity extends AppCompatActivity {
private Toolbar userToolbar;
private RecyclerView usersList;
private DatabaseReference mUsersDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
userToolbar = (Toolbar) findViewById(R.id.users_toolbar);
setSupportActionBar(userToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Users");
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
usersList = (RecyclerView) findViewById(R.id.users_list);
usersList.setHasFixedSize(true);
usersList.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.single_user_list_layout,
UsersViewHolder.class,
mUsersDatabase
) {
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder holder, int position, #NonNull Users model) {
holder.setName(model.getName());
}
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return null;
}
};
usersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder
{
View mView;
public UsersViewHolder(#NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name)
{
TextView userNameView = (TextView) mView.findViewById(R.id.single_user_name);
userNameView.setText(name);
}
}
}
The Error i'm getting is this:
please help!!
Sorry wanted to comment but i ain't got enough points to do so.
Try this first, if it doesnt work try using FirebaseRecyclerOptions
(The latest version (3.x) of FirebaseUI implements a different method ofinitializing a FirebaseRecyclerAdapter than previous versions.)
Make your " firebaseRecyclerAdapter " variable global, so you would have something like this.
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.single_user_list_layout,
UsersViewHolder.class,
mUsersDatabase
)

Prism Forms - can not see NavigationBar

Xamarin.Forms: 3.0.0.550
Prism: 7.0.0.396
Here is my code snippet in App.xaml.cs :
protected override void OnInitialized()
{
InitializeComponent();
NavigationService.NavigateAsync("NavigationPage/CoursesPage");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<CoursesPage>();
containerRegistry.RegisterForNavigation<MainPage>();
containerRegistry.RegisterForNavigation<Content>();
}
After running I do not see NavigationBar on CoursesPage even if is set NavigationPage.HasBackButton="True" in xaml file.
Any idea what can be wrong?

Basic Kaa mobile application with android sdk

Trying to connect to Kaa Server with Android SDK :
Added downloaded android sdk jar as library in application.
Code
public class MainActivity extends AppCompatActivity {
private Context mContext;
private KaaClient mClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = getApplicationContext();
mClient = Kaa.newClient(new AndroidKaaPlatformContext(mContext), new SimpleKaaClientStateListener(){
#Override
public void onStarted(){
Toast.makeText(mContext, "Success", Toast.LENGTH_LONG).show();
}
#Override
public void onStartFailure(KaaException exception){
Toast.makeText(mContext, "Failure", Toast.LENGTH_LONG).show();
}
},true);
mClient.start();
}
}
But not getting Success message.
Is there any tutorial out there to follow for Android SDK ?
Regards,
Hiten
You have to generate SDK right base on your application and choose Target Platform is Android.
And you can recheck way to add library in android studio.
This query is solved now. It's working as expected.

How to play video through FragmentTabHost in android

I made an application that has 4 tabs:
vedio tab, in this tab I want to play video, taking remote url
virtual lab
edit video
help
I have made MainActivity class in which use FragmentTabHost class id for display tab.
public class MainActivity extends FragmentActivity{
private FragmentTabHost mTabHost;
private FragmentTabHost mTabHostabove;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Vedio").setIndicator("Vedio",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Virtual Lab").setIndicator("Virtual Lab"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Edit Vedio").setIndicator("Edit Vedio"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Help").setIndicator("Help1"),FragmentTab.class,null);
mTabHostabove = (FragmentTabHost)findViewById(R.id.tabhostabove);
mTabHostabove.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Logo").setIndicator("Logo"),FragmentTab.class,null);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Vedio Url ").setIndicator("Vedio Url",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
}
}
I have also made FragmentTab class which extends Fragment.
here is code:
public class FragmentTab extends Fragment {
private TextView tv;
private VideoView mVideoView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_layout, container, false);
tv = (TextView) v.findViewById(R.id.text);
mVideoView = (VideoView)v.findViewById(R.id.vedioview);
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
String path1="http://commonsware.com/misc/test2.3gp";
MediaController mc = new MediaController(getActivity());
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mc);
mVideoView.requestFocus();
// mVideoView.setVideoURI(Uri.parse("android.resource://" +getActivity().getApplicationContext().getPackageName() +"/"+R.raw.song));
mVideoView.setVideoURI(Uri.parse(path1));
mc.show();
mVideoView.start();
} catch (Exception e) {
}
}
});
String tag = this.getTag();
if (tag == "Vedio") {
tv.setText("play vedio");
}
if (tag == "Edit Vedio") {
tv.setText("want to Edit Vedio !!!!!!!");
}
if (tag == "Help") {
tv.setText("do u want help !!!!!!!");
}
if (tag == "Virtual Lab") {
tv.setText("Enter Virtual lab !!!!!!!");
}
return v;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
I am stuck with to play vedio on click vedio tab
anybody solve it if u can . I have searched for 3 days, but i have not found a solution. vedio sound is coming, but vedio is not playing.
Not all devices support all video codecs.
I had the same problem: I work with mp4-format and a resolution of 1280x720. This video format wasn't support by all devices (e.g. HTC Wildfire S). After changing the resolution to 480x360 the video was shown by all devices.
This link should help you:
http://developer.android.com/guide/appendix/media-formats.html

Resources