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
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() |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val myWebView: WebView = view.findViewById(R.id.your_webView) | |
myWebView.webViewClient = WebViewClient() | |
myWebView.loadUrl("https://www.google.com/") | |
myWebView.setOnKeyListener { v, keyCode, event -> | |
if (keyCode == KeyEvent.KEYCODE_BACK && myWebView.canGoBack()) { | |
myWebView.goBack() // Navigate back to previous web page if there is one | |
nested_scroll.scrollTo(0, 0) // Scroll webview back to top of previous page | |
} |
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
class HomeFragment : Fragment() { | |
private lateinit var homeViewModel: HomeViewModel | |
private lateinit var sensorManager: SensorManager | |
lateinit var main: MainActivity | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? |
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
class HomeFragment : Fragment(), SensorEventListener { | |
private lateinit var homeViewModel: HomeViewModel | |
private lateinit var sensorManager: SensorManager | |
lateinit var main: MainActivity | |
var mGravity: Sensor? = null | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, |
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
// Handle Gravity data | |
if (currentSensor.type == Sensor.TYPE_GRAVITY) { | |
// Do something | |
} | |
// Handle Lin. Acceleration data | |
else if(currentSensor.type == Sensor.TYPE_LINEAR_ACCELERATION){ | |
// Do something else | |
} |
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
class SimpleTabsFragment : Fragment() { | |
private lateinit var dashboardViewModel: DashboardViewModel | |
var builder = CustomTabsIntent.Builder() | |
override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel::class.java) | |
val root = inflater.inflate(R.layout.fragment_simple_tabs, container, false) | |
return root | |
} |
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
class AdvancedTabsFragment : Fragment() { | |
lateinit var serviceConnection: CustomTabsServiceConnection | |
lateinit var client: CustomTabsClient | |
lateinit var session: CustomTabsSession | |
var builder = CustomTabsIntent.Builder() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) |
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
val sendLinkIntent = Intent(main,MainActivity::class.java) | |
sendLinkIntent.putExtra(Intent.EXTRA_SUBJECT,"This is the link you were exploring") | |
val pendingIntent = PendingIntent.getActivity(main,0,sendLinkIntent,PendingIntent.FLAG_UPDATE_CURRENT) | |
// Set the action button | |
AppCompatResources.getDrawable(main, R.drawable.close_icon)?.let { | |
DrawableCompat.setTint(it, Color.WHITE) | |
builder.setActionButton(it.toBitmap(),"This is your link",pendingIntent,false) | |
} | |
// Create the Custom Tabs Intent and launch the URL | |
val customTabsIntent: CustomTabsIntent = builder.build() |
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
// Handle any possible intents ************************************************************************** | |
// The URL is stored in the intent's data | |
val data: Uri? = intent?.data | |
// Figure out what to do based on the intent type | |
if (intent?.type?.startsWith("image/") == true) { | |
// Handle intents with image data ... | |
Log.d("Intent",intent?.type.toString()) | |
} else if (intent?.type == "text/plain") { | |
// Handle intents with text ... |
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
class DigBroadcastReceiver() : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
val uri: Uri? = intent.data | |
if (uri != null) { | |
Log.d("Broadcast URL",uri.toString()) | |
var toast = Toast.makeText(context, uri.toString(), Toast.LENGTH_SHORT) | |
val view = toast.view | |
view.background.setColorFilter(ContextCompat.getColor(context,R.color.red), PorterDuff.Mode.SRC_IN) | |
val text = view.findViewById(android.R.id.message) as TextView | |
text.setTextColor(ContextCompat.getColor(context, R.color.common_google_signin_btn_text_dark)) |