PhoneGap for Android - Fragment containing PhoneGap - android

I want to have a FragmentActivity with 2 Fragments. One of them runs a DroidGap, and the other one runs a permanent camera. Is there a way for me to do this? This diagram below illustrates what I want:
FragmentActivity (
Fragment 1: camera
Fragment 2: DroidGap
)
DroidGap extends Activity.
How do I run an existing Activity as a fragment? I tried startActivity() from Fragment.onActivityCreated(), but that simply calls the parent FragmentActivity.onActivityCreated(), which switches the entire Activity to the DroidGap. Is there an adapter that would treat an general Activity as a Fragment?
http://developer.android.com/reference/android/app/Fragment.html

PhoneGap v1.9 comes with CordovaWebView. This allows you to add PhoneGap into Fragments or ActivityGroup.
See Wiki at: http://wiki.apache.org/cordova/CordovaWebView
Working example: https://github.com/infil00p/CordovaActionView

Related

MVVMCross Navigation between Parent Activity and main Fragment overlaps and produces scrolling effect

I have an old Xamarin Android project, which targeted MVVMCross 6.
When the app launches, a welcome activity is loaded by MVVMcross.
Then the user selects the signin button, which loads the signin activity or signup activity.
Then after signin, the user is redirected to the MainActivity, which contains a home fragment.
Each of the activities mentioned above has its viewmodel. The Home fragment too has its viewmodel.
I use viewmodel first navigation, and before navigating from the signin/signup to the main activity's page, I close the current page first.
The issue is that, when I navigate from the signin/signup page to the main activity which contains a home fragment, There is an overlapp animation that occures in the app, and MVVMcross instantiates the MainActivity several times in a row.
When I look at the output window of Visualstudio, I see this:
(MvvmCross.Logging.MvxLog) PresentationAttribute not found for
MainActivity. Assuming Activity presentation (MvxAndroid) Activity
host with ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not
CurrentTopActivity. Showing Activity before showing Fragment for
MyApp.Mobile.ViewModels.HomeViewModel Activity host with
ViewModelType MyApp.Mobile.ViewModels.MainViewModel is not
CurrentTopActivity. Showing Activity before showing Fragment for
MyApp.Mobile.ViewModels.HomeViewModel (MvvmCross.Logging.MvxLog)
PresentationAttribute not found for MainActivity. Assuming Activity
presentation (MvvmCross.Logging.MvxLog) PresentationAttribute not
found for MainActivity. Assuming Activity presentation
From the error message, I can understand that the main activity and its fragment are fighting the top of the navigation stack.
To navigate, I use a "IMvxNavigationService"
Here is how I navigate to the MainActivity that contains the fragments of the app.
await this.navigationService.Navigate<MainViewModel>();
Here is how I attach my presenter to each fragment which is to be displayed in the main viewmodel:
[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.content_frame, true)]
public class HomeFragment : BaseTabFragment<HomeViewModel>
{
}
and BaseTabFragment has the following declaration:
public abstract class BaseTabFragment<TViewModel> : BaseFragment<TViewModel> where TViewModel : class, IMvxViewModel
And Base fragment inherits from: "MvxFragment"
I tried creating a custom MVVMcross fragment presenter, where I add the "ActivityFlags.NewTask | ActivityFlags.ClearTop | ActivityFlags.ClearTask" Flags to the top activities, but this doesn't work. Can someone please help ?
From my perspective if you really switch from signing-activity to main-activity you also have to create the View as activity. So the MainViewModel should map to the MainView as activity and should be a kind of "parent".
Fragments are part of activities.
Take a look at this example, hope it helps.
https://github.com/MvvmCross/MvvmCross/tree/master/Projects/Playground/Playground.Droid
Special to these:
https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/RootView.cs
https://github.com/MvvmCross/MvvmCross/blob/master/Projects/Playground/Playground.Droid/Activities/TabsRootView.cs

Where to place application logic in new Activity code generated by ADT 22.6.2

In the latest versions of eclipse (ADT v22.6.2) the create android application now generates an activity_main.xml and a fragment_main.xml. It generates only a single activity class
but this now has an embedded inner static fragment class that is created by the activity in its onCreate method
#Override
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
....
public static class PlaceholderFragment extends Fragment
My confusion is how to port old code/examples where there was only 1 activity and the main application
logic is usually put in the Activity onCreate method i.e. stuff like findViewById. Listeners
etc
The way I have approached it is that I put all my user created views as members of the static PlaceHolderFragment class. Then I call this in the fragment onCreateView. I still have some logic in the activity and it stores a pointer to the fragment. It updates the views members by calling getters on the fragment. Is this correct or should all logic be moved to the fragment now ?
All the tutorials/examples use the old approach where logic is placed in the activity
so there is no reference documentation for how to use the new files that Eclipse generates for an Android application. Any help appreciated ?
Don't worry about the files that Eclipse generate automatically: You can do whatever that you want!!!
Fragment is a element between an Activity and a container.That's mean that you can put the logic of your code inside of one fragment with not problems.
In theory, fragments are used when you want to manage screens using different modules, containers. It's a fragment, a module, part of one screen (but also can be used in a full screen looking as an activity and with the same behaviour than one activity.) For example, imagine that you have for mobile phone screens, one list of news in one screen, and when you click, your app go to the next screen for show the content of the news, right? Ok, so you can use for these 2 screens: 2 activities for each one or one parent activity with 2 fragments...whatever that you want...
Imagine the same case, for a tablet version of your app, now the left part of the screen you should show the list of news and in the right part of the screen, the contain of each news clicked, right? In that case, would be completly necessary to use one activity parent with two fragments...in that case, we could reuse almost the same case for the mobile phones or tablet.
And now, focus in your question: if you don't want complicate the life (not too much, because work with fragment is easy too) I will recomend you to use only activities for your app.
But, like your question, you want to port, there isn't any problem. Now imagine that your activity is going to be only the class where you are going to manage the fragments. The logic for each screen has to be in each fragment. Use the activity only for replace fragments, or share information between fragments, etc. The activity will be like the orchestra director.
From each fragment, you can access to methods or public variables of your activity using ((NameOfActivity)getActivity()).
Is it clear for you?
One more stuff, in fragment, normally the method that we used for initialize stuffs is onCreateView (and not onCreate like activities).

How to Migrate from activity to fragment

I'm migrating an activity to a fragment. The fragment will ultimately be placed in a tab page.
I have copied the "grouped list" from the Conference example. The listview was on an activity. I am now moving same to a fragment. The method OnViewModelSet() does not exist in the view. Where am I supposed to moved the code contained in OnViewModelSet() when using a fragment?
Here is a very good talk on this topic by Corey Latislaw. She gave it at DroidCon London 2012.
Extends your class from fragment instead of activity and call fragment class functions with the view.
I suggest you to please upload some piece of code.

Can't get onActivityResult when starting an activity from a child activity in TabActivity Android

In MainActivity.java, I extends TabActivity to use Tabhost.
public class MainActivity extends TabActivity
In each Tab, I use ActivityGroup to manage some child activity
public class MerchandiserTabGroupActivity extends ActivityGroup
In a child activity A, I want to start another child activity B.
Intent intCreateClaim = new Intent(mContext, MultiPhotoSelectActivity.class);
startActivityForResult(intCreateClaim, Parameter.ACTIVITY_SELECT_IMAGE);
After I call setResult(RESULT_OK) and finish() in Activity B, onActivityResult() in Activity A isn't called.
Can anyone helps me? Thanks in advance.
I know this isn't really the answer you're looking for, but you're using deprecated API. You should try a refactor and use the new Fragment API and the v4 support library if you need to support older versions of Android too. Using fragments you won't need to rely on setResult and onActivityResult.
Fragment
Fragment Tab Host
This happens because after B activity finishes, Android returns to your TabActivity, not your A activity.
Use fragments. This way you will not have to deal with multiple activities. You will have only one parent activity with fragments inside. To make your life easier and to add support for pre-ICS Android devices, try GrilledUI library.

Communication fragments/activities

In my existing app I am porting two activities to fragments. The case is the classic dual panel mode with a list on the left and the content on the right.
The doc says that I should avoid to manipulate fragments within fragments, passing instead through the host activity. Said that I am using callbacks to the activity.
The first doubt (maybe banal) I have is:
How to avoid to duplicate the same code in the activity that hosts the
2 fragments and into the activity that wraps the fragment when not in
dual mode?
I'll try to explain. So I have:
ListFragment and ListFragmentActivity
ContentFragment and ContentFragmentActivity
because both fragments can live independently from each other, then:
HostActivity
that implements a listener invoked from ListFragment for adding/replacing the ContentFragment
My question is: when ListFragment is instead hosted from ListFragmentActivity, how to avoid to duplicate the code present in the HostActivity into ListFragmentActivity.
Guess I am missing something, thanks in advance.
Get rid of ListFragmentActivity. Have HostActivity handle the case where there is either one or both fragments. Then, by definition, there is no code duplication. See: https://github.com/commonsguy/cw-omnibus/tree/master/LargeScreen/EU4You

Categories

Resources