Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
jtmuller5 / gradientDrawable.xml
Created January 30, 2020 05:13
Gradient Drawable for CardView
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="0"/>
<corners
android:bottomLeftRadius="@dimen/card_corner"
android:bottomRightRadius="@dimen/card_corner"
android:topLeftRadius="@dimen/card_corner"
@jtmuller5
jtmuller5 / progamGradient.kt
Created January 30, 2020 05:15
Programmatically Changing Drawable Gradient
// Change card gradient based on POS
var background = ResourcesCompat.getDrawable(main.resources, R.drawable.card_gradient, null) as GradientDrawable
var colorList = IntArray(10) {getWhiteColor()} // Create an integer array of all white values
background.mutate() // Mutate the drawable so changes don't affect every other drawable
// background.setGradientCenter(0.1F, 0.5F) // Reset the center of the gradient (default is 0.5F, 0.5F)) - Only works for radial and sweep types
// Conditionaly change the last color in the integer array
when (word?.partOfSpeech) {
"noun" -> colorList[colorList.size-1] = Color.argb(255, 66, 133, 244) // Blue
"verb" -> colorList[colorList.size-1] = Color.argb(255, 15, 157, 88) // Green
@jtmuller5
jtmuller5 / gist:a8de3598d31ad9f8de3c556cd4f79ec6
Created January 31, 2020 00:22
TextInputEditText from Material Design
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/search_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
app:endIconMode="clear_text"
app:endIconTint="@color/primaryYellow"
app:layout_constraintEnd_toEndOf="parent"
android:imeOptions="actionSearch"
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<View>(R.id.button_home).setOnClickListener {
val extras = FragmentNavigatorExtras(
textView to "exampleText"
)
val action = HomeFragmentDirections.actionHomeFragmentToHomeSecondFragment("From HomeFragment")
NavHostFragment.findNavController(this@HomeFragment).navigate(action,extras)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Determine how shared elements are handled
sharedElementEnterTransition = TransitionInflater.from(this.context).inflateTransition(R.transition.change_bounds)
sharedElementReturnTransition = TransitionInflater.from(this.context).inflateTransition(R.transition.change_bounds)
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home_second, container, false)
}
class SearchNews(var main: MainActivity) : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg params: String): String {
var searchString = params.get(0)
val url = "https://news.google.com/rss/search?q=$searchString&hl=en-US&gl=US&ceid=US:en"
var parseDoc = Jsoup.connect(url).parser(Parser.xmlParser()).get() //can also use maxBodySize(0) and timeout(0)
var items : Elements? = parseDoc?.select("item")
Log.d("result",items.toString())
return "Added"
}
}
class SearchNews(var main: MainActivity) : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg params: String): String {
var searchString = params.get(0)
val urlSearch = URLEncoder.encode(searchString,"UTF-8")
val url = "https://news.google.com/rss/search?q=$urlSearch&hl=en-US&gl=US&ceid=US:en"
var parseDoc = Jsoup.connect(url).parser(Parser.xmlParser()).get()
var items : Elements? = parseDoc?.select("item")
items?.forEach {
var title = it.getElementsByTag("title").html()
var link = it.getElementsByTag("link").html()
class SearchNews(var main: MainActivity) : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg params: String): String {
var searchString = params.get(0)
val urlSearch = URLEncoder.encode(searchString,"UTF-8")
val url = "https://news.google.com/rss/search?q=$urlSearch&hl=en-US&gl=US&ceid=US:en"
var parseDoc = Jsoup.connect(url).parser(Parser.xmlParser()).get()
var items : Elements? = parseDoc?.select("item")
items?.forEach {
var title = it.getElementsByTag("title").html()
var link = it.getElementsByTag("link").html()
class SearchNews(var main: MainActivity) : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg params: String): String {
var searchString = params.get(0)
val urlSearch = URLEncoder.encode(searchString,"UTF-8")
val url = "https://news.google.com/rss/search?q=$urlSearch&hl=en-US&gl=US&ceid=US:en"
var parseDoc = Jsoup.connect(url).parser(Parser.xmlParser()).get()
var items : Elements? = parseDoc?.select("item")
items?.forEach {
var title = it.getElementsByTag("title").html()
var link = it.getElementsByTag("link").html()