How to get the contents of the website and put it the way we want in the layout of the Android application?

His strange question that they ask me, but curiosity is the best teacher, and I look forward to knowing and developing such an Android application.

My background in Android design is not very good , but right now I am using WebView for a website that responds to its work but it takes too much time to load and does not provide such convenience for the user. Here is the code I have:

Mainactivity

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;
    }

}

webview, Android. , , - , . , , .

, : Web site

, , : enter image description here

, -, - . . , WebView

​​, - . .

, , .

- , ,

!

+4
3

1:

-, /.

2:

-, , ImageView .

HTML , JSOUP

:

/- API . , . API RESTful -. API JSON. .

. ,

http://your_address/shopping/v1/get_product_info

enter image description here

JSON ,

{
    "error": false,
    "name": "ETC Solid Men 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"
        }
    ]
}
+4

// - "" . , / css ( ) , (js/css).

0

Api, api, json-, json, html xml json . , , , - , .

api: Amazon api Facebook api Soundcloud api

Etc

0

All Articles