Search in sources :

Example 56 with WorkerThread

use of android.support.annotation.WorkerThread in project mobile-center-sdk-android by Microsoft.

the class AppCenter method finishConfiguration.

@WorkerThread
private void finishConfiguration() {
    /* Load some global constants. */
    Constants.loadFromContext(mApplication);
    /* If parameters are valid, init context related resources. */
    StorageHelper.initialize(mApplication);
    /* Initialize session storage. */
    SessionContext.getInstance();
    /* Get enabled state. */
    boolean enabled = isInstanceEnabled();
    /* Init uncaught exception handler. */
    mUncaughtExceptionHandler = new UncaughtExceptionHandler();
    if (enabled) {
        mUncaughtExceptionHandler.register();
    }
    /* Init channel. */
    mLogSerializer = new DefaultLogSerializer();
    mLogSerializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory());
    mLogSerializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory());
    mChannel = new DefaultChannel(mApplication, mAppSecret, mLogSerializer, mHandler);
    mChannel.setEnabled(enabled);
    mChannel.addGroup(CORE_GROUP, DEFAULT_TRIGGER_COUNT, DEFAULT_TRIGGER_INTERVAL, DEFAULT_TRIGGER_MAX_PARALLEL_REQUESTS, null);
    if (mLogUrl != null) {
        mChannel.setLogUrl(mLogUrl);
    }
    if (!enabled) {
        NetworkStateHelper.getSharedInstance(mApplication).close();
    }
    AppCenterLog.debug(LOG_TAG, "App Center storage initialized.");
}
Also used : StartServiceLogFactory(com.microsoft.appcenter.ingestion.models.json.StartServiceLogFactory) CustomPropertiesLogFactory(com.microsoft.appcenter.ingestion.models.json.CustomPropertiesLogFactory) DefaultChannel(com.microsoft.appcenter.channel.DefaultChannel) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) WorkerThread(android.support.annotation.WorkerThread)

Example 57 with WorkerThread

use of android.support.annotation.WorkerThread in project mobile-center-sdk-android by Microsoft.

the class AppCenter method sendStartServiceLog.

/**
 * Queue start service log.
 *
 * @param serviceNames the services to send.
 */
@WorkerThread
private void sendStartServiceLog(List<String> serviceNames) {
    if (isInstanceEnabled()) {
        StartServiceLog startServiceLog = new StartServiceLog();
        startServiceLog.setServices(serviceNames);
        mChannel.enqueue(startServiceLog, CORE_GROUP);
    } else {
        if (mStartedServicesNamesToLog == null) {
            mStartedServicesNamesToLog = new ArrayList<>();
        }
        mStartedServicesNamesToLog.addAll(serviceNames);
    }
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) WorkerThread(android.support.annotation.WorkerThread)

Example 58 with WorkerThread

use of android.support.annotation.WorkerThread in project Shuttle by timusus.

the class ArtworkUtils method getAllFolderArtwork.

/**
 * Searches the parent directory of the passed in path for [cover/album/artwork].[png/jpg/jpeg]
 * using regex and returns a {@link List<File>} representing the artwork
 */
@WorkerThread
public static List<File> getAllFolderArtwork(@Nullable final String path) {
    List<File> fileArray = new ArrayList<>();
    if (path != null) {
        File[] files;
        File parent = new File(path).getParentFile();
        if (parent.exists() && parent.isDirectory()) {
            final Pattern pattern = Pattern.compile("(folder|cover|album).*\\.(jpg|jpeg|png)", Pattern.CASE_INSENSITIVE);
            files = parent.listFiles(file1 -> pattern.matcher(file1.getName()).matches());
            if (files.length != 0) {
                for (File file : files) {
                    if (file.exists()) {
                        fileArray.add(file);
                    }
                }
            }
        }
    }
    return fileArray;
}
Also used : ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) Song(com.simplecity.amp_library.model.Song) AudioFile(org.jaudiotagger.audio.AudioFile) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaStore(android.provider.MediaStore) NoSuchElementException(java.util.NoSuchElementException) Log(android.util.Log) Cursor(android.database.Cursor) IOException(java.io.IOException) Tag(org.jaudiotagger.tag.Tag) FileInputStream(java.io.FileInputStream) WorkerThread(android.support.annotation.WorkerThread) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) TagException(org.jaudiotagger.tag.TagException) AudioFileIO(org.jaudiotagger.audio.AudioFileIO) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) Pattern(java.util.regex.Pattern) Nullable(android.support.annotation.Nullable) ContentUris(android.content.ContentUris) InputStream(java.io.InputStream) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File) WorkerThread(android.support.annotation.WorkerThread)

Example 59 with WorkerThread

use of android.support.annotation.WorkerThread in project ViewAnimator by florent37.

the class SvgPathParser method parsePath.

/**
 * This is where the hard-to-parse paths are handled.
 * Uppercase rules are absolute positions, lowercase are relative.
 * Types of path rules:
 * <p/>
 * <ol>
 * <li>M/m - (x y)+ - Move to (without drawing)
 * <li>Z/z - (no params) - Close path (back to starting point)
 * <li>L/l - (x y)+ - Line to
 * <li>H/h - x+ - Horizontal ine to
 * <li>V/v - y+ - Vertical line to
 * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to
 * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier)
 * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to
 * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point)
 * </ol>
 * <p/>
 * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign)
 *
 * @param dAttributeOfPath the d attribute of &lt;path&gt; from the XML
 */
@WorkerThread
public static Path parsePath(String dAttributeOfPath) throws Exception {
    int n = dAttributeOfPath.length();
    ParserHelper helper = new ParserHelper(dAttributeOfPath, 0);
    helper.skipWhitespace();
    Path path = new Path();
    float lastX = 0;
    float lastY = 0;
    float lastX1 = 0;
    float lastY1 = 0;
    float subPathStartX = 0;
    float subPathStartY = 0;
    char prevCmd = 0;
    while (helper.getPosition() < n) {
        char cmd = dAttributeOfPath.charAt(helper.getPosition());
        switch(cmd) {
            case '-':
            case '+':
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                if (prevCmd == 'm' || prevCmd == 'M') {
                    cmd = (char) (((int) prevCmd) - 1);
                    break;
                } else if (prevCmd == 'c' || prevCmd == 'C') {
                    cmd = prevCmd;
                    break;
                } else if (prevCmd == 'l' || prevCmd == 'L') {
                    cmd = prevCmd;
                    break;
                }
            default:
                {
                    helper.advance();
                    prevCmd = cmd;
                }
        }
        boolean wasCurve = false;
        switch(cmd) {
            case 'M':
            case 'm':
                {
                    float x = helper.nextFloat();
                    float y = helper.nextFloat();
                    Log.d(null, String.format("move to: [%s,%s]", x, y));
                    if (cmd == 'm') {
                        subPathStartX += x;
                        subPathStartY += y;
                        path.rMoveTo(x, y);
                        lastX += x;
                        lastY += y;
                    } else {
                        subPathStartX = x;
                        subPathStartY = y;
                        path.moveTo(x, y);
                        lastX = x;
                        lastY = y;
                    }
                    break;
                }
            case 'Z':
            case 'z':
                {
                    Log.d(null, String.format("close, move to: [%s,%s]", subPathStartX, subPathStartY));
                    path.close();
                    path.moveTo(subPathStartX, subPathStartY);
                    lastX = subPathStartX;
                    lastY = subPathStartY;
                    lastX1 = subPathStartX;
                    lastY1 = subPathStartY;
                    wasCurve = true;
                    break;
                }
            case 'L':
            case 'l':
                {
                    float x = helper.nextFloat();
                    float y = helper.nextFloat();
                    Log.d(null, String.format("line to: [%s,%s]", x, y));
                    if (cmd == 'l') {
                        path.rLineTo(x, y);
                        lastX += x;
                        lastY += y;
                    } else {
                        path.lineTo(x, y);
                        lastX = x;
                        lastY = y;
                    }
                    break;
                }
            case 'H':
            case 'h':
                {
                    float x = helper.nextFloat();
                    Log.d(null, String.format("horizontal line to: [%s]", x));
                    if (cmd == 'h') {
                        path.rLineTo(x, 0);
                        lastX += x;
                    } else {
                        path.lineTo(x, lastY);
                        lastX = x;
                    }
                    break;
                }
            case 'V':
            case 'v':
                {
                    float y = helper.nextFloat();
                    Log.d(null, String.format("vertical line to: [%s]", y));
                    if (cmd == 'v') {
                        path.rLineTo(0, y);
                        lastY += y;
                    } else {
                        path.lineTo(lastX, y);
                        lastY = y;
                    }
                    break;
                }
            case 'C':
            case 'c':
                {
                    wasCurve = true;
                    float x1 = helper.nextFloat();
                    float y1 = helper.nextFloat();
                    float x2 = helper.nextFloat();
                    float y2 = helper.nextFloat();
                    float x = helper.nextFloat();
                    float y = helper.nextFloat();
                    Log.d(null, String.format("cubic to: [%s,%s][%s,%s][%s,%s]", x1, y1, x2, y2, x, y));
                    if (cmd == 'c') {
                        x1 += lastX;
                        x2 += lastX;
                        x += lastX;
                        y1 += lastY;
                        y2 += lastY;
                        y += lastY;
                    }
                    path.cubicTo(x1, y1, x2, y2, x, y);
                    lastX1 = x2;
                    lastY1 = y2;
                    lastX = x;
                    lastY = y;
                    break;
                }
            case 'S':
            case 's':
                {
                    wasCurve = true;
                    float x2 = helper.nextFloat();
                    float y2 = helper.nextFloat();
                    float x = helper.nextFloat();
                    float y = helper.nextFloat();
                    Log.d(null, String.format("cubic to: [%s,%s][%s,%s]", x2, y2, x, y));
                    if (cmd == 's') {
                        x2 += lastX;
                        x += lastX;
                        y2 += lastY;
                        y += lastY;
                    }
                    float x1 = 2 * lastX - lastX1;
                    float y1 = 2 * lastY - lastY1;
                    path.cubicTo(x1, y1, x2, y2, x, y);
                    lastX1 = x2;
                    lastY1 = y2;
                    lastX = x;
                    lastY = y;
                    break;
                }
            case 'A':
            case 'a':
                {
                    float rx = helper.nextFloat();
                    float ry = helper.nextFloat();
                    float theta = helper.nextFloat();
                    int largeArc = (int) helper.nextFloat();
                    int sweepArc = (int) helper.nextFloat();
                    float x = helper.nextFloat();
                    float y = helper.nextFloat();
                    Log.d(null, String.format("arc to: [%s,%s][%s][%s,%s][%s,%s]", rx, ry, theta, largeArc, sweepArc, x, y));
                    drawArc(path, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc);
                    lastX = x;
                    lastY = y;
                    break;
                }
        }
        if (!wasCurve) {
            lastX1 = lastX;
            lastY1 = lastY;
        }
        helper.skipWhitespace();
    }
    return path;
}
Also used : Path(android.graphics.Path) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)59 NonNull (android.support.annotation.NonNull)21 Cursor (android.database.Cursor)17 StorIOException (com.pushtorefresh.storio.StorIOException)15 ArrayList (java.util.ArrayList)14 File (java.io.File)13 Uri (android.net.Uri)8 ContentValues (android.content.ContentValues)6 Nullable (android.support.annotation.Nullable)6 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)6 HashMap (java.util.HashMap)6 HistoryItem (acr.browser.lightning.database.HistoryItem)5 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 Intent (android.content.Intent)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 InputStream (java.io.InputStream)3 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)3 List (java.util.List)3 ContentUris (android.content.ContentUris)2