repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
chrisjenx/Calligraphy
calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java
CalligraphyFactory.applyFontToToolbar
private void applyFontToToolbar(final Toolbar view) { final CharSequence previousTitle = view.getTitle(); final CharSequence previousSubtitle = view.getSubtitle(); // The toolbar inflates both the title and the subtitle views lazily but luckily they do it // synchronously when you set a title and a subtitle programmatically. // So we set a title and a subtitle to something, then get the views, then revert. view.setTitle("uk.co.chrisjenx.calligraphy:toolbar_title"); view.setSubtitle("uk.co.chrisjenx.calligraphy:toolbar_subtitle"); // Iterate through the children to run post inflation on them final int childCount = view.getChildCount(); for (int i = 0; i < childCount; i++) { onViewCreated(view.getChildAt(i), view.getContext(), null); } // Remove views from view if they didn't have copy set. view.setTitle(previousTitle); view.setSubtitle(previousSubtitle); }
java
private void applyFontToToolbar(final Toolbar view) { final CharSequence previousTitle = view.getTitle(); final CharSequence previousSubtitle = view.getSubtitle(); // The toolbar inflates both the title and the subtitle views lazily but luckily they do it // synchronously when you set a title and a subtitle programmatically. // So we set a title and a subtitle to something, then get the views, then revert. view.setTitle("uk.co.chrisjenx.calligraphy:toolbar_title"); view.setSubtitle("uk.co.chrisjenx.calligraphy:toolbar_subtitle"); // Iterate through the children to run post inflation on them final int childCount = view.getChildCount(); for (int i = 0; i < childCount; i++) { onViewCreated(view.getChildAt(i), view.getContext(), null); } // Remove views from view if they didn't have copy set. view.setTitle(previousTitle); view.setSubtitle(previousSubtitle); }
[ "private", "void", "applyFontToToolbar", "(", "final", "Toolbar", "view", ")", "{", "final", "CharSequence", "previousTitle", "=", "view", ".", "getTitle", "(", ")", ";", "final", "CharSequence", "previousSubtitle", "=", "view", ".", "getSubtitle", "(", ")", "...
Will forcibly set text on the views then remove ones that didn't have copy. @param view toolbar view.
[ "Will", "forcibly", "set", "text", "on", "the", "views", "then", "remove", "ones", "that", "didn", "t", "have", "copy", "." ]
085e441954d787bd4ef31f245afe5f2f2a311ea5
https://github.com/chrisjenx/Calligraphy/blob/085e441954d787bd4ef31f245afe5f2f2a311ea5/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/CalligraphyFactory.java#L203-L220
train
chrisjenx/Calligraphy
calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/TypefaceUtils.java
TypefaceUtils.load
public static Typeface load(final AssetManager assetManager, final String filePath) { synchronized (sCachedFonts) { try { if (!sCachedFonts.containsKey(filePath)) { final Typeface typeface = Typeface.createFromAsset(assetManager, filePath); sCachedFonts.put(filePath, typeface); return typeface; } } catch (Exception e) { Log.w("Calligraphy", "Can't create asset from " + filePath + ". Make sure you have passed in the correct path and file name.", e); sCachedFonts.put(filePath, null); return null; } return sCachedFonts.get(filePath); } }
java
public static Typeface load(final AssetManager assetManager, final String filePath) { synchronized (sCachedFonts) { try { if (!sCachedFonts.containsKey(filePath)) { final Typeface typeface = Typeface.createFromAsset(assetManager, filePath); sCachedFonts.put(filePath, typeface); return typeface; } } catch (Exception e) { Log.w("Calligraphy", "Can't create asset from " + filePath + ". Make sure you have passed in the correct path and file name.", e); sCachedFonts.put(filePath, null); return null; } return sCachedFonts.get(filePath); } }
[ "public", "static", "Typeface", "load", "(", "final", "AssetManager", "assetManager", ",", "final", "String", "filePath", ")", "{", "synchronized", "(", "sCachedFonts", ")", "{", "try", "{", "if", "(", "!", "sCachedFonts", ".", "containsKey", "(", "filePath", ...
A helper loading a custom font. @param assetManager App's asset manager. @param filePath The path of the file. @return Return {@link android.graphics.Typeface} or null if the path is invalid.
[ "A", "helper", "loading", "a", "custom", "font", "." ]
085e441954d787bd4ef31f245afe5f2f2a311ea5
https://github.com/chrisjenx/Calligraphy/blob/085e441954d787bd4ef31f245afe5f2f2a311ea5/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/TypefaceUtils.java#L31-L46
train
chrisjenx/Calligraphy
calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/TypefaceUtils.java
TypefaceUtils.getSpan
public static CalligraphyTypefaceSpan getSpan(final Typeface typeface) { if (typeface == null) return null; synchronized (sCachedSpans) { if (!sCachedSpans.containsKey(typeface)) { final CalligraphyTypefaceSpan span = new CalligraphyTypefaceSpan(typeface); sCachedSpans.put(typeface, span); return span; } return sCachedSpans.get(typeface); } }
java
public static CalligraphyTypefaceSpan getSpan(final Typeface typeface) { if (typeface == null) return null; synchronized (sCachedSpans) { if (!sCachedSpans.containsKey(typeface)) { final CalligraphyTypefaceSpan span = new CalligraphyTypefaceSpan(typeface); sCachedSpans.put(typeface, span); return span; } return sCachedSpans.get(typeface); } }
[ "public", "static", "CalligraphyTypefaceSpan", "getSpan", "(", "final", "Typeface", "typeface", ")", "{", "if", "(", "typeface", "==", "null", ")", "return", "null", ";", "synchronized", "(", "sCachedSpans", ")", "{", "if", "(", "!", "sCachedSpans", ".", "co...
A helper loading custom spans so we don't have to keep creating hundreds of spans. @param typeface not null typeface @return will return null of typeface passed in is null.
[ "A", "helper", "loading", "custom", "spans", "so", "we", "don", "t", "have", "to", "keep", "creating", "hundreds", "of", "spans", "." ]
085e441954d787bd4ef31f245afe5f2f2a311ea5
https://github.com/chrisjenx/Calligraphy/blob/085e441954d787bd4ef31f245afe5f2f2a311ea5/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/TypefaceUtils.java#L54-L64
train
crossoverJie/distributed-redis-tool
src/main/java/com/crossoverjie/distributed/util/ScriptUtil.java
ScriptUtil.getScript
public static String getScript(String path) { StringBuilder sb = new StringBuilder(); InputStream stream = ScriptUtil.class.getClassLoader().getResourceAsStream(path); try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))){ String str; while ((str = br.readLine()) != null) { sb.append(str).append(System.lineSeparator()); } } catch (IOException e) { System.err.println(e.getStackTrace()); } return sb.toString(); }
java
public static String getScript(String path) { StringBuilder sb = new StringBuilder(); InputStream stream = ScriptUtil.class.getClassLoader().getResourceAsStream(path); try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))){ String str; while ((str = br.readLine()) != null) { sb.append(str).append(System.lineSeparator()); } } catch (IOException e) { System.err.println(e.getStackTrace()); } return sb.toString(); }
[ "public", "static", "String", "getScript", "(", "String", "path", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "InputStream", "stream", "=", "ScriptUtil", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResourceAsStream"...
return lua script String @param path @return
[ "return", "lua", "script", "String" ]
57169feaccb6a56ab8821fa34e8e15954bb7b3b9
https://github.com/crossoverJie/distributed-redis-tool/blob/57169feaccb6a56ab8821fa34e8e15954bb7b3b9/src/main/java/com/crossoverjie/distributed/util/ScriptUtil.java#L20-L35
train
crossoverJie/distributed-redis-tool
src/main/java/com/crossoverjie/distributed/lock/RedisLock.java
RedisLock.getConnection
private Object getConnection() { Object connection ; if (type == RedisToolsConstant.SINGLE){ RedisConnection redisConnection = jedisConnectionFactory.getConnection(); connection = redisConnection.getNativeConnection(); }else { RedisClusterConnection clusterConnection = jedisConnectionFactory.getClusterConnection(); connection = clusterConnection.getNativeConnection() ; } return connection; }
java
private Object getConnection() { Object connection ; if (type == RedisToolsConstant.SINGLE){ RedisConnection redisConnection = jedisConnectionFactory.getConnection(); connection = redisConnection.getNativeConnection(); }else { RedisClusterConnection clusterConnection = jedisConnectionFactory.getClusterConnection(); connection = clusterConnection.getNativeConnection() ; } return connection; }
[ "private", "Object", "getConnection", "(", ")", "{", "Object", "connection", ";", "if", "(", "type", "==", "RedisToolsConstant", ".", "SINGLE", ")", "{", "RedisConnection", "redisConnection", "=", "jedisConnectionFactory", ".", "getConnection", "(", ")", ";", "c...
get Redis connection @return
[ "get", "Redis", "connection" ]
57169feaccb6a56ab8821fa34e8e15954bb7b3b9
https://github.com/crossoverJie/distributed-redis-tool/blob/57169feaccb6a56ab8821fa34e8e15954bb7b3b9/src/main/java/com/crossoverjie/distributed/lock/RedisLock.java#L64-L74
train
crossoverJie/distributed-redis-tool
src/main/java/com/crossoverjie/distributed/lock/RedisLock.java
RedisLock.tryLock
public boolean tryLock(String key, String request) { //get connection Object connection = getConnection(); String result ; if (connection instanceof Jedis){ result = ((Jedis) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME); ((Jedis) connection).close(); }else { result = ((JedisCluster) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME); } if (LOCK_MSG.equals(result)) { return true; } else { return false; } }
java
public boolean tryLock(String key, String request) { //get connection Object connection = getConnection(); String result ; if (connection instanceof Jedis){ result = ((Jedis) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME); ((Jedis) connection).close(); }else { result = ((JedisCluster) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME); } if (LOCK_MSG.equals(result)) { return true; } else { return false; } }
[ "public", "boolean", "tryLock", "(", "String", "key", ",", "String", "request", ")", "{", "//get connection", "Object", "connection", "=", "getConnection", "(", ")", ";", "String", "result", ";", "if", "(", "connection", "instanceof", "Jedis", ")", "{", "res...
Non-blocking lock @param key lock business type @param request value @return true lock success false lock fail
[ "Non", "-", "blocking", "lock" ]
57169feaccb6a56ab8821fa34e8e15954bb7b3b9
https://github.com/crossoverJie/distributed-redis-tool/blob/57169feaccb6a56ab8821fa34e8e15954bb7b3b9/src/main/java/com/crossoverjie/distributed/lock/RedisLock.java#L84-L101
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/ErrorHandler.java
ErrorHandler.error
public void error(final String msg) { errors++; if (!suppressOutput) { out.println("ERROR: " + msg); } if (stopOnError) { throw new IllegalArgumentException(msg); } }
java
public void error(final String msg) { errors++; if (!suppressOutput) { out.println("ERROR: " + msg); } if (stopOnError) { throw new IllegalArgumentException(msg); } }
[ "public", "void", "error", "(", "final", "String", "msg", ")", "{", "errors", "++", ";", "if", "(", "!", "suppressOutput", ")", "{", "out", ".", "println", "(", "\"ERROR: \"", "+", "msg", ")", ";", "}", "if", "(", "stopOnError", ")", "{", "throw", ...
Record a message signifying an error condition. @param msg signifying an error.
[ "Record", "a", "message", "signifying", "an", "error", "condition", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/ErrorHandler.java#L61-L74
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/ErrorHandler.java
ErrorHandler.warning
public void warning(final String msg) { warnings++; if (!suppressOutput) { out.println("WARNING: " + msg); } if (warningsFatal && stopOnError) { throw new IllegalArgumentException(msg); } }
java
public void warning(final String msg) { warnings++; if (!suppressOutput) { out.println("WARNING: " + msg); } if (warningsFatal && stopOnError) { throw new IllegalArgumentException(msg); } }
[ "public", "void", "warning", "(", "final", "String", "msg", ")", "{", "warnings", "++", ";", "if", "(", "!", "suppressOutput", ")", "{", "out", ".", "println", "(", "\"WARNING: \"", "+", "msg", ")", ";", "}", "if", "(", "warningsFatal", "&&", "stopOnEr...
Record a message signifying an warning condition. @param msg signifying an warning.
[ "Record", "a", "message", "signifying", "an", "warning", "condition", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/ErrorHandler.java#L81-L94
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppUtil.java
CppUtil.formatByteOrderEncoding
public static String formatByteOrderEncoding(final ByteOrder byteOrder, final PrimitiveType primitiveType) { switch (primitiveType.size()) { case 2: return "SBE_" + byteOrder + "_ENCODE_16"; case 4: return "SBE_" + byteOrder + "_ENCODE_32"; case 8: return "SBE_" + byteOrder + "_ENCODE_64"; default: return ""; } }
java
public static String formatByteOrderEncoding(final ByteOrder byteOrder, final PrimitiveType primitiveType) { switch (primitiveType.size()) { case 2: return "SBE_" + byteOrder + "_ENCODE_16"; case 4: return "SBE_" + byteOrder + "_ENCODE_32"; case 8: return "SBE_" + byteOrder + "_ENCODE_64"; default: return ""; } }
[ "public", "static", "String", "formatByteOrderEncoding", "(", "final", "ByteOrder", "byteOrder", ",", "final", "PrimitiveType", "primitiveType", ")", "{", "switch", "(", "primitiveType", ".", "size", "(", ")", ")", "{", "case", "2", ":", "return", "\"SBE_\"", ...
Return the Cpp98 formatted byte order encoding string to use for a given byte order and primitiveType @param byteOrder of the {@link uk.co.real_logic.sbe.ir.Token} @param primitiveType of the {@link uk.co.real_logic.sbe.ir.Token} @return the string formatted as the byte ordering encoding
[ "Return", "the", "Cpp98", "formatted", "byte", "order", "encoding", "string", "to", "use", "for", "a", "given", "byte", "order", "and", "primitiveType" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppUtil.java#L125-L141
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangUtil.java
GolangUtil.formatPropertyName
public static String formatPropertyName(final String value) { String formattedValue = toUpperFirstChar(value); if (ValidationUtil.isGolangKeyword(formattedValue)) { final String keywordAppendToken = System.getProperty(SbeTool.KEYWORD_APPEND_TOKEN); if (null == keywordAppendToken) { throw new IllegalStateException( "Invalid property name='" + formattedValue + "' please correct the schema or consider setting system property: " + SbeTool.KEYWORD_APPEND_TOKEN); } formattedValue += keywordAppendToken; } return formattedValue; }
java
public static String formatPropertyName(final String value) { String formattedValue = toUpperFirstChar(value); if (ValidationUtil.isGolangKeyword(formattedValue)) { final String keywordAppendToken = System.getProperty(SbeTool.KEYWORD_APPEND_TOKEN); if (null == keywordAppendToken) { throw new IllegalStateException( "Invalid property name='" + formattedValue + "' please correct the schema or consider setting system property: " + SbeTool.KEYWORD_APPEND_TOKEN); } formattedValue += keywordAppendToken; } return formattedValue; }
[ "public", "static", "String", "formatPropertyName", "(", "final", "String", "value", ")", "{", "String", "formattedValue", "=", "toUpperFirstChar", "(", "value", ")", ";", "if", "(", "ValidationUtil", ".", "isGolangKeyword", "(", "formattedValue", ")", ")", "{",...
Format a String as a property name. @param value to be formatted. @return the string formatted as a property name.
[ "Format", "a", "String", "as", "a", "property", "name", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangUtil.java#L115-L133
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java
PrimitiveValue.parse
public static PrimitiveValue parse( final String value, final int length, final String characterEncoding) { if (value.length() > length) { throw new IllegalStateException("value.length=" + value.length() + " greater than length=" + length); } byte[] bytes = value.getBytes(forName(characterEncoding)); if (bytes.length < length) { bytes = Arrays.copyOf(bytes, length); } return new PrimitiveValue(bytes, characterEncoding, length); }
java
public static PrimitiveValue parse( final String value, final int length, final String characterEncoding) { if (value.length() > length) { throw new IllegalStateException("value.length=" + value.length() + " greater than length=" + length); } byte[] bytes = value.getBytes(forName(characterEncoding)); if (bytes.length < length) { bytes = Arrays.copyOf(bytes, length); } return new PrimitiveValue(bytes, characterEncoding, length); }
[ "public", "static", "PrimitiveValue", "parse", "(", "final", "String", "value", ",", "final", "int", "length", ",", "final", "String", "characterEncoding", ")", "{", "if", "(", "value", ".", "length", "(", ")", ">", "length", ")", "{", "throw", "new", "I...
Parse constant value string and set representation based on type, length, and characterEncoding @param value expressed as a String @param length of the type @param characterEncoding of the String @return a new {@link PrimitiveValue} for the value. @throws IllegalArgumentException if parsing malformed type
[ "Parse", "constant", "value", "string", "and", "set", "representation", "based", "on", "type", "length", "and", "characterEncoding" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java#L271-L286
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java
PrimitiveValue.byteArrayValue
public byte[] byteArrayValue(final PrimitiveType type) { if (representation == Representation.BYTE_ARRAY) { return byteArrayValue; } else if (representation == Representation.LONG && size == 1 && type == PrimitiveType.CHAR) { byteArrayValueForLong[0] = (byte)longValue; return byteArrayValueForLong; } throw new IllegalStateException("PrimitiveValue is not a byte[] representation"); }
java
public byte[] byteArrayValue(final PrimitiveType type) { if (representation == Representation.BYTE_ARRAY) { return byteArrayValue; } else if (representation == Representation.LONG && size == 1 && type == PrimitiveType.CHAR) { byteArrayValueForLong[0] = (byte)longValue; return byteArrayValueForLong; } throw new IllegalStateException("PrimitiveValue is not a byte[] representation"); }
[ "public", "byte", "[", "]", "byteArrayValue", "(", "final", "PrimitiveType", "type", ")", "{", "if", "(", "representation", "==", "Representation", ".", "BYTE_ARRAY", ")", "{", "return", "byteArrayValue", ";", "}", "else", "if", "(", "representation", "==", ...
Return byte array value for this PrimitiveValue given a particular type @param type of this value @return value expressed as a byte array @throws IllegalStateException if not a byte array value representation
[ "Return", "byte", "array", "value", "for", "this", "PrimitiveValue", "given", "a", "particular", "type" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java#L346-L359
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java
JavaUtil.append
public static void append(final StringBuilder builder, final String indent, final String line) { builder.append(indent).append(line).append('\n'); }
java
public static void append(final StringBuilder builder, final String indent, final String line) { builder.append(indent).append(line).append('\n'); }
[ "public", "static", "void", "append", "(", "final", "StringBuilder", "builder", ",", "final", "String", "indent", ",", "final", "String", "line", ")", "{", "builder", ".", "append", "(", "indent", ")", ".", "append", "(", "line", ")", ".", "append", "(",...
Shortcut to append a line of generated code @param builder string builder to which to append the line @param indent current text indentation @param line line to be appended
[ "Shortcut", "to", "append", "a", "line", "of", "generated", "code" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java#L178-L181
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java
JavaUtil.generateTypeJavadoc
public static String generateTypeJavadoc(final String indent, final Token typeToken) { final String description = typeToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " */\n"; }
java
public static String generateTypeJavadoc(final String indent, final Token typeToken) { final String description = typeToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " */\n"; }
[ "public", "static", "String", "generateTypeJavadoc", "(", "final", "String", "indent", ",", "final", "Token", "typeToken", ")", "{", "final", "String", "description", "=", "typeToken", ".", "description", "(", ")", ";", "if", "(", "null", "==", "description", ...
Generate the Javadoc comment header for a type. @param indent level for the comment. @param typeToken for the type. @return a string representation of the Javadoc comment.
[ "Generate", "the", "Javadoc", "comment", "header", "for", "a", "type", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java#L259-L271
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java
JavaUtil.generateOptionEncodeJavadoc
public static String generateOptionEncodeJavadoc(final String indent, final Token optionToken) { final String description = optionToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " *\n" + indent + " * @param value true if " + optionToken.name() + " is set or false if not\n" + indent + " */\n"; }
java
public static String generateOptionEncodeJavadoc(final String indent, final Token optionToken) { final String description = optionToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " *\n" + indent + " * @param value true if " + optionToken.name() + " is set or false if not\n" + indent + " */\n"; }
[ "public", "static", "String", "generateOptionEncodeJavadoc", "(", "final", "String", "indent", ",", "final", "Token", "optionToken", ")", "{", "final", "String", "description", "=", "optionToken", ".", "description", "(", ")", ";", "if", "(", "null", "==", "de...
Generate the Javadoc comment header for a bitset choice option encode method. @param indent level for the comment. @param optionToken for the type. @return a string representation of the Javadoc comment.
[ "Generate", "the", "Javadoc", "comment", "header", "for", "a", "bitset", "choice", "option", "encode", "method", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java#L303-L317
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java
JavaUtil.generateFlyweightPropertyJavadoc
public static String generateFlyweightPropertyJavadoc( final String indent, final Token propertyToken, final String typeName) { final String description = propertyToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " *\n" + indent + " * @return " + typeName + " : " + description + "\n" + indent + " */\n"; }
java
public static String generateFlyweightPropertyJavadoc( final String indent, final Token propertyToken, final String typeName) { final String description = propertyToken.description(); if (null == description || description.isEmpty()) { return ""; } return indent + "/**\n" + indent + " * " + description + '\n' + indent + " *\n" + indent + " * @return " + typeName + " : " + description + "\n" + indent + " */\n"; }
[ "public", "static", "String", "generateFlyweightPropertyJavadoc", "(", "final", "String", "indent", ",", "final", "Token", "propertyToken", ",", "final", "String", "typeName", ")", "{", "final", "String", "description", "=", "propertyToken", ".", "description", "(",...
Generate the Javadoc comment header for flyweight property. @param indent level for the comment. @param propertyToken for the property name. @param typeName for the property type. @return a string representation of the Javadoc comment.
[ "Generate", "the", "Javadoc", "comment", "header", "for", "flyweight", "property", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaUtil.java#L327-L342
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.findMessages
public static Map<Long, Message> findMessages( final Document document, final XPath xPath, final Map<String, Type> typeByNameMap) throws Exception { final Map<Long, Message> messageByIdMap = new HashMap<>(); final ObjectHashSet<String> distinctNames = new ObjectHashSet<>(); forEach((NodeList)xPath.compile(MESSAGE_XPATH_EXPR).evaluate(document, XPathConstants.NODESET), (node) -> addMessageWithIdCheck(distinctNames, messageByIdMap, new Message(node, typeByNameMap), node)); return messageByIdMap; }
java
public static Map<Long, Message> findMessages( final Document document, final XPath xPath, final Map<String, Type> typeByNameMap) throws Exception { final Map<Long, Message> messageByIdMap = new HashMap<>(); final ObjectHashSet<String> distinctNames = new ObjectHashSet<>(); forEach((NodeList)xPath.compile(MESSAGE_XPATH_EXPR).evaluate(document, XPathConstants.NODESET), (node) -> addMessageWithIdCheck(distinctNames, messageByIdMap, new Message(node, typeByNameMap), node)); return messageByIdMap; }
[ "public", "static", "Map", "<", "Long", ",", "Message", ">", "findMessages", "(", "final", "Document", "document", ",", "final", "XPath", "xPath", ",", "final", "Map", "<", "String", ",", "Type", ">", "typeByNameMap", ")", "throws", "Exception", "{", "fina...
Scan XML for all message definitions and save in map @param document for the XML parsing @param xPath for XPath expression reuse @param typeByNameMap to use for Type objects @return {@link java.util.Map} of schemaId to Message @throws Exception on parsing error.
[ "Scan", "XML", "for", "all", "message", "definitions", "and", "save", "in", "map" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L220-L230
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.handleError
public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
java
public static void handleError(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("ERROR: " + formatLocationInfo(node) + msg); } else { handler.error(formatLocationInfo(node) + msg); } }
[ "public", "static", "void", "handleError", "(", "final", "Node", "node", ",", "final", "String", "msg", ")", "{", "final", "ErrorHandler", "handler", "=", "(", "ErrorHandler", ")", "node", ".", "getOwnerDocument", "(", ")", ".", "getUserData", "(", "ERROR_HA...
Handle an error condition as consequence of parsing. @param node that is the context of the warning. @param msg associated with the error.
[ "Handle", "an", "error", "condition", "as", "consequence", "of", "parsing", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L238-L250
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.handleWarning
public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }
java
public static void handleWarning(final Node node, final String msg) { final ErrorHandler handler = (ErrorHandler)node.getOwnerDocument().getUserData(ERROR_HANDLER_KEY); if (handler == null) { throw new IllegalStateException("WARNING: " + formatLocationInfo(node) + msg); } else { handler.warning(formatLocationInfo(node) + msg); } }
[ "public", "static", "void", "handleWarning", "(", "final", "Node", "node", ",", "final", "String", "msg", ")", "{", "final", "ErrorHandler", "handler", "=", "(", "ErrorHandler", ")", "node", ".", "getOwnerDocument", "(", ")", ".", "getUserData", "(", "ERROR_...
Handle a warning condition as a consequence of parsing. @param node as the context for the warning. @param msg associated with the warning.
[ "Handle", "a", "warning", "condition", "as", "a", "consequence", "of", "parsing", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L258-L270
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.getAttributeValue
public static String getAttributeValue(final Node elementNode, final String attrName) { final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName); if (attrNode == null || "".equals(attrNode.getNodeValue())) { throw new IllegalStateException( "Element '" + elementNode.getNodeName() + "' has empty or missing attribute: " + attrName); } return attrNode.getNodeValue(); }
java
public static String getAttributeValue(final Node elementNode, final String attrName) { final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName); if (attrNode == null || "".equals(attrNode.getNodeValue())) { throw new IllegalStateException( "Element '" + elementNode.getNodeName() + "' has empty or missing attribute: " + attrName); } return attrNode.getNodeValue(); }
[ "public", "static", "String", "getAttributeValue", "(", "final", "Node", "elementNode", ",", "final", "String", "attrName", ")", "{", "final", "Node", "attrNode", "=", "elementNode", ".", "getAttributes", "(", ")", ".", "getNamedItemNS", "(", "null", ",", "att...
Helper function that throws an exception when the attribute is not set. @param elementNode that should have the attribute @param attrName that is to be looked up @return value of the attribute @throws IllegalArgumentException if the attribute is not present
[ "Helper", "function", "that", "throws", "an", "exception", "when", "the", "attribute", "is", "not", "set", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L280-L291
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.getAttributeValue
public static String getAttributeValue(final Node elementNode, final String attrName, final String defValue) { final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName); if (attrNode == null) { return defValue; } return attrNode.getNodeValue(); }
java
public static String getAttributeValue(final Node elementNode, final String attrName, final String defValue) { final Node attrNode = elementNode.getAttributes().getNamedItemNS(null, attrName); if (attrNode == null) { return defValue; } return attrNode.getNodeValue(); }
[ "public", "static", "String", "getAttributeValue", "(", "final", "Node", "elementNode", ",", "final", "String", "attrName", ",", "final", "String", "defValue", ")", "{", "final", "Node", "attrNode", "=", "elementNode", ".", "getAttributes", "(", ")", ".", "get...
Helper function that uses a default value when value not set. @param elementNode that should have the attribute @param attrName that is to be looked up @param defValue String to return if not set @return value of the attribute or defValue
[ "Helper", "function", "that", "uses", "a", "default", "value", "when", "value", "not", "set", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L301-L311
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java
XmlSchemaParser.checkForValidName
public static void checkForValidName(final Node node, final String name) { if (!ValidationUtil.isSbeCppName(name)) { handleWarning(node, "name is not valid for C++: " + name); } if (!ValidationUtil.isSbeJavaName(name)) { handleWarning(node, "name is not valid for Java: " + name); } if (!ValidationUtil.isSbeGolangName(name)) { handleWarning(node, "name is not valid for Golang: " + name); } if (!ValidationUtil.isSbeCSharpName(name)) { handleWarning(node, "name is not valid for C#: " + name); } }
java
public static void checkForValidName(final Node node, final String name) { if (!ValidationUtil.isSbeCppName(name)) { handleWarning(node, "name is not valid for C++: " + name); } if (!ValidationUtil.isSbeJavaName(name)) { handleWarning(node, "name is not valid for Java: " + name); } if (!ValidationUtil.isSbeGolangName(name)) { handleWarning(node, "name is not valid for Golang: " + name); } if (!ValidationUtil.isSbeCSharpName(name)) { handleWarning(node, "name is not valid for C#: " + name); } }
[ "public", "static", "void", "checkForValidName", "(", "final", "Node", "node", ",", "final", "String", "name", ")", "{", "if", "(", "!", "ValidationUtil", ".", "isSbeCppName", "(", "name", ")", ")", "{", "handleWarning", "(", "node", ",", "\"name is not vali...
Check name against validity for C++ and Java naming. Warning if not valid. @param node to have the name checked. @param name of the node to be checked.
[ "Check", "name", "against", "validity", "for", "C", "++", "and", "Java", "naming", ".", "Warning", "if", "not", "valid", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java#L363-L384
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java
GolangGenerator.generateFieldEncodeDecode
private int generateFieldEncodeDecode( final List<Token> tokens, final char varName, final int currentOffset, final StringBuilder encode, final StringBuilder decode, final StringBuilder rc, final StringBuilder init) { final Token signalToken = tokens.get(0); final Token encodingToken = tokens.get(1); final String propertyName = formatPropertyName(signalToken.name()); int gap = 0; // for offset calculations switch (encodingToken.signal()) { case BEGIN_COMPOSITE: case BEGIN_ENUM: case BEGIN_SET: gap = signalToken.offset() - currentOffset; encode.append(generateEncodeOffset(gap, "")); decode.append(generateDecodeOffset(gap, "")); // Encode of a constant is a nullop, decode is assignment if (signalToken.isConstantEncoding()) { decode.append(String.format( "\t%1$s.%2$s = %3$s\n", varName, propertyName, signalToken.encoding().constValue())); init.append(String.format( "\t%1$s.%2$s = %3$s\n", varName, propertyName, signalToken.encoding().constValue())); } else { encode.append(String.format( "\tif err := %1$s.%2$s.Encode(_m, _w); err != nil {\n" + "\t\treturn err\n" + "\t}\n", varName, propertyName)); decode.append(String.format( "\tif %1$s.%2$sInActingVersion(actingVersion) {\n" + "\t\tif err := %1$s.%2$s.Decode(_m, _r, actingVersion); err != nil {\n" + "\t\t\treturn err\n" + "\t\t}\n" + "\t}\n", varName, propertyName)); } if (encodingToken.signal() == Signal.BEGIN_ENUM) { rc.append(String.format( "\tif err := %1$s.%2$s.RangeCheck(actingVersion, schemaVersion); err != nil {\n" + "\t\treturn err\n" + "\t}\n", varName, propertyName)); } break; case ENCODING: gap = encodingToken.offset() - currentOffset; encode.append(generateEncodeOffset(gap, "")); decode.append(generateDecodeOffset(gap, "")); final String primitive = varName + "." + propertyName; // Encode of a constant is a nullop and we want to // initialize constant values. // (note: constancy is determined by the type's token) if (encodingToken.isConstantEncoding()) { generateConstantInitPrimitive(init, primitive, encodingToken); } else { generateEncodePrimitive(encode, varName, formatPropertyName(signalToken.name()), encodingToken); } // Optional tokens get initialized to NullValue // (note: optionality is determined by the field's token) if (signalToken.isOptionalEncoding()) { generateOptionalInitPrimitive(init, primitive, encodingToken); } generateDecodePrimitive(decode, primitive, encodingToken); generateRangeCheckPrimitive(rc, primitive, encodingToken, signalToken.isOptionalEncoding()); break; } return encodingToken.encodedLength() + gap; }
java
private int generateFieldEncodeDecode( final List<Token> tokens, final char varName, final int currentOffset, final StringBuilder encode, final StringBuilder decode, final StringBuilder rc, final StringBuilder init) { final Token signalToken = tokens.get(0); final Token encodingToken = tokens.get(1); final String propertyName = formatPropertyName(signalToken.name()); int gap = 0; // for offset calculations switch (encodingToken.signal()) { case BEGIN_COMPOSITE: case BEGIN_ENUM: case BEGIN_SET: gap = signalToken.offset() - currentOffset; encode.append(generateEncodeOffset(gap, "")); decode.append(generateDecodeOffset(gap, "")); // Encode of a constant is a nullop, decode is assignment if (signalToken.isConstantEncoding()) { decode.append(String.format( "\t%1$s.%2$s = %3$s\n", varName, propertyName, signalToken.encoding().constValue())); init.append(String.format( "\t%1$s.%2$s = %3$s\n", varName, propertyName, signalToken.encoding().constValue())); } else { encode.append(String.format( "\tif err := %1$s.%2$s.Encode(_m, _w); err != nil {\n" + "\t\treturn err\n" + "\t}\n", varName, propertyName)); decode.append(String.format( "\tif %1$s.%2$sInActingVersion(actingVersion) {\n" + "\t\tif err := %1$s.%2$s.Decode(_m, _r, actingVersion); err != nil {\n" + "\t\t\treturn err\n" + "\t\t}\n" + "\t}\n", varName, propertyName)); } if (encodingToken.signal() == Signal.BEGIN_ENUM) { rc.append(String.format( "\tif err := %1$s.%2$s.RangeCheck(actingVersion, schemaVersion); err != nil {\n" + "\t\treturn err\n" + "\t}\n", varName, propertyName)); } break; case ENCODING: gap = encodingToken.offset() - currentOffset; encode.append(generateEncodeOffset(gap, "")); decode.append(generateDecodeOffset(gap, "")); final String primitive = varName + "." + propertyName; // Encode of a constant is a nullop and we want to // initialize constant values. // (note: constancy is determined by the type's token) if (encodingToken.isConstantEncoding()) { generateConstantInitPrimitive(init, primitive, encodingToken); } else { generateEncodePrimitive(encode, varName, formatPropertyName(signalToken.name()), encodingToken); } // Optional tokens get initialized to NullValue // (note: optionality is determined by the field's token) if (signalToken.isOptionalEncoding()) { generateOptionalInitPrimitive(init, primitive, encodingToken); } generateDecodePrimitive(decode, primitive, encodingToken); generateRangeCheckPrimitive(rc, primitive, encodingToken, signalToken.isOptionalEncoding()); break; } return encodingToken.encodedLength() + gap; }
[ "private", "int", "generateFieldEncodeDecode", "(", "final", "List", "<", "Token", ">", "tokens", ",", "final", "char", "varName", ",", "final", "int", "currentOffset", ",", "final", "StringBuilder", "encode", ",", "final", "StringBuilder", "decode", ",", "final...
Returns how many extra tokens to skip over
[ "Returns", "how", "many", "extra", "tokens", "to", "skip", "over" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java#L980-L1072
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java
GolangGenerator.generateGroupProperties
private void generateGroupProperties( final StringBuilder sb, final List<Token> tokens, final String prefix) { for (int i = 0, size = tokens.size(); i < size; i++) { final Token token = tokens.get(i); if (token.signal() == Signal.BEGIN_GROUP) { final String propertyName = formatPropertyName(token.name()); generateId(sb, prefix, propertyName, token); generateSinceActingDeprecated(sb, prefix, propertyName, token); generateExtensibilityMethods(sb, prefix + propertyName, token); // Look inside for nested groups with extra prefix generateGroupProperties( sb, tokens.subList(i + 1, i + token.componentTokenCount() - 1), prefix + propertyName); i += token.componentTokenCount() - 1; } } }
java
private void generateGroupProperties( final StringBuilder sb, final List<Token> tokens, final String prefix) { for (int i = 0, size = tokens.size(); i < size; i++) { final Token token = tokens.get(i); if (token.signal() == Signal.BEGIN_GROUP) { final String propertyName = formatPropertyName(token.name()); generateId(sb, prefix, propertyName, token); generateSinceActingDeprecated(sb, prefix, propertyName, token); generateExtensibilityMethods(sb, prefix + propertyName, token); // Look inside for nested groups with extra prefix generateGroupProperties( sb, tokens.subList(i + 1, i + token.componentTokenCount() - 1), prefix + propertyName); i += token.componentTokenCount() - 1; } } }
[ "private", "void", "generateGroupProperties", "(", "final", "StringBuilder", "sb", ",", "final", "List", "<", "Token", ">", "tokens", ",", "final", "String", "prefix", ")", "{", "for", "(", "int", "i", "=", "0", ",", "size", "=", "tokens", ".", "size", ...
Recursively traverse groups to create the group properties
[ "Recursively", "traverse", "groups", "to", "create", "the", "group", "properties" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java#L1284-L1308
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java
GolangGenerator.generateExtensibilityMethods
private void generateExtensibilityMethods( final StringBuilder sb, final String typeName, final Token token) { sb.append(String.format( "\nfunc (*%1$s) SbeBlockLength() (blockLength uint) {\n" + "\treturn %2$s\n" + "}\n" + "\nfunc (*%1$s) SbeSchemaVersion() (schemaVersion %3$s) {\n" + "\treturn %4$s\n" + "}\n", typeName, generateLiteral(ir.headerStructure().blockLengthType(), Integer.toString(token.encodedLength())), golangTypeName(ir.headerStructure().schemaVersionType()), generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())))); }
java
private void generateExtensibilityMethods( final StringBuilder sb, final String typeName, final Token token) { sb.append(String.format( "\nfunc (*%1$s) SbeBlockLength() (blockLength uint) {\n" + "\treturn %2$s\n" + "}\n" + "\nfunc (*%1$s) SbeSchemaVersion() (schemaVersion %3$s) {\n" + "\treturn %4$s\n" + "}\n", typeName, generateLiteral(ir.headerStructure().blockLengthType(), Integer.toString(token.encodedLength())), golangTypeName(ir.headerStructure().schemaVersionType()), generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())))); }
[ "private", "void", "generateExtensibilityMethods", "(", "final", "StringBuilder", "sb", ",", "final", "String", "typeName", ",", "final", "Token", "token", ")", "{", "sb", ".", "append", "(", "String", ".", "format", "(", "\"\\nfunc (*%1$s) SbeBlockLength() (blockLe...
of block length and version to check for extensions
[ "of", "block", "length", "and", "version", "to", "check", "for", "extensions" ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java#L2067-L2083
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CUtil.java
CUtil.formatScopedName
public static String formatScopedName(final CharSequence[] scope, final String value) { return String.join("_", scope).toLowerCase() + "_" + formatName(value); }
java
public static String formatScopedName(final CharSequence[] scope, final String value) { return String.join("_", scope).toLowerCase() + "_" + formatName(value); }
[ "public", "static", "String", "formatScopedName", "(", "final", "CharSequence", "[", "]", "scope", ",", "final", "String", "value", ")", "{", "return", "String", ".", "join", "(", "\"_\"", ",", "scope", ")", ".", "toLowerCase", "(", ")", "+", "\"_\"", "+...
Format a String as a struct name prepended with a scope. @param scope to be prepended. @param value to be formatted. @return the string formatted as a struct name.
[ "Format", "a", "String", "as", "a", "struct", "name", "prepended", "with", "a", "scope", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CUtil.java#L125-L128
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java
SbeTool.main
public static void main(final String[] args) throws Exception { if (args.length == 0) { System.err.format("Usage: %s <filenames>...%n", SbeTool.class.getName()); System.exit(-1); } for (final String fileName : args) { final Ir ir; if (fileName.endsWith(".xml")) { final String xsdFilename = System.getProperty(SbeTool.VALIDATION_XSD); if (xsdFilename != null) { validateAgainstSchema(fileName, xsdFilename); } ir = new IrGenerator().generate(parseSchema(fileName), System.getProperty(TARGET_NAMESPACE)); } else if (fileName.endsWith(".sbeir")) { ir = new IrDecoder(fileName).decode(); } else { System.err.println("Input file format not supported: " + fileName); System.exit(-1); return; } final String outputDirName = System.getProperty(OUTPUT_DIR, "."); if (Boolean.parseBoolean(System.getProperty(GENERATE_STUBS, "true"))) { final String targetLanguage = System.getProperty(TARGET_LANGUAGE, "Java"); generate(ir, outputDirName, targetLanguage); } if (Boolean.parseBoolean(System.getProperty(GENERATE_IR, "false"))) { final File inputFile = new File(fileName); final String inputFilename = inputFile.getName(); final int nameEnd = inputFilename.lastIndexOf('.'); final String namePart = inputFilename.substring(0, nameEnd); final File fullPath = new File(outputDirName, namePart + ".sbeir"); try (IrEncoder irEncoder = new IrEncoder(fullPath.getAbsolutePath(), ir)) { irEncoder.encode(); } } } }
java
public static void main(final String[] args) throws Exception { if (args.length == 0) { System.err.format("Usage: %s <filenames>...%n", SbeTool.class.getName()); System.exit(-1); } for (final String fileName : args) { final Ir ir; if (fileName.endsWith(".xml")) { final String xsdFilename = System.getProperty(SbeTool.VALIDATION_XSD); if (xsdFilename != null) { validateAgainstSchema(fileName, xsdFilename); } ir = new IrGenerator().generate(parseSchema(fileName), System.getProperty(TARGET_NAMESPACE)); } else if (fileName.endsWith(".sbeir")) { ir = new IrDecoder(fileName).decode(); } else { System.err.println("Input file format not supported: " + fileName); System.exit(-1); return; } final String outputDirName = System.getProperty(OUTPUT_DIR, "."); if (Boolean.parseBoolean(System.getProperty(GENERATE_STUBS, "true"))) { final String targetLanguage = System.getProperty(TARGET_LANGUAGE, "Java"); generate(ir, outputDirName, targetLanguage); } if (Boolean.parseBoolean(System.getProperty(GENERATE_IR, "false"))) { final File inputFile = new File(fileName); final String inputFilename = inputFile.getName(); final int nameEnd = inputFilename.lastIndexOf('.'); final String namePart = inputFilename.substring(0, nameEnd); final File fullPath = new File(outputDirName, namePart + ".sbeir"); try (IrEncoder irEncoder = new IrEncoder(fullPath.getAbsolutePath(), ir)) { irEncoder.encode(); } } } }
[ "public", "static", "void", "main", "(", "final", "String", "[", "]", "args", ")", "throws", "Exception", "{", "if", "(", "args", ".", "length", "==", "0", ")", "{", "System", ".", "err", ".", "format", "(", "\"Usage: %s <filenames>...%n\"", ",", "SbeToo...
Main entry point for the SBE Tool. @param args command line arguments. A single filename is expected. @throws Exception if an error occurs during process of the message schema.
[ "Main", "entry", "point", "for", "the", "SBE", "Tool", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java#L188-L242
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java
SbeTool.validateAgainstSchema
public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); final Path path = Paths.get(sbeSchemaFilename); try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) { final InputSource inputSource = new InputSource(in); if (path.toAbsolutePath().getParent() != null) { inputSource.setSystemId(path.toUri().toString()); } XmlSchemaParser.validate(xsdFilename, inputSource, optionsBuilder.build()); } }
java
public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); final Path path = Paths.get(sbeSchemaFilename); try (InputStream in = new BufferedInputStream(Files.newInputStream(path))) { final InputSource inputSource = new InputSource(in); if (path.toAbsolutePath().getParent() != null) { inputSource.setSystemId(path.toUri().toString()); } XmlSchemaParser.validate(xsdFilename, inputSource, optionsBuilder.build()); } }
[ "public", "static", "void", "validateAgainstSchema", "(", "final", "String", "sbeSchemaFilename", ",", "final", "String", "xsdFilename", ")", "throws", "Exception", "{", "final", "ParserOptions", ".", "Builder", "optionsBuilder", "=", "ParserOptions", ".", "builder", ...
Validate the SBE Schema against the XSD. @param sbeSchemaFilename to be validated. @param xsdFilename XSD against which to validate. @throws Exception if an error occurs while validating.
[ "Validate", "the", "SBE", "Schema", "against", "the", "XSD", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java#L251-L272
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java
SbeTool.generate
public static void generate(final Ir ir, final String outputDirName, final String targetLanguage) throws Exception { final TargetCodeGenerator targetCodeGenerator = TargetCodeGeneratorLoader.get(targetLanguage); final CodeGenerator codeGenerator = targetCodeGenerator.newInstance(ir, outputDirName); codeGenerator.generate(); }
java
public static void generate(final Ir ir, final String outputDirName, final String targetLanguage) throws Exception { final TargetCodeGenerator targetCodeGenerator = TargetCodeGeneratorLoader.get(targetLanguage); final CodeGenerator codeGenerator = targetCodeGenerator.newInstance(ir, outputDirName); codeGenerator.generate(); }
[ "public", "static", "void", "generate", "(", "final", "Ir", "ir", ",", "final", "String", "outputDirName", ",", "final", "String", "targetLanguage", ")", "throws", "Exception", "{", "final", "TargetCodeGenerator", "targetCodeGenerator", "=", "TargetCodeGeneratorLoader...
Generate SBE encoding and decoding stubs for a target language. @param ir for the parsed specification. @param outputDirName directory into which code will be generated. @param targetLanguage for the generated code. @throws Exception if an error occurs while generating the code.
[ "Generate", "SBE", "encoding", "and", "decoding", "stubs", "for", "a", "target", "language", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java#L312-L319
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java
CompositeType.makeDataFieldCompositeType
public void makeDataFieldCompositeType() { final EncodedDataType edt = (EncodedDataType)containedTypeByNameMap.get("varData"); if (edt != null) { edt.variableLength(true); } }
java
public void makeDataFieldCompositeType() { final EncodedDataType edt = (EncodedDataType)containedTypeByNameMap.get("varData"); if (edt != null) { edt.variableLength(true); } }
[ "public", "void", "makeDataFieldCompositeType", "(", ")", "{", "final", "EncodedDataType", "edt", "=", "(", "EncodedDataType", ")", "containedTypeByNameMap", ".", "get", "(", "\"varData\"", ")", ";", "if", "(", "edt", "!=", "null", ")", "{", "edt", ".", "var...
Make this composite type, if it has a varData member, variable length by making the EncodedDataType with the name "varData" be variable length.
[ "Make", "this", "composite", "type", "if", "it", "has", "a", "varData", "member", "variable", "length", "by", "making", "the", "EncodedDataType", "with", "the", "name", "varData", "be", "variable", "length", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java#L146-L153
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java
CompositeType.checkForWellFormedGroupSizeEncoding
public void checkForWellFormedGroupSizeEncoding(final Node node) { final EncodedDataType blockLengthType = (EncodedDataType)containedTypeByNameMap.get("blockLength"); final EncodedDataType numInGroupType = (EncodedDataType)containedTypeByNameMap.get("numInGroup"); if (blockLengthType == null) { XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"blockLength\""); } else if (!isUnsigned(blockLengthType.primitiveType())) { XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned type"); } else { if (blockLengthType.primitiveType() != UINT8 && blockLengthType.primitiveType() != UINT16) { XmlSchemaParser.handleWarning(node, "\"blockLength\" should be UINT8 or UINT16"); } final PrimitiveValue blockLengthTypeMaxValue = blockLengthType.maxValue(); validateGroupMaxValue(node, blockLengthType.primitiveType(), blockLengthTypeMaxValue); } if (numInGroupType == null) { XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"numInGroup\""); } else if (!isUnsigned(numInGroupType.primitiveType())) { XmlSchemaParser.handleWarning(node, "\"numInGroup\" should be unsigned type"); final PrimitiveValue numInGroupMinValue = numInGroupType.minValue(); if (null == numInGroupMinValue) { XmlSchemaParser.handleError(node, "\"numInGroup\" minValue must be set for signed types"); } else if (numInGroupMinValue.longValue() < 0) { XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s must be greater than zero " + "for signed \"numInGroup\" types", numInGroupMinValue)); } } else { if (numInGroupType.primitiveType() != UINT8 && numInGroupType.primitiveType() != UINT16) { XmlSchemaParser.handleWarning(node, "\"numInGroup\" should be UINT8 or UINT16"); } final PrimitiveValue numInGroupMaxValue = numInGroupType.maxValue(); validateGroupMaxValue(node, numInGroupType.primitiveType(), numInGroupMaxValue); final PrimitiveValue numInGroupMinValue = numInGroupType.minValue(); if (null != numInGroupMinValue) { final long max = numInGroupMaxValue != null ? numInGroupMaxValue.longValue() : numInGroupType.primitiveType().maxValue().longValue(); if (numInGroupMinValue.longValue() > max) { XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s greater than maxValue=%d", numInGroupMinValue, max)); } } } }
java
public void checkForWellFormedGroupSizeEncoding(final Node node) { final EncodedDataType blockLengthType = (EncodedDataType)containedTypeByNameMap.get("blockLength"); final EncodedDataType numInGroupType = (EncodedDataType)containedTypeByNameMap.get("numInGroup"); if (blockLengthType == null) { XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"blockLength\""); } else if (!isUnsigned(blockLengthType.primitiveType())) { XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned type"); } else { if (blockLengthType.primitiveType() != UINT8 && blockLengthType.primitiveType() != UINT16) { XmlSchemaParser.handleWarning(node, "\"blockLength\" should be UINT8 or UINT16"); } final PrimitiveValue blockLengthTypeMaxValue = blockLengthType.maxValue(); validateGroupMaxValue(node, blockLengthType.primitiveType(), blockLengthTypeMaxValue); } if (numInGroupType == null) { XmlSchemaParser.handleError(node, "composite for group encodedLength encoding must have \"numInGroup\""); } else if (!isUnsigned(numInGroupType.primitiveType())) { XmlSchemaParser.handleWarning(node, "\"numInGroup\" should be unsigned type"); final PrimitiveValue numInGroupMinValue = numInGroupType.minValue(); if (null == numInGroupMinValue) { XmlSchemaParser.handleError(node, "\"numInGroup\" minValue must be set for signed types"); } else if (numInGroupMinValue.longValue() < 0) { XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s must be greater than zero " + "for signed \"numInGroup\" types", numInGroupMinValue)); } } else { if (numInGroupType.primitiveType() != UINT8 && numInGroupType.primitiveType() != UINT16) { XmlSchemaParser.handleWarning(node, "\"numInGroup\" should be UINT8 or UINT16"); } final PrimitiveValue numInGroupMaxValue = numInGroupType.maxValue(); validateGroupMaxValue(node, numInGroupType.primitiveType(), numInGroupMaxValue); final PrimitiveValue numInGroupMinValue = numInGroupType.minValue(); if (null != numInGroupMinValue) { final long max = numInGroupMaxValue != null ? numInGroupMaxValue.longValue() : numInGroupType.primitiveType().maxValue().longValue(); if (numInGroupMinValue.longValue() > max) { XmlSchemaParser.handleError(node, String.format( "\"numInGroup\" minValue=%s greater than maxValue=%d", numInGroupMinValue, max)); } } } }
[ "public", "void", "checkForWellFormedGroupSizeEncoding", "(", "final", "Node", "node", ")", "{", "final", "EncodedDataType", "blockLengthType", "=", "(", "EncodedDataType", ")", "containedTypeByNameMap", ".", "get", "(", "\"blockLength\"", ")", ";", "final", "EncodedD...
Check the composite for being a well formed group encodedLength encoding. This means that there are the fields "blockLength" and "numInGroup" present. @param node of the XML for this composite
[ "Check", "the", "composite", "for", "being", "a", "well", "formed", "group", "encodedLength", "encoding", ".", "This", "means", "that", "there", "are", "the", "fields", "blockLength", "and", "numInGroup", "present", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java#L161-L227
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java
CompositeType.checkForWellFormedVariableLengthDataEncoding
public void checkForWellFormedVariableLengthDataEncoding(final Node node) { final EncodedDataType lengthType = (EncodedDataType)containedTypeByNameMap.get("length"); if (lengthType == null) { XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"length\""); } else { final PrimitiveType primitiveType = lengthType.primitiveType(); if (!isUnsigned(primitiveType)) { XmlSchemaParser.handleError(node, "\"length\" must be unsigned type"); } else if (primitiveType != UINT8 && primitiveType != UINT16 && primitiveType != UINT32) { XmlSchemaParser.handleWarning(node, "\"length\" should be UINT8, UINT16, or UINT32"); } validateGroupMaxValue(node, primitiveType, lengthType.maxValue()); } if ("optional".equals(getAttributeValueOrNull(node, "presence"))) { XmlSchemaParser.handleError( node, "composite for variable length data encoding cannot have presence=\"optional\""); } if (containedTypeByNameMap.get("varData") == null) { XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"varData\""); } }
java
public void checkForWellFormedVariableLengthDataEncoding(final Node node) { final EncodedDataType lengthType = (EncodedDataType)containedTypeByNameMap.get("length"); if (lengthType == null) { XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"length\""); } else { final PrimitiveType primitiveType = lengthType.primitiveType(); if (!isUnsigned(primitiveType)) { XmlSchemaParser.handleError(node, "\"length\" must be unsigned type"); } else if (primitiveType != UINT8 && primitiveType != UINT16 && primitiveType != UINT32) { XmlSchemaParser.handleWarning(node, "\"length\" should be UINT8, UINT16, or UINT32"); } validateGroupMaxValue(node, primitiveType, lengthType.maxValue()); } if ("optional".equals(getAttributeValueOrNull(node, "presence"))) { XmlSchemaParser.handleError( node, "composite for variable length data encoding cannot have presence=\"optional\""); } if (containedTypeByNameMap.get("varData") == null) { XmlSchemaParser.handleError(node, "composite for variable length data encoding must have \"varData\""); } }
[ "public", "void", "checkForWellFormedVariableLengthDataEncoding", "(", "final", "Node", "node", ")", "{", "final", "EncodedDataType", "lengthType", "=", "(", "EncodedDataType", ")", "containedTypeByNameMap", ".", "get", "(", "\"length\"", ")", ";", "if", "(", "lengt...
Check the composite for being a well formed variable length data encoding. This means that there are the fields "length" and "varData" present. @param node of the XML for this composite
[ "Check", "the", "composite", "for", "being", "a", "well", "formed", "variable", "length", "data", "encoding", ".", "This", "means", "that", "there", "are", "the", "fields", "length", "and", "varData", "present", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java#L235-L268
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java
CompositeType.checkForWellFormedMessageHeader
public void checkForWellFormedMessageHeader(final Node node) { final boolean shouldGenerateInterfaces = Boolean.getBoolean(JAVA_GENERATE_INTERFACES); final EncodedDataType blockLengthType = (EncodedDataType)containedTypeByNameMap.get("blockLength"); final EncodedDataType templateIdType = (EncodedDataType)containedTypeByNameMap.get("templateId"); final EncodedDataType schemaIdType = (EncodedDataType)containedTypeByNameMap.get("schemaId"); final EncodedDataType versionType = (EncodedDataType)containedTypeByNameMap.get("version"); if (blockLengthType == null) { XmlSchemaParser.handleError(node, "composite for message header must have \"blockLength\""); } else if (!isUnsigned(blockLengthType.primitiveType())) { XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned"); } validateHeaderField(node, "blockLength", blockLengthType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "templateId", templateIdType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "schemaId", schemaIdType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "version", versionType, UINT16, shouldGenerateInterfaces); }
java
public void checkForWellFormedMessageHeader(final Node node) { final boolean shouldGenerateInterfaces = Boolean.getBoolean(JAVA_GENERATE_INTERFACES); final EncodedDataType blockLengthType = (EncodedDataType)containedTypeByNameMap.get("blockLength"); final EncodedDataType templateIdType = (EncodedDataType)containedTypeByNameMap.get("templateId"); final EncodedDataType schemaIdType = (EncodedDataType)containedTypeByNameMap.get("schemaId"); final EncodedDataType versionType = (EncodedDataType)containedTypeByNameMap.get("version"); if (blockLengthType == null) { XmlSchemaParser.handleError(node, "composite for message header must have \"blockLength\""); } else if (!isUnsigned(blockLengthType.primitiveType())) { XmlSchemaParser.handleError(node, "\"blockLength\" must be unsigned"); } validateHeaderField(node, "blockLength", blockLengthType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "templateId", templateIdType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "schemaId", schemaIdType, UINT16, shouldGenerateInterfaces); validateHeaderField(node, "version", versionType, UINT16, shouldGenerateInterfaces); }
[ "public", "void", "checkForWellFormedMessageHeader", "(", "final", "Node", "node", ")", "{", "final", "boolean", "shouldGenerateInterfaces", "=", "Boolean", ".", "getBoolean", "(", "JAVA_GENERATE_INTERFACES", ")", ";", "final", "EncodedDataType", "blockLengthType", "=",...
Check the composite for being a well formed message headerStructure encoding. This means that there are the fields "blockLength", "templateId" and "version" present. @param node of the XML for this composite
[ "Check", "the", "composite", "for", "being", "a", "well", "formed", "message", "headerStructure", "encoding", ".", "This", "means", "that", "there", "are", "the", "fields", "blockLength", "templateId", "and", "version", "present", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java#L304-L326
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java
CompositeType.checkForValidOffsets
public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
java
public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
[ "public", "void", "checkForValidOffsets", "(", "final", "Node", "node", ")", "{", "int", "offset", "=", "0", ";", "for", "(", "final", "Type", "edt", ":", "containedTypeByNameMap", ".", "values", "(", ")", ")", "{", "final", "int", "offsetAttribute", "=", ...
Check the composite for any specified offsets and validate they are correctly specified. @param node of the XML for this composite
[ "Check", "the", "composite", "for", "any", "specified", "offsets", "and", "validate", "they", "are", "correctly", "specified", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/CompositeType.java#L374-L396
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/Generators.java
Generators.findFirst
public static Token findFirst(final String name, final List<Token> tokens, final int index) { for (int i = index, size = tokens.size(); i < size; i++) { final Token token = tokens.get(i); if (token.name().equals(name)) { return token; } } throw new IllegalStateException("name not found: " + name); }
java
public static Token findFirst(final String name, final List<Token> tokens, final int index) { for (int i = index, size = tokens.size(); i < size; i++) { final Token token = tokens.get(i); if (token.name().equals(name)) { return token; } } throw new IllegalStateException("name not found: " + name); }
[ "public", "static", "Token", "findFirst", "(", "final", "String", "name", ",", "final", "List", "<", "Token", ">", "tokens", ",", "final", "int", "index", ")", "{", "for", "(", "int", "i", "=", "index", ",", "size", "=", "tokens", ".", "size", "(", ...
Find the first token with a given name from an index inclusive. @param name to search for. @param tokens to search. @param index from which to search. @return first found {@link Token} or throw a {@link IllegalStateException} if not found.
[ "Find", "the", "first", "token", "with", "a", "given", "name", "from", "an", "index", "inclusive", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/Generators.java#L91-L103
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java
OtfHeaderDecoder.getTemplateId
public int getTemplateId(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + templateIdOffset, templateIdType, templateIdByteOrder); }
java
public int getTemplateId(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + templateIdOffset, templateIdType, templateIdByteOrder); }
[ "public", "int", "getTemplateId", "(", "final", "DirectBuffer", "buffer", ",", "final", "int", "bufferOffset", ")", "{", "return", "Types", ".", "getInt", "(", "buffer", ",", "bufferOffset", "+", "templateIdOffset", ",", "templateIdType", ",", "templateIdByteOrder...
Get the template id from the message header. @param buffer from which to read the value. @param bufferOffset in the buffer at which the message header begins. @return the value of the template id.
[ "Get", "the", "template", "id", "from", "the", "message", "header", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java#L106-L109
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java
OtfHeaderDecoder.getSchemaId
public int getSchemaId(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + schemaIdOffset, schemaIdType, schemaIdByteOrder); }
java
public int getSchemaId(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + schemaIdOffset, schemaIdType, schemaIdByteOrder); }
[ "public", "int", "getSchemaId", "(", "final", "DirectBuffer", "buffer", ",", "final", "int", "bufferOffset", ")", "{", "return", "Types", ".", "getInt", "(", "buffer", ",", "bufferOffset", "+", "schemaIdOffset", ",", "schemaIdType", ",", "schemaIdByteOrder", ")"...
Get the schema id number from the message header. @param buffer from which to read the value. @param bufferOffset in the buffer at which the message header begins. @return the value of the schema id number.
[ "Get", "the", "schema", "id", "number", "from", "the", "message", "header", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java#L118-L121
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java
OtfHeaderDecoder.getSchemaVersion
public int getSchemaVersion(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + schemaVersionOffset, schemaVersionType, schemaVersionByteOrder); }
java
public int getSchemaVersion(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + schemaVersionOffset, schemaVersionType, schemaVersionByteOrder); }
[ "public", "int", "getSchemaVersion", "(", "final", "DirectBuffer", "buffer", ",", "final", "int", "bufferOffset", ")", "{", "return", "Types", ".", "getInt", "(", "buffer", ",", "bufferOffset", "+", "schemaVersionOffset", ",", "schemaVersionType", ",", "schemaVers...
Get the schema version number from the message header. @param buffer from which to read the value. @param bufferOffset in the buffer at which the message header begins. @return the value of the schema version number.
[ "Get", "the", "schema", "version", "number", "from", "the", "message", "header", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java#L130-L133
train
real-logic/simple-binary-encoding
sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java
OtfHeaderDecoder.getBlockLength
public int getBlockLength(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + blockLengthOffset, blockLengthType, blockLengthByteOrder); }
java
public int getBlockLength(final DirectBuffer buffer, final int bufferOffset) { return Types.getInt(buffer, bufferOffset + blockLengthOffset, blockLengthType, blockLengthByteOrder); }
[ "public", "int", "getBlockLength", "(", "final", "DirectBuffer", "buffer", ",", "final", "int", "bufferOffset", ")", "{", "return", "Types", ".", "getInt", "(", "buffer", ",", "bufferOffset", "+", "blockLengthOffset", ",", "blockLengthType", ",", "blockLengthByteO...
Get the block length of the root block in the message. @param buffer from which to read the value. @param bufferOffset in the buffer at which the message header begins. @return the length of the root block in the coming message.
[ "Get", "the", "block", "length", "of", "the", "root", "block", "in", "the", "message", "." ]
9a7be490c86d98f0e430e4189bc6c8c4fbef658b
https://github.com/real-logic/simple-binary-encoding/blob/9a7be490c86d98f0e430e4189bc6c8c4fbef658b/sbe-tool/src/main/java/uk/co/real_logic/sbe/otf/OtfHeaderDecoder.java#L142-L145
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.initialize
public static void initialize(AlbumConfig albumConfig) { if (sAlbumConfig == null) sAlbumConfig = albumConfig; else Log.w("Album", new IllegalStateException("Illegal operation, only allowed to configure once.")); }
java
public static void initialize(AlbumConfig albumConfig) { if (sAlbumConfig == null) sAlbumConfig = albumConfig; else Log.w("Album", new IllegalStateException("Illegal operation, only allowed to configure once.")); }
[ "public", "static", "void", "initialize", "(", "AlbumConfig", "albumConfig", ")", "{", "if", "(", "sAlbumConfig", "==", "null", ")", "sAlbumConfig", "=", "albumConfig", ";", "else", "Log", ".", "w", "(", "\"Album\"", ",", "new", "IllegalStateException", "(", ...
Initialize Album. @param albumConfig {@link AlbumConfig}.
[ "Initialize", "Album", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L106-L109
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.getAlbumConfig
public static AlbumConfig getAlbumConfig() { if (sAlbumConfig == null) { sAlbumConfig = AlbumConfig.newBuilder(null).build(); } return sAlbumConfig; }
java
public static AlbumConfig getAlbumConfig() { if (sAlbumConfig == null) { sAlbumConfig = AlbumConfig.newBuilder(null).build(); } return sAlbumConfig; }
[ "public", "static", "AlbumConfig", "getAlbumConfig", "(", ")", "{", "if", "(", "sAlbumConfig", "==", "null", ")", "{", "sAlbumConfig", "=", "AlbumConfig", ".", "newBuilder", "(", "null", ")", ".", "build", "(", ")", ";", "}", "return", "sAlbumConfig", ";",...
Get the album configuration.
[ "Get", "the", "album", "configuration", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L114-L119
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.camera
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(android.support.v4.app.Fragment fragment) { return new AlbumCamera(fragment.getContext()); }
java
public static Camera<ImageCameraWrapper, VideoCameraWrapper> camera(android.support.v4.app.Fragment fragment) { return new AlbumCamera(fragment.getContext()); }
[ "public", "static", "Camera", "<", "ImageCameraWrapper", ",", "VideoCameraWrapper", ">", "camera", "(", "android", ".", "support", ".", "v4", ".", "app", ".", "Fragment", "fragment", ")", "{", "return", "new", "AlbumCamera", "(", "fragment", ".", "getContext",...
Open the camera from the activity.
[ "Open", "the", "camera", "from", "the", "activity", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L250-L252
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.image
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(android.support.v4.app.Fragment fragment) { return new ImageChoice(fragment.getContext()); }
java
public static Choice<ImageMultipleWrapper, ImageSingleWrapper> image(android.support.v4.app.Fragment fragment) { return new ImageChoice(fragment.getContext()); }
[ "public", "static", "Choice", "<", "ImageMultipleWrapper", ",", "ImageSingleWrapper", ">", "image", "(", "android", ".", "support", ".", "v4", ".", "app", ".", "Fragment", "fragment", ")", "{", "return", "new", "ImageChoice", "(", "fragment", ".", "getContext"...
Select images.
[ "Select", "images", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L257-L259
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.video
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(android.support.v4.app.Fragment fragment) { return new VideoChoice(fragment.getContext()); }
java
public static Choice<VideoMultipleWrapper, VideoSingleWrapper> video(android.support.v4.app.Fragment fragment) { return new VideoChoice(fragment.getContext()); }
[ "public", "static", "Choice", "<", "VideoMultipleWrapper", ",", "VideoSingleWrapper", ">", "video", "(", "android", ".", "support", ".", "v4", ".", "app", ".", "Fragment", "fragment", ")", "{", "return", "new", "VideoChoice", "(", "fragment", ".", "getContext"...
Select videos.
[ "Select", "videos", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L264-L266
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/Album.java
Album.album
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(android.support.v4.app.Fragment fragment) { return new AlbumChoice(fragment.getContext()); }
java
public static Choice<AlbumMultipleWrapper, AlbumSingleWrapper> album(android.support.v4.app.Fragment fragment) { return new AlbumChoice(fragment.getContext()); }
[ "public", "static", "Choice", "<", "AlbumMultipleWrapper", ",", "AlbumSingleWrapper", ">", "album", "(", "android", ".", "support", ".", "v4", ".", "app", ".", "Fragment", "fragment", ")", "{", "return", "new", "AlbumChoice", "(", "fragment", ".", "getContext"...
Select images and videos.
[ "Select", "images", "and", "videos", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/Album.java#L271-L273
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/data/MediaReader.java
MediaReader.getAllVideo
@WorkerThread public ArrayList<AlbumFolder> getAllVideo() { Map<String, AlbumFolder> albumFolderMap = new HashMap<>(); AlbumFolder allFileFolder = new AlbumFolder(); allFileFolder.setChecked(true); allFileFolder.setName(mContext.getString(R.string.album_all_videos)); scanVideoFile(albumFolderMap, allFileFolder); ArrayList<AlbumFolder> albumFolders = new ArrayList<>(); Collections.sort(allFileFolder.getAlbumFiles()); albumFolders.add(allFileFolder); for (Map.Entry<String, AlbumFolder> folderEntry : albumFolderMap.entrySet()) { AlbumFolder albumFolder = folderEntry.getValue(); Collections.sort(albumFolder.getAlbumFiles()); albumFolders.add(albumFolder); } return albumFolders; }
java
@WorkerThread public ArrayList<AlbumFolder> getAllVideo() { Map<String, AlbumFolder> albumFolderMap = new HashMap<>(); AlbumFolder allFileFolder = new AlbumFolder(); allFileFolder.setChecked(true); allFileFolder.setName(mContext.getString(R.string.album_all_videos)); scanVideoFile(albumFolderMap, allFileFolder); ArrayList<AlbumFolder> albumFolders = new ArrayList<>(); Collections.sort(allFileFolder.getAlbumFiles()); albumFolders.add(allFileFolder); for (Map.Entry<String, AlbumFolder> folderEntry : albumFolderMap.entrySet()) { AlbumFolder albumFolder = folderEntry.getValue(); Collections.sort(albumFolder.getAlbumFiles()); albumFolders.add(albumFolder); } return albumFolders; }
[ "@", "WorkerThread", "public", "ArrayList", "<", "AlbumFolder", ">", "getAllVideo", "(", ")", "{", "Map", "<", "String", ",", "AlbumFolder", ">", "albumFolderMap", "=", "new", "HashMap", "<>", "(", ")", ";", "AlbumFolder", "allFileFolder", "=", "new", "Album...
Scan the list of videos in the library.
[ "Scan", "the", "list", "of", "videos", "in", "the", "library", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/data/MediaReader.java#L231-L250
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/widget/LoadingDialog.java
LoadingDialog.setupViews
public void setupViews(Widget widget) { if (widget.getUiStyle() == Widget.STYLE_LIGHT) { int color = ContextCompat.getColor(getContext(), R.color.albumLoadingDark); mProgressBar.setColorFilter(color); } else { mProgressBar.setColorFilter(widget.getToolBarColor()); } }
java
public void setupViews(Widget widget) { if (widget.getUiStyle() == Widget.STYLE_LIGHT) { int color = ContextCompat.getColor(getContext(), R.color.albumLoadingDark); mProgressBar.setColorFilter(color); } else { mProgressBar.setColorFilter(widget.getToolBarColor()); } }
[ "public", "void", "setupViews", "(", "Widget", "widget", ")", "{", "if", "(", "widget", ".", "getUiStyle", "(", ")", "==", "Widget", ".", "STYLE_LIGHT", ")", "{", "int", "color", "=", "ContextCompat", ".", "getColor", "(", "getContext", "(", ")", ",", ...
Set some properties of the view. @param widget widget.
[ "Set", "some", "properties", "of", "the", "view", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/widget/LoadingDialog.java#L50-L57
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/api/BasicGalleryWrapper.java
BasicGalleryWrapper.currentPosition
public Returner currentPosition(@IntRange(from = 0, to = Integer.MAX_VALUE) int currentPosition) { this.mCurrentPosition = currentPosition; return (Returner) this; }
java
public Returner currentPosition(@IntRange(from = 0, to = Integer.MAX_VALUE) int currentPosition) { this.mCurrentPosition = currentPosition; return (Returner) this; }
[ "public", "Returner", "currentPosition", "(", "@", "IntRange", "(", "from", "=", "0", ",", "to", "=", "Integer", ".", "MAX_VALUE", ")", "int", "currentPosition", ")", "{", "this", ".", "mCurrentPosition", "=", "currentPosition", ";", "return", "(", "Returner...
Set the show position of List. @param currentPosition the current position.
[ "Set", "the", "show", "position", "of", "List", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/api/BasicGalleryWrapper.java#L75-L78
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/SystemBar.java
SystemBar.invasionStatusBar
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static void invasionStatusBar(Window window) { View decorView = window.getDecorView(); decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.setStatusBarColor(Color.TRANSPARENT); }
java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static void invasionStatusBar(Window window) { View decorView = window.getDecorView(); decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.setStatusBarColor(Color.TRANSPARENT); }
[ "@", "RequiresApi", "(", "api", "=", "Build", ".", "VERSION_CODES", ".", "LOLLIPOP", ")", "public", "static", "void", "invasionStatusBar", "(", "Window", "window", ")", "{", "View", "decorView", "=", "window", ".", "getDecorView", "(", ")", ";", "decorView",...
Set the content layout full the StatusBar, but do not hide StatusBar.
[ "Set", "the", "content", "layout", "full", "the", "StatusBar", "but", "do", "not", "hide", "StatusBar", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/SystemBar.java#L76-L83
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/SystemBar.java
SystemBar.setStatusBarDarkFont
public static boolean setStatusBarDarkFont(Window window, boolean darkFont) { if (setMIUIStatusBarFont(window, darkFont)) { setDefaultStatusBarFont(window, darkFont); return true; } else if (setMeizuStatusBarFont(window, darkFont)) { setDefaultStatusBarFont(window, darkFont); return true; } else { return setDefaultStatusBarFont(window, darkFont); } }
java
public static boolean setStatusBarDarkFont(Window window, boolean darkFont) { if (setMIUIStatusBarFont(window, darkFont)) { setDefaultStatusBarFont(window, darkFont); return true; } else if (setMeizuStatusBarFont(window, darkFont)) { setDefaultStatusBarFont(window, darkFont); return true; } else { return setDefaultStatusBarFont(window, darkFont); } }
[ "public", "static", "boolean", "setStatusBarDarkFont", "(", "Window", "window", ",", "boolean", "darkFont", ")", "{", "if", "(", "setMIUIStatusBarFont", "(", "window", ",", "darkFont", ")", ")", "{", "setDefaultStatusBarFont", "(", "window", ",", "darkFont", ")"...
Set the status bar to dark.
[ "Set", "the", "status", "bar", "to", "dark", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/SystemBar.java#L114-L124
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/widget/photoview/PhotoViewAttacher.java
PhotoViewAttacher.setImageViewScaleTypeMatrix
private static void setImageViewScaleTypeMatrix(ImageView imageView) { /** * PhotoView sets its own ScaleType to Matrix, then diverts all calls * setScaleType to this.setScaleType automatically. */ if (null != imageView && !(imageView instanceof IPhotoView)) { if (!ScaleType.MATRIX.equals(imageView.getScaleType())) { imageView.setScaleType(ScaleType.MATRIX); } } }
java
private static void setImageViewScaleTypeMatrix(ImageView imageView) { /** * PhotoView sets its own ScaleType to Matrix, then diverts all calls * setScaleType to this.setScaleType automatically. */ if (null != imageView && !(imageView instanceof IPhotoView)) { if (!ScaleType.MATRIX.equals(imageView.getScaleType())) { imageView.setScaleType(ScaleType.MATRIX); } } }
[ "private", "static", "void", "setImageViewScaleTypeMatrix", "(", "ImageView", "imageView", ")", "{", "/**\n * PhotoView sets its own ScaleType to Matrix, then diverts all calls\n * setScaleType to this.setScaleType automatically.\n */", "if", "(", "null", "!=", "i...
Sets the ImageView's ScaleType to Matrix.
[ "Sets", "the", "ImageView", "s", "ScaleType", "to", "Matrix", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/widget/photoview/PhotoViewAttacher.java#L105-L115
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/widget/photoview/PhotoViewAttacher.java
PhotoViewAttacher.updateBaseMatrix
private void updateBaseMatrix(Drawable d) { ImageView imageView = getImageView(); if (null == imageView || null == d) { return; } final float viewWidth = getImageViewWidth(imageView); final float viewHeight = getImageViewHeight(imageView); final int drawableWidth = d.getIntrinsicWidth(); final int drawableHeight = d.getIntrinsicHeight(); mBaseMatrix.reset(); final float widthScale = viewWidth / drawableWidth; final float heightScale = viewHeight / drawableHeight; if (mScaleType == ScaleType.CENTER) { mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F); } else if (mScaleType == ScaleType.CENTER_CROP) { float scale = Math.max(widthScale, heightScale); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else if (mScaleType == ScaleType.CENTER_INSIDE) { float scale = Math.min(1.0f, Math.min(widthScale, heightScale)); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else { RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight); RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight); if ((int)mBaseRotation % 180 != 0) { mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth); } switch (mScaleType) { case FIT_CENTER: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER); break; case FIT_START: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START); break; case FIT_END: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END); break; case FIT_XY: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL); break; default: break; } } resetMatrix(); }
java
private void updateBaseMatrix(Drawable d) { ImageView imageView = getImageView(); if (null == imageView || null == d) { return; } final float viewWidth = getImageViewWidth(imageView); final float viewHeight = getImageViewHeight(imageView); final int drawableWidth = d.getIntrinsicWidth(); final int drawableHeight = d.getIntrinsicHeight(); mBaseMatrix.reset(); final float widthScale = viewWidth / drawableWidth; final float heightScale = viewHeight / drawableHeight; if (mScaleType == ScaleType.CENTER) { mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F); } else if (mScaleType == ScaleType.CENTER_CROP) { float scale = Math.max(widthScale, heightScale); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else if (mScaleType == ScaleType.CENTER_INSIDE) { float scale = Math.min(1.0f, Math.min(widthScale, heightScale)); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else { RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight); RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight); if ((int)mBaseRotation % 180 != 0) { mTempSrc = new RectF(0, 0, drawableHeight, drawableWidth); } switch (mScaleType) { case FIT_CENTER: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER); break; case FIT_START: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START); break; case FIT_END: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END); break; case FIT_XY: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL); break; default: break; } } resetMatrix(); }
[ "private", "void", "updateBaseMatrix", "(", "Drawable", "d", ")", "{", "ImageView", "imageView", "=", "getImageView", "(", ")", ";", "if", "(", "null", "==", "imageView", "||", "null", "==", "d", ")", "{", "return", ";", "}", "final", "float", "viewWidth...
Calculate Matrix for FIT_CENTER @param d - Drawable being displayed
[ "Calculate", "Matrix", "for", "FIT_CENTER" ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/widget/photoview/PhotoViewAttacher.java#L838-L900
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/api/widget/Widget.java
Widget.getDefaultWidget
public static Widget getDefaultWidget(Context context) { return Widget.newDarkBuilder(context) .statusBarColor(ContextCompat.getColor(context, R.color.albumColorPrimaryDark)) .toolBarColor(ContextCompat.getColor(context, R.color.albumColorPrimary)) .navigationBarColor(ContextCompat.getColor(context, R.color.albumColorPrimaryBlack)) .title(R.string.album_title) .mediaItemCheckSelector(ContextCompat.getColor(context, R.color.albumSelectorNormal), ContextCompat.getColor(context, R.color.albumColorPrimary)) .bucketItemCheckSelector(ContextCompat.getColor(context, R.color.albumSelectorNormal), ContextCompat.getColor(context, R.color.albumColorPrimary)) .buttonStyle( ButtonStyle.newDarkBuilder(context) .setButtonSelector(ContextCompat.getColor(context, R.color.albumColorPrimary), ContextCompat.getColor(context, R.color.albumColorPrimaryDark)) .build() ) .build(); }
java
public static Widget getDefaultWidget(Context context) { return Widget.newDarkBuilder(context) .statusBarColor(ContextCompat.getColor(context, R.color.albumColorPrimaryDark)) .toolBarColor(ContextCompat.getColor(context, R.color.albumColorPrimary)) .navigationBarColor(ContextCompat.getColor(context, R.color.albumColorPrimaryBlack)) .title(R.string.album_title) .mediaItemCheckSelector(ContextCompat.getColor(context, R.color.albumSelectorNormal), ContextCompat.getColor(context, R.color.albumColorPrimary)) .bucketItemCheckSelector(ContextCompat.getColor(context, R.color.albumSelectorNormal), ContextCompat.getColor(context, R.color.albumColorPrimary)) .buttonStyle( ButtonStyle.newDarkBuilder(context) .setButtonSelector(ContextCompat.getColor(context, R.color.albumColorPrimary), ContextCompat.getColor(context, R.color.albumColorPrimaryDark)) .build() ) .build(); }
[ "public", "static", "Widget", "getDefaultWidget", "(", "Context", "context", ")", "{", "return", "Widget", ".", "newDarkBuilder", "(", "context", ")", ".", "statusBarColor", "(", "ContextCompat", ".", "getColor", "(", "context", ",", "R", ".", "color", ".", ...
Create default widget.
[ "Create", "default", "widget", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/api/widget/Widget.java#L348-L365
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java
AlbumActivity.createView
private int createView() { switch (mWidget.getUiStyle()) { case Widget.STYLE_DARK: { return R.layout.album_activity_album_dark; } case Widget.STYLE_LIGHT: { return R.layout.album_activity_album_light; } default: { throw new AssertionError("This should not be the case."); } } }
java
private int createView() { switch (mWidget.getUiStyle()) { case Widget.STYLE_DARK: { return R.layout.album_activity_album_dark; } case Widget.STYLE_LIGHT: { return R.layout.album_activity_album_light; } default: { throw new AssertionError("This should not be the case."); } } }
[ "private", "int", "createView", "(", ")", "{", "switch", "(", "mWidget", ".", "getUiStyle", "(", ")", ")", "{", "case", "Widget", ".", "STYLE_DARK", ":", "{", "return", "R", ".", "layout", ".", "album_activity_album_dark", ";", "}", "case", "Widget", "."...
Use different layouts depending on the style. @return layout id.
[ "Use", "different", "layouts", "depending", "on", "the", "style", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java#L134-L146
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java
AlbumActivity.showFolderAlbumFiles
private void showFolderAlbumFiles(int position) { this.mCurrentFolder = position; AlbumFolder albumFolder = mAlbumFolders.get(position); mView.bindAlbumFolder(albumFolder); }
java
private void showFolderAlbumFiles(int position) { this.mCurrentFolder = position; AlbumFolder albumFolder = mAlbumFolders.get(position); mView.bindAlbumFolder(albumFolder); }
[ "private", "void", "showFolderAlbumFiles", "(", "int", "position", ")", "{", "this", ".", "mCurrentFolder", "=", "position", ";", "AlbumFolder", "albumFolder", "=", "mAlbumFolders", ".", "get", "(", "position", ")", ";", "mView", ".", "bindAlbumFolder", "(", "...
Update data source.
[ "Update", "data", "source", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java#L244-L248
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java
AlbumActivity.showLoadingDialog
private void showLoadingDialog() { if (mLoadingDialog == null) { mLoadingDialog = new LoadingDialog(this); mLoadingDialog.setupViews(mWidget); } if (!mLoadingDialog.isShowing()) { mLoadingDialog.show(); } }
java
private void showLoadingDialog() { if (mLoadingDialog == null) { mLoadingDialog = new LoadingDialog(this); mLoadingDialog.setupViews(mWidget); } if (!mLoadingDialog.isShowing()) { mLoadingDialog.show(); } }
[ "private", "void", "showLoadingDialog", "(", ")", "{", "if", "(", "mLoadingDialog", "==", "null", ")", "{", "mLoadingDialog", "=", "new", "LoadingDialog", "(", "this", ")", ";", "mLoadingDialog", ".", "setupViews", "(", "mWidget", ")", ";", "}", "if", "(",...
Display loading dialog.
[ "Display", "loading", "dialog", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/AlbumActivity.java#L583-L591
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/api/VideoMultipleWrapper.java
VideoMultipleWrapper.selectCount
public VideoMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) { this.mLimitCount = count; return this; }
java
public VideoMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) { this.mLimitCount = count; return this; }
[ "public", "VideoMultipleWrapper", "selectCount", "(", "@", "IntRange", "(", "from", "=", "1", ",", "to", "=", "Integer", ".", "MAX_VALUE", ")", "int", "count", ")", "{", "this", ".", "mLimitCount", "=", "count", ";", "return", "this", ";", "}" ]
Set the maximum number to be selected. @param count the maximum number.
[ "Set", "the", "maximum", "number", "to", "be", "selected", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/api/VideoMultipleWrapper.java#L56-L59
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/mvp/BaseActivity.java
BaseActivity.requestPermission
protected void requestPermission(String[] permissions, int code) { if (Build.VERSION.SDK_INT >= 23) { List<String> deniedPermissions = getDeniedPermissions(this, permissions); if (deniedPermissions.isEmpty()) { onPermissionGranted(code); } else { permissions = new String[deniedPermissions.size()]; deniedPermissions.toArray(permissions); ActivityCompat.requestPermissions(this, permissions, code); } } else { onPermissionGranted(code); } }
java
protected void requestPermission(String[] permissions, int code) { if (Build.VERSION.SDK_INT >= 23) { List<String> deniedPermissions = getDeniedPermissions(this, permissions); if (deniedPermissions.isEmpty()) { onPermissionGranted(code); } else { permissions = new String[deniedPermissions.size()]; deniedPermissions.toArray(permissions); ActivityCompat.requestPermissions(this, permissions, code); } } else { onPermissionGranted(code); } }
[ "protected", "void", "requestPermission", "(", "String", "[", "]", "permissions", ",", "int", "code", ")", "{", "if", "(", "Build", ".", "VERSION", ".", "SDK_INT", ">=", "23", ")", "{", "List", "<", "String", ">", "deniedPermissions", "=", "getDeniedPermis...
Request permission.
[ "Request", "permission", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/mvp/BaseActivity.java#L54-L67
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java
ThumbnailBuilder.createThumbnailForImage
@WorkerThread @Nullable public String createThumbnailForImage(String imagePath) { if (TextUtils.isEmpty(imagePath)) return null; File inFile = new File(imagePath); if (!inFile.exists()) return null; File thumbnailFile = randomPath(imagePath); if (thumbnailFile.exists()) return thumbnailFile.getAbsolutePath(); Bitmap inBitmap = readImageFromPath(imagePath, THUMBNAIL_SIZE, THUMBNAIL_SIZE); if (inBitmap == null) return null; ByteArrayOutputStream compressStream = new ByteArrayOutputStream(); inBitmap.compress(Bitmap.CompressFormat.JPEG, THUMBNAIL_QUALITY, compressStream); try { compressStream.close(); thumbnailFile.createNewFile(); FileOutputStream writeStream = new FileOutputStream(thumbnailFile); writeStream.write(compressStream.toByteArray()); writeStream.flush(); writeStream.close(); return thumbnailFile.getAbsolutePath(); } catch (Exception ignored) { return null; } }
java
@WorkerThread @Nullable public String createThumbnailForImage(String imagePath) { if (TextUtils.isEmpty(imagePath)) return null; File inFile = new File(imagePath); if (!inFile.exists()) return null; File thumbnailFile = randomPath(imagePath); if (thumbnailFile.exists()) return thumbnailFile.getAbsolutePath(); Bitmap inBitmap = readImageFromPath(imagePath, THUMBNAIL_SIZE, THUMBNAIL_SIZE); if (inBitmap == null) return null; ByteArrayOutputStream compressStream = new ByteArrayOutputStream(); inBitmap.compress(Bitmap.CompressFormat.JPEG, THUMBNAIL_QUALITY, compressStream); try { compressStream.close(); thumbnailFile.createNewFile(); FileOutputStream writeStream = new FileOutputStream(thumbnailFile); writeStream.write(compressStream.toByteArray()); writeStream.flush(); writeStream.close(); return thumbnailFile.getAbsolutePath(); } catch (Exception ignored) { return null; } }
[ "@", "WorkerThread", "@", "Nullable", "public", "String", "createThumbnailForImage", "(", "String", "imagePath", ")", "{", "if", "(", "TextUtils", ".", "isEmpty", "(", "imagePath", ")", ")", "return", "null", ";", "File", "inFile", "=", "new", "File", "(", ...
Create a thumbnail for the image. @param imagePath image path. @return thumbnail path.
[ "Create", "a", "thumbnail", "for", "the", "image", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java#L60-L89
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java
ThumbnailBuilder.createThumbnailForVideo
@WorkerThread @Nullable public String createThumbnailForVideo(String videoPath) { if (TextUtils.isEmpty(videoPath)) return null; File thumbnailFile = randomPath(videoPath); if (thumbnailFile.exists()) return thumbnailFile.getAbsolutePath(); try { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); if (URLUtil.isNetworkUrl(videoPath)) { retriever.setDataSource(videoPath, new HashMap<String, String>()); } else { retriever.setDataSource(videoPath); } Bitmap bitmap = retriever.getFrameAtTime(); thumbnailFile.createNewFile(); bitmap.compress(Bitmap.CompressFormat.JPEG, THUMBNAIL_QUALITY, new FileOutputStream(thumbnailFile)); return thumbnailFile.getAbsolutePath(); } catch (Exception ignored) { return null; } }
java
@WorkerThread @Nullable public String createThumbnailForVideo(String videoPath) { if (TextUtils.isEmpty(videoPath)) return null; File thumbnailFile = randomPath(videoPath); if (thumbnailFile.exists()) return thumbnailFile.getAbsolutePath(); try { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); if (URLUtil.isNetworkUrl(videoPath)) { retriever.setDataSource(videoPath, new HashMap<String, String>()); } else { retriever.setDataSource(videoPath); } Bitmap bitmap = retriever.getFrameAtTime(); thumbnailFile.createNewFile(); bitmap.compress(Bitmap.CompressFormat.JPEG, THUMBNAIL_QUALITY, new FileOutputStream(thumbnailFile)); return thumbnailFile.getAbsolutePath(); } catch (Exception ignored) { return null; } }
[ "@", "WorkerThread", "@", "Nullable", "public", "String", "createThumbnailForVideo", "(", "String", "videoPath", ")", "{", "if", "(", "TextUtils", ".", "isEmpty", "(", "videoPath", ")", ")", "return", "null", ";", "File", "thumbnailFile", "=", "randomPath", "(...
Create a thumbnail for the video. @param videoPath video path. @return thumbnail path.
[ "Create", "a", "thumbnail", "for", "the", "video", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java#L97-L119
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java
ThumbnailBuilder.readImageFromPath
@Nullable public static Bitmap readImageFromPath(String imagePath, int width, int height) { File imageFile = new File(imagePath); if (imageFile.exists()) { try { BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(imageFile)); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); options.inJustDecodeBounds = false; options.inSampleSize = computeSampleSize(options, width, height); Bitmap sampledBitmap = null; boolean attemptSuccess = false; while (!attemptSuccess) { inputStream = new BufferedInputStream(new FileInputStream(imageFile)); try { sampledBitmap = BitmapFactory.decodeStream(inputStream, null, options); attemptSuccess = true; } catch (Exception e) { options.inSampleSize *= 2; } inputStream.close(); } String lowerPath = imagePath.toLowerCase(); if (lowerPath.endsWith(".jpg") || lowerPath.endsWith(".jpeg")) { int degrees = computeDegree(imagePath); if (degrees > 0) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); Bitmap newBitmap = Bitmap.createBitmap(sampledBitmap, 0, 0, sampledBitmap.getWidth(), sampledBitmap.getHeight(), matrix, true); if (newBitmap != sampledBitmap) { sampledBitmap.recycle(); sampledBitmap = newBitmap; } } } return sampledBitmap; } catch (Exception ignored) { } } return null; }
java
@Nullable public static Bitmap readImageFromPath(String imagePath, int width, int height) { File imageFile = new File(imagePath); if (imageFile.exists()) { try { BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(imageFile)); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); options.inJustDecodeBounds = false; options.inSampleSize = computeSampleSize(options, width, height); Bitmap sampledBitmap = null; boolean attemptSuccess = false; while (!attemptSuccess) { inputStream = new BufferedInputStream(new FileInputStream(imageFile)); try { sampledBitmap = BitmapFactory.decodeStream(inputStream, null, options); attemptSuccess = true; } catch (Exception e) { options.inSampleSize *= 2; } inputStream.close(); } String lowerPath = imagePath.toLowerCase(); if (lowerPath.endsWith(".jpg") || lowerPath.endsWith(".jpeg")) { int degrees = computeDegree(imagePath); if (degrees > 0) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); Bitmap newBitmap = Bitmap.createBitmap(sampledBitmap, 0, 0, sampledBitmap.getWidth(), sampledBitmap.getHeight(), matrix, true); if (newBitmap != sampledBitmap) { sampledBitmap.recycle(); sampledBitmap = newBitmap; } } } return sampledBitmap; } catch (Exception ignored) { } } return null; }
[ "@", "Nullable", "public", "static", "Bitmap", "readImageFromPath", "(", "String", "imagePath", ",", "int", "width", ",", "int", "height", ")", "{", "File", "imageFile", "=", "new", "File", "(", "imagePath", ")", ";", "if", "(", "imageFile", ".", "exists",...
Deposit in the province read images, mViewWidth is high, the greater the picture clearer, but also the memory. @param imagePath pictures in the path of the memory card. @return bitmap.
[ "Deposit", "in", "the", "province", "read", "images", "mViewWidth", "is", "high", "the", "greater", "the", "picture", "clearer", "but", "also", "the", "memory", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/app/album/data/ThumbnailBuilder.java#L132-L177
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.getAlbumRootPath
@NonNull public static File getAlbumRootPath(Context context) { if (sdCardIsAvailable()) { return new File(Environment.getExternalStorageDirectory(), CACHE_DIRECTORY); } else { return new File(context.getFilesDir(), CACHE_DIRECTORY); } }
java
@NonNull public static File getAlbumRootPath(Context context) { if (sdCardIsAvailable()) { return new File(Environment.getExternalStorageDirectory(), CACHE_DIRECTORY); } else { return new File(context.getFilesDir(), CACHE_DIRECTORY); } }
[ "@", "NonNull", "public", "static", "File", "getAlbumRootPath", "(", "Context", "context", ")", "{", "if", "(", "sdCardIsAvailable", "(", ")", ")", "{", "return", "new", "File", "(", "Environment", ".", "getExternalStorageDirectory", "(", ")", ",", "CACHE_DIRE...
Get a writable root directory. @param context context. @return {@link File}.
[ "Get", "a", "writable", "root", "directory", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L66-L73
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.sdCardIsAvailable
public static boolean sdCardIsAvailable() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return Environment.getExternalStorageDirectory().canWrite(); } else return false; }
java
public static boolean sdCardIsAvailable() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return Environment.getExternalStorageDirectory().canWrite(); } else return false; }
[ "public", "static", "boolean", "sdCardIsAvailable", "(", ")", "{", "if", "(", "Environment", ".", "getExternalStorageState", "(", ")", ".", "equals", "(", "Environment", ".", "MEDIA_MOUNTED", ")", ")", "{", "return", "Environment", ".", "getExternalStorageDirector...
SD card is available. @return true when available, other wise is false.
[ "SD", "card", "is", "available", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L80-L85
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.randomMediaPath
@NonNull private static String randomMediaPath(File bucket, String extension) { if (bucket.exists() && bucket.isFile()) bucket.delete(); if (!bucket.exists()) bucket.mkdirs(); String outFilePath = AlbumUtils.getNowDateTime("yyyyMMdd_HHmmssSSS") + "_" + getMD5ForString(UUID.randomUUID().toString()) + extension; File file = new File(bucket, outFilePath); return file.getAbsolutePath(); }
java
@NonNull private static String randomMediaPath(File bucket, String extension) { if (bucket.exists() && bucket.isFile()) bucket.delete(); if (!bucket.exists()) bucket.mkdirs(); String outFilePath = AlbumUtils.getNowDateTime("yyyyMMdd_HHmmssSSS") + "_" + getMD5ForString(UUID.randomUUID().toString()) + extension; File file = new File(bucket, outFilePath); return file.getAbsolutePath(); }
[ "@", "NonNull", "private", "static", "String", "randomMediaPath", "(", "File", "bucket", ",", "String", "extension", ")", "{", "if", "(", "bucket", ".", "exists", "(", ")", "&&", "bucket", ".", "isFile", "(", ")", ")", "bucket", ".", "delete", "(", ")"...
Generates a random file path using the specified suffix name in the specified directory. @param bucket specify the directory. @param extension extension. @return file path.
[ "Generates", "a", "random", "file", "path", "using", "the", "specified", "suffix", "name", "in", "the", "specified", "directory", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L252-L259
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.getMimeType
public static String getMimeType(String url) { String extension = getExtension(url); if (!MimeTypeMap.getSingleton().hasExtension(extension)) return ""; String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); return TextUtils.isEmpty(mimeType) ? "" : mimeType; }
java
public static String getMimeType(String url) { String extension = getExtension(url); if (!MimeTypeMap.getSingleton().hasExtension(extension)) return ""; String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); return TextUtils.isEmpty(mimeType) ? "" : mimeType; }
[ "public", "static", "String", "getMimeType", "(", "String", "url", ")", "{", "String", "extension", "=", "getExtension", "(", "url", ")", ";", "if", "(", "!", "MimeTypeMap", ".", "getSingleton", "(", ")", ".", "hasExtension", "(", "extension", ")", ")", ...
Get the mime type of the file in the url. @param url file url. @return mime type.
[ "Get", "the", "mime", "type", "of", "the", "file", "in", "the", "url", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L279-L285
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.getExtension
public static String getExtension(String url) { url = TextUtils.isEmpty(url) ? "" : url.toLowerCase(); String extension = MimeTypeMap.getFileExtensionFromUrl(url); return TextUtils.isEmpty(extension) ? "" : extension; }
java
public static String getExtension(String url) { url = TextUtils.isEmpty(url) ? "" : url.toLowerCase(); String extension = MimeTypeMap.getFileExtensionFromUrl(url); return TextUtils.isEmpty(extension) ? "" : extension; }
[ "public", "static", "String", "getExtension", "(", "String", "url", ")", "{", "url", "=", "TextUtils", ".", "isEmpty", "(", "url", ")", "?", "\"\"", ":", "url", ".", "toLowerCase", "(", ")", ";", "String", "extension", "=", "MimeTypeMap", ".", "getFileEx...
Get the file extension in url. @param url file url. @return extension.
[ "Get", "the", "file", "extension", "in", "url", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L293-L297
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.convertDuration
@NonNull public static String convertDuration(@IntRange(from = 1) long duration) { duration /= 1000; int hour = (int) (duration / 3600); int minute = (int) ((duration - hour * 3600) / 60); int second = (int) (duration - hour * 3600 - minute * 60); String hourValue = ""; String minuteValue; String secondValue; if (hour > 0) { if (hour >= 10) { hourValue = Integer.toString(hour); } else { hourValue = "0" + hour; } hourValue += ":"; } if (minute > 0) { if (minute >= 10) { minuteValue = Integer.toString(minute); } else { minuteValue = "0" + minute; } } else { minuteValue = "00"; } minuteValue += ":"; if (second > 0) { if (second >= 10) { secondValue = Integer.toString(second); } else { secondValue = "0" + second; } } else { secondValue = "00"; } return hourValue + minuteValue + secondValue; }
java
@NonNull public static String convertDuration(@IntRange(from = 1) long duration) { duration /= 1000; int hour = (int) (duration / 3600); int minute = (int) ((duration - hour * 3600) / 60); int second = (int) (duration - hour * 3600 - minute * 60); String hourValue = ""; String minuteValue; String secondValue; if (hour > 0) { if (hour >= 10) { hourValue = Integer.toString(hour); } else { hourValue = "0" + hour; } hourValue += ":"; } if (minute > 0) { if (minute >= 10) { minuteValue = Integer.toString(minute); } else { minuteValue = "0" + minute; } } else { minuteValue = "00"; } minuteValue += ":"; if (second > 0) { if (second >= 10) { secondValue = Integer.toString(second); } else { secondValue = "0" + second; } } else { secondValue = "00"; } return hourValue + minuteValue + secondValue; }
[ "@", "NonNull", "public", "static", "String", "convertDuration", "(", "@", "IntRange", "(", "from", "=", "1", ")", "long", "duration", ")", "{", "duration", "/=", "1000", ";", "int", "hour", "=", "(", "int", ")", "(", "duration", "/", "3600", ")", ";...
Time conversion. @param duration ms. @return such as: {@code 00:00:00}, {@code 00:00}.
[ "Time", "conversion", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L391-L429
train
yanzhenjie/Album
album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java
AlbumUtils.getMD5ForString
public static String getMD5ForString(String content) { StringBuilder md5Buffer = new StringBuilder(); try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] tempBytes = digest.digest(content.getBytes()); int digital; for (int i = 0; i < tempBytes.length; i++) { digital = tempBytes[i]; if (digital < 0) { digital += 256; } if (digital < 16) { md5Buffer.append("0"); } md5Buffer.append(Integer.toHexString(digital)); } } catch (Exception ignored) { return Integer.toString(content.hashCode()); } return md5Buffer.toString(); }
java
public static String getMD5ForString(String content) { StringBuilder md5Buffer = new StringBuilder(); try { MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] tempBytes = digest.digest(content.getBytes()); int digital; for (int i = 0; i < tempBytes.length; i++) { digital = tempBytes[i]; if (digital < 0) { digital += 256; } if (digital < 16) { md5Buffer.append("0"); } md5Buffer.append(Integer.toHexString(digital)); } } catch (Exception ignored) { return Integer.toString(content.hashCode()); } return md5Buffer.toString(); }
[ "public", "static", "String", "getMD5ForString", "(", "String", "content", ")", "{", "StringBuilder", "md5Buffer", "=", "new", "StringBuilder", "(", ")", ";", "try", "{", "MessageDigest", "digest", "=", "MessageDigest", ".", "getInstance", "(", "\"MD5\"", ")", ...
Get the MD5 value of string. @param content the target string. @return the MD5 value.
[ "Get", "the", "MD5", "value", "of", "string", "." ]
b17506440d32909d42aba41f6a388041a25c8363
https://github.com/yanzhenjie/Album/blob/b17506440d32909d42aba41f6a388041a25c8363/album/src/main/java/com/yanzhenjie/album/util/AlbumUtils.java#L437-L457
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java
Broadcaster.stopRecording
@Override public void stopRecording() { super.stopRecording(); mSentBroadcastLiveEvent = false; if (mStream != null) { if (VERBOSE) Log.i(TAG, "Stopping Stream"); mKickflip.stopStream(mStream, new KickflipCallback() { @Override public void onSuccess(Response response) { if (VERBOSE) Log.i(TAG, "Got stop stream response " + response); } @Override public void onError(KickflipException error) { Log.w(TAG, "Error getting stop stream response! " + error); } }); } }
java
@Override public void stopRecording() { super.stopRecording(); mSentBroadcastLiveEvent = false; if (mStream != null) { if (VERBOSE) Log.i(TAG, "Stopping Stream"); mKickflip.stopStream(mStream, new KickflipCallback() { @Override public void onSuccess(Response response) { if (VERBOSE) Log.i(TAG, "Got stop stream response " + response); } @Override public void onError(KickflipException error) { Log.w(TAG, "Error getting stop stream response! " + error); } }); } }
[ "@", "Override", "public", "void", "stopRecording", "(", ")", "{", "super", ".", "stopRecording", "(", ")", ";", "mSentBroadcastLiveEvent", "=", "false", ";", "if", "(", "mStream", "!=", "null", ")", "{", "if", "(", "VERBOSE", ")", "Log", ".", "i", "("...
Stop broadcasting and release resources. After this call this Broadcaster can no longer be used.
[ "Stop", "broadcasting", "and", "release", "resources", ".", "After", "this", "call", "this", "Broadcaster", "can", "no", "longer", "be", "used", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java#L236-L254
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java
Broadcaster.queueOrSubmitUpload
private void queueOrSubmitUpload(String key, File file) { if (mReadyToBroadcast) { submitUpload(key, file); } else { if (VERBOSE) Log.i(TAG, "queueing " + key + " until S3 Credentials available"); queueUpload(key, file); } }
java
private void queueOrSubmitUpload(String key, File file) { if (mReadyToBroadcast) { submitUpload(key, file); } else { if (VERBOSE) Log.i(TAG, "queueing " + key + " until S3 Credentials available"); queueUpload(key, file); } }
[ "private", "void", "queueOrSubmitUpload", "(", "String", "key", ",", "File", "file", ")", "{", "if", "(", "mReadyToBroadcast", ")", "{", "submitUpload", "(", "key", ",", "file", ")", ";", "}", "else", "{", "if", "(", "VERBOSE", ")", "Log", ".", "i", ...
Handle an upload, either submitting to the S3 client or queueing for submission once credentials are ready @param key destination key @param file local file
[ "Handle", "an", "upload", "either", "submitting", "to", "the", "S3", "client", "or", "queueing", "for", "submission", "once", "credentials", "are", "ready" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java#L456-L463
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java
Broadcaster.queueUpload
private void queueUpload(String key, File file) { if (mUploadQueue == null) mUploadQueue = new ArrayDeque<>(); mUploadQueue.add(new Pair<>(key, file)); }
java
private void queueUpload(String key, File file) { if (mUploadQueue == null) mUploadQueue = new ArrayDeque<>(); mUploadQueue.add(new Pair<>(key, file)); }
[ "private", "void", "queueUpload", "(", "String", "key", ",", "File", "file", ")", "{", "if", "(", "mUploadQueue", "==", "null", ")", "mUploadQueue", "=", "new", "ArrayDeque", "<>", "(", ")", ";", "mUploadQueue", ".", "add", "(", "new", "Pair", "<>", "(...
Queue an upload for later submission to S3 @param key destination key @param file local file
[ "Queue", "an", "upload", "for", "later", "submission", "to", "S3" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java#L471-L475
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java
Broadcaster.submitQueuedUploadsToS3
private void submitQueuedUploadsToS3() { if (mUploadQueue == null) return; for (Pair<String, File> pair : mUploadQueue) { submitUpload(pair.first, pair.second); } }
java
private void submitQueuedUploadsToS3() { if (mUploadQueue == null) return; for (Pair<String, File> pair : mUploadQueue) { submitUpload(pair.first, pair.second); } }
[ "private", "void", "submitQueuedUploadsToS3", "(", ")", "{", "if", "(", "mUploadQueue", "==", "null", ")", "return", ";", "for", "(", "Pair", "<", "String", ",", "File", ">", "pair", ":", "mUploadQueue", ")", "{", "submitUpload", "(", "pair", ".", "first...
Submit all queued uploads to the S3 client
[ "Submit", "all", "queued", "uploads", "to", "the", "S3", "client" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/Broadcaster.java#L480-L485
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.applyFilter
public void applyFilter(int filter) { Filters.checkFilterArgument(filter); mDisplayRenderer.changeFilterMode(filter); synchronized (mReadyForFrameFence) { mNewFilter = filter; } }
java
public void applyFilter(int filter) { Filters.checkFilterArgument(filter); mDisplayRenderer.changeFilterMode(filter); synchronized (mReadyForFrameFence) { mNewFilter = filter; } }
[ "public", "void", "applyFilter", "(", "int", "filter", ")", "{", "Filters", ".", "checkFilterArgument", "(", "filter", ")", ";", "mDisplayRenderer", ".", "changeFilterMode", "(", "filter", ")", ";", "synchronized", "(", "mReadyForFrameFence", ")", "{", "mNewFilt...
Apply a filter to the camera input @param filter
[ "Apply", "a", "filter", "to", "the", "camera", "input" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L329-L335
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.handleCameraPreviewTouchEvent
public void handleCameraPreviewTouchEvent(MotionEvent ev) { if (mFullScreen != null) mFullScreen.handleTouchEvent(ev); if (mDisplayRenderer != null) mDisplayRenderer.handleTouchEvent(ev); }
java
public void handleCameraPreviewTouchEvent(MotionEvent ev) { if (mFullScreen != null) mFullScreen.handleTouchEvent(ev); if (mDisplayRenderer != null) mDisplayRenderer.handleTouchEvent(ev); }
[ "public", "void", "handleCameraPreviewTouchEvent", "(", "MotionEvent", "ev", ")", "{", "if", "(", "mFullScreen", "!=", "null", ")", "mFullScreen", ".", "handleTouchEvent", "(", "ev", ")", ";", "if", "(", "mDisplayRenderer", "!=", "null", ")", "mDisplayRenderer",...
Notify the preview and encoder programs of a touch event. Used by GLCameraEncoderView @param ev onTouchEvent event to handle
[ "Notify", "the", "preview", "and", "encoder", "programs", "of", "a", "touch", "event", ".", "Used", "by", "GLCameraEncoderView" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L344-L347
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.startRecording
public void startRecording() { if (mState != STATE.INITIALIZED) { Log.e(TAG, "startRecording called in invalid state. Ignoring"); return; } synchronized (mReadyForFrameFence) { mFrameNum = 0; mRecording = true; mState = STATE.RECORDING; } }
java
public void startRecording() { if (mState != STATE.INITIALIZED) { Log.e(TAG, "startRecording called in invalid state. Ignoring"); return; } synchronized (mReadyForFrameFence) { mFrameNum = 0; mRecording = true; mState = STATE.RECORDING; } }
[ "public", "void", "startRecording", "(", ")", "{", "if", "(", "mState", "!=", "STATE", ".", "INITIALIZED", ")", "{", "Log", ".", "e", "(", "TAG", ",", "\"startRecording called in invalid state. Ignoring\"", ")", ";", "return", ";", "}", "synchronized", "(", ...
Called from UI thread
[ "Called", "from", "UI", "thread" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L363-L373
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.onFrameAvailable
@Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { // Pass SurfaceTexture to Encoding thread via Handler // Then Encode and display frame mHandler.sendMessage(mHandler.obtainMessage(MSG_FRAME_AVAILABLE, surfaceTexture)); }
java
@Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { // Pass SurfaceTexture to Encoding thread via Handler // Then Encode and display frame mHandler.sendMessage(mHandler.obtainMessage(MSG_FRAME_AVAILABLE, surfaceTexture)); }
[ "@", "Override", "public", "void", "onFrameAvailable", "(", "SurfaceTexture", "surfaceTexture", ")", "{", "// Pass SurfaceTexture to Encoding thread via Handler", "// Then Encode and display frame", "mHandler", ".", "sendMessage", "(", "mHandler", ".", "obtainMessage", "(", "...
Called on an "arbitrary thread" @param surfaceTexture the SurfaceTexture initiating the call
[ "Called", "on", "an", "arbitrary", "thread" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L466-L471
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.prepareEncoder
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, Muxer muxer) throws IOException { mVideoEncoder = new VideoEncoderCore(width, height, bitRate, muxer); if (mEglCore == null) { // This is the first prepare called for this CameraEncoder instance mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE); } if (mInputWindowSurface != null) mInputWindowSurface.release(); mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface()); mInputWindowSurface.makeCurrent(); if (mFullScreen != null) mFullScreen.release(); mFullScreen = new FullFrameRect( new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT)); mFullScreen.getProgram().setTexSize(width, height); mIncomingSizeUpdated = true; }
java
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, Muxer muxer) throws IOException { mVideoEncoder = new VideoEncoderCore(width, height, bitRate, muxer); if (mEglCore == null) { // This is the first prepare called for this CameraEncoder instance mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE); } if (mInputWindowSurface != null) mInputWindowSurface.release(); mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface()); mInputWindowSurface.makeCurrent(); if (mFullScreen != null) mFullScreen.release(); mFullScreen = new FullFrameRect( new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT)); mFullScreen.getProgram().setTexSize(width, height); mIncomingSizeUpdated = true; }
[ "private", "void", "prepareEncoder", "(", "EGLContext", "sharedContext", ",", "int", "width", ",", "int", "height", ",", "int", "bitRate", ",", "Muxer", "muxer", ")", "throws", "IOException", "{", "mVideoEncoder", "=", "new", "VideoEncoderCore", "(", "width", ...
Called with the display EGLContext current, on Encoder thread @param sharedContext The display EGLContext to be shared with the Encoder Surface's context. @param width the desired width of the encoder's video output @param height the desired height of the encoder's video output @param bitRate the desired bitrate of the video encoder @param muxer the desired output muxer
[ "Called", "with", "the", "display", "EGLContext", "current", "on", "Encoder", "thread" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L692-L708
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.releaseEglResources
private void releaseEglResources() { mReadyForFrames = false; if (mInputWindowSurface != null) { mInputWindowSurface.release(); mInputWindowSurface = null; } if (mFullScreen != null) { mFullScreen.release(); mFullScreen = null; } if (mEglCore != null) { mEglCore.release(); mEglCore = null; } mSurfaceTexture = null; }
java
private void releaseEglResources() { mReadyForFrames = false; if (mInputWindowSurface != null) { mInputWindowSurface.release(); mInputWindowSurface = null; } if (mFullScreen != null) { mFullScreen.release(); mFullScreen = null; } if (mEglCore != null) { mEglCore.release(); mEglCore = null; } mSurfaceTexture = null; }
[ "private", "void", "releaseEglResources", "(", ")", "{", "mReadyForFrames", "=", "false", ";", "if", "(", "mInputWindowSurface", "!=", "null", ")", "{", "mInputWindowSurface", ".", "release", "(", ")", ";", "mInputWindowSurface", "=", "null", ";", "}", "if", ...
Release all recording-specific resources. The Encoder, EGLCore and FullFrameRect are tied to capture resolution, and other parameters.
[ "Release", "all", "recording", "-", "specific", "resources", ".", "The", "Encoder", "EGLCore", "and", "FullFrameRect", "are", "tied", "to", "capture", "resolution", "and", "other", "parameters", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L719-L735
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.releaseCamera
private void releaseCamera() { if (mDisplayView != null) releaseDisplayView(); if (mCamera != null) { if (VERBOSE) Log.d(TAG, "releasing camera"); mCamera.stopPreview(); mCamera.release(); mCamera = null; } }
java
private void releaseCamera() { if (mDisplayView != null) releaseDisplayView(); if (mCamera != null) { if (VERBOSE) Log.d(TAG, "releasing camera"); mCamera.stopPreview(); mCamera.release(); mCamera = null; } }
[ "private", "void", "releaseCamera", "(", ")", "{", "if", "(", "mDisplayView", "!=", "null", ")", "releaseDisplayView", "(", ")", ";", "if", "(", "mCamera", "!=", "null", ")", "{", "if", "(", "VERBOSE", ")", "Log", ".", "d", "(", "TAG", ",", "\"releas...
Stops camera preview, and releases the camera to the system.
[ "Stops", "camera", "preview", "and", "releases", "the", "camera", "to", "the", "system", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L846-L855
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.configureDisplayView
private void configureDisplayView() { if (mDisplayView instanceof GLCameraEncoderView) ((GLCameraEncoderView) mDisplayView).setCameraEncoder(this); else if (mDisplayView instanceof GLCameraView) ((GLCameraView) mDisplayView).setCamera(mCamera); }
java
private void configureDisplayView() { if (mDisplayView instanceof GLCameraEncoderView) ((GLCameraEncoderView) mDisplayView).setCameraEncoder(this); else if (mDisplayView instanceof GLCameraView) ((GLCameraView) mDisplayView).setCamera(mCamera); }
[ "private", "void", "configureDisplayView", "(", ")", "{", "if", "(", "mDisplayView", "instanceof", "GLCameraEncoderView", ")", "(", "(", "GLCameraEncoderView", ")", "mDisplayView", ")", ".", "setCameraEncoder", "(", "this", ")", ";", "else", "if", "(", "mDisplay...
Communicate camera-ready state to our display view. This method allows us to handle custom subclasses
[ "Communicate", "camera", "-", "ready", "state", "to", "our", "display", "view", ".", "This", "method", "allows", "us", "to", "handle", "custom", "subclasses" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L861-L866
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java
CameraEncoder.releaseDisplayView
private void releaseDisplayView() { if (mDisplayView instanceof GLCameraEncoderView) { ((GLCameraEncoderView) mDisplayView).releaseCamera(); } else if (mDisplayView instanceof GLCameraView) ((GLCameraView) mDisplayView).releaseCamera(); }
java
private void releaseDisplayView() { if (mDisplayView instanceof GLCameraEncoderView) { ((GLCameraEncoderView) mDisplayView).releaseCamera(); } else if (mDisplayView instanceof GLCameraView) ((GLCameraView) mDisplayView).releaseCamera(); }
[ "private", "void", "releaseDisplayView", "(", ")", "{", "if", "(", "mDisplayView", "instanceof", "GLCameraEncoderView", ")", "{", "(", "(", "GLCameraEncoderView", ")", "mDisplayView", ")", ".", "releaseCamera", "(", ")", ";", "}", "else", "if", "(", "mDisplayV...
Communicate camera-released state to our display view.
[ "Communicate", "camera", "-", "released", "state", "to", "our", "display", "view", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/CameraEncoder.java#L871-L876
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java
GlUtil.createProgram
public static int createProgram(String vertexSource, String fragmentSource) { int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); if (vertexShader == 0) { return 0; } int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); if (pixelShader == 0) { return 0; } int program = GLES20.glCreateProgram(); checkGlError("glCreateProgram"); if (program == 0) { Log.e(TAG, "Could not create program"); } GLES20.glAttachShader(program, vertexShader); checkGlError("glAttachShader"); GLES20.glAttachShader(program, pixelShader); checkGlError("glAttachShader"); GLES20.glLinkProgram(program); int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GLES20.GL_TRUE) { Log.e(TAG, "Could not link program: "); Log.e(TAG, GLES20.glGetProgramInfoLog(program)); GLES20.glDeleteProgram(program); program = 0; } return program; }
java
public static int createProgram(String vertexSource, String fragmentSource) { int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); if (vertexShader == 0) { return 0; } int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); if (pixelShader == 0) { return 0; } int program = GLES20.glCreateProgram(); checkGlError("glCreateProgram"); if (program == 0) { Log.e(TAG, "Could not create program"); } GLES20.glAttachShader(program, vertexShader); checkGlError("glAttachShader"); GLES20.glAttachShader(program, pixelShader); checkGlError("glAttachShader"); GLES20.glLinkProgram(program); int[] linkStatus = new int[1]; GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != GLES20.GL_TRUE) { Log.e(TAG, "Could not link program: "); Log.e(TAG, GLES20.glGetProgramInfoLog(program)); GLES20.glDeleteProgram(program); program = 0; } return program; }
[ "public", "static", "int", "createProgram", "(", "String", "vertexSource", ",", "String", "fragmentSource", ")", "{", "int", "vertexShader", "=", "loadShader", "(", "GLES20", ".", "GL_VERTEX_SHADER", ",", "vertexSource", ")", ";", "if", "(", "vertexShader", "=="...
Creates a new program from the supplied vertex and fragment shaders. @return A handle to the program, or 0 on failure.
[ "Creates", "a", "new", "program", "from", "the", "supplied", "vertex", "and", "fragment", "shaders", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java#L50-L79
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java
GlUtil.loadShader
public static int loadShader(int shaderType, String source) { int shader = GLES20.glCreateShader(shaderType); checkGlError("glCreateShader type=" + shaderType); GLES20.glShaderSource(shader, source); GLES20.glCompileShader(shader); int[] compiled = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e(TAG, "Could not compile shader " + shaderType + ":"); Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } return shader; }
java
public static int loadShader(int shaderType, String source) { int shader = GLES20.glCreateShader(shaderType); checkGlError("glCreateShader type=" + shaderType); GLES20.glShaderSource(shader, source); GLES20.glCompileShader(shader); int[] compiled = new int[1]; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e(TAG, "Could not compile shader " + shaderType + ":"); Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } return shader; }
[ "public", "static", "int", "loadShader", "(", "int", "shaderType", ",", "String", "source", ")", "{", "int", "shader", "=", "GLES20", ".", "glCreateShader", "(", "shaderType", ")", ";", "checkGlError", "(", "\"glCreateShader type=\"", "+", "shaderType", ")", "...
Compiles the provided shader source. @return A handle to the shader, or 0 on failure.
[ "Compiles", "the", "provided", "shader", "source", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java#L86-L100
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java
GlUtil.checkGlError
public static void checkGlError(String op) { int error = GLES20.glGetError(); if (error != GLES20.GL_NO_ERROR) { String msg = op + ": glError 0x" + Integer.toHexString(error); Log.e(TAG, msg); throw new RuntimeException(msg); } }
java
public static void checkGlError(String op) { int error = GLES20.glGetError(); if (error != GLES20.GL_NO_ERROR) { String msg = op + ": glError 0x" + Integer.toHexString(error); Log.e(TAG, msg); throw new RuntimeException(msg); } }
[ "public", "static", "void", "checkGlError", "(", "String", "op", ")", "{", "int", "error", "=", "GLES20", ".", "glGetError", "(", ")", ";", "if", "(", "error", "!=", "GLES20", ".", "GL_NO_ERROR", ")", "{", "String", "msg", "=", "op", "+", "\": glError ...
Checks to see if a GLES error has been raised.
[ "Checks", "to", "see", "if", "a", "GLES", "error", "has", "been", "raised", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java#L105-L112
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java
GlUtil.createFloatBuffer
public static FloatBuffer createFloatBuffer(float[] coords) { // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it. ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(coords); fb.position(0); return fb; }
java
public static FloatBuffer createFloatBuffer(float[] coords) { // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it. ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(coords); fb.position(0); return fb; }
[ "public", "static", "FloatBuffer", "createFloatBuffer", "(", "float", "[", "]", "coords", ")", "{", "// Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.", "ByteBuffer", "bb", "=", "ByteBuffer", ".", "allocateDirect", "(", "coords", ".", "lengt...
Allocates a direct float buffer, and populates it with the float array data.
[ "Allocates", "a", "direct", "float", "buffer", "and", "populates", "it", "with", "the", "float", "array", "data", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java#L129-L137
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java
GlUtil.logVersionInfo
public static void logVersionInfo() { Log.i(TAG, "vendor : " + GLES20.glGetString(GLES20.GL_VENDOR)); Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER)); Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION)); if (false) { int[] values = new int[1]; GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0); int majorVersion = values[0]; GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0); int minorVersion = values[0]; if (GLES30.glGetError() == GLES30.GL_NO_ERROR) { Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion); } } }
java
public static void logVersionInfo() { Log.i(TAG, "vendor : " + GLES20.glGetString(GLES20.GL_VENDOR)); Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER)); Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION)); if (false) { int[] values = new int[1]; GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0); int majorVersion = values[0]; GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0); int minorVersion = values[0]; if (GLES30.glGetError() == GLES30.GL_NO_ERROR) { Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion); } } }
[ "public", "static", "void", "logVersionInfo", "(", ")", "{", "Log", ".", "i", "(", "TAG", ",", "\"vendor : \"", "+", "GLES20", ".", "glGetString", "(", "GLES20", ".", "GL_VENDOR", ")", ")", ";", "Log", ".", "i", "(", "TAG", ",", "\"renderer: \"", "+",...
Writes GL version info to the log.
[ "Writes", "GL", "version", "info", "to", "the", "log", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/GlUtil.java#L142-L157
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.getConfig
private EGLConfig getConfig(int flags, int version) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (version >= 3) { renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR; } // The actual surface is generally RGBA or RGBX, so situationally omitting alpha // doesn't really help. It can also lead to a huge performance hit on glReadPixels() // when reading into a GL_RGBA buffer. int[] attribList = { EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_DEPTH_SIZE, 16, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_RENDERABLE_TYPE, renderableType, EGL14.EGL_NONE, 0, // placeholder for recordable [@-3] EGL14.EGL_NONE }; if ((flags & FLAG_RECORDABLE) != 0) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
java
private EGLConfig getConfig(int flags, int version) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (version >= 3) { renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR; } // The actual surface is generally RGBA or RGBX, so situationally omitting alpha // doesn't really help. It can also lead to a huge performance hit on glReadPixels() // when reading into a GL_RGBA buffer. int[] attribList = { EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_DEPTH_SIZE, 16, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_RENDERABLE_TYPE, renderableType, EGL14.EGL_NONE, 0, // placeholder for recordable [@-3] EGL14.EGL_NONE }; if ((flags & FLAG_RECORDABLE) != 0) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
[ "private", "EGLConfig", "getConfig", "(", "int", "flags", ",", "int", "version", ")", "{", "int", "renderableType", "=", "EGL14", ".", "EGL_OPENGL_ES2_BIT", ";", "if", "(", "version", ">=", "3", ")", "{", "renderableType", "|=", "EGLExt", ".", "EGL_OPENGL_ES...
Finds a suitable EGLConfig. @param flags Bit flags from constructor. @param version Must be 2 or 3.
[ "Finds", "a", "suitable", "EGLConfig", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L143-L175
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.release
public void release() { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { // Android is unusual in that it uses a reference-counted EGLDisplay. So for // every eglInitialize() we need an eglTerminate(). EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(mEGLDisplay); } mEGLDisplay = EGL14.EGL_NO_DISPLAY; mEGLContext = EGL14.EGL_NO_CONTEXT; mEGLConfig = null; }
java
public void release() { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { // Android is unusual in that it uses a reference-counted EGLDisplay. So for // every eglInitialize() we need an eglTerminate(). EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(mEGLDisplay); } mEGLDisplay = EGL14.EGL_NO_DISPLAY; mEGLContext = EGL14.EGL_NO_CONTEXT; mEGLConfig = null; }
[ "public", "void", "release", "(", ")", "{", "if", "(", "mEGLDisplay", "!=", "EGL14", ".", "EGL_NO_DISPLAY", ")", "{", "// Android is unusual in that it uses a reference-counted EGLDisplay. So for", "// every eglInitialize() we need an eglTerminate().", "EGL14", ".", "eglMakeCu...
Discard all resources held by this class, notably the EGL context.
[ "Discard", "all", "resources", "held", "by", "this", "class", "notably", "the", "EGL", "context", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L180-L193
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.createOffscreenSurface
public EGLSurface createOffscreenSurface(int width, int height) { int[] surfaceAttribs = { EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE }; EGLSurface eglSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, surfaceAttribs, 0); checkEglError("eglCreatePbufferSurface"); if (eglSurface == null) { throw new RuntimeException("surface was null"); } return eglSurface; }
java
public EGLSurface createOffscreenSurface(int width, int height) { int[] surfaceAttribs = { EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE }; EGLSurface eglSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, surfaceAttribs, 0); checkEglError("eglCreatePbufferSurface"); if (eglSurface == null) { throw new RuntimeException("surface was null"); } return eglSurface; }
[ "public", "EGLSurface", "createOffscreenSurface", "(", "int", "width", ",", "int", "height", ")", "{", "int", "[", "]", "surfaceAttribs", "=", "{", "EGL14", ".", "EGL_WIDTH", ",", "width", ",", "EGL14", ".", "EGL_HEIGHT", ",", "height", ",", "EGL14", ".", ...
Creates an EGL surface associated with an offscreen buffer.
[ "Creates", "an", "EGL", "surface", "associated", "with", "an", "offscreen", "buffer", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L245-L258
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.makeCurrent
public void makeCurrent(EGLSurface eglSurface) { if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) { // called makeCurrent() before create? Log.d(TAG, "NOTE: makeCurrent w/o display"); } if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) { throw new RuntimeException("eglMakeCurrent failed"); } }
java
public void makeCurrent(EGLSurface eglSurface) { if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) { // called makeCurrent() before create? Log.d(TAG, "NOTE: makeCurrent w/o display"); } if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) { throw new RuntimeException("eglMakeCurrent failed"); } }
[ "public", "void", "makeCurrent", "(", "EGLSurface", "eglSurface", ")", "{", "if", "(", "mEGLDisplay", "==", "EGL14", ".", "EGL_NO_DISPLAY", ")", "{", "// called makeCurrent() before create?", "Log", ".", "d", "(", "TAG", ",", "\"NOTE: makeCurrent w/o display\"", ")"...
Makes our EGL context current, using the supplied surface for both "draw" and "read".
[ "Makes", "our", "EGL", "context", "current", "using", "the", "supplied", "surface", "for", "both", "draw", "and", "read", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L263-L271
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.makeCurrent
public void makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) { if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) { // called makeCurrent() before create? Log.d(TAG, "NOTE: makeCurrent w/o display"); } if (!EGL14.eglMakeCurrent(mEGLDisplay, drawSurface, readSurface, mEGLContext)) { throw new RuntimeException("eglMakeCurrent(draw,read) failed"); } }
java
public void makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) { if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) { // called makeCurrent() before create? Log.d(TAG, "NOTE: makeCurrent w/o display"); } if (!EGL14.eglMakeCurrent(mEGLDisplay, drawSurface, readSurface, mEGLContext)) { throw new RuntimeException("eglMakeCurrent(draw,read) failed"); } }
[ "public", "void", "makeCurrent", "(", "EGLSurface", "drawSurface", ",", "EGLSurface", "readSurface", ")", "{", "if", "(", "mEGLDisplay", "==", "EGL14", ".", "EGL_NO_DISPLAY", ")", "{", "// called makeCurrent() before create?", "Log", ".", "d", "(", "TAG", ",", "...
Makes our EGL context current, using the supplied "draw" and "read" surfaces.
[ "Makes", "our", "EGL", "context", "current", "using", "the", "supplied", "draw", "and", "read", "surfaces", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L276-L284
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.makeNothingCurrent
public void makeNothingCurrent() { if (!EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)) { throw new RuntimeException("eglMakeCurrent failed"); } }
java
public void makeNothingCurrent() { if (!EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)) { throw new RuntimeException("eglMakeCurrent failed"); } }
[ "public", "void", "makeNothingCurrent", "(", ")", "{", "if", "(", "!", "EGL14", ".", "eglMakeCurrent", "(", "mEGLDisplay", ",", "EGL14", ".", "EGL_NO_SURFACE", ",", "EGL14", ".", "EGL_NO_SURFACE", ",", "EGL14", ".", "EGL_NO_CONTEXT", ")", ")", "{", "throw", ...
Makes no context current.
[ "Makes", "no", "context", "current", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L289-L294
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.isCurrent
public boolean isCurrent(EGLSurface eglSurface) { return mEGLContext.equals(EGL14.eglGetCurrentContext()) && eglSurface.equals(EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW)); }
java
public boolean isCurrent(EGLSurface eglSurface) { return mEGLContext.equals(EGL14.eglGetCurrentContext()) && eglSurface.equals(EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW)); }
[ "public", "boolean", "isCurrent", "(", "EGLSurface", "eglSurface", ")", "{", "return", "mEGLContext", ".", "equals", "(", "EGL14", ".", "eglGetCurrentContext", "(", ")", ")", "&&", "eglSurface", ".", "equals", "(", "EGL14", ".", "eglGetCurrentSurface", "(", "E...
Returns true if our context and the specified surface are current.
[ "Returns", "true", "if", "our", "context", "and", "the", "specified", "surface", "are", "current", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L315-L318
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.querySurface
public int querySurface(EGLSurface eglSurface, int what) { int[] value = new int[1]; EGL14.eglQuerySurface(mEGLDisplay, eglSurface, what, value, 0); return value[0]; }
java
public int querySurface(EGLSurface eglSurface, int what) { int[] value = new int[1]; EGL14.eglQuerySurface(mEGLDisplay, eglSurface, what, value, 0); return value[0]; }
[ "public", "int", "querySurface", "(", "EGLSurface", "eglSurface", ",", "int", "what", ")", "{", "int", "[", "]", "value", "=", "new", "int", "[", "1", "]", ";", "EGL14", ".", "eglQuerySurface", "(", "mEGLDisplay", ",", "eglSurface", ",", "what", ",", "...
Performs a simple surface query.
[ "Performs", "a", "simple", "surface", "query", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L323-L327
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.logCurrent
public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
java
public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
[ "public", "static", "void", "logCurrent", "(", "String", "msg", ")", "{", "EGLDisplay", "display", ";", "EGLContext", "context", ";", "EGLSurface", "surface", ";", "display", "=", "EGL14", ".", "eglGetCurrentDisplay", "(", ")", ";", "context", "=", "EGL14", ...
Writes the current display, context, and surface to the log.
[ "Writes", "the", "current", "display", "context", "and", "surface", "to", "the", "log", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L339-L349
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/EglCore.java
EglCore.checkEglError
private void checkEglError(String msg) { int error; if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) { throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error)); } }
java
private void checkEglError(String msg) { int error; if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) { throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error)); } }
[ "private", "void", "checkEglError", "(", "String", "msg", ")", "{", "int", "error", ";", "if", "(", "(", "error", "=", "EGL14", ".", "eglGetError", "(", ")", ")", "!=", "EGL14", ".", "EGL_SUCCESS", ")", "{", "throw", "new", "RuntimeException", "(", "ms...
Checks for EGL errors.
[ "Checks", "for", "EGL", "errors", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/EglCore.java#L354-L359
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/MicrophoneEncoder.java
MicrophoneEncoder.getJitterFreePTS
private long getJitterFreePTS(long bufferPts, long bufferSamplesNum) { long correctedPts = 0; long bufferDuration = (1000000 * bufferSamplesNum) / (mEncoderCore.mSampleRate); bufferPts -= bufferDuration; // accounts for the delay of acquiring the audio buffer if (totalSamplesNum == 0) { // reset startPTS = bufferPts; totalSamplesNum = 0; } correctedPts = startPTS + (1000000 * totalSamplesNum) / (mEncoderCore.mSampleRate); if(bufferPts - correctedPts >= 2*bufferDuration) { // reset startPTS = bufferPts; totalSamplesNum = 0; correctedPts = startPTS; } totalSamplesNum += bufferSamplesNum; return correctedPts; }
java
private long getJitterFreePTS(long bufferPts, long bufferSamplesNum) { long correctedPts = 0; long bufferDuration = (1000000 * bufferSamplesNum) / (mEncoderCore.mSampleRate); bufferPts -= bufferDuration; // accounts for the delay of acquiring the audio buffer if (totalSamplesNum == 0) { // reset startPTS = bufferPts; totalSamplesNum = 0; } correctedPts = startPTS + (1000000 * totalSamplesNum) / (mEncoderCore.mSampleRate); if(bufferPts - correctedPts >= 2*bufferDuration) { // reset startPTS = bufferPts; totalSamplesNum = 0; correctedPts = startPTS; } totalSamplesNum += bufferSamplesNum; return correctedPts; }
[ "private", "long", "getJitterFreePTS", "(", "long", "bufferPts", ",", "long", "bufferSamplesNum", ")", "{", "long", "correctedPts", "=", "0", ";", "long", "bufferDuration", "=", "(", "1000000", "*", "bufferSamplesNum", ")", "/", "(", "mEncoderCore", ".", "mSam...
Ensures that each audio pts differs by a constant amount from the previous one. @param bufferPts presentation timestamp in us @param bufferSamplesNum the number of samples of the buffer's frame @return
[ "Ensures", "that", "each", "audio", "pts", "differs", "by", "a", "constant", "amount", "from", "the", "previous", "one", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/MicrophoneEncoder.java#L207-L225
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/FullFrameRect.java
FullFrameRect.adjustForVerticalVideo
public void adjustForVerticalVideo(SCREEN_ROTATION orientation, boolean scaleToFit) { synchronized (mDrawLock) { mCorrectVerticalVideo = true; mScaleToFit = scaleToFit; requestedOrientation = orientation; Matrix.setIdentityM(IDENTITY_MATRIX, 0); switch (orientation) { case VERTICAL: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, -90, 0f, 0f, 1f); Matrix.scaleM(IDENTITY_MATRIX, 0, 3.16f, 1.0f, 1f); } else { Matrix.scaleM(IDENTITY_MATRIX, 0, 0.316f, 1f, 1f); } break; case UPSIDEDOWN_LANDSCAPE: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, -180, 0f, 0f, 1f); } break; case UPSIDEDOWN_VERTICAL: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, 90, 0f, 0f, 1f); Matrix.scaleM(IDENTITY_MATRIX, 0, 3.16f, 1.0f, 1f); } else { Matrix.scaleM(IDENTITY_MATRIX, 0, 0.316f, 1f, 1f); } break; } } }
java
public void adjustForVerticalVideo(SCREEN_ROTATION orientation, boolean scaleToFit) { synchronized (mDrawLock) { mCorrectVerticalVideo = true; mScaleToFit = scaleToFit; requestedOrientation = orientation; Matrix.setIdentityM(IDENTITY_MATRIX, 0); switch (orientation) { case VERTICAL: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, -90, 0f, 0f, 1f); Matrix.scaleM(IDENTITY_MATRIX, 0, 3.16f, 1.0f, 1f); } else { Matrix.scaleM(IDENTITY_MATRIX, 0, 0.316f, 1f, 1f); } break; case UPSIDEDOWN_LANDSCAPE: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, -180, 0f, 0f, 1f); } break; case UPSIDEDOWN_VERTICAL: if (scaleToFit) { Matrix.rotateM(IDENTITY_MATRIX, 0, 90, 0f, 0f, 1f); Matrix.scaleM(IDENTITY_MATRIX, 0, 3.16f, 1.0f, 1f); } else { Matrix.scaleM(IDENTITY_MATRIX, 0, 0.316f, 1f, 1f); } break; } } }
[ "public", "void", "adjustForVerticalVideo", "(", "SCREEN_ROTATION", "orientation", ",", "boolean", "scaleToFit", ")", "{", "synchronized", "(", "mDrawLock", ")", "{", "mCorrectVerticalVideo", "=", "true", ";", "mScaleToFit", "=", "scaleToFit", ";", "requestedOrientati...
Adjust the MVP Matrix to rotate and crop the texture to make vertical video appear upright
[ "Adjust", "the", "MVP", "Matrix", "to", "rotate", "and", "crop", "the", "texture", "to", "make", "vertical", "video", "appear", "upright" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/FullFrameRect.java#L70-L100
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/av/FullFrameRect.java
FullFrameRect.drawFrame
public void drawFrame(int textureId, float[] texMatrix) { // Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport. synchronized (mDrawLock) { if (mCorrectVerticalVideo && !mScaleToFit && (requestedOrientation == SCREEN_ROTATION.VERTICAL || requestedOrientation == SCREEN_ROTATION.UPSIDEDOWN_VERTICAL)) { Matrix.scaleM(texMatrix, 0, 0.316f, 1.0f, 1f); } mProgram.draw(IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0, mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(), mRectDrawable.getVertexStride(), texMatrix, TEX_COORDS_BUF, textureId, TEX_COORDS_STRIDE); } }
java
public void drawFrame(int textureId, float[] texMatrix) { // Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport. synchronized (mDrawLock) { if (mCorrectVerticalVideo && !mScaleToFit && (requestedOrientation == SCREEN_ROTATION.VERTICAL || requestedOrientation == SCREEN_ROTATION.UPSIDEDOWN_VERTICAL)) { Matrix.scaleM(texMatrix, 0, 0.316f, 1.0f, 1f); } mProgram.draw(IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0, mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(), mRectDrawable.getVertexStride(), texMatrix, TEX_COORDS_BUF, textureId, TEX_COORDS_STRIDE); } }
[ "public", "void", "drawFrame", "(", "int", "textureId", ",", "float", "[", "]", "texMatrix", ")", "{", "// Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport.", "synchronized", "(", "mDrawLock", ")", "{", "if", "(", "mCorrectVerticalVideo", "&&"...
Draws a viewport-filling rect, texturing it with the specified texture object.
[ "Draws", "a", "viewport", "-", "filling", "rect", "texturing", "it", "with", "the", "specified", "texture", "object", "." ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/av/FullFrameRect.java#L137-L148
train
Kickflip/kickflip-android-sdk
sdk/src/main/java/io/kickflip/sdk/fragment/GlassBroadcastFragment.java
GlassBroadcastFragment.stopBroadcasting
public void stopBroadcasting() { if (mBroadcaster.isRecording()) { mBroadcaster.stopRecording(); mBroadcaster.release(); } else { Log.e(TAG, "stopBroadcasting called but mBroadcaster not broadcasting"); } }
java
public void stopBroadcasting() { if (mBroadcaster.isRecording()) { mBroadcaster.stopRecording(); mBroadcaster.release(); } else { Log.e(TAG, "stopBroadcasting called but mBroadcaster not broadcasting"); } }
[ "public", "void", "stopBroadcasting", "(", ")", "{", "if", "(", "mBroadcaster", ".", "isRecording", "(", ")", ")", "{", "mBroadcaster", ".", "stopRecording", "(", ")", ";", "mBroadcaster", ".", "release", "(", ")", ";", "}", "else", "{", "Log", ".", "e...
Force this fragment to stop broadcasting. Useful if your application wants to stop broadcasting when a user leaves the Activity hosting this fragment
[ "Force", "this", "fragment", "to", "stop", "broadcasting", ".", "Useful", "if", "your", "application", "wants", "to", "stop", "broadcasting", "when", "a", "user", "leaves", "the", "Activity", "hosting", "this", "fragment" ]
af3aae5f1128d7376e67aefe11a3a1a3844be734
https://github.com/Kickflip/kickflip-android-sdk/blob/af3aae5f1128d7376e67aefe11a3a1a3844be734/sdk/src/main/java/io/kickflip/sdk/fragment/GlassBroadcastFragment.java#L242-L249
train