Search in sources :

Example 31 with UiThread

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();
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) AddCycleway(de.westnordost.streetcomplete.quests.bikeway.AddCycleway) Quest(de.westnordost.streetcomplete.data.Quest) UiThread(android.support.annotation.UiThread)

Example 32 with UiThread

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);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Location(android.location.Location) UiThread(android.support.annotation.UiThread)

Example 33 with UiThread

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();
}
Also used : DownloadEvents(net.osmand.plus.download.DownloadIndexesThread.DownloadEvents) DialogFragment(android.support.v4.app.DialogFragment) FreeVersionDialogFragment(net.osmand.plus.download.ui.FreeVersionDialogFragment) ActiveDownloadsDialogFragment(net.osmand.plus.download.ui.ActiveDownloadsDialogFragment) Fragment(android.support.v4.app.Fragment) BottomSheetDialogFragment(net.osmand.plus.base.BottomSheetDialogFragment) UpdatesIndexFragment(net.osmand.plus.download.ui.UpdatesIndexFragment) DownloadResourceGroupFragment(net.osmand.plus.download.ui.DownloadResourceGroupFragment) LocalIndexesFragment(net.osmand.plus.download.ui.LocalIndexesFragment) UiThread(android.support.annotation.UiThread)

Example 34 with UiThread

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();
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) DownloadEvents(net.osmand.plus.download.DownloadIndexesThread.DownloadEvents) File(java.io.File) DialogFragment(android.support.v4.app.DialogFragment) FreeVersionDialogFragment(net.osmand.plus.download.ui.FreeVersionDialogFragment) ActiveDownloadsDialogFragment(net.osmand.plus.download.ui.ActiveDownloadsDialogFragment) Fragment(android.support.v4.app.Fragment) BottomSheetDialogFragment(net.osmand.plus.base.BottomSheetDialogFragment) UpdatesIndexFragment(net.osmand.plus.download.ui.UpdatesIndexFragment) DownloadResourceGroupFragment(net.osmand.plus.download.ui.DownloadResourceGroupFragment) LocalIndexesFragment(net.osmand.plus.download.ui.LocalIndexesFragment) UiThread(android.support.annotation.UiThread)

Example 35 with UiThread

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;
}
Also used : Bitmap(android.graphics.Bitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) UiThread(android.support.annotation.UiThread)

Aggregations

UiThread (android.support.annotation.UiThread)48 View (android.view.View)9 ObjectAnimator (android.animation.ObjectAnimator)6 Animator (android.animation.Animator)5 Drawable (android.graphics.drawable.Drawable)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 Fragment (android.support.v4.app.Fragment)4 MenuItem (android.view.MenuItem)4 ViewPropertyAnimator (android.view.ViewPropertyAnimator)4 Paint (android.graphics.Paint)3 Rect (android.graphics.Rect)3 DialogFragment (android.support.v4.app.DialogFragment)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 Location (android.location.Location)2 Bundle (android.os.Bundle)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2