Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
401 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
map-fragment | ||
============ | ||
|
||
An example of how one can use MapActivity as a fragment. | ||
An example of how one can use MapActivity as a fragment. | ||
|
||
|
||
All code in this repository is under [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) (unless otherwise is stated in file header). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="gen"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> | ||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> | ||
<classpathentry kind="lib" path="libs/android-support-v4.jar"/> | ||
<classpathentry kind="output" path="bin/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>map-fragment-example</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.inazaruk.example" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="13" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
|
||
<uses-library android:name="com.google.android.maps" /> | ||
|
||
<activity android:label="@string/app_name" android:name="com.inazaruk.example.MyMapActivity" /> | ||
<activity android:label="@string/app_name" android:name=".MainFragmentActivity" > | ||
<intent-filter > | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=Google Inc.:Google APIs:11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All code and files in this folder and their subfolders are under (Apache License, Version 2.0)[http://www.apache.org/licenses/LICENSE-2.0.html] (unless otherwise is stated in file header). |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="horizontal" > | ||
|
||
<fragment android:id="@+id/my_map_fragment1" | ||
android:name="com.inazaruk.example.MyMapFragment" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="fill_parent" > | ||
<!-- Preview: layout=@layout/my_map_fragment --> | ||
</fragment> | ||
|
||
<View | ||
android:layout_width="1dp" | ||
android:layout_height="fill_parent" | ||
android:background="#ff000000" | ||
/> | ||
|
||
<fragment android:id="@+id/my_map_fragment2" | ||
android:name="com.inazaruk.example.MyMapFragment" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="fill_parent" > | ||
|
||
</fragment> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<com.google.android.maps.MapView | ||
android:id="@+id/mapview" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:clickable="true" | ||
android:apiKey="@string/googlemaps_sdk_key" | ||
/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@android:id/tabhost" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent"> | ||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" > | ||
|
||
<TabWidget | ||
android:id="@android:id/tabs" | ||
android:visibility="gone" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" /> | ||
|
||
<FrameLayout | ||
android:id="@android:id/tabcontent" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" /> | ||
|
||
</LinearLayout> | ||
</TabHost> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="hello">Hello World, MapFragmentExampleActivity!</string> | ||
<string name="app_name">MapFragmentExample</string> | ||
|
||
<string name="inazaruk_debug_googlemaps_sdk_key">0dndT94moYynYoLxXf5GGq3jQmCgfy-ZjfJg4gQ</string> | ||
<item type="string" name="googlemaps_sdk_key">@string/inazaruk_debug_googlemaps_sdk_key</item> | ||
|
||
</resources> |
58 changes: 58 additions & 0 deletions
58
map-fragment/src/com/inazaruk/example/ActivityHostFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2011 Ievgenii Nazaruk | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.inazaruk.example; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewParent; | ||
import android.view.Window; | ||
|
||
/** | ||
* This is a fragment that will be used during transition from activities to fragments. | ||
*/ | ||
public abstract class ActivityHostFragment extends LocalActivityManagerFragment { | ||
|
||
protected abstract Class<? extends Activity> getActivityClass(); | ||
private final static String ACTIVITY_TAG = "hosted"; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
Intent intent = new Intent(getActivity(), getActivityClass()); | ||
|
||
final Window w = getLocalActivityManager().startActivity(ACTIVITY_TAG, intent); | ||
final View wd = w != null ? w.getDecorView() : null; | ||
|
||
if (wd != null) { | ||
ViewParent parent = wd.getParent(); | ||
if(parent != null) { | ||
ViewGroup v = (ViewGroup)parent; | ||
v.removeView(wd); | ||
} | ||
|
||
wd.setVisibility(View.VISIBLE); | ||
wd.setFocusableInTouchMode(true); | ||
if(wd instanceof ViewGroup) { | ||
((ViewGroup) wd).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); | ||
} | ||
} | ||
return wd; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
map-fragment/src/com/inazaruk/example/LocalActivityManagerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (C) 2011 Ievgenii Nazaruk | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.inazaruk.example; | ||
|
||
import android.app.LocalActivityManager; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.util.Log; | ||
|
||
/** | ||
* This is a fragment that will be used during transition from activities to fragments. | ||
*/ | ||
public class LocalActivityManagerFragment extends Fragment { | ||
|
||
private static final String TAG = LocalActivityManagerFragment.class.getSimpleName(); | ||
private static final String KEY_STATE_BUNDLE = "localActivityManagerState"; | ||
|
||
private LocalActivityManager mLocalActivityManager; | ||
|
||
|
||
protected LocalActivityManager getLocalActivityManager() { | ||
return mLocalActivityManager; | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
Log.d(TAG, "onCreate(): " + getClass().getSimpleName()); | ||
|
||
Bundle state = null; | ||
if(savedInstanceState != null) { | ||
state = savedInstanceState.getBundle(KEY_STATE_BUNDLE); | ||
} | ||
|
||
mLocalActivityManager = new LocalActivityManager(getActivity(), true); | ||
mLocalActivityManager.dispatchCreate(state); | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
outState.putBundle(KEY_STATE_BUNDLE, mLocalActivityManager.saveInstanceState()); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
Log.d(TAG, "onResume(): " + getClass().getSimpleName()); | ||
mLocalActivityManager.dispatchResume(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
Log.d(TAG, "onPause(): " + getClass().getSimpleName()); | ||
mLocalActivityManager.dispatchPause(getActivity().isFinishing()); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
Log.d(TAG, "onStop(): " + getClass().getSimpleName()); | ||
mLocalActivityManager.dispatchStop(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
Log.d(TAG, "onDestroy(): " + getClass().getSimpleName()); | ||
mLocalActivityManager.dispatchDestroy(getActivity().isFinishing()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
map-fragment/src/com/inazaruk/example/MainFragmentActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2011 Ievgenii Nazaruk | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.inazaruk.example; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentActivity; | ||
|
||
public class MainFragmentActivity extends FragmentActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle bundle) { | ||
super.onCreate(bundle); | ||
setContentView(R.layout.main_fragment_activity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2011 Ievgenii Nazaruk | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.inazaruk.example; | ||
|
||
import android.os.Bundle; | ||
import com.google.android.maps.MapActivity; | ||
|
||
public class MyMapActivity extends MapActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle icicle) { | ||
super.onCreate(icicle); | ||
setContentView(R.layout.my_map_activity); | ||
} | ||
|
||
@Override | ||
protected boolean isRouteDisplayed() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.