diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java b/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java index bdf5b6a70e..8880184f96 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/io/NetworkUtils.java @@ -82,9 +82,9 @@ public class NetworkUtils { } return null; } catch (InterruptedException e) { - e.printStackTrace(); + log.error(e); } catch (ExecutionException e) { - e.printStackTrace(); + log.error(e); } return null; } @@ -166,7 +166,7 @@ public class NetworkUtils { Algorithms.closeStream(ous); return ous.toByteArray(); } catch (IOException e) { - e.printStackTrace(); + log.error(e); } return new byte[0]; } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java index ed2854bb02..5726855f72 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/oauth/OsmOAuthAuthorizationClient.java @@ -6,6 +6,8 @@ import com.github.scribejava.core.builder.api.DefaultApi10a; import com.github.scribejava.core.builder.api.OAuth1SignatureType; import com.github.scribejava.core.model.*; import com.github.scribejava.core.oauth.OAuth10aService; +import net.osmand.PlatformUtil; +import org.apache.commons.logging.Log; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -16,9 +18,10 @@ import java.util.concurrent.ExecutionException; * @since 2746 */ public class OsmOAuthAuthorizationClient { - OAuth10aService service; - OAuth1RequestToken requestToken; - OAuth1AccessToken accessToken; + private OAuth1RequestToken requestToken; + private OAuth1AccessToken accessToken; + private final OAuth10aService service; + public final static Log log = PlatformUtil.getLog(OsmOAuthAuthorizationClient.class); public OsmOAuthAuthorizationClient(String key, String secret) { service = new ServiceBuilder(key) @@ -58,7 +61,7 @@ public class OsmOAuthAuthorizationClient { } public OAuth1AccessToken getAccessToken() { - return this.accessToken; + return accessToken; } public Response performRequestWithoutAuth(String url, String requestMethod, String requestBody) @@ -96,11 +99,11 @@ public class OsmOAuthAuthorizationClient { try { requestToken = service.getRequestToken(); } catch (IOException e) { - e.printStackTrace(); + log.error(e); } catch (InterruptedException e) { - e.printStackTrace(); + log.error(e); } catch (ExecutionException e) { - e.printStackTrace(); + log.error(e); } return requestToken; } @@ -109,11 +112,11 @@ public class OsmOAuthAuthorizationClient { try { setAccessToken(service.getAccessToken(requestToken, oauthVerifier)); } catch (IOException e) { - e.printStackTrace(); + log.error(e); } catch (InterruptedException e) { - e.printStackTrace(); + log.error(e); } catch (ExecutionException e) { - e.printStackTrace(); + log.error(e); } return accessToken; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 8f826e76b1..450d7e4b0d 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -59,8 +59,8 @@ public class DownloadIndexesThread { private ConcurrentLinkedQueue indexItemDownloading = new ConcurrentLinkedQueue(); private IndexItem currentDownloadingItem = null; private int currentDownloadingItemProgress = 0; - private DownloadResources indexes; + private static final int THREAD_ID = 10103; public interface DownloadEvents { @@ -337,7 +337,6 @@ public class DownloadIndexesThread { @Override protected DownloadResources doInBackground(Void... params) { - final int THREAD_ID = 10103; TrafficStats.setThreadStatsTag(THREAD_ID); DownloadResources result = null; DownloadOsmandIndexesHelper.IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index 74eb48c1b4..e978c3841b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -180,7 +180,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { id = Long.parseLong(response); } } catch (Exception e) { - e.printStackTrace(); + log.error(e); } return id; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java index 75b226eb3f..724f798bf7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java @@ -109,7 +109,7 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil { private OsmBugResult editingPOI(String url, String requestMethod, String userOperation, boolean anonymous) { - OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(this.app); + OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app); OsmBugResult r = new OsmBugResult(); try { HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/SettingsOsmEditingActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/SettingsOsmEditingActivity.java index c4c8cb8d38..6be8066553 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/SettingsOsmEditingActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/SettingsOsmEditingActivity.java @@ -19,17 +19,20 @@ import android.widget.TextView; import android.widget.Toast; import com.github.scribejava.core.model.OAuthAsyncRequestCallback; import com.github.scribejava.core.model.Response; +import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; import net.osmand.plus.settings.backend.OsmAndAppCustomization; +import org.apache.commons.logging.Log; import java.io.IOException; public class SettingsOsmEditingActivity extends SettingsBaseActivity { - OsmOAuthAuthorizationAdapter client; + private OsmOAuthAuthorizationAdapter client; + private static final Log log = PlatformUtil.getLog(SettingsOsmEditingActivity.class); @Override public void onCreate(Bundle savedInstanceState) { @@ -43,7 +46,7 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity { ((OsmandApplication) getApplication()).applyTheme(this); super.onCreate(savedInstanceState); - client = new OsmOAuthAuthorizationAdapter(this.getMyApplication()); + client = new OsmOAuthAuthorizationAdapter(getMyApplication()); getToolbar().setTitle(R.string.osm_settings); @SuppressWarnings("deprecation") @@ -78,12 +81,12 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity { if (client.isValidToken()){ prefOAuth.setTitle(R.string.osm_authorization_success); prefOAuth.setSummary(R.string.osm_authorization_success); - prefOAuth.setKey("local_openstreetmap_token"); + prefOAuth.setKey("local_openstreetmap_oauth_success"); final Preference prefTestUser = new Preference(this); prefTestUser.setTitle(R.string.test_user_request); prefTestUser.setSummary(R.string.test_user_request_description); - prefTestUser.setKey("local_openstreetmap_token"); + prefTestUser.setKey("local_openstreetmap_oauth_user"); prefTestUser.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -94,7 +97,7 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity { try { Toast.makeText(SettingsOsmEditingActivity.this,response.getBody(),Toast.LENGTH_SHORT).show(); } catch (IOException e) { - e.printStackTrace(); + log.error(e); } } @@ -110,7 +113,7 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity { final Preference prefClearToken = new Preference(this); prefClearToken.setTitle(R.string.shared_string_logoff); prefClearToken.setSummary(R.string.clear_osm_token); - prefClearToken.setKey("local_openstreetmap_token"); + prefClearToken.setKey("local_openstreetmap_oauth_clear"); prefClearToken.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -128,7 +131,7 @@ public class SettingsOsmEditingActivity extends SettingsBaseActivity { else { prefOAuth.setTitle(R.string.perform_oauth_authorization); prefOAuth.setSummary(R.string.perform_oauth_authorization_description); - prefOAuth.setKey("local_openstreetmap_token"); + prefOAuth.setKey("local_openstreetmap_oauth_login"); prefOAuth.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java b/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java index 3824d060c7..285c359656 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java @@ -25,6 +25,7 @@ public class UploadOpenstreetmapPointAsyncTask private OsmEditingPlugin plugin; private final boolean closeChangeSet; private final boolean loadAnonymous; + private static final int THREAD_ID = 10102; public UploadOpenstreetmapPointAsyncTask(ProgressDialogFragment progress, OsmEditsUploadListener listener, @@ -44,7 +45,6 @@ public class UploadOpenstreetmapPointAsyncTask @Override protected Map doInBackground(OsmPoint... points) { - final int THREAD_ID = 10102; TrafficStats.setThreadStatsTag(THREAD_ID); Map loadErrorsMap = new HashMap<>(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthAuthorizationAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthAuthorizationAdapter.java index 47757317f7..09a3dba0c4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthAuthorizationAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/oauth/OsmOAuthAuthorizationAdapter.java @@ -16,11 +16,11 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; public class OsmOAuthAuthorizationAdapter { - OsmandApplication application; - OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET); + private OsmandApplication application; + private OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET); + private static final int THREAD_ID = 10101; public OsmOAuthAuthorizationAdapter(OsmandApplication application) { - final int THREAD_ID = 10101; TrafficStats.setThreadStatsTag(THREAD_ID); this.application = application; restoreToken();