Example usage for android.util Log DEBUG

List of usage examples for android.util Log DEBUG

Introduction

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

Prototype

int DEBUG

To view the source code for android.util Log DEBUG.

Click Source Link

Document

Priority constant for the println method; use Log.d.

Usage

From source file:com.example.jumpnote.android.SyncAdapter.java

@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        final ContentProviderClient provider, final SyncResult syncResult) {
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    String clientDeviceId = tm.getDeviceId();

    final long newSyncTime = System.currentTimeMillis();

    final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
    final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
    final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false);

    C2DMReceiver.refreshAppC2DMRegistrationState(mContext);

    Log.i(TAG, "Beginning " + (uploadOnly ? "upload-only" : "full") + " sync for account " + account.name);

    // Read this account's sync metadata
    final SharedPreferences syncMeta = mContext.getSharedPreferences("sync:" + account.name, 0);
    long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0);
    long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0);

    // Check for changes in either app-wide auto sync registration information, or changes in
    // the user's preferences for auto sync on this account; if either changes, piggy back the
    // new registration information in this sync.
    long lastRegistrationChangeTime = C2DMessaging.getLastRegistrationChange(mContext);

    boolean autoSyncDesired = ContentResolver.getMasterSyncAutomatically()
            && ContentResolver.getSyncAutomatically(account, JumpNoteContract.AUTHORITY);
    boolean autoSyncEnabled = syncMeta.getBoolean(DM_REGISTERED, false);

    // Will be 0 for no change, -1 for unregister, 1 for register.
    final int deviceRegChange;
    JsonRpcClient.Call deviceRegCall = null;
    if (autoSyncDesired != autoSyncEnabled || lastRegistrationChangeTime > lastSyncTime || initialize
            || manualSync) {//w w  w  .j av a 2  s.com

        String registrationId = C2DMessaging.getRegistrationId(mContext);
        deviceRegChange = (autoSyncDesired && registrationId != null) ? 1 : -1;

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG,
                    "Auto sync selection or registration information has changed, "
                            + (deviceRegChange == 1 ? "registering" : "unregistering")
                            + " messaging for this device, for account " + account.name);
        }

        try {
            if (deviceRegChange == 1) {
                // Register device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesRegister.METHOD);
                JSONObject params = new JSONObject();

                DeviceRegistration device = new DeviceRegistration(clientDeviceId, DEVICE_TYPE, registrationId);
                params.put(JumpNoteProtocol.DevicesRegister.ARG_DEVICE, device.toJSON());
                deviceRegCall.setParams(params);
            } else {
                // Unregister device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(JumpNoteProtocol.DevicesUnregister.METHOD);
                JSONObject params = new JSONObject();
                params.put(JumpNoteProtocol.DevicesUnregister.ARG_DEVICE_ID, clientDeviceId);
                deviceRegCall.setParams(params);
            }
        } catch (JSONException e) {
            logErrorMessage("Error generating device registration remote RPC parameters.", manualSync);
            e.printStackTrace();
            return;
        }
    } else {
        deviceRegChange = 0;
    }

    // Get the list of locally changed notes. If this is an upload-only sync and there were
    // no local changes, cancel the sync.
    List<ModelJava.Note> locallyChangedNotes = null;
    try {
        locallyChangedNotes = getLocallyChangedNotes(provider, account, new Date(lastSyncTime));
    } catch (RemoteException e) {
        logErrorMessage("Remote exception accessing content provider: " + e.getMessage(), manualSync);
        e.printStackTrace();
        syncResult.stats.numIoExceptions++;
        return;
    }

    if (uploadOnly && locallyChangedNotes.isEmpty() && deviceRegCall == null) {
        Log.i(TAG, "No local changes; upload-only sync canceled.");
        return;
    }

    // Set up the RPC sync calls
    final AuthenticatedJsonRpcJavaClient jsonRpcClient = new AuthenticatedJsonRpcJavaClient(mContext,
            Config.SERVER_AUTH_URL_TEMPLATE, Config.SERVER_RPC_URL);
    try {
        jsonRpcClient.blockingAuthenticateAccount(account,
                manualSync ? AuthenticatedJsonRpcJavaClient.NEED_AUTH_INTENT
                        : AuthenticatedJsonRpcJavaClient.NEED_AUTH_NOTIFICATION,
                false);
    } catch (AuthenticationException e) {
        logErrorMessage("Authentication exception when attempting to sync.", manualSync);
        e.printStackTrace();
        syncResult.stats.numAuthExceptions++;
        return;
    } catch (OperationCanceledException e) {
        Log.i(TAG, "Sync for account " + account.name + " manually canceled.");
        return;
    } catch (RequestedUserAuthenticationException e) {
        syncResult.stats.numAuthExceptions++;
        return;
    } catch (InvalidAuthTokenException e) {
        logErrorMessage("Invalid auth token provided by AccountManager when attempting to " + "sync.",
                manualSync);
        e.printStackTrace();
        syncResult.stats.numAuthExceptions++;
        return;
    }

    // Set up the notes sync call.
    JsonRpcClient.Call notesSyncCall = new JsonRpcClient.Call(JumpNoteProtocol.NotesSync.METHOD);
    try {
        JSONObject params = new JSONObject();
        params.put(JumpNoteProtocol.ARG_CLIENT_DEVICE_ID, clientDeviceId);
        params.put(JumpNoteProtocol.NotesSync.ARG_SINCE_DATE,
                Util.formatDateISO8601(new Date(lastServerSyncTime)));

        JSONArray locallyChangedNotesJson = new JSONArray();
        for (ModelJava.Note locallyChangedNote : locallyChangedNotes) {
            locallyChangedNotesJson.put(locallyChangedNote.toJSON());
        }

        params.put(JumpNoteProtocol.NotesSync.ARG_LOCAL_NOTES, locallyChangedNotesJson);
        notesSyncCall.setParams(params);
    } catch (JSONException e) {
        logErrorMessage("Error generating sync remote RPC parameters.", manualSync);
        e.printStackTrace();
        syncResult.stats.numParseExceptions++;
        return;
    }

    List<JsonRpcClient.Call> jsonRpcCalls = new ArrayList<JsonRpcClient.Call>();
    jsonRpcCalls.add(notesSyncCall);
    if (deviceRegChange != 0)
        jsonRpcCalls.add(deviceRegCall);

    jsonRpcClient.callBatch(jsonRpcCalls, new JsonRpcClient.BatchCallback() {
        public void onData(Object[] data) {
            if (data[0] != null) {
                // Read notes sync data.
                JSONObject dataJson = (JSONObject) data[0];
                try {
                    List<ModelJava.Note> changedNotes = new ArrayList<ModelJava.Note>();
                    JSONArray notesJson = dataJson.getJSONArray(JumpNoteProtocol.NotesSync.RET_NOTES);
                    for (int i = 0; i < notesJson.length(); i++) {
                        changedNotes.add(new ModelJava.Note(notesJson.getJSONObject(i)));
                    }

                    reconcileSyncedNotes(provider, account, changedNotes, syncResult.stats);

                    // If sync is successful (no exceptions thrown), update sync metadata
                    long newServerSyncTime = Util
                            .parseDateISO8601(dataJson.getString(JumpNoteProtocol.NotesSync.RET_NEW_SINCE_DATE))
                            .getTime();
                    syncMeta.edit().putLong(LAST_SYNC, newSyncTime).commit();
                    syncMeta.edit().putLong(SERVER_LAST_SYNC, newServerSyncTime).commit();
                    Log.i(TAG, "Sync complete, setting last sync time to " + Long.toString(newSyncTime));
                } catch (JSONException e) {
                    logErrorMessage("Error parsing note sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (ParseException e) {
                    logErrorMessage("Error parsing note sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (RemoteException e) {
                    logErrorMessage("RemoteException in reconcileSyncedNotes: " + e.getMessage(), manualSync);
                    e.printStackTrace();
                    return;
                } catch (OperationApplicationException e) {
                    logErrorMessage("Could not apply batch operations to content provider: " + e.getMessage(),
                            manualSync);
                    e.printStackTrace();
                    return;
                } finally {
                    provider.release();
                }
            }

            // Read device reg data.
            if (deviceRegChange != 0) {
                // data[1] will be null in case of an error (successful unregisters
                // will have an empty JSONObject, not null).
                boolean registered = (data[1] != null && deviceRegChange == 1);
                syncMeta.edit().putBoolean(DM_REGISTERED, registered).commit();
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Stored account auto sync registration state: " + Boolean.toString(registered));
                }
            }
        }

        public void onError(int callIndex, JsonRpcException e) {
            if (e.getHttpCode() == 403) {
                Log.w(TAG, "Got a 403 response, invalidating App Engine ACSID token");
                jsonRpcClient.invalidateAccountAcsidToken(account);
            }

            provider.release();
            logErrorMessage("Error calling remote note sync RPC", manualSync);
            e.printStackTrace();
        }
    });
}

From source file:de.madvertise.android.sdk.MadView.java

private void showTextBannerView() {
    MadUtil.logMessage(null, Log.DEBUG, "Add text banner");
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(currentAd.getText());
    textView.setTextSize(textSize);/*  w  w  w  . ja  v a  2s  .  c  om*/
    textView.setTextColor(textColor);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    setBackgroundDrawable(textBannerBackground);

    removeAllViews();
    addView(textView);
}

From source file:com.samsung.android.remindme.SyncAdapter.java

@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        final ContentProviderClient provider, final SyncResult syncResult) {
    Log.i(TAG, "onPerformSync called!");
    TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    String clientDeviceId = tm.getDeviceId();

    final long newSyncTime = System.currentTimeMillis();

    final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false);
    final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
    final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false);

    C2DMReceiver.refreshAppC2DMRegistrationState(mContext);

    Log.i(TAG, "Beginning " + (uploadOnly ? "upload-only" : "full") + " sync for account " + account.name);

    // Read this account's sync metadata
    final SharedPreferences syncMeta = mContext.getSharedPreferences("sync:" + account.name, 0);
    long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0);
    long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0);

    // Check for changes in either app-wide auto sync registration information, or changes in
    // the user's preferences for auto sync on this account; if either changes, piggy back the
    // new registration information in this sync.
    long lastRegistrationChangeTime = C2DMessaging.getLastRegistrationChange(mContext);

    boolean autoSyncDesired = ContentResolver.getMasterSyncAutomatically()
            && ContentResolver.getSyncAutomatically(account, RemindMeContract.AUTHORITY);
    boolean autoSyncEnabled = syncMeta.getBoolean(DM_REGISTERED, false);

    // Will be 0 for no change, -1 for unregister, 1 for register.
    final int deviceRegChange;
    JsonRpcClient.Call deviceRegCall = null;
    if (autoSyncDesired != autoSyncEnabled || lastRegistrationChangeTime > lastSyncTime || initialize
            || manualSync) {/*w  w  w  . j a v  a2s.  c om*/

        String registrationId = C2DMessaging.getRegistrationId(mContext);
        deviceRegChange = (autoSyncDesired && registrationId != null) ? 1 : -1;

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG,
                    "Auto sync selection or registration information has changed, "
                            + (deviceRegChange == 1 ? "registering" : "unregistering")
                            + " messaging for this device, for account " + account.name);
        }

        try {
            if (deviceRegChange == 1) {
                // Register device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(RemindMeProtocol.DevicesRegister.METHOD);
                JSONObject params = new JSONObject();

                DeviceRegistration device = new DeviceRegistration(clientDeviceId, DEVICE_TYPE, registrationId);
                params.put(RemindMeProtocol.DevicesRegister.ARG_DEVICE, device.toJSON());
                deviceRegCall.setParams(params);
            } else {
                // Unregister device for auto sync on this account.
                deviceRegCall = new JsonRpcClient.Call(RemindMeProtocol.DevicesUnregister.METHOD);
                JSONObject params = new JSONObject();
                params.put(RemindMeProtocol.DevicesUnregister.ARG_DEVICE_ID, clientDeviceId);
                deviceRegCall.setParams(params);
            }
        } catch (JSONException e) {
            logErrorMessage("Error generating device registration remote RPC parameters.", manualSync);
            e.printStackTrace();
            return;
        }
    } else {
        deviceRegChange = 0;
    }

    // Get the list of locally changed alerts. If this is an upload-only sync and there were
    // no local changes, cancel the sync.
    List<ModelJava.Alert> locallyChangedAlerts = null;
    try {
        locallyChangedAlerts = getLocallyChangedAlerts(provider, account, new Date(lastSyncTime));
    } catch (RemoteException e) {
        logErrorMessage("Remote exception accessing content provider: " + e.getMessage(), manualSync);
        e.printStackTrace();
        syncResult.stats.numIoExceptions++;
        return;
    }

    if (uploadOnly && locallyChangedAlerts.isEmpty() && deviceRegCall == null) {
        Log.i(TAG, "No local changes; upload-only sync canceled.");
        return;
    }

    // Set up the RPC sync calls
    final AuthenticatedJsonRpcJavaClient jsonRpcClient = new AuthenticatedJsonRpcJavaClient(mContext,
            Config.SERVER_AUTH_URL_TEMPLATE, Config.SERVER_RPC_URL);
    try {
        jsonRpcClient.blockingAuthenticateAccount(account,
                manualSync ? AuthenticatedJsonRpcJavaClient.NEED_AUTH_INTENT
                        : AuthenticatedJsonRpcJavaClient.NEED_AUTH_NOTIFICATION,
                false);
    } catch (AuthenticationException e) {
        logErrorMessage("Authentication exception when attempting to sync. root cause: " + e.getMessage(),
                manualSync);
        e.printStackTrace();

        syncResult.stats.numAuthExceptions++;
        return;
    } catch (OperationCanceledException e) {
        Log.i(TAG, "Sync for account " + account.name + " manually canceled.");
        return;
    } catch (RequestedUserAuthenticationException e) {
        syncResult.stats.numAuthExceptions++;
        return;
    } catch (InvalidAuthTokenException e) {
        logErrorMessage("Invalid auth token provided by AccountManager when attempting to " + "sync.",
                manualSync);
        e.printStackTrace();
        syncResult.stats.numAuthExceptions++;
        return;
    }

    // Set up the alerts sync call.
    JsonRpcClient.Call alertsSyncCall = new JsonRpcClient.Call(RemindMeProtocol.AlertsSync.METHOD);
    try {
        JSONObject params = new JSONObject();
        params.put(RemindMeProtocol.ARG_CLIENT_DEVICE_ID, clientDeviceId);
        params.put(RemindMeProtocol.AlertsSync.ARG_SINCE_DATE,
                Util.formatDateISO8601(new Date(lastServerSyncTime)));

        JSONArray locallyChangedAlertsJson = new JSONArray();
        for (ModelJava.Alert locallyChangedAlert : locallyChangedAlerts) {
            locallyChangedAlertsJson.put(locallyChangedAlert.toJSON());
        }

        params.put(RemindMeProtocol.AlertsSync.ARG_LOCAL_NOTES, locallyChangedAlertsJson);
        alertsSyncCall.setParams(params);
    } catch (JSONException e) {
        logErrorMessage("Error generating sync remote RPC parameters.", manualSync);
        e.printStackTrace();
        syncResult.stats.numParseExceptions++;
        return;
    }

    List<JsonRpcClient.Call> jsonRpcCalls = new ArrayList<JsonRpcClient.Call>();
    jsonRpcCalls.add(alertsSyncCall);
    if (deviceRegChange != 0)
        jsonRpcCalls.add(deviceRegCall);

    jsonRpcClient.callBatch(jsonRpcCalls, new JsonRpcClient.BatchCallback() {
        public void onData(Object[] data) {
            if (data[0] != null) {
                // Read alerts sync data.
                JSONObject dataJson = (JSONObject) data[0];
                try {
                    List<ModelJava.Alert> changedAlerts = new ArrayList<ModelJava.Alert>();
                    JSONArray alertsJson = dataJson.getJSONArray(RemindMeProtocol.AlertsSync.RET_NOTES);
                    for (int i = 0; i < alertsJson.length(); i++) {
                        changedAlerts.add(new ModelJava.Alert(alertsJson.getJSONObject(i)));
                    }

                    reconcileSyncedAlerts(provider, account, changedAlerts, syncResult.stats);

                    // If sync is successful (no exceptions thrown), update sync metadata
                    long newServerSyncTime = Util
                            .parseDateISO8601(
                                    dataJson.getString(RemindMeProtocol.AlertsSync.RET_NEW_SINCE_DATE))
                            .getTime();
                    syncMeta.edit().putLong(LAST_SYNC, newSyncTime).commit();
                    syncMeta.edit().putLong(SERVER_LAST_SYNC, newServerSyncTime).commit();
                    Log.i(TAG, "Sync complete, setting last sync time to " + Long.toString(newSyncTime));
                } catch (JSONException e) {
                    logErrorMessage("Error parsing alert sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (ParseException e) {
                    logErrorMessage("Error parsing alert sync RPC response", manualSync);
                    e.printStackTrace();
                    syncResult.stats.numParseExceptions++;
                    return;
                } catch (RemoteException e) {
                    logErrorMessage("RemoteException in reconcileSyncedAlerts: " + e.getMessage(), manualSync);
                    e.printStackTrace();
                    return;
                } catch (OperationApplicationException e) {
                    logErrorMessage("Could not apply batch operations to content provider: " + e.getMessage(),
                            manualSync);
                    e.printStackTrace();
                    return;
                } finally {
                    provider.release();
                }
            }

            // Read device reg data.
            if (deviceRegChange != 0) {
                // data[1] will be null in case of an error (successful unregisters
                // will have an empty JSONObject, not null).
                boolean registered = (data[1] != null && deviceRegChange == 1);
                syncMeta.edit().putBoolean(DM_REGISTERED, registered).commit();
                if (Log.isLoggable(TAG, Log.DEBUG)) {
                    Log.d(TAG, "Stored account auto sync registration state: " + Boolean.toString(registered));
                }
            }
        }

        public void onError(int callIndex, JsonRpcException e) {
            if (e.getHttpCode() == 403) {
                Log.w(TAG, "Got a 403 response, invalidating App Engine ACSID token");
                jsonRpcClient.invalidateAccountAcsidToken(account);
            }

            provider.release();
            logErrorMessage("Error calling remote alert sync RPC", manualSync);
            e.printStackTrace();
        }
    });
}

From source file:de.madvertise.android.sdk.Ad.java

/**
 * Handles the click action (opens the click url)
 */// w  w w  . jav a  2 s  .  c  o m
protected void handleClick() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(clickURL));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {
        context.startActivity(intent);
    } catch (Exception e) {
        MadUtil.logMessage(null, Log.DEBUG, "Failed to open URL : " + clickURL);
        e.printStackTrace();
    }
}

From source file:com.android.contacts.DynamicShortcuts.java

@VisibleForTesting
void refresh() {/*  w w w . j  ava  2s . co m*/
    // Guard here in addition to initialize because this could be run by the JobScheduler
    // after permissions are revoked (maybe)
    if (!hasRequiredPermissions())
        return;

    final List<ShortcutInfo> shortcuts = getStrequentShortcuts();
    mShortcutManager.setDynamicShortcuts(shortcuts);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "set dynamic shortcuts " + shortcuts);
    }
    updatePinned();
}

From source file:org.kotemaru.android.sample.webview.XMLHttpRequestXS.java

private void doRequest(String body) throws Throwable {
    try {/*  w  ww .  j a  v a 2 s  .  co  m*/
        if (POST.equals(_request.getMethod())) {
            HttpPost httpPost = (HttpPost) _request;
            Header header = httpPost.getFirstHeader(CONTENT_TYPE);
            String ctype = header != null ? header.getValue() : "plain/text; charset=" + HTTP.UTF_8;
            httpPost.setEntity(new StringEntity(body, ctype));
        }
        _response = _client.execute(_request);
        _responseCode = _response.getStatusLine().getStatusCode();

        CookieManager cookieManager = CookieManager.getInstance();
        Header[] cookies = _response.getHeaders("Set-Cookie");
        for (int i = 0; i < cookies.length; i++) {
            cookieManager.setCookie(_request.getURI().toString(), cookies[i].getValue());
        }

        if (Log.isLoggable(TAG, Log.DEBUG))
            debugLog();
    } catch (Throwable t) {
        Log.e(TAG, t.getMessage(), t);
        _request.abort();
        throw t;
    }
}

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.
 *//*w  w w.ja  v  a 2s  .c o  m*/
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.samsung.multiwindow.MultiWindow.java

/**
 * Executes the request and returns PluginResult.
 * //w w  w.  j  av a2s  . c  om
 * @param action
 *            The action to be executed.
 * @param args
 *            JSONArray of arguments for the plugin.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    int ret = -1;

    try {
        // window type argument index is same in all cases of
        // createmultiwindow
        windowType = args.getString(mainFsOptions.WINDOW_TYPE.ordinal());

        // Do not allow apis if metadata is missing
        if (!pluginMetadata) {
            callbackContext.error("METADATA_MISSING");
            Log.e("MultiWindow", "Metadata is missing");
            return false;
        }

        // Verify the multiwindow capability of the device
        ret = intializeMultiwindow();
        if (ret != INIT_SUCCESS) {

            switch (ret) {

            case SsdkUnsupportedException.VENDOR_NOT_SUPPORTED:
                callbackContext.error("VENDOR_NOT_SUPPORTED");
                break;
            case SsdkUnsupportedException.DEVICE_NOT_SUPPORTED:
                callbackContext.error("DEVICE_NOT_SUPPORTED");
                break;
            default:
                callbackContext.error("MUTLI_WINDOW_INITIALIZATION_FAILED");
                break;
            }

            return false;
        }

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Multiwindow initialization is successful" + ret);
        }

        // Check window support
        windowSupport = isMultiWindowSupported(windowType);
        if (windowType.equalsIgnoreCase("freestyle")) {

            if (!windowSupport) {
                callbackContext.error("FREE_STYLE_NOT_SUPPORTED");
            }

        } else if (windowType.equalsIgnoreCase("splitstyle")) {

            if (!windowSupport) {
                callbackContext.error("SPLIT_STYLE_NOT_SUPPORTED");
            }
        } else {

            callbackContext.error("INVALID_WINDOW_TYPE");
        }

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "MultiWindow window type Supported:" + windowSupport);
        }

        // Get zone info in case of split style
        if (windowSupport && (action.equals("action_main") || action.equals("action_view"))) {

            if (windowType.equalsIgnoreCase("splitstyle")) {

                switch (args.optInt(mainSsOptions.ZONE_INFO.ordinal())) {
                case ZONE_A:
                    Log.d(TAG, "Zone A selected");
                    zoneInfo = SMultiWindowActivity.ZONE_A;
                    break;
                case ZONE_B:
                    Log.d(TAG, "Zone B selected");
                    zoneInfo = SMultiWindowActivity.ZONE_B;
                    break;
                case ZONE_FULL:
                    Log.d(TAG, "Zone Full selected");
                    zoneInfo = SMultiWindowActivity.ZONE_FULL;
                    break;
                default:
                    Log.d(TAG, "Zone is not selected");
                    callbackContext.error("INVALID_ZONEINFO");
                    return false;
                }
            }
        }
    } catch (Exception e) {

        callbackContext.error(e.getMessage());
    }

    if (action.equals("action_main")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_main");
        }
        if (!windowSupport) {
            return false;
        }

        cordova.getThreadPool().execute(new Runnable() {

            public void run() {

                Intent intent = new Intent(Intent.ACTION_MAIN);
                int packageNameIndex = 0;
                int activityNameIndex = 0;
                float scaleInfo = 0;
                int zoneInfo = getZoneInfo();
                String windowType = getWindowType();

                if (windowType.equalsIgnoreCase("splitstyle")) {
                    packageNameIndex = mainSsOptions.PACKAGE_NAME.ordinal();
                    activityNameIndex = mainSsOptions.ACTIVITY_NAME.ordinal();
                } else {
                    packageNameIndex = mainFsOptions.PACKAGE_NAME.ordinal();
                    activityNameIndex = mainFsOptions.ACTIVITY_NAME.ordinal();
                }

                try {
                    intent.setComponent(new ComponentName(args.getString(packageNameIndex),
                            args.getString(activityNameIndex)));

                    if (windowType.equalsIgnoreCase("splitstyle")) {
                        SMultiWindowActivity.makeMultiWindowIntent(intent, zoneInfo);
                    } else {

                        scaleInfo = ((float) args.getDouble(mainFsOptions.SCALE_INFO.ordinal())) / 100;
                        if (scaleInfo < 0.6 || scaleInfo > 1.0) {
                            callbackContext.error("INVALID_SCALEINFO");
                            return;
                        }
                        SMultiWindowActivity.makeMultiWindowIntent(intent, scaleInfo);
                    }
                } catch (Exception e) { // May be JSONException

                    callbackContext.error(e.getMessage());
                }
                try {
                    cordova.getActivity().startActivity(intent);
                } catch (ActivityNotFoundException activityNotFound) {
                    callbackContext.error("ACTIVITY_NOT_FOUND");
                }

                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
            }
        });
        return true;

    } else if (action.equals("action_view")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_view");
        }
        if (!windowSupport) {
            return false;
        }

        cordova.getThreadPool().execute(new Runnable() {

            public void run() {

                int dataUriIndex = 0;
                float scaleInfo = 0;
                Intent dataUrl = null;
                String windowType = getWindowType();
                int zoneInfo = getZoneInfo();

                if (windowType.equalsIgnoreCase("splitstyle")) {
                    dataUriIndex = viewSsOptions.DATA_URI.ordinal();

                } else {
                    dataUriIndex = viewFsOptions.DATA_URI.ordinal();
                }
                String dataUri = null;
                try {
                    dataUri = args.getString(dataUriIndex);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                if (dataUri == null || dataUri.equals("") || dataUri.equals("null")) {
                    callbackContext.error("INVALID_DATA_URI");
                    return;
                } else {
                    boolean isUriProper = false;
                    for (String schema : URI_SCHEMA_SUPPORTED) {
                        if (dataUri.startsWith(schema)) {
                            isUriProper = true;
                            break;
                        }
                    }
                    if (!isUriProper) {
                        callbackContext.error("INVALID_DATA_URI");
                        return;
                    }
                }
                try {
                    dataUrl = new Intent(Intent.ACTION_VIEW, Uri.parse(dataUri));

                    if (windowType.equalsIgnoreCase("splitstyle")) {
                        SMultiWindowActivity.makeMultiWindowIntent(dataUrl, zoneInfo);
                    } else {
                        scaleInfo = ((float) args.getDouble(viewFsOptions.SCALE_INFO.ordinal())) / 100;
                        if (scaleInfo < 0.6 || scaleInfo > 1.0) {
                            callbackContext.error("INVALID_SCALEINFO");
                            return;
                        }
                        SMultiWindowActivity.makeMultiWindowIntent(dataUrl, scaleInfo);
                    }
                } catch (Exception e) { // May be JSONException

                    callbackContext.error(e.getMessage());
                }

                try {

                    if (dataUrl != null) {
                        cordova.getActivity().startActivity(dataUrl);
                    }

                } catch (ActivityNotFoundException activityNotFound) {
                    callbackContext.error("ACTIVITY_NOT_FOUND");
                }
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
            }
        });
        return true;

    } else if (action.equals("action_check")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_check");
        }

        if (windowSupport) {

            callbackContext.success();
        }
        return true;

    } else if (action.equals("action_getapps")) {

        if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
            Log.d(TAG, "Action is action_getapps");
        }

        if (!windowSupport) {

            return false;
        }

        getMultiWindowApps(windowType, callbackContext);
        return true;

    }

    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, 0));
    return false;
}

From source file:com.locadz.AdUnitAllocationService.java

/**
 * load the allocation configuration for the adunit from external source.
 *
 * @param adUnitContext the context of the adunit.
 * @return the allocation configuration for the adunit as a json string.
 *///from   w w w .  j  a  va2  s .  c  o m
String loadFromRemote(AdUnitContext adUnitContext) {

    Log.d(LOG_TAG, String.format("Fetching config with %s", adUnitContext));

    HttpClient httpClient = HttpClientFactory.getInstance();
    URI uri = LocadzUtils.getInfoUri(adUnitContext);
    HttpGet httpGet = new HttpGet(uri);

    String ret = null;
    try {

        HttpResponse httpResponse = httpClient.execute(httpGet);

        // if response is 1xx, 2xx or 3xx, we would return the response body
        if (httpResponse.getStatusLine().getStatusCode() < HttpStatus.SC_BAD_REQUEST) {
            Log.d(LOG_TAG, httpResponse.getStatusLine().toString());

            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                ret = EntityUtils.toString(entity);
            }
        }
    } catch (ClientProtocolException e) {
        Log.e(LOG_TAG, "Caught ClientProtocolException in loadFromRemote()", e);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Caught IOException in loadFromRemote()", e);
    }

    if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
        Log.d(LOG_TAG, String.format("Fetched Allocations is %s", ret));
    }
    return ret;
}

From source file:com.ibm.commerce.worklight.android.maps.StoreMapActivity.java

/**
 * Back button press exits the activity and returns to the store
 * @see android.support.v4.app.FragmentActivity#onBackPressed()
 *//*from  w  w w  . j  ava  2 s .co m*/
@Override
public void onBackPressed() {
    final String METHOD_NAME = CLASS_NAME + ".onBackPressed()";
    boolean loggingEnabled = Log.isLoggable(LOG_TAG, Log.DEBUG);
    if (loggingEnabled) {
        Log.d(METHOD_NAME, "ENTRY");
    }
    setResult(RESULT_OK, new Intent());
    finish();
    if (loggingEnabled) {
        Log.d(METHOD_NAME, "EXIT");
    }
}