Example usage for android.location LocationManager GPS_PROVIDER

List of usage examples for android.location LocationManager GPS_PROVIDER

Introduction

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

Prototype

String GPS_PROVIDER

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

Click Source Link

Document

Name of the GPS location provider.

Usage

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

/**
 * End of service, unregistered GPS or Network providers
 *//*from  www .  j  a  v  a 2s. c o m*/
public void onDestroy() {
    if (isRunning) {
        if (null != locationManager) {
            locationListener.onProviderDisabled(LocationManager.NETWORK_PROVIDER);
            locationManager.removeUpdates(locationListener);
            if (ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(this,
                            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;
            }
            locationListener.onProviderDisabled(LocationManager.GPS_PROVIDER);
            locationManager = null;
            //Log.d("LOCATION", "Detroyed");
        }
        //stopSelf();
        //Log.d("LOC", "STOP service location");
        isRunning = false;
    }
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.MainActivity.java

/**
 * Will be called when user clicked add Location button, it will pop a
 * dialog and let user choose the method of location which go to the
 * osmMainAcitivity// w  w  w.  j  a  v  a  2  s. c o  m
 * 
 * @param v
 *            View passed to the activity to check which button was pressed.
 */
public void goToMapAction(View v) {
    AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
    if (user.getHomelocation() != null) {
        adb.setMessage("Current Home Location is " + user.getHomelocation().getLatitude()
                + user.getHomelocation().getLongitude() + "\nChoose the HomeLocation Way");

    } else {
        adb.setMessage("Choose the HomeLocation Way");
    }
    adb.setNegativeButton("GPS", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            homeLocation = location;
            user.setHomelocation(location);
        }
    });

    adb.setPositiveButton("Map", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(MainActivity.this, osmMainActivity.class);
            startActivity(intent);
        }
    });

    adb.setCancelable(true);
    adb.show();

}

From source file:com.vonglasow.michael.satstat.ui.MapSectionFragment.java

/**
 * Creates layers and associated tile caches for the map view.
 * /*w w  w.j  av a2  s. co m*/
 * @param createOverlays Whether to create overlays (circle and markers) or just tile layers
 */
private void createLayers(boolean createOverlays) {
    LayerManager layerManager = mapMap.getLayerManager();
    Layers layers = layerManager.getLayers();

    if (mainActivity.prefMapOffline && (ContextCompat.checkSelfPermission(mainActivity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
        /*
         * If offline maps are enabled AND we have storage permission, use offline map tiles.
         * Skip this step if we don't have permission, else we would pollute the cache with blank tiles.
         */
        if (mapRendererTileCache == null)
            mapRendererTileCache = AndroidUtil.createExternalStorageTileCache(this.getContext(),
                    Const.TILE_CACHE_INTERNAL_RENDER_THEME,
                    Math.round(AndroidUtil.getMinimumCacheSize(this.getContext(),
                            mapMap.getModel().displayModel.getTileSize(),
                            mapMap.getModel().frameBufferModel.getOverdrawFactor(), 1f)),
                    mapMap.getModel().displayModel.getTileSize(), true);

        /*
         * If the offline map path changes, we need to purge the cache. This ensures we don't serve stale
         * tiles generated from the old map set.
         * 
         * We accomplish this by comparing the current map path to the map path for which we last
         * instantiated a cache. If they differ, we flush the cache and store the new map path.
         */
        String cachedPath = mainActivity.mSharedPreferences.getString(Const.KEY_PREF_MAP_CACHED_PATH, "");
        if (!cachedPath.equals(mainActivity.prefMapPath)) {
            mapRendererTileCache.purge();
            SharedPreferences.Editor spEditor = mainActivity.mSharedPreferences.edit();
            spEditor.putString(Const.KEY_PREF_MAP_CACHED_PATH, mainActivity.prefMapPath);
            spEditor.commit();
        }

        MultiMapDataStore mapDataStore = new MultiMapDataStore(DataPolicy.DEDUPLICATE);
        File mapDir = new File(mainActivity.prefMapPath);
        Log.i(TAG, String.format("Looking for maps in: %s", mapDir.getName()));
        if (mapDir.exists() && mapDir.canRead() && mapDir.isDirectory())
            for (File file : mapDir.listFiles())
                if (file.isFile())
                    try {
                        MapFile mapFile = new MapFile(file);
                        mapDataStore.addMapDataStore(mapFile, false, false);
                        Log.i(TAG, String.format("Added map file: %s", file.getName()));
                    } catch (MapFileException e) {
                        // not a map file, skip
                        Log.w(TAG, String.format("Could not add map file: %s", file.getName()));
                    }

        mapRendererLayer = new TileRendererLayer(mapRendererTileCache, mapDataStore,
                mapMap.getModel().mapViewPosition, false, true, false, AndroidGraphicFactory.INSTANCE);

        mapRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);

        //mapRendererLayer.setTextScale(1.5f); // FIXME
        layers.add(0, mapRendererLayer);
        mapAttribution.setText(R.string.osm_attribution);
    } else if (!mainActivity.prefMapOffline) {
        // use online map tiles
        if (mapDownloadTileCache == null)
            mapDownloadTileCache = AndroidUtil.createExternalStorageTileCache(this.getContext(),
                    Const.TILE_CACHE_OSM,
                    Math.round(AndroidUtil.getMinimumCacheSize(this.getContext(),
                            mapMap.getModel().displayModel.getTileSize(),
                            mapMap.getModel().frameBufferModel.getOverdrawFactor(), 1f)),
                    mapMap.getModel().displayModel.getTileSize(), true);

        mapDownloadLayer = new TileDownloadLayer(mapDownloadTileCache, mapMap.getModel().mapViewPosition,
                onlineTileSource, AndroidGraphicFactory.INSTANCE);
        layers.add(0, mapDownloadLayer);
        /*
         * Since tiles are now sourced from OSM (following Mapquest's decision to discontinue their free
         * tile service), attribution is the same for online and offline. This may change if we switch
         * to a different tile source (or allow multiple ones) - therefore, attribution should still
         * depend on the map source.
         */
        mapAttribution.setText(R.string.osm_attribution);
    } else
        mapAttribution.setText("");

    //parse list of location providers
    if (createOverlays)
        onLocationProvidersChanged(mainActivity.mSharedPreferences.getStringSet(Const.KEY_PREF_LOC_PROV,
                new HashSet<String>(Arrays.asList(
                        new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }))));

    // mark cache as purged
    SharedPreferences.Editor spEditor = mainActivity.mSharedPreferences.edit();
    spEditor.putBoolean(Const.KEY_PREF_MAP_PURGE, false);
    spEditor.commit();
}

From source file:com.grayfox.android.app.fragment.ExploreFragment.java

private boolean areAnyLocationProvidersEnabled() {
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

From source file:it.unipr.informatica.autobusparma.MappaFragment.java

@Override
public void onResume() {
    super.onResume();
    if (mMap != null) {

        locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 100, this);
    }// w  w  w .  j  a  v a 2  s  . c  om
}

From source file:com.waz.zclient.pages.main.conversation.LocationFragment.java

@SuppressWarnings("ResourceType")
@SuppressLint("MissingPermission")
private void startLocationManagerListeningForCurrentLocation() {
    Timber.i("startLocationManagerListeningForCurrentLocation");
    if (locationManager != null && PermissionUtils.hasSelfPermissions(getContext(), LOCATION_PERMISSIONS)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }//from   w w w .  j a v a  2 s .c o  m
}

From source file:cl.gisred.android.StandardActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LicenseResult licenseResult = ArcGISRuntime.setClientId(CLIENT_ID);
    LicenseLevel licenseLevel = ArcGISRuntime.License.getLicenseLevel();

    if (licenseResult == LicenseResult.VALID && licenseLevel == LicenseLevel.BASIC) {
        //Toast.makeText(getApplicationContext(), "Licencia bsica vlida", Toast.LENGTH_SHORT).show();
    } else if (licenseResult == LicenseResult.VALID && licenseLevel == LicenseLevel.STANDARD) {
        //Toast.makeText(getApplicationContext(), "Licencia standard vlida", Toast.LENGTH_SHORT).show();
    }/*from ww w. j a  v a  2s  .  c  o  m*/

    setContentView(R.layout.activity_standard);

    Toolbar toolbar = (Toolbar) findViewById(R.id.apptool);
    setSupportActionBar(toolbar);

    /*Get Credenciales String*/
    Bundle bundle = getIntent().getExtras();
    usuar = bundle.getString("usuario");
    passw = bundle.getString("password");
    modulo = bundle.getString("modulo");
    empresa = bundle.getString("empresa");

    //Set Credenciales
    setCredenciales(usuar, passw);

    //Set Mapa
    setMap(R.id.map, 0xffffff, 0xffffff, 10, 10, false, true);
    choices = 0;

    if (Build.VERSION.SDK_INT >= 23)
        verifPermisos();
    else
        initGeoposition();

    setLayersURL(this.getResources().getString(R.string.url_Mapabase), "MAPABASE");
    setLayersURL(this.getResources().getString(R.string.url_token), "TOKENSRV");
    setLayersURL(this.getResources().getString(R.string.url_EquiposLinea), "EQUIPOS_LINEA");
    setLayersURL(this.getResources().getString(R.string.url_TRAMOS), "TRAMOS");
    setLayersURL(this.getResources().getString(R.string.url_EquiposPTO), "EQUIPOS_PTO");
    setLayersURL(this.getResources().getString(R.string.url_Nodos), "NODOS");
    setLayersURL(this.getResources().getString(R.string.url_Luminarias), "LUMINARIAS");
    setLayersURL(this.getResources().getString(R.string.url_Clientes), "CLIENTES");
    setLayersURL(this.getResources().getString(R.string.url_Concesiones), "CONCESIONES");
    setLayersURL(this.getResources().getString(R.string.url_Direcciones), "DIRECCIONES");
    setLayersURL(this.getResources().getString(R.string.url_medidores), "MEDIDORES");
    setLayersURL(this.getResources().getString(R.string.url_Stx), "STX");
    setLayersURL(this.getResources().getString(R.string.url_ECSE_varios), "ECSE");
    setLayersURL(this.getResources().getString(R.string.url_Electrodependientes), "ELECTRODEP");

    //Agrega layers dinmicos.
    addLayersToMap(credenciales, "DYNAMIC", "MAPABASECHQ", din_urlMapaBase, null, true);
    addLayersToMap(credenciales, "DYNAMIC", "SED", din_urlEquiposPunto, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "SSEE", din_urlEquiposPunto, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "SALIDAALIM", din_urlEquiposPunto, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "REDMT", din_urlTramos, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "REDBT", din_urlTramos, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "REDAP", din_urlTramos, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "POSTES", din_urlNodos, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "EQUIPOS_LINEA", din_urlEquiposLinea, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "EQUIPOS_PTO", din_urlEquiposPunto, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "LUMINARIAS", din_urlLuminarias, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "CLIENTES", din_urlClientes, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "MEDIDORES", din_urlMedidores, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "CONCESIONES", din_urlConcesiones, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "DIRECCIONES", din_urlDirecciones, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "EMPALMES", din_urlClientes, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "REDSTX", din_urlStx, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "TORRESSTX", din_urlStx, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "ENCUESTADO", din_urlECSE, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "REEMPLAZO", din_urlECSE, null, false);
    addLayersToMap(credenciales, "DYNAMIC", "ELECTRODEP", din_urlElectroDep, null, false);

    //Aade Layer al Mapa
    myMapView.addLayer(mRoadBaseMaps, 0);
    myMapView.addLayer(LySED, 1);
    myMapView.addLayer(LySSEE, 2);
    myMapView.addLayer(LySALIDAALIM, 3);
    myMapView.addLayer(LyPOSTES, 4);
    myMapView.addLayer(LyREDMT, 5);
    myMapView.addLayer(LyREDBT, 6);
    myMapView.addLayer(LyREDAP, 7);
    myMapView.addLayer(LyEQUIPOSLINEA, 8);
    myMapView.addLayer(LyEQUIPOSPTO, 9);
    myMapView.addLayer(LyLUMINARIAS, 10);
    myMapView.addLayer(LyCLIENTES, 11);
    myMapView.addLayer(LyMEDIDORES, 12);
    myMapView.addLayer(LyCONCESIONES, 13);
    myMapView.addLayer(LyDIRECCIONES, 14);
    myMapView.addLayer(LyEMPALMES, 15);
    myMapView.addLayer(LyREDSTX, 16);
    myMapView.addLayer(LyTORRESSTX, 17);
    myMapView.addLayer(LyENCUESTA, 18);
    myMapView.addLayer(LyREEMPLAZO, 19);
    myMapView.addLayer(LyELECTRODEP, 20);

    final FloatingActionButton btnGps = (FloatingActionButton) findViewById(R.id.action_gps);
    btnGps.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                alertNoGps();
            }
            toogleGps(v);
        }
    });

    btnGps.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "Funcin Gps", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    final FloatingActionButton btnVerData = (FloatingActionButton) findViewById(R.id.action_ver_data);
    btnVerData.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toogleData(v);
        }
    });

    btnVerData.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "Ver Datos", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    drawOk = new ShapeDrawable(new OvalShape());
    drawOk.getPaint().setColor(getResources().getColor(R.color.colorPrimary));

    drawNo = new ShapeDrawable(new OvalShape());
    drawNo.getPaint().setColor(getResources().getColor(R.color.black_overlay));

    menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    fabShowDialog = (FloatingActionButton) findViewById(R.id.action_show_dialog);
    if (fabShowDialog != null)
        fabShowDialog.setVisibility(View.GONE);

    fabNavRoute = (FloatingActionButton) findViewById(R.id.action_nav_route);
    if (fabNavRoute != null) {
        fabNavRoute.setVisibility(View.GONE);
        fabNavRoute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (myMapView != null && myMapView.getCallout().isShowing()) {
                    Point p = (Point) GeometryEngine.project(myMapView.getCallout().getCoordinates(), wm, egs);
                    Util.QueryNavigation(StandardActivity.this, p);
                }
            }
        });

        fabNavRoute.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(getApplicationContext(), "Ir a Ruta", Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java

private void initializeUI() {
    setContentView(R.layout.romanblack_fanwall_main);

    mainlLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main);
    mainlLayout.setBackgroundColor(Statics.color1);

    // less then android L
    if (android.os.Build.VERSION.SDK_INT <= 20) {
        InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
        SoftKeyboard softKeyboard;//from  ww w.  j  av  a  2  s.c om
        softKeyboard = new SoftKeyboard(mainlLayout, im);
        softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() {

            @Override
            public void onSoftKeyboardHide() {
                Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 1, 0);
                handler.sendMessage(msg);
            }

            @Override
            public void onSoftKeyboardShow() {
                Message msg = handler.obtainMessage(HANDLE_TAP_BAR, 0, 0);
                handler.sendMessage(msg);
            }
        });
    }

    bottomBarHodler = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_bottom_bar);

    TextView noMsgText = (TextView) findViewById(R.id.romanblack_fanwall_nomessages_text);

    // top bar
    setTopBarLeftButtonText(getResources().getString(R.string.common_home_upper), true,
            new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });

    // set title
    if (TextUtils.isEmpty(widget.getTitle()))
        setTopBarTitle(getString(R.string.fanwall_talks));
    else
        setTopBarTitle(widget.getTitle());

    imageHolder = (LinearLayout) findViewById(R.id.fanwall_image_holder);
    userImage = (ImageView) findViewById(R.id.fanwall_user_image);
    closeBtn = (ImageView) findViewById(R.id.fanwall_close_image);
    closeBtn.setOnClickListener(this);

    chooserHolder = (LinearLayout) findViewById(R.id.fanwall_chooser_holder);
    openBottom = (LinearLayout) findViewById(R.id.romanblack_fanwall_open_bottom);
    openBottom.setOnClickListener(this);

    enableGpsCheckbox = (CheckBox) findViewById(R.id.romanblack_fanwall_enable_gps_checkbox);
    enableGpsCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(FanWallPlugin.this);
                    builder.setMessage(getString(R.string.enable_gps_msg)).setCancelable(false)
                            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                                        @SuppressWarnings("unused") final int id) {
                                    startActivityForResult(
                                            new Intent(
                                                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                            GPS_SETTINGS_ACTIVITY);
                                }
                            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                                public void onClick(final DialogInterface dialog,
                                        @SuppressWarnings("unused") final int id) {
                                    enableGpsCheckbox.setChecked(false);
                                    dialog.dismiss();
                                }
                            });
                    final AlertDialog alert = builder.create();
                    alert.show();
                } else {
                    Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true);
                }
            } else
                Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false);

        }
    });
    enableGpsCheckbox.setChecked(Prefs.with(FanWallPlugin.this).getBoolean(Prefs.KEY_GPS, false));

    galleryChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_gallery);
    galleryChooser.setOnClickListener(this);
    photoChooser = (LinearLayout) findViewById(R.id.romanblack_fanwall_make_photo);
    photoChooser.setOnClickListener(this);

    postMsg = (LinearLayout) findViewById(R.id.romanblack_fanwall_send_post);
    postMsg.setOnClickListener(this);
    editMsg = (EditText) findViewById(R.id.romanblack_fanwall_edit_msg);
    editMsg.addTextChangedListener(FanWallPlugin.this);

    tabHolder = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder);
    tabHolder.setBackgroundColor(res.getColor(R.color.black_50_trans));
    LinearLayout separator = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_separator);
    separator.setBackgroundColor(res.getColor(R.color.white_30_trans));
    LinearLayout separatorUp = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_up);
    LinearLayout separatorDown = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_holder_down);

    tabMapLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_map_layout);
    tabMapLayout.setOnClickListener(this);

    tabPhotosLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_tab_photos_layout);
    tabPhotosLayout.setOnClickListener(this);

    if (Statics.isSchemaDark) {
        separatorUp.setBackgroundColor(res.getColor(R.color.white_20_trans));
        separatorDown.setBackgroundColor(res.getColor(R.color.white_20_trans));
        int temp = Color.WHITE & 0x00ffffff;
        int result = temp | 0x80000000;
        noMsgText.setTextColor(result);
    } else {
        separatorUp.setBackgroundColor(res.getColor(R.color.black_20_trans));
        separatorDown.setBackgroundColor(res.getColor(R.color.black_20_trans));
        int temp = Color.BLACK & 0x00ffffff;
        int result = temp | 0x80000000;
        noMsgText.setTextColor(result);
    }

    noMessagesLayout = (LinearLayout) findViewById(R.id.romanblack_fanwall_main_nomessages_layout);

    messageListLayoutRoot = (FrameLayout) findViewById(R.id.romanblack_fanwall_messagelist_list_layout);
    messageList = (PullToRefreshListView) findViewById(R.id.romanblack_fanwall_messagelist_pulltorefresh);
    messageList.setDivider(null);
    messageList.setBackgroundColor(Color.TRANSPARENT);
    messageList.setDrawingCacheBackgroundColor(Color.TRANSPARENT);

    ILoadingLayout loadingLayout = messageList.getLoadingLayoutProxy();
    if (Statics.isSchemaDark) {
        loadingLayout.setHeaderColor(Color.WHITE);
    } else {
        loadingLayout.setHeaderColor(Color.BLACK);
    }

    //messageList.set
    adapter = new MainLayoutMessagesAdapter(FanWallPlugin.this, messageList, messages, widget);
    adapter.setInnerInterface(new MainLayoutMessagesAdapter.onEndReached() {
        @Override
        public void endReached() {
            if (!refreshingBottom)
                refreshBottom();
        }
    });

    messageList.setAdapter(adapter);
    messageList.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
        @Override
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            refreshTop();
        }
    });

    if (Statics.canEdit.compareToIgnoreCase("all") == 0) {
        bottomBarHodler.setVisibility(View.VISIBLE);
    } else {
        bottomBarHodler.setVisibility(View.GONE);
    }

    // start downloading messages
    // exactly in create() method!!!
    handler.sendEmptyMessage(SHOW_PROGRESS_DIALOG);
    refreshMessages();
}

From source file:com.example.administrator.myapplication2._2_exercise._2_Status_heart.fragments.LeftFragment.java

/**
 *   ??  ? //from   ww  w .j av a  2s  .c  o  m
 */
private void startLocationService() {
    //  ? ? 
    manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    //   ?   ? ?
    gpsListener = new GPSListener();
    long minTime = 5000;//GPS    - 20  
    float minDistance = 1;//?? (10m)

    // GPS   
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, gpsListener);

    // ?   
    manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTime, minDistance, gpsListener);

    /*   //  ?? ? ?? ? ??    ?
       try {
    Location lastLocation = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (lastLocation != null) {
        Double latitude = lastLocation.getLatitude();
        Double longitude = lastLocation.getLongitude();
            
    }
       } catch(Exception ex) {
    ex.printStackTrace();
       }*/

}

From source file:com.adwhirl.AdWhirlManager.java

public Location getLocation() {
    if (contextReference == null) {
        return null;
    }//from  w ww  . j  a v  a 2s. c om

    Context context = contextReference.get();
    if (context == null) {
        return null;
    }

    Location location = null;

    if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } else if (context.checkCallingOrSelfPermission(
            android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    return location;
}