Example usage for android.util Log isLoggable

List of usage examples for android.util Log isLoggable

Introduction

In this page you can find the example usage for android.util Log isLoggable.

Prototype

public static native boolean isLoggable(String tag, int level);

Source Link

Document

Checks to see whether or not a log for the specified tag is loggable at the specified level.

Usage

From source file:com.emorym.android_pusher.Pusher.java

public void disconnect() {
    try {//from  w w  w.ja va2 s  .  c om
        mWatchdog.interrupt();
        mWatchdog = null;
        mWebSocket.close();
    } catch (WebSocketException e) {
        if (Log.isLoggable(TAG, DEBUG))
            Log.d(TAG, "Exception closing web socket", e);
    }
}

From source file:com.sleekcoder.weardemo.NotificationUpdateService.java

private void dismissPhoneNotification(int id) {
    final Uri dataItemUri = new Uri.Builder().scheme(WEAR_URI_SCHEME).path(Constants.BOTH_PATH).build();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Deleting Uri: " + dataItemUri.toString());
    }/*from  w  w  w .  j a v a  2s .c  o  m*/
    Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri).setResultCallback(this);
}

From source file:com.deliciousdroid.client.NetworkUtilities.java

/**
 * Attempts to authenticate to Pinboard using a legacy Pinboard account.
 * /*from   w  w  w  . jav  a  2s.  c  om*/
 * @param username The user's username.
 * @param password The user's password.
 * @param handler The hander instance from the calling UI thread.
 * @param context The context of the calling Activity.
 * @return The boolean result indicating whether the user was
 *         successfully authenticated.
 */
public static boolean pinboardAuthenticate(String username, String password) {
    final HttpResponse resp;

    Uri.Builder builder = new Uri.Builder();
    builder.scheme(SCHEME);
    builder.authority(DELICIOUS_AUTHORITY);
    builder.appendEncodedPath("v1/posts/update");
    Uri uri = builder.build();

    HttpGet request = new HttpGet(String.valueOf(uri));

    DefaultHttpClient client = (DefaultHttpClient) HttpClientFactory.getThreadSafeClient();

    CredentialsProvider provider = client.getCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    provider.setCredentials(SCOPE, credentials);

    try {
        resp = client.execute(request);
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Successful authentication");
            }
            return true;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Error authenticating" + resp.getStatusLine());
            }
            return false;
        }
    } catch (final IOException e) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "IOException when getting authtoken", e);
        }
        return false;
    } finally {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "getAuthtoken completing");
        }
    }
}

From source file:com.joptimizer.optimizers.PrimalDualMethod.java

@Override
public int optimize() throws Exception {
    Log.i(MainActivity.JOPTIMIZER_LOGTAG, "optimize");
    long tStart = System.currentTimeMillis();
    OptimizationResponse response = new OptimizationResponse();

    // @TODO: check assumptions!!!
    //      if(getA()!=null){
    //         if(ALG.rank(getA())>=getA().rows()){
    //            throw new IllegalArgumentException("A-rank must be less than A-rows");
    //         }//from   w w w  .  j a v  a  2  s.c  om
    //      }

    DoubleMatrix1D X0 = getInitialPoint();
    if (X0 == null) {
        DoubleMatrix1D X0NF = getNotFeasibleInitialPoint();
        if (X0NF != null) {
            double rPriX0NFNorm = Math.sqrt(ALG.norm2(rPri(X0NF)));
            DoubleMatrix1D fiX0NF = getFi(X0NF);
            int maxIndex = Utils.getMaxIndex(fiX0NF.toArray());
            double maxValue = fiX0NF.get(maxIndex);
            if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
                Log.d(MainActivity.JOPTIMIZER_LOGTAG, "rPriX0NFNorm :  " + rPriX0NFNorm);
                Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X0NF         :  " + ArrayUtils.toString(X0NF.toArray()));
                Log.d(MainActivity.JOPTIMIZER_LOGTAG,
                        "fiX0NF       :  " + ArrayUtils.toString(fiX0NF.toArray()));
            }
            if (maxValue < 0 && rPriX0NFNorm <= getToleranceFeas()) {
                //the provided not-feasible starting point is already feasible
                Log.d(MainActivity.JOPTIMIZER_LOGTAG, "the provided initial point is already feasible");
                X0 = X0NF;
            }
        }
        if (X0 == null) {
            BasicPhaseIPDM bf1 = new BasicPhaseIPDM(this);
            X0 = bf1.findFeasibleInitialPoint();
        }
    }

    //check X0 feasibility
    DoubleMatrix1D fiX0 = getFi(X0);
    int maxIndex = Utils.getMaxIndex(fiX0.toArray());
    double maxValue = fiX0.get(maxIndex);
    double rPriX0Norm = Math.sqrt(ALG.norm2(rPri(X0)));
    if (maxValue >= 0 || rPriX0Norm > getToleranceFeas()) {
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "rPriX0Norm  : " + rPriX0Norm);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "ineqX0      : " + ArrayUtils.toString(fiX0.toArray()));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "max ineq index: " + maxIndex);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "max ineq value: " + maxValue);
        throw new Exception("initial point must be strictly feasible");
    }

    DoubleMatrix1D V0 = (getA() != null) ? F1.make(getA().rows()) : F1.make(0);

    DoubleMatrix1D L0 = getInitialLagrangian();
    if (L0 != null) {
        for (int j = 0; j < L0.size(); j++) {
            // must be >0
            if (L0.get(j) <= 0) {
                throw new IllegalArgumentException("initial lagrangian must be strictly > 0");
            }
        }
    } else {
        //L0 = F1.make(getFi().length, 1.);// must be >0
        L0 = F1.make(getFi().length, Math.min(1, (double) getDim() / getFi().length));// must be >0
    }
    if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X0:  " + ArrayUtils.toString(X0.toArray()));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "V0:  " + ArrayUtils.toString(V0.toArray()));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "L0:  " + ArrayUtils.toString(L0.toArray()));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "toleranceFeas:  " + getToleranceFeas());
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "tolerance    :  " + getTolerance());
    }

    DoubleMatrix1D X = X0;
    DoubleMatrix1D V = V0;
    DoubleMatrix1D L = L0;
    //double F0X;
    //DoubleMatrix1D gradF0X = null;
    //DoubleMatrix1D fiX = null;
    //DoubleMatrix2D GradFiX = null;
    //DoubleMatrix1D rPriX = null;
    //DoubleMatrix1D rCentXLt = null;
    //DoubleMatrix1D rDualXLV = null;
    //double rPriXNorm = Double.NaN;
    //double rCentXLtNorm = Double.NaN;
    //double rDualXLVNorm = Double.NaN;
    //double normRXLVt = Double.NaN;
    double previousF0X = Double.NaN;
    double previousRPriXNorm = Double.NaN;
    double previousRDualXLVNorm = Double.NaN;
    double previousSurrDG = Double.NaN;
    double t;
    int iteration = 0;
    while (true) {

        iteration++;
        // iteration limit condition
        if (iteration == getMaxIteration() + 1) {
            response.setReturnCode(OptimizationResponse.WARN);
            Log.w(MainActivity.JOPTIMIZER_LOGTAG, "Max iterations limit reached");
            break;
        }

        double F0X = getF0(X);
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "iteration: " + iteration);
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X=" + ArrayUtils.toString(X.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "L=" + ArrayUtils.toString(L.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "V=" + ArrayUtils.toString(V.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "f0(X)=" + F0X);
        }

        //         if(!Double.isNaN(previousF0X)){
        //            if (previousF0X < F0X) {
        //               throw new Exception("critical minimization problem");
        //            }
        //         }
        //         previousF0X = F0X;

        // determine functions evaluations
        DoubleMatrix1D gradF0X = getGradF0(X);
        DoubleMatrix1D fiX = getFi(X);
        DoubleMatrix2D GradFiX = getGradFi(X);
        DoubleMatrix2D[] HessFiX = getHessFi(X);

        // determine t
        double surrDG = getSurrogateDualityGap(fiX, L);
        t = getMu() * getFi().length / surrDG;
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "t:  " + t);

        // determine residuals
        DoubleMatrix1D rPriX = rPri(X);
        DoubleMatrix1D rCentXLt = rCent(fiX, L, t);
        DoubleMatrix1D rDualXLV = rDual(GradFiX, gradF0X, L, V);
        double rPriXNorm = Math.sqrt(ALG.norm2(rPriX));
        double rCentXLtNorm = Math.sqrt(ALG.norm2(rCentXLt));
        double rDualXLVNorm = Math.sqrt(ALG.norm2(rDualXLV));
        double normRXLVt = Math
                .sqrt(Math.pow(rPriXNorm, 2) + Math.pow(rCentXLtNorm, 2) + Math.pow(rDualXLVNorm, 2));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "rPri  norm: " + rPriXNorm);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "rCent norm: " + rCentXLtNorm);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "rDual norm: " + rDualXLVNorm);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "surrDG    : " + surrDG);

        // custom exit condition
        if (checkCustomExitConditions(X)) {
            response.setReturnCode(OptimizationResponse.SUCCESS);
            break;
        }

        // exit condition
        if (rPriXNorm <= getToleranceFeas() && rDualXLVNorm <= getToleranceFeas() && surrDG <= getTolerance()) {
            response.setReturnCode(OptimizationResponse.SUCCESS);
            break;
        }

        // progress conditions
        if (isCheckProgressConditions()) {
            if (!Double.isNaN(previousRPriXNorm) && !Double.isNaN(previousRDualXLVNorm)
                    && !Double.isNaN(previousSurrDG)) {
                if ((previousRPriXNorm <= rPriXNorm && rPriXNorm >= getToleranceFeas())
                        || (previousRDualXLVNorm <= rDualXLVNorm && rDualXLVNorm >= getToleranceFeas())) {
                    Log.w(MainActivity.JOPTIMIZER_LOGTAG,
                            "No progress achieved, exit iterations loop without desired accuracy");
                    response.setReturnCode(OptimizationResponse.WARN);
                    break;
                }
            }
            previousRPriXNorm = rPriXNorm;
            previousRDualXLVNorm = rDualXLVNorm;
            previousSurrDG = surrDG;
        }

        // compute primal-dual search direction
        // a) prepare 11.55 system
        DoubleMatrix2D HessSum = getHessF0(X);
        for (int j = 0; j < getFi().length; j++) {
            if (HessFiX[j] != FunctionsUtils.ZEROES_MATRIX_PLACEHOLDER) {
                HessSum.assign(HessFiX[j].copy().assign(Mult.mult(L.get(j))), Functions.plus);
            }
            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"HessSum    : " + ArrayUtils.toString(HessSum.toArray()));
        }

        //         DoubleMatrix2D GradSum = F2.make(getDim(), getDim());
        //         for (int j = 0; j < getFi().length; j++) {
        //            DoubleMatrix1D g = GradFiX.viewRow(j);
        //            GradSum.assign(ALG.multOuter(g, g, null).assign(Mult.mult(-L.get(j) / fiX.get(j))), Functions.plus);
        //            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"GradSum    : " + ArrayUtils.toString(GradSum.toArray()));
        //         }
        DoubleMatrix2D GradSum = F2.make(getDim(), getDim());
        for (int j = 0; j < getFi().length; j++) {
            final double c = -L.getQuick(j) / fiX.getQuick(j);
            DoubleMatrix1D g = GradFiX.viewRow(j);
            SeqBlas.seqBlas.dger(c, g, g, GradSum);
            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"GradSum    : " + ArrayUtils.toString(GradSum.toArray()));
        }

        DoubleMatrix2D Hpd = HessSum.assign(GradSum, Functions.plus);
        //DoubleMatrix2D Hpd = getHessF0(X).assign(HessSum, Functions.plus).assign(GradSum, Functions.plus);

        DoubleMatrix1D gradSum = F1.make(getDim());
        for (int j = 0; j < getFi().length; j++) {
            gradSum.assign(GradFiX.viewRow(j).copy().assign(Mult.div(-t * fiX.get(j))), Functions.plus);
            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"gradSum    : " + ArrayUtils.toString(gradSum.toArray()));
        }
        DoubleMatrix1D g = null;
        if (getAT() == null) {
            g = gradF0X.copy().assign(gradSum, Functions.plus);
        } else {
            g = gradF0X.copy().assign(gradSum, Functions.plus).assign(ALG.mult(getAT(), V), Functions.plus);
        }

        // b) solving 11.55 system
        if (this.kktSolver == null) {
            this.kktSolver = new BasicKKTSolver();
        }
        //KKTSolver solver = new DiagonalKKTSolver();
        if (isCheckKKTSolutionAccuracy()) {
            kktSolver.setCheckKKTSolutionAccuracy(true);
            kktSolver.setToleranceKKT(getToleranceKKT());
        }
        kktSolver.setHMatrix(Hpd.toArray());
        kktSolver.setGVector(g.toArray());
        if (getA() != null) {
            kktSolver.setAMatrix(getA().toArray());
            kktSolver.setATMatrix(getAT().toArray());
            kktSolver.setHVector(rPriX.toArray());
        }
        double[][] sol = kktSolver.solve();
        DoubleMatrix1D stepX = F1.make(sol[0]);
        DoubleMatrix1D stepV = (sol[1] != null) ? F1.make(sol[1]) : F1.make(0);
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "stepX: " + ArrayUtils.toString(stepX.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "stepV: " + ArrayUtils.toString(stepV.toArray()));
        }

        // c) solving for L
        DoubleMatrix1D stepL = null;
        DoubleMatrix2D diagFInv = F2.diagonal(fiX.copy().assign(Functions.inv));
        DoubleMatrix2D diagL = F2.diagonal(L);
        stepL = ALG.mult(diagFInv, ALG.mult(diagL, ALG.mult(GradFiX, stepX))).assign(Mult.mult(-1))
                .assign(ALG.mult(diagFInv, rCentXLt), Functions.plus);
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "stepL: " + ArrayUtils.toString(stepL.toArray()));
        }

        // line search and update
        // a) sMax computation 
        double sMax = Double.MAX_VALUE;
        for (int j = 0; j < getFi().length; j++) {
            if (stepL.get(j) < 0) {
                sMax = Math.min(-L.get(j) / stepL.get(j), sMax);
            }
        }
        sMax = Math.min(1, sMax);
        double s = 0.99 * sMax;
        // b) backtracking with f
        DoubleMatrix1D X1 = F1.make(X.size());
        DoubleMatrix1D L1 = F1.make(L.size());
        DoubleMatrix1D V1 = F1.make(V.size());
        DoubleMatrix1D fiX1 = null;
        DoubleMatrix1D gradF0X1 = null;
        DoubleMatrix2D GradFiX1 = null;
        DoubleMatrix1D rPriX1 = null;
        DoubleMatrix1D rCentX1L1t = null;
        DoubleMatrix1D rDualX1L1V1 = null;
        int cnt = 0;
        boolean areAllNegative = true;
        while (cnt < 500) {
            cnt++;
            // X1 = X + s*stepX
            X1 = stepX.copy().assign(Mult.mult(s)).assign(X, Functions.plus);
            DoubleMatrix1D ineqValueX1 = getFi(X1);
            areAllNegative = true;
            for (int j = 0; areAllNegative && j < getFi().length; j++) {
                areAllNegative = (Double.compare(ineqValueX1.get(j), 0.) < 0);
            }
            if (areAllNegative) {
                break;
            }
            s = getBeta() * s;
        }

        if (!areAllNegative) {
            //exited from the feasible region
            throw new Exception("Optimization failed: impossible to remain within the faesible region");
        }

        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "s: " + s);
        // c) backtracking with norm
        double previousNormRX1L1V1t = Double.NaN;
        cnt = 0;
        while (cnt < 500) {
            cnt++;
            X1 = stepX.copy().assign(Mult.mult(s)).assign(X, Functions.plus);
            L1 = stepL.copy().assign(Mult.mult(s)).assign(L, Functions.plus);
            V1 = stepV.copy().assign(Mult.mult(s)).assign(V, Functions.plus);
            //            X1.assign(stepX.copy().assign(Mult.mult(s)).assign(X, Functions.plus));
            //            L1.assign(stepL.copy().assign(Mult.mult(s)).assign(L, Functions.plus));
            //            V1.assign(stepV.copy().assign(Mult.mult(s)).assign(V, Functions.plus));

            if (isInDomainF0(X1)) {
                fiX1 = getFi(X1);
                gradF0X1 = getGradF0(X1);
                GradFiX1 = getGradFi(X1);

                rPriX1 = rPri(X1);
                rCentX1L1t = rCent(fiX1, L1, t);
                rDualX1L1V1 = rDual(GradFiX1, gradF0X1, L1, V1);
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rPriX1     : "+ArrayUtils.toString(rPriX1.toArray()));
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rCentX1L1t : "+ArrayUtils.toString(rCentX1L1t.toArray()));
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rDualX1L1V1: "+ArrayUtils.toString(rDualX1L1V1.toArray()));
                double normRX1L1V1t = Math
                        .sqrt(ALG.norm2(rPriX1) + ALG.norm2(rCentX1L1t) + ALG.norm2(rDualX1L1V1));
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"normRX1L1V1t: "+normRX1L1V1t);
                if (normRX1L1V1t <= (1 - getAlpha() * s) * normRXLVt) {
                    break;
                }

                if (!Double.isNaN(previousNormRX1L1V1t)) {
                    if (previousNormRX1L1V1t <= normRX1L1V1t) {
                        Log.w(MainActivity.JOPTIMIZER_LOGTAG, "No progress achieved in backtracking with norm");
                        break;
                    }
                }
                previousNormRX1L1V1t = normRX1L1V1t;
            }

            s = getBeta() * s;
            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"s: " + s);
        }

        // update
        X = X1;
        V = V1;
        L = L1;

        //         fiX     = fiX1;
        //         gradF0X = gradF0X1;
        //         GradFiX  = GradFiX1;
        //         
        //         rPriX    = rPriX1;
        //         rCentXLt = rCentX1L1t;
        //         rDualXLV = rDualX1L1V1;
        //         rPriXNorm    = Math.sqrt(ALG.norm2(rPriX));
        //         rCentXLtNorm = Math.sqrt(ALG.norm2(rCentXLt));
        //         rDualXLVNorm = Math.sqrt(ALG.norm2(rDualXLV));
        //         normRXLVt = Math.sqrt(Math.pow(rPriXNorm, 2) + Math.pow(rCentXLtNorm, 2) + Math.pow(rDualXLVNorm, 2));
        //         if(Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)){
        //            Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rPri  norm: " + rPriXNorm);
        //            Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rCent norm: " + rCentXLtNorm);
        //            Log.d(MainActivity.JOPTIMIZER_LOGTAG,"rDual norm: " + rDualXLVNorm);
        //            Log.d(MainActivity.JOPTIMIZER_LOGTAG,"surrDG    : " + surrDG);
        //         }
    }

    long tStop = System.currentTimeMillis();
    Log.d(MainActivity.JOPTIMIZER_LOGTAG, "time: " + (tStop - tStart));
    Log.d(MainActivity.JOPTIMIZER_LOGTAG, "sol : " + ArrayUtils.toString(X.toArray()));
    Log.d(MainActivity.JOPTIMIZER_LOGTAG, "ret code: " + response.getReturnCode());
    response.setSolution(X.toArray());
    setOptimizationResponse(response);
    return response.getReturnCode();
}

From source file:carbon.internal.PercentLayoutHelper.java

/**
 * Constructs a PercentLayoutInfo from attributes associated with a View. Call this method from
 * {@code LayoutParams(Context c, AttributeSet attrs)} constructor.
 *//*www  . j a  v  a2 s.  c om*/
public static PercentLayoutInfo getPercentLayoutInfo(Context context, AttributeSet attrs) {
    PercentLayoutInfo info = null;
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Carbon);
    float value = array.getFraction(R.styleable.Carbon_carbon_widthPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent width: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.widthPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_heightPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent height: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.heightPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.leftMarginPercent = value;
        info.topMarginPercent = value;
        info.rightMarginPercent = value;
        info.bottomMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginLeftPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent left margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.leftMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginTopPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent top margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.topMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginRightPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent right margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.rightMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginBottomPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent bottom margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.bottomMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginStartPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent start margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.startMarginPercent = value;
    }
    value = array.getFraction(R.styleable.Carbon_carbon_marginEndPercent, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "percent end margin: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.endMarginPercent = value;
    }

    value = array.getFraction(R.styleable.Carbon_carbon_aspectRatio, 1, 1, -1f);
    if (value != -1f) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "aspect ratio: " + value);
        }
        info = info != null ? info : new PercentLayoutInfo();
        info.aspectRatio = value;
    }

    array.recycle();
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "constructed: " + info);
    }
    return info;
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java

public void doAudioAlert(Context context) {
    // Use a throttler to keep this from interrupting itself too much.
    if (System.currentTimeMillis() - mLastAudioMs < THROTTLE_LIMIT_MS) {
        return;//w w w  . j  av a 2s .co m
    }
    mLastAudioMs = System.currentTimeMillis();
    final MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        mediaPlayer.setDataSource(context, mNotification);
        mediaPlayer.setOnPreparedListener(MEDIA_PLAYER_ON_PREPARED_LISTENER);
        mediaPlayer.setOnCompletionListener(MEDIA_PLAYER_COMPLETION_LISTENER);
        // Don't prepare the mediaplayer on the UI thread! That's asking for trouble.
        mediaPlayer.prepareAsync();
    } catch (IOException e) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "error getting notification sound");
        }
    }
}

From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java

/** {@inheritDoc} */
@Override//from w  w w.ja  v a  2 s .c o  m
public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver)
        throws JSONException, IOException {
    final ArrayList<ContentProviderOperation> batch = Lists.newArrayList();

    // Walk document, parsing any incoming entries
    int drink_id = 0;
    JSONObject result = parser.getJSONObject("result");
    JSONArray drinks = result.getJSONArray("drinks");
    JSONObject drink;
    for (int i = 0; i < drinks.length(); i++) {
        if (drink_id == 0) { // && ENTRY.equals(parser.getName()
            // Process single spreadsheet row at a time
            drink = drinks.getJSONObject(i);
            final String drinkId = sanitizeId(drink.getString("id"));
            final Uri drinkUri = Drinks.buildDrinkUri(drinkId);

            // Check for existing details, only update when changed
            final ContentValues values = queryDrinkDetails(drinkUri, resolver);
            final long localUpdated = values.getAsLong(SyncColumns.UPDATED);
            final long serverUpdated = 500; //entry.getUpdated();
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "found drink " + drinkId);
                Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated);
            }
            if (localUpdated != KegbotContract.UPDATED_NEVER)
                continue;

            final Uri drinkKegUri = Drinks.buildKegUri(drinkId);
            final Uri drinkUserUri = Drinks.buildUserUri(drinkId);

            // Clear any existing values for this session, treating the
            // incoming details as authoritative.
            batch.add(ContentProviderOperation.newDelete(drinkUri).build());
            batch.add(ContentProviderOperation.newDelete(drinkKegUri).build());

            final ContentProviderOperation.Builder builder = ContentProviderOperation
                    .newInsert(Drinks.CONTENT_URI);

            builder.withValue(SyncColumns.UPDATED, serverUpdated);
            builder.withValue(Drinks.DRINK_ID, drinkId);

            // Inherit starred value from previous row
            if (values.containsKey(Drinks.DRINK_STARRED)) {
                builder.withValue(Drinks.DRINK_STARRED, values.getAsInteger(Drinks.DRINK_STARRED));
            }

            if (drink.has("session_id"))
                builder.withValue(Drinks.SESSION_ID, drink.getInt("session_id"));
            if (drink.has("status"))
                builder.withValue(Drinks.STATUS, drink.getString("status"));
            if (drink.has("user_id"))
                builder.withValue(Drinks.USER_ID, drink.getString("user_id"));
            if (drink.has("keg_id"))
                builder.withValue(Drinks.KEG_ID, drink.getInt("keg_id"));
            if (drink.has("volume_ml"))
                builder.withValue(Drinks.VOLUME, drink.getDouble("volume_ml"));
            if (drink.has("pour_time"))
                builder.withValue(Drinks.POUR_TIME, drink.getString("pour_time"));

            // Normal session details ready, write to provider
            batch.add(builder.build());

            // Assign kegs
            final int kegId = drink.getInt("keg_id");
            batch.add(ContentProviderOperation.newInsert(drinkKegUri).withValue(DrinksKeg.DRINK_ID, drinkId)
                    .withValue(DrinksKeg.KEG_ID, kegId).build());

            // Assign users
            if (drink.has("user_id")) {
                final String userId = drink.getString("user_id");
                batch.add(ContentProviderOperation.newInsert(drinkUserUri)
                        .withValue(DrinksUser.DRINK_ID, drinkId).withValue(DrinksUser.USER_ID, userId).build());
            }
        }
    }

    return batch;
}

From source file:at.bitfire.davdroid.App.java

public void reinitLogger() {
    // don't use Android default logging, we have our own handlers
    log.setUseParentHandlers(false);//  w  ww  .  jav a  2  s. com

    @Cleanup
    ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(this);
    Settings settings = new Settings(dbHelper.getReadableDatabase());

    boolean logToFile = settings.getBoolean(LOG_TO_EXTERNAL_STORAGE, false),
            logVerbose = logToFile || Log.isLoggable(log.getName(), Log.DEBUG);

    // set logging level according to preferences
    log.setLevel(logVerbose ? Level.ALL : Level.INFO);

    // remove all handlers
    for (Handler handler : log.getHandlers())
        log.removeHandler(handler);

    // add logcat handler
    log.addHandler(LogcatHandler.INSTANCE);

    NotificationManagerCompat nm = NotificationManagerCompat.from(this);
    // log to external file according to preferences
    if (logToFile) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.drawable.ic_sd_storage_light).setLargeIcon(getLauncherBitmap(this))
                .setContentTitle(getString(R.string.logging_davdroid_file_logging)).setLocalOnly(true);

        File dir = getExternalFilesDir(null);
        if (dir != null)
            try {
                String fileName = new File(dir, "davdroid-" + android.os.Process.myPid() + "-"
                        + DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd-HHmmss") + ".txt")
                                .toString();
                log.info("Logging to " + fileName);

                FileHandler fileHandler = new FileHandler(fileName);
                fileHandler.setFormatter(PlainTextFormatter.DEFAULT);
                log.addHandler(fileHandler);
                builder.setContentText(dir.getPath())
                        .setSubText(getString(R.string.logging_to_external_storage_warning))
                        .setCategory(NotificationCompat.CATEGORY_STATUS)
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(getString(R.string.logging_to_external_storage, dir.getPath())))
                        .setOngoing(true);

            } catch (IOException e) {
                log.log(Level.SEVERE, "Couldn't create external log file", e);

                builder.setContentText(getString(R.string.logging_couldnt_create_file, e.getLocalizedMessage()))
                        .setCategory(NotificationCompat.CATEGORY_ERROR);
            }
        else
            builder.setContentText(getString(R.string.logging_no_external_storage));

        nm.notify(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING, builder.build());
    } else
        nm.cancel(Constants.NOTIFICATION_EXTERNAL_FILE_LOGGING);
}

From source file:com.samsung.multiwindow.MultiWindow.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {

    if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
        Log.d(TAG, "Initialize multiwindow");
    }/*from  w w  w . j av a2 s. c  o m*/
    super.initialize(cordova, webView);
    String packageName = cordova.getActivity().getPackageName();
    PackageManager pm = cordova.getActivity().getPackageManager();
    ApplicationInfo ai = null;
    try {
        ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if (ai.metaData != null) {
            pluginMetadata = ai.metaData.getBoolean(META_DATA);
        }
    } catch (NameNotFoundException e) {
        Log.e("MultiWindow", e.getMessage());
    }
}

From source file:org.openschedule.api.impl.EventTemplate.java

public List<Comment> getEventComments(String shortName) {
    Log.v(TAG, "getEventComments : enter");

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "getEventComments : shortName=" + shortName);
    }//from w w  w . ja va 2 s .  c  o  m

    Log.v(TAG, "getEventComments : exit");
    return restTemplate.getForObject(buildUri("public/" + shortName + "/comments"), CommentList.class);
}