forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -23,6 +23,8 @@ import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TabHost.TabContentFactory;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -35,96 +37,114 @@ import java.util.HashMap;
|
||||
* TabManager supplies its own dummy view to show as the tab content. It listens
|
||||
* to changes in tabs, and takes care of switch to the correct fragment shown in
|
||||
* a separate content area whenever the selected tab changes.
|
||||
*
|
||||
* Copied from the Fragment Tabs example in the API 4+ Support Demos.
|
||||
*
|
||||
* <p>
|
||||
* Copied from the Fragment Tabs example in the API 4+ Support Demos.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class TabManager implements TabHost.OnTabChangeListener {
|
||||
private final FragmentActivity mActivity;
|
||||
private final TabHost mTabHost;
|
||||
private final int mContainerId;
|
||||
private final HashMap<String, TabInfo> mTabs = new HashMap<String, TabInfo>();
|
||||
TabInfo mLastTab;
|
||||
|
||||
static final class TabInfo {
|
||||
private final FragmentActivity fragmentActivity;
|
||||
private final TabHost tabHost;
|
||||
private final int containerId;
|
||||
private final HashMap<String, TabInfo> tabs = new HashMap<String, TabInfo>();
|
||||
private TabInfo lastTabInfo;
|
||||
|
||||
/**
|
||||
* An object to hold a tab's info.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
private static final class TabInfo {
|
||||
|
||||
private final String tag;
|
||||
private final Class<?> clss;
|
||||
private final Bundle args;
|
||||
private final Bundle bundle;
|
||||
private Fragment fragment;
|
||||
|
||||
TabInfo(String _tag, Class<?> _class, Bundle _args) {
|
||||
tag = _tag;
|
||||
clss = _class;
|
||||
args = _args;
|
||||
public TabInfo(String tag, Class<?> clss, Bundle bundle) {
|
||||
this.tag = tag;
|
||||
this.clss = clss;
|
||||
this.bundle = bundle;
|
||||
}
|
||||
}
|
||||
|
||||
static class DummyTabFactory implements TabHost.TabContentFactory {
|
||||
private final Context mContext;
|
||||
/**
|
||||
* A dummy {@link TabContentFactory} that creates an empty view to satisfy the
|
||||
* {@link TabHost} API.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
private static class DummyTabContentFactory implements TabContentFactory {
|
||||
|
||||
public DummyTabFactory(Context context) {
|
||||
mContext = context;
|
||||
private final Context context;
|
||||
|
||||
public DummyTabContentFactory(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createTabContent(String tag) {
|
||||
View v = new View(mContext);
|
||||
v.setMinimumWidth(0);
|
||||
v.setMinimumHeight(0);
|
||||
return v;
|
||||
View view = new View(context);
|
||||
view.setMinimumWidth(0);
|
||||
view.setMinimumHeight(0);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
public TabManager(FragmentActivity activity, TabHost tabHost, int containerId) {
|
||||
mActivity = activity;
|
||||
mTabHost = tabHost;
|
||||
mContainerId = containerId;
|
||||
mTabHost.setOnTabChangedListener(this);
|
||||
public TabManager(FragmentActivity fragmentActivity, TabHost tabHost, int containerId) {
|
||||
this.fragmentActivity = fragmentActivity;
|
||||
this.tabHost = tabHost;
|
||||
this.containerId = containerId;
|
||||
tabHost.setOnTabChangedListener(this);
|
||||
}
|
||||
|
||||
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
|
||||
tabSpec.setContent(new DummyTabFactory(mActivity));
|
||||
public void addTab(TabSpec tabSpec, Class<?> clss, Bundle bundle) {
|
||||
tabSpec.setContent(new DummyTabContentFactory(fragmentActivity));
|
||||
|
||||
String tag = tabSpec.getTag();
|
||||
TabInfo tabInfo = new TabInfo(tag, clss, bundle);
|
||||
|
||||
TabInfo info = new TabInfo(tag, clss, args);
|
||||
|
||||
// Check to see if we already have a fragment for this tab, probably
|
||||
// from a previously saved state. If so, deactivate it, because our
|
||||
// initial state is that a tab isn't shown.
|
||||
info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag);
|
||||
if (info.fragment != null && !info.fragment.isDetached()) {
|
||||
FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
|
||||
ft.detach(info.fragment);
|
||||
ft.commit();
|
||||
/*
|
||||
* Check to see if we already have a fragment for this tab, probably from a
|
||||
* previously saved state. If so, deactivate it, because our initial state
|
||||
* is that a tab isn't shown.
|
||||
*/
|
||||
tabInfo.fragment = fragmentActivity.getSupportFragmentManager().findFragmentByTag(tag);
|
||||
if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
|
||||
FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager()
|
||||
.beginTransaction();
|
||||
fragmentTransaction.detach(tabInfo.fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
mTabs.put(tag, info);
|
||||
mTabHost.addTab(tabSpec);
|
||||
tabs.put(tag, tabInfo);
|
||||
tabHost.addTab(tabSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabChanged(String tabId) {
|
||||
TabInfo newTab = mTabs.get(tabId);
|
||||
if (mLastTab != newTab) {
|
||||
FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
|
||||
if (mLastTab != null) {
|
||||
if (mLastTab.fragment != null) {
|
||||
ft.detach(mLastTab.fragment);
|
||||
TabInfo newTabInfo = tabs.get(tabId);
|
||||
if (lastTabInfo != newTabInfo) {
|
||||
FragmentTransaction fragmentTransaction = fragmentActivity.getSupportFragmentManager()
|
||||
.beginTransaction();
|
||||
if (lastTabInfo != null) {
|
||||
if (lastTabInfo.fragment != null) {
|
||||
fragmentTransaction.detach(lastTabInfo.fragment);
|
||||
}
|
||||
}
|
||||
if (newTab != null) {
|
||||
if (newTab.fragment == null) {
|
||||
newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args);
|
||||
ft.add(mContainerId, newTab.fragment, newTab.tag);
|
||||
if (newTabInfo != null) {
|
||||
if (newTabInfo.fragment == null) {
|
||||
newTabInfo.fragment = Fragment.instantiate(
|
||||
fragmentActivity, newTabInfo.clss.getName(), newTabInfo.bundle);
|
||||
fragmentTransaction.add(containerId, newTabInfo.fragment, newTabInfo.tag);
|
||||
} else {
|
||||
ft.attach(newTab.fragment);
|
||||
fragmentTransaction.attach(newTabInfo.fragment);
|
||||
}
|
||||
}
|
||||
|
||||
mLastTab = newTab;
|
||||
ft.commit();
|
||||
mActivity.getSupportFragmentManager().executePendingTransactions();
|
||||
lastTabInfo = newTabInfo;
|
||||
fragmentTransaction.commit();
|
||||
fragmentActivity.getSupportFragmentManager().executePendingTransactions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,6 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
public static final String EXTRA_WAYPOINT_ID = "waypoint_id";
|
||||
|
||||
private static final String TAG = TrackDetailActivity.class.getSimpleName();
|
||||
private static final String MARKET_URL_PREFIX = "market://details?id=";
|
||||
private static final String CURRENT_TAG_KEY = "tab";
|
||||
|
||||
private static final int DIALOG_INSTALL_EARTH_ID = 0;
|
||||
@@ -216,7 +215,7 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent()
|
||||
.setData(Uri.parse(MARKET_URL_PREFIX + SaveActivity.GOOGLE_EARTH_PACKAGE));
|
||||
.setData(Uri.parse(SaveActivity.GOOGLE_EARTH_MARKET_URL));
|
||||
startActivity(intent);
|
||||
}
|
||||
})
|
||||
@@ -626,7 +625,8 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
*/
|
||||
private boolean isEarthInstalled() {
|
||||
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(
|
||||
new Intent().setType(SaveActivity.KML_MIME_TYPE), PackageManager.MATCH_DEFAULT_ONLY);
|
||||
new Intent().setType(SaveActivity.GOOGLE_EARTH_KML_MIME_TYPE),
|
||||
PackageManager.MATCH_DEFAULT_ONLY);
|
||||
for (ResolveInfo info : infos) {
|
||||
if (info.activityInfo != null && info.activityInfo.packageName != null
|
||||
&& info.activityInfo.packageName.equals(SaveActivity.GOOGLE_EARTH_PACKAGE)) {
|
||||
|
||||
@@ -47,12 +47,15 @@ public class SaveActivity extends Activity {
|
||||
public static final String EXTRA_SHARE_TRACK = "share_track";
|
||||
public static final String EXTRA_PLAY_TRACK = "play_track";
|
||||
|
||||
public static final String KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
|
||||
public static final String GOOGLE_EARTH_KML_MIME_TYPE = "application/vnd.google-earth.kml+xml";
|
||||
public static final String GOOGLE_EARTH_PACKAGE = "com.google.earth";
|
||||
|
||||
private static final String TAG = SaveActivity.class.getSimpleName();
|
||||
private static final String TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
|
||||
public static final String GOOGLE_EARTH_MARKET_URL = "market://details?id="
|
||||
+ GOOGLE_EARTH_PACKAGE;
|
||||
private static final String
|
||||
GOOGLE_EARTH_TOUR_FEATURE_ID = "com.google.earth.EXTRA.tour_feature_id";
|
||||
private static final String GOOGLE_EARTH_CLASS = "com.google.earth.EarthActivity";
|
||||
|
||||
private static final String TAG = SaveActivity.class.getSimpleName();
|
||||
|
||||
private static final int DIALOG_PROGRESS_ID = 0;
|
||||
private static final int DIALOG_RESULT_ID = 1;
|
||||
@@ -211,9 +214,9 @@ public class SaveActivity extends Activity {
|
||||
} else if (playTrack) {
|
||||
Intent intent = new Intent()
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
|
||||
.putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID, KmlTrackWriter.TOUR_FEATURE_ID)
|
||||
.setClassName(GOOGLE_EARTH_PACKAGE, GOOGLE_EARTH_CLASS)
|
||||
.setDataAndType(Uri.fromFile(new File(filePath)), KML_MIME_TYPE);
|
||||
.setDataAndType(Uri.fromFile(new File(filePath)), GOOGLE_EARTH_KML_MIME_TYPE);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user