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.layer.atlas.messenger.AtlasMessagesScreen.java

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

    updateValues();//  w  w  w .  j  a  va 2 s . co  m
    messagesList.jumpToLastMessage();

    // restore location tracking
    int requestLocationTimeout = 1 * 1000; // every second
    int distance = 100;
    Location loc = null;
    if (locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
        loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (debug)
            Log.w(TAG, "onResume() location from gps: " + loc);
    }
    if (loc == null && locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
        loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (debug)
            Log.w(TAG, "onResume() location from network: " + loc);
    }
    if (loc != null && loc.getTime() < System.currentTimeMillis() + LOCATION_EXPIRATION_TIME) {
        locationTracker.onLocationChanged(loc);
    }
    if (locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, requestLocationTimeout, distance,
                locationTracker);
    }
    if (locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, requestLocationTimeout,
                distance, locationTracker);
    }

    app.getLayerClient().registerEventListener(messagesList);
    app.getLayerClient().registerTypingIndicator(typingIndicator.clear());

    // when something changed
    app.getLayerClient().registerEventListener(new LayerChangeEventListener.MainThread() {
        public void onEventMainThread(LayerChangeEvent event) {
            updateValues();
        }
    });
}

From source file:com.geotrackin.gpslogger.GpsLoggingService.java

/**
 * Starts the location manager. There are two location managers - GPS and
 * Cell Tower. This code determines which manager to request updates from
 * based on user preference and whichever is enabled. If GPS is enabled on
 * the phone, that is used. But if the user has also specified that they
 * prefer cell towers, then cell towers are used. If neither is enabled,
 * then nothing is requested./*from  w  w  w  .ja v a  2  s  . c  o  m*/
 */
private void StartGpsManager() {
    tracer.debug("GpsLoggingService.StartGpsManager");

    GetPreferences();

    if (gpsLocationListener == null) {
        gpsLocationListener = new GeneralLocationListener(this, "GPS");
    }

    if (towerLocationListener == null) {
        towerLocationListener = new GeneralLocationListener(this, "CELL");
    }

    gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    CheckTowerAndGpsStatus();

    if (Session.isGpsEnabled() && AppSettings.getChosenListeners().contains("gps")) {
        tracer.info("Requesting GPS location updates");
        // gps satellite based
        gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener);

        gpsLocationManager.addGpsStatusListener(gpsLocationListener);
        gpsLocationManager.addNmeaListener(gpsLocationListener);

        Session.setUsingGps(true);
        startAbsoluteTimer();

    }

    if (Session.isTowerEnabled()
            && (AppSettings.getChosenListeners().contains("network") || !Session.isGpsEnabled())) {
        tracer.info("Requesting tower location updates");
        Session.setUsingGps(false);
        // Cell tower and wifi based
        towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0,
                towerLocationListener);

        startAbsoluteTimer();

    }

    if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) {
        tracer.info("No provider available");
        Session.setUsingGps(false);
        SetStatus(R.string.gpsprovider_unavailable);
        SetFatalMessage(R.string.gpsprovider_unavailable);
        StopLogging();
        return;
    }

    if (mainServiceClient != null) {
        mainServiceClient.OnWaitingForLocation(true);
        Session.setWaitingForLocation(true);
    }

    SetStatus(R.string.started);
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.UzBMap.java

private boolean isLocationOPen() {
    LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
    boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    return gps;//from   ww  w  .j a v  a  2s  .c om
}

From source file:com.adflake.AdFlakeManager.java

/**
 * Gets the current location./*from w ww.jav  a2s  .  c  o m*/
 * 
 * @note If location is not enabled, this method will return null
 * @return the current location or null if location access is not enabled or
 *         granted by the user.
 */
public Location getCurrentLocation() {
    if (_contextReference == null) {
        return null;
    }

    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;
}

From source file:gov.nasa.arc.geocam.geocam.GeoCamService.java

private void registerListener() {
    long minTime = GeoCamMobile.POS_UPDATE_MSECS_SLOW;

    if (mInForeground)
        minTime = GeoCamMobile.POS_UPDATE_MSECS_ACTIVE;

    if (mRecordingTrack)
        minTime = GeoCamMobile.POS_UPDATE_MSECS_RECORDING;

    if (mIsLocationUpdateFast)
        minTime = GeoCamMobile.POS_UPDATE_MSECS_FAST;

    if (minTime == mGpsUpdateRate.get()) {
        Log.d(GeoCamMobile.DEBUG_ID,//  ww w  .  j  a  v a  2  s.c  om
                "Current rate is same as previous. Not re-registering GPS updates: " + minTime + "ms");
        return;
    }

    synchronized (mMutex) {

        if (mIsLocationRegistered)
            unregisterListener();

        Log.d(GeoCamMobile.DEBUG_ID, "Registering GPS listener for " + minTime + "ms update rate");

        try {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, 0,
                    mLocationListener);
        } catch (RuntimeException e) {
            Log.e(GeoCamMobile.DEBUG_ID, "Unable to register LocationListener: " + e);
            return;
        }

        mGpsUpdateRate.set(minTime);
        mIsLocationRegistered = true;
    }
}

From source file:net.e_fas.oss.tabijiman.MapsActivity.java

@Override
public void onMapReady(GoogleMap googleMap) {

    e_print("onMapReady");
    mMap = googleMap;//  www.  j av  a 2  s .c o  m

    GoFukuiButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CameraPosition cameraPos = new CameraPosition.Builder().target(new LatLng(36.0642988, 136.220012))
                    .zoom(10.0f).bearing(0).build();
            mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos));
            GoFukuiButton.setVisibility(View.GONE);
        }
    });

    CameraPosition cameraPos = new CameraPosition.Builder().target(new LatLng(36.0614444, 136.2229937))
            .zoom(zoomLevel).bearing(0).build();
    mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos));

    // ??
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            Toast.makeText(getApplicationContext(), marker.getTitle(), Toast.LENGTH_LONG).show();
            return false;
        }
    });

    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {

            View view = getLayoutInflater().inflate(R.layout.info_window, null);
            // 
            TextView title = (TextView) view.findViewById(R.id.info_title);
            title.setText(marker.getTitle());
            e_print("marker_Snippet >> " + marker.getSnippet());

            if (marker.getSnippet() == null) {
                view.findViewById(R.id.info_address).setVisibility(View.GONE);
            } else {
                TextView address = (TextView) view.findViewById(R.id.info_address);
                address.setText(marker.getSnippet());
            }
            return view;
        }
    });

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {

            e_print("title_name >> " + marker.getTitle());

            //DB()??
            SQLiteDatabase dbRead = helper.getReadableDatabase();

            //SQL
            String select_frame_sql = "SELECT * FROM frame WHERE `name` = ? AND `lat` = ? AND `lng` = ?";
            String select_place_sql = "SELECT * FROM place WHERE `name` = ? AND `lat` = ? AND `lng` = ?";
            //SQL?
            Cursor cursor = dbRead.rawQuery(select_place_sql,
                    new String[] { marker.getTitle(), String.valueOf(marker.getPosition().latitude),
                            String.valueOf(marker.getPosition().longitude) });

            e_print("cursor_count >> " + cursor.getCount());

            if (cursor.getCount() != 0) {

                cursor.moveToFirst();

                e_print("lat >> " + marker.getPosition().latitude + " lng >> "
                        + marker.getPosition().longitude);

                Intent MoreInfo = new Intent(getApplicationContext(), MoreInfo.class);
                MoreInfo.putExtra("id", cursor.getInt(cursor.getColumnIndex("_id")));
                MoreInfo.putExtra("cat", "place");

                cursor.close();

                startActivity(MoreInfo);
            } else {

                cursor.close();

                //SQL?
                Cursor cursor2 = dbRead.rawQuery(select_frame_sql,
                        new String[] { marker.getTitle(), String.valueOf(marker.getPosition().latitude),
                                String.valueOf(marker.getPosition().longitude) });
                cursor2.moveToFirst();

                /*
                 * distance[0] = [??]
                 * distance[1] = [???]
                 * distance[2] = [???]
                 */
                float[] distance = getDistance(nowLocation.latitude, nowLocation.longitude,
                        marker.getPosition().latitude, marker.getPosition().longitude);

                Intent MoreInfo = new Intent(getApplicationContext(), MoreInfo.class);
                MoreInfo.putExtra("dist", distance[0]);
                MoreInfo.putExtra("id", cursor2.getInt(cursor2.getColumnIndex("_id")));
                MoreInfo.putExtra("cat", "frame");

                cursor2.close();

                startActivity(MoreInfo);
            }

        }
    });

    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            e_print("MyLocation >> " + location);

            Toast.makeText(getApplicationContext(), "location >> " + location, Toast.LENGTH_SHORT).show();
            return false;
        }
    });

    mMap.setMyLocationEnabled(true);
    // MyLocationButton?
    UiSettings settings = mMap.getUiSettings();
    settings.setMyLocationButtonEnabled(true);

    //??
    View locationButton = ((View) super.findViewById(Integer.parseInt("1")).getParent())
            .findViewById(Integer.parseInt("2"));

    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    rlp.setMargins(0, 0, 180, 180);

    print("mMap >> insert");

    for (String provider : providers) {

        e_print("enable_providers >> " + provider);
        mLocationManager.requestLocationUpdates(provider, 3000, 0, this);
    }

    if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {

        e_print("Provider_enable >> NETWORK");

        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);

    } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

        e_print("Providers_enable >> GPS");

        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this);
    } else {

        e_print("All_Providers_Disable");

    }
}

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

/**
 * Called by {@link MainActivity} when the status of the GPS changes. Updates GPS display.
 *///w  ww.j ava 2s  .  co m
public void onGpsStatusChanged(GpsStatus status, int satsInView, int satsUsed, Iterable<GpsSatellite> sats) {
    if (satsUsed == 0) {
        Location location = providerLocations.get(LocationManager.GPS_PROVIDER);
        if (location != null)
            markLocationAsStale(location);
        applyLocationProviderStyle(this.getContext(), LocationManager.GPS_PROVIDER,
                Const.LOCATION_PROVIDER_GRAY);
    }
}

From source file:com.ushahidi.android.app.ui.phone.ListMapActivity.java

/** Location stuff **/
// Fetches the current location of the device.
protected void setDeviceLocation() {
    mLocationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Get last known location from either GPS or Network provider
    Location loc = null;/*  w ww .j  a  va 2 s.  c  o  m*/
    boolean netAvail = (mLocationMgr.getProvider(LocationManager.NETWORK_PROVIDER) != null);
    boolean gpsAvail = (mLocationMgr.getProvider(LocationManager.GPS_PROVIDER) != null);
    if (gpsAvail) {
        loc = mLocationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } else if (netAvail) {
        loc = mLocationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }

    // Just use last location if it's less than 10 minutes old
    if (loc != null && ((new Date()).getTime() - loc.getTime() < 10 * 60 * 1000)) {
        onLocationChanged(loc);
    } else {
        if (gpsAvail) {
            mLocationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        }
        if (netAvail) {
            mLocationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
        }
    }
}

From source file:com.trigger_context.Main_Service.java

private boolean testConditions(String mac) {
    SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE);
    Map<String, ?> cond_map = conditions.getAll();
    Set<String> key_set = cond_map.keySet();
    boolean takeAction = true;
    if (key_set.contains("bluetooth")) {
        // checking the current state against the state set by the user
        final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        takeAction = new Boolean(bluetoothAdapter.isEnabled())
                .equals(conditions.getString("bluetooth", "false"));
    }/*from   w w  w .  j av  a  2  s .  com*/
    if (takeAction && key_set.contains("wifi")) {
        final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        takeAction = new Boolean(wm.isWifiEnabled()) == conditions.getBoolean("wifi", false);
    }

    if (takeAction && key_set.contains("gps")) {
        final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        takeAction = new Boolean(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
                .equals(conditions.getString("gps", "false"));
    }
    if (takeAction && key_set.contains("sms")) {
        final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
        Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null);
        if (c != null) {
            int unreadMessagesCount = c.getCount();
            c.close();
            takeAction = new Boolean(unreadMessagesCount > 0).equals(conditions.getString("sms", "false"));
        } else {
            takeAction = false;
        }
    }

    // "NOT TESTED" head set, missed call, accelerometer, proximity, gyro,
    // orientation
    if (takeAction && key_set.contains("headset")) {
        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        takeAction = am.isMusicActive() == conditions.getBoolean("headset", false);
        // am.isWiredHeadsetOn() is deprecated

    }
    /*
     * if(takeAction && key_set.contains("missedCall")) { final String[]
     * projection = null; final String selection = null; final String[]
     * selectionArgs = null; final String sortOrder =
     * android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null;
     * try{ cursor = getApplicationContext().getContentResolver().query(
     * Uri.parse("content://call_log/calls"), projection, selection,
     * selectionArgs, sortOrder); while (cursor.moveToNext()) { String
     * callLogID =
     * cursor.getString(cursor.getColumnIndex(android.provider.CallLog
     * .Calls._ID)); String callNumber =
     * cursor.getString(cursor.getColumnIndex
     * (android.provider.CallLog.Calls.NUMBER)); String callDate =
     * cursor.getString
     * (cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String
     * callType =
     * cursor.getString(cursor.getColumnIndex(android.provider.CallLog
     * .Calls.TYPE)); String isCallNew =
     * cursor.getString(cursor.getColumnIndex
     * (android.provider.CallLog.Calls.NEW)); if(Integer.parseInt(callType)
     * == android.provider.CallLog.Calls.MISSED_CALL_TYPE &&
     * Integer.parseInt(isCallNew) > 0){
     * 
     * } } }catch(Exception ex){ }finally{ cursor.close(); }
     * 
     * }
     */
    return takeAction;
}

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == SHOW_PHOTOLIST_ACTIVITY || requestCode == SHOW_IMAGES_ACTIVITY) {
        messages.clear();/*from ww  w.j  a v  a  2  s .c  o  m*/
        refreshMessages();
    } else if (requestCode == GPS_SETTINGS_ACTIVITY) {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, false);
            enableGpsCheckbox.setChecked(false);
        } else {
            enableGpsCheckbox.setChecked(true);
            Prefs.with(FanWallPlugin.this).save(Prefs.KEY_GPS, true);
        }
    } else if (requestCode == FACEBOOK_AUTHORIZATION_ACTIVITY) {
        if (resultCode == RESULT_OK)
            shareFacebook();
        else if (resultCode == RESULT_CANCELED)
            Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.alert_facebook_auth_error),
                    Toast.LENGTH_SHORT).show();
    } else if (requestCode == TWITTER_AUTHORIZATION_ACTIVITY) {
        if (resultCode == RESULT_OK)
            shareTwitter();
        else if (resultCode == RESULT_CANCELED)
            Toast.makeText(FanWallPlugin.this, getResources().getString(R.string.alert_twitter_auth_error),
                    Toast.LENGTH_SHORT).show();
    } else if (requestCode == TWITTER_PUBLISH_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            // increment sharing count
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (postIdToShare != -1) {
                        IncrementSharingStatus status = Statics.incrementSharing(Long.toString(postIdToShare));
                        Log.e(TAG, "Status = " + status.toString());

                        if (status.status_code == 0) {
                            FanWallMessage resMsg = null;
                            for (FanWallMessage msg : messages) {
                                if (msg.getId() == postIdToShare) {
                                    msg.setSharingCount(msg.getSharingCount() + 1);
                                    resMsg = msg;
                                    break;
                                }
                            }

                            if (resMsg != null)
                                handler.sendEmptyMessage(SHOW_MESSAGES);
                        }
                    }
                }
            }).start();

            Toast.makeText(FanWallPlugin.this,
                    getResources().getString(R.string.directoryplugin_twitter_posted_success),
                    Toast.LENGTH_LONG).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(FanWallPlugin.this,
                    getResources().getString(R.string.directoryplugin_twitter_posted_error), Toast.LENGTH_LONG)
                    .show();
        }
    } else if (requestCode == FACEBOOK_PUBLISH_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            // increment sharing count
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (postIdToShare != -1) {
                        IncrementSharingStatus status = Statics.incrementSharing(Long.toString(postIdToShare));
                        Log.e(TAG, "Status = " + status.toString());

                        if (status.status_code == 0) {
                            FanWallMessage resMsg = null;
                            for (FanWallMessage msg : messages) {
                                if (msg.getId() == postIdToShare) {
                                    msg.setSharingCount(msg.getSharingCount() + 1);
                                    resMsg = msg;
                                    break;
                                }
                            }

                            if (resMsg != null)
                                handler.sendEmptyMessage(SHOW_MESSAGES);
                        }
                    }
                }
            }).start();

            Toast.makeText(FanWallPlugin.this,
                    getResources().getString(R.string.directoryplugin_facebook_posted_success),
                    Toast.LENGTH_LONG).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(FanWallPlugin.this,
                    getResources().getString(R.string.directoryplugin_facebook_posted_error), Toast.LENGTH_LONG)
                    .show();
        }
    } else

    if (requestCode == FACEBOOK_LIKE_AUTH) {
        if (resultCode == RESULT_OK) {
            if (!TextUtils.isEmpty(urlToLike)) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            if (FacebookAuthorizationActivity.like(urlToLike))
                                refreshTop();
                        } catch (FacebookAuthorizationActivity.FacebookNotAuthorizedException e) {
                            e.printStackTrace();
                        } catch (FacebookAuthorizationActivity.FacebookAlreadyLiked facebookAlreadyLiked) {
                            refreshTop();
                        }
                    }
                }).start();
            }
        }
    } else if (requestCode == AUTHORIZATION_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            if (action == ACTIONS.SEND_MESSAGE) {
                startActivityForResult(actionIntent, SEND_MESSAGE_ACTIVITY);
            } else if (action == ACTIONS.SEND_MESSAGE_FROM_WALL) {
                showProgressDialog();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        FanWallMessage msg = Statics.postMessage(editMsg.getText().toString(), imagePath, 0, 0,
                                Prefs.with(getApplicationContext()).getBoolean(Prefs.KEY_GPS, false));
                        if (msg != null) {
                            imagePath = "";
                            handler.sendEmptyMessage(CLEAR_MSG_TEXT);

                            if (messages.size() == 0)
                                refreshMessages();
                            else
                                refreshTop();
                        } else
                            handler.sendEmptyMessage(HIDE_PROGRESS_DIALOG);
                    }
                }).start();
            }
        }
    } else if (requestCode == SIGN_UP_ACTIVITY) {
        if (resultCode == RESULT_OK) {

            if (action == ACTIONS.SEND_MESSAGE) {
                startActivityForResult(actionIntent, SEND_MESSAGE_ACTIVITY);
            }
        }
    } else if (requestCode == MESSAGE_VIEW_ACTIVITY) {
        FanWallMessage msg = (FanWallMessage) data.getSerializableExtra("message");
        if (msg != null) {
            for (FanWallMessage s : messages) {
                if (s.getId() == msg.getId()) {
                    s.setTotalComments(msg.getTotalComments());
                    break;
                }
            }
        }

        if (Prefs.with(FanWallPlugin.this).getBoolean(Prefs.KEY_GPS, false))
            enableGpsCheckbox.setChecked(true);
        else
            enableGpsCheckbox.setChecked(false);

        refreshMessages();
        handler.sendEmptyMessage(SHOW_MESSAGES);
    } else if (requestCode == IMAGE_VIEW_ACTIVITY) {
    } else if (requestCode == SEND_MESSAGE_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            final FanWallMessage tmpMessage = (FanWallMessage) data.getSerializableExtra("message");

            new Thread(new Runnable() {
                public void run() {
                    boolean stop = false;

                    ArrayList<FanWallMessage> tmpTmpMessages = new ArrayList<FanWallMessage>();
                    while (!stop) {

                        ArrayList<FanWallMessage> tmpMessages = new ArrayList<FanWallMessage>();

                        if (messages.isEmpty()) {
                            tmpMessages = JSONParser.parseMessagesUrl(
                                    Statics.BASE_URL + "/" + com.appbuilder.sdk.android.Statics.appId + "/"
                                            + Statics.MODULE_ID + "/" + "0" + "/" + "0" + "/" + "0" + "/" + "0"
                                            + "/" + com.appbuilder.sdk.android.Statics.appId + "/"
                                            + com.appbuilder.sdk.android.Statics.appToken);
                        } else {
                            tmpMessages = JSONParser.parseMessagesUrl(Statics.BASE_URL + "/"
                                    + com.appbuilder.sdk.android.Statics.appId + "/" + Statics.MODULE_ID + "/"
                                    + "0" + "/" + "0" + "/" + messages.get(0).getId() + "/" + "0" + "/"
                                    + com.appbuilder.sdk.android.Statics.appId + "/"
                                    + com.appbuilder.sdk.android.Statics.appToken);
                        }

                        for (int i = 0; i < tmpMessages.size(); i++) {
                            FanWallMessage msg = tmpMessages.get(tmpMessages.size() - i - 1);
                            tmpTmpMessages.add(msg);
                            if (msg.getId() == tmpMessage.getId()) {
                                stop = true;
                                break;
                            }
                        }
                    }

                    Collections.reverse(tmpTmpMessages);
                    tmpTmpMessages.addAll(messages);
                    messages.clear();
                    messages.addAll(tmpTmpMessages);

                    if (messages.isEmpty()) {
                        handler.sendEmptyMessage(SHOW_NO_MESSAGES);
                    } else {
                        handler.sendEmptyMessage(SHOW_MESSAGES);
                    }
                }
            }).start();

        }
    } else if (requestCode == TAKE_A_PICTURE_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            imagePath = data.getStringExtra("imagePath");

            if (TextUtils.isEmpty(imagePath))
                return;

            chooserHolder.setVisibility(View.GONE);

            setImage();
        }
    } else if (requestCode == PICK_IMAGE_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();

            imagePath = filePath;

            if (TextUtils.isEmpty(imagePath))
                return;

            if (imagePath.startsWith("http")) {
                Toast.makeText(this, R.string.romanblack_fanwall_alert_cant_select_image, Toast.LENGTH_LONG)
                        .show();
                return;
            }
            chooserHolder.setVisibility(View.GONE);

            setImage();
        }
    }
}