Moved loation listners from fragment to activity
This commit is contained in:
parent
d0da057585
commit
bdf161bbb8
2 changed files with 128 additions and 102 deletions
|
@ -9,6 +9,7 @@ import java.util.Random;
|
|||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.view.Gravity;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.access.AccessibleAlertBuilder;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
|
@ -50,7 +51,7 @@ import net.osmand.plus.views.controls.FloatingActionButton;
|
|||
|
||||
/**
|
||||
*/
|
||||
public class MainMenuActivity extends BaseDownloadActivity {
|
||||
public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
|
||||
private static final String LATEST_CHANGES_URL = "changes-1.9.html";
|
||||
public static final boolean TIPS_AND_TRICKS = false;
|
||||
public static final int APP_EXIT_CODE = 4;
|
||||
|
@ -68,18 +69,26 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
private static final int EXIT_ID = 2;
|
||||
private OsmAndLocationProvider lp;
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getMyApplication().getLocationProvider().removeCompassListener(this);
|
||||
getMyApplication().getLocationProvider().removeLocationListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getIntent() != null){
|
||||
if (getIntent() != null) {
|
||||
Intent intent = getIntent();
|
||||
if(intent.getExtras() != null && intent.getExtras().containsKey(APP_EXIT_KEY)){
|
||||
if (intent.getExtras() != null && intent.getExtras().containsKey(APP_EXIT_KEY)) {
|
||||
getMyApplication().closeApplication(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(Version.isSherpafy(getMyApplication())) {
|
||||
if (Version.isSherpafy(getMyApplication())) {
|
||||
final Intent mapIntent = new Intent(this, TourViewActivity.class);
|
||||
startActivity(mapIntent);
|
||||
finish();
|
||||
|
@ -89,7 +98,7 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
lp = getMyApplication().getLocationProvider();
|
||||
|
||||
String textVersion = Version.getFullVersion(getMyApplication());
|
||||
if(textVersion.indexOf("#") != -1) {
|
||||
if (textVersion.indexOf("#") != -1) {
|
||||
textVersion = textVersion.substring(0, textVersion.indexOf("#") + 1);
|
||||
}
|
||||
getSupportActionBar().setTitle(textVersion);
|
||||
|
@ -98,7 +107,7 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
getSupportActionBar().setIcon(android.R.color.transparent);
|
||||
|
||||
boolean firstTime = initApp(this, getMyApplication());
|
||||
if(getMyApplication().getAppCustomization().checkExceptionsOnStart()){
|
||||
if (getMyApplication().getAppCustomization().checkExceptionsOnStart()) {
|
||||
checkPreviousRunsForExceptions(firstTime);
|
||||
}
|
||||
setupContributionVersion();
|
||||
|
@ -119,10 +128,21 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) {
|
||||
getLocationProvider().addLocationListener(this);
|
||||
getLocationProvider().addCompassListener(this);
|
||||
getLocationProvider().registerOrUnregisterCompassListener(true);
|
||||
getLocationProvider().resumeAllUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(resultCode == APP_EXIT_CODE){
|
||||
if (resultCode == APP_EXIT_CODE) {
|
||||
getMyApplication().closeApplication(this);
|
||||
}
|
||||
}
|
||||
|
@ -155,20 +175,20 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
final String aboutString = getString(R.string.about_settings);
|
||||
SpannableString ss = new SpannableString(aboutString);
|
||||
ClickableSpan clickableSpan = new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View textView) {
|
||||
showAboutDialog(MainMenuActivity.this, getMyApplication());
|
||||
}
|
||||
@Override
|
||||
public void onClick(View textView) {
|
||||
showAboutDialog(MainMenuActivity.this, getMyApplication());
|
||||
}
|
||||
};
|
||||
ss.setSpan(clickableSpan, 0, aboutString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
about.setText(ss);
|
||||
about.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
private void addErrorFragment(){
|
||||
private void addErrorFragment() {
|
||||
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
|
||||
android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction();
|
||||
if (manager.findFragmentByTag(DashErrorFragment.TAG) == null){
|
||||
if (manager.findFragmentByTag(DashErrorFragment.TAG) == null) {
|
||||
DashErrorFragment errorFragment = new DashErrorFragment();
|
||||
fragmentTransaction.add(R.id.content, errorFragment, DashErrorFragment.TAG).commit();
|
||||
}
|
||||
|
@ -177,43 +197,43 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
public static void showAboutDialog(final Activity activity, final OsmandApplication app) {
|
||||
Builder bld = new AlertDialog.Builder(activity);
|
||||
bld.setTitle(R.string.about_settings);
|
||||
ScrollView sv = new ScrollView(activity);
|
||||
TextView tv = new TextView(activity);
|
||||
sv.addView(tv);
|
||||
ScrollView sv = new ScrollView(activity);
|
||||
TextView tv = new TextView(activity);
|
||||
sv.addView(tv);
|
||||
String version = Version.getFullVersion(app);
|
||||
String vt = activity.getString(R.string.about_version) +"\t";
|
||||
String vt = activity.getString(R.string.about_version) + "\t";
|
||||
int st = vt.length();
|
||||
String edition = "";
|
||||
if (!activity.getString(R.string.app_edition).equals("")) {
|
||||
edition = activity.getString(R.string.local_index_installed) + " : \t" + activity.getString(R.string.app_edition);
|
||||
}
|
||||
SharedPreferences prefs = app.getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE);
|
||||
if (prefs.contains(CONTRIBUTION_VERSION_FLAG) && Version.isDeveloperVersion(app)) {
|
||||
//Next 7 lines produced bogus Edition dates in many situtations, let us try (see above) to use the BUILD_ID as delivered from builder
|
||||
//try {
|
||||
//PackageManager pm = activity.getPackageManager();
|
||||
//ApplicationInfo appInfo = pm.getApplicationInfo(OsmandApplication.class.getPackage().getName(), 0);
|
||||
//Date date = new Date(new File(appInfo.sourceDir).lastModified());
|
||||
//edition = activity.getString(R.string.local_index_installed) + " : \t" + DateFormat.getDateFormat(app).format(date);
|
||||
//} catch (Exception e) {
|
||||
//}
|
||||
SpannableString content = new SpannableString(vt + version + "\n" +
|
||||
edition + "\n\n" +
|
||||
activity.getString(R.string.about_content));
|
||||
content.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
final Intent mapIntent = new Intent(activity, ContributionVersionActivity.class);
|
||||
activity.startActivityForResult(mapIntent, 0);
|
||||
}
|
||||
SharedPreferences prefs = app.getSharedPreferences("net.osmand.settings", MODE_WORLD_READABLE);
|
||||
if (prefs.contains(CONTRIBUTION_VERSION_FLAG) && Version.isDeveloperVersion(app)) {
|
||||
//Next 7 lines produced bogus Edition dates in many situtations, let us try (see above) to use the BUILD_ID as delivered from builder
|
||||
//try {
|
||||
//PackageManager pm = activity.getPackageManager();
|
||||
//ApplicationInfo appInfo = pm.getApplicationInfo(OsmandApplication.class.getPackage().getName(), 0);
|
||||
//Date date = new Date(new File(appInfo.sourceDir).lastModified());
|
||||
//edition = activity.getString(R.string.local_index_installed) + " : \t" + DateFormat.getDateFormat(app).format(date);
|
||||
//} catch (Exception e) {
|
||||
//}
|
||||
SpannableString content = new SpannableString(vt + version + "\n" +
|
||||
edition + "\n\n" +
|
||||
activity.getString(R.string.about_content));
|
||||
content.setSpan(new ClickableSpan() {
|
||||
@Override
|
||||
public void onClick(View widget) {
|
||||
final Intent mapIntent = new Intent(activity, ContributionVersionActivity.class);
|
||||
activity.startActivityForResult(mapIntent, 0);
|
||||
}
|
||||
|
||||
}, st, st + version.length(), 0);
|
||||
tv.setText(content);
|
||||
} else {
|
||||
tv.setText(vt + version + "\n" +
|
||||
edition + "\n\n" +
|
||||
activity.getString(R.string.about_content));
|
||||
}
|
||||
}, st, st + version.length(), 0);
|
||||
tv.setText(content);
|
||||
} else {
|
||||
tv.setText(vt + version + "\n" +
|
||||
edition + "\n\n" +
|
||||
activity.getString(R.string.about_content));
|
||||
}
|
||||
|
||||
tv.setPadding(5, 0, 5, 5);
|
||||
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
|
||||
|
@ -228,7 +248,7 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
protected boolean initApp(final Activity activity, OsmandApplication app) {
|
||||
final OsmAndAppCustomization appCustomization = app.getAppCustomization();
|
||||
// restore follow route mode
|
||||
if(app.getSettings().FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated()){
|
||||
if (app.getSettings().FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated()) {
|
||||
startMapActivity();
|
||||
return false;
|
||||
}
|
||||
|
@ -285,7 +305,7 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
netOsmandWasInstalled = false;
|
||||
}
|
||||
|
||||
if(netOsmandWasInstalled){
|
||||
if (netOsmandWasInstalled) {
|
||||
// Builder builder = new AccessibleAlertBuilder(this);
|
||||
// builder.setMessage(R.string.osmand_net_previously_installed);
|
||||
// builder.setPositiveButton(R.string.default_buttons_ok, null);
|
||||
|
@ -323,7 +343,6 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, HELP_ID, 0, R.string.tips_and_tricks).setIcon(R.drawable.ic_ac_help)
|
||||
|
@ -345,7 +364,7 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
|
||||
if (item.getItemId() == HELP_ID) {
|
||||
if(TIPS_AND_TRICKS) {
|
||||
if (TIPS_AND_TRICKS) {
|
||||
TipsAndTricksActivity activity = new TipsAndTricksActivity(this);
|
||||
Dialog dlg = activity.getDialogToShowTips(false, true);
|
||||
dlg.show();
|
||||
|
@ -353,10 +372,10 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
final Intent helpIntent = new Intent(this, HelpActivity.class);
|
||||
startActivity(helpIntent);
|
||||
}
|
||||
} else if (item.getItemId() == SETTINGS_ID){
|
||||
} else if (item.getItemId() == SETTINGS_ID) {
|
||||
final Intent settings = new Intent(this, appCustomization.getSettingsActivity());
|
||||
startActivity(settings);
|
||||
} else if (item.getItemId() == EXIT_ID){
|
||||
} else if (item.getItemId() == EXIT_ID) {
|
||||
getMyApplication().closeApplication(this);
|
||||
}
|
||||
return true;
|
||||
|
@ -369,9 +388,9 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
// do not show each time
|
||||
if (check && new Random().nextInt() % 5 == 1) {
|
||||
Builder builder = new AccessibleAlertBuilder(this);
|
||||
if(maps.isEmpty()){
|
||||
if (maps.isEmpty()) {
|
||||
builder.setMessage(R.string.vector_data_missing);
|
||||
} else if(!maps.basemapExists()){
|
||||
} else if (!maps.basemapExists()) {
|
||||
builder.setMessage(R.string.basemap_missing);
|
||||
} else {
|
||||
return;
|
||||
|
@ -413,37 +432,57 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
@Override
|
||||
public void updateProgress(boolean updateOnlyProgress) {
|
||||
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = BaseDownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
for(WeakReference<Fragment> ref : fragList) {
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if(f instanceof DashUpdatesFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((DashUpdatesFragment) f).updateProgress(basicProgressAsyncTask, updateOnlyProgress);
|
||||
}
|
||||
if (f instanceof DashUpdatesFragment && !f.isDetached()) {
|
||||
((DashUpdatesFragment) f).updateProgress(basicProgressAsyncTask, updateOnlyProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDownloadList(List<IndexItem> list){
|
||||
for(WeakReference<Fragment> ref : fragList) {
|
||||
public void updateDownloadList(List<IndexItem> list) {
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if(f instanceof DashUpdatesFragment) {
|
||||
if(!f.isDetached()) {
|
||||
if (downloadQueue.size() > 0){
|
||||
startDownload(downloadQueue.get(0));
|
||||
downloadQueue.remove(0);
|
||||
}
|
||||
((DashUpdatesFragment) f).updatedDownloadsList(list);
|
||||
if (f instanceof DashUpdatesFragment && !f.isDetached()) {
|
||||
if (downloadQueue.size() > 0) {
|
||||
startDownload(downloadQueue.get(0));
|
||||
downloadQueue.remove(0);
|
||||
}
|
||||
((DashUpdatesFragment) f).updatedDownloadsList(list);
|
||||
|
||||
}
|
||||
if(f instanceof DashDownloadMapsFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((DashDownloadMapsFragment) f).refreshData();
|
||||
}
|
||||
if (f instanceof DashDownloadMapsFragment && !f.isDetached()) {
|
||||
((DashDownloadMapsFragment) f).refreshData();
|
||||
}
|
||||
if(f instanceof DashAudioVideoNotesFragment && !f.isDetached()){
|
||||
|
||||
if (f instanceof DashAudioVideoNotesFragment && !f.isDetached()) {
|
||||
((DashAudioVideoNotesFragment) f).setupNotes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof DashFavoritesFragment && !f.isDetached()) {
|
||||
((DashFavoritesFragment) f).updateCompassValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
for (WeakReference<Fragment> ref : fragList) {
|
||||
Fragment f = ref.get();
|
||||
if (f instanceof DashFavoritesFragment && !f.isDetached()) {
|
||||
((DashFavoritesFragment) f).updateLocation(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OsmAndLocationProvider getLocationProvider() {
|
||||
return getMyApplication().getLocationProvider();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by Denis on 24.11.2014.
|
||||
*/
|
||||
public class DashFavoritesFragment extends DashBaseFragment implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
|
||||
public class DashFavoritesFragment extends DashBaseFragment {
|
||||
public static final String TAG = "DASH_FAVORITES_FRAGMENT";
|
||||
private net.osmand.Location location = null;
|
||||
private Float heading = null;
|
||||
|
@ -62,18 +62,12 @@ public class DashFavoritesFragment extends DashBaseFragment implements OsmAndLoc
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getLocationProvider().removeCompassListener(this);
|
||||
getLocationProvider().removeLocationListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) {
|
||||
registerListeners();
|
||||
if(!getMyApplication().getSettings().isLastKnownMapLocation()) {
|
||||
// show first time when application ran
|
||||
location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation();
|
||||
|
@ -88,12 +82,7 @@ public class DashFavoritesFragment extends DashBaseFragment implements OsmAndLoc
|
|||
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getLocationProvider().addLocationListener(this);
|
||||
getLocationProvider().addCompassListener(this);
|
||||
getLocationProvider().registerOrUnregisterCompassListener(true);
|
||||
getLocationProvider().resumeAllUpdates();
|
||||
}
|
||||
|
||||
|
||||
private void setupFavorites(){
|
||||
View mainView = getView();
|
||||
|
@ -189,13 +178,11 @@ public class DashFavoritesFragment extends DashBaseFragment implements OsmAndLoc
|
|||
direction.setImageDrawable(draw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
heading = value;
|
||||
updateArrows();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
if (location == null){
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue