How to change the tab layout theme programmatically? - tabs

I have created a custom style for my tab layout in styles.xml file.
styles.xml:
<style name="AppTabLayout" parent="Widget.Design.TabLayout">
<item name="tabMaxWidth">#dimen/tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabPaddingStart">6dp</item>
<item name="tabPaddingEnd">6dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">#style/AppTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/range</item>
</style>
<!-- for text -->
<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">12sp</item>
<item name="android:textColor">#color/orange</item>
<item name="textAllCaps">false</item>
</style>
Apply:
<android.support.design.widget.TabLayout
style="#style/AppTabLayout"
app:tabTextAppearance="#style/AppTabTextAppearance"
android:layout_width="match_parent"
.... />
I used this code for my tablayout.
Everything works fine. But I want to change the style at runtime. I have gone through stackoverflow, but haven't found anything about this. Is it possible ?

styles.xml
<resources>
<attr name="tabLayoutStyle" format="reference" />
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<style name="AppTheme.Blue">
<item name="tabLayoutStyle">#style/Blue.TabLayout</item>
</style>
<style name="Blue.TabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">#color/selected_textBlue</item>
<item name="tabIndicatorColor">#color/accent_blue</item>
<item name="tabBackground">#color/primary_blue</item>
</style>
<style name="AppTheme.Red">
<item name="tabLayoutStyle">#style/Red.TabLayout</item>
</style>
<style name="Red.TabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">#color/selected_textRed</item>
<item name="tabIndicatorColor">#color/accent_red</item>
<item name="tabBackground">#color/primary_red</item>
</style>
<color name="selected_textBlue">#000055</color>
<color name="accent_blue">#0000ff</color>
<color name="primary_blue">#0099ff</color>
<color name="selected_textRed">#880022</color>
<color name="accent_red">#550000</color>
<color name="primary_red">#ff0000</color>
</resources>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.design.widget.TabLayout
style="?attr/tabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:text="Tab 1" />
<android.support.design.widget.TabItem
android:text="Tab 2" />
</android.support.design.widget.TabLayout>
<Button
android:id="#+id/mainButton0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:onClick="onClick" />
<Button
android:id="#+id/mainButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue"
android:onClick="onClick" />
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(PreferenceManager.getDefaultSharedPreferences(this)
.getInt("theme", R.style.AppTheme_Blue));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(android.view.View v) {
switch (v.getId()) {
case R.id.mainButton0:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putInt("theme",
R.style.AppTheme_Red).commit();
break;
case R.id.mainButton1:
PreferenceManager.getDefaultSharedPreferences(this)
.edit().putInt("theme",
R.style.AppTheme_Blue).commit();
break;
}
recreate();
}
}

Related

View with elevation and shadow in ConstraintLayout

How can I show elevations in a view with shadows using ConstraintLayout?
With Relative and Linear could perform elevations with shadows to implement list but I can not do it with ConstraintLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TextView
android:id="#+id/list_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:elevation="8dp"
android:background="#fff"
android:text="SSID"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/list_ch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:elevation="8dp"
android:background="#fff"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="CH"
app:layout_constraintLeft_toLeftOf="#+id/guideline"
app:layout_constraintRight_toLeftOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/list_dB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:elevation="8dp"
android:background="#fff"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="dB"
app:layout_constraintLeft_toLeftOf="#+id/guideline2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.65"
tools:layout_editor_absoluteX="239dp"
tools:layout_editor_absoluteY="0dp" />
<android.support.constraint.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.83"
tools:layout_editor_absoluteX="306dp"
tools:layout_editor_absoluteY="0dp" />
</android.support.constraint.ConstraintLayout>
For some reason, elevation works in ConstraintLayout if you give a dummy drawable as the background::
Create a drawable:
dummyBg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
Use this as the background for the view and use elevation as you normally would.
android:elevation="8dp"
android:background="#drawable/dummyBg"
android:padding="4dp"
So you'd get:
<TextView
android:id="#+id/list_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="2dp"
android:elevation="8dp"
android:background="#drawable/dummyBg"
android:padding="4dp"
android:text="SSID"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
In order to make elevation work, you need to just set a background color to a view.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/your_color"
android:text="SSID"/>
Doesn't matter what kind of View it is,
a child of ConstraintLayout or ConstraintLayout itself
You also may use hex color or color attribute.
Just note that it mustn't be fully transparent.

SCORM 1.2 Nested Items In Manifest

I've been trying to create a SCORM 1.2 manifest file that will create multiple SCOs with sub-files but, although there's plenty written about it online, I've been unable to find any actual examples. Essentially, what I want to do is:
SCO1.html
SCO1.1.html
SCO1.2.html
SCO1.3.html
SCO2.html
SCO2.1.html
SCO2.2.html
SCO2.3.html
In the above scenario, if the user was to launch SCO1.2.html, for example, their progress would be recorded against SCO1. I've got the following in my imsmanifest.xml file, but don't know how to restructure it so that each item is not a separate SCO. I've left out the metadata and resources that don't affect this issue:
<organizations default="TOC1">
<organization identifier="TOC1">
<title>Test</title >
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
</item>
<item identifier="I_SCO1.1" identifierref="SCO1.1">
<title>SCO1.1</title>
</item>
<item identifier="I_SCO1.2" identifierref="SCO1.2">
<title>SCO1.2</title>
</item>
<item identifier="I_SCO1.3" identifierref="SCO1.3">
<title>SCO1.3</title>
</item>
<item identifier="I_SCO2" identifierref="SCO2">
<title>SCO2</title>
</item>
<item identifier="I_SCO2.1" identifierref="SCO2.1">
<title>SCO2.1</title>
</item>
<item identifier="I_SCO2.2" identifierref="SCO2.2">
<title>SCO2.2</title>
</item>
<item identifier="I_SCO2.3" identifierref="SCO2.3">
<title>SCO2.3</title>
</item>
</organization>
</organizations>
<resources>
<resource identifier="SCO1" type="webcontent" adlcp:scormtype="sco" href="SCO1.html">
<file href="SCO1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.1" type="webcontent" adlcp:scormtype="sco" href="SCO1.1.html">
<file href="SCO1.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.2" type="webcontent" adlcp:scormtype="sco" href="SCO1.2.html">
<file href="SCO1.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO1.3" type="webcontent" adlcp:scormtype="sco" href="SCO1.3.html">
<file href="SCO1.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2" type="webcontent" adlcp:scormtype="sco" href="SCO2.html">
<file href="SCO2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.1" type="webcontent" adlcp:scormtype="sco" href="SCO2.1.html">
<file href="SCO2.1.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.2" type="webcontent" adlcp:scormtype="sco" href="SCO2.2.html">
<file href="SCO2.2.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
<resource identifier="SCO2.3" type="webcontent" adlcp:scormtype="sco" href="SCO2.3.html">
<file href="SCO2.3.html" />
<dependency identifierref="ALLRESOURCES" />
</resource>
</resources>
Any help would be appreciated.
You'll be looking at something a little closer to this-
<organizations default="ORG-001">
<organization identifier="ORG-001">
<title>Page Progression Sample</title>
<item>
<title>Module 1</title>
<item identifier="ACT-001" identifierref="RES-001">
<title>Name of this page</title>
</item>
<item identifier="ACT-002" identifierref="RES-002">
<title>Name of this page</title>
</item>
<item identifier="ACT-003" identifierref="RES-003">
<title>Name of this page</title>
</item>
<item identifier="ACT-004" identifierref="RES-004">
<title>Name of this page</title>
</item>
</item>
<item>
<title>Module 2</title>
<item identifier="ACT-005" identifierref="RES-005">
<title>Name of this page</title>
</item>
<item identifier="ACT-006" identifierref="RES-006">
<title>Name of this page</title>
</item>
<item identifier="ACT-007" identifierref="RES-007">
<title>Name of this page</title>
</item>
<item identifier="ACT-008" identifierref="RES-008">
<title>Name of this page</title>
</item>
</item>
</organization>
But you could try nesting 2, 3, 4 within 1 to see if that works. I don't have the specification in front of me right now.
In your example -
<item identifier="I_SCO1" identifierref="SCO1">
<title>SCO1</title>
<!-- PUT YOUR NEXT SCO (page) HERE-->
</item> <!-- Close tag of SCO1 -->

Android transition doesn't care about targetId in transitionSet

I'm confused about how transitionSet is used. This is my definition:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" android:transitionOrdering="sequential">
<slide android:slideEdge="bottom" android:startDelay="0">
<targets>
<target android:targetId="#id/action_save" />
</targets>
</slide>
<slide android:slideEdge="top">
<targets>
<target android:targetId="#id/image_album_background" />
</targets>
</slide>
<slide
android:duration="500"
android:slideEdge="bottom">
<targets>
<target android:targetId="#id/fields_container" />
</targets>
</slide>
</transitionSet>
This way, all views will slide from bottom edge. But if I change the order into this:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android" android:transitionOrdering="sequential">
<slide android:slideEdge="top">
<targets>
<target android:targetId="#id/image_album_background" />
</targets>
</slide>
<slide android:slideEdge="bottom" android:startDelay="0">
<targets>
<target android:targetId="#id/action_save" />
</targets>
</slide>
<slide
android:duration="500"
android:slideEdge="bottom">
<targets>
<target android:targetId="#id/fields_container" />
</targets>
</slide>
</transitionSet>
Then, all will slide from top edge.
It seems that Android only cares about the first transition.
Update:
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Picture -->
<RelativeLayout
android:id="#+id/image_album_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff000000">
<ImageView
android:id="#+id/image_album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="No art"
android:maxHeight="320dp"
android:maxWidth="320dp"
android:src="#drawable/ic_noart"
android:transitionName="transition_album_cover"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/btn_img_marker"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignEnd="#+id/image_album"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/image_album"
android:background="#ff56bb21" />
</RelativeLayout>
<LinearLayout
android:id="#+id/fields_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image_album_background"
android:background="#ffffffff"
android:orientation="vertical"
android:padding="#dimen/frame_margin">
<CheckBox
android:id="#+id/cb_embed_art"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/label_embed_art" />
<TextView
android:id="#+id/text_filepath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="/mnt/data/path/to/file/audio.mp3" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/fields_container"
android:background="#ffffffff"
android:padding="24dp">
<!-- Title -->
<LinearLayout
android:id="#+id/title_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_title" />
<EditText
android:id="#+id/edit_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<!-- Artist -->
<LinearLayout
android:id="#+id/artist_row"
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_row"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_artist" />
<AutoCompleteTextView
android:id="#+id/edit_artist"
style="?android:editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
<!-- Album artist -->
<LinearLayout
android:id="#+id/album_artist_row"
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/artist_row"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_album_artist" />
<AutoCompleteTextView
android:id="#+id/edit_album_artist"
style="?android:editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
<!-- Album -->
<LinearLayout
android:id="#+id/album_row"
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/album_artist_row"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_album" />
<AutoCompleteTextView
android:id="#+id/edit_album"
style="?android:editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:id="#+id/two_column_row1"
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/album_row"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_genre" />
<AutoCompleteTextView
android:id="#+id/edit_genre"
style="?android:editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
<LinearLayout
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_year" />
<EditText
android:id="#+id/edit_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_weight="3"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_track_no" />
<EditText
android:id="#+id/edit_track_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
<LinearLayout
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_track_total" />
<EditText
android:id="#+id/edit_track_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
style="#style/input_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/two_column_row1"
android:orientation="horizontal">
<TextView
style="#style/label"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/label_comment" />
<EditText
android:id="#+id/edit_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:minLines="5" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<com.melnykov.fab.FloatingActionButton
android:id="#+id/action_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_action_save"
fab:fab_colorNormal="#color/accent_shade"
fab:fab_colorRipple="#66FF9800" />
</FrameLayout>
This is how to open the layout:
String transitionName = "transition_album_cover";
if (AnimationViews.albumCover != null) {
fragmentTx.addSharedElement(AnimationViews.albumCover, transitionName);
}
TransitionInflater inflater = TransitionInflater.from(this);
editorFragment.setEnterTransition(inflater.inflateTransition(R.transition.editor_fragment_enter));
It is tricky to be able to make work all transitions which are child views. Because it depends on ViewGroup (parent view) of that child views.
Quoting from jimulabs:
If the background of a ViewGroup is set (even if it’s android:color/transparent), the transition system will treat the
ViewGroup as a single view and ignore its children. Thus, any
transitions will only run on the ViewGroup, instead of its children
individually; if a transition has its target set to one of the
children only, the transition will not run at all.
Conversely, if a ViewGroup does not have a background (or it’s #null), transitions will run for all its individual children; if a
transition has its target set to the ViewGroup, the transition will
not run at all.
This does NOT happen if you run beginDelayedTransition() in normal cases such as setting the visibility of views in a OnClickListener.
You can also read about this from here on section Transitioning Views & Transition Groups.
However, you should be able to make it work through method ViewGroup#setTransitionGroup(boolean) which i could not make it work. I have tried using this method on parent layout of screen. So i had to stick with javacode for all transitionSet targets which is time consuming.
I just tried this and it works fine for me, so I have to think that it has to do with your specific targets. My guess is that image_album_background contains both action_save and fields_container. If so, those two Views are still going to slide within their container.
The easy way around this is to move the image_album_background into a sibling of other two instead of parent. If you don't already have a container that is capable of that (e.g. LinearLayout), one extra level will do it:
<FrameLayout ...>
<ImageView android:id="#+id/image_album_background"/>
<other views.../>
</FrameLayout>
5.1.1 fixed confirmed
#George Mount mentioned that support.v4.fragments would fix that one, but in return, you will need to implement your Activity as FragmentActivity.
This is an old question, though, today I was having the same problem and I solved it by adding the tag android:transitionGroup="false|true" to the the ViewGroups, include the root, which of course, should be settled to false. I'm now able to run different animations, in different views (include|exclude views) and the behaviour is as expected.

Adding a map to a class

Hello I would like to add a map (static image) to a page. I will try to explain what I have done so far and what my problem is as good as I can in case someone else has the same problem in the future.
I have done the following:
1. Updated the Manifest file with permissions/API (got the API (from Google API Console) key using the SHA1 from Eclipse using Window > Preferences > Build
2. Updated the XML file of the class where the map will be added
3. Added some Java code into the classes Java file
Below is the Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.lapmaster"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/lapmaster_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="net.learn2develop.lapmaster.LapMasterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Logged In"
android:name=".UserLoggedInScreen" >
<intent-filter >
<action android:name="net.learn2develop.UserLoggedInScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="Track Listing"
android:name=".ListOfCircuits" >
<intent-filter >
<action android:name="net.learn2develop.ListOfCircuits" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:label="Snetterton"
android:name=".Snetterton" >
<intent-filter >
<action android:name="net.learn2develop.Snetterton" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Other activities -->
<!-- Google Play Services -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Various" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
</application>
</manifest>
Below is the class XML:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Below is the class Java:
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.SupportMapFragment;
public class Snetterton extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.snetterton);
SupportMapFragment map = ((SupportMapFragment)
.getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
}
}
As you can probably guess from my code I am creating an app for race tracks. In the class called Snetterton I want to add a picture (Google maps) of Snetterton.
To get to this page the user:
1. Starts at a login screen (LapMasterActivity)
2. Is greeted with a home page (UserLoggedInScreen)
3. Goes to a page with a list of tracks (for now it is just Snetterton) (ListOFTracks)
4. When the user clicks the button for Snetterton it takes them to the Snetterton class' page where I would like the map. (Snetterton).
In my code only ((SupportMapFragment) is underlined.
Thanks.
Answered this myself (eventually):
Code I used is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
public class TopGear extends Activity
{
private GoogleMap aMap;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.top_gear);
aMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
aMap.getUiSettings().setAllGesturesEnabled(false);
LatLng topGearTrack = new LatLng(51.116492, -0.541767);
aMap.setMyLocationEnabled(true);
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(topGearTrack, 15));
aMap.addMarker(new MarkerOptions()
.title("Top Gear")
.snippet("Welcome to the famous Top Gear circuit.")
.position(topGearTrack));
aMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
setUpMapIfNeeded();
}
public void setUpMapIfNeeded()
{
//Do a null check to confirm that we have not already instantiated the map.
if (aMap == null)
{
aMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
//Check if we were successful in obtaining the map.
if (aMap != null)
{
//The Map is verified. It is now safe to manipulate the map.
}
}
}
}

How to set flex 3 tree label clickable?

How to set tree label clickable so tree node can expand? (not only click on arrow icon)
Solved.
<mx:Script>
<![CDATA[
import mx.collections.ICollectionView;
import mx.events.ListEvent;
private function tree_itemClick(evt:ListEvent):void {
var item:Object = Tree(evt.currentTarget).selectedItem;
if (tree.dataDescriptor.isBranch(item)) {
tree.expandItem(item, !tree.isItemOpen(item), true);
}
}
]]>
<mx:XML id="dp">
<root>
<folder label="One">
<folder label="One.A">
<item label="One.A.1" />
<item label="One.A.2" />
<item label="One.A.3" />
<item label="One.A.4" />
<item label="One.A.5" />
</folder>
<item label="One.1" />
<item label="One.2" />
</folder>
</root>
</mx:XML>
<mx:Tree id="tree" dataProvider="{dp}" showRoot="false" labelField="#label" width="300" rowCount="6"
itemClick="tree_itemClick(event);" />