List of usage examples for android.location LocationManager isProviderEnabled
public boolean isProviderEnabled(String provider)
From source file:com.ternup.caddisfly.fragment.LocationFragment.java
/** * Invoked by the "Start Updates" button * Sends a request to start location updates * * @param v The view object associated with this method, in this case a Button. */// w ww . j a v a2 s .c om public void startUpdates(View v) { // Get Location Manager and check for GPS & Network location services LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // Build the alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges the alert dialog Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { mUpdatesRequested = true; if (servicesConnected()) { // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); mLocationButton.setVisibility(View.GONE); startPeriodicUpdates(); } } }
From source file:org.odk.collect.android.map.OsmMapFragment.java
@Override public void setGpsLocationEnabled(boolean enable) { if (enable != gpsLocationEnabled) { gpsLocationEnabled = enable;// ww w . j a v a 2 s .c o m if (locationClient == null) { locationClient = LocationClients.clientForContext(getActivity()); locationClient.setListener(this); } if (gpsLocationEnabled) { LocationManager locationManager = (LocationManager) getContext() .getSystemService(Context.LOCATION_SERVICE); if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { map.getOverlays().add(myLocationOverlay); myLocationOverlay.setEnabled(true); myLocationOverlay.enableMyLocation(); locationClient.start(); } else { showGpsDisabledAlert(); } } else { locationClient.stop(); myLocationOverlay.setEnabled(false); myLocationOverlay.disableFollowLocation(); myLocationOverlay.disableMyLocation(); } } }
From source file:com.patil.geobells.lite.MainActivity.java
public void checkLocationServicesEnabled() { LocationManager lm = null; boolean gps_enabled = true, network_enabled = true; if (lm == null) lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); try {/*from ww w.j a v a2 s . c om*/ gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } if (!gps_enabled || !network_enabled) { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.dialog_title_enable_locationservices); dialog.setMessage(getString(R.string.dialog_message_enable_locationservices)); dialog.setCancelable(false); dialog.setPositiveButton(getString(R.string.dialog_button_open_location_settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { paramDialogInterface.dismiss(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(myIntent); } }); dialog.setNegativeButton(getString(R.string.dialog_button_nothanks), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface paramDialogInterface, int paramInt) { finish(); } }); dialog.create().show(); } }
From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java
private void checkLocationIsEnabled() { // On android Marshmallow we also need to have active Location Services (GPS or Network based) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); boolean isNetworkLocationProviderEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSLocationProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!isGPSLocationProviderEnabled && !isNetworkLocationProviderEnabled) { // Only if both providers are disabled we need to ask the user to do something Toast.makeText(this, "Location is off, enable it in system settings.", Toast.LENGTH_LONG).show(); Intent locationInSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivityForResult(locationInSettingsIntent, REQUEST_CODE_LOCATION); } else {/*from w ww . j a v a 2 s . c om*/ continueLoading(); } } else { continueLoading(); } }
From source file:com.prey.activities.CheckPasswordActivity.java
@Override protected void onResume() { super.onResume(); bindPasswordControls();/* w w w . j a v a2s. c om*/ TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text); final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password); Button password_btn_login = (Button) findViewById(R.id.password_btn_login); EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt); TextView textView1 = (TextView) findViewById(R.id.textView1); TextView textView2 = (TextView) findViewById(R.id.textView2); Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Regular.ttf"); Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Bold.ttf"); Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(), "fonts/MagdaClean/magdacleanmono-regular.ttf"); textView1.setTypeface(magdacleanmonoRegular); textView2.setTypeface(magdacleanmonoRegular); device_ready_h2_text.setTypeface(titilliumWebRegular); textForgotPassword.setTypeface(titilliumWebBold); password_btn_login.setTypeface(titilliumWebBold); password_pass_txt.setTypeface(magdacleanmonoRegular); try { textForgotPassword.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); } catch (Exception e) { } } }); } catch (Exception e) { } TextView textView5_1 = (TextView) findViewById(R.id.textView5_1); TextView textView5_2 = (TextView) findViewById(R.id.textView5_2); textView5_1.setTypeface(magdacleanmonoRegular); textView5_2.setTypeface(titilliumWebBold); TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall); LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour); textViewUninstall.setTypeface(titilliumWebBold); if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) { linearLayoutTour.setVisibility(View.GONE); textViewUninstall.setVisibility(View.VISIBLE); textViewUninstall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); finish(); } }); } else { linearLayoutTour.setVisibility(View.VISIBLE); textViewUninstall.setVisibility(View.GONE); try { linearLayoutTour.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplication(), TourActivity1.class); Bundle b = new Bundle(); b.putInt("id", 1); intent.putExtras(b); startActivity(intent); finish(); } }); } catch (Exception e) { } } boolean showLocation = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this); boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this); boolean canAccessCamera = PreyPermission.canAccessCamera(this); boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this); boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this); if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState || !canAccessReadExternalStorage) { AlertDialog.Builder builder = new AlertDialog.Builder(this); final FrameLayout frameView = new FrameLayout(this); builder.setView(frameView); final AlertDialog alertDialog = builder.create(); LayoutInflater inflater = alertDialog.getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.warning, frameView); TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title); TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body); warning_title.setTypeface(magdacleanmonoRegular); warning_body.setTypeface(titilliumWebBold); Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok); Button button_close = (Button) dialoglayout.findViewById(R.id.button_close); button_ok.setTypeface(titilliumWebBold); button_close.setTypeface(titilliumWebBold); final Activity thisActivity = this; button_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("askForPermission"); askForPermission(); alertDialog.dismiss(); } }); button_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("close ask"); alertDialog.dismiss(); } }); alertDialog.show(); showLocation = false; } else { showLocation = true; } } else { showLocation = true; } if (showLocation) { LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (isGpsEnabled || isNetworkEnabled) { PreyLogger.d("isGpsEnabled || isNetworkEnabled"); } else { PreyLogger.d("no gps ni red"); AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog alertDialog = builder.create(); TextView textview = new TextView(this); textview.setText(getString(R.string.location_settings)); textview.setMaxLines(10); textview.setTextSize(18F); textview.setPadding(20, 0, 20, 20); textview.setTextColor(Color.BLACK); builder.setView(textview); builder.setPositiveButton(getString(R.string.go_to_settings), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); return; } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }); builder.create().show(); } } }
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 ava2 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.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 w w w .j a v a2s. co m*/ }
From source file:com.example.devesh.Coride.DriverRegistration.java
@TargetApi(Build.VERSION_CODES.M) public void sendData(View view) throws MalformedURLException { Log.e("TEST LOG", "Entered the loop"); Toast.makeText(this, "coride", Toast.LENGTH_SHORT).show(); Master master = new Master(); String url_string = master.url + "driverdata"; EditText n_edittext;/* w w w . ja v a2 s . c o m*/ EditText mob_edittext; EditText confrm_edittext; EditText age_edittext; EditText lnumber; EditText pnumber; EditText vnumber; EditText mnumber; EditText capacity; String name; String mobile; String conpassword; String password; String address; String email; String slnumber; String spnumber; String svnumber; String smnumber; String scapacity; int count = 0; n_edittext = (EditText) findViewById(R.id.name); mob_edittext = (EditText) findViewById(R.id.mobileno); confrm_edittext = (EditText) findViewById(R.id.confirmpassword); mPasswordView = (EditText) findViewById(R.id.password); mEmailView = (AutoCompleteTextView) findViewById(R.id.email); age_edittext = (EditText) findViewById(R.id.address); lnumber = (EditText) findViewById(R.id.lnumber); pnumber = (EditText) findViewById(R.id.pnumber); vnumber = (EditText) findViewById(R.id.vnumber); mnumber = (EditText) findViewById(R.id.mnumber); capacity = (EditText) findViewById(R.id.capacity); name = n_edittext.getText().toString(); mobile = mob_edittext.getText().toString(); master.mobile1 = mobile; password = mPasswordView.getText().toString(); conpassword = confrm_edittext.getText().toString(); address = age_edittext.getText().toString(); email = mEmailView.getText().toString(); slnumber = lnumber.getText().toString(); spnumber = pnumber.getText().toString(); svnumber = vnumber.getText().toString(); smnumber = mnumber.getText().toString(); ; scapacity = capacity.getText().toString(); regId = registerGCM(); System.out.println(regId); // String reg=regId.toString(); count = validate(name, email, mobile, password, conpassword, address); if (count == 0) { count = email_validation(mEmailView, getBaseContext()); } if (count == 0) { count = password_matcher(password, conpassword); } if (count == 0) { String json = "[{name:\"" + name + "\"},{mobile:\"" + mobile + "\"},{password:\"" + password + "\"},{email:\"" + email + "\"},{address:\"" + address + "\"},{license:\"" + slnumber + "\"},{pan:\"" + spnumber + "\"},{vehicle:\"" + svnumber + "\"},{model:\"" + smnumber + "\"},{capacity:\"" + scapacity + "\"},{regid:\"" + regId + "\"}]"; // snd.addNameValuePair("name", name); //snd.addNameValuePair("mobile", mobile); //snd.addNameValuePair("password", password); // snd.addNameValuePair("email",email); //snd.addNameValuePair("age", age); SendDataTask snd = new SendDataTask(json); //Go to sendData class fromhere URL url = new URL(url_string); snd.execute(url); } System.out.println("i am hear"); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(locationManager.NETWORK_PROVIDER) || locationManager.isProviderEnabled(locationManager.GPS_PROVIDER)) { Log.e("Coride", "Provider enable"); callLocationService(); } else { Log.e("Coride", "provider disabled"); showSettingsAlert("NETWORK_PROVIDER"); } LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { callLocationService(); } @Override public void onProviderDisabled(String s) { showSettingsAlert("NETWORK_PROVIDER"); } }; // dialog.cancel(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 123); return; } locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, locationListener); }
From source file:io.development.tymo.adapters.FeedZoomMoreAdapter.java
@Override public void onBindViewHolder(SimpleViewHolder holder, int position) { ActivityServer feedCubeModel;/*w w w . j a va2 s . c om*/ FlagServer feedFlagModel; holder.adapter = new PersonSmallAdapter(listPeople.get(position), mContext); holder.recyclerView.setAdapter(holder.adapter); if (mItems.get(position) instanceof ActivityServer) { holder.textDescription.setVisibility(View.VISIBLE); holder.cubeLowerBox.setVisibility(View.VISIBLE); holder.locationBox.setVisibility(View.VISIBLE); holder.pieceIcon.setVisibility(View.VISIBLE); holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE); holder.cubeLowerBoxIcon.setVisibility(View.VISIBLE); feedCubeModel = (ActivityServer) mItems.get(position); holder.textTitle.setText(feedCubeModel.getTitle()); holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.grey_900)); holder.textDescription.setText(feedCubeModel.getTitle()); if (feedCubeModel.getDescription() != null && !feedCubeModel.getDescription().matches("")) holder.textDescription.setText(feedCubeModel.getDescription()); else holder.textDescription.setVisibility(View.GONE); holder.cubeLowerBox.setVisibility(View.VISIBLE); holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE); holder.flagButton.setVisibility(View.GONE); holder.cubeUpperBoxIcon.setColorFilter(feedCubeModel.getCubeColorUpper()); holder.cubeLowerBoxIcon.setColorFilter(feedCubeModel.getCubeColor()); Glide.clear(holder.pieceIcon); Glide.with(mContext).load(feedCubeModel.getCubeIcon()).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.pieceIcon); Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar.set(feedCubeModel.getYearStart(), feedCubeModel.getMonthStart() - 1, feedCubeModel.getDayStart()); calendar2.set(feedCubeModel.getYearEnd(), feedCubeModel.getMonthEnd() - 1, feedCubeModel.getDayEnd()); String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK), calendar); String dayStart = String.format("%02d", feedCubeModel.getDayStart()); String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar.getTime().getTime()); int yearStart = feedCubeModel.getYearStart(); String hourStart = String.format("%02d", feedCubeModel.getHourStart()); String minuteStart = String.format("%02d", feedCubeModel.getMinuteStart()); String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK), calendar2); String dayEnd = String.format("%02d", feedCubeModel.getDayEnd()); String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar2.getTime().getTime()); int yearEnd = feedCubeModel.getYearEnd(); String hourEnd = String.format("%02d", feedCubeModel.getHourEnd()); String minuteEnd = String.format("%02d", feedCubeModel.getMinuteEnd()); if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) { if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) { holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart)); } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd)); } } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd, yearEnd, hourEnd, minuteEnd)); } if (!feedCubeModel.getLocation().matches("")) { SharedPreferences mSharedPreferences = mContext.getSharedPreferences(Constants.USER_CREDENTIALS, MODE_PRIVATE); boolean location = mSharedPreferences.getBoolean(Constants.LOCATION, true); if (location) { LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && lat != -500 && (feedCubeModel.getLat() != 0 && feedCubeModel.getLng() != 0)) { double distance = Utilities.distance(lat, lng, feedCubeModel.getLat(), feedCubeModel.getLng()); if (distance < 1) { distanceText = mContext.getResources().getString(R.string.distance_meters, (int) (distance * 1000)) + " "; } else { distanceText = mContext.getResources().getString(R.string.distance_km, (int) distance) + " "; } } else distanceText = ""; } else distanceText = ""; if (!distanceText.matches("")) { final SpannableStringBuilder sb = new SpannableStringBuilder( distanceText + feedCubeModel.getLocation()); final StyleSpan styleBold = new StyleSpan(Typeface.BOLD); sb.setSpan(styleBold, 0, distanceText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); holder.location.setText(sb); } else { holder.location.setText(feedCubeModel.getLocation()); } } else { holder.locationBox.setVisibility(View.GONE); distanceText = ""; } if (!feedCubeModel.getUser().getPhoto().matches("")) { Glide.clear(holder.photoCreator); Glide.with(mContext).load(feedCubeModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new BitmapImageViewTarget(holder.photoCreator) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.photoCreator.setImageDrawable(circularBitmapDrawable); } }); } else holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty); if (feedCubeModel.getFavoriteCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more); } else if (feedCubeModel.getKnowCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more); } else if (feedCubeModel.getUser().getEmail().equals(email)) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more); } else { holder.photoCreatorRingBox.setVisibility(View.INVISIBLE); } } else { feedFlagModel = (FlagServer) mItems.get(position); holder.textTitle.setText(mContext.getResources().getString(R.string.flag_available)); holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.flag_available)); if (feedFlagModel.getTitle().matches("")) { holder.textDescription.setVisibility(View.GONE); } else { holder.textDescription.setText(feedFlagModel.getTitle()); } holder.cubeLowerBox.setVisibility(View.GONE); holder.cubeUpperBoxIcon.setVisibility(View.GONE); holder.flagButton.setVisibility(View.VISIBLE); holder.locationBox.setVisibility(View.GONE); Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar.set(feedFlagModel.getYearStart(), feedFlagModel.getMonthStart() - 1, feedFlagModel.getDayStart()); calendar2.set(feedFlagModel.getYearEnd(), feedFlagModel.getMonthEnd() - 1, feedFlagModel.getDayEnd()); String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK), calendar); String dayStart = String.format("%02d", feedFlagModel.getDayStart()); String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar.getTime().getTime()); int yearStart = feedFlagModel.getYearStart(); String hourStart = String.format("%02d", feedFlagModel.getHourStart()); String minuteStart = String.format("%02d", feedFlagModel.getMinuteStart()); String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK), calendar2); String dayEnd = String.format("%02d", feedFlagModel.getDayEnd()); String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar2.getTime().getTime()); int yearEnd = feedFlagModel.getYearEnd(); String hourEnd = String.format("%02d", feedFlagModel.getHourEnd()); String minuteEnd = String.format("%02d", feedFlagModel.getMinuteEnd()); if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) { if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) { holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart)); } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd)); } } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd, yearEnd, hourEnd, minuteEnd)); } if (!feedFlagModel.getUser().getPhoto().matches("")) { Glide.clear(holder.photoCreator); Glide.with(mContext).load(feedFlagModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new BitmapImageViewTarget(holder.photoCreator) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.photoCreator.setImageDrawable(circularBitmapDrawable); } }); } else holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty); if (feedFlagModel.getFavoriteCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more); } else if (feedFlagModel.getKnowCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more); } else if (feedFlagModel.getUser().getEmail().equals(email)) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more); } else { holder.photoCreatorRingBox.setVisibility(View.INVISIBLE); } } if (holder.flagButton.getVisibility() == View.VISIBLE) { holder.pieceBox.startAnimation(animation2); } else { holder.pieceBox.startAnimation(animation2); } holder.textBox.startAnimation(animation); holder.triangle.startAnimation(animation); }
From source file:org.openbmap.activities.HostActivity.java
/** * Checks whether GPS is enabled.// ww w. j a va 2 s .co m * If not, user is asked whether to activate GPS. */ private void verifyGPSProvider() { final LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { // GPS isn't enabled. Offer user to go enable it new AlertDialog.Builder(this).setTitle(R.string.no_gps).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(R.string.turnOnGpsQuestion).setCancelable(true) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.cancel(); } }).create().show(); } }