diff options
author | Tobrun Van Nuland <tobrun.van.nuland@gmail.com> | 2016-07-29 18:16:00 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2016-08-02 16:03:17 -0400 |
commit | ed821c06d96e414b43db6fd1505389803cb022d4 (patch) | |
tree | 5ba41a266c9a8780a3caf31b447535a031fb476f /platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp | |
parent | 94a58691e24cd0760f9a3c2ac1a9322aa7854367 (diff) | |
download | qtlocation-mapboxgl-ed821c06d96e414b43db6fd1505389803cb022d4.tar.gz |
[android] - add print example
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java new file mode 100644 index 0000000000..4d19b4702e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java @@ -0,0 +1,112 @@ +package com.mapbox.mapboxsdk.testapp.activity.imagegenerator; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.Bundle; +import android.app.Activity; +import android.support.annotation.NonNull; +import android.support.v4.print.PrintHelper; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.testapp.R; +import com.mapbox.mapboxsdk.testapp.activity.annotation.BulkMarkerActivity; + +public class PrintActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback { + + private MapView mMapView; + private MapboxMap mMapboxMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_print); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowHomeEnabled(true); + } + + mMapView = (MapView) findViewById(R.id.mapView); + mMapView.onCreate(savedInstanceState); + mMapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(@NonNull MapboxMap mapboxMap) { + mMapboxMap = mapboxMap; + } + }); + + final View fab = findViewById(R.id.fab); + if (fab != null) { + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(mMapboxMap!=null) { + mMapboxMap.snapshot(PrintActivity.this); + } + } + }); + } + } + + @Override + public void onSnapshotReady(Bitmap snapshot) { + PrintHelper photoPrinter = new PrintHelper(this); + photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT); + photoPrinter.printBitmap("map.jpg - mapbox print job", snapshot); + } + + @Override + public void onResume() { + super.onResume(); + mMapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mMapView.onPause(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mMapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mMapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mMapView.onLowMemory(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + +} |