diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java | 122 |
1 files changed, 66 insertions, 56 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java index 2661589d8..7c9318fa5 100644 --- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java @@ -11,7 +11,6 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; @@ -30,20 +29,43 @@ import de.pixart.messenger.services.EmojiService; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; -public class ShowLocationActivity extends AppCompatActivity { +public class ShowLocationActivity extends XmppActivity { private Location location; private String mLocationName; + private static String getAddress(Context context, Location location) { + double longitude = location.getLongitude(); + double latitude = location.getLatitude(); + String address = ""; + if (latitude != 0 && longitude != 0) { + Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); + try { + List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1); + if (addresses != null && addresses.size() > 0) { + Address Address = addresses.get(0); + StringBuilder strAddress = new StringBuilder(""); + + if (Address.getAddressLine(0).length() > 0) { + strAddress.append(Address.getAddressLine(0)); + } + address = strAddress.toString().replace(", ", "<br>"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return address; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean useBundledEmoji = getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); new EmojiService(this).init(useBundledEmoji); - if (getSupportActionBar() != null) { - getSupportActionBar().setHomeButtonEnabled(true); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - } setContentView(R.layout.activity_show_locaction); + setTitle(getString(R.string.show_location)); + setSupportActionBar(findViewById(R.id.toolbar)); + configureActionBar(getSupportActionBar()); Intent intent = getIntent(); @@ -66,61 +88,21 @@ public class ShowLocationActivity extends AppCompatActivity { new getAddressAsync(this).execute(); } } - private class getAddressAsync extends AsyncTask<Void, Void, Void> { - String address = null; - private WeakReference<ShowLocationActivity> activityReference; - - getAddressAsync(ShowLocationActivity context) { - activityReference = new WeakReference<>(context); - } - - @Override - protected void onPreExecute() { - super.onPreExecute(); - showLocation(location, null); - } - - @Override - protected Void doInBackground(Void... params) { - address = getAddress(ShowLocationActivity.this, location); - return null; - } + ; - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - showLocation(location, address); - } - }; + protected SharedPreferences getPreferences() { + return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + } - private static String getAddress(Context context, Location location) { - double longitude = location.getLongitude(); - double latitude = location.getLatitude(); - String address = ""; - if (latitude != 0 && longitude != 0) { - Geocoder geoCoder = new Geocoder(context, Locale.getDefault()); - try { - List<Address> addresses = geoCoder.getFromLocation(latitude, longitude, 1); - if (addresses != null && addresses.size() > 0) { - Address Address = addresses.get(0); - StringBuilder strAddress = new StringBuilder(""); + @Override + protected void refreshUiReal() { - if (Address.getAddressLine(0).length() > 0) { - strAddress.append(Address.getAddressLine(0)); - } - address = strAddress.toString().replace(", ", "<br>"); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - return address; } + @Override + void onBackendConnected() { - protected SharedPreferences getPreferences() { - return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } @Override @@ -155,7 +137,7 @@ public class ShowLocationActivity extends AppCompatActivity { super.onSaveInstanceState(outState); } - private void showLocation (@Nullable Location location, @Nullable String address) { + private void showLocation(@Nullable Location location, @Nullable String address) { if (location == null && TextUtils.isEmpty(address)) { // no location and no address available final WebView webView = findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); @@ -164,7 +146,7 @@ public class ShowLocationActivity extends AppCompatActivity { String LocationName = "<b>" + mLocationName + "</b>"; final WebView webView = findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); - webView.loadUrl("file:///android_asset/map.html?lat=" + location.getLatitude() + "&lon=" + location.getLongitude()+ "&name=" + LocationName); + webView.loadUrl("file:///android_asset/map.html?lat=" + location.getLatitude() + "&lon=" + location.getLongitude() + "&name=" + LocationName); } else if (location != null && !TextUtils.isEmpty(address)) { // location and address available String LocationName = "<b>" + mLocationName + "</b><br>" + address; final WebView webView = findViewById(R.id.webView); @@ -172,4 +154,32 @@ public class ShowLocationActivity extends AppCompatActivity { webView.loadUrl("file:///android_asset/map.html?lat=" + location.getLatitude() + "&lon=" + location.getLongitude() + "&name=" + LocationName); } } + + private class getAddressAsync extends AsyncTask<Void, Void, Void> { + String address = null; + + private WeakReference<ShowLocationActivity> activityReference; + + getAddressAsync(ShowLocationActivity context) { + activityReference = new WeakReference<>(context); + } + + @Override + protected void onPreExecute() { + super.onPreExecute(); + showLocation(location, null); + } + + @Override + protected Void doInBackground(Void... params) { + address = getAddress(ShowLocationActivity.this, location); + return null; + } + + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + showLocation(location, address); + } + } }
\ No newline at end of file |