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:KSView.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one calculated from percentage
 * values./*from w  w  w  . ja  va2s  .c o  m*/
 *
 * @param widthMeasureSpec  Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        LogUtil.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);

    LogUtil.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            LogUtil.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                LogUtil.d(TAG, "using " + info);
            }
            if (info != null) {
                supportTextSize(widthHint, heightHint, view, info);
                supportMinOrMaxDimesion(widthHint, heightHint, view, info);

                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }

}

From source file:com.gosuncn.core.percentlayout.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one
 * calculated from percentage values.//from w w w  .  j ava  2 s  .c  o m
 * 
 * @param widthMeasureSpec
 *            Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec
 *            Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);

    Log.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                // textsize percent support
                if (view instanceof TextView) {
                    PercentLayoutInfo.PercentVal textSizePercent = info.textSizePercent;
                    if (textSizePercent != null) {
                        int base = textSizePercent.isBaseWidth ? widthHint : heightHint;
                        float textSize = (int) (base * textSizePercent.percent);
                        ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                    }
                }
                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }
}

From source file:com.example.percentlayout.view.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one calculated from percentage
 * values.//  w w  w  .j  ava 2s  .c o  m
 *
 * @param widthMeasureSpec  Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);

    Log.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                supportTextSize(widthHint, heightHint, view, info);
                supportMinOrMaxDimesion(widthHint, heightHint, view, info);

                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }

}

From source file:nl.hardijzer.bitonsync.client.NetworkUtilities.java

/**
 * Connects to the Voiper server, authenticates the provided username and
 * password.//  w  ww  .  ja v a  2s .  c o  m
 * 
 * @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 boolean The boolean result indicating whether the user was
 *         successfully authenticated.
 */
public static boolean authenticate(String username, String password, Handler handler, final Context context) {
    final HttpResponse resp;

    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, password));
    params.add(new BasicNameValuePair(PARAM_METHOD, AUTH_METHOD));
    //params.add(new BasicNameValuePair("op","Inloggen"));
    HttpEntity entity = null;
    try {
        entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
        // this should never happen.
        throw new AssertionError(e);
    }
    final HttpPost post = new HttpPost(SYNC_URI);
    post.addHeader(entity.getContentType());
    post.setEntity(entity);
    maybeCreateHttpClient();

    try {
        resp = mHttpClient.execute(post);
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Successful authentication");
            }
            String strResponse = EntityUtils.toString(resp.getEntity());
            boolean loggedin = strResponse.startsWith("OK ");
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, loggedin ? "Auth: true" : "Auth: false");
            }
            sendResult(loggedin, handler, context);
            return loggedin;
        } else {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "Error authenticating" + resp.getStatusLine());
            }
            sendResult(false, handler, context);
            return false;
        }
    } catch (final IOException e) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "IOException when getting authtoken", e);
        }
        sendResult(false, handler, context);
        return false;
    } finally {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "getAuthtoken completing");
        }
    }
}

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

private void subscribeToAllChannels() {
    try {//  w w w  . j av  a  2s. c  om
        for (String channelName : channels.keySet()) {
            sendSubscribeMessage(channels.get(channelName));
        }
    } catch (Exception e) {
        if (Log.isLoggable(TAG, DEBUG))
            Log.d(TAG, "Exception sending subscribe message", e);
    }
}

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

@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.close();//from   w ww  .  jav  a  2  s .  c  o  m

    for (DataEvent dataEvent : events) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED
                && dataEvent.getDataItem().getUri().getPath().equals(Constants.IMAGE_PATH)) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(dataEvent.getDataItem());
            Asset image = dataMapItem.getDataMap().getAsset("image");
            Bitmap bitmap = loadBitMapFromAsset(image);
            buildWearableOnlyNotification("Image", "You took a photo!", Constants.BOTH_ID, false, bitmap);
        } else if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
            String content = dataMap.getString(Constants.KEY_CONTENT);
            String title = dataMap.getString(Constants.KEY_TITLE);
            if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, Constants.WATCH_ONLY_ID, false, null);
            } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, Constants.BOTH_ID, true, null);
            }
        } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
            }
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(Constants.BOTH_ID);
            }
        }
    }
}

From source file:mobi.jzcx.android.core.percent.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one
 * calculated from percentage values./*  w ww.jav  a 2 s  .  c o m*/
 * 
 * @param widthMeasureSpec
 *            Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec
 *            Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }
    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);
    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "widthHint = " + widthHint + " , heightHint = " + heightHint);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                supportTextSize(widthHint, heightHint, view, info);
                supportMinOrMaxDimesion(widthHint, heightHint, view, info);

                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }

}

From source file:com.hitomi.basic.view.percentlayout.PercentLayoutHelper.java

/**
 * Constructs a PercentLayoutInfo from attributes associated with a View. Call this method from
 * {@code LayoutParams(Context c, AttributeSet attrs)} constructor.
 *//* ww  w.ja v  a  2 s . c o m*/
public static PercentLayoutInfo getPercentLayoutInfo(Context context, AttributeSet attrs) {
    PercentLayoutInfo info = null;
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PercentLayout_Layout);

    info = setWidthAndHeightVal(array, info);
    info = setMarginRelatedVal(array, info);
    info = setPaddingRelatedVal(array, info);
    info = setMinMaxWidthHeightRelatedVal(array, info);
    info = setTextSizeSupportVal(array, info);
    array.recycle();

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

From source file:com.joptimizer.optimizers.BarrierMethod.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 ww.  ja va 2s .  c  o  m
    //      }

    DoubleMatrix1D X0 = getInitialPoint();
    if (X0 == null) {
        DoubleMatrix1D X0NF = getNotFeasibleInitialPoint();
        if (X0NF != null) {
            double rPriX0NFNorm = Math.sqrt(ALG.norm2(rPri(X0NF)));
            if (rPriX0NFNorm <= getToleranceFeas()
                    && !Double.isNaN(this.barrierFunction.value(X0NF.toArray()))) {
                Log.d(MainActivity.JOPTIMIZER_LOGTAG, "the provided initial point is already feasible");
                X0 = X0NF;
            }
            //            DoubleMatrix1D fiX0NF = getFi(X0NF);
            //            int maxIndex = Utils.getMaxIndex(fiX0NF);
            //            double maxValue = fiX0NF.get(maxIndex);
            //            if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            //               Log.d(MainActivity.JOPTIMIZER_LOGTAG,"X0NF  :  " + ArrayUtils.toString(X0NF.toArray()));
            //               Log.d(MainActivity.JOPTIMIZER_LOGTAG,"fiX0NF:  " + ArrayUtils.toString(fiX0NF.toArray()));
            //            }
            //            if(maxValue<0){
            //               //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) {
            BasicPhaseIBM bf1 = new BasicPhaseIBM(this);
            X0 = F1.make(bf1.findFeasibleInitialPoint());
        }
    }

    //check X0 feasibility
    double rPriX0Norm = Math.sqrt(ALG.norm2(rPri(X0)));
    if (Double.isNaN(this.barrierFunction.value(X0.toArray())) || rPriX0Norm > getToleranceFeas()) {
        throw new Exception("initial point must be strictly feasible");
    }
    //      DoubleMatrix1D fiX0 = getFi(X0);
    //      if(fiX0!=null){
    //         int maxIndex = Utils.getMaxIndex(fiX0);
    //         double maxValue = fiX0.get(maxIndex);
    //         if(maxValue >= 0){
    //            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);

    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()));
    }

    DoubleMatrix1D X = X0;
    final int dim = X.size();
    double t = 1d;
    int outerIteration = 0;
    while (true) {
        outerIteration++;
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "outerIteration: " + outerIteration);
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X=" + ArrayUtils.toString(X.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "f(X)=" + getF0(X));
        }

        //Stopping criterion: quit if gap < tolerance.
        double gap = this.barrierFunction.getDualityGap(t);
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "gap: " + gap);
        if (gap <= getTolerance()) {
            break;
        }

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

        //Centering step: compute x*(t) by minimizing tf0 + phi (the barrier function), subject to Ax = b, starting at x.
        final double tIter = t;
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "t: " + tIter);
        ConvexMultivariateRealFunction newObjectiveFunction = new ConvexMultivariateRealFunction() {

            public double value(double[] X) {
                DoubleMatrix1D x = F1.make(X);
                double phi = barrierFunction.value(X);
                return tIter * getF0(x) + phi;
            }

            public double[] gradient(double[] X) {
                DoubleMatrix1D x = F1.make(X);
                DoubleMatrix1D phiGrad = F1.make(barrierFunction.gradient(X));
                return getGradF0(x).assign(Mult.mult(tIter)).assign(phiGrad, Functions.plus).toArray();
            }

            public double[][] hessian(double[] X) {
                DoubleMatrix1D x = F1.make(X);
                DoubleMatrix2D hessF0X = getHessF0(x);
                double[][] hessX = barrierFunction.hessian(X);
                if (hessX == FunctionsUtils.ZEROES_2D_ARRAY_PLACEHOLDER) {
                    return hessF0X.assign(Mult.mult(tIter)).toArray();
                } else {
                    DoubleMatrix2D phiHess = F2.make(hessX);
                    return hessF0X.assign(Mult.mult(tIter)).assign(phiHess, Functions.plus).toArray();
                }
            }

            public int getDim() {
                return dim;
            }
        };

        //NB: cannot use the same request object for the inner step
        OptimizationRequest or = new OptimizationRequest();
        or.setA((getA() != null) ? getA().toArray() : null);
        or.setAlpha(getAlpha());
        or.setB((getB() != null) ? getB().toArray() : null);
        or.setBeta(getBeta());
        or.setCheckKKTSolutionAccuracy(isCheckKKTSolutionAccuracy());
        or.setCheckProgressConditions(isCheckProgressConditions());
        or.setF0(newObjectiveFunction);
        or.setInitialPoint(X.toArray());
        or.setMaxIteration(getMaxIteration());
        or.setMu(getMu());
        or.setTolerance(getToleranceInnerStep());
        or.setToleranceKKT(getToleranceKKT());

        BarrierNewtonLEConstrainedFSP opt = new BarrierNewtonLEConstrainedFSP(true, this);
        opt.setOptimizationRequest(or);
        if (opt.optimize() == OptimizationResponse.FAILED) {
            response.setReturnCode(OptimizationResponse.FAILED);
            break;
        }
        OptimizationResponse newtonResponse = opt.getOptimizationResponse();

        //Update. x := x*(t).
        X = F1.make(newtonResponse.getSolution());

        //         //Stopping criterion: quit if gap < tolerance.
        //         double gap = this.barrierFunction.getDualityGap(t);
        //         Log.d(MainActivity.JOPTIMIZER_LOGTAG,"gap: "+gap);
        //         if(gap <= getTolerance()){
        //            break;
        //         }
        //         
        //         // custom exit condition
        //         if(checkCustomExitConditions(X)){
        //            response.setReturnCode(OptimizationResponse.SUCCESS);
        //            break;
        //         }

        //Increase t: t := mu*t.
        t = getMu() * t;

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

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

From source file:com.infine.android.devoxx.ui.SessionsFragment.java

/** {@inheritDoc} */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null) {
        return;/*from w w  w .j ava 2  s. com*/
    }

    if (token == SessionsQuery._TOKEN || token == SearchQuery._TOKEN) {
        onSessionOrSearchQueryComplete(cursor);
    } else if (token == TracksQuery._TOKEN) {
        onTrackQueryComplete(cursor);
    } else {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d("SessionsFragment/onQueryComplete", "Query complete, Not Actionable: " + token);
        }
        cursor.close();
    }
}