Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

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

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:org.alfresco.mobile.android.api.session.impl.CloudSessionImpl.java

/** Start the authentication proces. */
private void authenticate(AuthenticationProvider authProvider) {
    try {/*w  ww . j av a 2 s.  c om*/
        // If no authenticationProvider start creation of
        // BasicAuthenticationProvider by default or the one provided by
        // session parameter.
        if (authProvider == null) {
            authenticator = createAuthenticationProvider((String) userParameters.get(AUTHENTICATOR_CLASSNAME));
        } else {
            authenticator = authProvider;
        }

        // Retrieve & select the Home Network or session parameters network.
        PagingResult<CloudNetwork> networks = getPagingNetworks();
        if (networks == null || networks.getTotalItems() == 0) {
            throw new AlfrescoSessionException(ErrorCodeRegistry.SESSION_NO_NETWORK_FOUND,
                    Messagesl18n.getString("SESSION_NO_NETWORK_FOUND"));
        }

        String networkIdentifier = null;
        if (hasParameter(CLOUD_NETWORK_ID)) {
            networkIdentifier = (String) getParameter(CLOUD_NETWORK_ID);
        }

        List<CloudNetwork> listNetworks = networks.getList();

        // Support GMail case where a user has a disabled homeNetwork
        // cf. MOBSDK-506.
        // In this case it's the latest enabled network which is going to be
        // available as default Network for the session.
        for (CloudNetwork cloudNetwork : listNetworks) {
            if (cloudNetwork.isHomeNetwork() && ((CloudNetworkImpl) cloudNetwork).isEnabled()
                    && networkIdentifier == null) {
                currentNetwork = cloudNetwork;
                break;
            } else if (networkIdentifier != null && networkIdentifier.equals(cloudNetwork.getIdentifier())) {
                currentNetwork = cloudNetwork;
                break;
            } else if (!cloudNetwork.isHomeNetwork() && ((CloudNetworkImpl) cloudNetwork).isEnabled()) {
                currentNetwork = cloudNetwork;
            }
        }

        if (currentNetwork == null) {
            throw new AlfrescoSessionException(ErrorCodeRegistry.SESSION_NO_NETWORK_FOUND,
                    Messagesl18n.getString("SESSION_NO_NETWORK_FOUND"));
        }

        // Create OpenCMIS Session Parameters
        addParameter(CLOUD_NETWORK_ID, currentNetwork.getIdentifier());
        Map<String, String> param = retrieveSessionParameters();

        // Create CMIS Session with selected network + parameters
        cmisSession = createSession(SessionFactoryImpl.newInstance(), authenticator, param);

        // Init Services + Object
        try {
            if (cmisSession.getRootFolder() != null) {
                rootNode = new FolderImpl(cmisSession.getRootFolder());
            }
        } catch (Exception e) {
            Log.e(TAG, "Unable to retrieve rootNode folder");
            Log.e(TAG, Log.getStackTraceString(e));
        }

        repositoryInfo = new CloudRepositoryInfoImpl(cmisSession.getRepositoryInfo());

        create();
    } catch (Exception e) {
        throw new AlfrescoSessionException(ErrorCodeRegistry.SESSION_GENERIC, e);
    }
}

From source file:eu.faircode.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//  ww w.  ja  va 2 s .c  o  m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/*from  ww  w . j av a 2s. c  om*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, MainActivity.class);
        main.putExtra(MainActivity.EXTRA_REFRESH, true);
        main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(context.getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(context.getString(R.string.msg_installed_n));
            else
                expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:com.master.metehan.filtereagle.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;/* w w  w. j  a  v  a  2s .co m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        Util.setTheme(context);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:com.zhengde163.netguard.Receiver.java

public static void notifyNewApplication(int uid, Context context) {
    if (uid < 0)
        return;//from   w  w w.j  ava2  s .  c o m

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
        // Get application info
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));

        // Get application info
        PackageManager pm = context.getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, context);

        // Build notification
        Intent main = new Intent(context, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        //            Util.setTheme(context);
        context.setTheme(R.style.AppThemeBlue);
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_security_white_24dp)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.msg_installed, name)).setContentIntent(pi)
                .setColor(tv.data).setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
        }

        // Get defaults
        SharedPreferences prefs_wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = context.getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(context, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(context, uid, riWifi,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                context.getString(wifi ? R.string.title_allow : R.string.title_block), piWifi);

        // Build mobile action
        Intent riOther = new Intent(context, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(context, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(other ? R.drawable.other_on : R.drawable.other_off,
                context.getString(other ? R.string.title_allow : R.string.title_block), piOther);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(context).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            expanded.bigText(context.getString(R.string.msg_installed, name));
            expanded.setSummaryText(context.getString(R.string.title_internet));
            NotificationManagerCompat.from(context).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

From source file:it.geosolutions.geocollect.android.core.mission.utils.SQLiteCascadeFeatureLoader.java

@Override
public List<MissionFeature> loadInBackground() {

    if (this.db == null || this.db.dbversion().equals("unknown")) {
        Log.w(TAG, "Cannot open DB");
        return null;
    }//ww w.ja  va  2s.  c o m

    if (this.sourceTableName == null || this.sourceTableName.isEmpty()) {
        Log.w(TAG, "Table Name is empty");
        return null;
    }

    // Default, reload anyway
    boolean reload = true;

    if (mPrefs != null) {
        // this must now specify a table, otherwise it blocks loading data for other tables
        long millis = mPrefs.getLong(LAST_UPDATE_PREF, 0L);
        if (millis > 0) {
            Date currentDate = new Date();
            if (currentDate.getTime() - millis < UPDATE_THRESHOLD) {
                // Disable reload when too early
                Log.v(TAG, "Data is already updated");
                reload = false;
            }
        }

    }

    if (this.pre_loader != null && reload) {

        List<Feature> fromPreLoader = this.pre_loader.loadInBackground();
        if (fromPreLoader != null) {

            // TODO: load only paginated rows

            // TODO: truncate only paginated rows
            try {
                Stmt stmt = db.prepare("DELETE FROM '" + sourceTableName + "';");
                stmt.step();
                stmt.close();
            } catch (jsqlite.Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
            }

            if (!fromPreLoader.isEmpty()) {

                // Get the list of the fields
                HashMap<String, String> dbFieldValues = SpatialiteUtils.getPropertiesFields(db,
                        sourceTableName);
                if (dbFieldValues != null) {

                    Stmt stmt;
                    String converted;

                    long startTime = System.nanoTime();

                    StringBuilder columnNames = new StringBuilder(300);
                    StringBuilder columnValues = new StringBuilder(300);

                    columnNames.append(" ( ").append(Mission.ORIGIN_ID_STRING);
                    columnValues.append(" ( ").append("'");

                    int namesToTruncate = columnNames.length();
                    int valuesToTruncate = columnValues.length();
                    long featureStartTime;
                    long queryTime;
                    long prefStartTime;
                    long stopTime;

                    StringBuilder loggerBuilder = new StringBuilder(300);

                    for (Feature f : fromPreLoader) {

                        featureStartTime = System.nanoTime();

                        columnValues.append(f.id).append("'");

                        for (Entry<String, String> e : dbFieldValues.entrySet()) {
                            //Log.v(TAG, "Got -> "+e.getKey()+" : "+e.getValue());

                            converted = SpatialiteUtils.getSQLiteTypeFromString(e.getValue());
                            if (converted.equals("point") && f.geometry != null) {

                                columnNames.append(", GEOMETRY");
                                // In JTS Point getX = longitude, getY = latitude
                                columnValues.append(", MakePoint(").append(((Point) f.geometry).getX())
                                        .append(",").append(((Point) f.geometry).getY()).append(", 4326)");

                            } else if (f.properties.containsKey(e.getKey()) && converted != null
                                    && f.properties.get(e.getKey()) != null) {

                                columnNames.append(", ").append(e.getKey());

                                if (converted.equals("text") || converted.equals("blob")
                                        || !isNumeric(String.valueOf(f.properties.get(e.getKey())))) {
                                    columnValues.append(", '")
                                            .append(SpatialiteUtils
                                                    .escape((String) f.properties.get(e.getKey())))
                                            .append("' ");
                                } else {
                                    columnValues.append(", ").append(f.properties.get(e.getKey()));
                                }

                            }

                        }

                        // add the geometry
                        columnNames.append(" )");
                        columnValues.append(" )");

                        // TODO: Use prepared statements and group all the insert queries into a transaction for insertion speedup
                        //       This will need to get the schema beforehand, based on the JSON features
                        String insertQuery = "INSERT INTO '" + sourceTableName + "' " + columnNames.toString()
                                + " VALUES " + columnValues.toString() + ";";
                        queryTime = System.nanoTime();
                        if (BuildConfig.DEBUG) {
                            loggerBuilder.append("Query created in: ")
                                    .append((queryTime - featureStartTime) / 1000000).append("ms\n");
                        }

                        columnNames.setLength(namesToTruncate);
                        columnValues.setLength(valuesToTruncate);

                        try {
                            stmt = db.prepare(insertQuery);
                            long prepareTime = System.nanoTime();
                            if (BuildConfig.DEBUG) {
                                loggerBuilder.append("Query prepared in: ")
                                        .append((prepareTime - queryTime) / 1000000).append("ms\n");
                            }

                            stmt.step();
                            stmt.close();

                            long featureStopTime = System.nanoTime();
                            if (BuildConfig.DEBUG) {
                                loggerBuilder.append("Feature inserted in: ")
                                        .append((featureStopTime - prepareTime) / 1000000).append("ms\n");
                            }

                        } catch (Exception e1) {
                            if (BuildConfig.DEBUG) {
                                Log.e(TAG, Log.getStackTraceString(e1));
                            }
                        } finally {
                            if (BuildConfig.DEBUG) {
                                Log.d(TAG, loggerBuilder.toString());
                                loggerBuilder.setLength(0);
                            }
                        }
                    }

                    prefStartTime = System.nanoTime();

                    // Update the "last update" time to prevent unnecessary downloads
                    if (mPrefs != null) {
                        SharedPreferences.Editor editor = mPrefs.edit();
                        Date currentDate = new Date();
                        editor.putLong(LAST_UPDATE_PREF, currentDate.getTime());
                        editor.commit();
                    }

                    stopTime = System.nanoTime();
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "Pref updated in: " + (stopTime - prefStartTime) / 1000000 + "ms");
                        Log.d(TAG, "Database updated in: " + (stopTime - startTime) / 1000000 + "ms");
                    }

                }
            }

            //mData = fromPreLoader;
        } else {
            // error in the loader (no connectivity)
        }
    }

    // TODO: Load data into mData
    // Get the list of the fields
    // TODO: Can this call be done before the pre_loader block? 
    // Are there any concurrent events that can modify the table schema before we read the data?
    HashMap<String, String> dbFieldValues = SpatialiteUtils.getPropertiesFields(db, sourceTableName);

    mData = new ArrayList<MissionFeature>();

    // Reader for the Geometry field
    WKBReader wkbReader = new WKBReader();

    if (dbFieldValues != null) {

        String converted;
        boolean hasGeometry = false;

        String columnNames = "SELECT ROWID "; // This is an SQLite standard column
        String filterString = "";
        String orderString = "";

        for (Entry<String, String> e : dbFieldValues.entrySet()) {
            //Log.v(TAG, "Got -> "+e.getKey()+" : "+e.getValue());

            converted = SpatialiteUtils.getSQLiteTypeFromString(e.getValue());

            if (converted != null) {

                if (converted.equals("point")) {
                    // Only Points are supported
                    columnNames = columnNames + ", ST_AsBinary(CastToXY(" + e.getKey() + ")) AS 'GEOMETRY'";
                    hasGeometry = true;
                } else {
                    columnNames = columnNames + ", " + e.getKey();
                }

            }

        }

        //Add Spatial filtering
        if (hasGeometry) {
            int filterSrid = mPrefs.getInt(FILTER_SRID, -1);
            // If the SRID is not defined, skip the filter
            if (filterSrid != -1) {
                double filterN = Double.longBitsToDouble(mPrefs.getLong(FILTER_N, Double.doubleToLongBits(0)));
                double filterS = Double.longBitsToDouble(mPrefs.getLong(FILTER_S, Double.doubleToLongBits(0)));
                double filterW = Double.longBitsToDouble(mPrefs.getLong(FILTER_W, Double.doubleToLongBits(0)));
                double filterE = Double.longBitsToDouble(mPrefs.getLong(FILTER_E, Double.doubleToLongBits(0)));

                filterString = " WHERE MbrIntersects(GEOMETRY, BuildMbr(" + filterW + ", " + filterN + ", "
                        + filterE + ", " + filterS + ")) ";
            }
            //WHERE MbrIntersects(GEOMETRY, BuildMbr(8.75269101373853, 44.505790969141614, 9.039467060007173, 44.35415617743291))
        }

        // TODO: Should the orderingField be mandatory to have the ordering?
        if (orderingField != null && !orderingField.isEmpty()) {
            boolean reverse = mPrefs.getBoolean(REVERSE_ORDER_PREF, false);
            boolean useDistance = mPrefs.getBoolean(ORDER_BY_DISTANCE, false);
            double posX = Double.longBitsToDouble(mPrefs.getLong(LOCATION_X, Double.doubleToLongBits(0)));
            double posY = Double.longBitsToDouble(mPrefs.getLong(LOCATION_Y, Double.doubleToLongBits(0)));

            if (useDistance) {
                columnNames = columnNames + ", Distance(ST_Transform(GEOMETRY,4326), MakePoint(" + posX + ","
                        + posY + ", 4326)) * 111195 AS '" + MissionFeature.DISTANCE_VALUE_ALIAS + "'";
                orderString = "ORDER BY " + MissionFeature.DISTANCE_VALUE_ALIAS;
            } else {
                orderString = "ORDER BY " + orderingField;
            }

            if (reverse) {
                orderString = orderString + " DESC";
            }
        }

        String finalQuery = columnNames + " FROM '" + sourceTableName + "' " + filterString + " " + orderString
                + ";";

        Log.v(TAG, finalQuery);
        loadMissionFeature(wkbReader, sourceTableName, finalQuery);

    }

    // Set the "Editing flag"

    if (formTableName != null && !formTableName.isEmpty()) {
        ArrayList<String> editingIds = new ArrayList<String>();
        String query = "SELECT " + Mission.ORIGIN_ID_STRING + " FROM '" + formTableName + "';";

        if (Database.complete(query)) {
            try {
                Stmt stmt = db.prepare(query);
                while (stmt.step()) {
                    editingIds.add(stmt.column_string(0));
                }
                stmt.close();
            } catch (jsqlite.Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
            }
        } else {
            if (BuildConfig.DEBUG) {
                Log.w(TAG, "Query is not complete: " + query);
            }
        }

        if (!editingIds.isEmpty()) {
            for (MissionFeature f : mData) {
                if (editingIds.contains(MissionUtils.getFeatureGCID(f))) {
                    f.editing = true;
                }
            }
        }
    }

    ///////////////////////
    // Add the NEW items
    ///////////////////////

    Log.v(TAG, "Loading created missions from " + sourceTableName + MissionTemplate.NEW_NOTICE_SUFFIX);
    final ArrayList<MissionFeature> missions = MissionUtils
            .getMissionFeatures(sourceTableName + MissionTemplate.NEW_NOTICE_SUFFIX, db, getContext());

    mData.addAll(missions);
    if (orderingField != null && !orderingField.isEmpty()) {

        boolean reverse = mPrefs.getBoolean(REVERSE_ORDER_PREF, false);
        boolean useDistance = mPrefs.getBoolean(ORDER_BY_DISTANCE, false);
        boolean preferEdited = mPrefs.getBoolean(PREFER_EDITED, false);

        Collections.sort(mData, new MissionFeatureSorter(orderingField, preferEdited, useDistance, reverse));

        if (reverse) {
            Collections.reverse(mData);
        }
    }

    ///////////////////////

    // Icon Color
    if (priorityField != null && !priorityField.isEmpty() && priorityColours != null
            && !priorityColours.isEmpty()) {

        for (MissionFeature f : mData) {
            if (f.properties.containsKey(priorityField)) {
                f.displayColor = priorityColours.get(f.properties.get(priorityField));
            }
        }

    }

    return mData;
}

From source file:org.alfresco.mobile.android.application.providers.storage.StorageAccessDocumentsProvider.java

@Override
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
    final DocumentFolderCursor rootCursor = new DocumentFolderCursor(resolveRootProjection(projection));
    final Uri uri = DocumentsContract.buildRootsUri(mAuthority);
    try {/*from   w w  w  . j a  v a 2 s .co  m*/
        for (int i = 0; i < accountsIndex.size(); i++) {
            addRootRow(rootCursor, accountsIndex.get(accountsIndex.keyAt(i)));
        }
    } catch (Exception e) {
        rootCursor.setErrorInformation("Error : " + e.getMessage());
        rootCursor.setNotificationUri(getContext().getContentResolver(), uri);
        getContext().getContentResolver().notifyChange(uri, null);
        Log.w(TAG, Log.getStackTraceString(e));
    }

    return rootCursor;
}

From source file:com.nick.scalpel.Scalpel.java

public boolean installScalpelHookService(final String jarPath, final String binPath) {
    Preconditions.checkNotNull(jarPath, "jar path is null.");
    Preconditions.checkNotNull(binPath, "bin path is null.");
    try {/*from w ww . j a  va 2  s.c om*/
        return new ScalpelServiceInstaller() {
            @Override
            protected String getBinaryPath() {
                return binPath;
            }

            @Override
            protected String getJarPath() {
                return jarPath;
            }
        }.install();
    } catch (Exception e) {
        Log.e(TAG, "Failed to install hook service:" + Log.getStackTraceString(e));
    }
    return false;
}

From source file:org.alfresco.mobile.android.application.fragments.create.DocumentPropertiesDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_NODE_CREATE_FORM);

    final String fragmentTag = (String) getArguments().get(ARGUMENT_FRAGMENT_TAG);
    final AlfrescoAccount currentAccount = (AlfrescoAccount) getArguments().get(ARGUMENT_ACCOUNT);
    final DocumentTypeRecord documentType = (DocumentTypeRecord) getArguments().get(ARGUMENT_DOCUMENT_TYPE);
    final ResolveInfo editor = (ResolveInfo) getArguments().get(ARGUMENT_EDITOR);

    File f = null;/*from www.  j ava  2s  .  c  om*/
    if (FileExplorerFragment.TAG.equals(fragmentTag)) {
        // If creation inside the download area, we store it inside
        // download.
        f = AlfrescoStorageManager.getInstance(getActivity()).getDownloadFolder(currentAccount);
    } else {
        // If creation inside a repository folder, we store temporarly
        // inside the capture.
        f = AlfrescoStorageManager.getInstance(getActivity()).getCaptureFolder(currentAccount);
    }

    final File folderStorage = f;

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.app_create_document, (ViewGroup) this.getView());

    ((TextView) v.findViewById(R.id.document_extension)).setText(documentType.extension);

    final MaterialEditText textName = ((MaterialEditText) v.findViewById(R.id.document_name));
    // This Listener is responsible to enable or not the validate button and
    // error message.
    textName.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                textName.setFloatingLabelText(getString(R.string.content_name));
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(true);
                if (UIUtils.hasInvalidName(s.toString().trim())) {
                    textName.setError(getString(R.string.filename_error_character));
                    ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                } else {
                    textName.setError(null);
                }
            } else {
                textName.setHint(R.string.create_document_name_hint);
                ((MaterialDialog) getDialog()).getActionButton(DialogAction.POSITIVE).setEnabled(false);
                textName.setError(null);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).iconRes(R.drawable.ic_application_logo)
            .title(R.string.create_document_title).customView(v, true).positiveText(R.string.create)
            .negativeText(R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onNegative(MaterialDialog dialog) {
                    dialog.dismiss();
                }

                @Override
                public void onPositive(MaterialDialog dialog) {
                    String fileName = textName.getText().toString().trim().concat(documentType.extension);

                    File newFile = new File(folderStorage, fileName);

                    if (newFile.exists() && FileExplorerFragment.TAG.equals(fragmentTag)) {
                        // If the file already exist, we prompt a warning
                        // message.
                        textName.setError(getString(R.string.create_document_filename_error));
                        return;
                    } else {
                        try {
                            // If there's a template we create the file
                            // based on
                            // this template.
                            if (documentType.templatePath != null) {
                                AssetManager assetManager = getActivity().getAssets();
                                IOUtils.copyFile(assetManager.open(documentType.templatePath), newFile);
                            } else {
                                newFile.createNewFile();
                            }
                        } catch (IOException e1) {
                            Log.e(TAG, Log.getStackTraceString(e1));
                        }
                    }

                    // We create the Intent based on informations we grab
                    // previously.
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.fromFile(newFile);
                    intent.setDataAndType(data, documentType.mimetype);
                    intent.setComponent(new ComponentName(editor.activityInfo.applicationInfo.packageName,
                            editor.activityInfo.name));

                    try {
                        Fragment fr = getFragmentManager().findFragmentByTag(fragmentTag);
                        if (fr != null && fr.isVisible()) {
                            if (fr instanceof DocumentFolderBrowserFragment) {
                                // During Creation on a specific folder.
                                ((DocumentFolderBrowserFragment) fr).setCreateFile(newFile);
                            } else if (fr instanceof FileExplorerFragment) {
                                // During Creation inside the download
                                // folder.
                                ((FileExplorerFragment) fr).setCreateFile(newFile);
                            }
                            fr.startActivity(intent);
                        }
                    } catch (ActivityNotFoundException e) {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showToast(R.string.error_unable_open_file);
                    }
                    dismiss();
                }
            }).build();

    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);

    return dialog;
}

From source file:com.dm.material.dashboard.candybar.fragments.dialog.InAppBillingFragment.java

private void loadInAppProducts() {
    mLoadInAppProducts = new AsyncTask<Void, Void, Boolean>() {

        InAppBilling[] inAppBillings;// w  w  w  .java 2s .  c  om
        boolean isBillingNotReady = false;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mProgress.setVisibility(View.VISIBLE);
            inAppBillings = new InAppBilling[mProductsId.length];
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    if (mBillingProcessor == null) {
                        isBillingNotReady = true;
                        return false;
                    }

                    for (int i = 0; i < mProductsId.length; i++) {
                        SkuDetails product = mBillingProcessor.getPurchaseListingDetails(mProductsId[i]);
                        if (product != null) {
                            InAppBilling inAppBilling;
                            String title = product.title.substring(0, product.title.lastIndexOf("("));
                            if (mProductsCount != null) {
                                inAppBilling = new InAppBilling(product.priceText, mProductsId[i], title,
                                        mProductsCount[i]);
                            } else {
                                inAppBilling = new InAppBilling(product.priceText, mProductsId[i], title);
                            }
                            inAppBillings[i] = inAppBilling;
                        } else {
                            if (i == mProductsId.length - 1)
                                return false;
                        }
                    }
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            mProgress.setVisibility(View.GONE);
            if (aBoolean) {
                mAdapter = new InAppBillingAdapter(getActivity(), inAppBillings);
                mInAppList.setAdapter(mAdapter);
            } else {
                dismiss();
                Preferences.getPreferences(getActivity()).setInAppBillingType(-1);
                if (!isBillingNotReady)
                    Toast.makeText(getActivity(), R.string.billing_load_product_failed, Toast.LENGTH_LONG)
                            .show();
            }
            mLoadInAppProducts = null;
        }

    }.execute();
}