-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainActivity.java
69 lines (62 loc) · 2.56 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.example.gourav.pdf;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class MainActivity extends AppCompatActivity {
ProgressBar bar;
String s;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DatabaseReference mref= FirebaseDatabase.getInstance().getReference();
mref=mref.child("root").child("url");
bar= (ProgressBar)findViewById(R.id.progressBar2);
if(isNetworkAvailable())
{
mref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
s=dataSnapshot.child("Coding").getValue().toString();
WebView mWebView=new WebView(MainActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+s);
setContentView(mWebView);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
else
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("No Internet Connection").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void onClick(DialogInterface dialog, int id) {
finishAffinity();
}
}).show();
}
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
}