Example usage for android.os BadParcelableException printStackTrace

List of usage examples for android.os BadParcelableException printStackTrace

Introduction

In this page you can find the example usage for android.os BadParcelableException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:de.j4velin.mapsmeasure.Map.java

@SuppressLint("NewApi")
@Override/*from  ww w. ja v  a 2s. c  o m*/
public void onCreate(final Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
    } catch (final BadParcelableException bpe) {
        bpe.printStackTrace();
    }
    setContentView(R.layout.activity_map);

    formatter_no_dec.setMaximumFractionDigits(0);
    formatter_two_dec.setMaximumFractionDigits(2);

    final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE);

    // use metric a the default everywhere, except in the US
    metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US));

    final View topCenterOverlay = findViewById(R.id.topCenterOverlay);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    final View menuButton = findViewById(R.id.menu);
    if (menuButton != null) {
        menuButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                mDrawerLayout.openDrawer(GravityCompat.START);
            }
        });
    }

    if (mDrawerLayout != null) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

            private boolean menuButtonVisible = true;

            @Override
            public void onDrawerStateChanged(int newState) {

            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onDrawerSlide(final View drawerView, final float slideOffset) {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setAlpha(1 - slideOffset);
                if (menuButtonVisible && menuButton != null && slideOffset > 0) {
                    menuButton.setVisibility(View.INVISIBLE);
                    menuButtonVisible = false;
                }
            }

            @Override
            public void onDrawerOpened(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onDrawerClosed(final View drawerView) {
                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
                    topCenterOverlay.setVisibility(View.VISIBLE);
                if (menuButton != null) {
                    menuButton.setVisibility(View.VISIBLE);
                    menuButtonVisible = true;
                }
            }
        });
    }

    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (mMap == null) {
        Dialog d = GooglePlayServicesUtil
                .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0);
        d.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        });
        d.show();
        return;
    }

    marker = BitmapDescriptorFactory.fromResource(R.drawable.marker);
    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(final Marker click) {
            addPoint(click.getPosition());
            return true;
        }
    });

    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            if (mMap.getMyLocation() != null) {
                LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(),
                        mMap.getMyLocation().getLongitude());
                double distance = SphericalUtil.computeDistanceBetween(myLocation,
                        mMap.getCameraPosition().target);

                // Only if the distance is less than 50cm we are on our location, add the marker
                if (distance < 0.5) {
                    Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show();
                    addPoint(myLocation);
                }
            }
            return false;
        }
    });

    // check if open with csv file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        try {
            Util.loadFromFile(getIntent().getData(), this);
            if (!trace.isEmpty())
                mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16));
        } catch (IOException e) {
            Toast.makeText(this,
                    getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

    mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(final Bundle bundle) {
                    Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
                    if (l != null && mMap.getCameraPosition().zoom <= 2) {
                        mMap.moveCamera(CameraUpdateFactory
                                .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16));
                    }
                    mGoogleApiClient.disconnect();
                }

                @Override
                public void onConnectionSuspended(int cause) {

                }
            }).build();
    mGoogleApiClient.connect();

    valueTv = (TextView) findViewById(R.id.distance);
    updateValueText();
    valueTv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (type == MeasureType.DISTANCE)
                changeType(MeasureType.AREA);
            // only switch to elevation mode is an internet connection is
            // available and user has access to this feature
            else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION)
                changeType(MeasureType.ELEVATION);
            else
                changeType(MeasureType.DISTANCE);
        }
    });

    View delete = findViewById(R.id.delete);
    delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            removeLast();
        }
    });
    delete.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Map.this);
            builder.setMessage(getString(R.string.delete_all, trace.size()));
            builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    clear();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show();
            return true;
        }
    });

    mMap.setOnMapClickListener(new OnMapClickListener() {
        @Override
        public void onMapClick(final LatLng center) {
            addPoint(center);
        }
    });

    // Drawer stuff
    ListView drawerList = (ListView) findViewById(R.id.left_drawer);
    drawerListAdapert = new DrawerListAdapter(this);
    drawerList.setAdapter(drawerListAdapert);
    drawerList.setDivider(null);
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) {
            switch (position) {
            case 0: // Search before Android 5.0
                Dialogs.getSearchDialog(Map.this).show();
                closeDrawer();
                break;
            case 2: // Units
                Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show();
                closeDrawer();
                break;
            case 3: // distance
                changeType(MeasureType.DISTANCE);
                break;
            case 4: // area
                changeType(MeasureType.AREA);
                break;
            case 5: // elevation
                if (PRO_VERSION) {
                    changeType(MeasureType.ELEVATION);
                } else {
                    Dialogs.getElevationAccessDialog(Map.this, mService).show();
                }
                break;
            case 7: // map
                changeView(GoogleMap.MAP_TYPE_NORMAL);
                break;
            case 8: // satellite
                changeView(GoogleMap.MAP_TYPE_HYBRID);
                break;
            case 9: // terrain
                changeView(GoogleMap.MAP_TYPE_TERRAIN);
                break;
            case 11: // save
                Dialogs.getSaveNShare(Map.this, trace).show();
                closeDrawer();
                break;
            case 12: // more apps
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin"))
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (ActivityNotFoundException anf) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/developer?id=j4velin"))
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
            case 13: // about
                Dialogs.getAbout(Map.this).show();
                closeDrawer();
                break;
            default:
                break;
            }
        }
    });

    changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL));
    changeType(MeasureType.DISTANCE);

    // KitKat translucent decor enabled? -> Add some margin/padding to the
    // drawer and the map
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {

        int statusbar = Util.getStatusBarHeight(this);

        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams();
        lp.setMargins(0, statusbar + 10, 0, 0);
        topCenterOverlay.setLayoutParams(lp);

        // on most devices and in most orientations, the navigation bar
        // should be at the bottom and therefore reduces the available
        // display height
        int navBarHeight = Util.getNavigationBarHeight(this);

        DisplayMetrics total, available;
        total = new DisplayMetrics();
        available = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(available);
        API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total);

        boolean navBarOnRight = getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE
                && (total.widthPixels - available.widthPixels > 0);

        if (navBarOnRight) {
            // in landscape on phones, the navigation bar might be at the
            // right side, reducing the available display width
            mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, 0);
        } else {
            mMap.setPadding(0, statusbar, 0, navBarHeight);
            drawerList.setPadding(0, statusbar + 10, 0, 0);
            drawerListAdapert.setMarginBottom(navBarHeight);
            if (menuButton != null)
                menuButton.setPadding(0, 0, 0, navBarHeight);
        }
    }

    mMap.setMyLocationEnabled(true);

    PRO_VERSION |= prefs.getBoolean("pro", false);
    if (!PRO_VERSION) {
        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND")
                .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE);
    }
}