I am looking for a way to create a First-Start Tutorial for an App, and I found the following package: AppIntro for that.
Probably a nice package, but I have no clue on how to use it. Some pieces of how to use it are given, but no full downloadable example project.
Is there an example app somewhere on how to use this AppIntro package, or do I have to experiment on my own for days in order to learn how to use it ...?
There is an example project given here, but upon compiling this project I see nothing that actually resembles what I was expecting. I was expecting what is shown the original page in the first images. Some pages you can 'slide', with some dots on the button showing on which tutorial page you are.
Actually, some working hints come from
the video tutorial given on the main page of the library
and using the class SampleSlide given somewhere in the example section.
However, at the end, the Intro never starts, as the SharedPreferences firstStart is always set to 'false'. Now I need to figure out a way to 'reset' the SharedPreferences...
Solution:
Do not follow the code exampled given on the main page
Follow the Video tutorial
Download the not-working example code
Find the code for SampleSlide somwehere in the example code
Insert a button in order to 'reset' the shared preferences
Use this code to 'reset' the shared preferences:
public void resetPrefs(View view) {
// Make a new preferences editor
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
getPrefs.edit().clear().commit();
// changes layout
}
When I have some time I will put the COMPLETE and FULLY WORKING code in here later ...
Here's how I implemented it:
Added the dependencies in root build.gradle and app-level build.gradle.
Added a java file named IntroActivity.java and inserted the necessary code.
Along with the above java file, I created respective XML layout
files and called them in the addSlide function.
I also added the BaseSlide.java (or SampleSlide.java) for
Fragments.
Finally, added the Manifest declaration.
Related
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 have 10 apps based of of one Library Project. I have an activity in the Library Project that shows a list of images. The images are different for every App, and are in the individual project. How can I create a data structure of the image data so that the Library Project activity can loop through it?
CommonsWare's answer seems like a good idea and I would try that first.
Another approach would be to create an empty integer-list inside your library:
<integer-array name="resources">
</integer-array>
and inside every project list drawables that would be actually used:
<integer-array name="resources">
<item>#drawable/res1</item>
<item>#drawable/res2</item>
<item>#drawable/res3</item>
</integer-array>
This way you have a reference to it inside library and can loop over the list, that will override library's empty list.
No code is running on the app that can call any of those APIs or sent anything to with Intents
Then how is your library code ever going to get executed?
If the answer is "I am publishing components that go in the manifest of the hosting app", then use <meta-data> elements in the manifest to allow the hosting app to point you to an XML resource file that contains this configuration information. You can see this with app widgets, searchable activities, and so forth.
When I originally wrote and published my app, I was using a custom written activity to handle application settings. I used custom file name to store shared preferfences, like this:
getSharedPreferences("custom_settings_file",MODE_PRIVATE);
But now I'm refactoring my app and I would like to implement PreferenceActivity or PreferenceFragment and an xml file with PreferenceScreen section. Every tutorial or example that I've seen is using
getDefaultSharedPreferences(context);
to retrieve shared preferences, because PreferenceActivity assumes default filename to store preferences and there's no way to tell it to use a different one(at least I couldn't find one after an hour of searching and reading documentation).
So now I have a problem. If I just simply use the new default file, existing users of my app will lose their settings when they update the app, because the new application will not know anything about "custom_settings_file". What would be the best way to move the data from an old file to a new one on app update?
Here are the possible options that I could come up with:
Extend Application class and implement a piece of code in onCreate() so that every time my app is launched, it would check for existence of "custom_settings_file" and move it's contents to the new one. But running a block of code on every app launch seems like wasting too much processing resources for an operation that only needs to run once.
Just notify the user that their old settings are gone. But obviously this is not acceptable.
Is there a better solution, than option 1? Perhaps someone has already faced a similar problem?
What is preventing you from doing number 1 only once?
Just add a "migration" boolean to the new sharedpreferences.
If you also load the xml preference file then you can try this:
PreferenceManager.setDefaultValues(context, YOUR_PREFERENCE_NAME, MODE_PRIVATE, R.xml.preference_file, false);
If not (you want to add each preference item dynamically in your code) then you can do like this:
PreferenceManager pm = getPreferenceManager();
pm.setSharedPreferencesMode(MODE_PRIVATE);
pm.setSharedPreferencesName(YOUR_PREFERENCE_NAME);
In case you still want to use the defaultSharedPreference and process the migration then ... I'm writing this and I see Nicklas's answer, so I'm done here.
Could you add value in your new SharedPreferences that records whether you are a new install or an upgrade. If you don't have the setting in your sharedpreferences, check to see if you have an old preferences file in the way you were before. Then convert those preferences to your new method, and set your private setting indicating that it's been upgraded. Then just set the new value indicating the new state and you won't need to check your old preferences any more.
This is probably realy noobish question but, i am unable to solve it. I dont know what i am doing wrong or what should i do, i checked some tuts but i wasnt able to solve it. So i created new folder in res called menu and created new file there called xyz.xml. Now i want to call it in activity with following R.menu.item ... But when i just write R. it doesnt show menu as option. I can call any map which are default here like layout etc, but maps which i created i cant call them. What should i do to solve this?
If the menu file you create is called xyz.xml, then in your code you should use it as:
R.menu.xyz
Also, are you referring to the correct R? There's one R class used for the Android framework resources (android.R) and then there's one specific R class for your projects resources. To ensure you're using the right one you can use the fully qualified namespace, e.g. yourprojectsnamespace.R.
See http://developer.android.com/guide/topics/ui/menus.html for more information about Android menus.
my app has a styles.xml file with various visual constants defined.
I'd like my users to be able to switch the entire app to an alternative visual theme. I'd like to provide an alternative styles2.xml file and switch at runtime (via the Settings).
Is this possible, and how? I suspect the style names' appearance in the generated R class does not bode well.
If it's not possible, what's my next best option?
Not sure if anyone is still interested but I have found a possible solution. A bit hackish but gets the desired result.
Basically I set up my 2 style files in separate country code directories:
res/values-mcc199/style.xml
res/values-mcc198/style.xml
Then in my activity I use the following to change which is referenced:
Configuration config = new Configuration();
config.mcc = 199;
getBaseContext().getResources().updateConfiguration(config,null);
I've only done some basic testing so far but it appears to work. Obviously if you are already using country code to decide your layouts then this will interfere. I think there may be problems as well if the phone gets an event about a country change.
Actually, after some reading of the doc, it seems that this can be done. Look here.
As it is mentionned :
To create a set of styles, save an XML
file in the res/values/ directory of
your project. The name of the XML file
is arbitrary, but it must use the .xml
extension and be saved in the
res/values/ folder.
Now, if this is logical and I didn't read the doc wrongly, you can create as many styles as you want, reference them in themes.xml with #style/... (if you want to apply it to a whole activity or application) and then, just call
setTheme(R.id.yourtheme)
I think this should work. Have a go at it and tell us?
It's not an exact answer; in my blog post here:
http://blog.blundell-apps.com/switching-android-configurations-using-constants-and-ant/
I switch out a java class at build time using Ant, there is nothing to stop you switching out an XML file, as it compiles after the switch. To amend the tutorial you'd just have to change the path's of the file your templating.
Also mirrored on GitHub: https://github.com/blundell/BuildChoiceTut