Example usage for com.badlogic.gdx.files FileHandle type

List of usage examples for com.badlogic.gdx.files FileHandle type

Introduction

In this page you can find the example usage for com.badlogic.gdx.files FileHandle type.

Prototype

FileType type

To view the source code for com.badlogic.gdx.files FileHandle type.

Click Source Link

Usage

From source file:CB_Translation_Base.TranslationEngine.Translation.java

License:Open Source License

private ArrayList<Lang> getLangs(String FilePath) {
    ArrayList<Lang> Temp = new ArrayList<Lang>();

    FileHandle Dir = Gdx.files.getFileHandle(FilePath, mFiletype);
    final FileHandle[] files;

    if (Dir.type() == FileType.Classpath) {
        // Cannot list a classpath directory
        // so we hardcoded the lang path
        files = new FileHandle[] { //
                Gdx.files.classpath("data/lang/cs"), //
                Gdx.files.classpath("data/lang/de"), //
                Gdx.files.classpath("data/lang/en-GB"), //
                Gdx.files.classpath("data/lang/fr"), //
                Gdx.files.classpath("data/lang/hu"), //
                Gdx.files.classpath("data/lang/nl"), //
                Gdx.files.classpath("data/lang/pl"), //
                Gdx.files.classpath("data/lang/pt-PT"),//
        };//from   w ww.j  a v  a2  s  . c o m
    } else {
        files = Dir.list();
    }

    for (FileHandle tmp : files) {
        try {

            String stringFile = tmp + "/strings.ini";

            FileHandle langFile = Gdx.files.getFileHandle(stringFile, mFiletype);

            if (langFile.exists()) {
                String tmpName = getLangNameFromFile(stringFile);
                Temp.add(new Lang(tmpName, stringFile));
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    return Temp;
}

From source file:com.forerunnergames.peril.client.assets.MultiSourceAssetManager.java

License:Open Source License

@Override
@SuppressWarnings("rawtypes")
public synchronized <T> void load(final String fileName, final Class<T> type,
        @Nullable final AssetLoaderParameters<T> parameters) {
    Arguments.checkIsNotNull(fileName, "fileName");
    Arguments.checkIsNotNull(type, "type");

    for (final com.badlogic.gdx.assets.AssetManager assetManager : libGdxAssetManagers) {
        String resolvedPathDescription = "?";

        try {/*  www. j av a2 s .  co m*/
            final AssetLoader loader = assetManager.getLoader(type);

            if (loader == null)
                continue;

            final FileHandle fileHandle = loader.resolve(fileName);
            final File file = fileHandle.file();

            if (fileHandle.type() == Files.FileType.Internal && !file.exists()) {
                resolvedPathDescription = "classpath:/" + fileHandle.path();
            } else {
                resolvedPathDescription = file.getAbsolutePath();
            }

            log.debug("Queuing asset [{}] for loading as [{}]...", fileName, resolvedPathDescription);

            if (!fileHandle.exists()) {
                log.debug("Failed (file doesn't exist).");
                continue;
            }

            assetManager.load(fileName, type, parameters);
            fileNamesToManagers.put(fileName, assetManager);

            log.debug("Success.");

            return;
        } catch (final GdxRuntimeException e) {
            log.error("Cannot queue asset [{}] for loading as [{}]. Reason:\n\n{}", fileName,
                    resolvedPathDescription, e);
        }
    }

    log.error(Strings.format("Failed to queue asset [{}] for loading.", fileName));
}

From source file:com.jltrem.video.VideoPlayerAndroid.java

License:Apache License

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   ww w .jav a 2  s.  c o  m*/
public boolean play(final FileHandle file) throws FileNotFoundException {
    if (!file.exists()) {
        throw new FileNotFoundException("Could not find file: " + file.path());
    }

    //Wait for the player to be created. (If the Looper thread is busy,
    if (player == null) {
        synchronized (lock) {
            while (player == null) {
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    return false;
                }
            }
        }
    }

    player.reset();
    done = false;

    player.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            /*
                           float x = -mp.getVideoWidth() / 2;
                           float y = -mp.getVideoHeight() / 2;
                           float width = mp.getVideoWidth();
                           float height = mp.getVideoHeight();
                    
                           //@formatter:off
                           mesh.setVertices(
             new float[] {x, y, 0, 0, 1, x + width, y, 0, 1, 1, x + width, y + height, 0, 1, 0, x, y + height, 0, 0, 0});
                           //@formatter:on
                    
                           // set viewport world dimensions according to video dimensions and viewport type
                           //viewport.setWorldSize(width, height);
                    
                           Gdx.app.postRunnable(new Runnable() {
                              @Override public void run() {
             // force viewport update to let scaling take effect
             viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
                              }
                           });
                    
                           prepared = true;
                           if (sizeListener != null) {
                              sizeListener.onVideoSize(width, height);
                           }
                           mp.start();
            */
            if (true) {
                float w = mp.getVideoWidth();
                float h = mp.getVideoHeight();

                cam = new OrthographicCamera(w, h);
                cam.position.set(w / 2f, h / 2f, 0);
                cam.update();

                float baz = .94f;
                mesh.setVertices(
                        new float[] { 0, 0, 0, 0, 1 * baz, w, 0, 0, 1, 1 * baz, w, h, 0, 1, 0, 0, h, 0, 0, 0 });

                /*
                               viewport.setWorldSize(w, h);
                               Gdx.app.postRunnable(new Runnable() {
                                  @Override public void run() {
                                     // force viewport update to let scaling take effect
                                     viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
                                  }
                               });
                */
                prepared = true;
                if (sizeListener != null) {
                    sizeListener.onVideoSize(w, h);
                }
                mp.start();
            }
        }
    });

    player.setOnErrorListener(new OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            done = true;
            Log.e("VideoPlayer", String.format("Error occured: %d, %d\n", what, extra));
            return false;
        }
    });

    player.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            done = true;
            if (completionListener != null) {
                completionListener.onCompletionListener(file);
            }
        }
    });

    try {
        if (file.type() == FileType.Classpath || (file.type() == FileType.Internal && !file.file().exists())) {
            AssetManager assets = ((AndroidApplication) Gdx.app).getAssets();
            AssetFileDescriptor descriptor = assets.openFd(file.name());
            player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),
                    descriptor.getLength());
        } else {
            player.setDataSource(file.file().getAbsolutePath());
        }
        player.setSurface(new Surface(videoTexture));
        player.prepareAsync();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return true;
}

From source file:com.kotcrab.vis.ui.widget.file.FilePopupMenu.java

License:Apache License

public void build(Array<FileHandle> favorites, FileHandle file) {
    this.file = file;

    clearChildren();//from w w w . j ava 2 s. co  m

    addItem(newDirectory);
    addSeparator();

    if (file.type() == FileType.Absolute || file.type() == FileType.External)
        addItem(delete);

    if (file.type() == FileType.Absolute) {
        addItem(showInExplorer);

        if (file.isDirectory()) {
            if (favorites.contains(file, false))
                addItem(removeFromFavorites);
            else
                addItem(addToFavorites);
        }
    }
}

From source file:com.kotcrab.vis.ui.widget.file.internal.FilePopupMenu.java

License:Apache License

public void build(Array<FileHandle> favorites, FileHandle file) {
    sortingPopupMenu.build();//w ww .j  a  v a2  s  . c om
    this.file = file;

    clearChildren();

    addItem(newDirectory);
    addItem(sortBy);
    addItem(refresh);
    addSeparator();

    if (file.type() == FileType.Absolute || file.type() == FileType.External)
        addItem(delete);

    if (file.type() == FileType.Absolute) {
        addItem(showInExplorer);

        if (file.isDirectory()) {
            if (favorites.contains(file, false))
                addItem(removeFromFavorites);
            else
                addItem(addToFavorites);
        }
    }
}

From source file:de.longri.cachebox3.translation.Translation.java

License:Open Source License

private ArrayList<Lang> getLangs(String path) {
    ArrayList<Lang> Temp = new ArrayList<Lang>();

    FileHandle Dir = Gdx.files.internal(path);
    final FileHandle[] files;

    if (Dir.type() == FileType.Classpath) {
        // Cannot list a classpath directory
        // so we hardcoded the lang path
        files = new FileHandle[] { //
                Gdx.files.internal("data/lang/cs"), //
                Gdx.files.internal("data/lang/de"), //
                Gdx.files.internal("data/lang/en-GB"), //
                Gdx.files.internal("data/lang/fr"), //
                Gdx.files.internal("data/lang/hu"), //
                Gdx.files.internal("data/lang/nl"), //
                Gdx.files.internal("data/lang/pl"), //
                Gdx.files.internal("data/lang/pt-PT"),//
        };//www. j  a  v a 2 s  . c o m
    } else {
        files = Dir.list();
    }

    for (FileHandle tmp : files) {
        try {

            String stringFile = tmp + "/strings.ini";

            FileHandle langFile = Gdx.files.internal(stringFile);

            if (langFile.exists()) {
                String tmpName = getLangNameFromFile(stringFile);
                Temp.add(new Lang(tmpName, stringFile));
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    return Temp;
}

From source file:es.eucm.ead.engine.effects.video.VLCPlayer.java

License:Open Source License

/**
 * Extracts the video in the given file handle to a temp file
 * /*  w ww .  ja  v a  2  s  .  co  m*/
 * @param fileHandle
 *            the video file handle
 * @return the temp file path
 */
private String copyVideoToTemp(FileHandle fileHandle) {
    String destiny = null;
    // If file is internal means the video is inside the jar. To play it,
    // wee need to extract the video to a temp file. VLC can't deal with
    // InputStreams
    if (fileHandle.type() == FileType.Internal) {
        String name = fileHandle.path();
        destiny = tempVideos.get(name);
        if (destiny == null || !new File(destiny).exists()) {
            OutputStream os = null;
            InputStream is = null;
            try {
                is = ClassLoader.getSystemResourceAsStream(name);
                File tempFile = File.createTempFile("ead", "video");
                destiny = tempFile.getAbsolutePath();
                os = new FileOutputStream(tempFile);

                byte[] buffer = new byte[1024];
                int len;
                while ((len = is.read(buffer)) != -1) {
                    os.write(buffer, 0, len);
                }
                tempVideos.put(name, destiny);
            } catch (IOException e) {
                Gdx.app.error("VLCPlayer", "Error copying video to temp file", e);
                return null;
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        Gdx.app.error("VLCPlayer", "Error closing input stream", e);
                    }
                }
                if (os != null) {
                    try {
                        os.close();
                    } catch (IOException e) {
                        Gdx.app.error("VLCPlayer", "Error closing output stream", e);
                    }
                }
            }
        }
        // If it's absolute, it is outside the jar
    } else if (fileHandle.type() == FileType.Absolute) {
        destiny = fileHandle.file().getAbsolutePath();
    }
    return destiny;
}