Java – How do I get website content and put it into the android app layout the way we want?

How do I get website content and put it into the android app layout the way we want?… here is a solution to the problem.

How do I get website content and put it into the android app layout the way we want?

I

was asked such strange questions, but curiosity is the best teacher, and I would very much like to know and develop such an Android application.

My background in android app development wasn’t great, but right now I’m using WebView to respond to the website it works on, but it takes too much time to load and doesn’t provide as much convenience to the user. Here is my code :

Main activity

package com.testWebview.deep;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

private WebView webview;
    private ProgressDialog progress;

public void runTask(){
        ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        if(connec!=null && (connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) || (connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)) {
            webview = (WebView)findViewById(R.id.MainWebView);
            WebSettings webSettings = webview.getSettings();
            webSettings.setJavaScriptEnabled(true);
            webSettings.setLoadsImagesAutomatically(true);
            webSettings.setLoadWithOverviewMode(true);
            webSettings.setDomStorageEnabled(true);
            webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
            webSettings.setAllowFileAccess(true);
            webSettings.setBuiltInZoomControls(true);
            webSettings.setUseWideViewPort(true);
            loadingC();
            webview.setWebViewClient(new WebViewClient(){

@Override
                public void onPageStarted(WebView view, String url,Bitmap favicon){
                    if(!progress.isShowing()){
                        loadingC();
                    }

}
                @Override
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    if(progress.isShowing()){progress.dismiss(); }
                    checkConnection();
                    webview.loadUrl("file:///android_asset/error.html");
                }

@Override
                public void onPageFinished(WebView view, String url) {
                    if(progress.isShowing()) {
                        progress.dismiss();
                    }
                }
            });
            webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            webview.setScrollbarFadingEnabled(false);
            webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            webview.loadUrl("http://www.bharatcoupons.com/");
        }
        else{
            checkConnection();
        }
    }

public void checkConnection(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Error");
        builder.setMessage("Please make sure your connected to internet!");
        builder.setCancelable(false);
        builder.setPositiveButton("retry", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
                runTask();
            }

});
        builder.show();
    }

public void loadingC(){
        progress = ProgressDialog.show(this, "Loading", "Please wait for a moment...");
    }

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        runTask();
    }

@Override
    public void onBackPressed(){
        if(webview.canGoBack()){
            webview.goBack();
        }else{
            super.onBackPressed();
        }
    }

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
         Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
         Handle action bar item clicks here. The action bar will
         automatically handle clicks on the Home/Up button, so long
         as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

return super.onOptionsItemSelected(item);
    }

private class MyAppWebViewClient extends WebViewClient{

}
}

MyAppWebViewClient

package com.testWebview.deep;

import android.content.Intent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.net.Uri;

public class MyAppWebViewClient extends WebViewClient{

@Override
    public boolean shouldOverrideUrlLoading(WebView view, String url){
        if(Uri.parse(url).getHost().endsWith("bharatcoupons.com")){
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }

}

The above code works fine on WebView, but it’s a slow and unprofessional way of developing Android apps. Now what I want to do is take the website content and put it into the application framework I want. I will show you an example detailing everything I want to do.

Let’s say my website looks like this:
An website

What method or method, trick should I follow to make my application like this:
enter image description here

As far as I know, it’s not a WebView that displays website content directly into an application. When swapping left or right, it shows you the next item. Put the entire Web site into this application without using WebView

They make such frameworks to take content from websites and put them into apps. I want to do this.

I

don’t want code, but where should I start and what method or technique should I use to achieve it.

The referring websites and apps I use are for educational purposes only and have no other intent

Thanks in advance!

Solution

Method 1:

Use a responsive website that automatically adapts to mobile/tabbed screens.

Method two:

Parse web documents, such as images and text, and then display them in ImageView or other UI content.

For HTML parsing, you can use 3rd-party libraries such as JSOUP

Best Method:

Today, almost all companies/online services use APIs to communicate between networks and other platforms. It makes all data consistent and flexible because all information comes from the same source. Create a RESTful API for your web service. Call the API and get the data in JSON format. Parse the information later and display it in View.

For example, to get information about a specific product

http://your_address/shopping/v1/get_product_info

enter image description here

The result in JSON format might look like this

{
    "error": false,
    "name": "ETC Solid Men's Polo Neck -Tshirt",
    "description": "Your pruduct description",
    "images": [
        {
            "preview1": "http://yoururl.com/images/preview1"
        },
        {
            "preview2": "http://yoururl.com/images/preview2"
        },
        {
            "preview3": "http://yoururl.com/images/preview3"
        },
        {
            "preview4": "http://yoururl.com/images/preview4"
        }
    ]
}

Related Problems and Solutions