SoFunction
Updated on 2025-04-09

Android uses AsyncTask asynchronous class to enlarge and reduce web content

This article shares the detailed code for AsyncTask asynchronous class to enlarge and reduce web content for your reference. The specific content is as follows

:

package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class WebActivity extends Activity {
 //Web browser private WebView webView;
 //Progress bar layout and web content main layout private RelativeLayout loadingLayout,webLayout;
 //Zoom in and out the controller private ZoomControls zoomControls; 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 (savedInstanceState);
 setContentView();
 //Initialize the page component webView = (WebView)findViewById();
 loadingLayout = (RelativeLayout)findViewById();
 webLayout = (RelativeLayout)findViewById();
 zoomControls = (ZoomControls)findViewById(); 
 WebSettings webSettings = ();
 //Setting can use js script (true);
 //Execute asynchronous process new MyAsyncTask().execute(""); 
 }
 private void reading(){
 String filePath = getIntent().getStringExtra("filePath");
 if (filePath != null) {
  //Read the file  (readWebDataToStringFromPath(filePath, new FileReadOverBack() {
  @Override
  public void fileReadOver() {
  }
  }), "text/html", HTTP.UTF_8);
 } else {
  new ().setTitle("What went wrong").setMessage("There was an error in obtaining the file path!").setPositiveButton("return", new OnClickListener() {
  @Override
  public void onClick(DialogInterface dialog, int which) {
   ();
  }
  });
 }
 }
 //Read web page data into a string variable private String readWebDataToStringFromPath(String path,final FileReadOverBack fileReadOverBack){
 File file = new File(path);
 StringBuffer stringBuffer = new StringBuffer();
 try {
  //Read the file content  FileInputStream inputStream = new FileInputStream(file);
  byte[] bytes = new byte[1024];
  int readCount = 0;
  while ((readCount = (bytes)) > 0) {
  (new String(bytes, 0, readCount));
  }
  ();
 } catch (FileNotFoundException e) {
  return "The file does not exist!";
 } catch (IOException e) {
  return "File reading error!";
 }
 return ();
 } 
 interface FileReadOverBack{
 void fileReadOver();
 }
 //Asynchronous processing class class MyAsyncTask extends AsyncTask<String, String, String>{
 //The function executed first @Override
 protected void onPreExecute() {
  ();
  ();
  ();
 }
 //Background execution @Override
 protected String doInBackground(String... params) {
  reading();
  return null;
 } 
 @Override
 protected void onPostExecute(String result) {
  (result);
  //Set the load progress bar to hide  ();
  //Set the browser content to be visible  ();  
  // Zoom in button  (new () {
  //Enlarge the content of the web page  @Override
  public void onClick(View v) {
   ();
  }
  });
  // Zoom out button  (new () { 
  //Shrink the content of the web page  @Override
  public void onClick(View v) {
   ();
  }
  });
 } 
 }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.