Example usage for android.location LocationManager NETWORK_PROVIDER

List of usage examples for android.location LocationManager NETWORK_PROVIDER

Introduction

In this page you can find the example usage for android.location LocationManager NETWORK_PROVIDER.

Prototype

String NETWORK_PROVIDER

To view the source code for android.location LocationManager NETWORK_PROVIDER.

Click Source Link

Document

Name of the network location provider.

Usage

From source file:com.nextgis.mobile.MapFragment.java

public void showInfoPane(boolean isShow) {

    if (isShow) {
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mChangeLocationListener);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                mChangeLocationListener);
        mLocationManager.addGpsStatusListener(mGpsStatusListener);

        final RelativeLayout.LayoutParams RightParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        RightParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

        int nHeight = 0;

        if (mContext.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {

            TypedValue typeValue = new TypedValue();

            mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true);
            nHeight = TypedValue.complexToDimensionPixelSize(typeValue.data,
                    mContext.getResources().getDisplayMetrics());

            //getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true);
            //nHeight = TypedValue.complexToDimensionPixelSize(
            //        typeValue.data,getResources().getDisplayMetrics());
        }/* w  w w  .  j  a  v a2 s.  co  m*/

        RightParams.setMargins(0, 0, 0, nHeight);
        mMapRelativeLayout.addView(mInfoPane, RightParams);

    } else {
        mLocationManager.removeUpdates(mChangeLocationListener);
        mLocationManager.removeGpsStatusListener(mGpsStatusListener);
        mMapRelativeLayout.removeView(mInfoPane);
    }

    mIsInfoPaneShow = isShow;
}

From source file:com.warp10.app.LocationService.java

/**
 * Function used to get the last location of user
 * @param isListenGPS if check GPS provider if available
 * @param isListenNetWork if check Network provider
 * @return Last known location/*from   w  w  w .  j  a  va2 s . co  m*/
 */
public static Location getLastLocation(boolean isListenGPS, boolean isListenNetWork) {
    Location mLastLocation = null;
    if (null != locManager) {
        if (isListenGPS) {
            if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                if (ActivityCompat.checkSelfPermission(ctx,
                        Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(ctx,
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    // TODO: Consider calling
                    //    ActivityCompat#requestPermissions
                    // here to request the missing permissions, and then overriding
                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                    //                                          int[] grantResults)
                    // to handle the case where the user grants the permission. See the documentation
                    // for ActivityCompat#requestPermissions for more details.
                    return null;
                }
                mLastLocation = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            } else if (isListenNetWork) {
                mLastLocation = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            }
        } else if (isListenNetWork) {
            mLastLocation = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }
    return mLastLocation;
}

From source file:org.odk.collect.android.activities.GeoPointOsmMapActivity.java

private void upMyLocationOverlayLayers() {
    // make sure we have a good location provider before continuing
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;//w w w .j a va 2  s.  c  o  m
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        } else if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
        }
    }

    mShowLocationButton.setClickable(mMarker != null);

    if (!mGPSOn && !mNetworkOn) {
        showGPSDisabledAlertToUser();
    } else {
        overlayMyLocationLayers();
    }
}

From source file:jp.co.tweetmap.Fragment0.java

/**
 * This is where we can add markers or lines, add listeners or move the camera. In this case, we
 * just add a marker near Africa./*  w  w  w .ja v a  2s . c  o  m*/
 * <p/>
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    if (LogUtil.isDebug())
        Log.e(TAG, "### mapInit() ###");
    // LocationManager
    LocationManager locationManager = (LocationManager) this.getActivity().getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);

    double latitude = MapUtil.TOKYO_STATION_LATITUDE;
    double longitude = MapUtil.TOKYO_STATION_LONGITUDE;

    if (null != locationManager) {
        String bestProv = locationManager.getBestProvider(new Criteria(), true);

        // Get location information from GPS
        Location myLocate = locationManager.getLastKnownLocation(bestProv);
        if (null == myLocate) {
            myLocate = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }
        if (null == myLocate) {
            myLocate = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }

        if (null != myLocate) {
            latitude = myLocate.getLatitude();
            longitude = myLocate.getLongitude();
        }
    }

    CameraPosition camerapos = new CameraPosition.Builder().target(new LatLng(latitude, longitude)).zoom(15.0f)
            .build();
    // Move camera position
    mMap.moveCamera(CameraUpdateFactory.newCameraPosition(camerapos));
    // Set current position
    mCenterPosition = camerapos;

    getNearestStation();
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();/*  ww w.j a  v  a2 s .co  m*/
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) SonetCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.koboc.collect.android.activities.GeoPointMapActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (mMap == null) {
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (mMap == null) {
            Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured),
                    Toast.LENGTH_SHORT).show();
            finish();//from w w w. ja v a2 s .  c  o m
            return;
        }

        // possibly enable clear value action...
        if (mCaptureLocation) {
            mMap.setOnMarkerDragListener(this);
            mMap.setOnMapLongClickListener(this);
        }

        /*Zoom only if there's a previous location*/
        if (mLatLng != null) {
            mMarkerOption.position(mLatLng);
            mMarker = mMap.addMarker(mMarkerOption);
            mMarker.setDraggable(mCaptureLocation);
            mZoomed = true;
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
        }

        mShowLocation.setClickable(mMarker != null);
    }

    if (mRefreshLocation) {
        mLocationStatus.setVisibility(View.VISIBLE);
        if (mGPSOn) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        }
        if (mNetworkOn) {
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
        }
    }
}

From source file:com.qi.airstat.BluetoothLeService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    int signal = 0;

    // This is special handling for the Heart Rate Measurement profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {/*w  ww. j  a va  2s. c  om*/
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }

        final int heartRate = characteristic.getIntValue(format, 1);
        signal = heartRate;
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());

            signal = Integer.parseInt(new String(data));
        }
    }

    DatabaseManager databaseManager = new DatabaseManager(BluetoothLeService.this);
    SQLiteDatabase database = databaseManager.getWritableDatabase();

    ContentValues values = new ContentValues();
    String date = new SimpleDateFormat("yyMMddHHmmss").format(new java.util.Date());

    values.put(Constants.DATABASE_COMMON_COLUMN_TIME_STAMP, date);
    values.put(Constants.DATABASE_HEART_RATE_COLUMN_HEART_RATE, signal);
    database.insert(Constants.DATABASE_HEART_RATE_TABLE, null, values);

    database.close();

    try {
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    } catch (SecurityException exception) {
        exception.printStackTrace();
    }

    JSONObject reformedObject = new JSONObject();
    JSONArray reformedArray = new JSONArray();

    try {
        JSONObject item = new JSONObject();
        item.put("timeStamp", date);
        item.put("connectionID", Constants.CID_BLE);
        item.put("heartrate", signal);
        item.put("latitude", latitude);
        item.put("longitude", longitude);

        reformedArray.put(item);
        reformedObject.put("HR", reformedArray);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    HttpService httpService = new HttpService();
    String responseCode = httpService.executeConn(null, "POST",
            "http://teamc-iot.calit2.net/IOT/public/rcv_json_data", reformedObject);

    sendBroadcast(intent);
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java

/**
 * {@inheritDoc}/* ww  w .  j  a  v a2 s  . c  om*/
 */
@Override
public void onResume() {
    super.onResume();

    // Feed back life cycle events back to the MapView.
    mapView.onResume();

    // Start the location providers if they are enabled.
    if (locMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, REQUEST_PERIOD, MIN_DISTANCE, this);
    }

    if (locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, REQUEST_PERIOD, MIN_DISTANCE, this);
    }

    // Start the accelerometer and magnetometer.
    startOrientationSensors();

    // Show the user's location on the map if we can.
    if (map != null) {
        map.setMyLocationEnabled(getActivity().getSharedPreferences(PreferencesActivity.PREF_FILE, 0)
                .getBoolean(PreferencesActivity.PREF_AUTO_LOCATION, true));
    }

    if (sd.getFavouriteStopExists(stopCode)) {
        favouriteBtn.setBackgroundResource(R.drawable.ic_list_favourite);
        favouriteBtn.setContentDescription(getString(R.string.favourite_rem));
    } else {
        favouriteBtn.setBackgroundResource(R.drawable.ic_list_unfavourite);
        favouriteBtn.setContentDescription(getString(R.string.favourite_add));
    }

    if (sd.isActiveProximityAlert(stopCode)) {
        txtProxAlert.setText(R.string.busstopdetails_prox_rem);
    } else {
        txtProxAlert.setText(R.string.busstopdetails_prox_add);
    }

    if (sd.isActiveTimeAlert(stopCode)) {
        txtTimeAlert.setText(R.string.busstopdetails_time_rem);
    } else {
        txtTimeAlert.setText(R.string.busstopdetails_time_add);
    }
}

From source file:com.eeshana.icstories.activities.UploadVideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // this will copy the license file and the demo video file.
    // to the videokit work folder location.
    // without the license file the library will not work.
    //copyLicenseAndDemoFilesFromAssetsToSDIfNeeded();
    setContentView(R.layout.upload_video_activity);

    height = SignInActivity.getScreenHeight(UploadVideoActivity.this);
    width = SignInActivity.getScreenWidth(UploadVideoActivity.this);
    mProgressDialog = new ProgressDialog(UploadVideoActivity.this);
    pDialog = new ProgressDialog(UploadVideoActivity.this);
    showCustomToast = new ShowCustomToast();
    connectionDetector = new ConnectionDetector(UploadVideoActivity.this);
    //      mProgressDialog=new ProgressDialog(UploadVideoActivity.this,AlertDialog.THEME_HOLO_LIGHT);
    //      mProgressDialog.setFeatureDrawableResource(height,R.drawable.rounded_toast);
    prefs = getSharedPreferences("PREF", MODE_PRIVATE);
    regId = prefs.getString("regid", "NA");
    SharedPreferences pref = getSharedPreferences("DB", 0);
    userid = pref.getString("userid", "1");
    SharedPreferences assign_prefs = getSharedPreferences("ASSIGN", 0);
    assignment_id = assign_prefs.getString("ASSIGN_ID", "");
    videoPath = getIntent().getStringExtra("VIDEOPATH");

    //      iCTextView=(TextView) findViewById(R.id.tvIC);
    //      iCTextView.setTypeface(CaptureVideoActivity.ic_typeface,Typeface.BOLD);
    //      storiesTextView=(TextView) findViewById(R.id.tvStories);
    //      storiesTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.BOLD);
    //      watsStoryTextView=(TextView) findViewById(R.id.tvWhatsStory);
    //      watsStoryTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.ITALIC);

    //      logoImageView=(ImageView) findViewById(R.id.ivLogo);
    //      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int) (width/1.9), (int) (height/9.5));
    //      lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    //      lp.setMargins(0, 0, 0, 0);
    //      logoImageView.setLayoutParams(lp);

    uploadtTextView = (TextView) findViewById(R.id.tvUpload);
    uploadtTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    //      extension=getIntent().getStringExtra("EXTENSION");
    //      folderPath = Environment.getExternalStorageDirectory().getPath()+"/ICStoriesFolder";
    //      if (!FileUtils.checkIfFolderExists(folderPath)) {
    //         boolean isFolderCreated = FileUtils.createFolder(folderPath);
    //         Log.i(Prefs.TAG, folderPath + " created? " + isFolderCreated);
    //         if (isFolderCreated) {
    ///*from   ww w . j  a  v  a2  s .co  m*/
    //         }
    //      }
    //command for rotating video 90 degree
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k "+folderPath+"/out."+extension;

    //Change Video Resolution:
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=3 -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/res."+extension;

    //command for compressing video 
    //      String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/test."+extension;
    //      setCommand(commandStr);
    //      runTranscoing();

    thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.MINI_KIND);
    System.out.println("THUMB IMG  in uplaod== " + thumb);

    titleEditText = (EditText) findViewById(R.id.etTitle);
    titleEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    descriptionEditText = (EditText) findViewById(R.id.etDescripton);
    descriptionEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    locationEditText = (EditText) findViewById(R.id.etLocation);
    locationEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton = (Button) findViewById(R.id.buttonCheck);
    isAssignmentButton.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton.setOnClickListener(this);
    dailyAssignTextView = (TextView) findViewById(R.id.tvDailyAssignment);
    dailyAssignTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    uploadButton = (Button) findViewById(R.id.buttonUpload);
    uploadButton.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout uploadRelativeLayout = (RelativeLayout) findViewById(R.id.rlUpload);
    RelativeLayout.LayoutParams lp9 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, height / 17);
    lp9.addRule(RelativeLayout.BELOW, R.id.rlDailyAssignment);
    lp9.setMargins(width / 7, 30, width / 7, 0);
    uploadRelativeLayout.setLayoutParams(lp9);
    uploadButton.setOnClickListener(this);

    //bottom bar

    homeRelativeLayout = (RelativeLayout) findViewById(R.id.rlHome);
    homeRelativeLayout.setBackgroundResource(R.drawable.press_border);
    homeRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    homeTextView = (TextView) homeRelativeLayout.findViewById(R.id.tvHome);
    homeTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    homeTextView.setTextColor(Color.parseColor("#fffffe"));
    RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp4.addRule(RelativeLayout.ALIGN_LEFT);
    homeRelativeLayout.setLayoutParams(lp4);
    homeRelativeLayout.setOnClickListener(this);

    wallRelativeLayout = (RelativeLayout) findViewById(R.id.rlWall);
    wallRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    wallTextView = (TextView) wallRelativeLayout.findViewById(R.id.tvWall);
    wallTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp5.addRule(RelativeLayout.RIGHT_OF, R.id.rlHome);
    wallRelativeLayout.setLayoutParams(lp5);
    wallRelativeLayout.setOnClickListener(this);

    settingsRelativeLayout = (RelativeLayout) findViewById(R.id.rlSettings);
    settingsRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    settingsTextView = (TextView) settingsRelativeLayout.findViewById(R.id.tvSettings);
    settingsTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp6.addRule(RelativeLayout.RIGHT_OF, R.id.rlWall);
    settingsRelativeLayout.setLayoutParams(lp6);
    settingsRelativeLayout.setOnClickListener(this);

    // current location
    locationDialog = new Dialog(UploadVideoActivity.this);
    locationDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    locationDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    locationDialog.setContentView(R.layout.location_dialog);
    locationDialog.setCancelable(true);
    LinearLayout dialogLayout = (LinearLayout) locationDialog.findViewById(R.id.ll1);
    okButton = (Button) dialogLayout.findViewById(R.id.OkBtn);
    okButton.setOnClickListener(this);
    cancelButton = (Button) dialogLayout.findViewById(R.id.cancelBtn);
    cancelButton.setOnClickListener(this);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (network_enabled) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    } else {
        showCustomToast.showToast(UploadVideoActivity.this,
                "Could not find current location. Please enable location services of your device.");
    }
    //      else if(gps_enabled == false){
    //         locationDialog.show();
    //      }
}

From source file:org.odk.collect.android.activities.GeoTraceGoogleMapActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.geotrace_google_layout);

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.gmap)).getMap();
    mHelper = new MapHelper(this, mMap);
    mMap.setMyLocationEnabled(true);//w  w  w. j a va 2 s. c o m
    mMap.setOnMapLongClickListener(this);
    mMap.setOnMarkerDragListener(this);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);
    mMap.getUiSettings().setZoomControlsEnabled(false);

    polylineOptions = new PolylineOptions();
    polylineOptions.color(Color.RED);

    clear_button = (Button) findViewById(R.id.clear);
    clear_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (markerArray.size() != 0) {
                showClearDialog();
            }
        }
    });

    inflater = this.getLayoutInflater();
    traceSettingsView = inflater.inflate(R.layout.geotrace_dialog, null);
    polygonPolylineView = inflater.inflate(R.layout.polygon_polyline_dialog, null);
    resource_proxy = new DefaultResourceProxyImpl(getApplicationContext());
    time_delay = (Spinner) traceSettingsView.findViewById(R.id.trace_delay);
    time_delay.setSelection(3);
    time_units = (Spinner) traceSettingsView.findViewById(R.id.trace_scale);
    pause_button = (Button) findViewById(R.id.pause);
    pause_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            play_button.setVisibility(View.VISIBLE);
            if (markerArray != null && markerArray.size() > 0) {
                clear_button.setEnabled(true);
            }
            pause_button.setVisibility(View.GONE);
            manual_button.setVisibility(View.GONE);
            play_check = true;
            mode_active = false;
            try {
                schedulerHandler.cancel(true);
            } catch (Exception e) {
                // Do nothing
            }

        }
    });
    layers_button = (Button) findViewById(R.id.layers);

    save_button = (Button) findViewById(R.id.geotrace_save);
    save_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (markerArray.size() != 0) {
                p_alert.show();
            } else {
                saveGeoTrace();
            }

        }
    });
    play_button = (Button) findViewById(R.id.play);
    play_button.setEnabled(false);
    play_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (!play_check) {
                if (!beenPaused) {
                    alert.show();
                } else {
                    RadioGroup rb = (RadioGroup) traceSettingsView.findViewById(R.id.radio_group);
                    int radioButtonID = rb.getCheckedRadioButtonId();
                    View radioButton = rb.findViewById(radioButtonID);
                    int idx = rb.indexOfChild(radioButton);
                    TRACE_MODE = idx;
                    if (TRACE_MODE == 0) {
                        setupManualMode();
                    } else if (TRACE_MODE == 1) {
                        setupAutomaticMode();
                    } else {
                        //Do nothing
                    }
                }
                play_check = true;
            } else {
                play_check = false;
                startGeoTrace();
            }
        }
    });

    if (markerArray == null || markerArray.size() == 0) {
        clear_button.setEnabled(false);
    }

    manual_button = (Button) findViewById(R.id.manual_button);
    manual_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addLocationMarker();

        }
    });

    polygon_save = (Button) polygonPolylineView.findViewById(R.id.polygon_save);
    polygon_save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (markerArray.size() > 2) {
                createPolygon();
                p_alert.dismiss();
                saveGeoTrace();
            } else {
                p_alert.dismiss();
                showPolyonErrorDialog();
            }

        }
    });
    polyline_save = (Button) polygonPolylineView.findViewById(R.id.polyline_save);
    polyline_save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            p_alert.dismiss();
            saveGeoTrace();

        }
    });

    buildDialogs();

    layers = (Button) findViewById(R.id.layers);
    layers.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mHelper.showLayersDialog();
        }
    });

    location_button = (Button) findViewById(R.id.show_location);
    location_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showZoomDialog();
        }
    });

    zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);

    zoomLocationButton = (Button) zoomDialogView.findViewById(R.id.zoom_location);
    zoomLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            zoomToMyLocation();
            zoomDialog.dismiss();
        }
    });

    zoomPointButton = (Button) zoomDialogView.findViewById(R.id.zoom_shape);
    zoomPointButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            zoomtoBounds();
            zoomDialog.dismiss();
        }
    });
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;
            curLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }
        if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
            curLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
    }

    if (mGPSOn) {
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                GeoTraceGoogleMapActivity.this);
    }
    if (mNetworkOn) {
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                GeoTraceGoogleMapActivity.this);
    }

    if (!mGPSOn & !mNetworkOn) {
        showGPSDisabledAlertToUser();
    }
    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) {
            String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION);
            play_button.setEnabled(false);
            clear_button.setEnabled(true);
            firstLocationFound = true;
            location_button.setEnabled(true);
            overlayIntentTrace(s);
            zoomtoBounds();
        }
    } else {
        if (curLocation != null) {
            curlatLng = new LatLng(curLocation.getLatitude(), curLocation.getLongitude());
            initZoom = true;
        }
    }

}