com.activeandroid.util.Log Java Examples

The following examples show how to use com.activeandroid.util.Log. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Cache.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
public static synchronized void initialize(Configuration configuration) {
	if (sIsInitialized) {
		Log.v("ActiveAndroid already initialized.");
		return;
	}

	sContext = configuration.getContext();
	sModelInfo = new ModelInfo(configuration);
	sDatabaseHelper = new DatabaseHelper(configuration);

	// TODO: It would be nice to override sizeOf here and calculate the memory
	// actually used, however at this point it seems like the reflection
	// required would be too costly to be of any benefit. We'll just set a max
	// object size instead.
	sEntities = new LruCache<String, Model>(configuration.getCacheSize());

	openDatabase();

	sIsInitialized = true;

	Log.v("ActiveAndroid initialized successfully.");
}
 
Example #2
Source File: Configuration.java    From mobile-android-survey-app with MIT License 6 votes vote down vote up
private List<Class<? extends TypeSerializer>> loadSerializerList(String[] serializers) {
	final List<Class<? extends TypeSerializer>> typeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String serializer : serializers) {
		try {
			Class serializerClass = Class.forName(serializer.trim(), false, classLoader);
			if (ReflectionUtils.isTypeSerializer(serializerClass)) {
				typeSerializers.add(serializerClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return typeSerializers;
}
 
Example #3
Source File: Configuration.java    From mobile-android-survey-app with MIT License 6 votes vote down vote up
private List<Class<? extends Model>> loadModelList(String[] models) {
	final List<Class<? extends Model>> modelClasses = new ArrayList<Class<? extends Model>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String model : models) {
		try {
			Class modelClass = Class.forName(model.trim(), false, classLoader);
			if (ReflectionUtils.isModel(modelClass)) {
				modelClasses.add(modelClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return modelClasses;
}
 
Example #4
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
private List<Class<? extends Model>> loadModelList(String[] models) {
	final List<Class<? extends Model>> modelClasses = new ArrayList<Class<? extends Model>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String model : models) {
		try {
			Class modelClass = Class.forName(model.trim(), false, classLoader);
			if (ReflectionUtils.isModel(modelClass)) {
				modelClasses.add(modelClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return modelClasses;
}
 
Example #5
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
private List<Class<? extends TypeSerializer>> loadSerializerList(String[] serializers) {
	final List<Class<? extends TypeSerializer>> typeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String serializer : serializers) {
		try {
			Class serializerClass = Class.forName(serializer.trim(), false, classLoader);
			if (ReflectionUtils.isTypeSerializer(serializerClass)) {
				typeSerializers.add(serializerClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return typeSerializers;
}
 
Example #6
Source File: Cache.java    From mobile-android-survey-app with MIT License 6 votes vote down vote up
public static synchronized void initialize(Configuration configuration) {
	if (sIsInitialized) {
		Log.v("ActiveAndroid already initialized.");
		return;
	}

	sContext = configuration.getContext();
	sModelInfo = new ModelInfo(configuration);
	sDatabaseHelper = new DatabaseHelper(configuration);

	// TODO: It would be nice to override sizeOf here and calculate the memory
	// actually used, however at this point it seems like the reflection
	// required would be too costly to be of any benefit. We'll just set a max
	// object size instead.
	sEntities = new LruCache<String, Model>(configuration.getCacheSize());

	openDatabase();

	sIsInitialized = true;

	Log.v("ActiveAndroid initialized successfully.");
}
 
Example #7
Source File: ModelInfo.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
public ModelInfo(Configuration configuration) {
	if (!loadModelFromMetaData(configuration)) {
		try {
			scanForModel(configuration.getContext());
		}
		catch (IOException e) {
			Log.e("Couldn't open source path.", e);
		}
	}

	Log.i("ModelInfo loaded.");
}
 
Example #8
Source File: Cache.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
public static synchronized void dispose() {
	closeDatabase();

	sEntities = null;
	sModelInfo = null;
	sDatabaseHelper = null;

	sIsInitialized = false;

	Log.v("ActiveAndroid disposed. Call initialize to use library.");
}
 
Example #9
Source File: IOUtils.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
/**
 * <p>
 * Unconditionally close a {@link Closeable}.
 * </p>
 * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is
 * typically used in finally blocks.
 * @param closeable A {@link Closeable} to close.
 */
public static void closeQuietly(final Closeable closeable) {

    if (closeable == null) {
        return;
    }

    try {
        closeable.close();
    } catch (final IOException e) {
        Log.e("Couldn't close closeable.", e);
    }
}
 
Example #10
Source File: IOUtils.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
/**
 * <p>
 * Unconditionally close a {@link Cursor}.
 * </p>
 * Equivalent to {@link Cursor#close()}, except any exceptions will be ignored. This is
 * typically used in finally blocks.
 * @param cursor A {@link Cursor} to close.
 */
public static void closeQuietly(final Cursor cursor) {

    if (cursor == null) {
        return;
    }

    try {
        cursor.close();
    } catch (final Exception e) {
        Log.e("Couldn't close cursor.", e);
    }
}
 
Example #11
Source File: DatabaseHelper.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
public void copyAttachedDatabase(Context context, String databaseName) {
	final File dbPath = context.getDatabasePath(databaseName);

	// If the database already exists, return
	if (dbPath.exists()) {
		return;
	}

	// Make sure we have a path to the file
	dbPath.getParentFile().mkdirs();

	// Try to copy database file
	try {
		final InputStream inputStream = context.getAssets().open(databaseName);
		final OutputStream output = new FileOutputStream(dbPath);

		byte[] buffer = new byte[8192];
		int length;

		while ((length = inputStream.read(buffer, 0, 8192)) > 0) {
			output.write(buffer, 0, length);
		}

		output.flush();
		output.close();
		inputStream.close();
	}
	catch (IOException e) {
		Log.e("Failed to open file", e);
	}
}
 
Example #12
Source File: DatabaseHelper.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public void copyAttachedDatabase(Context context, String databaseName) {
	final File dbPath = context.getDatabasePath(databaseName);

	// If the database already exists, return
	if (dbPath.exists()) {
		return;
	}

	// Make sure we have a path to the file
	dbPath.getParentFile().mkdirs();

	// Try to copy database file
	try {
		final InputStream inputStream = context.getAssets().open(databaseName);
		final OutputStream output = new FileOutputStream(dbPath);

		byte[] buffer = new byte[8192];
		int length;

		while ((length = inputStream.read(buffer, 0, 8192)) > 0) {
			output.write(buffer, 0, length);
		}

		output.flush();
		output.close();
		inputStream.close();
	}
	catch (IOException e) {
		Log.e("Failed to open file", e);
	}
}
 
Example #13
Source File: IOUtils.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>
 * Unconditionally close a {@link Cursor}.
 * </p>
 * Equivalent to {@link Cursor#close()}, except any exceptions will be ignored. This is
 * typically used in finally blocks.
 * @param cursor A {@link Cursor} to close.
 */
public static void closeQuietly(final Cursor cursor) {

    if (cursor == null) {
        return;
    }

    try {
        cursor.close();
    } catch (final Exception e) {
        Log.e("Couldn't close cursor.", e);
    }
}
 
Example #14
Source File: IOUtils.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>
 * Unconditionally close a {@link Closeable}.
 * </p>
 * Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is
 * typically used in finally blocks.
 * @param closeable A {@link Closeable} to close.
 */
public static void closeQuietly(final Closeable closeable) {

    if (closeable == null) {
        return;
    }

    try {
        closeable.close();
    } catch (final IOException e) {
        Log.e("Couldn't close closeable.", e);
    }
}
 
Example #15
Source File: ModelInfo.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public ModelInfo(Configuration configuration) {
	if (!loadModelFromMetaData(configuration)) {
		try {
			scanForModel(configuration.getContext());
		}
		catch (IOException e) {
			Log.e("Couldn't open source path.", e);
		}
	}

	Log.i("ModelInfo loaded.");
}
 
Example #16
Source File: Cache.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized void dispose() {
	closeDatabase();

	sEntities = null;
	sModelInfo = null;
	sDatabaseHelper = null;

	sIsInitialized = false;

	Log.v("ActiveAndroid disposed. Call initialize to use library.");
}
 
Example #17
Source File: ImporterAsyncTask.java    From 10000sentences with Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(String... strings) {
    String url = strings[0];
    publishProgress(0);

    OkHttpClient httpClient = new OkHttpClient();
    Call call = httpClient.newCall(new Request.Builder().url(url).get().build());
    try {
        Response response = call.execute();

        InputStream stream = response.body().byteStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        List<Sentence> sentences = new ArrayList<>();

        int order = 0;
        String line;
        while ((line = reader.readLine()) != null) {
            order += 1;
            sentences.add(parseSentence(order, line));
            if (sentences.size() == PROGRESS_EVERY) {
                importSentences(sentences);
                publishProgress(order);
            }
        }
        importSentences(sentences);
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
        Toast.makeText(activity, R.string.error_retrieving, Toast.LENGTH_SHORT).show();
        return null;
    }

    dao.reloadCollectionCounter(collection);

    return null;
}
 
Example #18
Source File: DatabaseHelper.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
private void executePragmas(SQLiteDatabase db) {
	if (SQLiteUtils.FOREIGN_KEYS_SUPPORTED) {
		db.execSQL("PRAGMA foreign_keys=ON;");
		Log.i("Foreign Keys supported. Enabling foreign key features.");
	}
}
 
Example #19
Source File: DatabaseHelper.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
private void executeSqlScript(SQLiteDatabase db, String file) {

	    InputStream stream = null;

		try {
		    stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file);

		    if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) {
		        executeDelimitedSqlScript(db, stream);

		    } else {
		        executeLegacySqlScript(db, stream);

		    }

		} catch (IOException e) {
			Log.e("Failed to execute " + file, e);

		} finally {
		    IOUtils.closeQuietly(stream);

		}
	}
 
Example #20
Source File: ActiveAndroid.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public static void setLoggingEnabled(boolean enabled) {
	Log.setEnabled(enabled);
}
 
Example #21
Source File: Cache.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public static synchronized void clear() {
	sEntities.evictAll();
	Log.v("Cache cleared.");
}
 
Example #22
Source File: DatabaseHelper.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
private void executeSqlScript(SQLiteDatabase db, String file) {

	    InputStream stream = null;

		try {
		    stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file);

		    if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) {
		        executeDelimitedSqlScript(db, stream);

		    } else {
		        executeLegacySqlScript(db, stream);

		    }

		} catch (IOException e) {
			Log.e("Failed to execute " + file, e);

		} finally {
		    IOUtils.closeQuietly(stream);

		}
	}
 
Example #23
Source File: DatabaseHelper.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
private void executePragmas(SQLiteDatabase db) {
	if (SQLiteUtils.FOREIGN_KEYS_SUPPORTED) {
		db.execSQL("PRAGMA foreign_keys=ON;");
		Log.i("Foreign Keys supported. Enabling foreign key features.");
	}
}
 
Example #24
Source File: ActiveAndroid.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public static void setLoggingEnabled(boolean enabled) {
	Log.setEnabled(enabled);
}
 
Example #25
Source File: Cache.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public static synchronized void clear() {
	sEntities.evictAll();
	Log.v("Cache cleared.");
}