use of android.support.annotation.UiThread in project StreetComplete by westnordost.
the class QuestsMapFragment method addQuests.
/*
public void addQuest(Quest quest, QuestGroup group)
{
// TODO: this method may also be called for quests that are already displayed on this map
if(questsLayer == null) return;
LngLat pos = TangramConst.toLngLat(quest.getMarkerLocation());
Map<String, String> props = new HashMap<>();
props.put("type", "point");
props.put("kind", quest.getType().getIconName());
props.put(MARKER_QUEST_GROUP, group.name());
props.put(MARKER_QUEST_ID, String.valueOf(quest.getId()));
questsLayer.addPoint(pos, props);
controller.applySceneUpdates();
}
*/
@UiThread
public void addQuests(Iterable quests, QuestGroup group) {
if (questsLayer == null)
return;
StringBuilder geoJson = new StringBuilder();
geoJson.append("{\"type\":\"FeatureCollection\",\"features\": [");
boolean first = true;
for (Object q : quests) {
Quest quest = (Quest) q;
// hack away cycleway quests for old Android SDK versions (#713)
if (quest.getType() instanceof AddCycleway && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
continue;
}
if (first)
first = false;
else
geoJson.append(",");
LatLon pos = quest.getMarkerLocation();
String questIconName = getActivity().getResources().getResourceEntryName(quest.getType().getIcon());
Integer order = questTypeOrder.get(quest.getType());
if (order == null)
order = 0;
geoJson.append("{\"type\":\"Feature\",");
geoJson.append("\"geometry\":{\"type\":\"Point\",\"coordinates\": [");
geoJson.append(pos.getLongitude());
geoJson.append(",");
geoJson.append(pos.getLatitude());
geoJson.append("]},\"properties\": {\"type\":\"point\", \"kind\":\"");
geoJson.append(questIconName);
geoJson.append("\",\"");
geoJson.append(MARKER_QUEST_GROUP);
geoJson.append("\":\"");
geoJson.append(group.name());
geoJson.append("\",\"");
geoJson.append(MARKER_QUEST_ID);
geoJson.append("\":\"");
geoJson.append(quest.getId());
geoJson.append("\",\"");
geoJson.append("order");
geoJson.append("\":\"");
geoJson.append(order);
geoJson.append("\"}}");
}
geoJson.append("]}");
questsLayer.addGeoJson(geoJson.toString());
controller.requestRender();
}
use of android.support.annotation.UiThread in project PocketMaps by junjunguo.
the class NaviEngine method updatePosition.
@UiThread
public void updatePosition(Activity activity, Location pos) {
if (active == false) {
return;
}
if (uiJob == UiJob.RecalcPath) {
return;
}
if (this.pos == null) {
this.pos = new Location((String) null);
}
this.pos.set(pos);
GeoPoint curPos = new GeoPoint(pos.getLatitude(), pos.getLongitude());
GeoPoint newCenter = curPos.destinationPoint(70.0 * tiltMultPos, pos.getBearing());
MapHandler.getMapHandler().centerPointOnMap(newCenter, BEST_NAVI_ZOOM, 360.0f - pos.getBearing(), 45.0f * tiltMult);
calculatePositionAsync(curPos);
}
use of android.support.annotation.UiThread in project Osmand by osmandapp.
the class DownloadActivity method downloadInProgress.
@Override
@UiThread
public void downloadInProgress() {
if (accessibilityAssistant.isUiUpdateDiscouraged())
return;
accessibilityAssistant.lockEvents();
visibleBanner.updateBannerInProgress();
showDownloadWorldMapIfNeeded();
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof DownloadEvents && f.isAdded()) {
((DownloadEvents) f).downloadInProgress();
}
}
accessibilityAssistant.unlockEvents();
}
use of android.support.annotation.UiThread in project Osmand by osmandapp.
the class DownloadActivity method downloadHasFinished.
@Override
@UiThread
public void downloadHasFinished() {
visibleBanner.updateBannerInProgress();
if (downloadItem != null && downloadItem != getMyApplication().getRegions().getWorldRegion() && !WorldRegion.WORLD_BASEMAP.equals(downloadItem.getRegionDownloadNameLC())) {
if (!Algorithms.isEmpty(downloadTargetFileName)) {
File f = new File(downloadTargetFileName);
if (f.exists() && f.lastModified() > System.currentTimeMillis() - 10000) {
getMyApplication().getDownloadThread().initSettingsFirstMap(downloadItem);
showGoToMap(downloadItem);
}
}
downloadItem = null;
downloadTargetFileName = null;
}
if (!Algorithms.isEmpty(downloadTargetFileName)) {
File f = new File(downloadTargetFileName);
if (f.exists()) {
String fileName = f.getName();
if (fileName.endsWith(IndexConstants.FONT_INDEX_EXT)) {
AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage(R.string.restart_is_required);
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
android.os.Process.killProcess(android.os.Process.myPid());
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
} else if (fileName.startsWith(FileNameTranslationHelper.SEA_DEPTH)) {
getMyApplication().getSettings().getCustomRenderBooleanProperty("depthContours").set(true);
}
}
downloadItem = null;
downloadTargetFileName = null;
}
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof DownloadEvents && f.isAdded()) {
((DownloadEvents) f).downloadHasFinished();
}
}
}
use of android.support.annotation.UiThread in project android_packages_apps_Dialer by LineageOS.
the class ContactPhotoManagerImpl method loadCachedPhoto.
/**
* Checks if the photo is present in cache. If so, sets the photo on the view.
*
* @return false if the photo needs to be (re)loaded from the provider.
*/
@UiThread
private boolean loadCachedPhoto(ImageView view, Request request, boolean fadeIn) {
BitmapHolder holder = mBitmapHolderCache.get(request.getKey());
if (holder == null) {
// The bitmap has not been loaded ==> show default avatar
request.applyDefaultImage(view, request.mIsCircular);
return false;
}
if (holder.bytes == null) {
request.applyDefaultImage(view, request.mIsCircular);
return holder.fresh;
}
Bitmap cachedBitmap = holder.bitmapRef == null ? null : holder.bitmapRef.get();
if (cachedBitmap == null) {
request.applyDefaultImage(view, request.mIsCircular);
return false;
}
final Drawable previousDrawable = view.getDrawable();
if (fadeIn && previousDrawable != null) {
final Drawable[] layers = new Drawable[2];
// Prevent cascade of TransitionDrawables.
if (previousDrawable instanceof TransitionDrawable) {
final TransitionDrawable previousTransitionDrawable = (TransitionDrawable) previousDrawable;
layers[0] = previousTransitionDrawable.getDrawable(previousTransitionDrawable.getNumberOfLayers() - 1);
} else {
layers[0] = previousDrawable;
}
layers[1] = getDrawableForBitmap(mContext.getResources(), cachedBitmap, request);
TransitionDrawable drawable = new TransitionDrawable(layers);
view.setImageDrawable(drawable);
drawable.startTransition(FADE_TRANSITION_DURATION);
} else {
view.setImageDrawable(getDrawableForBitmap(mContext.getResources(), cachedBitmap, request));
}
// (we require that at least six of those can be cached at the same time)
if (cachedBitmap.getByteCount() < mBitmapCache.maxSize() / 6) {
mBitmapCache.put(request.getKey(), cachedBitmap);
}
// Soften the reference
holder.bitmap = null;
return holder.fresh;
}
Aggregations