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.piusvelte.sonet.core.SonetCreatePost.java

protected void chooseAccounts() {
    // don't limit accounts to the widget...
    Cursor c = this.getContentResolver().query(Accounts.getContentUri(this),
            new String[] { Accounts._ID, ACCOUNTS_QUERY, Accounts.SERVICE }, null, null, null);
    if (c.moveToFirst()) {
        int i = 0;
        ;//from  www. jav  a  2 s . c o m
        int count = c.getCount();
        final long[] accountIndexes = new long[count];
        final String[] accounts = new String[count];
        final boolean[] defaults = new boolean[count];
        final int[] accountServices = new int[count];
        while (!c.isAfterLast()) {
            long id = c.getLong(0);
            accountIndexes[i] = id;
            accounts[i] = c.getString(1);
            accountServices[i] = c.getInt(2);
            defaults[i++] = mAccountsService.containsKey(id);
            c.moveToNext();
        }
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                .setMultiChoiceItems(accounts, defaults, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        if (isChecked) {
                            final long accountId = accountIndexes[which];
                            mAccountsService.put(accountId, accountServices[which]);
                            if (sLocationSupported.contains(accountServices[which])) {
                                if (mLat == null) {
                                    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 ((mLat != null) && (mLong != null)) {
                                    dialog.cancel();
                                    mDialog = (new AlertDialog.Builder(SonetCreatePost.this))
                                            .setTitle(R.string.set_location)
                                            .setPositiveButton(android.R.string.ok,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            setLocation(accountId);
                                                            dialog.dismiss();
                                                        }
                                                    })
                                            .setNegativeButton(android.R.string.cancel,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();
                                                        }
                                                    })
                                            .create();
                                    mDialog.show();
                                }
                            }
                        } else {
                            mAccountsService.remove(accountIndexes[which]);
                            mAccountsLocation.remove(accountIndexes[which]);
                            mAccountsTags.remove(accountIndexes[which]);
                        }
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create();
        mDialog.show();
    }
    c.close();
}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

protected void chooseAccounts() {
    // don't limit accounts to the widget...
    Cursor c = this.getContentResolver().query(Accounts.getContentUri(this),
            new String[] { Accounts._ID, ACCOUNTS_QUERY, Accounts.SERVICE }, null, null, null);
    if (c.moveToFirst()) {
        int i = 0;
        ;//from  w w  w  .  ja  v  a2  s.c om
        int count = c.getCount();
        final long[] accountIndexes = new long[count];
        final String[] accounts = new String[count];
        final boolean[] defaults = new boolean[count];
        final int[] accountServices = new int[count];
        while (!c.isAfterLast()) {
            long id = c.getLong(0);
            accountIndexes[i] = id;
            accounts[i] = c.getString(1);
            accountServices[i] = c.getInt(2);
            defaults[i++] = mAccountsService.containsKey(id);
            c.moveToNext();
        }
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                .setMultiChoiceItems(accounts, defaults, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        if (isChecked) {
                            final long accountId = accountIndexes[which];
                            mAccountsService.put(accountId, accountServices[which]);
                            if (sLocationSupported.contains(accountServices[which])) {
                                if (mLat == null) {
                                    LocationManager locationManager = (LocationManager) MyfeedleCreatePost.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 ((mLat != null) && (mLong != null)) {
                                    dialog.cancel();
                                    mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this))
                                            .setTitle(R.string.set_location)
                                            .setPositiveButton(android.R.string.ok,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            setLocation(accountId);
                                                            dialog.dismiss();
                                                        }
                                                    })
                                            .setNegativeButton(android.R.string.cancel,
                                                    new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialog, int which) {
                                                            dialog.dismiss();
                                                        }
                                                    })
                                            .create();
                                    mDialog.show();
                                }
                            }
                        } else {
                            mAccountsService.remove(accountIndexes[which]);
                            mAccountsLocation.remove(accountIndexes[which]);
                            mAccountsTags.remove(accountIndexes[which]);
                        }
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create();
        mDialog.show();
    }
    c.close();
}

From source file:com.scoreflex.Scoreflex.java

/**
 * Returns the Location as set in {@link setLocation(Location)} or the best
 * last known location of the {@link LocationManager} or null if permission
 * was not given./*w w w.  j  a  v a 2 s  . c  o  m*/
 */

public static Location getLocation() {
    if (null != sLocation)
        return sLocation;

    Context applicationContext = getApplicationContext();

    if (applicationContext == null)
        return null;

    LocationManager locationManager = (LocationManager) applicationContext
            .getSystemService(Context.LOCATION_SERVICE);
    try {
        Location locations[] = { locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER), };

        Location best = null;
        for (int i = 0; i < locations.length; i++) {

            // If this location is null, discard
            if (null == locations[i])
                continue;

            // If we have no best yet, use this first location
            if (null == best) {
                best = locations[i];
                continue;
            }

            // If this location is significantly older, discard
            long timeDelta = locations[i].getTime() - best.getTime();
            if (timeDelta < -1000 * 60 * 2)
                continue;

            // If we have no accuracy, discard
            if (0 == locations[i].getAccuracy())
                continue;

            // If this location is less accurate, discard
            if (best.getAccuracy() < locations[i].getAccuracy())
                continue;

            best = locations[i];
        }

        return best;
    } catch (java.lang.SecurityException e) {
        // Missing permission;
        return null;
    }
}

From source file:com.aware.Aware_Preferences.java

/**
 * Location module settings UI/*from  ww w  .j  a va 2 s  .c om*/
 */
private void locations() {
    final CheckBoxPreference location_gps = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_LOCATION_GPS);
    location_gps.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS).equals("true"));
    location_gps.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.GPS_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_GPS,
                    location_gps.isChecked());
            if (location_gps.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

    final CheckBoxPreference location_network = (CheckBoxPreference) findPreference(
            Aware_Preferences.STATUS_LOCATION_NETWORK);
    location_network.setChecked(Aware
            .getSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK).equals("true"));
    location_network.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            LocationManager localMng = (LocationManager) getSystemService(LOCATION_SERVICE);
            List<String> providers = localMng.getAllProviders();

            if (!providers.contains(LocationManager.NETWORK_PROVIDER)) {
                showDialog(DIALOG_ERROR_MISSING_SENSOR);
                location_gps.setChecked(false);
                Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK, false);
                return false;
            }

            Aware.setSetting(getApplicationContext(), Aware_Preferences.STATUS_LOCATION_NETWORK,
                    location_network.isChecked());
            if (location_network.isChecked()) {
                framework.startLocations();
            } else {
                framework.stopLocations();
            }
            return true;
        }
    });

    final EditTextPreference gpsInterval = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_LOCATION_GPS);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS).length() > 0) {
        gpsInterval
                .setSummary(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS)
                        + " seconds");
    }
    gpsInterval.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS));
    gpsInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_GPS,
                    (String) newValue);
            gpsInterval.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference networkInterval = (EditTextPreference) findPreference(
            Aware_Preferences.FREQUENCY_LOCATION_NETWORK);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK).length() > 0) {
        networkInterval.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK)
                        + " seconds");
    }
    networkInterval
            .setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK));
    networkInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_LOCATION_NETWORK,
                    (String) newValue);
            networkInterval.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference gpsAccuracy = (EditTextPreference) findPreference(
            Aware_Preferences.MIN_LOCATION_GPS_ACCURACY);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY).length() > 0) {
        gpsAccuracy.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY)
                        + " meters");
    }
    gpsAccuracy.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY));
    gpsAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_GPS_ACCURACY,
                    (String) newValue);
            gpsAccuracy.setSummary((String) newValue + " meters");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference networkAccuracy = (EditTextPreference) findPreference(
            Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY)
            .length() > 0) {
        networkAccuracy.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY)
                        + " meters");
    }
    networkAccuracy.setText(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY));
    networkAccuracy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.MIN_LOCATION_NETWORK_ACCURACY,
                    (String) newValue);
            networkAccuracy.setSummary((String) newValue + " meters");
            framework.startLocations();
            return true;
        }
    });

    final EditTextPreference expirateTime = (EditTextPreference) findPreference(
            Aware_Preferences.LOCATION_EXPIRATION_TIME);
    if (Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME).length() > 0) {
        expirateTime.setSummary(
                Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME)
                        + " seconds");
    }
    expirateTime.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME));
    expirateTime.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.LOCATION_EXPIRATION_TIME,
                    (String) newValue);
            expirateTime.setSummary((String) newValue + " seconds");
            framework.startLocations();
            return true;
        }
    });
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Registers for updates with selected location providers.
 * @param context/*from  ww  w .j  a  v a2 s. c  om*/
 */
protected void registerLocationProviders(Context context) {
    Set<String> providers = new HashSet<String>(
            mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV, new HashSet<String>(Arrays
                    .asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }))));
    List<String> allProviders = mLocationManager.getAllProviders();

    mLocationManager.removeUpdates(this);

    ArrayList<String> removedProviders = new ArrayList<String>();
    for (String pr : providerLocations.keySet())
        if (!providers.contains(pr))
            removedProviders.add(pr);
    for (String pr : removedProviders)
        providerLocations.remove(pr);

    for (String pr : providers) {
        if (allProviders.indexOf(pr) >= 0) {
            if (!providerLocations.containsKey(pr)) {
                Location location = new Location("");
                providerLocations.put(pr, location);
            }
            if (!isStopped) {
                mLocationManager.requestLocationUpdates(pr, 0, 0, this);
                Log.d("MainActivity", "Registered with provider: " + pr);
            }
        } else {
            Log.w("MainActivity", "No " + pr
                    + " location provider found. Data display will not be available for this provider.");
        }
    }

    // if GPS is not selected, request location updates but don't store location
    if ((!providers.contains(LocationManager.GPS_PROVIDER)) && (!isStopped)
            && (allProviders.indexOf(LocationManager.GPS_PROVIDER) >= 0))
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}

From source file:com.davidmascharka.lips.TrackerActivity.java

/**
 * Unnecessary if you're not testing/evaluating
 * Prints out the sensor values and time at each data point
 *//*from   w w w  .  j  ava 2s  .c o m*/
private void printValues() {
    valuesWriter.print(accelerometerX + "," + accelerometerY + "," + accelerometerZ + "," + magneticX + ","
            + magneticY + "," + magneticZ + "," + light + "," + rotationX + "," + rotationY + "," + rotationZ
            + "," + orientation[0] + "," + orientation[1] + "," + orientation[2]);

    for (String key : wifiReadings.keySet()) {
        valuesWriter.print("," + wifiReadings.get(key));
    }

    if (location != null) {
        valuesWriter.print(
                "," + location.getLatitude() + "," + location.getLongitude() + "," + location.getAccuracy());
    } else {
        //@author Mahesh Gaya added permission if-statment
        if (ActivityCompat.checkSelfPermission(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                || ActivityCompat.checkSelfPermission(this,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            Log.i(TAG, "Permissions have NOT been granted. Requesting permissions.");
            requestMyPermissions();
        } else {
            Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network");
            location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }
        if (location != null) {
            valuesWriter.print("," + location.getLatitude() + "," + location.getLongitude() + ","
                    + location.getAccuracy());
        } else {
            //@author Mahesh Gaya added permission if-statment
            if (ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
                    || ActivityCompat.checkSelfPermission(this,
                            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                Log.i(TAG, "Permissions have NOT been granted. Requesting permissions.");
                requestMyPermissions();
            } else {
                Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network");
                location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            }
            if (location != null) {
                valuesWriter.print("," + location.getLatitude() + "," + location.getLongitude() + ","
                        + location.getAccuracy());
            } else {
                valuesWriter.print(",?,?,?");
            }
        }
    }

    valuesWriter.print(" %" + (new Timestamp(System.currentTimeMillis())).toString());

    valuesWriter.print("\n\n");
    valuesWriter.flush();

}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Updates internal data structures when the user's selection of location providers has changed.
 * @param context//from w w w. j  a  v  a2 s  .com
 */
protected static void updateLocationProviders(Context context) {
    // add overlays
    if (isMapViewReady) {
        Set<String> providers = mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV,
                new HashSet<String>(Arrays.asList(
                        new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER })));

        updateLocationProviderStyles();

        mapCircles = new HashMap<String, Circle>();
        mapMarkers = new HashMap<String, Marker>();

        ArrayList<String> removedProviders = new ArrayList<String>();
        for (String pr : providerInvalidators.keySet())
            if (!providers.contains(pr))
                removedProviders.add(pr);
        for (String pr : removedProviders)
            providerInvalidators.remove(pr);

        Log.d("MainActivity", "Provider location cache: " + providerLocations.keySet().toString());

        Layers layers = mapMap.getLayerManager().getLayers();

        // remove all layers other than tile render layer from map
        for (int i = 0; i < layers.size();)
            if ((layers.get(i) instanceof TileRendererLayer) || (layers.get(i) instanceof TileDownloadLayer)) {
                i++;
            } else {
                layers.remove(i);
            }

        for (String pr : providers) {
            // no invalidator for GPS, which is invalidated through GPS status
            if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
                final String provider = pr;
                final Context ctx = context;
                providerInvalidators.put(pr, new Runnable() {
                    private String mProvider = provider;

                    @Override
                    public void run() {
                        if (isMapViewReady) {
                            Location location = providerLocations.get(mProvider);
                            if (location != null)
                                markLocationAsStale(location);
                            applyLocationProviderStyle(ctx, mProvider, LOCATION_PROVIDER_GRAY);
                        }
                    }
                });
            }

            String styleName = assignLocationProviderStyle(pr);
            LatLong latLong;
            float acc;
            boolean visible;
            if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
                latLong = new LatLong(providerLocations.get(pr).getLatitude(),
                        providerLocations.get(pr).getLongitude());
                if (providerLocations.get(pr).hasAccuracy())
                    acc = providerLocations.get(pr).getAccuracy();
                else
                    acc = 0;
                visible = true;
                if (isLocationStale(providerLocations.get(pr)))
                    styleName = LOCATION_PROVIDER_GRAY;
                Log.d("MainActivity", pr + " has " + latLong.toString());
            } else {
                latLong = new LatLong(0, 0);
                acc = 0;
                visible = false;
                Log.d("MainActivity", pr + " has no location, hiding");
            }

            // Circle layer
            Resources res = context.getResources();
            TypedArray style = res
                    .obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
            Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
            fill.setColor(style.getColor(STYLE_FILL, R.color.circle_gray_fill));
            fill.setStyle(Style.FILL);
            Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
            stroke.setColor(style.getColor(STYLE_STROKE, R.color.circle_gray_stroke));
            stroke.setStrokeWidth(4); // FIXME: make this DPI-dependent
            stroke.setStyle(Style.STROKE);
            Circle circle = new Circle(latLong, acc, fill, stroke);
            mapCircles.put(pr, circle);
            layers.add(circle);
            circle.setVisible(visible);

            // Marker layer
            Drawable drawable = style.getDrawable(STYLE_MARKER);
            Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
            Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 9 / 20);
            mapMarkers.put(pr, marker);
            layers.add(marker);
            marker.setVisible(visible);
            style.recycle();
        }

        // move layers into view
        updateMap();
    }
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

/**
 * Updates the list of styles to use for the location providers.
 * /*from  w  ww .j av a 2 s  .  c  o m*/
 * This method updates the internal list of styles to use for displaying
 * locations on the map, assigning a style to each location provider.
 * Styles that are defined in {@link SharedPreferences} are preserved. If
 * none are defined, the GPS location provider is assigned the red style
 * and the network location provider is assigned the blue style. The
 * passive location provider is not assigned a style, as it does not send
 * any locations of its own. Other location providers are assigned one of
 * the following styles: green, orange, purple. If there are more location
 * providers than styles, the same style (including red and blue) can be
 * assigned to multiple providers. The mapping is written to 
 * SharedPreferences so that it will be preserved even as available
 * location providers change.
 */
public static void updateLocationProviderStyles() {
    //FIXME: move code into assignLocationProviderStyle and use that
    List<String> allProviders = mLocationManager.getAllProviders();
    allProviders.remove(LocationManager.PASSIVE_PROVIDER);
    if (allProviders.contains(LocationManager.GPS_PROVIDER)) {
        providerStyles.put(LocationManager.GPS_PROVIDER,
                mSharedPreferences.getString(
                        SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.GPS_PROVIDER,
                        LOCATION_PROVIDER_RED));
        mAvailableProviderStyles.remove(LOCATION_PROVIDER_RED);
        allProviders.remove(LocationManager.GPS_PROVIDER);
    }
    if (allProviders.contains(LocationManager.NETWORK_PROVIDER)) {
        providerStyles.put(LocationManager.NETWORK_PROVIDER,
                mSharedPreferences.getString(
                        SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.NETWORK_PROVIDER,
                        LOCATION_PROVIDER_BLUE));
        mAvailableProviderStyles.remove(LOCATION_PROVIDER_BLUE);
        allProviders.remove(LocationManager.NETWORK_PROVIDER);
    }
    for (String prov : allProviders) {
        if (mAvailableProviderStyles.isEmpty())
            mAvailableProviderStyles.addAll(Arrays.asList(LOCATION_PROVIDER_STYLES));
        providerStyles.put(prov, mSharedPreferences.getString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov,
                mAvailableProviderStyles.get(0)));
        mAvailableProviderStyles.remove(providerStyles.get(prov));
    }
    ;
    SharedPreferences.Editor spEditor = mSharedPreferences.edit();
    for (String prov : providerStyles.keySet())
        spEditor.putString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov, providerStyles.get(prov));
    spEditor.commit();
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        String message = messageText.getText().toString();
        Message msjNew = new Message();
        Calendar fecha = Calendar.getInstance();
        String id = u.id + contact.idContacto + fecha.getTimeInMillis()
                + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

        msjNew.mensajeId = id;//from  w  w  w .  jav  a 2 s.  co  m
        msjNew.emisor = u.id;
        msjNew.receptor = contact.idContacto;
        msjNew.mensaje = message;
        msjNew.emisorEmail = u.email;
        msjNew.receptorEmail = contact.email;
        msjNew.emisorLang = u.lang;
        msjNew.receptorLang = contact.lang;
        msjNew.emitedAt = fecha.getTimeInMillis();
        msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_TEXT));
        if (tiempoMensaje)
            msjNew.delay = temporizadorSeek.getValue();
        else
            msjNew.delay = 0;
        msjNew.translation = translate;
        if (SpeakSocket.mSocket != null)
            if (SpeakSocket.mSocket.connected()) {
                msjNew.status = 1;
            } else {
                msjNew.status = -1;
            }

        msjNew.save();
        Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor).executeSingle();
        if (chat == null) {
            Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor)
                    .executeSingle();
            Chats newChat = new Chats();
            newChat.mensajeId = msjNew.mensajeId;
            newChat.idContacto = msjNew.receptor;
            newChat.isLockedConversation = false;
            newChat.lastStatus = msjNew.status;
            newChat.email = msjNew.receptorEmail;
            if (contact != null) {
                newChat.photo = contact.photo;
                newChat.fullName = contact.fullName;
                newChat.lang = contact.lang;
                newChat.screenName = contact.screenName;
                newChat.photoload = true;
                newChat.phone = contact.phone;
            } else {
                newChat.photo = null;
                newChat.photoload = false;
                newChat.fullName = msjNew.receptorEmail;
                newChat.lang = msjNew.receptorLang;
                newChat.screenName = msjNew.receptorEmail;
                newChat.phone = null;
            }
            newChat.emitedAt = msjNew.emitedAt;
            newChat.notRead = 0;
            newChat.lastMessage = msjNew.mensaje;
            newChat.show = true;
            newChat.save();
        } else {
            if (!chat.photoload) {
                Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.emisor)
                        .executeSingle();
                if (contact != null) {
                    chat.photo = contact.photo;
                    chat.photoload = true;
                } else {
                    chat.photo = null;
                    chat.photoload = false;
                }
            }
            chat.mensajeId = msjNew.mensajeId;
            chat.lastStatus = msjNew.status;
            chat.emitedAt = msjNew.emitedAt;
            chat.notRead = 0;
            chat.lastMessage = msjNew.mensaje;
            chat.save();
        }
        messageText.setText("");
        showNewMessage(msjNew);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        translate = !translate;
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.add_to_contacts:
        try {
            JSONArray jsonArr = new JSONArray();
            JSONObject jsonObj = new JSONObject();
            jsonObj.put(C.c_id_contact, contact.idContacto);
            RequestParams params = new RequestParams();
            params.put("contacts", jsonArr.put(jsonObj));
            addToContacts(params);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        File imagesFolder = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        imagesFolder.mkdirs();
        adjuntLayout.setVisibility(View.GONE);
        dateToCamera = Calendar.getInstance().getTimeInMillis();
        File image = new File(imagesFolder, dateToCamera + ".png");
        Uri uriSavedImage = Uri.fromFile(image);
        Intent pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
        startActivityForResult(pictureActionIntent, 23);
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
        break;
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void checkCountryLocation(final boolean gpsProvider, final boolean netProvider) {
    getActivity().runOnUiThread(new Runnable() {
        @Override//ww  w . j  ava  2s . c  o  m
        public void run() {
            boolean gpsEnabled = false;
            boolean networkEnabled = false;
            if (gpsProvider) {
                gpsEnabled = milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            }
            if (netProvider) {
                networkEnabled = milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            }
            if (gpsProvider && netProvider) {
                if (!gpsEnabled && !networkEnabled) {
                    LayoutInflater dialogInflater = (LayoutInflater) activity
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    dialogView = dialogInflater.inflate(R.layout.null_contact_dialog, null);
                    TextView mensaje = (TextView) dialogView.findViewById(R.id.dialog_add_contact);
                    mensaje.setText(getString(R.string.location_services));
                    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
                            .setView(dialogView).setCancelable(true)
                            .setPositiveButton(R.string.add_contact_yes, null)
                            .setNegativeButton(R.string.add_contact_no, null);
                    finderDialog = dialogBuilder.show();
                    finderDialog.setCanceledOnTouchOutside(true);
                    finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                    System.gc();
                                    dontClose = true;
                                    ((MainActivity) activity).dontClose = true;
                                    hideKeyBoard();
                                    Intent intent = new Intent(
                                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, 45);
                                }
                            });
                    finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                }
                            });
                } else {
                    milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                    milocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                }
            }
        }
    });
}