Skip to content

Instantly share code, notes, and snippets.

View sandeepyohans's full-sized avatar
🎯
Focusing

Sandeep Yohans sandeepyohans

🎯
Focusing
  • Hyderabad, India
View GitHub Profile
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sandeepyohans
sandeepyohans / WebViewWithBackForward
Last active August 23, 2018 11:59
Add back and forward button to WebView
webView = findViewById(R.id.webview_devotions);
//Button Initialization
backButton =(Button) findViewById(R.id.bt_back);
forwardButton =(Button) findViewById(R.id.bt_forward);
//Back Button Action
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@sandeepyohans
sandeepyohans / MainActivity.java
Last active October 30, 2023 10:42
Adding alert() support to a WebView - Android
/*
Retrieved from https://web.archive.org/web/20160516165158/http://lexandera.com/2009/01/adding-alert-support-to-a-webview/
*/
final WebView browser = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
browser.getSettings().setJavaScriptEnabled(true);
final Context myApp = this;
@sandeepyohans
sandeepyohans / MainActivity.java
Created April 8, 2019 07:17
Read Version number from Gradle build file
/**
* Called when an item in the navigation menu is selected.
*
* @param item The selected item
* @return true to display the item as the selected item
*/
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
@sandeepyohans
sandeepyohans / activity_main.xml
Created June 24, 2019 04:17
Shadow to text in TextView
.
.
.
<TextView
.
.
.
android:shadowColor="@color/text_shadow_color"
android:shadowDx="-2"
android:shadowDy="2"
@sandeepyohans
sandeepyohans / MySpinnerActivity.java
Created September 10, 2019 11:12
Create Spinner and populate data in it - Android
// Create a collection and initialize it with data
ArrayList<String> list = new ArrayList<>();
for (int i=0; i<10; i++) {
list.add("Item "+i);
}
// Create an adapter for Spinner
ArrayAdapter<String> spinAdapter = new ArrayAdapter<>(context,android.R.layout.simple_list_item_1, list);
@sandeepyohans
sandeepyohans / GetMonth.java
Created September 12, 2019 06:51
Get Current Month
DateFormat dateFormat = new SimpleDateFormat("MM");
Date date = new Date();
dateFormat.format(date);
@sandeepyohans
sandeepyohans / DemoDateFormating.java
Created September 17, 2019 09:40
Format Date and Increment it by 1 month
// Desired date pattern
String pattern = "MM-dd-yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String strDate;
// Current date
Date date = new Date();
// Current date in desired format
strDate = simpleDateFormat.format(date);
@sandeepyohans
sandeepyohans / AlertDialogWithProgressBar.java
Created September 19, 2019 09:40
Utility method to display AlertDialog with ProgressBar in Android
public AlertDialog.Builder getDialogProgressBar() {
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getContext()));
builder.setTitle("Loading...");
builder.setCancelable(false);
final ProgressBar progressBar = new ProgressBar(getContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
@sandeepyohans
sandeepyohans / CustomAlertActivity.java
Last active September 23, 2019 07:30
Add Custom Layout to AlertDialog Android
public void showCustomAlert() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.update_layout, null);
dialogBuilder.setView(dialogView);
EditText etName = (EditText) dialogView.findViewById(R.id.etName);
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();