Question

Exercise 2: Develop a file loading app as shown below: User enters URL in an EditText On the on click listener of the load bu

Develop a file loading app as shown below:

User enters URL in an EditText. On the on click listener of the load button, url’s data should be read into a html file in a separate thread as an asynchronous task.  Display a progress bar too. On the post execute method, display done text in a text view.

On the click of Display button, data that’s stored in html file gets retrieved and displayed in text view.

USING ANDRIOD STUDIO / JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

actually i have made the same project before i have complete source code i m uploading here you can copy paste this code easily from here below is the code ---------------------------------------------------------------------------------------------------------------

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.web_view_demo"

    android:versionCode="1"

    android:versionName="1.0" >

    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="22" />

    <!-- Permission required for loading urls -->

    <uses-permission android:name="android.permission.INTERNET" />

    

    <!-- Permission required for checking internet connection -->

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name=".WebActivity"

            android:theme="@android:style/Theme.NoTitleBar" >

        </activity>

        <activity

            android:name="com.web_view_demo.MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>

</manifest>

-----------------------------------------------------------activity_main.xml file :---------------------------------------------------------------------------

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <TextView

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:gravity="center"

        android:padding="10dp"

        android:text="@string/text"

        android:textColor="#0587d9"

        android:textSize="18sp"

        android:textStyle="bold" />

    <EditText

        android:id="@+id/url"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_marginLeft="5dp"

        android:layout_marginRight="5dp"

        android:gravity="center"

        android:hint="@string/enter_url"

        android:inputType="textUri"

        android:padding="10dp"

        android:singleLine="true"

        android:textColor="#000000"

        android:textSize="15sp" />

    <Button

        android:id="@+id/open_url"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:gravity="center"

        android:padding="5dp"

        android:text="@string/open_url"

        android:textSize="15sp" />

    <!-- Web View to open URL -->

    <WebView

        android:id="@+id/webview"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent" />

</LinearLayout>

------------------------------------------------------------------ MainActivity.java--------------------------------------------------------------------------

package com.web_view_demo;

import android.app.ProgressDialog;

import android.content.Context;

import android.net.ConnectivityManager;

import android.net.NetworkInfo;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.util.Patterns;

import android.view.View;

import android.view.View.OnClickListener;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private static WebView web;

private static ProgressDialog dialog;

private static EditText enter_url;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

web = (WebView) findViewById(R.id.webview);

enter_url = (EditText) findViewById(R.id.url);

// Implement click listener over button

findViewById(R.id.open_url).setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

String url = enter_url.getText().toString();// Get editext text

// into string

// Check if string url is not null

if (url.equals("") || url.length() == 0)

// If null then display toast

Toast.makeText(MainActivity.this, "Please enter a url.",

Toast.LENGTH_SHORT).show();

else if // Check if entered url is valid or not and if it is not

// valid then show toast

(!Patterns.WEB_URL.matcher(url).matches())

Toast.makeText(MainActivity.this,

"Entered URL is not Valid.", Toast.LENGTH_SHORT)

.show();

else {

// Check if interent is there or not

if (isConnectingToInternet())

// if both above conditions falls then load url

loadUrl(url);

else

Toast.makeText(MainActivity.this,

"There is no Interent connection.",

Toast.LENGTH_SHORT).show();

}

}

});

}

// Load url method in webview

private void loadUrl(String url) {

// Progressdialog to show when url is loading

dialog = new ProgressDialog(MainActivity.this);

dialog.setMessage("Please wait..nWhile loading URL");

dialog.setCancelable(true);// Make it cancelable true so that user can

// dismiss it anytime

web.setWebViewClient(new WebViewClient() {

@Override

public void onPageFinished(WebView view, String url) {

// On page finished loading dismiss dialog

if (dialog.isShowing()) {

dialog.dismiss();

}

}

});

dialog.show();// Show dialog

web.loadUrl(url);// Load url into webview

web.getSettings().setJavaScriptEnabled(true);// Enable javascript

}

// Return status of internet connection

private boolean isConnectingToInternet() {

ConnectivityManager connectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

if (connectivity != null) {

NetworkInfo[] info = connectivity.getAllNetworkInfo();

if (info != null)

for (int i = 0; i < info.length; i++)

if (info[i].getState() == NetworkInfo.State.CONNECTED) {

return true;

}

}

return false;

}

}

Add a comment
Know the answer?
Add Answer to:
Develop a file loading app as shown below: User enters URL in an EditText. On the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • for Javascript, JQuery When the page is first opened a user will see the name field...

    for Javascript, JQuery When the page is first opened a user will see the name field and the three vacation images to the left of the page. The page should behave according to the following rules. 1. When a user's mouse pointer goes over any image, that image's border will change to be "outset 10px" and when the mouse pointer leaves that image it's border will change to "none". 2. When the user clicks a "Vacation" image on the left,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT