This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AlertDialog.Builder(thisActivity).apply { | |
setMessage(R.string.more_info_dialog_message) | |
setTitle(R.string.more_info_dialog_title) | |
setPositiveButton(R.string.yes_please) { d, i -> | |
// Se o usuário quiser, requere novamente permissão à funcionalidade | |
ActivityCompat.requestPermissions( | |
thisActivity, | |
arrayOf(Manifest.permission.CALL_PHONE), | |
CALL_PHONE_RESULT_CODE) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { | |
// Verifica se o usuário já negou acesso a permisão | |
if (shouldShowRequestPermissionRationale(Manifest.permission.CALL_PHONE)) { | |
// Usuário negou acesso | |
// Mostrar uma dialog explicando a importância do app ter acesso a funcionalidade | |
} else { | |
// Usuário não negou acesso ou negou e marcou a caixa de "não perguntar novamente" | |
// Fazer a requisição da permissão | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { | |
// Permissão ainda não foi concedida | |
} else { | |
// Permissão já foi concedida, já é possível usufruir da funcionalidade | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { | |
// Permissão ainda não foi concedida | |
} else { | |
// Permissão já foi concedida, já é possível usufruir da funcionalidade | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd src/ && find -type f | sed -e 's/.*.//' | sort | uniq -c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preferences > Key Bindings > Add it to your "Keymap User" file: | |
{"keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import static br.com.felipebelluco.javaplayground.PredicateUtil.negate; | |
public class Main { | |
public static void main(String[] args) { | |
List<String> list = Arrays.asList("foo", "", "bar"); | |
// Instead of this... | |
list.stream().filter(name -> !name.isEmpty()).forEach(System.out::println); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
List<String> names = null; | |
// NPE!!! | |
names.stream().filter(Objects::nonNull).forEach(System.out::println); | |
NewerOlder