diff options
author | mvglasow <michael -at- vonglasow.com> | 2018-09-29 20:49:49 +0300 |
---|---|---|
committer | mvglasow <michael -at- vonglasow.com> | 2018-09-29 20:49:49 +0300 |
commit | ac447a4aa4d97f26765ee313e5164ac7ca726148 (patch) | |
tree | fc525e8ebe9d9d81c2cf659975d7475bd2742d60 | |
parent | d0210eb1536b5072abecde26254bd32a6546102d (diff) | |
download | navit-ac447a4aa4d97f26765ee313e5164ac7ca726148.tar.gz |
Refactor:traffic/traff_android:Clean up some errors found by CodeFactor
Signed-off-by: mvglasow <michael -at- vonglasow.com>
-rw-r--r-- | navit/android/src/org/navitproject/navit/NavitTraff.java | 112 |
1 files changed, 60 insertions, 52 deletions
diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 7d99ac397..a45ad2197 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -32,69 +32,77 @@ import android.util.Log; import java.util.List; /** - * @brief The TraFF receiver implementation + * @brief The TraFF receiver implementation. + * + * This class registers the broadcast receiver for TraFF feeds, polls all registered sources once on creation, receives + * TraFF feeds and forwards them to the traffic module for processing. */ public class NavitTraff extends BroadcastReceiver { - public static String ACTION_TRAFF_FEED = "org.traffxml.traff.FEED"; + public static String ACTION_TRAFF_FEED = "org.traffxml.traff.FEED"; - public static String ACTION_TRAFF_POLL = "org.traffxml.traff.POLL"; + public static String ACTION_TRAFF_POLL = "org.traffxml.traff.POLL"; - public static String EXTRA_FEED = "feed"; + public static String EXTRA_FEED = "feed"; - /** Identifier for the callback function */ - private int cbid; + /** Identifier for the callback function. */ + private int cbid; - private Context context = null; + private Context context = null; - /** An intent filter for TraFF events */ - private IntentFilter traffFilter = new IntentFilter(); + /** An intent filter for TraFF events. */ + private IntentFilter traffFilter = new IntentFilter(); - /** - * @brief Called when a TraFF feed is received. - * - * @param id The identifier for the native callback implementation - * @param feed The TraFF feed - */ - public native void onFeedReceived(int id, String feed); + /** + * @brief Called when a TraFF feed is received. + * + * This method forwards the newly received feed to the traffic module for processing. + * + * @param id The identifier for the native callback implementation + * @param feed The TraFF feed + */ + public native void onFeedReceived(int id, String feed); - /** - * @brief Creates a new {@code NavitTraff} instance. - * - * @param context The context - * @param cbid The callback identifier for the native method to call upon receiving a feed - */ - NavitTraff(Context context, int cbid) { - this.context = context; - this.cbid = cbid; + /** + * @brief Creates a new {@code NavitTraff} instance. + * + * Creating a new {@code NavitTraff} instance registers a broadcast receiver for TraFF broadcasts and polls all + * registered sources once to ensure we have messages which were received by these sources before we started up. + * + * @param context The context + * @param cbid The callback identifier for the native method to call upon receiving a feed + */ + NavitTraff(Context context, int cbid) { + this.context = context; + this.cbid = cbid; - traffFilter.addAction(ACTION_TRAFF_FEED); - traffFilter.addAction(ACTION_TRAFF_POLL); + traffFilter.addAction(ACTION_TRAFF_FEED); + traffFilter.addAction(ACTION_TRAFF_POLL); - context.registerReceiver(this, traffFilter); - /* TODO unregister receiver on exit */ + context.registerReceiver(this, traffFilter); + /* TODO unregister receiver on exit */ - /* Broadcast a poll intent */ - Intent outIntent = new Intent(ACTION_TRAFF_POLL); - PackageManager pm = context.getPackageManager(); - List<ResolveInfo> receivers = pm.queryBroadcastReceivers(outIntent, 0); - if (receivers != null) - for (ResolveInfo receiver : receivers) { - ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, - receiver.activityInfo.name); - outIntent = new Intent(ACTION_TRAFF_POLL); - outIntent.setComponent(cn); - context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); - } - } + /* Broadcast a poll intent */ + Intent outIntent = new Intent(ACTION_TRAFF_POLL); + PackageManager pm = context.getPackageManager(); + List<ResolveInfo> receivers = pm.queryBroadcastReceivers(outIntent, 0); + if (receivers != null) + for (ResolveInfo receiver : receivers) { + ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, + receiver.activityInfo.name); + outIntent = new Intent(ACTION_TRAFF_POLL); + outIntent.setComponent(cn); + context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); + } + } - @Override - public void onReceive(Context context, Intent intent) { - if ((intent != null) && (intent.getAction().equals(ACTION_TRAFF_FEED))) { - String feed = intent.getStringExtra(EXTRA_FEED); - if (feed == null) - Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); - else - onFeedReceived(cbid, feed); - } - } + @Override + public void onReceive(Context context, Intent intent) { + if ((intent != null) && (intent.getAction().equals(ACTION_TRAFF_FEED))) { + String feed = intent.getStringExtra(EXTRA_FEED); + if (feed == null) + Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); + else + onFeedReceived(cbid, feed); + } + } } |