mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-04 10:23:06 +02:00
Merging Sandor's changes.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.google.android.apps.mytracks.io.SendToMyMaps.OnSendCompletedListener;
|
||||
import com.google.android.apps.mytracks.io.TempFileCleaner;
|
||||
import com.google.android.apps.mytracks.io.TrackWriter;
|
||||
import com.google.android.apps.mytracks.io.TrackWriterFactory;
|
||||
import com.google.android.apps.mytracks.io.SendToMyMaps.OnSendCompletedListener;
|
||||
import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat;
|
||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||
import com.google.android.apps.mytracks.services.StatusAnnouncerFactory;
|
||||
@@ -67,9 +68,9 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager.BadTokenException;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TabHost;
|
||||
@@ -99,9 +100,10 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
private static MyTracks instance = null;
|
||||
private ChartActivity chartActivity = null;
|
||||
private static MyTracks instance;
|
||||
|
||||
private ChartActivity chartActivity;
|
||||
|
||||
public ChartActivity getChartActivity() {
|
||||
return chartActivity;
|
||||
}
|
||||
@@ -166,6 +168,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* Utilities to deal with the database.
|
||||
*/
|
||||
private MyTracksProviderUtils providerUtils;
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
/**
|
||||
* The connection to the track recording service.
|
||||
@@ -221,20 +225,35 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we have a track recording session in progress.
|
||||
* In some cases, when the service has crashed or has been restarted
|
||||
* by the system, we fall back to the shared preferences.
|
||||
*
|
||||
* @return true if the activity is bound to the track recording service and
|
||||
* the service is recording a track.
|
||||
* the service is recording a track or in case the service is down,
|
||||
* based on settings from the shared preferences.
|
||||
*/
|
||||
public boolean isRecording() {
|
||||
if (trackRecordingService == null) {
|
||||
return false;
|
||||
// Fall back to alternative check method.
|
||||
return isRecordingBasedOnSharedPreferences();
|
||||
}
|
||||
try {
|
||||
return trackRecordingService.isRecording();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(MyTracksConstants.TAG, "MyTracks: Remote exception.", e);
|
||||
return false;
|
||||
|
||||
// Fall back to alternative check method.
|
||||
return isRecordingBasedOnSharedPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRecordingBasedOnSharedPreferences() {
|
||||
// TrackRecordingServices guarantees that recordingTrackId is set to
|
||||
// -1 if the track has been stopped.
|
||||
// TODO: Refresh recordingTrackId.
|
||||
return recordingTrackId >= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Application lifetime events:
|
||||
@@ -248,6 +267,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
instance = this;
|
||||
providerUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
menuManager = new MenuManager(this);
|
||||
sharedPreferences = getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
dialogManager = new DialogManager(this);
|
||||
|
||||
// The volume we want to control is the Text-To-Speech volume
|
||||
@@ -285,14 +305,18 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
tabHost.addView(layout);
|
||||
layout.setOnTouchListener(this);
|
||||
|
||||
SharedPreferences prefs =
|
||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
if (prefs != null) {
|
||||
if (sharedPreferences != null) {
|
||||
selectedTrackId =
|
||||
prefs.getLong(getString(R.string.selected_track_key), -1);
|
||||
recordingTrackId =
|
||||
prefs.getLong(getString(R.string.recording_track_key), -1);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
sharedPreferences.getLong(getString(R.string.selected_track_key), -1);
|
||||
recordingTrackId = sharedPreferences.getLong(
|
||||
getString(R.string.recording_track_key), -1);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
Log.d(MyTracksConstants.TAG, "recordingTrackId: " + recordingTrackId
|
||||
+ ", selectedTrackId: " + selectedTrackId);
|
||||
if (recordingTrackId > 0) {
|
||||
Intent startIntent = new Intent(this, TrackRecordingService.class);
|
||||
startService(startIntent);
|
||||
}
|
||||
}
|
||||
|
||||
// This will show the eula until the user accepts or quits the app.
|
||||
@@ -850,20 +874,15 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
getResources().getText(R.string.share_map_subject).toString());
|
||||
|
||||
SharedPreferences prefs =
|
||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
boolean shareUrlOnly = true;
|
||||
if (prefs != null) {
|
||||
shareUrlOnly =
|
||||
prefs.getBoolean(getString(R.string.share_url_only_key), false);
|
||||
if (sharedPreferences != null) {
|
||||
shareUrlOnly = sharedPreferences.getBoolean(
|
||||
getString(R.string.share_url_only_key), false);
|
||||
}
|
||||
|
||||
String url = MyMapsConstants.MAPSHOP_BASE_URL + "?msa=0&msid=" + mapId;
|
||||
String msg = (shareUrlOnly
|
||||
? url
|
||||
: String.format(
|
||||
getResources().getText(R.string.share_map_body_format).toString(),
|
||||
url));
|
||||
String msg = shareUrlOnly ? url : String.format(
|
||||
getResources().getText(R.string.share_map_body_format).toString(), url);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
|
||||
startActivity(Intent.createChooser(shareIntent,
|
||||
getResources().getText(R.string.share_map).toString()));
|
||||
@@ -1077,9 +1096,10 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
private void startRecordingNewTrack() {
|
||||
try {
|
||||
recordingTrackId = trackRecordingService.startNewTrack();
|
||||
// Select the recording track.
|
||||
setSelectedTrack(recordingTrackId);
|
||||
Toast.makeText(this, getString(R.string.status_now_recording),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
setSelectedAndRecordingTrack(recordingTrackId, recordingTrackId);
|
||||
} catch (RemoteException e) {
|
||||
Toast.makeText(this,
|
||||
getString(R.string.error_unable_to_start_recording),
|
||||
@@ -1114,7 +1134,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
} catch (RemoteException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to stop recording.", e);
|
||||
}
|
||||
setRecordingTrack(-1);
|
||||
Intent intent = new Intent(MyTracks.this, MyTracksDetails.class);
|
||||
intent.putExtra("trackid", recordingTrackId);
|
||||
intent.putExtra("hasCancelButton", false);
|
||||
@@ -1171,9 +1190,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
public void setSelectedTrack(final long trackId) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
SharedPreferences prefs =
|
||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putLong(getString(R.string.selected_track_key), trackId);
|
||||
editor.commit();
|
||||
}
|
||||
@@ -1184,46 +1201,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
return selectedTrackId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the recording track id to the shared preferences.
|
||||
* Executed on the UI thread.
|
||||
*
|
||||
* @param trackId the id of the track
|
||||
*/
|
||||
private void setRecordingTrack(final long trackId) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
SharedPreferences prefs =
|
||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putLong(getString(R.string.recording_track_key), trackId);
|
||||
editor.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the selected and the recording track id to the shared preferences.
|
||||
* Executed on UI thread.
|
||||
*/
|
||||
private void setSelectedAndRecordingTrack(final long theSelectedTrackId,
|
||||
final long theRecordingTrackId) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
SharedPreferences prefs =
|
||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||
if (prefs != null) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putLong(getString(R.string.selected_track_key),
|
||||
theSelectedTrackId);
|
||||
editor.putLong(getString(R.string.recording_track_key),
|
||||
theRecordingTrackId);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds to track recording service if it is running.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user