Android Open Source - WearPomodoro Pomodoro Utils






From Project

Back to project page WearPomodoro.

License

The source code is released under:

GNU General Public License

If you think the Android project WearPomodoro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Alex Korovyansky./*from w  w w . ja va2  s. com*/
 */
package com.alexkorovyansky.wearpomodoro.helpers;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class PomodoroUtils {

    public static byte[] readRawResourceBytes(Resources resources, int rawId) {
        InputStream input = resources.openRawResource(rawId);
        try {
            return toByteArray(input);
        } catch (IOException e) {
            return null;
        } finally {
            closeQuietly(input);
        }
    }

    public static float dipToPixels(Context context, float dipValue) {
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
    }

    private static byte[] toByteArray(final InputStream input) throws IOException {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);
        return output.toByteArray();
    }

    private static long copy(final InputStream input, final OutputStream output) throws IOException {
        final byte[] buffer = new byte[1024 * 4];
        long count = 0;
        int n;
        int EOF = -1;
        while (EOF != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    private static void closeQuietly(Closeable stream) {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }

    private PomodoroUtils() {

    }
}




Java Source Code List

com.alexkorovyansky.wearpomodoro.app.MainActivity.java
com.alexkorovyansky.wearpomodoro.app.PomodoroConstants.java
com.alexkorovyansky.wearpomodoro.app.base.BasePomodoroActivity.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroAlarmReceiver.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroAlarmTickReceiver.java
com.alexkorovyansky.wearpomodoro.app.receivers.PomodoroControlReceiver.java
com.alexkorovyansky.wearpomodoro.app.services.PomodoroNotificationService.java
com.alexkorovyansky.wearpomodoro.app.ui.PomodoroEntryActivity.java
com.alexkorovyansky.wearpomodoro.app.ui.PomodoroTransitionActivity.java
com.alexkorovyansky.wearpomodoro.helpers.PersistentStorage.java
com.alexkorovyansky.wearpomodoro.helpers.PomodoroMaster.java
com.alexkorovyansky.wearpomodoro.helpers.PomodoroUtils.java
com.alexkorovyansky.wearpomodoro.helpers.ServiceProvider.java
com.alexkorovyansky.wearpomodoro.helpers.UITimer.java
com.alexkorovyansky.wearpomodoro.helpers.WakefulBroadcastReceiver.java
com.alexkorovyansky.wearpomodoro.model.ActivityType.java