Search in sources :

Example 81 with Pair

use of mpicbg.trakem2.util.Pair in project Shuttle by timusus.

the class AestheticCoordinatorLayout method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    // Find the toolbar and color view used to blend the scroll transition
    if (getChildCount() > 0 && getChildAt(0) instanceof AppBarLayout) {
        appBarLayout = (AppBarLayout) getChildAt(0);
        if (appBarLayout.getChildCount() > 0 && appBarLayout.getChildAt(0) instanceof CollapsingToolbarLayout) {
            collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(0);
            for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
                if (this.toolbar != null && this.colorView != null) {
                    break;
                }
                View child = collapsingToolbarLayout.getChildAt(i);
                if (child instanceof AestheticToolbar) {
                    this.toolbar = (AestheticToolbar) child;
                } else if (child.getBackground() != null && child.getBackground() instanceof ColorDrawable) {
                    this.colorView = child;
                }
            }
        }
    }
    if (toolbar != null && colorView != null) {
        this.appBarLayout.addOnOffsetChangedListener(this);
        toolbarColorSubscription = Observable.combineLatest(toolbar.colorUpdated(), Aesthetic.get(getContext()).colorIconTitle(toolbar.colorUpdated()), new BiFunction<Integer, ActiveInactiveColors, Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public Pair<Integer, ActiveInactiveColors> apply(Integer integer, ActiveInactiveColors activeInactiveColors) {
                return Pair.create(integer, activeInactiveColors);
            }
        }).compose(Rx.<Pair<Integer, ActiveInactiveColors>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public void accept(@NonNull Pair<Integer, ActiveInactiveColors> result) {
                toolbarColor = result.first;
                iconTextColors = result.second;
                invalidateColors();
            }
        }, onErrorLogAndRethrow());
    }
    if (collapsingToolbarLayout != null) {
        statusBarColorSubscription = Aesthetic.get(getContext()).colorStatusBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

            @Override
            public void accept(@io.reactivex.annotations.NonNull Integer color) {
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);
            }
        }, onErrorLogAndRethrow());
    }
}
Also used : ActionMenuView(android.support.v7.widget.ActionMenuView) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) Consumer(io.reactivex.functions.Consumer) BiFunction(io.reactivex.functions.BiFunction) NonNull(android.support.annotation.NonNull) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Pair(android.support.v4.util.Pair)

Example 82 with Pair

use of mpicbg.trakem2.util.Pair in project AmazeFileManager by TeamAmaze.

the class LoadFilesListTask method doInBackground.

@Override
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
    HybridFile hFile = null;
    if (openmode == OpenMode.UNKNOWN) {
        hFile = new HybridFile(OpenMode.UNKNOWN, path);
        hFile.generateMode(ma.getActivity());
        openmode = hFile.getMode();
        if (hFile.isSmb()) {
            ma.smbPath = path;
        } else if (android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) {
            openmode = OpenMode.ROOT;
        }
    }
    if (isCancelled())
        return null;
    ma.folder_count = 0;
    ma.file_count = 0;
    final ArrayList<LayoutElementParcelable> list;
    switch(openmode) {
        case SMB:
            if (hFile == null) {
                hFile = new HybridFile(OpenMode.SMB, path);
            }
            try {
                SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
                list = ma.addToSmb(smbFile, path);
                openmode = OpenMode.SMB;
            } catch (SmbAuthException e) {
                if (!e.getMessage().toLowerCase().contains("denied")) {
                    ma.reauthenticateSmb();
                }
                return null;
            } catch (SmbException | NullPointerException e) {
                e.printStackTrace();
                return null;
            }
            break;
        case SFTP:
            HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
            list = new ArrayList<LayoutElementParcelable>();
            sftpHFile.forEachChildrenFile(c, false, file -> {
                LayoutElementParcelable elem = createListParcelables(file);
                if (elem != null)
                    list.add(elem);
            });
            break;
        case CUSTOM:
            switch(Integer.parseInt(path)) {
                case 0:
                    list = listImages();
                    break;
                case 1:
                    list = listVideos();
                    break;
                case 2:
                    list = listaudio();
                    break;
                case 3:
                    list = listDocs();
                    break;
                case 4:
                    list = listApks();
                    break;
                case 5:
                    list = listRecent();
                    break;
                case 6:
                    list = listRecentFiles();
                    break;
                default:
                    throw new IllegalStateException();
            }
            break;
        case OTG:
            list = new ArrayList<>();
            listOtg(path, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            openmode = OpenMode.OTG;
            break;
        case DROPBOX:
        case BOX:
        case GDRIVE:
        case ONEDRIVE:
            CloudStorage cloudStorage = dataUtils.getAccount(openmode);
            list = new ArrayList<>();
            try {
                listCloud(path, cloudStorage, openmode, new OnFileFound() {

                    @Override
                    public void onFileFound(HybridFileParcelable file) {
                        LayoutElementParcelable elem = createListParcelables(file);
                        if (elem != null)
                            list.add(elem);
                    }
                });
            } catch (CloudPluginException e) {
                e.printStackTrace();
                AppConfig.toast(c, c.getResources().getString(R.string.failed_no_connection));
                return new Pair<>(openmode, list);
            }
            break;
        default:
            // we're neither in OTG not in SMB, load the list based on root/general filesystem
            list = new ArrayList<>();
            RootHelper.getFiles(path, ma.getMainActivity().isRootExplorer(), showHiddenFiles, new RootHelper.GetModeCallBack() {

                @Override
                public void getMode(OpenMode mode) {
                    openmode = mode;
                }
            }, new OnFileFound() {

                @Override
                public void onFileFound(HybridFileParcelable file) {
                    LayoutElementParcelable elem = createListParcelables(file);
                    if (elem != null)
                        list.add(elem);
                }
            });
            break;
    }
    if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
        Collections.sort(list, new FileListSorter(ma.dsort, ma.sortby, ma.asc));
    }
    return new Pair<>(openmode, list);
}
Also used : LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) OpenMode(com.amaze.filemanager.utils.OpenMode) SmbFile(jcifs.smb.SmbFile) SmbException(jcifs.smb.SmbException) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) HybridFile(com.amaze.filemanager.filesystem.HybridFile) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SmbAuthException(jcifs.smb.SmbAuthException) RootHelper(com.amaze.filemanager.filesystem.RootHelper) FileListSorter(com.amaze.filemanager.utils.files.FileListSorter) OnFileFound(com.amaze.filemanager.utils.OnFileFound) Pair(android.support.v4.util.Pair)

Example 83 with Pair

use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.

the class MapillaryImageDialog method fetchTiles.

public void fetchTiles() {
    RotatedTileBox tileBox = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
    if (fetchedTileLat == tileBox.getLatitude() && fetchedTileLon == tileBox.getLongitude()) {
        return;
    }
    ITileSource map = TileSourceManager.getMapillaryVectorSource();
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = getMapActivity().getMyApplication().getResourceManager();
    final QuadRect tilesRect = tileBox.getTileBounds();
    // recalculate for ellipsoid coordinates
    float ellipticTileCorrection = 0;
    if (map.isEllipticYTile()) {
        ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
    }
    int left = (int) Math.floor(tilesRect.left);
    int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
    int width = (int) Math.ceil(tilesRect.right - left);
    int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            Pair<QuadPointDouble, GeometryTile> p = tiles.get(tileId);
            if (p == null) {
                GeometryTile tile = null;
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist) {
                    if (sync) {
                        tile = mgr.getGeometryTilesCache().getTileForMapSync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                        sync = false;
                    } else {
                        tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                    }
                }
                if (tile != null) {
                    tiles.put(tileId, new Pair<>(new QuadPointDouble(tileX, tileY), tile));
                }
            }
        }
    }
    fetchedTileLat = tileBox.getLatitude();
    fetchedTileLon = tileBox.getLongitude();
    this.tiles = new ArrayList<>(tiles.values());
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) SuppressLint(android.annotation.SuppressLint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) Pair(android.support.v4.util.Pair) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 84 with Pair

use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.

the class MapOverlayAction method getOnAddBtnClickListener.

@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
    return new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final OsmandSettings settings = activity.getMyApplication().getSettings();
            Map<String, String> entriesMap = settings.getTileSourceEntries();
            entriesMap.put(KEY_NO_OVERLAY, activity.getString(R.string.no_overlay));
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
            final String[] items = new String[entriesMap.size()];
            int i = 0;
            for (String it : entriesMap.values()) {
                items[i++] = it;
            }
            final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
            arrayAdapter.addAll(items);
            builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int i) {
                    Pair<String, String> layer = new Pair<>(keys.get(i), items[i]);
                    adapter.addItem(layer, activity);
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.shared_string_cancel, null);
            builder.show();
        }
    };
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) ArrayAdapter(android.widget.ArrayAdapter) Pair(android.support.v4.util.Pair)

Example 85 with Pair

use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.

the class MapOverlayAction method execute.

@Override
public void execute(MapActivity activity) {
    OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
    if (plugin != null) {
        OsmandSettings settings = activity.getMyApplication().getSettings();
        List<Pair<String, String>> sources = loadListFromParams();
        Pair<String, String> currentSource = new Pair<>(settings.MAP_OVERLAY.get(), settings.MAP_OVERLAY.get());
        Pair<String, String> nextSource = sources.get(0);
        int index = sources.indexOf(currentSource);
        if (index >= 0 && index + 1 < sources.size()) {
            nextSource = sources.get(index + 1);
        }
        boolean hasOverlay = !nextSource.first.equals(KEY_NO_OVERLAY);
        if (hasOverlay) {
            settings.MAP_OVERLAY.set(nextSource.first);
            settings.MAP_OVERLAY_PREVIOUS.set(nextSource.first);
        } else {
            settings.MAP_OVERLAY.set(null);
            settings.MAP_OVERLAY_PREVIOUS.set(null);
        }
        plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
        Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
    }
}
Also used : OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.OsmandSettings) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)79 ArrayList (java.util.ArrayList)39 View (android.view.View)28 Pair (org.apache.commons.math3.util.Pair)20 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)16 TextView (android.widget.TextView)15 Intent (android.content.Intent)14 List (java.util.List)13 ImageView (android.widget.ImageView)10 ByteProcessor (ij.process.ByteProcessor)9 RecyclerView (android.support.v7.widget.RecyclerView)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AlertDialog (android.support.v7.app.AlertDialog)7 Pair (mpicbg.trakem2.util.Pair)7 NonNull (android.support.annotation.NonNull)6 Patch (ini.trakem2.display.Patch)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 DialogInterface (android.content.DialogInterface)5 IOException (java.io.IOException)5