Java Code Examples for com.android.SdkConstants#PLATFORM_WINDOWS

The following examples show how to use com.android.SdkConstants#PLATFORM_WINDOWS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdaterData.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Check if any error occurred during initialization.
 * If it did, display an error message.
 *
 * @return True if an error occurred, false if we should continue.
 */
public boolean checkIfInitFailed() {
    if (mAvdManagerInitError != null) {
        String example;
        if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS) {
            example = "%USERPROFILE%";     //$NON-NLS-1$
        } else {
            example = "~";                 //$NON-NLS-1$
        }

        String error = String.format(
            "The AVD manager normally uses the user's profile directory to store " +
            "AVD files. However it failed to find the default profile directory. " +
            "\n" +
            "To fix this, please set the environment variable ANDROID_SDK_HOME to " +
            "a valid path such as \"%s\".",
            example);

        displayInitError(error);

        return true;
    }
    return false;
}
 
Example 2
Source File: StdLogger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private void printMessage(String msg, PrintStream stream) {
    if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS &&
            !msg.endsWith("\r\n") &&
            msg.endsWith("\n")) {
        // remove last \n so that println can use \r\n as needed.
        msg = msg.substring(0, msg.length() - 1);
    }

    stream.print(msg);

    if (!msg.endsWith("\n")) {
        stream.println();
    }
}
 
Example 3
Source File: StdLogger.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void printMessage(String msg, PrintStream stream) {
    if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS &&
            !msg.endsWith("\r\n") &&
            msg.endsWith("\n")) {
        // remove last \n so that println can use \r\n as needed.
        msg = msg.substring(0, msg.length() - 1);
    }

    stream.print(msg);

    if (!msg.endsWith("\n")) {
        stream.println();
    }
}
 
Example 4
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether this AVD name would generate a conflict.
 *
 * @param name the name of the AVD to return
 * @return A pair of {@link AvdConflict} and the path or AVD name that conflicts.
 */
@NonNull
public Pair<AvdConflict, String> isAvdNameConflicting(@Nullable String name) {

    boolean ignoreCase = SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS;

    // Check whether we have a conflict with an existing or invalid AVD
    // known to the manager.
    synchronized (mAllAvdList) {
        for (AvdInfo info : mAllAvdList) {
            String name2 = info.getName();
            if (name2.equals(name) || (ignoreCase && name2.equalsIgnoreCase(name))) {
                if (info.getStatus() == AvdStatus.OK) {
                    return Pair.of(AvdConflict.CONFLICT_EXISTING_AVD, name2);
                } else {
                    return Pair.of(AvdConflict.CONFLICT_INVALID_AVD, name2);
                }
            }
        }
    }

    // No conflict with known AVDs.
    // Are some existing files/folders in the way of creating this AVD?

    try {
        File file = AvdInfo.getDefaultIniFile(this, name);
        if (file.exists()) {
            return Pair.of(AvdConflict.CONFLICT_EXISTING_PATH, file.getPath());
        }

        file = AvdInfo.getDefaultAvdFolder(this, name);
        if (file.exists()) {
            return Pair.of(AvdConflict.CONFLICT_EXISTING_PATH, file.getPath());
        }

    } catch (AndroidLocationException e) {
        // ignore
    }


    return Pair.of(AvdConflict.NO_CONFLICT, null);
}
 
Example 5
Source File: FileOp.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Helper to delete a file or a directory.
 * For a directory, recursively deletes all of its content.
 * Files that cannot be deleted right away are marked for deletion on exit.
 * It's ok for the file or folder to not exist at all.
 * The argument can be null.
 */
@Override
public void deleteFileOrFolder(@NonNull File fileOrFolder) {
    if (fileOrFolder != null) {
        if (isDirectory(fileOrFolder)) {
            // Must delete content recursively first
            File[] files = fileOrFolder.listFiles();
            if (files != null) {
                for (File item : files) {
                    deleteFileOrFolder(item);
                }
            }
        }

        // Don't try to delete it if it doesn't exist.
        if (!exists(fileOrFolder)) {
            return;
        }

        if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS) {
            // Trying to delete a resource on windows might fail if there's a file
            // indexer locking the resource. Generally retrying will be enough to
            // make it work.
            //
            // Try for half a second before giving up.

            for (int i = 0; i < 5; i++) {
                if (fileOrFolder.delete()) {
                    return;
                }

                try {
                    Thread.sleep(100 /*ms*/);
                } catch (InterruptedException e) {
                    // Ignore.
                }
            }

            fileOrFolder.deleteOnExit();

        } else {
            // On Linux or Mac, just straight deleting it should just work.

            if (!fileOrFolder.delete()) {
                fileOrFolder.deleteOnExit();
            }
        }
    }
}
 
Example 6
Source File: FileOp.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Helper to delete a file or a directory.
 * For a directory, recursively deletes all of its content.
 * Files that cannot be deleted right away are marked for deletion on exit.
 * It's ok for the file or folder to not exist at all.
 * The argument can be null.
 */
@Override
public void deleteFileOrFolder(@NonNull File fileOrFolder) {
    if (fileOrFolder != null) {
        if (isDirectory(fileOrFolder)) {
            // Must delete content recursively first
            File[] files = fileOrFolder.listFiles();
            if (files != null) {
                for (File item : files) {
                    deleteFileOrFolder(item);
                }
            }
        }

        // Don't try to delete it if it doesn't exist.
        if (!exists(fileOrFolder)) {
            return;
        }

        if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_WINDOWS) {
            // Trying to delete a resource on windows might fail if there's a file
            // indexer locking the resource. Generally retrying will be enough to
            // make it work.
            //
            // Try for half a second before giving up.

            for (int i = 0; i < 5; i++) {
                if (fileOrFolder.delete()) {
                    return;
                }

                try {
                    Thread.sleep(100 /*ms*/);
                } catch (InterruptedException e) {
                    // Ignore.
                }
            }

            fileOrFolder.deleteOnExit();

        } else {
            // On Linux or Mac, just straight deleting it should just work.

            if (!fileOrFolder.delete()) {
                fileOrFolder.deleteOnExit();
            }
        }
    }
}