use of android.support.annotation.WorkerThread in project Lightning-Browser by anthonycr.
the class HistoryDatabase method findItemsContaining.
@WorkerThread
@NonNull
synchronized List<HistoryItem> findItemsContaining(@Nullable String search) {
List<HistoryItem> itemList = new ArrayList<>(5);
if (search == null) {
return itemList;
}
search = '%' + search + '%';
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, KEY_TITLE + " LIKE ? OR " + KEY_URL + " LIKE ?", new String[] { search, search }, null, null, KEY_TIME_VISITED + " DESC", "5");
while (cursor.moveToNext()) {
itemList.add(fromCursor(cursor));
}
cursor.close();
return itemList;
}
use of android.support.annotation.WorkerThread in project Lightning-Browser by anthonycr.
the class HistoryDatabase method getHistoryItem.
@WorkerThread
@Nullable
synchronized String getHistoryItem(@NonNull String url) {
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, new String[] { KEY_ID, KEY_URL, KEY_TITLE }, KEY_URL + " = ?", new String[] { url }, null, null, null, "1");
String m = null;
if (cursor != null) {
cursor.moveToFirst();
m = cursor.getString(0);
cursor.close();
}
return m;
}
use of android.support.annotation.WorkerThread in project Lightning-Browser by anthonycr.
the class HistoryDatabase method getLastHundredItems.
@WorkerThread
@NonNull
synchronized List<HistoryItem> getLastHundredItems() {
List<HistoryItem> itemList = new ArrayList<>(100);
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, null, null, null, null, KEY_TIME_VISITED + " DESC", "100");
while (cursor.moveToNext()) {
itemList.add(fromCursor(cursor));
}
cursor.close();
return itemList;
}
use of android.support.annotation.WorkerThread in project Lightning-Browser by anthonycr.
the class BookmarkLocalSync method getBrowserCursor.
@Nullable
@WorkerThread
private Cursor getBrowserCursor(String contentUri) {
Cursor cursor;
Uri uri = Uri.parse(contentUri);
try {
cursor = mContext.getContentResolver().query(uri, new String[] { COLUMN_URL, COLUMN_TITLE, COLUMN_BOOKMARK }, null, null, null);
} catch (IllegalArgumentException e) {
return null;
}
return cursor;
}
use of android.support.annotation.WorkerThread in project ViewAnimator by florent37.
the class SvgPathParser method parsePath.
/**
* This is where the hard-to-parse paths are handled.
* Uppercase rules are absolute positions, lowercase are relative.
* Types of path rules:
* <p/>
* <ol>
* <li>M/m - (x y)+ - Move to (without drawing)
* <li>Z/z - (no params) - Close path (back to starting point)
* <li>L/l - (x y)+ - Line to
* <li>H/h - x+ - Horizontal ine to
* <li>V/v - y+ - Vertical line to
* <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to
* <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier)
* <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to
* <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point)
* </ol>
* <p/>
* Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign)
*
* @param dAttributeOfPath the d attribute of <path> from the XML
*/
@WorkerThread
public static Path parsePath(String dAttributeOfPath) throws Exception {
int n = dAttributeOfPath.length();
ParserHelper helper = new ParserHelper(dAttributeOfPath, 0);
helper.skipWhitespace();
Path path = new Path();
float lastX = 0;
float lastY = 0;
float lastX1 = 0;
float lastY1 = 0;
float subPathStartX = 0;
float subPathStartY = 0;
char prevCmd = 0;
while (helper.getPosition() < n) {
char cmd = dAttributeOfPath.charAt(helper.getPosition());
switch(cmd) {
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (prevCmd == 'm' || prevCmd == 'M') {
cmd = (char) (((int) prevCmd) - 1);
break;
} else if (prevCmd == 'c' || prevCmd == 'C') {
cmd = prevCmd;
break;
} else if (prevCmd == 'l' || prevCmd == 'L') {
cmd = prevCmd;
break;
}
default:
{
helper.advance();
prevCmd = cmd;
}
}
boolean wasCurve = false;
switch(cmd) {
case 'M':
case 'm':
{
float x = helper.nextFloat();
float y = helper.nextFloat();
Log.d(null, String.format("move to: [%s,%s]", x, y));
if (cmd == 'm') {
subPathStartX += x;
subPathStartY += y;
path.rMoveTo(x, y);
lastX += x;
lastY += y;
} else {
subPathStartX = x;
subPathStartY = y;
path.moveTo(x, y);
lastX = x;
lastY = y;
}
break;
}
case 'Z':
case 'z':
{
Log.d(null, String.format("close, move to: [%s,%s]", subPathStartX, subPathStartY));
path.close();
path.moveTo(subPathStartX, subPathStartY);
lastX = subPathStartX;
lastY = subPathStartY;
lastX1 = subPathStartX;
lastY1 = subPathStartY;
wasCurve = true;
break;
}
case 'L':
case 'l':
{
float x = helper.nextFloat();
float y = helper.nextFloat();
Log.d(null, String.format("line to: [%s,%s]", x, y));
if (cmd == 'l') {
path.rLineTo(x, y);
lastX += x;
lastY += y;
} else {
path.lineTo(x, y);
lastX = x;
lastY = y;
}
break;
}
case 'H':
case 'h':
{
float x = helper.nextFloat();
Log.d(null, String.format("horizontal line to: [%s]", x));
if (cmd == 'h') {
path.rLineTo(x, 0);
lastX += x;
} else {
path.lineTo(x, lastY);
lastX = x;
}
break;
}
case 'V':
case 'v':
{
float y = helper.nextFloat();
Log.d(null, String.format("vertical line to: [%s]", y));
if (cmd == 'v') {
path.rLineTo(0, y);
lastY += y;
} else {
path.lineTo(lastX, y);
lastY = y;
}
break;
}
case 'C':
case 'c':
{
wasCurve = true;
float x1 = helper.nextFloat();
float y1 = helper.nextFloat();
float x2 = helper.nextFloat();
float y2 = helper.nextFloat();
float x = helper.nextFloat();
float y = helper.nextFloat();
Log.d(null, String.format("cubic to: [%s,%s][%s,%s][%s,%s]", x1, y1, x2, y2, x, y));
if (cmd == 'c') {
x1 += lastX;
x2 += lastX;
x += lastX;
y1 += lastY;
y2 += lastY;
y += lastY;
}
path.cubicTo(x1, y1, x2, y2, x, y);
lastX1 = x2;
lastY1 = y2;
lastX = x;
lastY = y;
break;
}
case 'S':
case 's':
{
wasCurve = true;
float x2 = helper.nextFloat();
float y2 = helper.nextFloat();
float x = helper.nextFloat();
float y = helper.nextFloat();
Log.d(null, String.format("cubic to: [%s,%s][%s,%s]", x2, y2, x, y));
if (cmd == 's') {
x2 += lastX;
x += lastX;
y2 += lastY;
y += lastY;
}
float x1 = 2 * lastX - lastX1;
float y1 = 2 * lastY - lastY1;
path.cubicTo(x1, y1, x2, y2, x, y);
lastX1 = x2;
lastY1 = y2;
lastX = x;
lastY = y;
break;
}
case 'A':
case 'a':
{
float rx = helper.nextFloat();
float ry = helper.nextFloat();
float theta = helper.nextFloat();
int largeArc = (int) helper.nextFloat();
int sweepArc = (int) helper.nextFloat();
float x = helper.nextFloat();
float y = helper.nextFloat();
Log.d(null, String.format("arc to: [%s,%s][%s][%s,%s][%s,%s]", rx, ry, theta, largeArc, sweepArc, x, y));
drawArc(path, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc);
lastX = x;
lastY = y;
break;
}
}
if (!wasCurve) {
lastX1 = lastX;
lastY1 = lastY;
}
helper.skipWhitespace();
}
return path;
}
Aggregations