id
int32 0
165k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
14,900
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ConfigImplUtil.java
|
ConfigImplUtil.syntaxFromExtension
|
public static ConfigSyntax syntaxFromExtension(String filename) {
if (filename == null)
return null;
else if (filename.endsWith(".json"))
return ConfigSyntax.JSON;
else if (filename.endsWith(".conf"))
return ConfigSyntax.CONF;
else if (filename.endsWith(".properties"))
return ConfigSyntax.PROPERTIES;
else
return null;
}
|
java
|
public static ConfigSyntax syntaxFromExtension(String filename) {
if (filename == null)
return null;
else if (filename.endsWith(".json"))
return ConfigSyntax.JSON;
else if (filename.endsWith(".conf"))
return ConfigSyntax.CONF;
else if (filename.endsWith(".properties"))
return ConfigSyntax.PROPERTIES;
else
return null;
}
|
[
"public",
"static",
"ConfigSyntax",
"syntaxFromExtension",
"(",
"String",
"filename",
")",
"{",
"if",
"(",
"filename",
"==",
"null",
")",
"return",
"null",
";",
"else",
"if",
"(",
"filename",
".",
"endsWith",
"(",
"\".json\"",
")",
")",
"return",
"ConfigSyntax",
".",
"JSON",
";",
"else",
"if",
"(",
"filename",
".",
"endsWith",
"(",
"\".conf\"",
")",
")",
"return",
"ConfigSyntax",
".",
"CONF",
";",
"else",
"if",
"(",
"filename",
".",
"endsWith",
"(",
"\".properties\"",
")",
")",
"return",
"ConfigSyntax",
".",
"PROPERTIES",
";",
"else",
"return",
"null",
";",
"}"
] |
Guess configuration syntax from given filename.
@param filename configuration filename
@return configuration syntax if a match is found. Otherwise, null.
|
[
"Guess",
"configuration",
"syntax",
"from",
"given",
"filename",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ConfigImplUtil.java#L290-L301
|
14,901
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java
|
ConfigDelayedMerge.makeReplacement
|
static AbstractConfigValue makeReplacement(ResolveContext context, List<AbstractConfigValue> stack, int skipping) {
List<AbstractConfigValue> subStack = stack.subList(skipping, stack.size());
if (subStack.isEmpty()) {
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace(context.depth(), "Nothing else in the merge stack, replacing with null");
return null;
} else {
// generate a new merge stack from only the remaining items
AbstractConfigValue merged = null;
for (AbstractConfigValue v : subStack) {
if (merged == null)
merged = v;
else
merged = merged.withFallback(v);
}
return merged;
}
}
|
java
|
static AbstractConfigValue makeReplacement(ResolveContext context, List<AbstractConfigValue> stack, int skipping) {
List<AbstractConfigValue> subStack = stack.subList(skipping, stack.size());
if (subStack.isEmpty()) {
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace(context.depth(), "Nothing else in the merge stack, replacing with null");
return null;
} else {
// generate a new merge stack from only the remaining items
AbstractConfigValue merged = null;
for (AbstractConfigValue v : subStack) {
if (merged == null)
merged = v;
else
merged = merged.withFallback(v);
}
return merged;
}
}
|
[
"static",
"AbstractConfigValue",
"makeReplacement",
"(",
"ResolveContext",
"context",
",",
"List",
"<",
"AbstractConfigValue",
">",
"stack",
",",
"int",
"skipping",
")",
"{",
"List",
"<",
"AbstractConfigValue",
">",
"subStack",
"=",
"stack",
".",
"subList",
"(",
"skipping",
",",
"stack",
".",
"size",
"(",
")",
")",
";",
"if",
"(",
"subStack",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"ConfigImpl",
".",
"traceSubstitutionsEnabled",
"(",
")",
")",
"ConfigImpl",
".",
"trace",
"(",
"context",
".",
"depth",
"(",
")",
",",
"\"Nothing else in the merge stack, replacing with null\"",
")",
";",
"return",
"null",
";",
"}",
"else",
"{",
"// generate a new merge stack from only the remaining items",
"AbstractConfigValue",
"merged",
"=",
"null",
";",
"for",
"(",
"AbstractConfigValue",
"v",
":",
"subStack",
")",
"{",
"if",
"(",
"merged",
"==",
"null",
")",
"merged",
"=",
"v",
";",
"else",
"merged",
"=",
"merged",
".",
"withFallback",
"(",
"v",
")",
";",
"}",
"return",
"merged",
";",
"}",
"}"
] |
static method also used by ConfigDelayedMergeObject; end may be null
|
[
"static",
"method",
"also",
"used",
"by",
"ConfigDelayedMergeObject",
";",
"end",
"may",
"be",
"null"
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java#L161-L179
|
14,902
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java
|
ConfigDelayedMerge.stackIgnoresFallbacks
|
static boolean stackIgnoresFallbacks(List<AbstractConfigValue> stack) {
AbstractConfigValue last = stack.get(stack.size() - 1);
return last.ignoresFallbacks();
}
|
java
|
static boolean stackIgnoresFallbacks(List<AbstractConfigValue> stack) {
AbstractConfigValue last = stack.get(stack.size() - 1);
return last.ignoresFallbacks();
}
|
[
"static",
"boolean",
"stackIgnoresFallbacks",
"(",
"List",
"<",
"AbstractConfigValue",
">",
"stack",
")",
"{",
"AbstractConfigValue",
"last",
"=",
"stack",
".",
"get",
"(",
"stack",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"return",
"last",
".",
"ignoresFallbacks",
"(",
")",
";",
"}"
] |
static utility shared with ConfigDelayedMergeObject
|
[
"static",
"utility",
"shared",
"with",
"ConfigDelayedMergeObject"
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java#L210-L213
|
14,903
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java
|
ConfigDelayedMerge.render
|
static void render(List<AbstractConfigValue> stack, StringBuilder sb, int indent, boolean atRoot, String atKey,
ConfigRenderOptions options) {
boolean commentMerge = options.getComments();
if (commentMerge) {
sb.append("# unresolved merge of " + stack.size() + " values follows (\n");
if (atKey == null) {
indent(sb, indent, options);
sb.append("# this unresolved merge will not be parseable because it's at the root of the object\n");
indent(sb, indent, options);
sb.append("# the HOCON format has no way to list multiple root objects in a single file\n");
}
}
List<AbstractConfigValue> reversed = new ArrayList<AbstractConfigValue>();
reversed.addAll(stack);
Collections.reverse(reversed);
int i = 0;
for (AbstractConfigValue v : reversed) {
if (commentMerge) {
indent(sb, indent, options);
if (atKey != null) {
sb.append("# unmerged value " + i + " for key "
+ ConfigImplUtil.renderJsonString(atKey) + " from ");
} else {
sb.append("# unmerged value " + i + " from ");
}
i += 1;
sb.append(v.origin().description());
sb.append("\n");
for (String comment : v.origin().comments()) {
indent(sb, indent, options);
sb.append("# ");
sb.append(comment);
sb.append("\n");
}
}
indent(sb, indent, options);
if (atKey != null) {
sb.append(ConfigImplUtil.renderJsonString(atKey));
if (options.getFormatted())
sb.append(" : ");
else
sb.append(":");
}
v.render(sb, indent, atRoot, options);
sb.append(",");
if (options.getFormatted())
sb.append('\n');
}
// chop comma or newline
sb.setLength(sb.length() - 1);
if (options.getFormatted()) {
sb.setLength(sb.length() - 1); // also chop comma
sb.append("\n"); // put a newline back
}
if (commentMerge) {
indent(sb, indent, options);
sb.append("# ) end of unresolved merge\n");
}
}
|
java
|
static void render(List<AbstractConfigValue> stack, StringBuilder sb, int indent, boolean atRoot, String atKey,
ConfigRenderOptions options) {
boolean commentMerge = options.getComments();
if (commentMerge) {
sb.append("# unresolved merge of " + stack.size() + " values follows (\n");
if (atKey == null) {
indent(sb, indent, options);
sb.append("# this unresolved merge will not be parseable because it's at the root of the object\n");
indent(sb, indent, options);
sb.append("# the HOCON format has no way to list multiple root objects in a single file\n");
}
}
List<AbstractConfigValue> reversed = new ArrayList<AbstractConfigValue>();
reversed.addAll(stack);
Collections.reverse(reversed);
int i = 0;
for (AbstractConfigValue v : reversed) {
if (commentMerge) {
indent(sb, indent, options);
if (atKey != null) {
sb.append("# unmerged value " + i + " for key "
+ ConfigImplUtil.renderJsonString(atKey) + " from ");
} else {
sb.append("# unmerged value " + i + " from ");
}
i += 1;
sb.append(v.origin().description());
sb.append("\n");
for (String comment : v.origin().comments()) {
indent(sb, indent, options);
sb.append("# ");
sb.append(comment);
sb.append("\n");
}
}
indent(sb, indent, options);
if (atKey != null) {
sb.append(ConfigImplUtil.renderJsonString(atKey));
if (options.getFormatted())
sb.append(" : ");
else
sb.append(":");
}
v.render(sb, indent, atRoot, options);
sb.append(",");
if (options.getFormatted())
sb.append('\n');
}
// chop comma or newline
sb.setLength(sb.length() - 1);
if (options.getFormatted()) {
sb.setLength(sb.length() - 1); // also chop comma
sb.append("\n"); // put a newline back
}
if (commentMerge) {
indent(sb, indent, options);
sb.append("# ) end of unresolved merge\n");
}
}
|
[
"static",
"void",
"render",
"(",
"List",
"<",
"AbstractConfigValue",
">",
"stack",
",",
"StringBuilder",
"sb",
",",
"int",
"indent",
",",
"boolean",
"atRoot",
",",
"String",
"atKey",
",",
"ConfigRenderOptions",
"options",
")",
"{",
"boolean",
"commentMerge",
"=",
"options",
".",
"getComments",
"(",
")",
";",
"if",
"(",
"commentMerge",
")",
"{",
"sb",
".",
"append",
"(",
"\"# unresolved merge of \"",
"+",
"stack",
".",
"size",
"(",
")",
"+",
"\" values follows (\\n\"",
")",
";",
"if",
"(",
"atKey",
"==",
"null",
")",
"{",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"sb",
".",
"append",
"(",
"\"# this unresolved merge will not be parseable because it's at the root of the object\\n\"",
")",
";",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"sb",
".",
"append",
"(",
"\"# the HOCON format has no way to list multiple root objects in a single file\\n\"",
")",
";",
"}",
"}",
"List",
"<",
"AbstractConfigValue",
">",
"reversed",
"=",
"new",
"ArrayList",
"<",
"AbstractConfigValue",
">",
"(",
")",
";",
"reversed",
".",
"addAll",
"(",
"stack",
")",
";",
"Collections",
".",
"reverse",
"(",
"reversed",
")",
";",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"AbstractConfigValue",
"v",
":",
"reversed",
")",
"{",
"if",
"(",
"commentMerge",
")",
"{",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"if",
"(",
"atKey",
"!=",
"null",
")",
"{",
"sb",
".",
"append",
"(",
"\"# unmerged value \"",
"+",
"i",
"+",
"\" for key \"",
"+",
"ConfigImplUtil",
".",
"renderJsonString",
"(",
"atKey",
")",
"+",
"\" from \"",
")",
";",
"}",
"else",
"{",
"sb",
".",
"append",
"(",
"\"# unmerged value \"",
"+",
"i",
"+",
"\" from \"",
")",
";",
"}",
"i",
"+=",
"1",
";",
"sb",
".",
"append",
"(",
"v",
".",
"origin",
"(",
")",
".",
"description",
"(",
")",
")",
";",
"sb",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"for",
"(",
"String",
"comment",
":",
"v",
".",
"origin",
"(",
")",
".",
"comments",
"(",
")",
")",
"{",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"sb",
".",
"append",
"(",
"\"# \"",
")",
";",
"sb",
".",
"append",
"(",
"comment",
")",
";",
"sb",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"}",
"}",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"if",
"(",
"atKey",
"!=",
"null",
")",
"{",
"sb",
".",
"append",
"(",
"ConfigImplUtil",
".",
"renderJsonString",
"(",
"atKey",
")",
")",
";",
"if",
"(",
"options",
".",
"getFormatted",
"(",
")",
")",
"sb",
".",
"append",
"(",
"\" : \"",
")",
";",
"else",
"sb",
".",
"append",
"(",
"\":\"",
")",
";",
"}",
"v",
".",
"render",
"(",
"sb",
",",
"indent",
",",
"atRoot",
",",
"options",
")",
";",
"sb",
".",
"append",
"(",
"\",\"",
")",
";",
"if",
"(",
"options",
".",
"getFormatted",
"(",
")",
")",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"}",
"// chop comma or newline",
"sb",
".",
"setLength",
"(",
"sb",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"if",
"(",
"options",
".",
"getFormatted",
"(",
")",
")",
"{",
"sb",
".",
"setLength",
"(",
"sb",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"// also chop comma",
"sb",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"// put a newline back",
"}",
"if",
"(",
"commentMerge",
")",
"{",
"indent",
"(",
"sb",
",",
"indent",
",",
"options",
")",
";",
"sb",
".",
"append",
"(",
"\"# ) end of unresolved merge\\n\"",
")",
";",
"}",
"}"
] |
static method also used by ConfigDelayedMergeObject.
|
[
"static",
"method",
"also",
"used",
"by",
"ConfigDelayedMergeObject",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java#L279-L341
|
14,904
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ConfigImpl.java
|
ConfigImpl.improveNotResolved
|
static ConfigException.NotResolved improveNotResolved(Path what,
ConfigException.NotResolved original) {
String newMessage = what.render()
+ " has not been resolved, you need to call Config#resolve(),"
+ " see API docs for Config#resolve()";
if (newMessage.equals(original.getMessage()))
return original;
else
return new ConfigException.NotResolved(newMessage, original);
}
|
java
|
static ConfigException.NotResolved improveNotResolved(Path what,
ConfigException.NotResolved original) {
String newMessage = what.render()
+ " has not been resolved, you need to call Config#resolve(),"
+ " see API docs for Config#resolve()";
if (newMessage.equals(original.getMessage()))
return original;
else
return new ConfigException.NotResolved(newMessage, original);
}
|
[
"static",
"ConfigException",
".",
"NotResolved",
"improveNotResolved",
"(",
"Path",
"what",
",",
"ConfigException",
".",
"NotResolved",
"original",
")",
"{",
"String",
"newMessage",
"=",
"what",
".",
"render",
"(",
")",
"+",
"\" has not been resolved, you need to call Config#resolve(),\"",
"+",
"\" see API docs for Config#resolve()\"",
";",
"if",
"(",
"newMessage",
".",
"equals",
"(",
"original",
".",
"getMessage",
"(",
")",
")",
")",
"return",
"original",
";",
"else",
"return",
"new",
"ConfigException",
".",
"NotResolved",
"(",
"newMessage",
",",
"original",
")",
";",
"}"
] |
further down on the stack.
|
[
"further",
"down",
"on",
"the",
"stack",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java#L489-L498
|
14,905
|
lightbend/config
|
config/src/main/java/com/typesafe/config/ConfigRenderOptions.java
|
ConfigRenderOptions.setFormatted
|
public ConfigRenderOptions setFormatted(boolean value) {
if (value == formatted)
return this;
else
return new ConfigRenderOptions(originComments, comments, value, json);
}
|
java
|
public ConfigRenderOptions setFormatted(boolean value) {
if (value == formatted)
return this;
else
return new ConfigRenderOptions(originComments, comments, value, json);
}
|
[
"public",
"ConfigRenderOptions",
"setFormatted",
"(",
"boolean",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"formatted",
")",
"return",
"this",
";",
"else",
"return",
"new",
"ConfigRenderOptions",
"(",
"originComments",
",",
"comments",
",",
"value",
",",
"json",
")",
";",
"}"
] |
Returns options with formatting toggled. Formatting means indentation and
whitespace, enabling formatting makes things prettier but larger.
@param value
true to enable formatting
@return options with requested setting for formatting
|
[
"Returns",
"options",
"with",
"formatting",
"toggled",
".",
"Formatting",
"means",
"indentation",
"and",
"whitespace",
"enabling",
"formatting",
"makes",
"things",
"prettier",
"but",
"larger",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/ConfigRenderOptions.java#L121-L126
|
14,906
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ResolveSource.java
|
ResolveSource.rootMustBeObj
|
private AbstractConfigObject rootMustBeObj(Container value) {
if (value instanceof AbstractConfigObject) {
return (AbstractConfigObject) value;
} else {
return SimpleConfigObject.empty();
}
}
|
java
|
private AbstractConfigObject rootMustBeObj(Container value) {
if (value instanceof AbstractConfigObject) {
return (AbstractConfigObject) value;
} else {
return SimpleConfigObject.empty();
}
}
|
[
"private",
"AbstractConfigObject",
"rootMustBeObj",
"(",
"Container",
"value",
")",
"{",
"if",
"(",
"value",
"instanceof",
"AbstractConfigObject",
")",
"{",
"return",
"(",
"AbstractConfigObject",
")",
"value",
";",
"}",
"else",
"{",
"return",
"SimpleConfigObject",
".",
"empty",
"(",
")",
";",
"}",
"}"
] |
object with nothing in it instead.
|
[
"object",
"with",
"nothing",
"in",
"it",
"instead",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ResolveSource.java#L29-L35
|
14,907
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ResolveSource.java
|
ResolveSource.findInObject
|
static private ResultWithPath findInObject(AbstractConfigObject obj, ResolveContext context, Path path)
throws NotPossibleToResolve {
// resolve ONLY portions of the object which are along our path
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace("*** finding '" + path + "' in " + obj);
Path restriction = context.restrictToChild();
ResolveResult<? extends AbstractConfigValue> partiallyResolved = context.restrict(path).resolve(obj,
new ResolveSource(obj));
ResolveContext newContext = partiallyResolved.context.restrict(restriction);
if (partiallyResolved.value instanceof AbstractConfigObject) {
ValueWithPath pair = findInObject((AbstractConfigObject) partiallyResolved.value, path);
return new ResultWithPath(ResolveResult.make(newContext, pair.value), pair.pathFromRoot);
} else {
throw new ConfigException.BugOrBroken("resolved object to non-object " + obj + " to " + partiallyResolved);
}
}
|
java
|
static private ResultWithPath findInObject(AbstractConfigObject obj, ResolveContext context, Path path)
throws NotPossibleToResolve {
// resolve ONLY portions of the object which are along our path
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace("*** finding '" + path + "' in " + obj);
Path restriction = context.restrictToChild();
ResolveResult<? extends AbstractConfigValue> partiallyResolved = context.restrict(path).resolve(obj,
new ResolveSource(obj));
ResolveContext newContext = partiallyResolved.context.restrict(restriction);
if (partiallyResolved.value instanceof AbstractConfigObject) {
ValueWithPath pair = findInObject((AbstractConfigObject) partiallyResolved.value, path);
return new ResultWithPath(ResolveResult.make(newContext, pair.value), pair.pathFromRoot);
} else {
throw new ConfigException.BugOrBroken("resolved object to non-object " + obj + " to " + partiallyResolved);
}
}
|
[
"static",
"private",
"ResultWithPath",
"findInObject",
"(",
"AbstractConfigObject",
"obj",
",",
"ResolveContext",
"context",
",",
"Path",
"path",
")",
"throws",
"NotPossibleToResolve",
"{",
"// resolve ONLY portions of the object which are along our path",
"if",
"(",
"ConfigImpl",
".",
"traceSubstitutionsEnabled",
"(",
")",
")",
"ConfigImpl",
".",
"trace",
"(",
"\"*** finding '\"",
"+",
"path",
"+",
"\"' in \"",
"+",
"obj",
")",
";",
"Path",
"restriction",
"=",
"context",
".",
"restrictToChild",
"(",
")",
";",
"ResolveResult",
"<",
"?",
"extends",
"AbstractConfigValue",
">",
"partiallyResolved",
"=",
"context",
".",
"restrict",
"(",
"path",
")",
".",
"resolve",
"(",
"obj",
",",
"new",
"ResolveSource",
"(",
"obj",
")",
")",
";",
"ResolveContext",
"newContext",
"=",
"partiallyResolved",
".",
"context",
".",
"restrict",
"(",
"restriction",
")",
";",
"if",
"(",
"partiallyResolved",
".",
"value",
"instanceof",
"AbstractConfigObject",
")",
"{",
"ValueWithPath",
"pair",
"=",
"findInObject",
"(",
"(",
"AbstractConfigObject",
")",
"partiallyResolved",
".",
"value",
",",
"path",
")",
";",
"return",
"new",
"ResultWithPath",
"(",
"ResolveResult",
".",
"make",
"(",
"newContext",
",",
"pair",
".",
"value",
")",
",",
"pair",
".",
"pathFromRoot",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"resolved object to non-object \"",
"+",
"obj",
"+",
"\" to \"",
"+",
"partiallyResolved",
")",
";",
"}",
"}"
] |
the ValueWithPath instance itself should not be.
|
[
"the",
"ValueWithPath",
"instance",
"itself",
"should",
"not",
"be",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ResolveSource.java#L41-L56
|
14,908
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ResolveSource.java
|
ResolveSource.replace
|
private static Node<Container> replace(Node<Container> list, Container old, AbstractConfigValue replacement) {
Container child = list.head();
if (child != old)
throw new ConfigException.BugOrBroken("Can only replace() the top node we're resolving; had " + child
+ " on top and tried to replace " + old + " overall list was " + list);
Container parent = list.tail() == null ? null : list.tail().head();
if (replacement == null || !(replacement instanceof Container)) {
if (parent == null) {
return null;
} else {
/*
* we are deleting the child from the stack of containers
* because it's either going away or not a container
*/
AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, null);
return replace(list.tail(), parent, newParent);
}
} else {
/* we replaced the container with another container */
if (parent == null) {
return new Node<Container>((Container) replacement);
} else {
AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, replacement);
Node<Container> newTail = replace(list.tail(), parent, newParent);
if (newTail != null)
return newTail.prepend((Container) replacement);
else
return new Node<Container>((Container) replacement);
}
}
}
|
java
|
private static Node<Container> replace(Node<Container> list, Container old, AbstractConfigValue replacement) {
Container child = list.head();
if (child != old)
throw new ConfigException.BugOrBroken("Can only replace() the top node we're resolving; had " + child
+ " on top and tried to replace " + old + " overall list was " + list);
Container parent = list.tail() == null ? null : list.tail().head();
if (replacement == null || !(replacement instanceof Container)) {
if (parent == null) {
return null;
} else {
/*
* we are deleting the child from the stack of containers
* because it's either going away or not a container
*/
AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, null);
return replace(list.tail(), parent, newParent);
}
} else {
/* we replaced the container with another container */
if (parent == null) {
return new Node<Container>((Container) replacement);
} else {
AbstractConfigValue newParent = parent.replaceChild((AbstractConfigValue) old, replacement);
Node<Container> newTail = replace(list.tail(), parent, newParent);
if (newTail != null)
return newTail.prepend((Container) replacement);
else
return new Node<Container>((Container) replacement);
}
}
}
|
[
"private",
"static",
"Node",
"<",
"Container",
">",
"replace",
"(",
"Node",
"<",
"Container",
">",
"list",
",",
"Container",
"old",
",",
"AbstractConfigValue",
"replacement",
")",
"{",
"Container",
"child",
"=",
"list",
".",
"head",
"(",
")",
";",
"if",
"(",
"child",
"!=",
"old",
")",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"Can only replace() the top node we're resolving; had \"",
"+",
"child",
"+",
"\" on top and tried to replace \"",
"+",
"old",
"+",
"\" overall list was \"",
"+",
"list",
")",
";",
"Container",
"parent",
"=",
"list",
".",
"tail",
"(",
")",
"==",
"null",
"?",
"null",
":",
"list",
".",
"tail",
"(",
")",
".",
"head",
"(",
")",
";",
"if",
"(",
"replacement",
"==",
"null",
"||",
"!",
"(",
"replacement",
"instanceof",
"Container",
")",
")",
"{",
"if",
"(",
"parent",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"/*\n * we are deleting the child from the stack of containers\n * because it's either going away or not a container\n */",
"AbstractConfigValue",
"newParent",
"=",
"parent",
".",
"replaceChild",
"(",
"(",
"AbstractConfigValue",
")",
"old",
",",
"null",
")",
";",
"return",
"replace",
"(",
"list",
".",
"tail",
"(",
")",
",",
"parent",
",",
"newParent",
")",
";",
"}",
"}",
"else",
"{",
"/* we replaced the container with another container */",
"if",
"(",
"parent",
"==",
"null",
")",
"{",
"return",
"new",
"Node",
"<",
"Container",
">",
"(",
"(",
"Container",
")",
"replacement",
")",
";",
"}",
"else",
"{",
"AbstractConfigValue",
"newParent",
"=",
"parent",
".",
"replaceChild",
"(",
"(",
"AbstractConfigValue",
")",
"old",
",",
"replacement",
")",
";",
"Node",
"<",
"Container",
">",
"newTail",
"=",
"replace",
"(",
"list",
".",
"tail",
"(",
")",
",",
"parent",
",",
"newParent",
")",
";",
"if",
"(",
"newTail",
"!=",
"null",
")",
"return",
"newTail",
".",
"prepend",
"(",
"(",
"Container",
")",
"replacement",
")",
";",
"else",
"return",
"new",
"Node",
"<",
"Container",
">",
"(",
"(",
"Container",
")",
"replacement",
")",
";",
"}",
"}",
"}"
] |
returns null if the replacement results in deleting all the nodes.
|
[
"returns",
"null",
"if",
"the",
"replacement",
"results",
"in",
"deleting",
"all",
"the",
"nodes",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ResolveSource.java#L169-L200
|
14,909
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/ResolveSource.java
|
ResolveSource.replaceWithinCurrentParent
|
ResolveSource replaceWithinCurrentParent(AbstractConfigValue old, AbstractConfigValue replacement) {
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace("replaceWithinCurrentParent old " + old + "@" + System.identityHashCode(old)
+ " replacement " + replacement + "@" + System.identityHashCode(old) + " in " + this);
if (old == replacement) {
return this;
} else if (pathFromRoot != null) {
Container parent = pathFromRoot.head();
AbstractConfigValue newParent = parent.replaceChild(old, replacement);
return replaceCurrentParent(parent, (newParent instanceof Container) ? (Container) newParent : null);
} else {
if (old == root && replacement instanceof Container) {
return new ResolveSource(rootMustBeObj((Container) replacement));
} else {
throw new ConfigException.BugOrBroken("replace in parent not possible " + old + " with " + replacement
+ " in " + this);
// return this;
}
}
}
|
java
|
ResolveSource replaceWithinCurrentParent(AbstractConfigValue old, AbstractConfigValue replacement) {
if (ConfigImpl.traceSubstitutionsEnabled())
ConfigImpl.trace("replaceWithinCurrentParent old " + old + "@" + System.identityHashCode(old)
+ " replacement " + replacement + "@" + System.identityHashCode(old) + " in " + this);
if (old == replacement) {
return this;
} else if (pathFromRoot != null) {
Container parent = pathFromRoot.head();
AbstractConfigValue newParent = parent.replaceChild(old, replacement);
return replaceCurrentParent(parent, (newParent instanceof Container) ? (Container) newParent : null);
} else {
if (old == root && replacement instanceof Container) {
return new ResolveSource(rootMustBeObj((Container) replacement));
} else {
throw new ConfigException.BugOrBroken("replace in parent not possible " + old + " with " + replacement
+ " in " + this);
// return this;
}
}
}
|
[
"ResolveSource",
"replaceWithinCurrentParent",
"(",
"AbstractConfigValue",
"old",
",",
"AbstractConfigValue",
"replacement",
")",
"{",
"if",
"(",
"ConfigImpl",
".",
"traceSubstitutionsEnabled",
"(",
")",
")",
"ConfigImpl",
".",
"trace",
"(",
"\"replaceWithinCurrentParent old \"",
"+",
"old",
"+",
"\"@\"",
"+",
"System",
".",
"identityHashCode",
"(",
"old",
")",
"+",
"\" replacement \"",
"+",
"replacement",
"+",
"\"@\"",
"+",
"System",
".",
"identityHashCode",
"(",
"old",
")",
"+",
"\" in \"",
"+",
"this",
")",
";",
"if",
"(",
"old",
"==",
"replacement",
")",
"{",
"return",
"this",
";",
"}",
"else",
"if",
"(",
"pathFromRoot",
"!=",
"null",
")",
"{",
"Container",
"parent",
"=",
"pathFromRoot",
".",
"head",
"(",
")",
";",
"AbstractConfigValue",
"newParent",
"=",
"parent",
".",
"replaceChild",
"(",
"old",
",",
"replacement",
")",
";",
"return",
"replaceCurrentParent",
"(",
"parent",
",",
"(",
"newParent",
"instanceof",
"Container",
")",
"?",
"(",
"Container",
")",
"newParent",
":",
"null",
")",
";",
"}",
"else",
"{",
"if",
"(",
"old",
"==",
"root",
"&&",
"replacement",
"instanceof",
"Container",
")",
"{",
"return",
"new",
"ResolveSource",
"(",
"rootMustBeObj",
"(",
"(",
"Container",
")",
"replacement",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"replace in parent not possible \"",
"+",
"old",
"+",
"\" with \"",
"+",
"replacement",
"+",
"\" in \"",
"+",
"this",
")",
";",
"// return this;",
"}",
"}",
"}"
] |
replacement may be null to delete
|
[
"replacement",
"may",
"be",
"null",
"to",
"delete"
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/ResolveSource.java#L231-L250
|
14,910
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/Tokenizer.java
|
Tokenizer.tokenize
|
static Iterator<Token> tokenize(ConfigOrigin origin, Reader input, ConfigSyntax flavor) {
return new TokenIterator(origin, input, flavor != ConfigSyntax.JSON);
}
|
java
|
static Iterator<Token> tokenize(ConfigOrigin origin, Reader input, ConfigSyntax flavor) {
return new TokenIterator(origin, input, flavor != ConfigSyntax.JSON);
}
|
[
"static",
"Iterator",
"<",
"Token",
">",
"tokenize",
"(",
"ConfigOrigin",
"origin",
",",
"Reader",
"input",
",",
"ConfigSyntax",
"flavor",
")",
"{",
"return",
"new",
"TokenIterator",
"(",
"origin",
",",
"input",
",",
"flavor",
"!=",
"ConfigSyntax",
".",
"JSON",
")",
";",
"}"
] |
Tokenizes a Reader. Does not close the reader; you have to arrange to do
that after you're done with the returned iterator.
|
[
"Tokenizes",
"a",
"Reader",
".",
"Does",
"not",
"close",
"the",
"reader",
";",
"you",
"have",
"to",
"arrange",
"to",
"do",
"that",
"after",
"you",
"re",
"done",
"with",
"the",
"returned",
"iterator",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/Tokenizer.java#L51-L53
|
14,911
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/SimpleConfigOrigin.java
|
SimpleConfigOrigin.mergeThree
|
private static SimpleConfigOrigin mergeThree(SimpleConfigOrigin a, SimpleConfigOrigin b, SimpleConfigOrigin c) {
if (similarity(a, b) >= similarity(b, c)) {
return mergeTwo(mergeTwo(a, b), c);
} else {
return mergeTwo(a, mergeTwo(b, c));
}
}
|
java
|
private static SimpleConfigOrigin mergeThree(SimpleConfigOrigin a, SimpleConfigOrigin b, SimpleConfigOrigin c) {
if (similarity(a, b) >= similarity(b, c)) {
return mergeTwo(mergeTwo(a, b), c);
} else {
return mergeTwo(a, mergeTwo(b, c));
}
}
|
[
"private",
"static",
"SimpleConfigOrigin",
"mergeThree",
"(",
"SimpleConfigOrigin",
"a",
",",
"SimpleConfigOrigin",
"b",
",",
"SimpleConfigOrigin",
"c",
")",
"{",
"if",
"(",
"similarity",
"(",
"a",
",",
"b",
")",
">=",
"similarity",
"(",
"b",
",",
"c",
")",
")",
"{",
"return",
"mergeTwo",
"(",
"mergeTwo",
"(",
"a",
",",
"b",
")",
",",
"c",
")",
";",
"}",
"else",
"{",
"return",
"mergeTwo",
"(",
"a",
",",
"mergeTwo",
"(",
"b",
",",
"c",
")",
")",
";",
"}",
"}"
] |
better consolidated.
|
[
"better",
"consolidated",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/SimpleConfigOrigin.java#L338-L344
|
14,912
|
lightbend/config
|
config/src/main/java/com/typesafe/config/impl/SimpleConfigOrigin.java
|
SimpleConfigOrigin.fieldsDelta
|
static Map<SerializedField, Object> fieldsDelta(Map<SerializedField, Object> base,
Map<SerializedField, Object> child) {
Map<SerializedField, Object> m = new EnumMap<SerializedField, Object>(child);
for (Map.Entry<SerializedField, Object> baseEntry : base.entrySet()) {
SerializedField f = baseEntry.getKey();
if (m.containsKey(f) && ConfigImplUtil.equalsHandlingNull(baseEntry.getValue(), m.get(f))) {
// if field is unchanged, just remove it so we inherit
m.remove(f);
} else if (!m.containsKey(f)) {
// if field has been removed, we have to add a deletion entry
switch (f) {
case ORIGIN_DESCRIPTION:
throw new ConfigException.BugOrBroken("origin missing description field? " + child);
case ORIGIN_LINE_NUMBER:
m.put(SerializedField.ORIGIN_LINE_NUMBER, -1);
break;
case ORIGIN_END_LINE_NUMBER:
m.put(SerializedField.ORIGIN_END_LINE_NUMBER, -1);
break;
case ORIGIN_TYPE:
throw new ConfigException.BugOrBroken("should always be an ORIGIN_TYPE field");
case ORIGIN_URL:
m.put(SerializedField.ORIGIN_NULL_URL, "");
break;
case ORIGIN_RESOURCE:
m.put(SerializedField.ORIGIN_NULL_RESOURCE, "");
break;
case ORIGIN_COMMENTS:
m.put(SerializedField.ORIGIN_NULL_COMMENTS, "");
break;
case ORIGIN_NULL_URL: // FALL THRU
case ORIGIN_NULL_RESOURCE: // FALL THRU
case ORIGIN_NULL_COMMENTS:
throw new ConfigException.BugOrBroken("computing delta, base object should not contain " + f + " "
+ base);
case END_MARKER:
case ROOT_VALUE:
case ROOT_WAS_CONFIG:
case UNKNOWN:
case VALUE_DATA:
case VALUE_ORIGIN:
throw new ConfigException.BugOrBroken("should not appear here: " + f);
}
} else {
// field is in base and child, but differs, so leave it
}
}
return m;
}
|
java
|
static Map<SerializedField, Object> fieldsDelta(Map<SerializedField, Object> base,
Map<SerializedField, Object> child) {
Map<SerializedField, Object> m = new EnumMap<SerializedField, Object>(child);
for (Map.Entry<SerializedField, Object> baseEntry : base.entrySet()) {
SerializedField f = baseEntry.getKey();
if (m.containsKey(f) && ConfigImplUtil.equalsHandlingNull(baseEntry.getValue(), m.get(f))) {
// if field is unchanged, just remove it so we inherit
m.remove(f);
} else if (!m.containsKey(f)) {
// if field has been removed, we have to add a deletion entry
switch (f) {
case ORIGIN_DESCRIPTION:
throw new ConfigException.BugOrBroken("origin missing description field? " + child);
case ORIGIN_LINE_NUMBER:
m.put(SerializedField.ORIGIN_LINE_NUMBER, -1);
break;
case ORIGIN_END_LINE_NUMBER:
m.put(SerializedField.ORIGIN_END_LINE_NUMBER, -1);
break;
case ORIGIN_TYPE:
throw new ConfigException.BugOrBroken("should always be an ORIGIN_TYPE field");
case ORIGIN_URL:
m.put(SerializedField.ORIGIN_NULL_URL, "");
break;
case ORIGIN_RESOURCE:
m.put(SerializedField.ORIGIN_NULL_RESOURCE, "");
break;
case ORIGIN_COMMENTS:
m.put(SerializedField.ORIGIN_NULL_COMMENTS, "");
break;
case ORIGIN_NULL_URL: // FALL THRU
case ORIGIN_NULL_RESOURCE: // FALL THRU
case ORIGIN_NULL_COMMENTS:
throw new ConfigException.BugOrBroken("computing delta, base object should not contain " + f + " "
+ base);
case END_MARKER:
case ROOT_VALUE:
case ROOT_WAS_CONFIG:
case UNKNOWN:
case VALUE_DATA:
case VALUE_ORIGIN:
throw new ConfigException.BugOrBroken("should not appear here: " + f);
}
} else {
// field is in base and child, but differs, so leave it
}
}
return m;
}
|
[
"static",
"Map",
"<",
"SerializedField",
",",
"Object",
">",
"fieldsDelta",
"(",
"Map",
"<",
"SerializedField",
",",
"Object",
">",
"base",
",",
"Map",
"<",
"SerializedField",
",",
"Object",
">",
"child",
")",
"{",
"Map",
"<",
"SerializedField",
",",
"Object",
">",
"m",
"=",
"new",
"EnumMap",
"<",
"SerializedField",
",",
"Object",
">",
"(",
"child",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"SerializedField",
",",
"Object",
">",
"baseEntry",
":",
"base",
".",
"entrySet",
"(",
")",
")",
"{",
"SerializedField",
"f",
"=",
"baseEntry",
".",
"getKey",
"(",
")",
";",
"if",
"(",
"m",
".",
"containsKey",
"(",
"f",
")",
"&&",
"ConfigImplUtil",
".",
"equalsHandlingNull",
"(",
"baseEntry",
".",
"getValue",
"(",
")",
",",
"m",
".",
"get",
"(",
"f",
")",
")",
")",
"{",
"// if field is unchanged, just remove it so we inherit",
"m",
".",
"remove",
"(",
"f",
")",
";",
"}",
"else",
"if",
"(",
"!",
"m",
".",
"containsKey",
"(",
"f",
")",
")",
"{",
"// if field has been removed, we have to add a deletion entry",
"switch",
"(",
"f",
")",
"{",
"case",
"ORIGIN_DESCRIPTION",
":",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"origin missing description field? \"",
"+",
"child",
")",
";",
"case",
"ORIGIN_LINE_NUMBER",
":",
"m",
".",
"put",
"(",
"SerializedField",
".",
"ORIGIN_LINE_NUMBER",
",",
"-",
"1",
")",
";",
"break",
";",
"case",
"ORIGIN_END_LINE_NUMBER",
":",
"m",
".",
"put",
"(",
"SerializedField",
".",
"ORIGIN_END_LINE_NUMBER",
",",
"-",
"1",
")",
";",
"break",
";",
"case",
"ORIGIN_TYPE",
":",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"should always be an ORIGIN_TYPE field\"",
")",
";",
"case",
"ORIGIN_URL",
":",
"m",
".",
"put",
"(",
"SerializedField",
".",
"ORIGIN_NULL_URL",
",",
"\"\"",
")",
";",
"break",
";",
"case",
"ORIGIN_RESOURCE",
":",
"m",
".",
"put",
"(",
"SerializedField",
".",
"ORIGIN_NULL_RESOURCE",
",",
"\"\"",
")",
";",
"break",
";",
"case",
"ORIGIN_COMMENTS",
":",
"m",
".",
"put",
"(",
"SerializedField",
".",
"ORIGIN_NULL_COMMENTS",
",",
"\"\"",
")",
";",
"break",
";",
"case",
"ORIGIN_NULL_URL",
":",
"// FALL THRU",
"case",
"ORIGIN_NULL_RESOURCE",
":",
"// FALL THRU",
"case",
"ORIGIN_NULL_COMMENTS",
":",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"computing delta, base object should not contain \"",
"+",
"f",
"+",
"\" \"",
"+",
"base",
")",
";",
"case",
"END_MARKER",
":",
"case",
"ROOT_VALUE",
":",
"case",
"ROOT_WAS_CONFIG",
":",
"case",
"UNKNOWN",
":",
"case",
"VALUE_DATA",
":",
"case",
"VALUE_ORIGIN",
":",
"throw",
"new",
"ConfigException",
".",
"BugOrBroken",
"(",
"\"should not appear here: \"",
"+",
"f",
")",
";",
"}",
"}",
"else",
"{",
"// field is in base and child, but differs, so leave it",
"}",
"}",
"return",
"m",
";",
"}"
] |
filename with every single value.
|
[
"filename",
"with",
"every",
"single",
"value",
"."
] |
68cebfde5e861e9a5fdc75ceff366ed95e17d475
|
https://github.com/lightbend/config/blob/68cebfde5e861e9a5fdc75ceff366ed95e17d475/config/src/main/java/com/typesafe/config/impl/SimpleConfigOrigin.java#L424-L474
|
14,913
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.withDrawerWidthDp
|
public DrawerBuilder withDrawerWidthDp(int drawerWidthDp) {
if (mActivity == null) {
throw new RuntimeException("please pass an activity first to use this call");
}
this.mDrawerWidth = Utils.convertDpToPx(mActivity, drawerWidthDp);
return this;
}
|
java
|
public DrawerBuilder withDrawerWidthDp(int drawerWidthDp) {
if (mActivity == null) {
throw new RuntimeException("please pass an activity first to use this call");
}
this.mDrawerWidth = Utils.convertDpToPx(mActivity, drawerWidthDp);
return this;
}
|
[
"public",
"DrawerBuilder",
"withDrawerWidthDp",
"(",
"int",
"drawerWidthDp",
")",
"{",
"if",
"(",
"mActivity",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"please pass an activity first to use this call\"",
")",
";",
"}",
"this",
".",
"mDrawerWidth",
"=",
"Utils",
".",
"convertDpToPx",
"(",
"mActivity",
",",
"drawerWidthDp",
")",
";",
"return",
"this",
";",
"}"
] |
Set the DrawerBuilder width with a dp value
@param drawerWidthDp
@return
|
[
"Set",
"the",
"DrawerBuilder",
"width",
"with",
"a",
"dp",
"value"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L419-L426
|
14,914
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.addMenuItems
|
private void addMenuItems(Menu mMenu, boolean subMenu) {
int groupId = R.id.material_drawer_menu_default_group;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem mMenuItem = mMenu.getItem(i);
IDrawerItem iDrawerItem;
if (!subMenu && mMenuItem.getGroupId() != groupId && mMenuItem.getGroupId() != 0) {
groupId = mMenuItem.getGroupId();
iDrawerItem = new DividerDrawerItem();
getItemAdapter().add(iDrawerItem);
}
if (mMenuItem.hasSubMenu()) {
iDrawerItem = new PrimaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled())
.withSelectable(false);
getItemAdapter().add(iDrawerItem);
addMenuItems(mMenuItem.getSubMenu(), true);
} else if (mMenuItem.getGroupId() != 0 || subMenu) {
iDrawerItem = new SecondaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled());
getItemAdapter().add(iDrawerItem);
} else {
iDrawerItem = new PrimaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled());
getItemAdapter().add(iDrawerItem);
}
}
}
|
java
|
private void addMenuItems(Menu mMenu, boolean subMenu) {
int groupId = R.id.material_drawer_menu_default_group;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem mMenuItem = mMenu.getItem(i);
IDrawerItem iDrawerItem;
if (!subMenu && mMenuItem.getGroupId() != groupId && mMenuItem.getGroupId() != 0) {
groupId = mMenuItem.getGroupId();
iDrawerItem = new DividerDrawerItem();
getItemAdapter().add(iDrawerItem);
}
if (mMenuItem.hasSubMenu()) {
iDrawerItem = new PrimaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled())
.withSelectable(false);
getItemAdapter().add(iDrawerItem);
addMenuItems(mMenuItem.getSubMenu(), true);
} else if (mMenuItem.getGroupId() != 0 || subMenu) {
iDrawerItem = new SecondaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled());
getItemAdapter().add(iDrawerItem);
} else {
iDrawerItem = new PrimaryDrawerItem()
.withName(mMenuItem.getTitle().toString())
.withIcon(mMenuItem.getIcon())
.withIdentifier(mMenuItem.getItemId())
.withEnabled(mMenuItem.isEnabled());
getItemAdapter().add(iDrawerItem);
}
}
}
|
[
"private",
"void",
"addMenuItems",
"(",
"Menu",
"mMenu",
",",
"boolean",
"subMenu",
")",
"{",
"int",
"groupId",
"=",
"R",
".",
"id",
".",
"material_drawer_menu_default_group",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mMenu",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"MenuItem",
"mMenuItem",
"=",
"mMenu",
".",
"getItem",
"(",
"i",
")",
";",
"IDrawerItem",
"iDrawerItem",
";",
"if",
"(",
"!",
"subMenu",
"&&",
"mMenuItem",
".",
"getGroupId",
"(",
")",
"!=",
"groupId",
"&&",
"mMenuItem",
".",
"getGroupId",
"(",
")",
"!=",
"0",
")",
"{",
"groupId",
"=",
"mMenuItem",
".",
"getGroupId",
"(",
")",
";",
"iDrawerItem",
"=",
"new",
"DividerDrawerItem",
"(",
")",
";",
"getItemAdapter",
"(",
")",
".",
"add",
"(",
"iDrawerItem",
")",
";",
"}",
"if",
"(",
"mMenuItem",
".",
"hasSubMenu",
"(",
")",
")",
"{",
"iDrawerItem",
"=",
"new",
"PrimaryDrawerItem",
"(",
")",
".",
"withName",
"(",
"mMenuItem",
".",
"getTitle",
"(",
")",
".",
"toString",
"(",
")",
")",
".",
"withIcon",
"(",
"mMenuItem",
".",
"getIcon",
"(",
")",
")",
".",
"withIdentifier",
"(",
"mMenuItem",
".",
"getItemId",
"(",
")",
")",
".",
"withEnabled",
"(",
"mMenuItem",
".",
"isEnabled",
"(",
")",
")",
".",
"withSelectable",
"(",
"false",
")",
";",
"getItemAdapter",
"(",
")",
".",
"add",
"(",
"iDrawerItem",
")",
";",
"addMenuItems",
"(",
"mMenuItem",
".",
"getSubMenu",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"mMenuItem",
".",
"getGroupId",
"(",
")",
"!=",
"0",
"||",
"subMenu",
")",
"{",
"iDrawerItem",
"=",
"new",
"SecondaryDrawerItem",
"(",
")",
".",
"withName",
"(",
"mMenuItem",
".",
"getTitle",
"(",
")",
".",
"toString",
"(",
")",
")",
".",
"withIcon",
"(",
"mMenuItem",
".",
"getIcon",
"(",
")",
")",
".",
"withIdentifier",
"(",
"mMenuItem",
".",
"getItemId",
"(",
")",
")",
".",
"withEnabled",
"(",
"mMenuItem",
".",
"isEnabled",
"(",
")",
")",
";",
"getItemAdapter",
"(",
")",
".",
"add",
"(",
"iDrawerItem",
")",
";",
"}",
"else",
"{",
"iDrawerItem",
"=",
"new",
"PrimaryDrawerItem",
"(",
")",
".",
"withName",
"(",
"mMenuItem",
".",
"getTitle",
"(",
")",
".",
"toString",
"(",
")",
")",
".",
"withIcon",
"(",
"mMenuItem",
".",
"getIcon",
"(",
")",
")",
".",
"withIdentifier",
"(",
"mMenuItem",
".",
"getItemId",
"(",
")",
")",
".",
"withEnabled",
"(",
"mMenuItem",
".",
"isEnabled",
"(",
")",
")",
";",
"getItemAdapter",
"(",
")",
".",
"add",
"(",
"iDrawerItem",
")",
";",
"}",
"}",
"}"
] |
helper method to init the drawerItems from a menu
@param mMenu
@param subMenu
|
[
"helper",
"method",
"to",
"init",
"the",
"drawerItems",
"from",
"a",
"menu"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1048-L1083
|
14,915
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.handleShowOnLaunch
|
private void handleShowOnLaunch() {
//check if it should be shown on launch (and we have a drawerLayout)
if (mActivity != null && mDrawerLayout != null) {
if (mShowDrawerOnFirstLaunch || mShowDrawerUntilDraggedOpened) {
final SharedPreferences preferences = mSharedPreferences != null ? mSharedPreferences : PreferenceManager.getDefaultSharedPreferences(mActivity);
if (mShowDrawerOnFirstLaunch && !preferences.getBoolean(Drawer.PREF_USER_LEARNED_DRAWER, false)) {
//if it was not shown yet
//open the drawer
mDrawerLayout.openDrawer(mSliderLayout);
//save that it showed up once ;)
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(Drawer.PREF_USER_LEARNED_DRAWER, true);
editor.apply();
} else if (mShowDrawerUntilDraggedOpened && !preferences.getBoolean(Drawer.PREF_USER_OPENED_DRAWER_BY_DRAGGING, false)) {
// open the drawer since the user has not dragged it open yet
mDrawerLayout.openDrawer(mSliderLayout);
// add a listener to detect dragging
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
boolean hasBeenDragged = false;
@Override
public void onDrawerStateChanged(int newState) {
if (newState == DrawerLayout.STATE_DRAGGING) {
// save that the user was dragging
hasBeenDragged = true;
} else if (newState == DrawerLayout.STATE_IDLE) {
// check if the user was dragging and if that resulted in an open drawer
if (hasBeenDragged && mDrawerLayout.isDrawerOpen(mDrawerGravity)) {
// Save that the user has dragged it open
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(Drawer.PREF_USER_OPENED_DRAWER_BY_DRAGGING, true);
editor.apply();
} else {
// reset the drag boolean
hasBeenDragged = false;
}
}
}
});
}
}
}
}
|
java
|
private void handleShowOnLaunch() {
//check if it should be shown on launch (and we have a drawerLayout)
if (mActivity != null && mDrawerLayout != null) {
if (mShowDrawerOnFirstLaunch || mShowDrawerUntilDraggedOpened) {
final SharedPreferences preferences = mSharedPreferences != null ? mSharedPreferences : PreferenceManager.getDefaultSharedPreferences(mActivity);
if (mShowDrawerOnFirstLaunch && !preferences.getBoolean(Drawer.PREF_USER_LEARNED_DRAWER, false)) {
//if it was not shown yet
//open the drawer
mDrawerLayout.openDrawer(mSliderLayout);
//save that it showed up once ;)
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(Drawer.PREF_USER_LEARNED_DRAWER, true);
editor.apply();
} else if (mShowDrawerUntilDraggedOpened && !preferences.getBoolean(Drawer.PREF_USER_OPENED_DRAWER_BY_DRAGGING, false)) {
// open the drawer since the user has not dragged it open yet
mDrawerLayout.openDrawer(mSliderLayout);
// add a listener to detect dragging
mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
boolean hasBeenDragged = false;
@Override
public void onDrawerStateChanged(int newState) {
if (newState == DrawerLayout.STATE_DRAGGING) {
// save that the user was dragging
hasBeenDragged = true;
} else if (newState == DrawerLayout.STATE_IDLE) {
// check if the user was dragging and if that resulted in an open drawer
if (hasBeenDragged && mDrawerLayout.isDrawerOpen(mDrawerGravity)) {
// Save that the user has dragged it open
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(Drawer.PREF_USER_OPENED_DRAWER_BY_DRAGGING, true);
editor.apply();
} else {
// reset the drag boolean
hasBeenDragged = false;
}
}
}
});
}
}
}
}
|
[
"private",
"void",
"handleShowOnLaunch",
"(",
")",
"{",
"//check if it should be shown on launch (and we have a drawerLayout)",
"if",
"(",
"mActivity",
"!=",
"null",
"&&",
"mDrawerLayout",
"!=",
"null",
")",
"{",
"if",
"(",
"mShowDrawerOnFirstLaunch",
"||",
"mShowDrawerUntilDraggedOpened",
")",
"{",
"final",
"SharedPreferences",
"preferences",
"=",
"mSharedPreferences",
"!=",
"null",
"?",
"mSharedPreferences",
":",
"PreferenceManager",
".",
"getDefaultSharedPreferences",
"(",
"mActivity",
")",
";",
"if",
"(",
"mShowDrawerOnFirstLaunch",
"&&",
"!",
"preferences",
".",
"getBoolean",
"(",
"Drawer",
".",
"PREF_USER_LEARNED_DRAWER",
",",
"false",
")",
")",
"{",
"//if it was not shown yet",
"//open the drawer",
"mDrawerLayout",
".",
"openDrawer",
"(",
"mSliderLayout",
")",
";",
"//save that it showed up once ;)",
"SharedPreferences",
".",
"Editor",
"editor",
"=",
"preferences",
".",
"edit",
"(",
")",
";",
"editor",
".",
"putBoolean",
"(",
"Drawer",
".",
"PREF_USER_LEARNED_DRAWER",
",",
"true",
")",
";",
"editor",
".",
"apply",
"(",
")",
";",
"}",
"else",
"if",
"(",
"mShowDrawerUntilDraggedOpened",
"&&",
"!",
"preferences",
".",
"getBoolean",
"(",
"Drawer",
".",
"PREF_USER_OPENED_DRAWER_BY_DRAGGING",
",",
"false",
")",
")",
"{",
"// open the drawer since the user has not dragged it open yet",
"mDrawerLayout",
".",
"openDrawer",
"(",
"mSliderLayout",
")",
";",
"// add a listener to detect dragging",
"mDrawerLayout",
".",
"addDrawerListener",
"(",
"new",
"DrawerLayout",
".",
"SimpleDrawerListener",
"(",
")",
"{",
"boolean",
"hasBeenDragged",
"=",
"false",
";",
"@",
"Override",
"public",
"void",
"onDrawerStateChanged",
"(",
"int",
"newState",
")",
"{",
"if",
"(",
"newState",
"==",
"DrawerLayout",
".",
"STATE_DRAGGING",
")",
"{",
"// save that the user was dragging",
"hasBeenDragged",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"newState",
"==",
"DrawerLayout",
".",
"STATE_IDLE",
")",
"{",
"// check if the user was dragging and if that resulted in an open drawer",
"if",
"(",
"hasBeenDragged",
"&&",
"mDrawerLayout",
".",
"isDrawerOpen",
"(",
"mDrawerGravity",
")",
")",
"{",
"// Save that the user has dragged it open",
"SharedPreferences",
".",
"Editor",
"editor",
"=",
"preferences",
".",
"edit",
"(",
")",
";",
"editor",
".",
"putBoolean",
"(",
"Drawer",
".",
"PREF_USER_OPENED_DRAWER_BY_DRAGGING",
",",
"true",
")",
";",
"editor",
".",
"apply",
"(",
")",
";",
"}",
"else",
"{",
"// reset the drag boolean",
"hasBeenDragged",
"=",
"false",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
"}",
"}",
"}"
] |
helper method to handle when the drawer should be shown on launch
|
[
"helper",
"method",
"to",
"handle",
"when",
"the",
"drawer",
"should",
"be",
"shown",
"on",
"launch"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1265-L1312
|
14,916
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.buildView
|
public Drawer buildView() {
// get the slider view
mSliderLayout = (ScrimInsetsRelativeLayout) mActivity.getLayoutInflater().inflate(R.layout.material_drawer_slider, mDrawerLayout, false);
mSliderLayout.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
// get the layout params
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mSliderLayout.getLayoutParams();
if (params != null) {
// if we've set a custom gravity set it
params.gravity = mDrawerGravity;
// if this is a drawer from the right, change the margins :D
params = DrawerUtils.processDrawerLayoutParams(this, params);
// set the new layout params
mSliderLayout.setLayoutParams(params);
}
//create the content
createContent();
//create the result object
Drawer result = new Drawer(this);
//set the drawer for the accountHeader if set
if (mAccountHeader != null) {
mAccountHeader.setDrawer(result);
}
//toggle selection list if we were previously on the account list
if (mSavedInstance != null && mSavedInstance.getBoolean(Drawer.BUNDLE_DRAWER_CONTENT_SWITCHED, false)) {
mAccountHeader.toggleSelectionList(mActivity);
}
//handle if the drawer should be shown on launch
handleShowOnLaunch();
//we only want to hook a Drawer to the MiniDrawer if it is the main drawer, not the appended one
if (!mAppended && mGenerateMiniDrawer) {
// if we should create a MiniDrawer we have to do this now
mMiniDrawer = new MiniDrawer().withDrawer(result).withAccountHeader(mAccountHeader);
}
//forget the reference to the activity
mActivity = null;
return result;
}
|
java
|
public Drawer buildView() {
// get the slider view
mSliderLayout = (ScrimInsetsRelativeLayout) mActivity.getLayoutInflater().inflate(R.layout.material_drawer_slider, mDrawerLayout, false);
mSliderLayout.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
// get the layout params
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mSliderLayout.getLayoutParams();
if (params != null) {
// if we've set a custom gravity set it
params.gravity = mDrawerGravity;
// if this is a drawer from the right, change the margins :D
params = DrawerUtils.processDrawerLayoutParams(this, params);
// set the new layout params
mSliderLayout.setLayoutParams(params);
}
//create the content
createContent();
//create the result object
Drawer result = new Drawer(this);
//set the drawer for the accountHeader if set
if (mAccountHeader != null) {
mAccountHeader.setDrawer(result);
}
//toggle selection list if we were previously on the account list
if (mSavedInstance != null && mSavedInstance.getBoolean(Drawer.BUNDLE_DRAWER_CONTENT_SWITCHED, false)) {
mAccountHeader.toggleSelectionList(mActivity);
}
//handle if the drawer should be shown on launch
handleShowOnLaunch();
//we only want to hook a Drawer to the MiniDrawer if it is the main drawer, not the appended one
if (!mAppended && mGenerateMiniDrawer) {
// if we should create a MiniDrawer we have to do this now
mMiniDrawer = new MiniDrawer().withDrawer(result).withAccountHeader(mAccountHeader);
}
//forget the reference to the activity
mActivity = null;
return result;
}
|
[
"public",
"Drawer",
"buildView",
"(",
")",
"{",
"// get the slider view",
"mSliderLayout",
"=",
"(",
"ScrimInsetsRelativeLayout",
")",
"mActivity",
".",
"getLayoutInflater",
"(",
")",
".",
"inflate",
"(",
"R",
".",
"layout",
".",
"material_drawer_slider",
",",
"mDrawerLayout",
",",
"false",
")",
";",
"mSliderLayout",
".",
"setBackgroundColor",
"(",
"UIUtils",
".",
"getThemeColorFromAttrOrRes",
"(",
"mActivity",
",",
"R",
".",
"attr",
".",
"material_drawer_background",
",",
"R",
".",
"color",
".",
"material_drawer_background",
")",
")",
";",
"// get the layout params",
"DrawerLayout",
".",
"LayoutParams",
"params",
"=",
"(",
"DrawerLayout",
".",
"LayoutParams",
")",
"mSliderLayout",
".",
"getLayoutParams",
"(",
")",
";",
"if",
"(",
"params",
"!=",
"null",
")",
"{",
"// if we've set a custom gravity set it",
"params",
".",
"gravity",
"=",
"mDrawerGravity",
";",
"// if this is a drawer from the right, change the margins :D",
"params",
"=",
"DrawerUtils",
".",
"processDrawerLayoutParams",
"(",
"this",
",",
"params",
")",
";",
"// set the new layout params",
"mSliderLayout",
".",
"setLayoutParams",
"(",
"params",
")",
";",
"}",
"//create the content",
"createContent",
"(",
")",
";",
"//create the result object",
"Drawer",
"result",
"=",
"new",
"Drawer",
"(",
"this",
")",
";",
"//set the drawer for the accountHeader if set",
"if",
"(",
"mAccountHeader",
"!=",
"null",
")",
"{",
"mAccountHeader",
".",
"setDrawer",
"(",
"result",
")",
";",
"}",
"//toggle selection list if we were previously on the account list",
"if",
"(",
"mSavedInstance",
"!=",
"null",
"&&",
"mSavedInstance",
".",
"getBoolean",
"(",
"Drawer",
".",
"BUNDLE_DRAWER_CONTENT_SWITCHED",
",",
"false",
")",
")",
"{",
"mAccountHeader",
".",
"toggleSelectionList",
"(",
"mActivity",
")",
";",
"}",
"//handle if the drawer should be shown on launch",
"handleShowOnLaunch",
"(",
")",
";",
"//we only want to hook a Drawer to the MiniDrawer if it is the main drawer, not the appended one",
"if",
"(",
"!",
"mAppended",
"&&",
"mGenerateMiniDrawer",
")",
"{",
"// if we should create a MiniDrawer we have to do this now",
"mMiniDrawer",
"=",
"new",
"MiniDrawer",
"(",
")",
".",
"withDrawer",
"(",
"result",
")",
".",
"withAccountHeader",
"(",
"mAccountHeader",
")",
";",
"}",
"//forget the reference to the activity",
"mActivity",
"=",
"null",
";",
"return",
"result",
";",
"}"
] |
build the drawers content only. This will still return a Result object, but only with the content set. No inflating of a DrawerLayout.
@return Result object with only the content set
|
[
"build",
"the",
"drawers",
"content",
"only",
".",
"This",
"will",
"still",
"return",
"a",
"Result",
"object",
"but",
"only",
"with",
"the",
"content",
"set",
".",
"No",
"inflating",
"of",
"a",
"DrawerLayout",
"."
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1537-L1580
|
14,917
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.closeDrawerDelayed
|
protected void closeDrawerDelayed() {
if (mCloseOnClick && mDrawerLayout != null) {
if (mDelayOnDrawerClose > -1) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mDrawerLayout.closeDrawers();
if (mScrollToTopAfterClick) {
mRecyclerView.smoothScrollToPosition(0);
}
}
}, mDelayOnDrawerClose);
} else {
mDrawerLayout.closeDrawers();
}
}
}
|
java
|
protected void closeDrawerDelayed() {
if (mCloseOnClick && mDrawerLayout != null) {
if (mDelayOnDrawerClose > -1) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mDrawerLayout.closeDrawers();
if (mScrollToTopAfterClick) {
mRecyclerView.smoothScrollToPosition(0);
}
}
}, mDelayOnDrawerClose);
} else {
mDrawerLayout.closeDrawers();
}
}
}
|
[
"protected",
"void",
"closeDrawerDelayed",
"(",
")",
"{",
"if",
"(",
"mCloseOnClick",
"&&",
"mDrawerLayout",
"!=",
"null",
")",
"{",
"if",
"(",
"mDelayOnDrawerClose",
">",
"-",
"1",
")",
"{",
"new",
"Handler",
"(",
")",
".",
"postDelayed",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"mDrawerLayout",
".",
"closeDrawers",
"(",
")",
";",
"if",
"(",
"mScrollToTopAfterClick",
")",
"{",
"mRecyclerView",
".",
"smoothScrollToPosition",
"(",
"0",
")",
";",
"}",
"}",
"}",
",",
"mDelayOnDrawerClose",
")",
";",
"}",
"else",
"{",
"mDrawerLayout",
".",
"closeDrawers",
"(",
")",
";",
"}",
"}",
"}"
] |
helper method to close the drawer delayed
|
[
"helper",
"method",
"to",
"close",
"the",
"drawer",
"delayed"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1848-L1865
|
14,918
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java
|
DrawerBuilder.resetStickyFooterSelection
|
protected void resetStickyFooterSelection() {
if (mStickyFooterView instanceof LinearLayout) {
for (int i = 0; i < (mStickyFooterView).getChildCount(); i++) {
(mStickyFooterView).getChildAt(i).setActivated(false);
(mStickyFooterView).getChildAt(i).setSelected(false);
}
}
}
|
java
|
protected void resetStickyFooterSelection() {
if (mStickyFooterView instanceof LinearLayout) {
for (int i = 0; i < (mStickyFooterView).getChildCount(); i++) {
(mStickyFooterView).getChildAt(i).setActivated(false);
(mStickyFooterView).getChildAt(i).setSelected(false);
}
}
}
|
[
"protected",
"void",
"resetStickyFooterSelection",
"(",
")",
"{",
"if",
"(",
"mStickyFooterView",
"instanceof",
"LinearLayout",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"(",
"mStickyFooterView",
")",
".",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"(",
"mStickyFooterView",
")",
".",
"getChildAt",
"(",
"i",
")",
".",
"setActivated",
"(",
"false",
")",
";",
"(",
"mStickyFooterView",
")",
".",
"getChildAt",
"(",
"i",
")",
".",
"setSelected",
"(",
"false",
")",
";",
"}",
"}",
"}"
] |
simple helper method to reset the selection of the sticky footer
|
[
"simple",
"helper",
"method",
"to",
"reset",
"the",
"selection",
"of",
"the",
"sticky",
"footer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1891-L1898
|
14,919
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java
|
AccountHeader.setActiveProfile
|
public void setActiveProfile(IProfile profile, boolean fireOnProfileChanged) {
final boolean isCurrentSelectedProfile = mAccountHeaderBuilder.switchProfiles(profile);
//if the selectionList is shown we should also update the current selected profile in the list
if (mAccountHeaderBuilder.mDrawer != null && isSelectionListShown()) {
mAccountHeaderBuilder.mDrawer.setSelection(profile.getIdentifier(), false);
}
//fire the event if enabled and a listener is set
if (fireOnProfileChanged && mAccountHeaderBuilder.mOnAccountHeaderListener != null) {
mAccountHeaderBuilder.mOnAccountHeaderListener.onProfileChanged(null, profile, isCurrentSelectedProfile);
}
}
|
java
|
public void setActiveProfile(IProfile profile, boolean fireOnProfileChanged) {
final boolean isCurrentSelectedProfile = mAccountHeaderBuilder.switchProfiles(profile);
//if the selectionList is shown we should also update the current selected profile in the list
if (mAccountHeaderBuilder.mDrawer != null && isSelectionListShown()) {
mAccountHeaderBuilder.mDrawer.setSelection(profile.getIdentifier(), false);
}
//fire the event if enabled and a listener is set
if (fireOnProfileChanged && mAccountHeaderBuilder.mOnAccountHeaderListener != null) {
mAccountHeaderBuilder.mOnAccountHeaderListener.onProfileChanged(null, profile, isCurrentSelectedProfile);
}
}
|
[
"public",
"void",
"setActiveProfile",
"(",
"IProfile",
"profile",
",",
"boolean",
"fireOnProfileChanged",
")",
"{",
"final",
"boolean",
"isCurrentSelectedProfile",
"=",
"mAccountHeaderBuilder",
".",
"switchProfiles",
"(",
"profile",
")",
";",
"//if the selectionList is shown we should also update the current selected profile in the list",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mDrawer",
"!=",
"null",
"&&",
"isSelectionListShown",
"(",
")",
")",
"{",
"mAccountHeaderBuilder",
".",
"mDrawer",
".",
"setSelection",
"(",
"profile",
".",
"getIdentifier",
"(",
")",
",",
"false",
")",
";",
"}",
"//fire the event if enabled and a listener is set",
"if",
"(",
"fireOnProfileChanged",
"&&",
"mAccountHeaderBuilder",
".",
"mOnAccountHeaderListener",
"!=",
"null",
")",
"{",
"mAccountHeaderBuilder",
".",
"mOnAccountHeaderListener",
".",
"onProfileChanged",
"(",
"null",
",",
"profile",
",",
"isCurrentSelectedProfile",
")",
";",
"}",
"}"
] |
Selects the given profile and sets it to the new active profile
@param profile
|
[
"Selects",
"the",
"given",
"profile",
"and",
"sets",
"it",
"to",
"the",
"new",
"active",
"profile"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java#L190-L200
|
14,920
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java
|
AccountHeader.setActiveProfile
|
public void setActiveProfile(long identifier, boolean fireOnProfileChanged) {
if (mAccountHeaderBuilder.mProfiles != null) {
for (IProfile profile : mAccountHeaderBuilder.mProfiles) {
if (profile != null) {
if (profile.getIdentifier() == identifier) {
setActiveProfile(profile, fireOnProfileChanged);
return;
}
}
}
}
}
|
java
|
public void setActiveProfile(long identifier, boolean fireOnProfileChanged) {
if (mAccountHeaderBuilder.mProfiles != null) {
for (IProfile profile : mAccountHeaderBuilder.mProfiles) {
if (profile != null) {
if (profile.getIdentifier() == identifier) {
setActiveProfile(profile, fireOnProfileChanged);
return;
}
}
}
}
}
|
[
"public",
"void",
"setActiveProfile",
"(",
"long",
"identifier",
",",
"boolean",
"fireOnProfileChanged",
")",
"{",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mProfiles",
"!=",
"null",
")",
"{",
"for",
"(",
"IProfile",
"profile",
":",
"mAccountHeaderBuilder",
".",
"mProfiles",
")",
"{",
"if",
"(",
"profile",
"!=",
"null",
")",
"{",
"if",
"(",
"profile",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
")",
"{",
"setActiveProfile",
"(",
"profile",
",",
"fireOnProfileChanged",
")",
";",
"return",
";",
"}",
"}",
"}",
"}",
"}"
] |
Selects a profile by its identifier
@param identifier
|
[
"Selects",
"a",
"profile",
"by",
"its",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java#L216-L227
|
14,921
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java
|
AccountHeader.removeProfile
|
public void removeProfile(int position) {
if (mAccountHeaderBuilder.mProfiles != null && mAccountHeaderBuilder.mProfiles.size() > position) {
mAccountHeaderBuilder.mProfiles.remove(position);
}
mAccountHeaderBuilder.updateHeaderAndList();
}
|
java
|
public void removeProfile(int position) {
if (mAccountHeaderBuilder.mProfiles != null && mAccountHeaderBuilder.mProfiles.size() > position) {
mAccountHeaderBuilder.mProfiles.remove(position);
}
mAccountHeaderBuilder.updateHeaderAndList();
}
|
[
"public",
"void",
"removeProfile",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mProfiles",
"!=",
"null",
"&&",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"size",
"(",
")",
">",
"position",
")",
"{",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"remove",
"(",
"position",
")",
";",
"}",
"mAccountHeaderBuilder",
".",
"updateHeaderAndList",
"(",
")",
";",
"}"
] |
remove a profile from the given position
@param position
|
[
"remove",
"a",
"profile",
"from",
"the",
"given",
"position"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java#L298-L304
|
14,922
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java
|
AccountHeader.removeProfileByIdentifier
|
public void removeProfileByIdentifier(long identifier) {
int found = getPositionByIdentifier(identifier);
if (found > -1) {
mAccountHeaderBuilder.mProfiles.remove(found);
}
mAccountHeaderBuilder.updateHeaderAndList();
}
|
java
|
public void removeProfileByIdentifier(long identifier) {
int found = getPositionByIdentifier(identifier);
if (found > -1) {
mAccountHeaderBuilder.mProfiles.remove(found);
}
mAccountHeaderBuilder.updateHeaderAndList();
}
|
[
"public",
"void",
"removeProfileByIdentifier",
"(",
"long",
"identifier",
")",
"{",
"int",
"found",
"=",
"getPositionByIdentifier",
"(",
"identifier",
")",
";",
"if",
"(",
"found",
">",
"-",
"1",
")",
"{",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"remove",
"(",
"found",
")",
";",
"}",
"mAccountHeaderBuilder",
".",
"updateHeaderAndList",
"(",
")",
";",
"}"
] |
remove the profile with the given identifier
@param identifier
|
[
"remove",
"the",
"profile",
"with",
"the",
"given",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java#L311-L318
|
14,923
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java
|
AccountHeader.getPositionByIdentifier
|
private int getPositionByIdentifier(long identifier) {
int found = -1;
if (mAccountHeaderBuilder.mProfiles != null && identifier != -1) {
for (int i = 0; i < mAccountHeaderBuilder.mProfiles.size(); i++) {
if (mAccountHeaderBuilder.mProfiles.get(i) != null) {
if (mAccountHeaderBuilder.mProfiles.get(i).getIdentifier() == identifier) {
found = i;
break;
}
}
}
}
return found;
}
|
java
|
private int getPositionByIdentifier(long identifier) {
int found = -1;
if (mAccountHeaderBuilder.mProfiles != null && identifier != -1) {
for (int i = 0; i < mAccountHeaderBuilder.mProfiles.size(); i++) {
if (mAccountHeaderBuilder.mProfiles.get(i) != null) {
if (mAccountHeaderBuilder.mProfiles.get(i).getIdentifier() == identifier) {
found = i;
break;
}
}
}
}
return found;
}
|
[
"private",
"int",
"getPositionByIdentifier",
"(",
"long",
"identifier",
")",
"{",
"int",
"found",
"=",
"-",
"1",
";",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mProfiles",
"!=",
"null",
"&&",
"identifier",
"!=",
"-",
"1",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"get",
"(",
"i",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"mAccountHeaderBuilder",
".",
"mProfiles",
".",
"get",
"(",
"i",
")",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
")",
"{",
"found",
"=",
"i",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] |
gets the position of a profile by it's identifier
@param identifier
@return
|
[
"gets",
"the",
"position",
"of",
"a",
"profile",
"by",
"it",
"s",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeader.java#L348-L361
|
14,924
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/view/BezelImageView.java
|
BezelImageView.setSelectorColor
|
public void setSelectorColor(int selectorColor) {
this.mSelectorColor = selectorColor;
this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
this.invalidate();
}
|
java
|
public void setSelectorColor(int selectorColor) {
this.mSelectorColor = selectorColor;
this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP);
this.invalidate();
}
|
[
"public",
"void",
"setSelectorColor",
"(",
"int",
"selectorColor",
")",
"{",
"this",
".",
"mSelectorColor",
"=",
"selectorColor",
";",
"this",
".",
"mSelectorFilter",
"=",
"new",
"PorterDuffColorFilter",
"(",
"Color",
".",
"argb",
"(",
"mSelectorAlpha",
",",
"Color",
".",
"red",
"(",
"mSelectorColor",
")",
",",
"Color",
".",
"green",
"(",
"mSelectorColor",
")",
",",
"Color",
".",
"blue",
"(",
"mSelectorColor",
")",
")",
",",
"PorterDuff",
".",
"Mode",
".",
"SRC_ATOP",
")",
";",
"this",
".",
"invalidate",
"(",
")",
";",
"}"
] |
Sets the color of the selector to be draw over the
CircularImageView. Be sure to provide some opacity.
@param selectorColor The color (including alpha) to set for the selector overlay.
|
[
"Sets",
"the",
"color",
"of",
"the",
"selector",
"to",
"be",
"draw",
"over",
"the",
"CircularImageView",
".",
"Be",
"sure",
"to",
"provide",
"some",
"opacity",
"."
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/view/BezelImageView.java#L300-L304
|
14,925
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.generateMiniDrawerItem
|
public IDrawerItem generateMiniDrawerItem(IDrawerItem drawerItem) {
if (drawerItem instanceof SecondaryDrawerItem) {
return mIncludeSecondaryDrawerItems ? new MiniDrawerItem((SecondaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground).withSelectedBackgroundAnimated(false) : null;
} else if (drawerItem instanceof PrimaryDrawerItem) {
return new MiniDrawerItem((PrimaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground).withSelectedBackgroundAnimated(false);
} else if (drawerItem instanceof ProfileDrawerItem) {
MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem((ProfileDrawerItem) drawerItem);
mpdi.withEnabled(mEnableProfileClick);
return mpdi;
}
return null;
}
|
java
|
public IDrawerItem generateMiniDrawerItem(IDrawerItem drawerItem) {
if (drawerItem instanceof SecondaryDrawerItem) {
return mIncludeSecondaryDrawerItems ? new MiniDrawerItem((SecondaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground).withSelectedBackgroundAnimated(false) : null;
} else if (drawerItem instanceof PrimaryDrawerItem) {
return new MiniDrawerItem((PrimaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground).withSelectedBackgroundAnimated(false);
} else if (drawerItem instanceof ProfileDrawerItem) {
MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem((ProfileDrawerItem) drawerItem);
mpdi.withEnabled(mEnableProfileClick);
return mpdi;
}
return null;
}
|
[
"public",
"IDrawerItem",
"generateMiniDrawerItem",
"(",
"IDrawerItem",
"drawerItem",
")",
"{",
"if",
"(",
"drawerItem",
"instanceof",
"SecondaryDrawerItem",
")",
"{",
"return",
"mIncludeSecondaryDrawerItems",
"?",
"new",
"MiniDrawerItem",
"(",
"(",
"SecondaryDrawerItem",
")",
"drawerItem",
")",
".",
"withEnableSelectedBackground",
"(",
"mEnableSelectedMiniDrawerItemBackground",
")",
".",
"withSelectedBackgroundAnimated",
"(",
"false",
")",
":",
"null",
";",
"}",
"else",
"if",
"(",
"drawerItem",
"instanceof",
"PrimaryDrawerItem",
")",
"{",
"return",
"new",
"MiniDrawerItem",
"(",
"(",
"PrimaryDrawerItem",
")",
"drawerItem",
")",
".",
"withEnableSelectedBackground",
"(",
"mEnableSelectedMiniDrawerItemBackground",
")",
".",
"withSelectedBackgroundAnimated",
"(",
"false",
")",
";",
"}",
"else",
"if",
"(",
"drawerItem",
"instanceof",
"ProfileDrawerItem",
")",
"{",
"MiniProfileDrawerItem",
"mpdi",
"=",
"new",
"MiniProfileDrawerItem",
"(",
"(",
"ProfileDrawerItem",
")",
"drawerItem",
")",
";",
"mpdi",
".",
"withEnabled",
"(",
"mEnableProfileClick",
")",
";",
"return",
"mpdi",
";",
"}",
"return",
"null",
";",
"}"
] |
generates a MiniDrawerItem from a IDrawerItem
@param drawerItem
@return
|
[
"generates",
"a",
"MiniDrawerItem",
"from",
"a",
"IDrawerItem"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L267-L278
|
14,926
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.build
|
public View build(Context ctx) {
mContainer = new LinearLayout(ctx);
if (mInnerShadow) {
if (!mInRTL) {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
//create and append recyclerView
mRecyclerView = new RecyclerView(ctx);
mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//set the itemAnimator
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
//adapter
mItemAdapter = new ItemAdapter<>();
mAdapter = FastAdapter.with(mItemAdapter);
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mRecyclerView.setAdapter(mAdapter);
//if the activity with the drawer should be fullscreen add the padding for the statusbar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
}
//if the activity with the drawer should be fullscreen add the padding for the navigationBar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar) && ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx));
}
//set the adapter with the items
createItems();
return mContainer;
}
|
java
|
public View build(Context ctx) {
mContainer = new LinearLayout(ctx);
if (mInnerShadow) {
if (!mInRTL) {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
} else {
mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
}
}
//create and append recyclerView
mRecyclerView = new RecyclerView(ctx);
mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//set the itemAnimator
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
//some style improvements on older devices
mRecyclerView.setFadingEdgeLength(0);
//set the drawing cache background to the same color as the slider to improve performance
//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));
mRecyclerView.setClipToPadding(false);
//additional stuff
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
//adapter
mItemAdapter = new ItemAdapter<>();
mAdapter = FastAdapter.with(mItemAdapter);
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mRecyclerView.setAdapter(mAdapter);
//if the activity with the drawer should be fullscreen add the padding for the statusbar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
}
//if the activity with the drawer should be fullscreen add the padding for the navigationBar
if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar) && ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx));
}
//set the adapter with the items
createItems();
return mContainer;
}
|
[
"public",
"View",
"build",
"(",
"Context",
"ctx",
")",
"{",
"mContainer",
"=",
"new",
"LinearLayout",
"(",
"ctx",
")",
";",
"if",
"(",
"mInnerShadow",
")",
"{",
"if",
"(",
"!",
"mInRTL",
")",
"{",
"mContainer",
".",
"setBackgroundResource",
"(",
"R",
".",
"drawable",
".",
"material_drawer_shadow_left",
")",
";",
"}",
"else",
"{",
"mContainer",
".",
"setBackgroundResource",
"(",
"R",
".",
"drawable",
".",
"material_drawer_shadow_right",
")",
";",
"}",
"}",
"//create and append recyclerView",
"mRecyclerView",
"=",
"new",
"RecyclerView",
"(",
"ctx",
")",
";",
"mContainer",
".",
"addView",
"(",
"mRecyclerView",
",",
"ViewGroup",
".",
"LayoutParams",
".",
"MATCH_PARENT",
",",
"ViewGroup",
".",
"LayoutParams",
".",
"MATCH_PARENT",
")",
";",
"//set the itemAnimator",
"mRecyclerView",
".",
"setItemAnimator",
"(",
"new",
"DefaultItemAnimator",
"(",
")",
")",
";",
"//some style improvements on older devices",
"mRecyclerView",
".",
"setFadingEdgeLength",
"(",
"0",
")",
";",
"//set the drawing cache background to the same color as the slider to improve performance",
"//mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));",
"mRecyclerView",
".",
"setClipToPadding",
"(",
"false",
")",
";",
"//additional stuff",
"mRecyclerView",
".",
"setLayoutManager",
"(",
"new",
"LinearLayoutManager",
"(",
"ctx",
")",
")",
";",
"//adapter",
"mItemAdapter",
"=",
"new",
"ItemAdapter",
"<>",
"(",
")",
";",
"mAdapter",
"=",
"FastAdapter",
".",
"with",
"(",
"mItemAdapter",
")",
";",
"mAdapter",
".",
"withSelectable",
"(",
"true",
")",
";",
"mAdapter",
".",
"withAllowDeselection",
"(",
"false",
")",
";",
"mRecyclerView",
".",
"setAdapter",
"(",
"mAdapter",
")",
";",
"//if the activity with the drawer should be fullscreen add the padding for the statusbar",
"if",
"(",
"mDrawer",
"!=",
"null",
"&&",
"mDrawer",
".",
"mDrawerBuilder",
"!=",
"null",
"&&",
"(",
"mDrawer",
".",
"mDrawerBuilder",
".",
"mFullscreen",
"||",
"mDrawer",
".",
"mDrawerBuilder",
".",
"mTranslucentStatusBar",
")",
")",
"{",
"mRecyclerView",
".",
"setPadding",
"(",
"mRecyclerView",
".",
"getPaddingLeft",
"(",
")",
",",
"UIUtils",
".",
"getStatusBarHeight",
"(",
"ctx",
")",
",",
"mRecyclerView",
".",
"getPaddingRight",
"(",
")",
",",
"mRecyclerView",
".",
"getPaddingBottom",
"(",
")",
")",
";",
"}",
"//if the activity with the drawer should be fullscreen add the padding for the navigationBar",
"if",
"(",
"mDrawer",
"!=",
"null",
"&&",
"mDrawer",
".",
"mDrawerBuilder",
"!=",
"null",
"&&",
"(",
"mDrawer",
".",
"mDrawerBuilder",
".",
"mFullscreen",
"||",
"mDrawer",
".",
"mDrawerBuilder",
".",
"mTranslucentNavigationBar",
")",
"&&",
"ctx",
".",
"getResources",
"(",
")",
".",
"getConfiguration",
"(",
")",
".",
"orientation",
"==",
"Configuration",
".",
"ORIENTATION_PORTRAIT",
")",
"{",
"mRecyclerView",
".",
"setPadding",
"(",
"mRecyclerView",
".",
"getPaddingLeft",
"(",
")",
",",
"mRecyclerView",
".",
"getPaddingTop",
"(",
")",
",",
"mRecyclerView",
".",
"getPaddingRight",
"(",
")",
",",
"UIUtils",
".",
"getNavigationBarHeight",
"(",
"ctx",
")",
")",
";",
"}",
"//set the adapter with the items",
"createItems",
"(",
")",
";",
"return",
"mContainer",
";",
"}"
] |
build the MiniDrawer
@param ctx
@return
|
[
"build",
"the",
"MiniDrawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L301-L345
|
14,927
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.onProfileClick
|
public void onProfileClick() {
//crossfade if we are cross faded
if (mCrossFader != null) {
if (mCrossFader.isCrossfaded()) {
mCrossFader.crossfade();
}
}
//update the current profile
if (mAccountHeader != null) {
IProfile profile = mAccountHeader.getActiveProfile();
if (profile instanceof IDrawerItem) {
mItemAdapter.set(0, generateMiniDrawerItem((IDrawerItem) profile));
}
}
}
|
java
|
public void onProfileClick() {
//crossfade if we are cross faded
if (mCrossFader != null) {
if (mCrossFader.isCrossfaded()) {
mCrossFader.crossfade();
}
}
//update the current profile
if (mAccountHeader != null) {
IProfile profile = mAccountHeader.getActiveProfile();
if (profile instanceof IDrawerItem) {
mItemAdapter.set(0, generateMiniDrawerItem((IDrawerItem) profile));
}
}
}
|
[
"public",
"void",
"onProfileClick",
"(",
")",
"{",
"//crossfade if we are cross faded",
"if",
"(",
"mCrossFader",
"!=",
"null",
")",
"{",
"if",
"(",
"mCrossFader",
".",
"isCrossfaded",
"(",
")",
")",
"{",
"mCrossFader",
".",
"crossfade",
"(",
")",
";",
"}",
"}",
"//update the current profile",
"if",
"(",
"mAccountHeader",
"!=",
"null",
")",
"{",
"IProfile",
"profile",
"=",
"mAccountHeader",
".",
"getActiveProfile",
"(",
")",
";",
"if",
"(",
"profile",
"instanceof",
"IDrawerItem",
")",
"{",
"mItemAdapter",
".",
"set",
"(",
"0",
",",
"generateMiniDrawerItem",
"(",
"(",
"IDrawerItem",
")",
"profile",
")",
")",
";",
"}",
"}",
"}"
] |
call this method to trigger the onProfileClick on the MiniDrawer
|
[
"call",
"this",
"method",
"to",
"trigger",
"the",
"onProfileClick",
"on",
"the",
"MiniDrawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L350-L365
|
14,928
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.onItemClick
|
public boolean onItemClick(IDrawerItem selectedDrawerItem) {
//We only need to clear if the new item is selectable
if (selectedDrawerItem.isSelectable()) {
//crossfade if we are cross faded
if (mCrossFader != null) {
if (mCrossFader.isCrossfaded()) {
mCrossFader.crossfade();
}
}
//update everything
setSelection(selectedDrawerItem.getIdentifier());
return false;
} else {
return true;
}
}
|
java
|
public boolean onItemClick(IDrawerItem selectedDrawerItem) {
//We only need to clear if the new item is selectable
if (selectedDrawerItem.isSelectable()) {
//crossfade if we are cross faded
if (mCrossFader != null) {
if (mCrossFader.isCrossfaded()) {
mCrossFader.crossfade();
}
}
//update everything
setSelection(selectedDrawerItem.getIdentifier());
return false;
} else {
return true;
}
}
|
[
"public",
"boolean",
"onItemClick",
"(",
"IDrawerItem",
"selectedDrawerItem",
")",
"{",
"//We only need to clear if the new item is selectable",
"if",
"(",
"selectedDrawerItem",
".",
"isSelectable",
"(",
")",
")",
"{",
"//crossfade if we are cross faded",
"if",
"(",
"mCrossFader",
"!=",
"null",
")",
"{",
"if",
"(",
"mCrossFader",
".",
"isCrossfaded",
"(",
")",
")",
"{",
"mCrossFader",
".",
"crossfade",
"(",
")",
";",
"}",
"}",
"//update everything",
"setSelection",
"(",
"selectedDrawerItem",
".",
"getIdentifier",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
call this method to trigger the onItemClick on the MiniDrawer
@param selectedDrawerItem
@return
|
[
"call",
"this",
"method",
"to",
"trigger",
"the",
"onItemClick",
"on",
"the",
"MiniDrawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L373-L389
|
14,929
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.setSelection
|
public void setSelection(long identifier) {
if (identifier == -1) {
mAdapter.deselect();
}
int count = mAdapter.getItemCount();
for (int i = 0; i < count; i++) {
IDrawerItem item = mAdapter.getItem(i);
if (item.getIdentifier() == identifier && !item.isSelected()) {
mAdapter.deselect();
mAdapter.select(i);
}
}
}
|
java
|
public void setSelection(long identifier) {
if (identifier == -1) {
mAdapter.deselect();
}
int count = mAdapter.getItemCount();
for (int i = 0; i < count; i++) {
IDrawerItem item = mAdapter.getItem(i);
if (item.getIdentifier() == identifier && !item.isSelected()) {
mAdapter.deselect();
mAdapter.select(i);
}
}
}
|
[
"public",
"void",
"setSelection",
"(",
"long",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"==",
"-",
"1",
")",
"{",
"mAdapter",
".",
"deselect",
"(",
")",
";",
"}",
"int",
"count",
"=",
"mAdapter",
".",
"getItemCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"IDrawerItem",
"item",
"=",
"mAdapter",
".",
"getItem",
"(",
"i",
")",
";",
"if",
"(",
"item",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
"&&",
"!",
"item",
".",
"isSelected",
"(",
")",
")",
"{",
"mAdapter",
".",
"deselect",
"(",
")",
";",
"mAdapter",
".",
"select",
"(",
"i",
")",
";",
"}",
"}",
"}"
] |
set the selection of the MiniDrawer
@param identifier the identifier of the item which should be selected (-1 for none)
|
[
"set",
"the",
"selection",
"of",
"the",
"MiniDrawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L396-L408
|
14,930
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.createItems
|
public void createItems() {
mItemAdapter.clear();
int profileOffset = 0;
if (mAccountHeader != null && mAccountHeader.getAccountHeaderBuilder().mProfileImagesVisible) {
IProfile profile = mAccountHeader.getActiveProfile();
if (profile instanceof IDrawerItem) {
mItemAdapter.add(generateMiniDrawerItem((IDrawerItem) profile));
profileOffset = 1;
}
}
int select = -1;
if (mDrawer != null) {
if (getDrawerItems() != null) {
//migrate to miniDrawerItems
int length = getDrawerItems().size();
int position = 0;
for (int i = 0; i < length; i++) {
IDrawerItem miniDrawerItem = generateMiniDrawerItem(getDrawerItems().get(i));
if (miniDrawerItem != null) {
if (miniDrawerItem.isSelected()) {
select = position;
}
mItemAdapter.add(miniDrawerItem);
position = position + 1;
}
}
if (select >= 0) {
//+1 because of the profile
mAdapter.select(select + profileOffset);
}
}
}
//listener
if (mOnMiniDrawerItemOnClickListener != null) {
mAdapter.withOnClickListener(mOnMiniDrawerItemOnClickListener);
} else {
mAdapter.withOnClickListener(new OnClickListener<IDrawerItem>() {
@Override
public boolean onClick(View v, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
int type = getMiniDrawerType(item);
//if a listener is defined and we consume the event return
if (mOnMiniDrawerItemClickListener != null && mOnMiniDrawerItemClickListener.onItemClick(v, position, item, type)) {
return false;
}
if (type == ITEM) {
//fire the onClickListener also if the specific drawerItem is not Selectable
if (item.isSelectable()) {
//make sure we are on the original drawerItemList
if (mAccountHeader != null && mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
IDrawerItem drawerItem = mDrawer.getDrawerItem(item.getIdentifier());
if (drawerItem != null && !drawerItem.isSelected()) {
//set the selection
mDrawer.setSelection(item, true);
}
} else if (mDrawer.getOnDrawerItemClickListener() != null) {
//get the original `DrawerItem` from the Drawer as this one will contain all information
mDrawer.getOnDrawerItemClickListener().onItemClick(v, position, DrawerUtils.getDrawerItem(getDrawerItems(), item.getIdentifier()));
}
} else if (type == PROFILE) {
if (mAccountHeader != null && !mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
if (mCrossFader != null) {
mCrossFader.crossfade();
}
}
return false;
}
});
}
mAdapter.withOnLongClickListener(mOnMiniDrawerItemLongClickListener);
mRecyclerView.scrollToPosition(0);
}
|
java
|
public void createItems() {
mItemAdapter.clear();
int profileOffset = 0;
if (mAccountHeader != null && mAccountHeader.getAccountHeaderBuilder().mProfileImagesVisible) {
IProfile profile = mAccountHeader.getActiveProfile();
if (profile instanceof IDrawerItem) {
mItemAdapter.add(generateMiniDrawerItem((IDrawerItem) profile));
profileOffset = 1;
}
}
int select = -1;
if (mDrawer != null) {
if (getDrawerItems() != null) {
//migrate to miniDrawerItems
int length = getDrawerItems().size();
int position = 0;
for (int i = 0; i < length; i++) {
IDrawerItem miniDrawerItem = generateMiniDrawerItem(getDrawerItems().get(i));
if (miniDrawerItem != null) {
if (miniDrawerItem.isSelected()) {
select = position;
}
mItemAdapter.add(miniDrawerItem);
position = position + 1;
}
}
if (select >= 0) {
//+1 because of the profile
mAdapter.select(select + profileOffset);
}
}
}
//listener
if (mOnMiniDrawerItemOnClickListener != null) {
mAdapter.withOnClickListener(mOnMiniDrawerItemOnClickListener);
} else {
mAdapter.withOnClickListener(new OnClickListener<IDrawerItem>() {
@Override
public boolean onClick(View v, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
int type = getMiniDrawerType(item);
//if a listener is defined and we consume the event return
if (mOnMiniDrawerItemClickListener != null && mOnMiniDrawerItemClickListener.onItemClick(v, position, item, type)) {
return false;
}
if (type == ITEM) {
//fire the onClickListener also if the specific drawerItem is not Selectable
if (item.isSelectable()) {
//make sure we are on the original drawerItemList
if (mAccountHeader != null && mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
IDrawerItem drawerItem = mDrawer.getDrawerItem(item.getIdentifier());
if (drawerItem != null && !drawerItem.isSelected()) {
//set the selection
mDrawer.setSelection(item, true);
}
} else if (mDrawer.getOnDrawerItemClickListener() != null) {
//get the original `DrawerItem` from the Drawer as this one will contain all information
mDrawer.getOnDrawerItemClickListener().onItemClick(v, position, DrawerUtils.getDrawerItem(getDrawerItems(), item.getIdentifier()));
}
} else if (type == PROFILE) {
if (mAccountHeader != null && !mAccountHeader.isSelectionListShown()) {
mAccountHeader.toggleSelectionList(v.getContext());
}
if (mCrossFader != null) {
mCrossFader.crossfade();
}
}
return false;
}
});
}
mAdapter.withOnLongClickListener(mOnMiniDrawerItemLongClickListener);
mRecyclerView.scrollToPosition(0);
}
|
[
"public",
"void",
"createItems",
"(",
")",
"{",
"mItemAdapter",
".",
"clear",
"(",
")",
";",
"int",
"profileOffset",
"=",
"0",
";",
"if",
"(",
"mAccountHeader",
"!=",
"null",
"&&",
"mAccountHeader",
".",
"getAccountHeaderBuilder",
"(",
")",
".",
"mProfileImagesVisible",
")",
"{",
"IProfile",
"profile",
"=",
"mAccountHeader",
".",
"getActiveProfile",
"(",
")",
";",
"if",
"(",
"profile",
"instanceof",
"IDrawerItem",
")",
"{",
"mItemAdapter",
".",
"add",
"(",
"generateMiniDrawerItem",
"(",
"(",
"IDrawerItem",
")",
"profile",
")",
")",
";",
"profileOffset",
"=",
"1",
";",
"}",
"}",
"int",
"select",
"=",
"-",
"1",
";",
"if",
"(",
"mDrawer",
"!=",
"null",
")",
"{",
"if",
"(",
"getDrawerItems",
"(",
")",
"!=",
"null",
")",
"{",
"//migrate to miniDrawerItems",
"int",
"length",
"=",
"getDrawerItems",
"(",
")",
".",
"size",
"(",
")",
";",
"int",
"position",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"IDrawerItem",
"miniDrawerItem",
"=",
"generateMiniDrawerItem",
"(",
"getDrawerItems",
"(",
")",
".",
"get",
"(",
"i",
")",
")",
";",
"if",
"(",
"miniDrawerItem",
"!=",
"null",
")",
"{",
"if",
"(",
"miniDrawerItem",
".",
"isSelected",
"(",
")",
")",
"{",
"select",
"=",
"position",
";",
"}",
"mItemAdapter",
".",
"add",
"(",
"miniDrawerItem",
")",
";",
"position",
"=",
"position",
"+",
"1",
";",
"}",
"}",
"if",
"(",
"select",
">=",
"0",
")",
"{",
"//+1 because of the profile",
"mAdapter",
".",
"select",
"(",
"select",
"+",
"profileOffset",
")",
";",
"}",
"}",
"}",
"//listener",
"if",
"(",
"mOnMiniDrawerItemOnClickListener",
"!=",
"null",
")",
"{",
"mAdapter",
".",
"withOnClickListener",
"(",
"mOnMiniDrawerItemOnClickListener",
")",
";",
"}",
"else",
"{",
"mAdapter",
".",
"withOnClickListener",
"(",
"new",
"OnClickListener",
"<",
"IDrawerItem",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"onClick",
"(",
"View",
"v",
",",
"IAdapter",
"<",
"IDrawerItem",
">",
"adapter",
",",
"final",
"IDrawerItem",
"item",
",",
"final",
"int",
"position",
")",
"{",
"int",
"type",
"=",
"getMiniDrawerType",
"(",
"item",
")",
";",
"//if a listener is defined and we consume the event return",
"if",
"(",
"mOnMiniDrawerItemClickListener",
"!=",
"null",
"&&",
"mOnMiniDrawerItemClickListener",
".",
"onItemClick",
"(",
"v",
",",
"position",
",",
"item",
",",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"type",
"==",
"ITEM",
")",
"{",
"//fire the onClickListener also if the specific drawerItem is not Selectable",
"if",
"(",
"item",
".",
"isSelectable",
"(",
")",
")",
"{",
"//make sure we are on the original drawerItemList",
"if",
"(",
"mAccountHeader",
"!=",
"null",
"&&",
"mAccountHeader",
".",
"isSelectionListShown",
"(",
")",
")",
"{",
"mAccountHeader",
".",
"toggleSelectionList",
"(",
"v",
".",
"getContext",
"(",
")",
")",
";",
"}",
"IDrawerItem",
"drawerItem",
"=",
"mDrawer",
".",
"getDrawerItem",
"(",
"item",
".",
"getIdentifier",
"(",
")",
")",
";",
"if",
"(",
"drawerItem",
"!=",
"null",
"&&",
"!",
"drawerItem",
".",
"isSelected",
"(",
")",
")",
"{",
"//set the selection",
"mDrawer",
".",
"setSelection",
"(",
"item",
",",
"true",
")",
";",
"}",
"}",
"else",
"if",
"(",
"mDrawer",
".",
"getOnDrawerItemClickListener",
"(",
")",
"!=",
"null",
")",
"{",
"//get the original `DrawerItem` from the Drawer as this one will contain all information",
"mDrawer",
".",
"getOnDrawerItemClickListener",
"(",
")",
".",
"onItemClick",
"(",
"v",
",",
"position",
",",
"DrawerUtils",
".",
"getDrawerItem",
"(",
"getDrawerItems",
"(",
")",
",",
"item",
".",
"getIdentifier",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"type",
"==",
"PROFILE",
")",
"{",
"if",
"(",
"mAccountHeader",
"!=",
"null",
"&&",
"!",
"mAccountHeader",
".",
"isSelectionListShown",
"(",
")",
")",
"{",
"mAccountHeader",
".",
"toggleSelectionList",
"(",
"v",
".",
"getContext",
"(",
")",
")",
";",
"}",
"if",
"(",
"mCrossFader",
"!=",
"null",
")",
"{",
"mCrossFader",
".",
"crossfade",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
")",
";",
"}",
"mAdapter",
".",
"withOnLongClickListener",
"(",
"mOnMiniDrawerItemLongClickListener",
")",
";",
"mRecyclerView",
".",
"scrollToPosition",
"(",
"0",
")",
";",
"}"
] |
creates the items for the MiniDrawer
|
[
"creates",
"the",
"items",
"for",
"the",
"MiniDrawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L432-L513
|
14,931
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java
|
MiniDrawer.getDrawerItems
|
private List<IDrawerItem> getDrawerItems() {
return mDrawer.getOriginalDrawerItems() != null ? mDrawer.getOriginalDrawerItems() : mDrawer.getDrawerItems();
}
|
java
|
private List<IDrawerItem> getDrawerItems() {
return mDrawer.getOriginalDrawerItems() != null ? mDrawer.getOriginalDrawerItems() : mDrawer.getDrawerItems();
}
|
[
"private",
"List",
"<",
"IDrawerItem",
">",
"getDrawerItems",
"(",
")",
"{",
"return",
"mDrawer",
".",
"getOriginalDrawerItems",
"(",
")",
"!=",
"null",
"?",
"mDrawer",
".",
"getOriginalDrawerItems",
"(",
")",
":",
"mDrawer",
".",
"getDrawerItems",
"(",
")",
";",
"}"
] |
returns always the original drawerItems and not the switched content
@return
|
[
"returns",
"always",
"the",
"original",
"drawerItems",
"and",
"not",
"the",
"switched",
"content"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/MiniDrawer.java#L520-L522
|
14,932
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.setHeaderHeight
|
private void setHeaderHeight(int height) {
if (mAccountHeaderContainer != null) {
ViewGroup.LayoutParams params = mAccountHeaderContainer.getLayoutParams();
if (params != null) {
params.height = height;
mAccountHeaderContainer.setLayoutParams(params);
}
View accountHeader = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header);
if (accountHeader != null) {
// TODO why is this null?
params = accountHeader.getLayoutParams();
if(params != null) {
params.height = height;
accountHeader.setLayoutParams(params);
}
}
View accountHeaderBackground = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header_background);
if (accountHeaderBackground != null) {
params = accountHeaderBackground.getLayoutParams();
params.height = height;
accountHeaderBackground.setLayoutParams(params);
}
}
}
|
java
|
private void setHeaderHeight(int height) {
if (mAccountHeaderContainer != null) {
ViewGroup.LayoutParams params = mAccountHeaderContainer.getLayoutParams();
if (params != null) {
params.height = height;
mAccountHeaderContainer.setLayoutParams(params);
}
View accountHeader = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header);
if (accountHeader != null) {
// TODO why is this null?
params = accountHeader.getLayoutParams();
if(params != null) {
params.height = height;
accountHeader.setLayoutParams(params);
}
}
View accountHeaderBackground = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header_background);
if (accountHeaderBackground != null) {
params = accountHeaderBackground.getLayoutParams();
params.height = height;
accountHeaderBackground.setLayoutParams(params);
}
}
}
|
[
"private",
"void",
"setHeaderHeight",
"(",
"int",
"height",
")",
"{",
"if",
"(",
"mAccountHeaderContainer",
"!=",
"null",
")",
"{",
"ViewGroup",
".",
"LayoutParams",
"params",
"=",
"mAccountHeaderContainer",
".",
"getLayoutParams",
"(",
")",
";",
"if",
"(",
"params",
"!=",
"null",
")",
"{",
"params",
".",
"height",
"=",
"height",
";",
"mAccountHeaderContainer",
".",
"setLayoutParams",
"(",
"params",
")",
";",
"}",
"View",
"accountHeader",
"=",
"mAccountHeaderContainer",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"material_drawer_account_header",
")",
";",
"if",
"(",
"accountHeader",
"!=",
"null",
")",
"{",
"// TODO why is this null?",
"params",
"=",
"accountHeader",
".",
"getLayoutParams",
"(",
")",
";",
"if",
"(",
"params",
"!=",
"null",
")",
"{",
"params",
".",
"height",
"=",
"height",
";",
"accountHeader",
".",
"setLayoutParams",
"(",
"params",
")",
";",
"}",
"}",
"View",
"accountHeaderBackground",
"=",
"mAccountHeaderContainer",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"material_drawer_account_header_background",
")",
";",
"if",
"(",
"accountHeaderBackground",
"!=",
"null",
")",
"{",
"params",
"=",
"accountHeaderBackground",
".",
"getLayoutParams",
"(",
")",
";",
"params",
".",
"height",
"=",
"height",
";",
"accountHeaderBackground",
".",
"setLayoutParams",
"(",
"params",
")",
";",
"}",
"}",
"}"
] |
helper method to set the height for the header!
@param height
|
[
"helper",
"method",
"to",
"set",
"the",
"height",
"for",
"the",
"header!"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L702-L727
|
14,933
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.handleSelectionView
|
private void handleSelectionView(IProfile profile, boolean on) {
if (on) {
if (Build.VERSION.SDK_INT >= 23) {
mAccountHeaderContainer.setForeground(AppCompatResources.getDrawable(mAccountHeaderContainer.getContext(), mAccountHeaderTextSectionBackgroundResource));
} else {
// todo foreground thing?
}
mAccountHeaderContainer.setOnClickListener(onSelectionClickListener);
mAccountHeaderContainer.setTag(R.id.material_drawer_profile_header, profile);
} else {
if (Build.VERSION.SDK_INT >= 23) {
mAccountHeaderContainer.setForeground(null);
} else {
// TODO foreground reset
}
mAccountHeaderContainer.setOnClickListener(null);
}
}
|
java
|
private void handleSelectionView(IProfile profile, boolean on) {
if (on) {
if (Build.VERSION.SDK_INT >= 23) {
mAccountHeaderContainer.setForeground(AppCompatResources.getDrawable(mAccountHeaderContainer.getContext(), mAccountHeaderTextSectionBackgroundResource));
} else {
// todo foreground thing?
}
mAccountHeaderContainer.setOnClickListener(onSelectionClickListener);
mAccountHeaderContainer.setTag(R.id.material_drawer_profile_header, profile);
} else {
if (Build.VERSION.SDK_INT >= 23) {
mAccountHeaderContainer.setForeground(null);
} else {
// TODO foreground reset
}
mAccountHeaderContainer.setOnClickListener(null);
}
}
|
[
"private",
"void",
"handleSelectionView",
"(",
"IProfile",
"profile",
",",
"boolean",
"on",
")",
"{",
"if",
"(",
"on",
")",
"{",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"23",
")",
"{",
"mAccountHeaderContainer",
".",
"setForeground",
"(",
"AppCompatResources",
".",
"getDrawable",
"(",
"mAccountHeaderContainer",
".",
"getContext",
"(",
")",
",",
"mAccountHeaderTextSectionBackgroundResource",
")",
")",
";",
"}",
"else",
"{",
"// todo foreground thing?",
"}",
"mAccountHeaderContainer",
".",
"setOnClickListener",
"(",
"onSelectionClickListener",
")",
";",
"mAccountHeaderContainer",
".",
"setTag",
"(",
"R",
".",
"id",
".",
"material_drawer_profile_header",
",",
"profile",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"23",
")",
"{",
"mAccountHeaderContainer",
".",
"setForeground",
"(",
"null",
")",
";",
"}",
"else",
"{",
"// TODO foreground reset",
"}",
"mAccountHeaderContainer",
".",
"setOnClickListener",
"(",
"null",
")",
";",
"}",
"}"
] |
a small helper to handle the selectionView
@param on
|
[
"a",
"small",
"helper",
"to",
"handle",
"the",
"selectionView"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L734-L751
|
14,934
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.switchProfiles
|
protected boolean switchProfiles(IProfile newSelection) {
if (newSelection == null) {
return false;
}
if (mCurrentProfile == newSelection) {
return true;
}
if (mAlternativeProfileHeaderSwitching) {
int prevSelection = -1;
if (mProfileFirst == newSelection) {
prevSelection = 1;
} else if (mProfileSecond == newSelection) {
prevSelection = 2;
} else if (mProfileThird == newSelection) {
prevSelection = 3;
}
IProfile tmp = mCurrentProfile;
mCurrentProfile = newSelection;
if (prevSelection == 1) {
mProfileFirst = tmp;
} else if (prevSelection == 2) {
mProfileSecond = tmp;
} else if (prevSelection == 3) {
mProfileThird = tmp;
}
} else {
if (mProfiles != null) {
ArrayList<IProfile> previousActiveProfiles = new ArrayList<>(Arrays.asList(mCurrentProfile, mProfileFirst, mProfileSecond, mProfileThird));
if (previousActiveProfiles.contains(newSelection)) {
int position = -1;
for (int i = 0; i < 4; i++) {
if (previousActiveProfiles.get(i) == newSelection) {
position = i;
break;
}
}
if (position != -1) {
previousActiveProfiles.remove(position);
previousActiveProfiles.add(0, newSelection);
mCurrentProfile = previousActiveProfiles.get(0);
mProfileFirst = previousActiveProfiles.get(1);
mProfileSecond = previousActiveProfiles.get(2);
mProfileThird = previousActiveProfiles.get(3);
}
} else {
mProfileThird = mProfileSecond;
mProfileSecond = mProfileFirst;
mProfileFirst = mCurrentProfile;
mCurrentProfile = newSelection;
}
}
}
//if we only show the small profile images we have to make sure the first (would be the current selected) profile is also shown
if (mOnlySmallProfileImagesVisible) {
mProfileThird = mProfileSecond;
mProfileSecond = mProfileFirst;
mProfileFirst = mCurrentProfile;
//mCurrentProfile = mProfileThird;
}
buildProfiles();
return false;
}
|
java
|
protected boolean switchProfiles(IProfile newSelection) {
if (newSelection == null) {
return false;
}
if (mCurrentProfile == newSelection) {
return true;
}
if (mAlternativeProfileHeaderSwitching) {
int prevSelection = -1;
if (mProfileFirst == newSelection) {
prevSelection = 1;
} else if (mProfileSecond == newSelection) {
prevSelection = 2;
} else if (mProfileThird == newSelection) {
prevSelection = 3;
}
IProfile tmp = mCurrentProfile;
mCurrentProfile = newSelection;
if (prevSelection == 1) {
mProfileFirst = tmp;
} else if (prevSelection == 2) {
mProfileSecond = tmp;
} else if (prevSelection == 3) {
mProfileThird = tmp;
}
} else {
if (mProfiles != null) {
ArrayList<IProfile> previousActiveProfiles = new ArrayList<>(Arrays.asList(mCurrentProfile, mProfileFirst, mProfileSecond, mProfileThird));
if (previousActiveProfiles.contains(newSelection)) {
int position = -1;
for (int i = 0; i < 4; i++) {
if (previousActiveProfiles.get(i) == newSelection) {
position = i;
break;
}
}
if (position != -1) {
previousActiveProfiles.remove(position);
previousActiveProfiles.add(0, newSelection);
mCurrentProfile = previousActiveProfiles.get(0);
mProfileFirst = previousActiveProfiles.get(1);
mProfileSecond = previousActiveProfiles.get(2);
mProfileThird = previousActiveProfiles.get(3);
}
} else {
mProfileThird = mProfileSecond;
mProfileSecond = mProfileFirst;
mProfileFirst = mCurrentProfile;
mCurrentProfile = newSelection;
}
}
}
//if we only show the small profile images we have to make sure the first (would be the current selected) profile is also shown
if (mOnlySmallProfileImagesVisible) {
mProfileThird = mProfileSecond;
mProfileSecond = mProfileFirst;
mProfileFirst = mCurrentProfile;
//mCurrentProfile = mProfileThird;
}
buildProfiles();
return false;
}
|
[
"protected",
"boolean",
"switchProfiles",
"(",
"IProfile",
"newSelection",
")",
"{",
"if",
"(",
"newSelection",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"mCurrentProfile",
"==",
"newSelection",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"mAlternativeProfileHeaderSwitching",
")",
"{",
"int",
"prevSelection",
"=",
"-",
"1",
";",
"if",
"(",
"mProfileFirst",
"==",
"newSelection",
")",
"{",
"prevSelection",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"mProfileSecond",
"==",
"newSelection",
")",
"{",
"prevSelection",
"=",
"2",
";",
"}",
"else",
"if",
"(",
"mProfileThird",
"==",
"newSelection",
")",
"{",
"prevSelection",
"=",
"3",
";",
"}",
"IProfile",
"tmp",
"=",
"mCurrentProfile",
";",
"mCurrentProfile",
"=",
"newSelection",
";",
"if",
"(",
"prevSelection",
"==",
"1",
")",
"{",
"mProfileFirst",
"=",
"tmp",
";",
"}",
"else",
"if",
"(",
"prevSelection",
"==",
"2",
")",
"{",
"mProfileSecond",
"=",
"tmp",
";",
"}",
"else",
"if",
"(",
"prevSelection",
"==",
"3",
")",
"{",
"mProfileThird",
"=",
"tmp",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"mProfiles",
"!=",
"null",
")",
"{",
"ArrayList",
"<",
"IProfile",
">",
"previousActiveProfiles",
"=",
"new",
"ArrayList",
"<>",
"(",
"Arrays",
".",
"asList",
"(",
"mCurrentProfile",
",",
"mProfileFirst",
",",
"mProfileSecond",
",",
"mProfileThird",
")",
")",
";",
"if",
"(",
"previousActiveProfiles",
".",
"contains",
"(",
"newSelection",
")",
")",
"{",
"int",
"position",
"=",
"-",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"if",
"(",
"previousActiveProfiles",
".",
"get",
"(",
"i",
")",
"==",
"newSelection",
")",
"{",
"position",
"=",
"i",
";",
"break",
";",
"}",
"}",
"if",
"(",
"position",
"!=",
"-",
"1",
")",
"{",
"previousActiveProfiles",
".",
"remove",
"(",
"position",
")",
";",
"previousActiveProfiles",
".",
"add",
"(",
"0",
",",
"newSelection",
")",
";",
"mCurrentProfile",
"=",
"previousActiveProfiles",
".",
"get",
"(",
"0",
")",
";",
"mProfileFirst",
"=",
"previousActiveProfiles",
".",
"get",
"(",
"1",
")",
";",
"mProfileSecond",
"=",
"previousActiveProfiles",
".",
"get",
"(",
"2",
")",
";",
"mProfileThird",
"=",
"previousActiveProfiles",
".",
"get",
"(",
"3",
")",
";",
"}",
"}",
"else",
"{",
"mProfileThird",
"=",
"mProfileSecond",
";",
"mProfileSecond",
"=",
"mProfileFirst",
";",
"mProfileFirst",
"=",
"mCurrentProfile",
";",
"mCurrentProfile",
"=",
"newSelection",
";",
"}",
"}",
"}",
"//if we only show the small profile images we have to make sure the first (would be the current selected) profile is also shown",
"if",
"(",
"mOnlySmallProfileImagesVisible",
")",
"{",
"mProfileThird",
"=",
"mProfileSecond",
";",
"mProfileSecond",
"=",
"mProfileFirst",
";",
"mProfileFirst",
"=",
"mCurrentProfile",
";",
"//mCurrentProfile = mProfileThird;",
"}",
"buildProfiles",
"(",
")",
";",
"return",
"false",
";",
"}"
] |
helper method to switch the profiles
@param newSelection
@return true if the new selection was the current profile
|
[
"helper",
"method",
"to",
"switch",
"the",
"profiles"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L987-L1058
|
14,935
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.setImageOrPlaceholder
|
private void setImageOrPlaceholder(ImageView iv, ImageHolder imageHolder) {
//cancel previous started image loading processes
DrawerImageLoader.getInstance().cancelImage(iv);
//set the placeholder
iv.setImageDrawable(DrawerImageLoader.getInstance().getImageLoader().placeholder(iv.getContext(), DrawerImageLoader.Tags.PROFILE.name()));
//set the real image (probably also the uri)
ImageHolder.applyTo(imageHolder, iv, DrawerImageLoader.Tags.PROFILE.name());
}
|
java
|
private void setImageOrPlaceholder(ImageView iv, ImageHolder imageHolder) {
//cancel previous started image loading processes
DrawerImageLoader.getInstance().cancelImage(iv);
//set the placeholder
iv.setImageDrawable(DrawerImageLoader.getInstance().getImageLoader().placeholder(iv.getContext(), DrawerImageLoader.Tags.PROFILE.name()));
//set the real image (probably also the uri)
ImageHolder.applyTo(imageHolder, iv, DrawerImageLoader.Tags.PROFILE.name());
}
|
[
"private",
"void",
"setImageOrPlaceholder",
"(",
"ImageView",
"iv",
",",
"ImageHolder",
"imageHolder",
")",
"{",
"//cancel previous started image loading processes",
"DrawerImageLoader",
".",
"getInstance",
"(",
")",
".",
"cancelImage",
"(",
"iv",
")",
";",
"//set the placeholder",
"iv",
".",
"setImageDrawable",
"(",
"DrawerImageLoader",
".",
"getInstance",
"(",
")",
".",
"getImageLoader",
"(",
")",
".",
"placeholder",
"(",
"iv",
".",
"getContext",
"(",
")",
",",
"DrawerImageLoader",
".",
"Tags",
".",
"PROFILE",
".",
"name",
"(",
")",
")",
")",
";",
"//set the real image (probably also the uri)",
"ImageHolder",
".",
"applyTo",
"(",
"imageHolder",
",",
"iv",
",",
"DrawerImageLoader",
".",
"Tags",
".",
"PROFILE",
".",
"name",
"(",
")",
")",
";",
"}"
] |
small helper method to set an profile image or a placeholder
@param iv
@param imageHolder
|
[
"small",
"helper",
"method",
"to",
"set",
"an",
"profile",
"image",
"or",
"a",
"placeholder"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1182-L1189
|
14,936
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.onProfileImageClick
|
private void onProfileImageClick(View v, boolean current) {
IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
boolean consumed = false;
if (mOnAccountHeaderProfileImageListener != null) {
consumed = mOnAccountHeaderProfileImageListener.onProfileImageClick(v, profile, current);
}
//if the event was already consumed by the click don't continue. note that this will also stop the profile change event
if (!consumed) {
onProfileClick(v, current);
}
}
|
java
|
private void onProfileImageClick(View v, boolean current) {
IProfile profile = (IProfile) v.getTag(R.id.material_drawer_profile_header);
boolean consumed = false;
if (mOnAccountHeaderProfileImageListener != null) {
consumed = mOnAccountHeaderProfileImageListener.onProfileImageClick(v, profile, current);
}
//if the event was already consumed by the click don't continue. note that this will also stop the profile change event
if (!consumed) {
onProfileClick(v, current);
}
}
|
[
"private",
"void",
"onProfileImageClick",
"(",
"View",
"v",
",",
"boolean",
"current",
")",
"{",
"IProfile",
"profile",
"=",
"(",
"IProfile",
")",
"v",
".",
"getTag",
"(",
"R",
".",
"id",
".",
"material_drawer_profile_header",
")",
";",
"boolean",
"consumed",
"=",
"false",
";",
"if",
"(",
"mOnAccountHeaderProfileImageListener",
"!=",
"null",
")",
"{",
"consumed",
"=",
"mOnAccountHeaderProfileImageListener",
".",
"onProfileImageClick",
"(",
"v",
",",
"profile",
",",
"current",
")",
";",
"}",
"//if the event was already consumed by the click don't continue. note that this will also stop the profile change event",
"if",
"(",
"!",
"consumed",
")",
"{",
"onProfileClick",
"(",
"v",
",",
"current",
")",
";",
"}",
"}"
] |
calls the mOnAccountHEaderProfileImageListener and continues with the actions afterwards
@param v
@param current
|
[
"calls",
"the",
"mOnAccountHEaderProfileImageListener",
"and",
"continues",
"with",
"the",
"actions",
"afterwards"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1217-L1229
|
14,937
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.getCurrentSelection
|
protected int getCurrentSelection() {
if (mCurrentProfile != null && mProfiles != null) {
int i = 0;
for (IProfile profile : mProfiles) {
if (profile == mCurrentProfile) {
return i;
}
i++;
}
}
return -1;
}
|
java
|
protected int getCurrentSelection() {
if (mCurrentProfile != null && mProfiles != null) {
int i = 0;
for (IProfile profile : mProfiles) {
if (profile == mCurrentProfile) {
return i;
}
i++;
}
}
return -1;
}
|
[
"protected",
"int",
"getCurrentSelection",
"(",
")",
"{",
"if",
"(",
"mCurrentProfile",
"!=",
"null",
"&&",
"mProfiles",
"!=",
"null",
")",
"{",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"IProfile",
"profile",
":",
"mProfiles",
")",
"{",
"if",
"(",
"profile",
"==",
"mCurrentProfile",
")",
"{",
"return",
"i",
";",
"}",
"i",
"++",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
get the current selection
@return
|
[
"get",
"the",
"current",
"selection"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1300-L1311
|
14,938
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.toggleSelectionList
|
protected void toggleSelectionList(Context ctx) {
if (mDrawer != null) {
//if we already show the list. reset everything instead
if (mDrawer.switchedDrawerContent()) {
resetDrawerContent(ctx);
mSelectionListShown = false;
} else {
//build and set the drawer selection list
buildDrawerSelectionList();
// update the arrow image within the drawer
mAccountSwitcherArrow.clearAnimation();
ViewCompat.animate(mAccountSwitcherArrow).rotation(180).start();
//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_up).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));
mSelectionListShown = true;
}
}
}
|
java
|
protected void toggleSelectionList(Context ctx) {
if (mDrawer != null) {
//if we already show the list. reset everything instead
if (mDrawer.switchedDrawerContent()) {
resetDrawerContent(ctx);
mSelectionListShown = false;
} else {
//build and set the drawer selection list
buildDrawerSelectionList();
// update the arrow image within the drawer
mAccountSwitcherArrow.clearAnimation();
ViewCompat.animate(mAccountSwitcherArrow).rotation(180).start();
//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_up).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));
mSelectionListShown = true;
}
}
}
|
[
"protected",
"void",
"toggleSelectionList",
"(",
"Context",
"ctx",
")",
"{",
"if",
"(",
"mDrawer",
"!=",
"null",
")",
"{",
"//if we already show the list. reset everything instead",
"if",
"(",
"mDrawer",
".",
"switchedDrawerContent",
"(",
")",
")",
"{",
"resetDrawerContent",
"(",
"ctx",
")",
";",
"mSelectionListShown",
"=",
"false",
";",
"}",
"else",
"{",
"//build and set the drawer selection list",
"buildDrawerSelectionList",
"(",
")",
";",
"// update the arrow image within the drawer",
"mAccountSwitcherArrow",
".",
"clearAnimation",
"(",
")",
";",
"ViewCompat",
".",
"animate",
"(",
"mAccountSwitcherArrow",
")",
".",
"rotation",
"(",
"180",
")",
".",
"start",
"(",
")",
";",
"//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_up).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));",
"mSelectionListShown",
"=",
"true",
";",
"}",
"}",
"}"
] |
helper method to toggle the collection
@param ctx
|
[
"helper",
"method",
"to",
"toggle",
"the",
"collection"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1335-L1352
|
14,939
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.buildDrawerSelectionList
|
protected void buildDrawerSelectionList() {
int selectedPosition = -1;
int position = 0;
ArrayList<IDrawerItem> profileDrawerItems = new ArrayList<>();
if (mProfiles != null) {
for (IProfile profile : mProfiles) {
if (profile == mCurrentProfile) {
if (mCurrentHiddenInList) {
continue;
} else {
selectedPosition = mDrawer.mDrawerBuilder.getItemAdapter().getGlobalPosition(position);
}
}
if (profile instanceof IDrawerItem) {
((IDrawerItem) profile).withSetSelected(false);
profileDrawerItems.add((IDrawerItem) profile);
}
position = position + 1;
}
}
mDrawer.switchDrawerContent(onDrawerItemClickListener, onDrawerItemLongClickListener, profileDrawerItems, selectedPosition);
}
|
java
|
protected void buildDrawerSelectionList() {
int selectedPosition = -1;
int position = 0;
ArrayList<IDrawerItem> profileDrawerItems = new ArrayList<>();
if (mProfiles != null) {
for (IProfile profile : mProfiles) {
if (profile == mCurrentProfile) {
if (mCurrentHiddenInList) {
continue;
} else {
selectedPosition = mDrawer.mDrawerBuilder.getItemAdapter().getGlobalPosition(position);
}
}
if (profile instanceof IDrawerItem) {
((IDrawerItem) profile).withSetSelected(false);
profileDrawerItems.add((IDrawerItem) profile);
}
position = position + 1;
}
}
mDrawer.switchDrawerContent(onDrawerItemClickListener, onDrawerItemLongClickListener, profileDrawerItems, selectedPosition);
}
|
[
"protected",
"void",
"buildDrawerSelectionList",
"(",
")",
"{",
"int",
"selectedPosition",
"=",
"-",
"1",
";",
"int",
"position",
"=",
"0",
";",
"ArrayList",
"<",
"IDrawerItem",
">",
"profileDrawerItems",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"mProfiles",
"!=",
"null",
")",
"{",
"for",
"(",
"IProfile",
"profile",
":",
"mProfiles",
")",
"{",
"if",
"(",
"profile",
"==",
"mCurrentProfile",
")",
"{",
"if",
"(",
"mCurrentHiddenInList",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"selectedPosition",
"=",
"mDrawer",
".",
"mDrawerBuilder",
".",
"getItemAdapter",
"(",
")",
".",
"getGlobalPosition",
"(",
"position",
")",
";",
"}",
"}",
"if",
"(",
"profile",
"instanceof",
"IDrawerItem",
")",
"{",
"(",
"(",
"IDrawerItem",
")",
"profile",
")",
".",
"withSetSelected",
"(",
"false",
")",
";",
"profileDrawerItems",
".",
"add",
"(",
"(",
"IDrawerItem",
")",
"profile",
")",
";",
"}",
"position",
"=",
"position",
"+",
"1",
";",
"}",
"}",
"mDrawer",
".",
"switchDrawerContent",
"(",
"onDrawerItemClickListener",
",",
"onDrawerItemLongClickListener",
",",
"profileDrawerItems",
",",
"selectedPosition",
")",
";",
"}"
] |
helper method to build and set the drawer selection list
|
[
"helper",
"method",
"to",
"build",
"and",
"set",
"the",
"drawer",
"selection",
"list"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1357-L1378
|
14,940
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java
|
AccountHeaderBuilder.resetDrawerContent
|
private void resetDrawerContent(Context ctx) {
if (mDrawer != null) {
mDrawer.resetDrawerContent();
}
mAccountSwitcherArrow.clearAnimation();
ViewCompat.animate(mAccountSwitcherArrow).rotation(0).start();
//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_down).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));
}
|
java
|
private void resetDrawerContent(Context ctx) {
if (mDrawer != null) {
mDrawer.resetDrawerContent();
}
mAccountSwitcherArrow.clearAnimation();
ViewCompat.animate(mAccountSwitcherArrow).rotation(0).start();
//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_down).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));
}
|
[
"private",
"void",
"resetDrawerContent",
"(",
"Context",
"ctx",
")",
"{",
"if",
"(",
"mDrawer",
"!=",
"null",
")",
"{",
"mDrawer",
".",
"resetDrawerContent",
"(",
")",
";",
"}",
"mAccountSwitcherArrow",
".",
"clearAnimation",
"(",
")",
";",
"ViewCompat",
".",
"animate",
"(",
"mAccountSwitcherArrow",
")",
".",
"rotation",
"(",
"0",
")",
".",
"start",
"(",
")",
";",
"//mAccountSwitcherArrow.setImageDrawable(new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_arrow_drop_down).sizeRes(R.dimen.material_drawer_account_header_dropdown).paddingRes(R.dimen.material_drawer_account_header_dropdown_padding).color(ColorHolder.color(mTextColor, ctx, R.attr.material_drawer_header_selection_text, R.color.material_drawer_header_selection_text)));",
"}"
] |
helper method to reset the drawer content
|
[
"helper",
"method",
"to",
"reset",
"the",
"drawer",
"content"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/AccountHeaderBuilder.java#L1452-L1460
|
14,941
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.isDrawerOpen
|
public boolean isDrawerOpen() {
if (mDrawerBuilder.mDrawerLayout != null && mDrawerBuilder.mSliderLayout != null) {
return mDrawerBuilder.mDrawerLayout.isDrawerOpen(mDrawerBuilder.mDrawerGravity);
}
return false;
}
|
java
|
public boolean isDrawerOpen() {
if (mDrawerBuilder.mDrawerLayout != null && mDrawerBuilder.mSliderLayout != null) {
return mDrawerBuilder.mDrawerLayout.isDrawerOpen(mDrawerBuilder.mDrawerGravity);
}
return false;
}
|
[
"public",
"boolean",
"isDrawerOpen",
"(",
")",
"{",
"if",
"(",
"mDrawerBuilder",
".",
"mDrawerLayout",
"!=",
"null",
"&&",
"mDrawerBuilder",
".",
"mSliderLayout",
"!=",
"null",
")",
"{",
"return",
"mDrawerBuilder",
".",
"mDrawerLayout",
".",
"isDrawerOpen",
"(",
"mDrawerBuilder",
".",
"mDrawerGravity",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Get the current state of the drawer.
True if the drawer is currently open.
@return
|
[
"Get",
"the",
"current",
"state",
"of",
"the",
"drawer",
".",
"True",
"if",
"the",
"drawer",
"is",
"currently",
"open",
"."
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L153-L158
|
14,942
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.getMiniDrawer
|
public MiniDrawer getMiniDrawer() {
if (mDrawerBuilder.mMiniDrawer == null) {
mDrawerBuilder.mMiniDrawer = new MiniDrawer().withDrawer(this).withAccountHeader(mDrawerBuilder.mAccountHeader);
}
return mDrawerBuilder.mMiniDrawer;
}
|
java
|
public MiniDrawer getMiniDrawer() {
if (mDrawerBuilder.mMiniDrawer == null) {
mDrawerBuilder.mMiniDrawer = new MiniDrawer().withDrawer(this).withAccountHeader(mDrawerBuilder.mAccountHeader);
}
return mDrawerBuilder.mMiniDrawer;
}
|
[
"public",
"MiniDrawer",
"getMiniDrawer",
"(",
")",
"{",
"if",
"(",
"mDrawerBuilder",
".",
"mMiniDrawer",
"==",
"null",
")",
"{",
"mDrawerBuilder",
".",
"mMiniDrawer",
"=",
"new",
"MiniDrawer",
"(",
")",
".",
"withDrawer",
"(",
"this",
")",
".",
"withAccountHeader",
"(",
"mDrawerBuilder",
".",
"mAccountHeader",
")",
";",
"}",
"return",
"mDrawerBuilder",
".",
"mMiniDrawer",
";",
"}"
] |
gets the already generated MiniDrawer or creates a new one
@return
|
[
"gets",
"the",
"already",
"generated",
"MiniDrawer",
"or",
"creates",
"a",
"new",
"one"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L188-L193
|
14,943
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.getContent
|
public FrameLayout getContent() {
if (mContentView == null && this.mDrawerBuilder.mDrawerLayout != null) {
mContentView = (FrameLayout) this.mDrawerBuilder.mDrawerLayout.findViewById(R.id.content_layout);
}
return mContentView;
}
|
java
|
public FrameLayout getContent() {
if (mContentView == null && this.mDrawerBuilder.mDrawerLayout != null) {
mContentView = (FrameLayout) this.mDrawerBuilder.mDrawerLayout.findViewById(R.id.content_layout);
}
return mContentView;
}
|
[
"public",
"FrameLayout",
"getContent",
"(",
")",
"{",
"if",
"(",
"mContentView",
"==",
"null",
"&&",
"this",
".",
"mDrawerBuilder",
".",
"mDrawerLayout",
"!=",
"null",
")",
"{",
"mContentView",
"=",
"(",
"FrameLayout",
")",
"this",
".",
"mDrawerBuilder",
".",
"mDrawerLayout",
".",
"findViewById",
"(",
"R",
".",
"id",
".",
"content_layout",
")",
";",
"}",
"return",
"mContentView",
";",
"}"
] |
get the container frameLayout of the current drawer
@return
|
[
"get",
"the",
"container",
"frameLayout",
"of",
"the",
"current",
"drawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L210-L215
|
14,944
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.setGravity
|
public void setGravity(int gravity) {
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) getSlider().getLayoutParams();
params.gravity = gravity;
getSlider().setLayoutParams(params);
mDrawerBuilder.mDrawerGravity = gravity;
}
|
java
|
public void setGravity(int gravity) {
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) getSlider().getLayoutParams();
params.gravity = gravity;
getSlider().setLayoutParams(params);
mDrawerBuilder.mDrawerGravity = gravity;
}
|
[
"public",
"void",
"setGravity",
"(",
"int",
"gravity",
")",
"{",
"DrawerLayout",
".",
"LayoutParams",
"params",
"=",
"(",
"DrawerLayout",
".",
"LayoutParams",
")",
"getSlider",
"(",
")",
".",
"getLayoutParams",
"(",
")",
";",
"params",
".",
"gravity",
"=",
"gravity",
";",
"getSlider",
"(",
")",
".",
"setLayoutParams",
"(",
"params",
")",
";",
"mDrawerBuilder",
".",
"mDrawerGravity",
"=",
"gravity",
";",
"}"
] |
sets the gravity for this drawer.
@param gravity the gravity which is defined for the drawer
|
[
"sets",
"the",
"gravity",
"for",
"this",
"drawer",
"."
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L396-L401
|
14,945
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.getDrawerItem
|
public IDrawerItem getDrawerItem(long identifier) {
Pair<IDrawerItem, Integer> res = getAdapter().getItemById(identifier);
if (res != null) {
return res.first;
} else {
return null;
}
}
|
java
|
public IDrawerItem getDrawerItem(long identifier) {
Pair<IDrawerItem, Integer> res = getAdapter().getItemById(identifier);
if (res != null) {
return res.first;
} else {
return null;
}
}
|
[
"public",
"IDrawerItem",
"getDrawerItem",
"(",
"long",
"identifier",
")",
"{",
"Pair",
"<",
"IDrawerItem",
",",
"Integer",
">",
"res",
"=",
"getAdapter",
"(",
")",
".",
"getItemById",
"(",
"identifier",
")",
";",
"if",
"(",
"res",
"!=",
"null",
")",
"{",
"return",
"res",
".",
"first",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
returns the DrawerItem by the given identifier
@param identifier
@return
|
[
"returns",
"the",
"DrawerItem",
"by",
"the",
"given",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L429-L436
|
14,946
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.getCurrentSelectedPosition
|
public int getCurrentSelectedPosition() {
return mDrawerBuilder.mAdapter.getSelections().size() == 0 ? -1 : mDrawerBuilder.mAdapter.getSelections().iterator().next();
}
|
java
|
public int getCurrentSelectedPosition() {
return mDrawerBuilder.mAdapter.getSelections().size() == 0 ? -1 : mDrawerBuilder.mAdapter.getSelections().iterator().next();
}
|
[
"public",
"int",
"getCurrentSelectedPosition",
"(",
")",
"{",
"return",
"mDrawerBuilder",
".",
"mAdapter",
".",
"getSelections",
"(",
")",
".",
"size",
"(",
")",
"==",
"0",
"?",
"-",
"1",
":",
"mDrawerBuilder",
".",
"mAdapter",
".",
"getSelections",
"(",
")",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
";",
"}"
] |
get the current position of the selected drawer element
@return
|
[
"get",
"the",
"current",
"position",
"of",
"the",
"selected",
"drawer",
"element"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L473-L475
|
14,947
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.getCurrentSelection
|
public long getCurrentSelection() {
IDrawerItem drawerItem = mDrawerBuilder.getDrawerItem(getCurrentSelectedPosition());
if (drawerItem != null) {
return drawerItem.getIdentifier();
}
return -1;
}
|
java
|
public long getCurrentSelection() {
IDrawerItem drawerItem = mDrawerBuilder.getDrawerItem(getCurrentSelectedPosition());
if (drawerItem != null) {
return drawerItem.getIdentifier();
}
return -1;
}
|
[
"public",
"long",
"getCurrentSelection",
"(",
")",
"{",
"IDrawerItem",
"drawerItem",
"=",
"mDrawerBuilder",
".",
"getDrawerItem",
"(",
"getCurrentSelectedPosition",
"(",
")",
")",
";",
"if",
"(",
"drawerItem",
"!=",
"null",
")",
"{",
"return",
"drawerItem",
".",
"getIdentifier",
"(",
")",
";",
"}",
"return",
"-",
"1",
";",
"}"
] |
get the current selected item identifier
@return
|
[
"get",
"the",
"current",
"selected",
"item",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L482-L488
|
14,948
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.updateBadge
|
public void updateBadge(long identifier, StringHolder badge) {
IDrawerItem drawerItem = getDrawerItem(identifier);
if (drawerItem instanceof Badgeable) {
Badgeable badgeable = (Badgeable) drawerItem;
badgeable.withBadge(badge);
updateItem((IDrawerItem) badgeable);
}
}
|
java
|
public void updateBadge(long identifier, StringHolder badge) {
IDrawerItem drawerItem = getDrawerItem(identifier);
if (drawerItem instanceof Badgeable) {
Badgeable badgeable = (Badgeable) drawerItem;
badgeable.withBadge(badge);
updateItem((IDrawerItem) badgeable);
}
}
|
[
"public",
"void",
"updateBadge",
"(",
"long",
"identifier",
",",
"StringHolder",
"badge",
")",
"{",
"IDrawerItem",
"drawerItem",
"=",
"getDrawerItem",
"(",
"identifier",
")",
";",
"if",
"(",
"drawerItem",
"instanceof",
"Badgeable",
")",
"{",
"Badgeable",
"badgeable",
"=",
"(",
"Badgeable",
")",
"drawerItem",
";",
"badgeable",
".",
"withBadge",
"(",
"badge",
")",
";",
"updateItem",
"(",
"(",
"IDrawerItem",
")",
"badgeable",
")",
";",
"}",
"}"
] |
update the badge for a specific drawerItem
identified by its id
@param identifier
@param badge
|
[
"update",
"the",
"badge",
"for",
"a",
"specific",
"drawerItem",
"identified",
"by",
"its",
"id"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L665-L672
|
14,949
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.removeItemByPosition
|
public void removeItemByPosition(int position) {
if (mDrawerBuilder.checkDrawerItem(position, false)) {
mDrawerBuilder.getItemAdapter().remove(position);
}
}
|
java
|
public void removeItemByPosition(int position) {
if (mDrawerBuilder.checkDrawerItem(position, false)) {
mDrawerBuilder.getItemAdapter().remove(position);
}
}
|
[
"public",
"void",
"removeItemByPosition",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"mDrawerBuilder",
".",
"checkDrawerItem",
"(",
"position",
",",
"false",
")",
")",
"{",
"mDrawerBuilder",
".",
"getItemAdapter",
"(",
")",
".",
"remove",
"(",
"position",
")",
";",
"}",
"}"
] |
Remove a drawerItem at a specific position
@param position
|
[
"Remove",
"a",
"drawerItem",
"at",
"a",
"specific",
"position"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L752-L756
|
14,950
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.removeStickyFooterItemAtPosition
|
public void removeStickyFooterItemAtPosition(int position) {
if (mDrawerBuilder.mStickyDrawerItems != null && mDrawerBuilder.mStickyDrawerItems.size() > position) {
mDrawerBuilder.mStickyDrawerItems.remove(position);
}
DrawerUtils.rebuildStickyFooterView(mDrawerBuilder);
}
|
java
|
public void removeStickyFooterItemAtPosition(int position) {
if (mDrawerBuilder.mStickyDrawerItems != null && mDrawerBuilder.mStickyDrawerItems.size() > position) {
mDrawerBuilder.mStickyDrawerItems.remove(position);
}
DrawerUtils.rebuildStickyFooterView(mDrawerBuilder);
}
|
[
"public",
"void",
"removeStickyFooterItemAtPosition",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"mDrawerBuilder",
".",
"mStickyDrawerItems",
"!=",
"null",
"&&",
"mDrawerBuilder",
".",
"mStickyDrawerItems",
".",
"size",
"(",
")",
">",
"position",
")",
"{",
"mDrawerBuilder",
".",
"mStickyDrawerItems",
".",
"remove",
"(",
"position",
")",
";",
"}",
"DrawerUtils",
".",
"rebuildStickyFooterView",
"(",
"mDrawerBuilder",
")",
";",
"}"
] |
Remove a footerDrawerItem at a specific position
@param position
|
[
"Remove",
"a",
"footerDrawerItem",
"at",
"a",
"specific",
"position"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L903-L909
|
14,951
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.removeAllStickyFooterItems
|
public void removeAllStickyFooterItems() {
if (mDrawerBuilder.mStickyDrawerItems != null) {
mDrawerBuilder.mStickyDrawerItems.clear();
}
if (mDrawerBuilder.mStickyFooterView != null) {
mDrawerBuilder.mStickyFooterView.setVisibility(View.GONE);
}
}
|
java
|
public void removeAllStickyFooterItems() {
if (mDrawerBuilder.mStickyDrawerItems != null) {
mDrawerBuilder.mStickyDrawerItems.clear();
}
if (mDrawerBuilder.mStickyFooterView != null) {
mDrawerBuilder.mStickyFooterView.setVisibility(View.GONE);
}
}
|
[
"public",
"void",
"removeAllStickyFooterItems",
"(",
")",
"{",
"if",
"(",
"mDrawerBuilder",
".",
"mStickyDrawerItems",
"!=",
"null",
")",
"{",
"mDrawerBuilder",
".",
"mStickyDrawerItems",
".",
"clear",
"(",
")",
";",
"}",
"if",
"(",
"mDrawerBuilder",
".",
"mStickyFooterView",
"!=",
"null",
")",
"{",
"mDrawerBuilder",
".",
"mStickyFooterView",
".",
"setVisibility",
"(",
"View",
".",
"GONE",
")",
";",
"}",
"}"
] |
Removes all footerItems from drawer
|
[
"Removes",
"all",
"footerItems",
"from",
"drawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L914-L921
|
14,952
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/Drawer.java
|
Drawer.resetDrawerContent
|
public void resetDrawerContent() {
if (switchedDrawerContent()) {
//set the new items
setOnDrawerItemClickListener(originalOnDrawerItemClickListener);
setOnDrawerItemLongClickListener(originalOnDrawerItemLongClickListener);
setItems(originalDrawerItems, true);
getAdapter().withSavedInstanceState(originalDrawerState);
//remove the references
originalOnDrawerItemClickListener = null;
originalOnDrawerItemLongClickListener = null;
originalDrawerItems = null;
originalDrawerState = null;
//if we switch back scroll back to the top
mDrawerBuilder.mRecyclerView.smoothScrollToPosition(0);
//show the stickyFooter and it's shadow again
if (getStickyFooter() != null) {
getStickyFooter().setVisibility(View.VISIBLE);
}
if (getStickyFooterShadow() != null) {
getStickyFooterShadow().setVisibility(View.VISIBLE);
}
//if we currently show the accountHeader selection list make sure to reset this attr
if (mDrawerBuilder.mAccountHeader != null && mDrawerBuilder.mAccountHeader.mAccountHeaderBuilder != null) {
mDrawerBuilder.mAccountHeader.mAccountHeaderBuilder.mSelectionListShown = false;
}
}
}
|
java
|
public void resetDrawerContent() {
if (switchedDrawerContent()) {
//set the new items
setOnDrawerItemClickListener(originalOnDrawerItemClickListener);
setOnDrawerItemLongClickListener(originalOnDrawerItemLongClickListener);
setItems(originalDrawerItems, true);
getAdapter().withSavedInstanceState(originalDrawerState);
//remove the references
originalOnDrawerItemClickListener = null;
originalOnDrawerItemLongClickListener = null;
originalDrawerItems = null;
originalDrawerState = null;
//if we switch back scroll back to the top
mDrawerBuilder.mRecyclerView.smoothScrollToPosition(0);
//show the stickyFooter and it's shadow again
if (getStickyFooter() != null) {
getStickyFooter().setVisibility(View.VISIBLE);
}
if (getStickyFooterShadow() != null) {
getStickyFooterShadow().setVisibility(View.VISIBLE);
}
//if we currently show the accountHeader selection list make sure to reset this attr
if (mDrawerBuilder.mAccountHeader != null && mDrawerBuilder.mAccountHeader.mAccountHeaderBuilder != null) {
mDrawerBuilder.mAccountHeader.mAccountHeaderBuilder.mSelectionListShown = false;
}
}
}
|
[
"public",
"void",
"resetDrawerContent",
"(",
")",
"{",
"if",
"(",
"switchedDrawerContent",
"(",
")",
")",
"{",
"//set the new items",
"setOnDrawerItemClickListener",
"(",
"originalOnDrawerItemClickListener",
")",
";",
"setOnDrawerItemLongClickListener",
"(",
"originalOnDrawerItemLongClickListener",
")",
";",
"setItems",
"(",
"originalDrawerItems",
",",
"true",
")",
";",
"getAdapter",
"(",
")",
".",
"withSavedInstanceState",
"(",
"originalDrawerState",
")",
";",
"//remove the references",
"originalOnDrawerItemClickListener",
"=",
"null",
";",
"originalOnDrawerItemLongClickListener",
"=",
"null",
";",
"originalDrawerItems",
"=",
"null",
";",
"originalDrawerState",
"=",
"null",
";",
"//if we switch back scroll back to the top",
"mDrawerBuilder",
".",
"mRecyclerView",
".",
"smoothScrollToPosition",
"(",
"0",
")",
";",
"//show the stickyFooter and it's shadow again",
"if",
"(",
"getStickyFooter",
"(",
")",
"!=",
"null",
")",
"{",
"getStickyFooter",
"(",
")",
".",
"setVisibility",
"(",
"View",
".",
"VISIBLE",
")",
";",
"}",
"if",
"(",
"getStickyFooterShadow",
"(",
")",
"!=",
"null",
")",
"{",
"getStickyFooterShadow",
"(",
")",
".",
"setVisibility",
"(",
"View",
".",
"VISIBLE",
")",
";",
"}",
"//if we currently show the accountHeader selection list make sure to reset this attr",
"if",
"(",
"mDrawerBuilder",
".",
"mAccountHeader",
"!=",
"null",
"&&",
"mDrawerBuilder",
".",
"mAccountHeader",
".",
"mAccountHeaderBuilder",
"!=",
"null",
")",
"{",
"mDrawerBuilder",
".",
"mAccountHeader",
".",
"mAccountHeaderBuilder",
".",
"mSelectionListShown",
"=",
"false",
";",
"}",
"}",
"}"
] |
helper method to reset to the original drawerContent
|
[
"helper",
"method",
"to",
"reset",
"to",
"the",
"original",
"drawerContent"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L1034-L1063
|
14,953
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.getTextColorStateList
|
public static ColorStateList getTextColorStateList(int text_color, int selected_text_color) {
return new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{}
},
new int[]{
selected_text_color,
text_color
}
);
}
|
java
|
public static ColorStateList getTextColorStateList(int text_color, int selected_text_color) {
return new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_selected},
new int[]{}
},
new int[]{
selected_text_color,
text_color
}
);
}
|
[
"public",
"static",
"ColorStateList",
"getTextColorStateList",
"(",
"int",
"text_color",
",",
"int",
"selected_text_color",
")",
"{",
"return",
"new",
"ColorStateList",
"(",
"new",
"int",
"[",
"]",
"[",
"]",
"{",
"new",
"int",
"[",
"]",
"{",
"android",
".",
"R",
".",
"attr",
".",
"state_selected",
"}",
",",
"new",
"int",
"[",
"]",
"{",
"}",
"}",
",",
"new",
"int",
"[",
"]",
"{",
"selected_text_color",
",",
"text_color",
"}",
")",
";",
"}"
] |
helper to create a colorStateList for the text
@param text_color
@param selected_text_color
@return
|
[
"helper",
"to",
"create",
"a",
"colorStateList",
"for",
"the",
"text"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L135-L146
|
14,954
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.getIconStateList
|
public static StateListDrawable getIconStateList(Drawable icon, Drawable selectedIcon) {
StateListDrawable iconStateListDrawable = new StateListDrawable();
iconStateListDrawable.addState(new int[]{android.R.attr.state_selected}, selectedIcon);
iconStateListDrawable.addState(new int[]{}, icon);
return iconStateListDrawable;
}
|
java
|
public static StateListDrawable getIconStateList(Drawable icon, Drawable selectedIcon) {
StateListDrawable iconStateListDrawable = new StateListDrawable();
iconStateListDrawable.addState(new int[]{android.R.attr.state_selected}, selectedIcon);
iconStateListDrawable.addState(new int[]{}, icon);
return iconStateListDrawable;
}
|
[
"public",
"static",
"StateListDrawable",
"getIconStateList",
"(",
"Drawable",
"icon",
",",
"Drawable",
"selectedIcon",
")",
"{",
"StateListDrawable",
"iconStateListDrawable",
"=",
"new",
"StateListDrawable",
"(",
")",
";",
"iconStateListDrawable",
".",
"addState",
"(",
"new",
"int",
"[",
"]",
"{",
"android",
".",
"R",
".",
"attr",
".",
"state_selected",
"}",
",",
"selectedIcon",
")",
";",
"iconStateListDrawable",
".",
"addState",
"(",
"new",
"int",
"[",
"]",
"{",
"}",
",",
"icon",
")",
";",
"return",
"iconStateListDrawable",
";",
"}"
] |
helper to create a stateListDrawable for the icon
@param icon
@param selectedIcon
@return
|
[
"helper",
"to",
"create",
"a",
"stateListDrawable",
"for",
"the",
"icon"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L155-L160
|
14,955
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.getDrawerItemBackground
|
public static StateListDrawable getDrawerItemBackground(int selected_color) {
ColorDrawable clrActive = new ColorDrawable(selected_color);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_selected}, clrActive);
return states;
}
|
java
|
public static StateListDrawable getDrawerItemBackground(int selected_color) {
ColorDrawable clrActive = new ColorDrawable(selected_color);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_selected}, clrActive);
return states;
}
|
[
"public",
"static",
"StateListDrawable",
"getDrawerItemBackground",
"(",
"int",
"selected_color",
")",
"{",
"ColorDrawable",
"clrActive",
"=",
"new",
"ColorDrawable",
"(",
"selected_color",
")",
";",
"StateListDrawable",
"states",
"=",
"new",
"StateListDrawable",
"(",
")",
";",
"states",
".",
"addState",
"(",
"new",
"int",
"[",
"]",
"{",
"android",
".",
"R",
".",
"attr",
".",
"state_selected",
"}",
",",
"clrActive",
")",
";",
"return",
"states",
";",
"}"
] |
helper to create a StateListDrawable for the drawer item background
@param selected_color
@return
|
[
"helper",
"to",
"create",
"a",
"StateListDrawable",
"for",
"the",
"drawer",
"item",
"background"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L168-L173
|
14,956
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.getOptimalDrawerWidth
|
public static int getOptimalDrawerWidth(Context context) {
int possibleMinDrawerWidth = UIUtils.getScreenWidth(context) - UIUtils.getActionBarHeight(context);
int maxDrawerWidth = context.getResources().getDimensionPixelSize(R.dimen.material_drawer_width);
return Math.min(possibleMinDrawerWidth, maxDrawerWidth);
}
|
java
|
public static int getOptimalDrawerWidth(Context context) {
int possibleMinDrawerWidth = UIUtils.getScreenWidth(context) - UIUtils.getActionBarHeight(context);
int maxDrawerWidth = context.getResources().getDimensionPixelSize(R.dimen.material_drawer_width);
return Math.min(possibleMinDrawerWidth, maxDrawerWidth);
}
|
[
"public",
"static",
"int",
"getOptimalDrawerWidth",
"(",
"Context",
"context",
")",
"{",
"int",
"possibleMinDrawerWidth",
"=",
"UIUtils",
".",
"getScreenWidth",
"(",
"context",
")",
"-",
"UIUtils",
".",
"getActionBarHeight",
"(",
"context",
")",
";",
"int",
"maxDrawerWidth",
"=",
"context",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_width",
")",
";",
"return",
"Math",
".",
"min",
"(",
"possibleMinDrawerWidth",
",",
"maxDrawerWidth",
")",
";",
"}"
] |
helper to calculate the optimal drawer width
@param context
@return
|
[
"helper",
"to",
"calculate",
"the",
"optimal",
"drawer",
"width"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L181-L185
|
14,957
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.getPlaceHolder
|
public static Drawable getPlaceHolder(Context ctx) {
return new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_person).colorRes(R.color.accent).backgroundColorRes(R.color.primary).sizeDp(56).paddingDp(16);
}
|
java
|
public static Drawable getPlaceHolder(Context ctx) {
return new IconicsDrawable(ctx, MaterialDrawerFont.Icon.mdf_person).colorRes(R.color.accent).backgroundColorRes(R.color.primary).sizeDp(56).paddingDp(16);
}
|
[
"public",
"static",
"Drawable",
"getPlaceHolder",
"(",
"Context",
"ctx",
")",
"{",
"return",
"new",
"IconicsDrawable",
"(",
"ctx",
",",
"MaterialDrawerFont",
".",
"Icon",
".",
"mdf_person",
")",
".",
"colorRes",
"(",
"R",
".",
"color",
".",
"accent",
")",
".",
"backgroundColorRes",
"(",
"R",
".",
"color",
".",
"primary",
")",
".",
"sizeDp",
"(",
"56",
")",
".",
"paddingDp",
"(",
"16",
")",
";",
"}"
] |
helper method to get a person placeHolder drawable
@param ctx
@return
|
[
"helper",
"method",
"to",
"get",
"a",
"person",
"placeHolder",
"drawable"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L194-L196
|
14,958
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.setDrawerVerticalPadding
|
public static void setDrawerVerticalPadding(View v) {
int verticalPadding = v.getContext().getResources().getDimensionPixelSize(R.dimen.material_drawer_vertical_padding);
v.setPadding(verticalPadding, 0, verticalPadding, 0);
}
|
java
|
public static void setDrawerVerticalPadding(View v) {
int verticalPadding = v.getContext().getResources().getDimensionPixelSize(R.dimen.material_drawer_vertical_padding);
v.setPadding(verticalPadding, 0, verticalPadding, 0);
}
|
[
"public",
"static",
"void",
"setDrawerVerticalPadding",
"(",
"View",
"v",
")",
"{",
"int",
"verticalPadding",
"=",
"v",
".",
"getContext",
"(",
")",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_vertical_padding",
")",
";",
"v",
".",
"setPadding",
"(",
"verticalPadding",
",",
"0",
",",
"verticalPadding",
",",
"0",
")",
";",
"}"
] |
helper to set the vertical padding to the DrawerItems
this is required because on API Level 17 the padding is ignored which is set via the XML
@param v
|
[
"helper",
"to",
"set",
"the",
"vertical",
"padding",
"to",
"the",
"DrawerItems",
"this",
"is",
"required",
"because",
"on",
"API",
"Level",
"17",
"the",
"padding",
"is",
"ignored",
"which",
"is",
"set",
"via",
"the",
"XML"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L204-L207
|
14,959
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.setDrawerVerticalPadding
|
public static void setDrawerVerticalPadding(View v, int level) {
int verticalPadding = v.getContext().getResources().getDimensionPixelSize(R.dimen.material_drawer_vertical_padding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
v.setPaddingRelative(verticalPadding * level, 0, verticalPadding, 0);
} else {
v.setPadding(verticalPadding * level, 0, verticalPadding, 0);
}
}
|
java
|
public static void setDrawerVerticalPadding(View v, int level) {
int verticalPadding = v.getContext().getResources().getDimensionPixelSize(R.dimen.material_drawer_vertical_padding);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
v.setPaddingRelative(verticalPadding * level, 0, verticalPadding, 0);
} else {
v.setPadding(verticalPadding * level, 0, verticalPadding, 0);
}
}
|
[
"public",
"static",
"void",
"setDrawerVerticalPadding",
"(",
"View",
"v",
",",
"int",
"level",
")",
"{",
"int",
"verticalPadding",
"=",
"v",
".",
"getContext",
"(",
")",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_vertical_padding",
")",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"JELLY_BEAN_MR1",
")",
"{",
"v",
".",
"setPaddingRelative",
"(",
"verticalPadding",
"*",
"level",
",",
"0",
",",
"verticalPadding",
",",
"0",
")",
";",
"}",
"else",
"{",
"v",
".",
"setPadding",
"(",
"verticalPadding",
"*",
"level",
",",
"0",
",",
"verticalPadding",
",",
"0",
")",
";",
"}",
"}"
] |
helper to set the vertical padding including the extra padding for deeper item hirachy level to the DrawerItems
this is required because on API Level 17 the padding is ignored which is set via the XML
@param v
@param level
|
[
"helper",
"to",
"set",
"the",
"vertical",
"padding",
"including",
"the",
"extra",
"padding",
"for",
"deeper",
"item",
"hirachy",
"level",
"to",
"the",
"DrawerItems",
"this",
"is",
"required",
"because",
"on",
"API",
"Level",
"17",
"the",
"padding",
"is",
"ignored",
"which",
"is",
"set",
"via",
"the",
"XML"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L216-L224
|
14,960
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java
|
DrawerUIUtils.isSystemBarOnBottom
|
public static boolean isSystemBarOnBottom(Context ctx) {
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
Configuration cfg = ctx.getResources().getConfiguration();
boolean canMove = (metrics.widthPixels != metrics.heightPixels &&
cfg.smallestScreenWidthDp < 600);
return (!canMove || metrics.widthPixels < metrics.heightPixels);
}
|
java
|
public static boolean isSystemBarOnBottom(Context ctx) {
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
Configuration cfg = ctx.getResources().getConfiguration();
boolean canMove = (metrics.widthPixels != metrics.heightPixels &&
cfg.smallestScreenWidthDp < 600);
return (!canMove || metrics.widthPixels < metrics.heightPixels);
}
|
[
"public",
"static",
"boolean",
"isSystemBarOnBottom",
"(",
"Context",
"ctx",
")",
"{",
"WindowManager",
"wm",
"=",
"(",
"WindowManager",
")",
"ctx",
".",
"getSystemService",
"(",
"Context",
".",
"WINDOW_SERVICE",
")",
";",
"DisplayMetrics",
"metrics",
"=",
"new",
"DisplayMetrics",
"(",
")",
";",
"wm",
".",
"getDefaultDisplay",
"(",
")",
".",
"getMetrics",
"(",
"metrics",
")",
";",
"Configuration",
"cfg",
"=",
"ctx",
".",
"getResources",
"(",
")",
".",
"getConfiguration",
"(",
")",
";",
"boolean",
"canMove",
"=",
"(",
"metrics",
".",
"widthPixels",
"!=",
"metrics",
".",
"heightPixels",
"&&",
"cfg",
".",
"smallestScreenWidthDp",
"<",
"600",
")",
";",
"return",
"(",
"!",
"canMove",
"||",
"metrics",
".",
"widthPixels",
"<",
"metrics",
".",
"heightPixels",
")",
";",
"}"
] |
helper to check if the system bar is on the bottom of the screen
@param ctx
@return
|
[
"helper",
"to",
"check",
"if",
"the",
"system",
"bar",
"is",
"on",
"the",
"bottom",
"of",
"the",
"screen"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/DrawerUIUtils.java#L232-L241
|
14,961
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/model/AbstractDrawerItem.java
|
AbstractDrawerItem.onPostBindView
|
public void onPostBindView(IDrawerItem drawerItem, View view) {
if (mOnPostBindViewListener != null) {
mOnPostBindViewListener.onBindView(drawerItem, view);
}
}
|
java
|
public void onPostBindView(IDrawerItem drawerItem, View view) {
if (mOnPostBindViewListener != null) {
mOnPostBindViewListener.onBindView(drawerItem, view);
}
}
|
[
"public",
"void",
"onPostBindView",
"(",
"IDrawerItem",
"drawerItem",
",",
"View",
"view",
")",
"{",
"if",
"(",
"mOnPostBindViewListener",
"!=",
"null",
")",
"{",
"mOnPostBindViewListener",
".",
"onBindView",
"(",
"drawerItem",
",",
"view",
")",
";",
"}",
"}"
] |
is called after bindView to allow some post creation setps
@param drawerItem the drawerItem which is bound to the view
@param view the currently view which will be bound
|
[
"is",
"called",
"after",
"bindView",
"to",
"allow",
"some",
"post",
"creation",
"setps"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/model/AbstractDrawerItem.java#L204-L208
|
14,962
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/model/AbstractDrawerItem.java
|
AbstractDrawerItem.getViewHolder
|
@Override
public VH getViewHolder(ViewGroup parent) {
return getViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutRes(), parent, false));
}
|
java
|
@Override
public VH getViewHolder(ViewGroup parent) {
return getViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutRes(), parent, false));
}
|
[
"@",
"Override",
"public",
"VH",
"getViewHolder",
"(",
"ViewGroup",
"parent",
")",
"{",
"return",
"getViewHolder",
"(",
"LayoutInflater",
".",
"from",
"(",
"parent",
".",
"getContext",
"(",
")",
")",
".",
"inflate",
"(",
"getLayoutRes",
"(",
")",
",",
"parent",
",",
"false",
")",
")",
";",
"}"
] |
This method returns the ViewHolder for our item, using the provided View.
@param parent
@return the ViewHolder for this Item
|
[
"This",
"method",
"returns",
"the",
"ViewHolder",
"for",
"our",
"item",
"using",
"the",
"provided",
"View",
"."
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/model/AbstractDrawerItem.java#L390-L393
|
14,963
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/model/SecondarySwitchDrawerItem.java
|
SecondarySwitchDrawerItem.getColor
|
@Override
protected int getColor(Context ctx) {
int color;
if (this.isEnabled()) {
color = ColorHolder.color(getTextColor(), ctx, R.attr.material_drawer_secondary_text, R.color.material_drawer_secondary_text);
} else {
color = ColorHolder.color(getDisabledTextColor(), ctx, R.attr.material_drawer_hint_text, R.color.material_drawer_hint_text);
}
return color;
}
|
java
|
@Override
protected int getColor(Context ctx) {
int color;
if (this.isEnabled()) {
color = ColorHolder.color(getTextColor(), ctx, R.attr.material_drawer_secondary_text, R.color.material_drawer_secondary_text);
} else {
color = ColorHolder.color(getDisabledTextColor(), ctx, R.attr.material_drawer_hint_text, R.color.material_drawer_hint_text);
}
return color;
}
|
[
"@",
"Override",
"protected",
"int",
"getColor",
"(",
"Context",
"ctx",
")",
"{",
"int",
"color",
";",
"if",
"(",
"this",
".",
"isEnabled",
"(",
")",
")",
"{",
"color",
"=",
"ColorHolder",
".",
"color",
"(",
"getTextColor",
"(",
")",
",",
"ctx",
",",
"R",
".",
"attr",
".",
"material_drawer_secondary_text",
",",
"R",
".",
"color",
".",
"material_drawer_secondary_text",
")",
";",
"}",
"else",
"{",
"color",
"=",
"ColorHolder",
".",
"color",
"(",
"getDisabledTextColor",
"(",
")",
",",
"ctx",
",",
"R",
".",
"attr",
".",
"material_drawer_hint_text",
",",
"R",
".",
"color",
".",
"material_drawer_hint_text",
")",
";",
"}",
"return",
"color",
";",
"}"
] |
helper method to decide for the correct color
OVERWRITE to get the correct secondary color
@param ctx
@return
|
[
"helper",
"method",
"to",
"decide",
"for",
"the",
"correct",
"color",
"OVERWRITE",
"to",
"get",
"the",
"correct",
"secondary",
"color"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/model/SecondarySwitchDrawerItem.java#L32-L41
|
14,964
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.onFooterDrawerItemClick
|
public static void onFooterDrawerItemClick(DrawerBuilder drawer, IDrawerItem drawerItem, View v, Boolean fireOnClick) {
boolean checkable = !(drawerItem != null && drawerItem instanceof Selectable && !drawerItem.isSelectable());
if (checkable) {
drawer.resetStickyFooterSelection();
v.setActivated(true);
v.setSelected(true);
//remove the selection in the list
drawer.getAdapter().deselect();
//find the position of the clicked footer item
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
for (int i = 0; i < footer.getChildCount(); i++) {
if (footer.getChildAt(i) == v) {
drawer.mCurrentStickyFooterSelection = i;
break;
}
}
}
}
if (fireOnClick != null) {
boolean consumed = false;
if (fireOnClick) {
if (drawerItem instanceof AbstractDrawerItem && ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener() != null) {
consumed = ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener().onItemClick(v, -1, drawerItem);
}
if (drawer.mOnDrawerItemClickListener != null) {
consumed = drawer.mOnDrawerItemClickListener.onItemClick(v, -1, drawerItem);
}
}
if (!consumed) {
//close the drawer after click
drawer.closeDrawerDelayed();
}
}
}
|
java
|
public static void onFooterDrawerItemClick(DrawerBuilder drawer, IDrawerItem drawerItem, View v, Boolean fireOnClick) {
boolean checkable = !(drawerItem != null && drawerItem instanceof Selectable && !drawerItem.isSelectable());
if (checkable) {
drawer.resetStickyFooterSelection();
v.setActivated(true);
v.setSelected(true);
//remove the selection in the list
drawer.getAdapter().deselect();
//find the position of the clicked footer item
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
for (int i = 0; i < footer.getChildCount(); i++) {
if (footer.getChildAt(i) == v) {
drawer.mCurrentStickyFooterSelection = i;
break;
}
}
}
}
if (fireOnClick != null) {
boolean consumed = false;
if (fireOnClick) {
if (drawerItem instanceof AbstractDrawerItem && ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener() != null) {
consumed = ((AbstractDrawerItem) drawerItem).getOnDrawerItemClickListener().onItemClick(v, -1, drawerItem);
}
if (drawer.mOnDrawerItemClickListener != null) {
consumed = drawer.mOnDrawerItemClickListener.onItemClick(v, -1, drawerItem);
}
}
if (!consumed) {
//close the drawer after click
drawer.closeDrawerDelayed();
}
}
}
|
[
"public",
"static",
"void",
"onFooterDrawerItemClick",
"(",
"DrawerBuilder",
"drawer",
",",
"IDrawerItem",
"drawerItem",
",",
"View",
"v",
",",
"Boolean",
"fireOnClick",
")",
"{",
"boolean",
"checkable",
"=",
"!",
"(",
"drawerItem",
"!=",
"null",
"&&",
"drawerItem",
"instanceof",
"Selectable",
"&&",
"!",
"drawerItem",
".",
"isSelectable",
"(",
")",
")",
";",
"if",
"(",
"checkable",
")",
"{",
"drawer",
".",
"resetStickyFooterSelection",
"(",
")",
";",
"v",
".",
"setActivated",
"(",
"true",
")",
";",
"v",
".",
"setSelected",
"(",
"true",
")",
";",
"//remove the selection in the list",
"drawer",
".",
"getAdapter",
"(",
")",
".",
"deselect",
"(",
")",
";",
"//find the position of the clicked footer item",
"if",
"(",
"drawer",
".",
"mStickyFooterView",
"!=",
"null",
"&&",
"drawer",
".",
"mStickyFooterView",
"instanceof",
"LinearLayout",
")",
"{",
"LinearLayout",
"footer",
"=",
"(",
"LinearLayout",
")",
"drawer",
".",
"mStickyFooterView",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"footer",
".",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"footer",
".",
"getChildAt",
"(",
"i",
")",
"==",
"v",
")",
"{",
"drawer",
".",
"mCurrentStickyFooterSelection",
"=",
"i",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"fireOnClick",
"!=",
"null",
")",
"{",
"boolean",
"consumed",
"=",
"false",
";",
"if",
"(",
"fireOnClick",
")",
"{",
"if",
"(",
"drawerItem",
"instanceof",
"AbstractDrawerItem",
"&&",
"(",
"(",
"AbstractDrawerItem",
")",
"drawerItem",
")",
".",
"getOnDrawerItemClickListener",
"(",
")",
"!=",
"null",
")",
"{",
"consumed",
"=",
"(",
"(",
"AbstractDrawerItem",
")",
"drawerItem",
")",
".",
"getOnDrawerItemClickListener",
"(",
")",
".",
"onItemClick",
"(",
"v",
",",
"-",
"1",
",",
"drawerItem",
")",
";",
"}",
"if",
"(",
"drawer",
".",
"mOnDrawerItemClickListener",
"!=",
"null",
")",
"{",
"consumed",
"=",
"drawer",
".",
"mOnDrawerItemClickListener",
".",
"onItemClick",
"(",
"v",
",",
"-",
"1",
",",
"drawerItem",
")",
";",
"}",
"}",
"if",
"(",
"!",
"consumed",
")",
"{",
"//close the drawer after click",
"drawer",
".",
"closeDrawerDelayed",
"(",
")",
";",
"}",
"}",
"}"
] |
helper method to handle the onClick of the footer
@param drawer
@param drawerItem
@param v
@param fireOnClick true if we should call the listener, false if not, null to not call the listener and not close the drawer
|
[
"helper",
"method",
"to",
"handle",
"the",
"onClick",
"of",
"the",
"footer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L34-L76
|
14,965
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.setStickyFooterSelection
|
public static void setStickyFooterSelection(DrawerBuilder drawer, int position, Boolean fireOnClick) {
if (position > -1) {
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
if (drawer.mStickyFooterDivider) {
position = position + 1;
}
if (footer.getChildCount() > position && position >= 0) {
IDrawerItem drawerItem = (IDrawerItem) footer.getChildAt(position).getTag(R.id.material_drawer_item);
onFooterDrawerItemClick(drawer, drawerItem, footer.getChildAt(position), fireOnClick);
}
}
}
}
|
java
|
public static void setStickyFooterSelection(DrawerBuilder drawer, int position, Boolean fireOnClick) {
if (position > -1) {
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
if (drawer.mStickyFooterDivider) {
position = position + 1;
}
if (footer.getChildCount() > position && position >= 0) {
IDrawerItem drawerItem = (IDrawerItem) footer.getChildAt(position).getTag(R.id.material_drawer_item);
onFooterDrawerItemClick(drawer, drawerItem, footer.getChildAt(position), fireOnClick);
}
}
}
}
|
[
"public",
"static",
"void",
"setStickyFooterSelection",
"(",
"DrawerBuilder",
"drawer",
",",
"int",
"position",
",",
"Boolean",
"fireOnClick",
")",
"{",
"if",
"(",
"position",
">",
"-",
"1",
")",
"{",
"if",
"(",
"drawer",
".",
"mStickyFooterView",
"!=",
"null",
"&&",
"drawer",
".",
"mStickyFooterView",
"instanceof",
"LinearLayout",
")",
"{",
"LinearLayout",
"footer",
"=",
"(",
"LinearLayout",
")",
"drawer",
".",
"mStickyFooterView",
";",
"if",
"(",
"drawer",
".",
"mStickyFooterDivider",
")",
"{",
"position",
"=",
"position",
"+",
"1",
";",
"}",
"if",
"(",
"footer",
".",
"getChildCount",
"(",
")",
">",
"position",
"&&",
"position",
">=",
"0",
")",
"{",
"IDrawerItem",
"drawerItem",
"=",
"(",
"IDrawerItem",
")",
"footer",
".",
"getChildAt",
"(",
"position",
")",
".",
"getTag",
"(",
"R",
".",
"id",
".",
"material_drawer_item",
")",
";",
"onFooterDrawerItemClick",
"(",
"drawer",
",",
"drawerItem",
",",
"footer",
".",
"getChildAt",
"(",
"position",
")",
",",
"fireOnClick",
")",
";",
"}",
"}",
"}",
"}"
] |
helper method to set the selection of the footer
@param drawer
@param position
@param fireOnClick
|
[
"helper",
"method",
"to",
"set",
"the",
"selection",
"of",
"the",
"footer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L85-L98
|
14,966
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.getPositionByIdentifier
|
public static int getPositionByIdentifier(DrawerBuilder drawer, long identifier) {
if (identifier != -1) {
for (int i = 0; i < drawer.getAdapter().getItemCount(); i++) {
if (drawer.getAdapter().getItem(i).getIdentifier() == identifier) {
return i;
}
}
}
return -1;
}
|
java
|
public static int getPositionByIdentifier(DrawerBuilder drawer, long identifier) {
if (identifier != -1) {
for (int i = 0; i < drawer.getAdapter().getItemCount(); i++) {
if (drawer.getAdapter().getItem(i).getIdentifier() == identifier) {
return i;
}
}
}
return -1;
}
|
[
"public",
"static",
"int",
"getPositionByIdentifier",
"(",
"DrawerBuilder",
"drawer",
",",
"long",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"!=",
"-",
"1",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"drawer",
".",
"getAdapter",
"(",
")",
".",
"getItemCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"drawer",
".",
"getAdapter",
"(",
")",
".",
"getItem",
"(",
"i",
")",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
")",
"{",
"return",
"i",
";",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
calculates the position of an drawerItem. searching by it's identifier
@param identifier
@return
|
[
"calculates",
"the",
"position",
"of",
"an",
"drawerItem",
".",
"searching",
"by",
"it",
"s",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L106-L116
|
14,967
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.getDrawerItem
|
public static IDrawerItem getDrawerItem(List<IDrawerItem> drawerItems, long identifier) {
if (identifier != -1) {
for (IDrawerItem drawerItem : drawerItems) {
if (drawerItem.getIdentifier() == identifier) {
return drawerItem;
}
}
}
return null;
}
|
java
|
public static IDrawerItem getDrawerItem(List<IDrawerItem> drawerItems, long identifier) {
if (identifier != -1) {
for (IDrawerItem drawerItem : drawerItems) {
if (drawerItem.getIdentifier() == identifier) {
return drawerItem;
}
}
}
return null;
}
|
[
"public",
"static",
"IDrawerItem",
"getDrawerItem",
"(",
"List",
"<",
"IDrawerItem",
">",
"drawerItems",
",",
"long",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"!=",
"-",
"1",
")",
"{",
"for",
"(",
"IDrawerItem",
"drawerItem",
":",
"drawerItems",
")",
"{",
"if",
"(",
"drawerItem",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
")",
"{",
"return",
"drawerItem",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
gets the drawerItem with the specific identifier from a drawerItem list
@param drawerItems
@param identifier
@return
|
[
"gets",
"the",
"drawerItem",
"with",
"the",
"specific",
"identifier",
"from",
"a",
"drawerItem",
"list"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L125-L134
|
14,968
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.getDrawerItem
|
public static IDrawerItem getDrawerItem(List<IDrawerItem> drawerItems, Object tag) {
if (tag != null) {
for (IDrawerItem drawerItem : drawerItems) {
if (tag.equals(drawerItem.getTag())) {
return drawerItem;
}
}
}
return null;
}
|
java
|
public static IDrawerItem getDrawerItem(List<IDrawerItem> drawerItems, Object tag) {
if (tag != null) {
for (IDrawerItem drawerItem : drawerItems) {
if (tag.equals(drawerItem.getTag())) {
return drawerItem;
}
}
}
return null;
}
|
[
"public",
"static",
"IDrawerItem",
"getDrawerItem",
"(",
"List",
"<",
"IDrawerItem",
">",
"drawerItems",
",",
"Object",
"tag",
")",
"{",
"if",
"(",
"tag",
"!=",
"null",
")",
"{",
"for",
"(",
"IDrawerItem",
"drawerItem",
":",
"drawerItems",
")",
"{",
"if",
"(",
"tag",
".",
"equals",
"(",
"drawerItem",
".",
"getTag",
"(",
")",
")",
")",
"{",
"return",
"drawerItem",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
gets the drawerItem by a defined tag from a drawerItem list
@param drawerItems
@param tag
@return
|
[
"gets",
"the",
"drawerItem",
"by",
"a",
"defined",
"tag",
"from",
"a",
"drawerItem",
"list"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L143-L152
|
14,969
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.getStickyFooterPositionByIdentifier
|
public static int getStickyFooterPositionByIdentifier(DrawerBuilder drawer, long identifier) {
if (identifier != -1) {
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
int shadowOffset = 0;
for (int i = 0; i < footer.getChildCount(); i++) {
Object o = footer.getChildAt(i).getTag(R.id.material_drawer_item);
//count up the shadowOffset to return the correct position of the given item
if (o == null && drawer.mStickyFooterDivider) {
shadowOffset = shadowOffset + 1;
}
if (o != null && o instanceof IDrawerItem && ((IDrawerItem) o).getIdentifier() == identifier) {
return i - shadowOffset;
}
}
}
}
return -1;
}
|
java
|
public static int getStickyFooterPositionByIdentifier(DrawerBuilder drawer, long identifier) {
if (identifier != -1) {
if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
int shadowOffset = 0;
for (int i = 0; i < footer.getChildCount(); i++) {
Object o = footer.getChildAt(i).getTag(R.id.material_drawer_item);
//count up the shadowOffset to return the correct position of the given item
if (o == null && drawer.mStickyFooterDivider) {
shadowOffset = shadowOffset + 1;
}
if (o != null && o instanceof IDrawerItem && ((IDrawerItem) o).getIdentifier() == identifier) {
return i - shadowOffset;
}
}
}
}
return -1;
}
|
[
"public",
"static",
"int",
"getStickyFooterPositionByIdentifier",
"(",
"DrawerBuilder",
"drawer",
",",
"long",
"identifier",
")",
"{",
"if",
"(",
"identifier",
"!=",
"-",
"1",
")",
"{",
"if",
"(",
"drawer",
".",
"mStickyFooterView",
"!=",
"null",
"&&",
"drawer",
".",
"mStickyFooterView",
"instanceof",
"LinearLayout",
")",
"{",
"LinearLayout",
"footer",
"=",
"(",
"LinearLayout",
")",
"drawer",
".",
"mStickyFooterView",
";",
"int",
"shadowOffset",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"footer",
".",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"Object",
"o",
"=",
"footer",
".",
"getChildAt",
"(",
"i",
")",
".",
"getTag",
"(",
"R",
".",
"id",
".",
"material_drawer_item",
")",
";",
"//count up the shadowOffset to return the correct position of the given item",
"if",
"(",
"o",
"==",
"null",
"&&",
"drawer",
".",
"mStickyFooterDivider",
")",
"{",
"shadowOffset",
"=",
"shadowOffset",
"+",
"1",
";",
"}",
"if",
"(",
"o",
"!=",
"null",
"&&",
"o",
"instanceof",
"IDrawerItem",
"&&",
"(",
"(",
"IDrawerItem",
")",
"o",
")",
".",
"getIdentifier",
"(",
")",
"==",
"identifier",
")",
"{",
"return",
"i",
"-",
"shadowOffset",
";",
"}",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
calculates the position of an drawerItem inside the footer. searching by it's identifier
@param identifier
@return
|
[
"calculates",
"the",
"position",
"of",
"an",
"drawerItem",
"inside",
"the",
"footer",
".",
"searching",
"by",
"it",
"s",
"identifier"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L160-L182
|
14,970
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.rebuildStickyFooterView
|
public static void rebuildStickyFooterView(final DrawerBuilder drawer) {
if (drawer.mSliderLayout != null) {
if (drawer.mStickyFooterView != null) {
drawer.mStickyFooterView.removeAllViews();
//create the divider
if (drawer.mStickyFooterDivider) {
addStickyFooterDivider(drawer.mStickyFooterView.getContext(), drawer.mStickyFooterView);
}
//fill the footer with items
DrawerUtils.fillStickyDrawerItemFooter(drawer, drawer.mStickyFooterView, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag(R.id.material_drawer_item);
com.mikepenz.materialdrawer.DrawerUtils.onFooterDrawerItemClick(drawer, drawerItem, v, true);
}
});
drawer.mStickyFooterView.setVisibility(View.VISIBLE);
} else {
//there was no footer yet. now just create one
DrawerUtils.handleFooterView(drawer, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag(R.id.material_drawer_item);
DrawerUtils.onFooterDrawerItemClick(drawer, drawerItem, v, true);
}
});
}
setStickyFooterSelection(drawer, drawer.mCurrentStickyFooterSelection, false);
}
}
|
java
|
public static void rebuildStickyFooterView(final DrawerBuilder drawer) {
if (drawer.mSliderLayout != null) {
if (drawer.mStickyFooterView != null) {
drawer.mStickyFooterView.removeAllViews();
//create the divider
if (drawer.mStickyFooterDivider) {
addStickyFooterDivider(drawer.mStickyFooterView.getContext(), drawer.mStickyFooterView);
}
//fill the footer with items
DrawerUtils.fillStickyDrawerItemFooter(drawer, drawer.mStickyFooterView, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag(R.id.material_drawer_item);
com.mikepenz.materialdrawer.DrawerUtils.onFooterDrawerItemClick(drawer, drawerItem, v, true);
}
});
drawer.mStickyFooterView.setVisibility(View.VISIBLE);
} else {
//there was no footer yet. now just create one
DrawerUtils.handleFooterView(drawer, new View.OnClickListener() {
@Override
public void onClick(View v) {
IDrawerItem drawerItem = (IDrawerItem) v.getTag(R.id.material_drawer_item);
DrawerUtils.onFooterDrawerItemClick(drawer, drawerItem, v, true);
}
});
}
setStickyFooterSelection(drawer, drawer.mCurrentStickyFooterSelection, false);
}
}
|
[
"public",
"static",
"void",
"rebuildStickyFooterView",
"(",
"final",
"DrawerBuilder",
"drawer",
")",
"{",
"if",
"(",
"drawer",
".",
"mSliderLayout",
"!=",
"null",
")",
"{",
"if",
"(",
"drawer",
".",
"mStickyFooterView",
"!=",
"null",
")",
"{",
"drawer",
".",
"mStickyFooterView",
".",
"removeAllViews",
"(",
")",
";",
"//create the divider",
"if",
"(",
"drawer",
".",
"mStickyFooterDivider",
")",
"{",
"addStickyFooterDivider",
"(",
"drawer",
".",
"mStickyFooterView",
".",
"getContext",
"(",
")",
",",
"drawer",
".",
"mStickyFooterView",
")",
";",
"}",
"//fill the footer with items",
"DrawerUtils",
".",
"fillStickyDrawerItemFooter",
"(",
"drawer",
",",
"drawer",
".",
"mStickyFooterView",
",",
"new",
"View",
".",
"OnClickListener",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"onClick",
"(",
"View",
"v",
")",
"{",
"IDrawerItem",
"drawerItem",
"=",
"(",
"IDrawerItem",
")",
"v",
".",
"getTag",
"(",
"R",
".",
"id",
".",
"material_drawer_item",
")",
";",
"com",
".",
"mikepenz",
".",
"materialdrawer",
".",
"DrawerUtils",
".",
"onFooterDrawerItemClick",
"(",
"drawer",
",",
"drawerItem",
",",
"v",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"drawer",
".",
"mStickyFooterView",
".",
"setVisibility",
"(",
"View",
".",
"VISIBLE",
")",
";",
"}",
"else",
"{",
"//there was no footer yet. now just create one",
"DrawerUtils",
".",
"handleFooterView",
"(",
"drawer",
",",
"new",
"View",
".",
"OnClickListener",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"onClick",
"(",
"View",
"v",
")",
"{",
"IDrawerItem",
"drawerItem",
"=",
"(",
"IDrawerItem",
")",
"v",
".",
"getTag",
"(",
"R",
".",
"id",
".",
"material_drawer_item",
")",
";",
"DrawerUtils",
".",
"onFooterDrawerItemClick",
"(",
"drawer",
",",
"drawerItem",
",",
"v",
",",
"true",
")",
";",
"}",
"}",
")",
";",
"}",
"setStickyFooterSelection",
"(",
"drawer",
",",
"drawer",
".",
"mCurrentStickyFooterSelection",
",",
"false",
")",
";",
"}",
"}"
] |
small helper to rebuild the FooterView
@param drawer
|
[
"small",
"helper",
"to",
"rebuild",
"the",
"FooterView"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L257-L290
|
14,971
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.handleFooterView
|
public static void handleFooterView(DrawerBuilder drawer, View.OnClickListener onClickListener) {
Context ctx = drawer.mSliderLayout.getContext();
//use the StickyDrawerItems if set
if (drawer.mStickyDrawerItems != null && drawer.mStickyDrawerItems.size() > 0) {
drawer.mStickyFooterView = DrawerUtils.buildStickyDrawerItemFooter(ctx, drawer, onClickListener);
}
//sticky footer view
if (drawer.mStickyFooterView != null) {
//add the sticky footer view and align it to the bottom
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
drawer.mStickyFooterView.setId(R.id.material_drawer_sticky_footer);
drawer.mSliderLayout.addView(drawer.mStickyFooterView, layoutParams);
if ((drawer.mTranslucentNavigationBar || drawer.mFullscreen) && Build.VERSION.SDK_INT >= 19) {
drawer.mStickyFooterView.setPadding(0, 0, 0, UIUtils.getNavigationBarHeight(ctx));
}
//now align the recyclerView above the stickyFooterView ;)
RelativeLayout.LayoutParams layoutParamsListView = (RelativeLayout.LayoutParams) drawer.mRecyclerView.getLayoutParams();
layoutParamsListView.addRule(RelativeLayout.ABOVE, R.id.material_drawer_sticky_footer);
drawer.mRecyclerView.setLayoutParams(layoutParamsListView);
//handle shadow on top of the sticky footer
if (drawer.mStickyFooterShadow) {
drawer.mStickyFooterShadowView = new View(ctx);
drawer.mStickyFooterShadowView.setBackgroundResource(R.drawable.material_drawer_shadow_top);
drawer.mSliderLayout.addView(drawer.mStickyFooterShadowView, RelativeLayout.LayoutParams.MATCH_PARENT, ctx.getResources().getDimensionPixelSize(R.dimen.material_drawer_sticky_footer_elevation));
//now align the shadow below the stickyHeader ;)
RelativeLayout.LayoutParams lps = (RelativeLayout.LayoutParams) drawer.mStickyFooterShadowView.getLayoutParams();
lps.addRule(RelativeLayout.ABOVE, R.id.material_drawer_sticky_footer);
drawer.mStickyFooterShadowView.setLayoutParams(lps);
}
//remove the padding of the recyclerView again we have the footer below it
drawer.mRecyclerView.setPadding(drawer.mRecyclerView.getPaddingLeft(), drawer.mRecyclerView.getPaddingTop(), drawer.mRecyclerView.getPaddingRight(), ctx.getResources().getDimensionPixelSize(R.dimen.material_drawer_padding));
}
// set the footer (do this before the setAdapter because some devices will crash else
if (drawer.mFooterView != null) {
if (drawer.mRecyclerView == null) {
throw new RuntimeException("can't use a footerView without a recyclerView");
}
if (drawer.mFooterDivider) {
drawer.getFooterAdapter().add(new ContainerDrawerItem().withView(drawer.mFooterView).withViewPosition(ContainerDrawerItem.Position.BOTTOM));
} else {
drawer.getFooterAdapter().add(new ContainerDrawerItem().withView(drawer.mFooterView).withViewPosition(ContainerDrawerItem.Position.NONE));
}
}
}
|
java
|
public static void handleFooterView(DrawerBuilder drawer, View.OnClickListener onClickListener) {
Context ctx = drawer.mSliderLayout.getContext();
//use the StickyDrawerItems if set
if (drawer.mStickyDrawerItems != null && drawer.mStickyDrawerItems.size() > 0) {
drawer.mStickyFooterView = DrawerUtils.buildStickyDrawerItemFooter(ctx, drawer, onClickListener);
}
//sticky footer view
if (drawer.mStickyFooterView != null) {
//add the sticky footer view and align it to the bottom
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
drawer.mStickyFooterView.setId(R.id.material_drawer_sticky_footer);
drawer.mSliderLayout.addView(drawer.mStickyFooterView, layoutParams);
if ((drawer.mTranslucentNavigationBar || drawer.mFullscreen) && Build.VERSION.SDK_INT >= 19) {
drawer.mStickyFooterView.setPadding(0, 0, 0, UIUtils.getNavigationBarHeight(ctx));
}
//now align the recyclerView above the stickyFooterView ;)
RelativeLayout.LayoutParams layoutParamsListView = (RelativeLayout.LayoutParams) drawer.mRecyclerView.getLayoutParams();
layoutParamsListView.addRule(RelativeLayout.ABOVE, R.id.material_drawer_sticky_footer);
drawer.mRecyclerView.setLayoutParams(layoutParamsListView);
//handle shadow on top of the sticky footer
if (drawer.mStickyFooterShadow) {
drawer.mStickyFooterShadowView = new View(ctx);
drawer.mStickyFooterShadowView.setBackgroundResource(R.drawable.material_drawer_shadow_top);
drawer.mSliderLayout.addView(drawer.mStickyFooterShadowView, RelativeLayout.LayoutParams.MATCH_PARENT, ctx.getResources().getDimensionPixelSize(R.dimen.material_drawer_sticky_footer_elevation));
//now align the shadow below the stickyHeader ;)
RelativeLayout.LayoutParams lps = (RelativeLayout.LayoutParams) drawer.mStickyFooterShadowView.getLayoutParams();
lps.addRule(RelativeLayout.ABOVE, R.id.material_drawer_sticky_footer);
drawer.mStickyFooterShadowView.setLayoutParams(lps);
}
//remove the padding of the recyclerView again we have the footer below it
drawer.mRecyclerView.setPadding(drawer.mRecyclerView.getPaddingLeft(), drawer.mRecyclerView.getPaddingTop(), drawer.mRecyclerView.getPaddingRight(), ctx.getResources().getDimensionPixelSize(R.dimen.material_drawer_padding));
}
// set the footer (do this before the setAdapter because some devices will crash else
if (drawer.mFooterView != null) {
if (drawer.mRecyclerView == null) {
throw new RuntimeException("can't use a footerView without a recyclerView");
}
if (drawer.mFooterDivider) {
drawer.getFooterAdapter().add(new ContainerDrawerItem().withView(drawer.mFooterView).withViewPosition(ContainerDrawerItem.Position.BOTTOM));
} else {
drawer.getFooterAdapter().add(new ContainerDrawerItem().withView(drawer.mFooterView).withViewPosition(ContainerDrawerItem.Position.NONE));
}
}
}
|
[
"public",
"static",
"void",
"handleFooterView",
"(",
"DrawerBuilder",
"drawer",
",",
"View",
".",
"OnClickListener",
"onClickListener",
")",
"{",
"Context",
"ctx",
"=",
"drawer",
".",
"mSliderLayout",
".",
"getContext",
"(",
")",
";",
"//use the StickyDrawerItems if set",
"if",
"(",
"drawer",
".",
"mStickyDrawerItems",
"!=",
"null",
"&&",
"drawer",
".",
"mStickyDrawerItems",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"drawer",
".",
"mStickyFooterView",
"=",
"DrawerUtils",
".",
"buildStickyDrawerItemFooter",
"(",
"ctx",
",",
"drawer",
",",
"onClickListener",
")",
";",
"}",
"//sticky footer view",
"if",
"(",
"drawer",
".",
"mStickyFooterView",
"!=",
"null",
")",
"{",
"//add the sticky footer view and align it to the bottom",
"RelativeLayout",
".",
"LayoutParams",
"layoutParams",
"=",
"new",
"RelativeLayout",
".",
"LayoutParams",
"(",
"RelativeLayout",
".",
"LayoutParams",
".",
"MATCH_PARENT",
",",
"RelativeLayout",
".",
"LayoutParams",
".",
"WRAP_CONTENT",
")",
";",
"layoutParams",
".",
"addRule",
"(",
"RelativeLayout",
".",
"ALIGN_PARENT_BOTTOM",
",",
"1",
")",
";",
"drawer",
".",
"mStickyFooterView",
".",
"setId",
"(",
"R",
".",
"id",
".",
"material_drawer_sticky_footer",
")",
";",
"drawer",
".",
"mSliderLayout",
".",
"addView",
"(",
"drawer",
".",
"mStickyFooterView",
",",
"layoutParams",
")",
";",
"if",
"(",
"(",
"drawer",
".",
"mTranslucentNavigationBar",
"||",
"drawer",
".",
"mFullscreen",
")",
"&&",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"19",
")",
"{",
"drawer",
".",
"mStickyFooterView",
".",
"setPadding",
"(",
"0",
",",
"0",
",",
"0",
",",
"UIUtils",
".",
"getNavigationBarHeight",
"(",
"ctx",
")",
")",
";",
"}",
"//now align the recyclerView above the stickyFooterView ;)",
"RelativeLayout",
".",
"LayoutParams",
"layoutParamsListView",
"=",
"(",
"RelativeLayout",
".",
"LayoutParams",
")",
"drawer",
".",
"mRecyclerView",
".",
"getLayoutParams",
"(",
")",
";",
"layoutParamsListView",
".",
"addRule",
"(",
"RelativeLayout",
".",
"ABOVE",
",",
"R",
".",
"id",
".",
"material_drawer_sticky_footer",
")",
";",
"drawer",
".",
"mRecyclerView",
".",
"setLayoutParams",
"(",
"layoutParamsListView",
")",
";",
"//handle shadow on top of the sticky footer",
"if",
"(",
"drawer",
".",
"mStickyFooterShadow",
")",
"{",
"drawer",
".",
"mStickyFooterShadowView",
"=",
"new",
"View",
"(",
"ctx",
")",
";",
"drawer",
".",
"mStickyFooterShadowView",
".",
"setBackgroundResource",
"(",
"R",
".",
"drawable",
".",
"material_drawer_shadow_top",
")",
";",
"drawer",
".",
"mSliderLayout",
".",
"addView",
"(",
"drawer",
".",
"mStickyFooterShadowView",
",",
"RelativeLayout",
".",
"LayoutParams",
".",
"MATCH_PARENT",
",",
"ctx",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_sticky_footer_elevation",
")",
")",
";",
"//now align the shadow below the stickyHeader ;)",
"RelativeLayout",
".",
"LayoutParams",
"lps",
"=",
"(",
"RelativeLayout",
".",
"LayoutParams",
")",
"drawer",
".",
"mStickyFooterShadowView",
".",
"getLayoutParams",
"(",
")",
";",
"lps",
".",
"addRule",
"(",
"RelativeLayout",
".",
"ABOVE",
",",
"R",
".",
"id",
".",
"material_drawer_sticky_footer",
")",
";",
"drawer",
".",
"mStickyFooterShadowView",
".",
"setLayoutParams",
"(",
"lps",
")",
";",
"}",
"//remove the padding of the recyclerView again we have the footer below it",
"drawer",
".",
"mRecyclerView",
".",
"setPadding",
"(",
"drawer",
".",
"mRecyclerView",
".",
"getPaddingLeft",
"(",
")",
",",
"drawer",
".",
"mRecyclerView",
".",
"getPaddingTop",
"(",
")",
",",
"drawer",
".",
"mRecyclerView",
".",
"getPaddingRight",
"(",
")",
",",
"ctx",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_padding",
")",
")",
";",
"}",
"// set the footer (do this before the setAdapter because some devices will crash else",
"if",
"(",
"drawer",
".",
"mFooterView",
"!=",
"null",
")",
"{",
"if",
"(",
"drawer",
".",
"mRecyclerView",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"can't use a footerView without a recyclerView\"",
")",
";",
"}",
"if",
"(",
"drawer",
".",
"mFooterDivider",
")",
"{",
"drawer",
".",
"getFooterAdapter",
"(",
")",
".",
"add",
"(",
"new",
"ContainerDrawerItem",
"(",
")",
".",
"withView",
"(",
"drawer",
".",
"mFooterView",
")",
".",
"withViewPosition",
"(",
"ContainerDrawerItem",
".",
"Position",
".",
"BOTTOM",
")",
")",
";",
"}",
"else",
"{",
"drawer",
".",
"getFooterAdapter",
"(",
")",
".",
"add",
"(",
"new",
"ContainerDrawerItem",
"(",
")",
".",
"withView",
"(",
"drawer",
".",
"mFooterView",
")",
".",
"withViewPosition",
"(",
"ContainerDrawerItem",
".",
"Position",
".",
"NONE",
")",
")",
";",
"}",
"}",
"}"
] |
helper method to handle the footerView
@param drawer
|
[
"helper",
"method",
"to",
"handle",
"the",
"footerView"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L297-L349
|
14,972
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.buildStickyDrawerItemFooter
|
public static ViewGroup buildStickyDrawerItemFooter(Context ctx, DrawerBuilder drawer, View.OnClickListener onClickListener) {
//create the container view
final LinearLayout linearLayout = new LinearLayout(ctx);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
//set the background color to the drawer background color (if it has alpha the shadow won't be visible)
linearLayout.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, R.attr.material_drawer_background, R.color.material_drawer_background));
//create the divider
if (drawer.mStickyFooterDivider) {
addStickyFooterDivider(ctx, linearLayout);
}
fillStickyDrawerItemFooter(drawer, linearLayout, onClickListener);
return linearLayout;
}
|
java
|
public static ViewGroup buildStickyDrawerItemFooter(Context ctx, DrawerBuilder drawer, View.OnClickListener onClickListener) {
//create the container view
final LinearLayout linearLayout = new LinearLayout(ctx);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
linearLayout.setOrientation(LinearLayout.VERTICAL);
//set the background color to the drawer background color (if it has alpha the shadow won't be visible)
linearLayout.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, R.attr.material_drawer_background, R.color.material_drawer_background));
//create the divider
if (drawer.mStickyFooterDivider) {
addStickyFooterDivider(ctx, linearLayout);
}
fillStickyDrawerItemFooter(drawer, linearLayout, onClickListener);
return linearLayout;
}
|
[
"public",
"static",
"ViewGroup",
"buildStickyDrawerItemFooter",
"(",
"Context",
"ctx",
",",
"DrawerBuilder",
"drawer",
",",
"View",
".",
"OnClickListener",
"onClickListener",
")",
"{",
"//create the container view",
"final",
"LinearLayout",
"linearLayout",
"=",
"new",
"LinearLayout",
"(",
"ctx",
")",
";",
"linearLayout",
".",
"setLayoutParams",
"(",
"new",
"LinearLayout",
".",
"LayoutParams",
"(",
"ViewGroup",
".",
"LayoutParams",
".",
"MATCH_PARENT",
",",
"ViewGroup",
".",
"LayoutParams",
".",
"WRAP_CONTENT",
")",
")",
";",
"linearLayout",
".",
"setOrientation",
"(",
"LinearLayout",
".",
"VERTICAL",
")",
";",
"//set the background color to the drawer background color (if it has alpha the shadow won't be visible)",
"linearLayout",
".",
"setBackgroundColor",
"(",
"UIUtils",
".",
"getThemeColorFromAttrOrRes",
"(",
"ctx",
",",
"R",
".",
"attr",
".",
"material_drawer_background",
",",
"R",
".",
"color",
".",
"material_drawer_background",
")",
")",
";",
"//create the divider",
"if",
"(",
"drawer",
".",
"mStickyFooterDivider",
")",
"{",
"addStickyFooterDivider",
"(",
"ctx",
",",
"linearLayout",
")",
";",
"}",
"fillStickyDrawerItemFooter",
"(",
"drawer",
",",
"linearLayout",
",",
"onClickListener",
")",
";",
"return",
"linearLayout",
";",
"}"
] |
build the sticky footer item view
@return
|
[
"build",
"the",
"sticky",
"footer",
"item",
"view"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L357-L373
|
14,973
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.addStickyFooterDivider
|
private static void addStickyFooterDivider(Context ctx, ViewGroup footerView) {
LinearLayout divider = new LinearLayout(ctx);
LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
divider.setMinimumHeight((int) UIUtils.convertDpToPixel(1, ctx));
divider.setOrientation(LinearLayout.VERTICAL);
divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, R.attr.material_drawer_divider, R.color.material_drawer_divider));
footerView.addView(divider, dividerParams);
}
|
java
|
private static void addStickyFooterDivider(Context ctx, ViewGroup footerView) {
LinearLayout divider = new LinearLayout(ctx);
LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
divider.setMinimumHeight((int) UIUtils.convertDpToPixel(1, ctx));
divider.setOrientation(LinearLayout.VERTICAL);
divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ctx, R.attr.material_drawer_divider, R.color.material_drawer_divider));
footerView.addView(divider, dividerParams);
}
|
[
"private",
"static",
"void",
"addStickyFooterDivider",
"(",
"Context",
"ctx",
",",
"ViewGroup",
"footerView",
")",
"{",
"LinearLayout",
"divider",
"=",
"new",
"LinearLayout",
"(",
"ctx",
")",
";",
"LinearLayout",
".",
"LayoutParams",
"dividerParams",
"=",
"new",
"LinearLayout",
".",
"LayoutParams",
"(",
"ViewGroup",
".",
"LayoutParams",
".",
"MATCH_PARENT",
",",
"ViewGroup",
".",
"LayoutParams",
".",
"WRAP_CONTENT",
")",
";",
"divider",
".",
"setMinimumHeight",
"(",
"(",
"int",
")",
"UIUtils",
".",
"convertDpToPixel",
"(",
"1",
",",
"ctx",
")",
")",
";",
"divider",
".",
"setOrientation",
"(",
"LinearLayout",
".",
"VERTICAL",
")",
";",
"divider",
".",
"setBackgroundColor",
"(",
"UIUtils",
".",
"getThemeColorFromAttrOrRes",
"(",
"ctx",
",",
"R",
".",
"attr",
".",
"material_drawer_divider",
",",
"R",
".",
"color",
".",
"material_drawer_divider",
")",
")",
";",
"footerView",
".",
"addView",
"(",
"divider",
",",
"dividerParams",
")",
";",
"}"
] |
adds the shadow to the stickyFooter
@param ctx
@param footerView
|
[
"adds",
"the",
"shadow",
"to",
"the",
"stickyFooter"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L381-L388
|
14,974
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.fillStickyDrawerItemFooter
|
public static void fillStickyDrawerItemFooter(DrawerBuilder drawer, ViewGroup container, View.OnClickListener onClickListener) {
//add all drawer items
for (IDrawerItem drawerItem : drawer.mStickyDrawerItems) {
View view = drawerItem.generateView(container.getContext(), container);
view.setTag(drawerItem);
if (drawerItem.isEnabled()) {
//UIUtils.setBackground(view, UIUtils.getSelectableBackground(container.getContext(), selected_color, drawerItem.isSelectedBackgroundAnimated()));
view.setOnClickListener(onClickListener);
}
container.addView(view);
//for android API 17 --> Padding not applied via xml
DrawerUIUtils.setDrawerVerticalPadding(view);
}
//and really. don't ask about this. it won't set the padding if i don't set the padding for the container
container.setPadding(0, 0, 0, 0);
}
|
java
|
public static void fillStickyDrawerItemFooter(DrawerBuilder drawer, ViewGroup container, View.OnClickListener onClickListener) {
//add all drawer items
for (IDrawerItem drawerItem : drawer.mStickyDrawerItems) {
View view = drawerItem.generateView(container.getContext(), container);
view.setTag(drawerItem);
if (drawerItem.isEnabled()) {
//UIUtils.setBackground(view, UIUtils.getSelectableBackground(container.getContext(), selected_color, drawerItem.isSelectedBackgroundAnimated()));
view.setOnClickListener(onClickListener);
}
container.addView(view);
//for android API 17 --> Padding not applied via xml
DrawerUIUtils.setDrawerVerticalPadding(view);
}
//and really. don't ask about this. it won't set the padding if i don't set the padding for the container
container.setPadding(0, 0, 0, 0);
}
|
[
"public",
"static",
"void",
"fillStickyDrawerItemFooter",
"(",
"DrawerBuilder",
"drawer",
",",
"ViewGroup",
"container",
",",
"View",
".",
"OnClickListener",
"onClickListener",
")",
"{",
"//add all drawer items",
"for",
"(",
"IDrawerItem",
"drawerItem",
":",
"drawer",
".",
"mStickyDrawerItems",
")",
"{",
"View",
"view",
"=",
"drawerItem",
".",
"generateView",
"(",
"container",
".",
"getContext",
"(",
")",
",",
"container",
")",
";",
"view",
".",
"setTag",
"(",
"drawerItem",
")",
";",
"if",
"(",
"drawerItem",
".",
"isEnabled",
"(",
")",
")",
"{",
"//UIUtils.setBackground(view, UIUtils.getSelectableBackground(container.getContext(), selected_color, drawerItem.isSelectedBackgroundAnimated()));",
"view",
".",
"setOnClickListener",
"(",
"onClickListener",
")",
";",
"}",
"container",
".",
"addView",
"(",
"view",
")",
";",
"//for android API 17 --> Padding not applied via xml",
"DrawerUIUtils",
".",
"setDrawerVerticalPadding",
"(",
"view",
")",
";",
"}",
"//and really. don't ask about this. it won't set the padding if i don't set the padding for the container",
"container",
".",
"setPadding",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"}"
] |
helper method to fill the sticky footer with it's elements
@param drawer
@param container
@param onClickListener
|
[
"helper",
"method",
"to",
"fill",
"the",
"sticky",
"footer",
"with",
"it",
"s",
"elements"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L397-L415
|
14,975
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java
|
DrawerUtils.processDrawerLayoutParams
|
public static DrawerLayout.LayoutParams processDrawerLayoutParams(DrawerBuilder drawer, DrawerLayout.LayoutParams params) {
if (params != null) {
if (drawer.mDrawerGravity != null && (drawer.mDrawerGravity == Gravity.RIGHT || drawer.mDrawerGravity == Gravity.END)) {
params.rightMargin = 0;
if (Build.VERSION.SDK_INT >= 17) {
params.setMarginEnd(0);
}
params.leftMargin = drawer.mActivity.getResources().getDimensionPixelSize(R.dimen.material_drawer_margin);
if (Build.VERSION.SDK_INT >= 17) {
params.setMarginEnd(drawer.mActivity.getResources().getDimensionPixelSize(R.dimen.material_drawer_margin));
}
}
if (drawer.mDrawerWidth > -1) {
params.width = drawer.mDrawerWidth;
} else {
params.width = DrawerUIUtils.getOptimalDrawerWidth(drawer.mActivity);
}
}
return params;
}
|
java
|
public static DrawerLayout.LayoutParams processDrawerLayoutParams(DrawerBuilder drawer, DrawerLayout.LayoutParams params) {
if (params != null) {
if (drawer.mDrawerGravity != null && (drawer.mDrawerGravity == Gravity.RIGHT || drawer.mDrawerGravity == Gravity.END)) {
params.rightMargin = 0;
if (Build.VERSION.SDK_INT >= 17) {
params.setMarginEnd(0);
}
params.leftMargin = drawer.mActivity.getResources().getDimensionPixelSize(R.dimen.material_drawer_margin);
if (Build.VERSION.SDK_INT >= 17) {
params.setMarginEnd(drawer.mActivity.getResources().getDimensionPixelSize(R.dimen.material_drawer_margin));
}
}
if (drawer.mDrawerWidth > -1) {
params.width = drawer.mDrawerWidth;
} else {
params.width = DrawerUIUtils.getOptimalDrawerWidth(drawer.mActivity);
}
}
return params;
}
|
[
"public",
"static",
"DrawerLayout",
".",
"LayoutParams",
"processDrawerLayoutParams",
"(",
"DrawerBuilder",
"drawer",
",",
"DrawerLayout",
".",
"LayoutParams",
"params",
")",
"{",
"if",
"(",
"params",
"!=",
"null",
")",
"{",
"if",
"(",
"drawer",
".",
"mDrawerGravity",
"!=",
"null",
"&&",
"(",
"drawer",
".",
"mDrawerGravity",
"==",
"Gravity",
".",
"RIGHT",
"||",
"drawer",
".",
"mDrawerGravity",
"==",
"Gravity",
".",
"END",
")",
")",
"{",
"params",
".",
"rightMargin",
"=",
"0",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"17",
")",
"{",
"params",
".",
"setMarginEnd",
"(",
"0",
")",
";",
"}",
"params",
".",
"leftMargin",
"=",
"drawer",
".",
"mActivity",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_margin",
")",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"17",
")",
"{",
"params",
".",
"setMarginEnd",
"(",
"drawer",
".",
"mActivity",
".",
"getResources",
"(",
")",
".",
"getDimensionPixelSize",
"(",
"R",
".",
"dimen",
".",
"material_drawer_margin",
")",
")",
";",
"}",
"}",
"if",
"(",
"drawer",
".",
"mDrawerWidth",
">",
"-",
"1",
")",
"{",
"params",
".",
"width",
"=",
"drawer",
".",
"mDrawerWidth",
";",
"}",
"else",
"{",
"params",
".",
"width",
"=",
"DrawerUIUtils",
".",
"getOptimalDrawerWidth",
"(",
"drawer",
".",
"mActivity",
")",
";",
"}",
"}",
"return",
"params",
";",
"}"
] |
helper to extend the layoutParams of the drawer
@param params
@return
|
[
"helper",
"to",
"extend",
"the",
"layoutParams",
"of",
"the",
"drawer"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/DrawerUtils.java#L424-L446
|
14,976
|
mikepenz/MaterialDrawer
|
library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java
|
KeyboardUtil.hideKeyboard
|
public static void hideKeyboard(Activity act) {
if (act != null && act.getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
}
}
|
java
|
public static void hideKeyboard(Activity act) {
if (act != null && act.getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
}
}
|
[
"public",
"static",
"void",
"hideKeyboard",
"(",
"Activity",
"act",
")",
"{",
"if",
"(",
"act",
"!=",
"null",
"&&",
"act",
".",
"getCurrentFocus",
"(",
")",
"!=",
"null",
")",
"{",
"InputMethodManager",
"inputMethodManager",
"=",
"(",
"InputMethodManager",
")",
"act",
".",
"getSystemService",
"(",
"Activity",
".",
"INPUT_METHOD_SERVICE",
")",
";",
"inputMethodManager",
".",
"hideSoftInputFromWindow",
"(",
"act",
".",
"getCurrentFocus",
"(",
")",
".",
"getWindowToken",
"(",
")",
",",
"0",
")",
";",
"}",
"}"
] |
Helper to hide the keyboard
@param act
|
[
"Helper",
"to",
"hide",
"the",
"keyboard"
] |
f4fb31635767edead0a01cee7b7588942b89d8d9
|
https://github.com/mikepenz/MaterialDrawer/blob/f4fb31635767edead0a01cee7b7588942b89d8d9/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java#L97-L102
|
14,977
|
cucumber/cucumber-jvm
|
core/src/main/java/cucumber/api/cli/Main.java
|
Main.run
|
public static byte run(String[] argv, ClassLoader classLoader) {
final Runtime runtime = Runtime.builder()
.withArgs(argv)
.withClassLoader(classLoader)
.build();
runtime.run();
return runtime.exitStatus();
}
|
java
|
public static byte run(String[] argv, ClassLoader classLoader) {
final Runtime runtime = Runtime.builder()
.withArgs(argv)
.withClassLoader(classLoader)
.build();
runtime.run();
return runtime.exitStatus();
}
|
[
"public",
"static",
"byte",
"run",
"(",
"String",
"[",
"]",
"argv",
",",
"ClassLoader",
"classLoader",
")",
"{",
"final",
"Runtime",
"runtime",
"=",
"Runtime",
".",
"builder",
"(",
")",
".",
"withArgs",
"(",
"argv",
")",
".",
"withClassLoader",
"(",
"classLoader",
")",
".",
"build",
"(",
")",
";",
"runtime",
".",
"run",
"(",
")",
";",
"return",
"runtime",
".",
"exitStatus",
"(",
")",
";",
"}"
] |
Launches the Cucumber-JVM command line.
@param argv runtime options. See details in the {@code cucumber.api.cli.Usage.txt} resource.
@param classLoader classloader used to load the runtime
@return 0 if execution was successful, 1 if it was not (test failures)
|
[
"Launches",
"the",
"Cucumber",
"-",
"JVM",
"command",
"line",
"."
] |
437bb3a1f1d91b56f44059c835765b395eefc777
|
https://github.com/cucumber/cucumber-jvm/blob/437bb3a1f1d91b56f44059c835765b395eefc777/core/src/main/java/cucumber/api/cli/Main.java#L19-L28
|
14,978
|
cucumber/cucumber-jvm
|
core/src/main/java/cucumber/runtime/formatter/Plugins.java
|
Plugins.pluginProxy
|
private <T> T pluginProxy(final Class<T> type) {
Object proxy = Proxy.newProxyInstance(classLoader, new Class<?>[]{type}, new InvocationHandler() {
@Override
public Object invoke(Object target, Method method, Object[] args) throws Throwable {
for (Object plugin : getPlugins()) {
if (type.isInstance(plugin)) {
try {
Utils.invoke(plugin, method, 0, args);
} catch (Throwable t) {
if (!method.getName().equals("startOfScenarioLifeCycle") && !method.getName().equals("endOfScenarioLifeCycle")) {
// IntelliJ has its own formatter which doesn't yet implement these methods.
throw t;
}
}
}
}
return null;
}
});
return type.cast(proxy);
}
|
java
|
private <T> T pluginProxy(final Class<T> type) {
Object proxy = Proxy.newProxyInstance(classLoader, new Class<?>[]{type}, new InvocationHandler() {
@Override
public Object invoke(Object target, Method method, Object[] args) throws Throwable {
for (Object plugin : getPlugins()) {
if (type.isInstance(plugin)) {
try {
Utils.invoke(plugin, method, 0, args);
} catch (Throwable t) {
if (!method.getName().equals("startOfScenarioLifeCycle") && !method.getName().equals("endOfScenarioLifeCycle")) {
// IntelliJ has its own formatter which doesn't yet implement these methods.
throw t;
}
}
}
}
return null;
}
});
return type.cast(proxy);
}
|
[
"private",
"<",
"T",
">",
"T",
"pluginProxy",
"(",
"final",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"Object",
"proxy",
"=",
"Proxy",
".",
"newProxyInstance",
"(",
"classLoader",
",",
"new",
"Class",
"<",
"?",
">",
"[",
"]",
"{",
"type",
"}",
",",
"new",
"InvocationHandler",
"(",
")",
"{",
"@",
"Override",
"public",
"Object",
"invoke",
"(",
"Object",
"target",
",",
"Method",
"method",
",",
"Object",
"[",
"]",
"args",
")",
"throws",
"Throwable",
"{",
"for",
"(",
"Object",
"plugin",
":",
"getPlugins",
"(",
")",
")",
"{",
"if",
"(",
"type",
".",
"isInstance",
"(",
"plugin",
")",
")",
"{",
"try",
"{",
"Utils",
".",
"invoke",
"(",
"plugin",
",",
"method",
",",
"0",
",",
"args",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"if",
"(",
"!",
"method",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"startOfScenarioLifeCycle\"",
")",
"&&",
"!",
"method",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"\"endOfScenarioLifeCycle\"",
")",
")",
"{",
"// IntelliJ has its own formatter which doesn't yet implement these methods.",
"throw",
"t",
";",
"}",
"}",
"}",
"}",
"return",
"null",
";",
"}",
"}",
")",
";",
"return",
"type",
".",
"cast",
"(",
"proxy",
")",
";",
"}"
] |
Creates a dynamic proxy that multiplexes method invocations to all plugins of the same type.
@param type proxy type
@param <T> generic proxy type
@return a proxy
|
[
"Creates",
"a",
"dynamic",
"proxy",
"that",
"multiplexes",
"method",
"invocations",
"to",
"all",
"plugins",
"of",
"the",
"same",
"type",
"."
] |
437bb3a1f1d91b56f44059c835765b395eefc777
|
https://github.com/cucumber/cucumber-jvm/blob/437bb3a1f1d91b56f44059c835765b395eefc777/core/src/main/java/cucumber/runtime/formatter/Plugins.java#L124-L144
|
14,979
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedJsonStringEncoder.java
|
BackportedJsonStringEncoder.getInstance
|
public static BackportedJsonStringEncoder getInstance() {
SoftReference<BackportedJsonStringEncoder> ref = _threadEncoder.get();
BackportedJsonStringEncoder enc = (ref == null) ? null : ref.get();
if (enc == null) {
enc = new BackportedJsonStringEncoder();
_threadEncoder.set(new SoftReference<BackportedJsonStringEncoder>(enc));
}
return enc;
}
|
java
|
public static BackportedJsonStringEncoder getInstance() {
SoftReference<BackportedJsonStringEncoder> ref = _threadEncoder.get();
BackportedJsonStringEncoder enc = (ref == null) ? null : ref.get();
if (enc == null) {
enc = new BackportedJsonStringEncoder();
_threadEncoder.set(new SoftReference<BackportedJsonStringEncoder>(enc));
}
return enc;
}
|
[
"public",
"static",
"BackportedJsonStringEncoder",
"getInstance",
"(",
")",
"{",
"SoftReference",
"<",
"BackportedJsonStringEncoder",
">",
"ref",
"=",
"_threadEncoder",
".",
"get",
"(",
")",
";",
"BackportedJsonStringEncoder",
"enc",
"=",
"(",
"ref",
"==",
"null",
")",
"?",
"null",
":",
"ref",
".",
"get",
"(",
")",
";",
"if",
"(",
"enc",
"==",
"null",
")",
"{",
"enc",
"=",
"new",
"BackportedJsonStringEncoder",
"(",
")",
";",
"_threadEncoder",
".",
"set",
"(",
"new",
"SoftReference",
"<",
"BackportedJsonStringEncoder",
">",
"(",
"enc",
")",
")",
";",
"}",
"return",
"enc",
";",
"}"
] |
Factory method for getting an instance; this is either recycled per-thread instance,
or a newly constructed one.
|
[
"Factory",
"method",
"for",
"getting",
"an",
"instance",
";",
"this",
"is",
"either",
"recycled",
"per",
"-",
"thread",
"instance",
"or",
"a",
"newly",
"constructed",
"one",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedJsonStringEncoder.java#L99-L108
|
14,980
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedJsonStringEncoder.java
|
BackportedJsonStringEncoder.quoteAsString
|
public char[] quoteAsString(String input) {
TextBuffer textBuffer = _textBuffer;
if (textBuffer == null) {
// no allocator; can add if we must, shouldn't need to
_textBuffer = textBuffer = new TextBuffer(null);
}
char[] outputBuffer = textBuffer.emptyAndGetCurrentSegment();
final int[] escCodes = sOutputEscapes128;
final int escCodeCount = escCodes.length;
int inPtr = 0;
final int inputLen = input.length();
int outPtr = 0;
outer_loop: while (inPtr < inputLen) {
tight_loop: while (true) {
char c = input.charAt(inPtr);
if (c < escCodeCount && escCodes[c] != 0) {
break tight_loop;
}
if (outPtr >= outputBuffer.length) {
outputBuffer = textBuffer.finishCurrentSegment();
outPtr = 0;
}
outputBuffer[outPtr++] = c;
if (++inPtr >= inputLen) {
break outer_loop;
}
}
// something to escape; 2 or 6-char variant?
int escCode = escCodes[input.charAt(inPtr++)];
int length = _appendSingleEscape(escCode, _quoteBuffer);
if ((outPtr + length) > outputBuffer.length) {
int first = outputBuffer.length - outPtr;
if (first > 0) {
System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, first);
}
outputBuffer = textBuffer.finishCurrentSegment();
int second = length - first;
System.arraycopy(_quoteBuffer, first, outputBuffer, outPtr, second);
outPtr += second;
}
else {
System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, length);
outPtr += length;
}
}
textBuffer.setCurrentLength(outPtr);
return textBuffer.contentsAsArray();
}
|
java
|
public char[] quoteAsString(String input) {
TextBuffer textBuffer = _textBuffer;
if (textBuffer == null) {
// no allocator; can add if we must, shouldn't need to
_textBuffer = textBuffer = new TextBuffer(null);
}
char[] outputBuffer = textBuffer.emptyAndGetCurrentSegment();
final int[] escCodes = sOutputEscapes128;
final int escCodeCount = escCodes.length;
int inPtr = 0;
final int inputLen = input.length();
int outPtr = 0;
outer_loop: while (inPtr < inputLen) {
tight_loop: while (true) {
char c = input.charAt(inPtr);
if (c < escCodeCount && escCodes[c] != 0) {
break tight_loop;
}
if (outPtr >= outputBuffer.length) {
outputBuffer = textBuffer.finishCurrentSegment();
outPtr = 0;
}
outputBuffer[outPtr++] = c;
if (++inPtr >= inputLen) {
break outer_loop;
}
}
// something to escape; 2 or 6-char variant?
int escCode = escCodes[input.charAt(inPtr++)];
int length = _appendSingleEscape(escCode, _quoteBuffer);
if ((outPtr + length) > outputBuffer.length) {
int first = outputBuffer.length - outPtr;
if (first > 0) {
System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, first);
}
outputBuffer = textBuffer.finishCurrentSegment();
int second = length - first;
System.arraycopy(_quoteBuffer, first, outputBuffer, outPtr, second);
outPtr += second;
}
else {
System.arraycopy(_quoteBuffer, 0, outputBuffer, outPtr, length);
outPtr += length;
}
}
textBuffer.setCurrentLength(outPtr);
return textBuffer.contentsAsArray();
}
|
[
"public",
"char",
"[",
"]",
"quoteAsString",
"(",
"String",
"input",
")",
"{",
"TextBuffer",
"textBuffer",
"=",
"_textBuffer",
";",
"if",
"(",
"textBuffer",
"==",
"null",
")",
"{",
"// no allocator; can add if we must, shouldn't need to",
"_textBuffer",
"=",
"textBuffer",
"=",
"new",
"TextBuffer",
"(",
"null",
")",
";",
"}",
"char",
"[",
"]",
"outputBuffer",
"=",
"textBuffer",
".",
"emptyAndGetCurrentSegment",
"(",
")",
";",
"final",
"int",
"[",
"]",
"escCodes",
"=",
"sOutputEscapes128",
";",
"final",
"int",
"escCodeCount",
"=",
"escCodes",
".",
"length",
";",
"int",
"inPtr",
"=",
"0",
";",
"final",
"int",
"inputLen",
"=",
"input",
".",
"length",
"(",
")",
";",
"int",
"outPtr",
"=",
"0",
";",
"outer_loop",
":",
"while",
"(",
"inPtr",
"<",
"inputLen",
")",
"{",
"tight_loop",
":",
"while",
"(",
"true",
")",
"{",
"char",
"c",
"=",
"input",
".",
"charAt",
"(",
"inPtr",
")",
";",
"if",
"(",
"c",
"<",
"escCodeCount",
"&&",
"escCodes",
"[",
"c",
"]",
"!=",
"0",
")",
"{",
"break",
"tight_loop",
";",
"}",
"if",
"(",
"outPtr",
">=",
"outputBuffer",
".",
"length",
")",
"{",
"outputBuffer",
"=",
"textBuffer",
".",
"finishCurrentSegment",
"(",
")",
";",
"outPtr",
"=",
"0",
";",
"}",
"outputBuffer",
"[",
"outPtr",
"++",
"]",
"=",
"c",
";",
"if",
"(",
"++",
"inPtr",
">=",
"inputLen",
")",
"{",
"break",
"outer_loop",
";",
"}",
"}",
"// something to escape; 2 or 6-char variant?",
"int",
"escCode",
"=",
"escCodes",
"[",
"input",
".",
"charAt",
"(",
"inPtr",
"++",
")",
"]",
";",
"int",
"length",
"=",
"_appendSingleEscape",
"(",
"escCode",
",",
"_quoteBuffer",
")",
";",
"if",
"(",
"(",
"outPtr",
"+",
"length",
")",
">",
"outputBuffer",
".",
"length",
")",
"{",
"int",
"first",
"=",
"outputBuffer",
".",
"length",
"-",
"outPtr",
";",
"if",
"(",
"first",
">",
"0",
")",
"{",
"System",
".",
"arraycopy",
"(",
"_quoteBuffer",
",",
"0",
",",
"outputBuffer",
",",
"outPtr",
",",
"first",
")",
";",
"}",
"outputBuffer",
"=",
"textBuffer",
".",
"finishCurrentSegment",
"(",
")",
";",
"int",
"second",
"=",
"length",
"-",
"first",
";",
"System",
".",
"arraycopy",
"(",
"_quoteBuffer",
",",
"first",
",",
"outputBuffer",
",",
"outPtr",
",",
"second",
")",
";",
"outPtr",
"+=",
"second",
";",
"}",
"else",
"{",
"System",
".",
"arraycopy",
"(",
"_quoteBuffer",
",",
"0",
",",
"outputBuffer",
",",
"outPtr",
",",
"length",
")",
";",
"outPtr",
"+=",
"length",
";",
"}",
"}",
"textBuffer",
".",
"setCurrentLength",
"(",
"outPtr",
")",
";",
"return",
"textBuffer",
".",
"contentsAsArray",
"(",
")",
";",
"}"
] |
Method that will quote text contents using JSON standard quoting,
and return results as a character array
|
[
"Method",
"that",
"will",
"quote",
"text",
"contents",
"using",
"JSON",
"standard",
"quoting",
"and",
"return",
"results",
"as",
"a",
"character",
"array"
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedJsonStringEncoder.java#L115-L164
|
14,981
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/auth/bearer/EsApiKeyAuthScheme.java
|
EsApiKeyAuthScheme.authenticate
|
private String authenticate(Credentials credentials) throws AuthenticationException {
if (!(credentials instanceof EsApiKeyCredentials)) {
throw new AuthenticationException("Incorrect credentials type provided. Expected [" + EsApiKeyCredentials.class.getName()
+ "] but got [" + credentials.getClass().getName() + "]");
}
EsApiKeyCredentials esApiKeyCredentials = ((EsApiKeyCredentials) credentials);
String authString = null;
if (esApiKeyCredentials.getToken() != null && StringUtils.hasText(esApiKeyCredentials.getToken().getName())) {
EsToken token = esApiKeyCredentials.getToken();
String keyComponents = token.getId() + ":" + token.getApiKey();
byte[] base64Encoded = Base64.encodeBase64(keyComponents.getBytes(StringUtils.UTF_8));
String tokenText = new String(base64Encoded, StringUtils.UTF_8);
authString = EsHadoopAuthPolicies.APIKEY + " " + tokenText;
}
return authString;
}
|
java
|
private String authenticate(Credentials credentials) throws AuthenticationException {
if (!(credentials instanceof EsApiKeyCredentials)) {
throw new AuthenticationException("Incorrect credentials type provided. Expected [" + EsApiKeyCredentials.class.getName()
+ "] but got [" + credentials.getClass().getName() + "]");
}
EsApiKeyCredentials esApiKeyCredentials = ((EsApiKeyCredentials) credentials);
String authString = null;
if (esApiKeyCredentials.getToken() != null && StringUtils.hasText(esApiKeyCredentials.getToken().getName())) {
EsToken token = esApiKeyCredentials.getToken();
String keyComponents = token.getId() + ":" + token.getApiKey();
byte[] base64Encoded = Base64.encodeBase64(keyComponents.getBytes(StringUtils.UTF_8));
String tokenText = new String(base64Encoded, StringUtils.UTF_8);
authString = EsHadoopAuthPolicies.APIKEY + " " + tokenText;
}
return authString;
}
|
[
"private",
"String",
"authenticate",
"(",
"Credentials",
"credentials",
")",
"throws",
"AuthenticationException",
"{",
"if",
"(",
"!",
"(",
"credentials",
"instanceof",
"EsApiKeyCredentials",
")",
")",
"{",
"throw",
"new",
"AuthenticationException",
"(",
"\"Incorrect credentials type provided. Expected [\"",
"+",
"EsApiKeyCredentials",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\"] but got [\"",
"+",
"credentials",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\"]\"",
")",
";",
"}",
"EsApiKeyCredentials",
"esApiKeyCredentials",
"=",
"(",
"(",
"EsApiKeyCredentials",
")",
"credentials",
")",
";",
"String",
"authString",
"=",
"null",
";",
"if",
"(",
"esApiKeyCredentials",
".",
"getToken",
"(",
")",
"!=",
"null",
"&&",
"StringUtils",
".",
"hasText",
"(",
"esApiKeyCredentials",
".",
"getToken",
"(",
")",
".",
"getName",
"(",
")",
")",
")",
"{",
"EsToken",
"token",
"=",
"esApiKeyCredentials",
".",
"getToken",
"(",
")",
";",
"String",
"keyComponents",
"=",
"token",
".",
"getId",
"(",
")",
"+",
"\":\"",
"+",
"token",
".",
"getApiKey",
"(",
")",
";",
"byte",
"[",
"]",
"base64Encoded",
"=",
"Base64",
".",
"encodeBase64",
"(",
"keyComponents",
".",
"getBytes",
"(",
"StringUtils",
".",
"UTF_8",
")",
")",
";",
"String",
"tokenText",
"=",
"new",
"String",
"(",
"base64Encoded",
",",
"StringUtils",
".",
"UTF_8",
")",
";",
"authString",
"=",
"EsHadoopAuthPolicies",
".",
"APIKEY",
"+",
"\" \"",
"+",
"tokenText",
";",
"}",
"return",
"authString",
";",
"}"
] |
Implementation method for authentication
|
[
"Implementation",
"method",
"for",
"authentication"
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/auth/bearer/EsApiKeyAuthScheme.java#L73-L91
|
14,982
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java
|
PooledHttpTransportFactory.assertCorrectJobId
|
private void assertCorrectJobId(Settings settings) {
SettingsUtils.ensureJobTransportPoolingKey(settings);
String requestingJobKey = SettingsUtils.getJobTransportPoolingKey(settings);
if (!jobKey.equals(requestingJobKey)) {
throw new EsHadoopIllegalArgumentException("Settings object passed does not have the same job " +
"pooling key property as when this pool was created. Job key requested was [" +
requestingJobKey + "] but this pool services job [" + jobKey + "]. This could be a " +
"different job incorrectly polluting the TransportPool. Bailing out...");
}
}
|
java
|
private void assertCorrectJobId(Settings settings) {
SettingsUtils.ensureJobTransportPoolingKey(settings);
String requestingJobKey = SettingsUtils.getJobTransportPoolingKey(settings);
if (!jobKey.equals(requestingJobKey)) {
throw new EsHadoopIllegalArgumentException("Settings object passed does not have the same job " +
"pooling key property as when this pool was created. Job key requested was [" +
requestingJobKey + "] but this pool services job [" + jobKey + "]. This could be a " +
"different job incorrectly polluting the TransportPool. Bailing out...");
}
}
|
[
"private",
"void",
"assertCorrectJobId",
"(",
"Settings",
"settings",
")",
"{",
"SettingsUtils",
".",
"ensureJobTransportPoolingKey",
"(",
"settings",
")",
";",
"String",
"requestingJobKey",
"=",
"SettingsUtils",
".",
"getJobTransportPoolingKey",
"(",
"settings",
")",
";",
"if",
"(",
"!",
"jobKey",
".",
"equals",
"(",
"requestingJobKey",
")",
")",
"{",
"throw",
"new",
"EsHadoopIllegalArgumentException",
"(",
"\"Settings object passed does not have the same job \"",
"+",
"\"pooling key property as when this pool was created. Job key requested was [\"",
"+",
"requestingJobKey",
"+",
"\"] but this pool services job [\"",
"+",
"jobKey",
"+",
"\"]. This could be a \"",
"+",
"\"different job incorrectly polluting the TransportPool. Bailing out...\"",
")",
";",
"}",
"}"
] |
Checks to ensure that the caller is using a settings object with the same job id
that this pool is responsible for.
@param settings To be checked
|
[
"Checks",
"to",
"ensure",
"that",
"the",
"caller",
"is",
"using",
"a",
"settings",
"object",
"with",
"the",
"same",
"job",
"id",
"that",
"this",
"pool",
"is",
"responsible",
"for",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java#L64-L73
|
14,983
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java
|
PooledHttpTransportFactory.getOrCreateTransportPool
|
private TransportPool getOrCreateTransportPool(String hostInfo, Settings settings, SecureSettings secureSettings) {
TransportPool pool;
pool = hostPools.get(hostInfo); // Check again in case it was added while waiting for the lock
if (pool == null) {
pool = new TransportPool(jobKey, hostInfo, settings, secureSettings);
hostPools.put(hostInfo, pool);
if (log.isDebugEnabled()) {
log.debug("Creating new TransportPool for job ["+jobKey+"] for host ["+hostInfo+"]");
}
}
return pool;
}
|
java
|
private TransportPool getOrCreateTransportPool(String hostInfo, Settings settings, SecureSettings secureSettings) {
TransportPool pool;
pool = hostPools.get(hostInfo); // Check again in case it was added while waiting for the lock
if (pool == null) {
pool = new TransportPool(jobKey, hostInfo, settings, secureSettings);
hostPools.put(hostInfo, pool);
if (log.isDebugEnabled()) {
log.debug("Creating new TransportPool for job ["+jobKey+"] for host ["+hostInfo+"]");
}
}
return pool;
}
|
[
"private",
"TransportPool",
"getOrCreateTransportPool",
"(",
"String",
"hostInfo",
",",
"Settings",
"settings",
",",
"SecureSettings",
"secureSettings",
")",
"{",
"TransportPool",
"pool",
";",
"pool",
"=",
"hostPools",
".",
"get",
"(",
"hostInfo",
")",
";",
"// Check again in case it was added while waiting for the lock",
"if",
"(",
"pool",
"==",
"null",
")",
"{",
"pool",
"=",
"new",
"TransportPool",
"(",
"jobKey",
",",
"hostInfo",
",",
"settings",
",",
"secureSettings",
")",
";",
"hostPools",
".",
"put",
"(",
"hostInfo",
",",
"pool",
")",
";",
"if",
"(",
"log",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Creating new TransportPool for job [\"",
"+",
"jobKey",
"+",
"\"] for host [\"",
"+",
"hostInfo",
"+",
"\"]\"",
")",
";",
"}",
"}",
"return",
"pool",
";",
"}"
] |
Gets the transport pool for the given host info, or creates one if it is absent.
@param hostInfo To get a pool for
@param settings For creating the pool if it does not exist
@param secureSettings For providing secure settings to the connections within the pool once created
@return A transport pool for the given host
|
[
"Gets",
"the",
"transport",
"pool",
"for",
"the",
"given",
"host",
"info",
"or",
"creates",
"one",
"if",
"it",
"is",
"absent",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java#L82-L93
|
14,984
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java
|
PooledHttpTransportFactory.borrowFrom
|
private Transport borrowFrom(TransportPool pool, String hostInfo) {
if (!pool.getJobPoolingKey().equals(jobKey)) {
throw new EsHadoopIllegalArgumentException("PooledTransportFactory found a pool with a different owner than this job. " +
"This could be a different job incorrectly polluting the TransportPool. Bailing out...");
}
try {
return pool.borrowTransport();
} catch (Exception ex) {
throw new EsHadoopException(
String.format("Could not get a Transport from the Transport Pool for host [%s]", hostInfo),
ex
);
}
}
|
java
|
private Transport borrowFrom(TransportPool pool, String hostInfo) {
if (!pool.getJobPoolingKey().equals(jobKey)) {
throw new EsHadoopIllegalArgumentException("PooledTransportFactory found a pool with a different owner than this job. " +
"This could be a different job incorrectly polluting the TransportPool. Bailing out...");
}
try {
return pool.borrowTransport();
} catch (Exception ex) {
throw new EsHadoopException(
String.format("Could not get a Transport from the Transport Pool for host [%s]", hostInfo),
ex
);
}
}
|
[
"private",
"Transport",
"borrowFrom",
"(",
"TransportPool",
"pool",
",",
"String",
"hostInfo",
")",
"{",
"if",
"(",
"!",
"pool",
".",
"getJobPoolingKey",
"(",
")",
".",
"equals",
"(",
"jobKey",
")",
")",
"{",
"throw",
"new",
"EsHadoopIllegalArgumentException",
"(",
"\"PooledTransportFactory found a pool with a different owner than this job. \"",
"+",
"\"This could be a different job incorrectly polluting the TransportPool. Bailing out...\"",
")",
";",
"}",
"try",
"{",
"return",
"pool",
".",
"borrowTransport",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"EsHadoopException",
"(",
"String",
".",
"format",
"(",
"\"Could not get a Transport from the Transport Pool for host [%s]\"",
",",
"hostInfo",
")",
",",
"ex",
")",
";",
"}",
"}"
] |
Creates a Transport using the given TransportPool.
@param pool Transport is borrowed from
@param hostInfo For logging purposes
@return A Transport backed by a pooled resource
|
[
"Creates",
"a",
"Transport",
"using",
"the",
"given",
"TransportPool",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java#L101-L114
|
14,985
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java
|
PooledHttpTransportFactory.cleanPools
|
synchronized int cleanPools() {
int totalConnectionsRemaining = 0;
List<String> hostsToRemove = new ArrayList<String>();
for (Map.Entry<String, TransportPool> hostPool : hostPools.entrySet()) {
String host = hostPool.getKey();
TransportPool pool = hostPool.getValue();
int connectionsRemaining = pool.removeOldConnections();
if (connectionsRemaining == 0) {
hostsToRemove.add(host);
} else {
totalConnectionsRemaining += connectionsRemaining;
}
}
// Remove old pools that now have no connections.
for (String hostToRemove : hostsToRemove) {
hostPools.remove(hostToRemove);
}
return totalConnectionsRemaining;
}
|
java
|
synchronized int cleanPools() {
int totalConnectionsRemaining = 0;
List<String> hostsToRemove = new ArrayList<String>();
for (Map.Entry<String, TransportPool> hostPool : hostPools.entrySet()) {
String host = hostPool.getKey();
TransportPool pool = hostPool.getValue();
int connectionsRemaining = pool.removeOldConnections();
if (connectionsRemaining == 0) {
hostsToRemove.add(host);
} else {
totalConnectionsRemaining += connectionsRemaining;
}
}
// Remove old pools that now have no connections.
for (String hostToRemove : hostsToRemove) {
hostPools.remove(hostToRemove);
}
return totalConnectionsRemaining;
}
|
[
"synchronized",
"int",
"cleanPools",
"(",
")",
"{",
"int",
"totalConnectionsRemaining",
"=",
"0",
";",
"List",
"<",
"String",
">",
"hostsToRemove",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"TransportPool",
">",
"hostPool",
":",
"hostPools",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"host",
"=",
"hostPool",
".",
"getKey",
"(",
")",
";",
"TransportPool",
"pool",
"=",
"hostPool",
".",
"getValue",
"(",
")",
";",
"int",
"connectionsRemaining",
"=",
"pool",
".",
"removeOldConnections",
"(",
")",
";",
"if",
"(",
"connectionsRemaining",
"==",
"0",
")",
"{",
"hostsToRemove",
".",
"add",
"(",
"host",
")",
";",
"}",
"else",
"{",
"totalConnectionsRemaining",
"+=",
"connectionsRemaining",
";",
"}",
"}",
"// Remove old pools that now have no connections.",
"for",
"(",
"String",
"hostToRemove",
":",
"hostsToRemove",
")",
"{",
"hostPools",
".",
"remove",
"(",
"hostToRemove",
")",
";",
"}",
"return",
"totalConnectionsRemaining",
";",
"}"
] |
Iterates over the available host pools and asks each one to purge transports older than a certain age.
@return Total number of pooled connections still alive in this factory.
|
[
"Iterates",
"over",
"the",
"available",
"host",
"pools",
"and",
"asks",
"each",
"one",
"to",
"purge",
"transports",
"older",
"than",
"a",
"certain",
"age",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/pooling/PooledHttpTransportFactory.java#L120-L141
|
14,986
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java
|
CommonsHttpTransport.doExecute
|
private void doExecute(HttpMethod method) throws IOException {
long start = System.currentTimeMillis();
try {
client.executeMethod(method);
afterExecute(method);
} finally {
stats.netTotalTime += (System.currentTimeMillis() - start);
closeAuthSchemeQuietly(method);
}
}
|
java
|
private void doExecute(HttpMethod method) throws IOException {
long start = System.currentTimeMillis();
try {
client.executeMethod(method);
afterExecute(method);
} finally {
stats.netTotalTime += (System.currentTimeMillis() - start);
closeAuthSchemeQuietly(method);
}
}
|
[
"private",
"void",
"doExecute",
"(",
"HttpMethod",
"method",
")",
"throws",
"IOException",
"{",
"long",
"start",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"try",
"{",
"client",
".",
"executeMethod",
"(",
"method",
")",
";",
"afterExecute",
"(",
"method",
")",
";",
"}",
"finally",
"{",
"stats",
".",
"netTotalTime",
"+=",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"start",
")",
";",
"closeAuthSchemeQuietly",
"(",
"method",
")",
";",
"}",
"}"
] |
Actually perform the request
@param method the HTTP method to perform
@throws IOException If there is an issue during the method execution
|
[
"Actually",
"perform",
"the",
"request"
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java#L682-L691
|
14,987
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java
|
CommonsHttpTransport.afterExecute
|
private void afterExecute(HttpMethod method) throws IOException {
AuthState hostAuthState = method.getHostAuthState();
if (hostAuthState.isPreemptive() || hostAuthState.isAuthAttempted()) {
AuthScheme authScheme = hostAuthState.getAuthScheme();
if (authScheme instanceof SpnegoAuthScheme && settings.getNetworkSpnegoAuthMutual()) {
// Perform Mutual Authentication
SpnegoAuthScheme spnegoAuthScheme = ((SpnegoAuthScheme) authScheme);
Map challenges = AuthChallengeParser.parseChallenges(method.getResponseHeaders(WWW_AUTHENTICATE));
String id = spnegoAuthScheme.getSchemeName();
String challenge = (String) challenges.get(id.toLowerCase());
if (challenge == null) {
throw new IOException(id + " authorization challenge expected, but not found");
}
spnegoAuthScheme.ensureMutualAuth(challenge);
}
}
}
|
java
|
private void afterExecute(HttpMethod method) throws IOException {
AuthState hostAuthState = method.getHostAuthState();
if (hostAuthState.isPreemptive() || hostAuthState.isAuthAttempted()) {
AuthScheme authScheme = hostAuthState.getAuthScheme();
if (authScheme instanceof SpnegoAuthScheme && settings.getNetworkSpnegoAuthMutual()) {
// Perform Mutual Authentication
SpnegoAuthScheme spnegoAuthScheme = ((SpnegoAuthScheme) authScheme);
Map challenges = AuthChallengeParser.parseChallenges(method.getResponseHeaders(WWW_AUTHENTICATE));
String id = spnegoAuthScheme.getSchemeName();
String challenge = (String) challenges.get(id.toLowerCase());
if (challenge == null) {
throw new IOException(id + " authorization challenge expected, but not found");
}
spnegoAuthScheme.ensureMutualAuth(challenge);
}
}
}
|
[
"private",
"void",
"afterExecute",
"(",
"HttpMethod",
"method",
")",
"throws",
"IOException",
"{",
"AuthState",
"hostAuthState",
"=",
"method",
".",
"getHostAuthState",
"(",
")",
";",
"if",
"(",
"hostAuthState",
".",
"isPreemptive",
"(",
")",
"||",
"hostAuthState",
".",
"isAuthAttempted",
"(",
")",
")",
"{",
"AuthScheme",
"authScheme",
"=",
"hostAuthState",
".",
"getAuthScheme",
"(",
")",
";",
"if",
"(",
"authScheme",
"instanceof",
"SpnegoAuthScheme",
"&&",
"settings",
".",
"getNetworkSpnegoAuthMutual",
"(",
")",
")",
"{",
"// Perform Mutual Authentication",
"SpnegoAuthScheme",
"spnegoAuthScheme",
"=",
"(",
"(",
"SpnegoAuthScheme",
")",
"authScheme",
")",
";",
"Map",
"challenges",
"=",
"AuthChallengeParser",
".",
"parseChallenges",
"(",
"method",
".",
"getResponseHeaders",
"(",
"WWW_AUTHENTICATE",
")",
")",
";",
"String",
"id",
"=",
"spnegoAuthScheme",
".",
"getSchemeName",
"(",
")",
";",
"String",
"challenge",
"=",
"(",
"String",
")",
"challenges",
".",
"get",
"(",
"id",
".",
"toLowerCase",
"(",
")",
")",
";",
"if",
"(",
"challenge",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"id",
"+",
"\" authorization challenge expected, but not found\"",
")",
";",
"}",
"spnegoAuthScheme",
".",
"ensureMutualAuth",
"(",
"challenge",
")",
";",
"}",
"}",
"}"
] |
Close any authentication resources that we may still have open and perform any after-response duties that we need to perform.
@param method The method that has been executed
@throws IOException If any issues arise during post processing
|
[
"Close",
"any",
"authentication",
"resources",
"that",
"we",
"may",
"still",
"have",
"open",
"and",
"perform",
"any",
"after",
"-",
"response",
"duties",
"that",
"we",
"need",
"to",
"perform",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java#L698-L715
|
14,988
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java
|
CommonsHttpTransport.closeAuthSchemeQuietly
|
private void closeAuthSchemeQuietly(HttpMethod method) {
AuthScheme scheme = method.getHostAuthState().getAuthScheme();
if (scheme instanceof Closeable) {
try {
((Closeable) scheme).close();
} catch (IOException e) {
log.error("Could not close [" + scheme.getSchemeName() + "] auth scheme", e);
}
}
}
|
java
|
private void closeAuthSchemeQuietly(HttpMethod method) {
AuthScheme scheme = method.getHostAuthState().getAuthScheme();
if (scheme instanceof Closeable) {
try {
((Closeable) scheme).close();
} catch (IOException e) {
log.error("Could not close [" + scheme.getSchemeName() + "] auth scheme", e);
}
}
}
|
[
"private",
"void",
"closeAuthSchemeQuietly",
"(",
"HttpMethod",
"method",
")",
"{",
"AuthScheme",
"scheme",
"=",
"method",
".",
"getHostAuthState",
"(",
")",
".",
"getAuthScheme",
"(",
")",
";",
"if",
"(",
"scheme",
"instanceof",
"Closeable",
")",
"{",
"try",
"{",
"(",
"(",
"Closeable",
")",
"scheme",
")",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Could not close [\"",
"+",
"scheme",
".",
"getSchemeName",
"(",
")",
"+",
"\"] auth scheme\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Close the underlying authscheme if it is a Closeable object.
@param method Executing method
@throws IOException If the scheme could not be closed
|
[
"Close",
"the",
"underlying",
"authscheme",
"if",
"it",
"is",
"a",
"Closeable",
"object",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/rest/commonshttp/CommonsHttpTransport.java#L722-L731
|
14,989
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/serialization/dto/mapping/MappingUtils.java
|
MappingUtils.findTypos
|
static List[] findTypos(Collection<String> fields, Mapping mapping) {
Set<String> keys = mapping.flatten().keySet();
// find missing
List<String> missing = new ArrayList<String>(fields.size());
for (String field : fields) {
if (!keys.contains(field) && !isBuiltIn(field)) {
missing.add(field);
}
}
if (missing.isEmpty()) {
return null;
}
Map<String, String> unwrapped = new LinkedHashMap<String, String>();
// find similar
for (String key : keys) {
int match = key.lastIndexOf(".");
if (match > 0) {
String leafField = key.substring(match + 1);
// leaf fields are secondary to top-level ones (in case of overwrite, the top level ones win)
if (!unwrapped.containsKey(leafField)) {
unwrapped.put(leafField, key);
}
}
unwrapped.put(key, key);
}
List<String> typos = new ArrayList<String>();
Set<String> similar = unwrapped.keySet();
for (String string : missing) {
List<String> matches = StringUtils.findSimiliar(string, similar);
for (String match : matches) {
// get actual field
typos.add(unwrapped.get(match));
}
}
return new List[] { missing, typos };
}
|
java
|
static List[] findTypos(Collection<String> fields, Mapping mapping) {
Set<String> keys = mapping.flatten().keySet();
// find missing
List<String> missing = new ArrayList<String>(fields.size());
for (String field : fields) {
if (!keys.contains(field) && !isBuiltIn(field)) {
missing.add(field);
}
}
if (missing.isEmpty()) {
return null;
}
Map<String, String> unwrapped = new LinkedHashMap<String, String>();
// find similar
for (String key : keys) {
int match = key.lastIndexOf(".");
if (match > 0) {
String leafField = key.substring(match + 1);
// leaf fields are secondary to top-level ones (in case of overwrite, the top level ones win)
if (!unwrapped.containsKey(leafField)) {
unwrapped.put(leafField, key);
}
}
unwrapped.put(key, key);
}
List<String> typos = new ArrayList<String>();
Set<String> similar = unwrapped.keySet();
for (String string : missing) {
List<String> matches = StringUtils.findSimiliar(string, similar);
for (String match : matches) {
// get actual field
typos.add(unwrapped.get(match));
}
}
return new List[] { missing, typos };
}
|
[
"static",
"List",
"[",
"]",
"findTypos",
"(",
"Collection",
"<",
"String",
">",
"fields",
",",
"Mapping",
"mapping",
")",
"{",
"Set",
"<",
"String",
">",
"keys",
"=",
"mapping",
".",
"flatten",
"(",
")",
".",
"keySet",
"(",
")",
";",
"// find missing",
"List",
"<",
"String",
">",
"missing",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"fields",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"String",
"field",
":",
"fields",
")",
"{",
"if",
"(",
"!",
"keys",
".",
"contains",
"(",
"field",
")",
"&&",
"!",
"isBuiltIn",
"(",
"field",
")",
")",
"{",
"missing",
".",
"add",
"(",
"field",
")",
";",
"}",
"}",
"if",
"(",
"missing",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"Map",
"<",
"String",
",",
"String",
">",
"unwrapped",
"=",
"new",
"LinkedHashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"// find similar",
"for",
"(",
"String",
"key",
":",
"keys",
")",
"{",
"int",
"match",
"=",
"key",
".",
"lastIndexOf",
"(",
"\".\"",
")",
";",
"if",
"(",
"match",
">",
"0",
")",
"{",
"String",
"leafField",
"=",
"key",
".",
"substring",
"(",
"match",
"+",
"1",
")",
";",
"// leaf fields are secondary to top-level ones (in case of overwrite, the top level ones win)",
"if",
"(",
"!",
"unwrapped",
".",
"containsKey",
"(",
"leafField",
")",
")",
"{",
"unwrapped",
".",
"put",
"(",
"leafField",
",",
"key",
")",
";",
"}",
"}",
"unwrapped",
".",
"put",
"(",
"key",
",",
"key",
")",
";",
"}",
"List",
"<",
"String",
">",
"typos",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"Set",
"<",
"String",
">",
"similar",
"=",
"unwrapped",
".",
"keySet",
"(",
")",
";",
"for",
"(",
"String",
"string",
":",
"missing",
")",
"{",
"List",
"<",
"String",
">",
"matches",
"=",
"StringUtils",
".",
"findSimiliar",
"(",
"string",
",",
"similar",
")",
";",
"for",
"(",
"String",
"match",
":",
"matches",
")",
"{",
"// get actual field",
"typos",
".",
"add",
"(",
"unwrapped",
".",
"get",
"(",
"match",
")",
")",
";",
"}",
"}",
"return",
"new",
"List",
"[",
"]",
"{",
"missing",
",",
"typos",
"}",
";",
"}"
] |
return a tuple for proper messages
|
[
"return",
"a",
"tuple",
"for",
"proper",
"messages"
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/serialization/dto/mapping/MappingUtils.java#L78-L118
|
14,990
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/serialization/dto/mapping/MappingUtils.java
|
MappingUtils.joinParentField
|
public static String joinParentField(Settings settings) {
if (StringUtils.hasText(settings.getMappingJoin())) {
return settings.getMappingJoin().concat(".parent");
}
return null;
}
|
java
|
public static String joinParentField(Settings settings) {
if (StringUtils.hasText(settings.getMappingJoin())) {
return settings.getMappingJoin().concat(".parent");
}
return null;
}
|
[
"public",
"static",
"String",
"joinParentField",
"(",
"Settings",
"settings",
")",
"{",
"if",
"(",
"StringUtils",
".",
"hasText",
"(",
"settings",
".",
"getMappingJoin",
"(",
")",
")",
")",
"{",
"return",
"settings",
".",
"getMappingJoin",
"(",
")",
".",
"concat",
"(",
"\".parent\"",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
If "es.mapping.join" is set, this returns the field name for the join field's parent sub-field.
@param settings to pull info from
@return the parent sub-field to pull routing information from.
|
[
"If",
"es",
".",
"mapping",
".",
"join",
"is",
"set",
"this",
"returns",
"the",
"field",
"name",
"for",
"the",
"join",
"field",
"s",
"parent",
"sub",
"-",
"field",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/serialization/dto/mapping/MappingUtils.java#L218-L223
|
14,991
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedObjectReader.java
|
BackportedObjectReader._findRootDeserializer
|
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType)
throws JsonMappingException {
// Sanity check: must have actual type...
if (valueType == null) {
throw new JsonMappingException("No value type configured for ObjectReader");
}
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser != null) {
return deser;
}
// es-hadoop: findType with 2 args have been removed since 1.9 so this code compiles on 1.8 (which has the fallback method)
// es-hadoop: on 1.5 only the 2 args method exists, since 1.9 only the one with 3 args hence the if
// Nope: need to ask provider to resolve it
deser = _provider.findTypedValueDeserializer(cfg, valueType);
if (deser == null) { // can this happen?
throw new JsonMappingException("Can not find a deserializer for type " + valueType);
}
_rootDeserializers.put(valueType, deser);
return deser;
}
|
java
|
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationConfig cfg, JavaType valueType)
throws JsonMappingException {
// Sanity check: must have actual type...
if (valueType == null) {
throw new JsonMappingException("No value type configured for ObjectReader");
}
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser != null) {
return deser;
}
// es-hadoop: findType with 2 args have been removed since 1.9 so this code compiles on 1.8 (which has the fallback method)
// es-hadoop: on 1.5 only the 2 args method exists, since 1.9 only the one with 3 args hence the if
// Nope: need to ask provider to resolve it
deser = _provider.findTypedValueDeserializer(cfg, valueType);
if (deser == null) { // can this happen?
throw new JsonMappingException("Can not find a deserializer for type " + valueType);
}
_rootDeserializers.put(valueType, deser);
return deser;
}
|
[
"protected",
"JsonDeserializer",
"<",
"Object",
">",
"_findRootDeserializer",
"(",
"DeserializationConfig",
"cfg",
",",
"JavaType",
"valueType",
")",
"throws",
"JsonMappingException",
"{",
"// Sanity check: must have actual type...",
"if",
"(",
"valueType",
"==",
"null",
")",
"{",
"throw",
"new",
"JsonMappingException",
"(",
"\"No value type configured for ObjectReader\"",
")",
";",
"}",
"// First: have we already seen it?",
"JsonDeserializer",
"<",
"Object",
">",
"deser",
"=",
"_rootDeserializers",
".",
"get",
"(",
"valueType",
")",
";",
"if",
"(",
"deser",
"!=",
"null",
")",
"{",
"return",
"deser",
";",
"}",
"// es-hadoop: findType with 2 args have been removed since 1.9 so this code compiles on 1.8 (which has the fallback method)",
"// es-hadoop: on 1.5 only the 2 args method exists, since 1.9 only the one with 3 args hence the if",
"// Nope: need to ask provider to resolve it",
"deser",
"=",
"_provider",
".",
"findTypedValueDeserializer",
"(",
"cfg",
",",
"valueType",
")",
";",
"if",
"(",
"deser",
"==",
"null",
")",
"{",
"// can this happen?",
"throw",
"new",
"JsonMappingException",
"(",
"\"Can not find a deserializer for type \"",
"+",
"valueType",
")",
";",
"}",
"_rootDeserializers",
".",
"put",
"(",
"valueType",
",",
"deser",
")",
";",
"return",
"deser",
";",
"}"
] |
Method called to locate deserializer for the passed root-level value.
|
[
"Method",
"called",
"to",
"locate",
"deserializer",
"for",
"the",
"passed",
"root",
"-",
"level",
"value",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/serialization/json/BackportedObjectReader.java#L161-L185
|
14,992
|
elastic/elasticsearch-hadoop
|
hive/src/main/java/org/elasticsearch/hadoop/hive/HiveUtils.java
|
HiveUtils.columnToAlias
|
static Collection<String> columnToAlias(Settings settings) {
FieldAlias fa = alias(settings);
List<String> columnNames = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS), ",");
// eliminate virtual columns
// we can't use virtual columns since some distro don't have this field...
for (String vc : HiveConstants.VIRTUAL_COLUMNS) {
columnNames.remove(vc);
}
for (int i = 0; i < columnNames.size(); i++) {
String original = columnNames.get(i);
String alias = fa.toES(original);
if (alias != null) {
columnNames.set(i, alias);
}
}
return columnNames;
}
|
java
|
static Collection<String> columnToAlias(Settings settings) {
FieldAlias fa = alias(settings);
List<String> columnNames = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS), ",");
// eliminate virtual columns
// we can't use virtual columns since some distro don't have this field...
for (String vc : HiveConstants.VIRTUAL_COLUMNS) {
columnNames.remove(vc);
}
for (int i = 0; i < columnNames.size(); i++) {
String original = columnNames.get(i);
String alias = fa.toES(original);
if (alias != null) {
columnNames.set(i, alias);
}
}
return columnNames;
}
|
[
"static",
"Collection",
"<",
"String",
">",
"columnToAlias",
"(",
"Settings",
"settings",
")",
"{",
"FieldAlias",
"fa",
"=",
"alias",
"(",
"settings",
")",
";",
"List",
"<",
"String",
">",
"columnNames",
"=",
"StringUtils",
".",
"tokenize",
"(",
"settings",
".",
"getProperty",
"(",
"HiveConstants",
".",
"COLUMNS",
")",
",",
"\",\"",
")",
";",
"// eliminate virtual columns",
"// we can't use virtual columns since some distro don't have this field...",
"for",
"(",
"String",
"vc",
":",
"HiveConstants",
".",
"VIRTUAL_COLUMNS",
")",
"{",
"columnNames",
".",
"remove",
"(",
"vc",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"columnNames",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"String",
"original",
"=",
"columnNames",
".",
"get",
"(",
"i",
")",
";",
"String",
"alias",
"=",
"fa",
".",
"toES",
"(",
"original",
")",
";",
"if",
"(",
"alias",
"!=",
"null",
")",
"{",
"columnNames",
".",
"set",
"(",
"i",
",",
"alias",
")",
";",
"}",
"}",
"return",
"columnNames",
";",
"}"
] |
Renders the full collection of field names needed from ES by combining the names of
the hive table fields with the user provided name mappings.
@param settings Settings to pull hive column names and user name mappings from.
@return A collection of ES field names
|
[
"Renders",
"the",
"full",
"collection",
"of",
"field",
"names",
"needed",
"from",
"ES",
"by",
"combining",
"the",
"names",
"of",
"the",
"hive",
"table",
"fields",
"with",
"the",
"user",
"provided",
"name",
"mappings",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/hive/src/main/java/org/elasticsearch/hadoop/hive/HiveUtils.java#L84-L102
|
14,993
|
elastic/elasticsearch-hadoop
|
hive/src/main/java/org/elasticsearch/hadoop/hive/HiveUtils.java
|
HiveUtils.discoverJsonFieldName
|
static String discoverJsonFieldName(Settings settings, FieldAlias alias) {
Set<String> virtualColumnsToBeRemoved = new HashSet<String>(HiveConstants.VIRTUAL_COLUMNS.length);
Collections.addAll(virtualColumnsToBeRemoved, HiveConstants.VIRTUAL_COLUMNS);
List<String> columnNames = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS), ",");
Iterator<String> nameIter = columnNames.iterator();
List<String> columnTypes = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS_TYPES), ":");
Iterator<String> typeIter = columnTypes.iterator();
String candidateField = null;
while(nameIter.hasNext() && candidateField == null) {
String columnName = nameIter.next();
String type = typeIter.next();
if ("string".equalsIgnoreCase(type) && !virtualColumnsToBeRemoved.contains(columnName)) {
candidateField = columnName;
}
}
Assert.hasText(candidateField, "Could not identify a field to insert JSON data into " +
"from the given fields : {" + columnNames + "} of types {" + columnTypes + "}");
// If the candidate field is aliased to something else, find the alias name and use that for the field name:
candidateField = alias.toES(candidateField);
return candidateField;
}
|
java
|
static String discoverJsonFieldName(Settings settings, FieldAlias alias) {
Set<String> virtualColumnsToBeRemoved = new HashSet<String>(HiveConstants.VIRTUAL_COLUMNS.length);
Collections.addAll(virtualColumnsToBeRemoved, HiveConstants.VIRTUAL_COLUMNS);
List<String> columnNames = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS), ",");
Iterator<String> nameIter = columnNames.iterator();
List<String> columnTypes = StringUtils.tokenize(settings.getProperty(HiveConstants.COLUMNS_TYPES), ":");
Iterator<String> typeIter = columnTypes.iterator();
String candidateField = null;
while(nameIter.hasNext() && candidateField == null) {
String columnName = nameIter.next();
String type = typeIter.next();
if ("string".equalsIgnoreCase(type) && !virtualColumnsToBeRemoved.contains(columnName)) {
candidateField = columnName;
}
}
Assert.hasText(candidateField, "Could not identify a field to insert JSON data into " +
"from the given fields : {" + columnNames + "} of types {" + columnTypes + "}");
// If the candidate field is aliased to something else, find the alias name and use that for the field name:
candidateField = alias.toES(candidateField);
return candidateField;
}
|
[
"static",
"String",
"discoverJsonFieldName",
"(",
"Settings",
"settings",
",",
"FieldAlias",
"alias",
")",
"{",
"Set",
"<",
"String",
">",
"virtualColumnsToBeRemoved",
"=",
"new",
"HashSet",
"<",
"String",
">",
"(",
"HiveConstants",
".",
"VIRTUAL_COLUMNS",
".",
"length",
")",
";",
"Collections",
".",
"addAll",
"(",
"virtualColumnsToBeRemoved",
",",
"HiveConstants",
".",
"VIRTUAL_COLUMNS",
")",
";",
"List",
"<",
"String",
">",
"columnNames",
"=",
"StringUtils",
".",
"tokenize",
"(",
"settings",
".",
"getProperty",
"(",
"HiveConstants",
".",
"COLUMNS",
")",
",",
"\",\"",
")",
";",
"Iterator",
"<",
"String",
">",
"nameIter",
"=",
"columnNames",
".",
"iterator",
"(",
")",
";",
"List",
"<",
"String",
">",
"columnTypes",
"=",
"StringUtils",
".",
"tokenize",
"(",
"settings",
".",
"getProperty",
"(",
"HiveConstants",
".",
"COLUMNS_TYPES",
")",
",",
"\":\"",
")",
";",
"Iterator",
"<",
"String",
">",
"typeIter",
"=",
"columnTypes",
".",
"iterator",
"(",
")",
";",
"String",
"candidateField",
"=",
"null",
";",
"while",
"(",
"nameIter",
".",
"hasNext",
"(",
")",
"&&",
"candidateField",
"==",
"null",
")",
"{",
"String",
"columnName",
"=",
"nameIter",
".",
"next",
"(",
")",
";",
"String",
"type",
"=",
"typeIter",
".",
"next",
"(",
")",
";",
"if",
"(",
"\"string\"",
".",
"equalsIgnoreCase",
"(",
"type",
")",
"&&",
"!",
"virtualColumnsToBeRemoved",
".",
"contains",
"(",
"columnName",
")",
")",
"{",
"candidateField",
"=",
"columnName",
";",
"}",
"}",
"Assert",
".",
"hasText",
"(",
"candidateField",
",",
"\"Could not identify a field to insert JSON data into \"",
"+",
"\"from the given fields : {\"",
"+",
"columnNames",
"+",
"\"} of types {\"",
"+",
"columnTypes",
"+",
"\"}\"",
")",
";",
"// If the candidate field is aliased to something else, find the alias name and use that for the field name:",
"candidateField",
"=",
"alias",
".",
"toES",
"(",
"candidateField",
")",
";",
"return",
"candidateField",
";",
"}"
] |
Selects an appropriate field from the given Hive table schema to insert JSON data into if the feature is enabled
@param settings Settings to read schema information from
@return A FieldAlias object that projects the json source field into the select destination field
|
[
"Selects",
"an",
"appropriate",
"field",
"from",
"the",
"given",
"Hive",
"table",
"schema",
"to",
"insert",
"JSON",
"data",
"into",
"if",
"the",
"feature",
"is",
"enabled"
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/hive/src/main/java/org/elasticsearch/hadoop/hive/HiveUtils.java#L138-L166
|
14,994
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.obtainEsToken
|
private static EsToken obtainEsToken(final RestClient client, User user) {
// TODO: Should we extend this to basic authentication at some point?
KerberosPrincipal principal = user.getKerberosPrincipal();
if (user.isProxyUser()) {
principal = user.getRealUserProvider().getUser().getKerberosPrincipal();
}
Assert.isTrue(principal != null, "Kerberos credentials are missing on current user");
return user.doAs(new PrivilegedExceptionAction<EsToken>() {
@Override
public EsToken run() {
return client.createNewApiToken(newKeyName());
}
});
}
|
java
|
private static EsToken obtainEsToken(final RestClient client, User user) {
// TODO: Should we extend this to basic authentication at some point?
KerberosPrincipal principal = user.getKerberosPrincipal();
if (user.isProxyUser()) {
principal = user.getRealUserProvider().getUser().getKerberosPrincipal();
}
Assert.isTrue(principal != null, "Kerberos credentials are missing on current user");
return user.doAs(new PrivilegedExceptionAction<EsToken>() {
@Override
public EsToken run() {
return client.createNewApiToken(newKeyName());
}
});
}
|
[
"private",
"static",
"EsToken",
"obtainEsToken",
"(",
"final",
"RestClient",
"client",
",",
"User",
"user",
")",
"{",
"// TODO: Should we extend this to basic authentication at some point?",
"KerberosPrincipal",
"principal",
"=",
"user",
".",
"getKerberosPrincipal",
"(",
")",
";",
"if",
"(",
"user",
".",
"isProxyUser",
"(",
")",
")",
"{",
"principal",
"=",
"user",
".",
"getRealUserProvider",
"(",
")",
".",
"getUser",
"(",
")",
".",
"getKerberosPrincipal",
"(",
")",
";",
"}",
"Assert",
".",
"isTrue",
"(",
"principal",
"!=",
"null",
",",
"\"Kerberos credentials are missing on current user\"",
")",
";",
"return",
"user",
".",
"doAs",
"(",
"new",
"PrivilegedExceptionAction",
"<",
"EsToken",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"EsToken",
"run",
"(",
")",
"{",
"return",
"client",
".",
"createNewApiToken",
"(",
"newKeyName",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Obtain the given user's authentication token from Elasticsearch by performing the getAuthToken operation
as the given user, thus ensuring the subject's private credentials available on the thread's access control
context for the life of the operation.
@param client The Elasticsearch client
@param user the user object that contains credentials for obtaining an auth token
@return the authentication token in ES-Hadoop specific format.
|
[
"Obtain",
"the",
"given",
"user",
"s",
"authentication",
"token",
"from",
"Elasticsearch",
"by",
"performing",
"the",
"getAuthToken",
"operation",
"as",
"the",
"given",
"user",
"thus",
"ensuring",
"the",
"subject",
"s",
"private",
"credentials",
"available",
"on",
"the",
"thread",
"s",
"access",
"control",
"context",
"for",
"the",
"life",
"of",
"the",
"operation",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L67-L80
|
14,995
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.obtainToken
|
public static Token<EsTokenIdentifier> obtainToken(RestClient client, User user) {
EsToken esToken = obtainEsToken(client, user);
return EsTokenIdentifier.createTokenFrom(esToken);
}
|
java
|
public static Token<EsTokenIdentifier> obtainToken(RestClient client, User user) {
EsToken esToken = obtainEsToken(client, user);
return EsTokenIdentifier.createTokenFrom(esToken);
}
|
[
"public",
"static",
"Token",
"<",
"EsTokenIdentifier",
">",
"obtainToken",
"(",
"RestClient",
"client",
",",
"User",
"user",
")",
"{",
"EsToken",
"esToken",
"=",
"obtainEsToken",
"(",
"client",
",",
"user",
")",
";",
"return",
"EsTokenIdentifier",
".",
"createTokenFrom",
"(",
"esToken",
")",
";",
"}"
] |
Obtain and return an authentication token for the current user.
@param client The Elasticsearch client
@return the authentication token instance in Hadoop Token format.
|
[
"Obtain",
"and",
"return",
"an",
"authentication",
"token",
"for",
"the",
"current",
"user",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L87-L90
|
14,996
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.obtainAndCache
|
public static void obtainAndCache(RestClient client, User user) throws IOException {
EsToken token = obtainEsToken(client, user);
if (token == null) {
throw new IOException("No token returned for user " + user.getKerberosPrincipal().getName());
}
if (LOG.isDebugEnabled()) {
LOG.debug("Obtained token " + EsTokenIdentifier.KIND_NAME + " for user " +
user.getKerberosPrincipal().getName());
}
user.addEsToken(token);
}
|
java
|
public static void obtainAndCache(RestClient client, User user) throws IOException {
EsToken token = obtainEsToken(client, user);
if (token == null) {
throw new IOException("No token returned for user " + user.getKerberosPrincipal().getName());
}
if (LOG.isDebugEnabled()) {
LOG.debug("Obtained token " + EsTokenIdentifier.KIND_NAME + " for user " +
user.getKerberosPrincipal().getName());
}
user.addEsToken(token);
}
|
[
"public",
"static",
"void",
"obtainAndCache",
"(",
"RestClient",
"client",
",",
"User",
"user",
")",
"throws",
"IOException",
"{",
"EsToken",
"token",
"=",
"obtainEsToken",
"(",
"client",
",",
"user",
")",
";",
"if",
"(",
"token",
"==",
"null",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"No token returned for user \"",
"+",
"user",
".",
"getKerberosPrincipal",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Obtained token \"",
"+",
"EsTokenIdentifier",
".",
"KIND_NAME",
"+",
"\" for user \"",
"+",
"user",
".",
"getKerberosPrincipal",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"user",
".",
"addEsToken",
"(",
"token",
")",
";",
"}"
] |
Obtain an authentication token for the given user and add it to the
user's credentials.
@param client The Elasticsearch client
@param user The user for obtaining and storing the token
@throws IOException If making a remote call to the authentication service fails
|
[
"Obtain",
"an",
"authentication",
"token",
"for",
"the",
"given",
"user",
"and",
"add",
"it",
"to",
"the",
"user",
"s",
"credentials",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L99-L110
|
14,997
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.obtainTokenForJob
|
public static void obtainTokenForJob(final RestClient client, User user, Job job) {
Token<EsTokenIdentifier> token = obtainToken(client, user);
if (token == null) {
throw new EsHadoopException("No token returned for user " + user.getKerberosPrincipal().getName());
}
Text clusterName = token.getService();
if (LOG.isDebugEnabled()) {
LOG.debug("Obtained token " + EsTokenIdentifier.KIND_NAME.toString() + " for user " +
user.getKerberosPrincipal().getName() + " on cluster " + clusterName.toString());
}
job.getCredentials().addToken(clusterName, token);
}
|
java
|
public static void obtainTokenForJob(final RestClient client, User user, Job job) {
Token<EsTokenIdentifier> token = obtainToken(client, user);
if (token == null) {
throw new EsHadoopException("No token returned for user " + user.getKerberosPrincipal().getName());
}
Text clusterName = token.getService();
if (LOG.isDebugEnabled()) {
LOG.debug("Obtained token " + EsTokenIdentifier.KIND_NAME.toString() + " for user " +
user.getKerberosPrincipal().getName() + " on cluster " + clusterName.toString());
}
job.getCredentials().addToken(clusterName, token);
}
|
[
"public",
"static",
"void",
"obtainTokenForJob",
"(",
"final",
"RestClient",
"client",
",",
"User",
"user",
",",
"Job",
"job",
")",
"{",
"Token",
"<",
"EsTokenIdentifier",
">",
"token",
"=",
"obtainToken",
"(",
"client",
",",
"user",
")",
";",
"if",
"(",
"token",
"==",
"null",
")",
"{",
"throw",
"new",
"EsHadoopException",
"(",
"\"No token returned for user \"",
"+",
"user",
".",
"getKerberosPrincipal",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"Text",
"clusterName",
"=",
"token",
".",
"getService",
"(",
")",
";",
"if",
"(",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Obtained token \"",
"+",
"EsTokenIdentifier",
".",
"KIND_NAME",
".",
"toString",
"(",
")",
"+",
"\" for user \"",
"+",
"user",
".",
"getKerberosPrincipal",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\" on cluster \"",
"+",
"clusterName",
".",
"toString",
"(",
")",
")",
";",
"}",
"job",
".",
"getCredentials",
"(",
")",
".",
"addToken",
"(",
"clusterName",
",",
"token",
")",
";",
"}"
] |
Obtain an authentication token on behalf of the given user and add it to
the credentials for the given map reduce job. This version always obtains
a fresh authentication token instead of checking for existing ones on the
current user.
@param client The Elasticsearch client
@param user The user for whom to obtain the token
@param job The job instance in which the token should be stored
|
[
"Obtain",
"an",
"authentication",
"token",
"on",
"behalf",
"of",
"the",
"given",
"user",
"and",
"add",
"it",
"to",
"the",
"credentials",
"for",
"the",
"given",
"map",
"reduce",
"job",
".",
"This",
"version",
"always",
"obtains",
"a",
"fresh",
"authentication",
"token",
"instead",
"of",
"checking",
"for",
"existing",
"ones",
"on",
"the",
"current",
"user",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L122-L133
|
14,998
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.addTokenForJob
|
public static void addTokenForJob(final RestClient client, ClusterName clusterName, User user, Job job) {
Token<EsTokenIdentifier> token = getAuthToken(clusterName, user);
if (token == null) {
token = obtainToken(client, user);
}
job.getCredentials().addToken(token.getService(), token);
}
|
java
|
public static void addTokenForJob(final RestClient client, ClusterName clusterName, User user, Job job) {
Token<EsTokenIdentifier> token = getAuthToken(clusterName, user);
if (token == null) {
token = obtainToken(client, user);
}
job.getCredentials().addToken(token.getService(), token);
}
|
[
"public",
"static",
"void",
"addTokenForJob",
"(",
"final",
"RestClient",
"client",
",",
"ClusterName",
"clusterName",
",",
"User",
"user",
",",
"Job",
"job",
")",
"{",
"Token",
"<",
"EsTokenIdentifier",
">",
"token",
"=",
"getAuthToken",
"(",
"clusterName",
",",
"user",
")",
";",
"if",
"(",
"token",
"==",
"null",
")",
"{",
"token",
"=",
"obtainToken",
"(",
"client",
",",
"user",
")",
";",
"}",
"job",
".",
"getCredentials",
"(",
")",
".",
"addToken",
"(",
"token",
".",
"getService",
"(",
")",
",",
"token",
")",
";",
"}"
] |
Retrieves an authentication token from the given user, obtaining a new token if necessary,
and adds it to the credentials for the given map reduce job.
@param client The Elasticsearch client
@param clusterName the name of the cluster you are connecting to
@param user The user for whom to obtain the token
@param job The job instance in which the token should be stored
@throws IOException If making a remote call fails
@throws InterruptedException If executing as the given user is interrupted
|
[
"Retrieves",
"an",
"authentication",
"token",
"from",
"the",
"given",
"user",
"obtaining",
"a",
"new",
"token",
"if",
"necessary",
"and",
"adds",
"it",
"to",
"the",
"credentials",
"for",
"the",
"given",
"map",
"reduce",
"job",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L169-L175
|
14,999
|
elastic/elasticsearch-hadoop
|
mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java
|
TokenUtil.getAuthToken
|
private static Token<EsTokenIdentifier> getAuthToken(ClusterName clusterName, User user) {
EsToken esToken = getEsAuthToken(clusterName, user);
if (esToken == null) {
return null;
} else {
return EsTokenIdentifier.createTokenFrom(esToken);
}
}
|
java
|
private static Token<EsTokenIdentifier> getAuthToken(ClusterName clusterName, User user) {
EsToken esToken = getEsAuthToken(clusterName, user);
if (esToken == null) {
return null;
} else {
return EsTokenIdentifier.createTokenFrom(esToken);
}
}
|
[
"private",
"static",
"Token",
"<",
"EsTokenIdentifier",
">",
"getAuthToken",
"(",
"ClusterName",
"clusterName",
",",
"User",
"user",
")",
"{",
"EsToken",
"esToken",
"=",
"getEsAuthToken",
"(",
"clusterName",
",",
"user",
")",
";",
"if",
"(",
"esToken",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"EsTokenIdentifier",
".",
"createTokenFrom",
"(",
"esToken",
")",
";",
"}",
"}"
] |
Get the authentication token of the user for the provided cluster name in its Hadoop Token form.
@return null if the user does not have the token, otherwise the auth token for the cluster.
|
[
"Get",
"the",
"authentication",
"token",
"of",
"the",
"user",
"for",
"the",
"provided",
"cluster",
"name",
"in",
"its",
"Hadoop",
"Token",
"form",
"."
] |
f3acaba268ff96efae8eb946088c748c777c22cc
|
https://github.com/elastic/elasticsearch-hadoop/blob/f3acaba268ff96efae8eb946088c748c777c22cc/mr/src/main/java/org/elasticsearch/hadoop/mr/security/TokenUtil.java#L200-L207
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.