map

Marker startMarker = mMap.addMarker(new MarkerOptions()
        .position(new LatLng(locationList.get(0).getLat(), locationList.get(0).getLong()))
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.at_icon_map_start)));



public void captureScreen() {
    Bitmap image = ImageUtil.getViewBitmap(findViewById(R.id.share_content));
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .build();
    SharePhotoContent content = new SharePhotoContent.Builder()
            .addPhoto(photo)
            .build();

    ShareDialog shareDialog = new ShareDialog((Activity) context);
    shareDialog.show(content);

    finish();
}
****************************************************************************

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.afrimack.R;

import static com.afrimack.R.drawable.user;

public class TestGPS extends AppCompatActivity {

    private LocationManager manager;
    private boolean isDataRecieved = false, isRecieverRegistered = false,
            isNetDialogShowing = false, isGpsDialogShowing = false;
    private AlertDialog internetDialog, gpsAlertDialog, locationAlertDialog;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_gps);

        manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }

    @Override    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
     //   Mint.startSession(MainDrawerActivity.this);
        if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            ShowGpsDialog();
        }
        else {
            removeGpsDialog();
        }
       // registerReceiver(internetConnectionReciever, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));        registerReceiver(GpsChangeReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
        isRecieverRegistered = true;

        /*if (AndyUtils.isNetworkAvailable(this)                && manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {            if (!isDataRecieved) {                isDataRecieved = true;                checkStatus();            }        }*/        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            if (!isDataRecieved) {
                isDataRecieved = true;
                //checkStatus();                Log.e("fgcgcgc","hghghhgg");
            }
        }
        /*user = dbHelper.getUser();        if (user != null) {            aQuery.id(ivMenuProfile).progress(R.id.pBar)                    .image(user.getPicture(), imageOptions);
            tvMenuName.setText(user.getFname() + " " + user.getLname());        }*/
    }


    @Override    protected void onStop() {
        // TODO Auto-generated method stub        super.onStop();
       // Mint.closeSession(MainDrawerActivity.this);    }

    private void ShowGpsDialog() {
       // AndyUtils.removeCustomProgressDialog();        isGpsDialogShowing = true;
        AlertDialog.Builder gpsBuilder = new AlertDialog.Builder(
                TestGPS.this);
        gpsBuilder.setCancelable(false);
        gpsBuilder
                .setTitle(getString(R.string.dialog_no_gps))
                .setMessage(getString(R.string.dialog_no_gps_messgae))
                .setPositiveButton(getString(R.string.dialog_enable_gps),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                // continue with delete                                Intent intent = new Intent(
                                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                startActivity(intent);
                                removeGpsDialog();
                            }
                        })

                .setNegativeButton(getString(R.string.dialog_exit),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                // do nothing                                removeGpsDialog();
                                finish();
                            }
                        });
        gpsAlertDialog = gpsBuilder.create();
        gpsAlertDialog.show();
    }

    public void showLocationOffDialog() {

        AlertDialog.Builder gpsBuilder = new AlertDialog.Builder(
                TestGPS.this);
        gpsBuilder.setCancelable(false);
        gpsBuilder
                .setTitle(getString(R.string.dialog_no_location_service_title))
                .setMessage(getString(R.string.dialog_no_location_service))
                .setPositiveButton(
                        getString(R.string.dialog_enable_location_service),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                // continue with delete                                dialog.dismiss();
                                Intent viewIntent = new Intent(
                                        Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                startActivity(viewIntent);

                            }
                        })

                .setNegativeButton(getString(R.string.dialog_exit),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                                int which) {
                                // do nothing                                dialog.dismiss();
                                finish();
                            }
                        });
        locationAlertDialog = gpsBuilder.create();
        locationAlertDialog.show();
    }
    private void removeGpsDialog() {
        if (gpsAlertDialog != null && gpsAlertDialog.isShowing()) {
            gpsAlertDialog.dismiss();
            isGpsDialogShowing = false;
            gpsAlertDialog = null;

        }
    }
    public BroadcastReceiver GpsChangeReceiver = new BroadcastReceiver() {
        @Override        public void onReceive(Context context, Intent intent) {

            final LocationManager manager = (LocationManager) context
                    .getSystemService(Context.LOCATION_SERVICE);
            if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                // do something                removeGpsDialog();
            } else {
                // do something else                if (isGpsDialogShowing) {
                    return;
                }
                ShowGpsDialog();
            }
        }
    };

    @Override    protected void onDestroy() {

        super.onDestroy();
       // Mint.closeSession(this);        if (isRecieverRegistered) {
           // unregisterReceiver(internetConnectionReciever);            unregisterReceiver(GpsChangeReceiver);
        }

    }
}
Share:

No comments:

Post a Comment

Powered by Blogger.

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.