Skip to content

Instantly share code, notes, and snippets.

@ceruleanotter
ceruleanotter / GetUserData.java
Last active June 8, 2016 00:24
Intent Extras To Send Data Between Activities
// This is the code showing how to get user input from and EditText
// First, use findViewById to get the EditText view (just like you would
// get any other view in the layout
EditText myEditText = (EditText) findViewById(R.id.send_edit_text);
// Then from the edit text, perform two actions, first to get the "Text", then
// to change it to a String. It is kind of silly that you can't just have one
// action "getString", but it is the way that the engineers of Android chose
// to make it so ¯\_(ツ)_/¯
@ceruleanotter
ceruleanotter / .bash_profile
Last active September 3, 2020 20:10
github bash profile enhancements
### GIT ENHANCEMENT START ###
# Git enhancement settings
unset GIT_PS1_SHOWSTASHSTATE
# Git enhancements
source ~/.git-completion.sh
source ~/.git-prompt.sh
# colors!
cyan=$(tput setaf 33)
@ceruleanotter
ceruleanotter / ScoreViewModel.java
Last active August 7, 2017 09:09
ViewModel BlogPost : Part 1 : Step 1
public class ScoreViewModel extends ViewModel {
// Tracks the score for Team A
public int scoreTeamA = 0;
// Tracks the score for Team B
public int scoreTeamB = 0;
}
@ceruleanotter
ceruleanotter / MainActivity.java
Last active June 26, 2017 22:03
ViewModel BlogPost : Part 1 : Step 2
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewModel = ViewModelProviders.of(this).get(ScoreViewModel.class);
// Other setup code below...
}
@ceruleanotter
ceruleanotter / MainActivity.java
Created June 23, 2017 18:43
ViewModel BlogPost : Part 1 : Step 3
// The finished onCreate method
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewModel = ViewModelProviders.of(this).get(ScoreViewModel.class);
displayForTeamA(mViewModel.scoreTeamA);
displayForTeamB(mViewModel.scoreTeamB);
}
@ceruleanotter
ceruleanotter / build.gradle (Module: app) [Java]
Last active October 23, 2018 17:18
App's build.gradle NOT project
// -- Copy into dependencies block --
// Room components
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
@ceruleanotter
ceruleanotter / UploadWorker.kt
Last active June 25, 2022 06:31
WorkManager Basics - UploadWorker.kt Example
class UploadWorker(appContext: Context, workerParams: WorkerParameters)
: Worker(appContext, workerParams) {
override fun doWork(): Result {
try {
// Get the input
val imageUriInput = inputData.getString(Constants.KEY_IMAGE_URI)
// Do the work
val response = upload(imageUriInput)
@ceruleanotter
ceruleanotter / SimpleWorkRequest.kt
Created January 22, 2019 19:08
WorkManager Basics: Simple WorkRequest
// workDataOf (part of KTX) converts a list of pairs to a [Data] object.
val imageData = workDataOf(Constants.KEY_IMAGE_URI to imageUriString)
val uploadWorkRequest = OneTimeWorkRequestBuilder<UploadWorker>()
.setInputData(imageData)
.build()
@ceruleanotter
ceruleanotter / SimpleNetworkConstraint.kt
Created January 22, 2019 19:16
WorkManager Basics: Simple Constraint
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
@ceruleanotter
ceruleanotter / ManyConstraintsExample.kt
Last active January 30, 2019 20:54
WorkManager Basics: Multiple constraints example
val constraints = Constraints.Builder()
.setRequiresBatteryNotLow(true)
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(true)
.setRequiresStorageNotLow(true)
.setRequiresDeviceIdle(true)
.build()