Skip to content

Instantly share code, notes, and snippets.

View harshavardhan98's full-sized avatar

P.Harshavardhan harshavardhan98

  • Citi
  • Chennai
View GitHub Profile
// assigning an onclick listener to a button
// declare a Button b1 above outside the onCreate
// assigns a button with id 'btn1' in the xml layout file to the variable b1
b1=findViewById(R.id.btn1);
// assigning an onClickListener to the Button b1
b1.setOnClickListener(new View.OnClickListener() {
@Override
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
public class adapter_name extends ArrayAdapter<class_name> {
//source:
//https://www.concretepage.com/android/android-alarm-clock-tutorial-to-schedule-and-cancel-alarmmanager-pendingintent-and-wakefulbroadcastreceiver-example
// permissions - add this in the manifest file
// <uses-permission android:name="android.permission.WAKE_LOCK"/>
//<receiver android:name=".AlarmReceiver"/> - add this to the manifest file
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent myIntent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);
lex programs repo - https://github.com/VandanaBaidya/Lex-Programs
https://github.com/3ZadeSSG/Lex-Yacc-Basics/blob/master/Problem%20Statements%20Scanned%20Copy.pdf
Setting up a callback interface when querying the DB:
https://stackoverflow.com/questions/42121771/handle-data-returned-by-an-async-task-firebase?rq=1
@harshavardhan98
harshavardhan98 / binary_search.cpp
Created March 24, 2019 06:15
cp code snippets
//https://stackoverflow.com/a/39100135/10664312
int bs_upper_bound(int a[], int n, int x) {
int l = 0;
int h = n; // Not n - 1
while (l < h) {
int mid = (l + h) / 2;
if (x >= a[mid]) {
l = mid + 1;
} else {
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="hellp"
@harshavardhan98
harshavardhan98 / Contact.java
Last active August 5, 2019 15:28
List View - Contains code to implement a list view with custom Adapter
public class Contact {
String name;
String message;
String dpUrl;
String time;
public Contact(String name, String message, String dpUrl, String time) {
this.name = name;
this.message = message;
@harshavardhan98
harshavardhan98 / BSNL()
Last active August 13, 2019 09:36
Bombit
public void BSNL(String phoneNo,Callback cb) {
OkHttpClient okHttpClient = new OkHttpClient();
String url="https://portal2.bsnl.in/myportal/validatemobile.do";
String referer_url = "https://portal2.bsnl.in/myportal/authorize.do";
MediaType parse = MediaType.parse("application/x-www-form-urlencoded");
okHttpClient.newCall(new Request.Builder().url(url)
.post(RequestBody.create(parse,"mobile=" + phoneNo))
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
public void initGoogleSignIn() {
mAuth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(fb.this, gso);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 111);