Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add print example
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Aug 2, 2016
1 parent 94a5869 commit ed821c0
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,22 @@
android:name="@string/category"
android:value="@string/category_fragment" />
</activity>

<activity android:name=".activity.style.RuntimeStyleActivity"
android:description="@string/description_runtime_style"
android:label="@string/activity_runtime_style">
<activity
android:name=".activity.style.RuntimeStyleActivity"
android:description="@string/description_runtime_style"
android:label="@string/activity_runtime_style">
<meta-data
android:name="@string/category"
android:value="@string/category_style" />
</activity>
<activity
android:name=".activity.imagegenerator.PrintActivity"
android:description="@string/description_print"
android:label="@string/activity_print">
<meta-data
android:name="@string/category"
android:value="@string/category_imagegenerator" />
</activity>

<!-- Configuration Settings -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,8L5,8c-1.66,0 -3,1.34 -3,3v6h4v4h12v-4h4v-6c0,-1.66 -1.34,-3 -3,-3zM16,19L8,19v-5h8v5zM19,12c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM18,3L6,3v4h12L18,3z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

</android.support.v7.widget.Toolbar>

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_print_24dp"
app:backgroundTint="@color/accent"/>

</android.support.design.widget.CoordinatorLayout>

</FrameLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<string name="activity_viewpager">ViewPager</string>
<string name="title_activity_navigation_drawer">Navigation Drawer</string>
<string name="activity_runtime_style">Runtime Style</string>
<string name="activity_print">Print a map</string>

<!-- Description -->
<string name="description_user_location_tracking">Tracks the location of the user</string>
Expand Down Expand Up @@ -94,6 +95,7 @@
<string name="description_viewpager">Use SupportMapFragments in a ViewPager</string>
<string name="description_navigation_drawer">Test for Navigation Drawer support</string>
<string name="description_runtime_style">Adopt the map style on the fly</string>
<string name="description_print">Shows how to print a map</string>

<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
Expand Down

0 comments on commit ed821c0

Please sign in to comment.