Skip to content

Feature/mapcache 817 #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputEditText;

import org.jetbrains.annotations.NotNull;
import org.locationtech.proj4j.units.Units;

Expand Down Expand Up @@ -166,6 +165,7 @@
import mil.nga.mapcache.preferences.PreferencesActivity;
import mil.nga.mapcache.repository.GeoPackageModifier;
import mil.nga.mapcache.repository.sensors.SensorHandler;
import mil.nga.mapcache.utils.MatomoEventDispatcher;
import mil.nga.mapcache.utils.SwipeController;
import mil.nga.mapcache.utils.ViewAnimation;
import mil.nga.mapcache.view.GeoPackageAdapter;
Expand Down Expand Up @@ -477,6 +477,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
*/
public void launchPreferences() {
try {
MatomoEventDispatcher.Companion.submitButtonClickEvent("Settings");
Intent intent = new Intent(getContext(), PreferencesActivity.class);
preferencePageActivityResultLauncher.launch(intent);
} catch (Exception e) {
Expand Down Expand Up @@ -876,6 +877,7 @@ public void onShareGP(String gpName) {

gpkgData = new GpkgDataToExport(gpName, databaseFile);
showSaveOrShareDialog(gpkgData);
MatomoEventDispatcher.Companion.submitButtonClickEvent("Share GeoPackage");
}


Expand All @@ -901,13 +903,15 @@ public void showSaveOrShareDialog(GpkgDataToExport gpkgData){
ShareGpkgExecutor shareExec = new ShareGpkgExecutor(getActivity(), gpkgData);
shareExec.shareDatabaseViaIntent();
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Share with apps");
});

// Click listener for "Save"
alertView.findViewById(R.id.share_menu_save_card)
.setOnClickListener(v -> {
sendIntentForGpkgFileCreation(gpkgData);
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Save to storage");
});

alertDialog.show();
Expand Down Expand Up @@ -1095,6 +1099,8 @@ public void onCancelButtonClicked() {
*/
public void openMapSelect() {
if (getActivity() != null) {
MatomoEventDispatcher.Companion.submitButtonClickEvent("BaseMap Selection");

Context wrapper = new ContextThemeWrapper(getContext(), R.style.MyPopupMenu);
PopupMenu pm = new PopupMenu(wrapper, mapSelectButton);
// Needed to make the icons visible
Expand Down Expand Up @@ -1409,6 +1415,7 @@ private void setNewLayerFab() {
String geoName = detailPageAdapter.getGeoPackageName();
if (geoName != null) {
newLayerWizard();
MatomoEventDispatcher.Companion.submitButtonClickEvent("New GeoPackage Layer");
}
});
}
Expand Down Expand Up @@ -1577,6 +1584,8 @@ private void showMaxFeaturesExceeded() {
*/
private void createNewWizard() {
if (getActivity() != null) {
MatomoEventDispatcher.Companion.submitButtonClickEvent("New Geopackage");

// Create Alert window with basic input text layout
LayoutInflater inflater = LayoutInflater.from(getActivity());
View alertView = inflater.inflate(R.layout.new_geopackage_wizard, null);
Expand All @@ -1595,20 +1604,23 @@ private void createNewWizard() {
.setOnClickListener((View v) -> {
createGeoPackage();
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Create New");
});

// Click listener for "Import URL"
alertView.findViewById(R.id.new_wizard_download_card)
.setOnClickListener((View v) -> {
showGpkgImportFromUrlDialog();
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Import from URL");
});

// Click listener for "Import from file"
alertView.findViewById(R.id.new_wizard_file_card)
.setOnClickListener((View v) -> {
importGeopackageFromFile();
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Import from File");
});

alertDialog.show();
Expand Down Expand Up @@ -1692,6 +1704,7 @@ public void newLayerWizard() {
createFeature.setOnClickListener((View v) -> {
createFeatureOption();
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Create Feature Layer");
});

// Listener for create tiles
Expand All @@ -1702,6 +1715,7 @@ public void newLayerWizard() {
newTileLayerWizard(geoName);
}
alertDialog.dismiss();
MatomoEventDispatcher.Companion.submitButtonClickEvent("Create Tile Layer");
});


Expand Down
19 changes: 12 additions & 7 deletions mapcache/src/main/java/mil/nga/mapcache/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import java.util.Arrays;

import org.matomo.sdk.Matomo;
import org.matomo.sdk.Tracker;
import org.matomo.sdk.TrackerBuilder;
import org.matomo.sdk.extra.TrackHelper;

import mil.nga.mapcache.io.MapCacheFileUtils;
import mil.nga.mapcache.utils.MatomoEventDispatcher;
import mil.nga.mapcache.utils.MatomoHeartBeatManager;

/**
* Main Activity
Expand All @@ -36,6 +37,8 @@ public class MainActivity extends AppCompatActivity {
*/
private GeoPackageMapFragment mapFragment;

private MatomoHeartBeatManager matomoHeartBeatManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -60,12 +63,11 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

String siteUrl = getString(R.string.matomo_url);
int siteId = getResources().getInteger(R.integer.matomo_site_id);
MatomoEventDispatcher.Companion.submitScreenEvent("/Main Activity", "App Opened");

Tracker tracker = new TrackerBuilder(siteUrl, siteId, "MapCacheTracker").build(Matomo.getInstance(this));
TrackHelper.track().screen("/Main Activity").title("App Opened").with(tracker);
tracker.dispatch();
Tracker tracker = MapCacheApplication.Companion.getMatomoTracker();
matomoHeartBeatManager = new MatomoHeartBeatManager(15);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the class defaults with 15 you probably don't need to specify it here.

getLifecycle().addObserver(matomoHeartBeatManager);
}

@Override
Expand Down Expand Up @@ -145,5 +147,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
protected void onDestroy() {
super.onDestroy();
MapCacheApplication.Companion.deleteCacheFiles();
if (matomoHeartBeatManager != null) {
matomoHeartBeatManager.destroy();
}
}
}
15 changes: 15 additions & 0 deletions mapcache/src/main/java/mil/nga/mapcache/MapCacheApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ package mil.nga.mapcache
import android.app.Application
import mil.nga.mapcache.io.CacheDirectoryType
import mil.nga.mapcache.io.MapCacheFileUtils
import org.matomo.sdk.Matomo
import org.matomo.sdk.Tracker
import org.matomo.sdk.TrackerBuilder

class MapCacheApplication: Application() {
companion object {
lateinit var appInstance: MapCacheApplication
private set

lateinit var matomoTracker: Tracker
private set

//delete files from cache directories
fun deleteCacheFiles() {
MapCacheFileUtils.deleteCacheFiles(CacheDirectoryType.images)
Expand All @@ -19,8 +25,17 @@ class MapCacheApplication: Application() {
override fun onCreate() {
super.onCreate()
appInstance = this
matomoTracker = createMatomoTracker()

deleteCacheFiles()
}

private fun createMatomoTracker(): Tracker {
val siteUrl = getString(R.string.matomo_url)
val siteId = resources.getInteger(R.integer.matomo_site_id)

return TrackerBuilder(siteUrl, siteId, "MapCacheTracker").build(Matomo.getInstance(this))
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

public class AboutMapcacheActivity extends AppCompatActivity {

Expand All @@ -17,6 +18,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new AboutMapcacheActivityFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/About MapCache Activity", "About MapCache Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

/**
* The activity where the user can configure their basemaps.
Expand All @@ -19,6 +20,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new BasemapSettingsFragment(this)).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/BaseMap Settings Activity", "BaseMap Settings Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

public class DisclaimerActivity extends AppCompatActivity {

Expand All @@ -17,6 +18,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new DisclaimerFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/Disclaimer Activity", "Disclaimer Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.preference.PreferenceFragmentCompat;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

/**
* Activity for the Preferences menu
Expand All @@ -34,6 +35,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new PreferencesFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/Preferences Activity", "Settings Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

public class PrivacyPolicyActivity extends AppCompatActivity {

Expand All @@ -23,6 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new PrivacyPolicyFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/Privacy Policy Activity", "Privacy Policy Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

public class TileUrlActivity extends AppCompatActivity {
@Override
Expand All @@ -16,6 +17,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new TileUrlFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/Add Tile Server Activity", "Add Tile Server Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.appcompat.app.AppCompatActivity;

import mil.nga.mapcache.R;
import mil.nga.mapcache.utils.MatomoEventDispatcher;

public class TutorialActivity extends AppCompatActivity {

Expand All @@ -17,6 +18,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Adds back arrow button to action bar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, new TutorialFragment()).commit();

MatomoEventDispatcher.Companion.submitScreenEvent("/Tutorial Activity", "Tutorial Opened");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mil.nga.mapcache.utils

import mil.nga.mapcache.MapCacheApplication
import org.matomo.sdk.extra.TrackHelper

class MatomoEventDispatcher {

enum class EventTypes {
BUTTON_CLICK,
APPLICATION
}

companion object{
private val tracker = MapCacheApplication.matomoTracker

//button click tracking
fun submitButtonClickEvent(buttonName: String) {
TrackHelper.track().event(EventTypes.BUTTON_CLICK.toString(), buttonName).with(tracker)
tracker.dispatch()
}

//screen tracking
fun submitScreenEvent(screenName: String, title: String) {
TrackHelper.track().screen(screenName).title(title).with(tracker)
tracker.dispatch()
}

//heart beat tracking
fun submitHeartBeat() {
TrackHelper.track().event(EventTypes.APPLICATION.toString(), "HeartBeat").with(tracker)
tracker.dispatch()
}
}
}
Loading