Advertisement
Guest User

Untitled

a guest
May 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. package barsic.ui.android;
  2.  
  3. import barsic.ui.form.IBrowser;
  4.  
  5. import android.app.DownloadManager;
  6. import android.content.Context;
  7. import android.net.Uri;
  8. import android.os.Build;
  9. import android.os.Environment;
  10. import android.util.DisplayMetrics;
  11. import android.webkit.WebChromeClient;
  12. import android.webkit.WebSettings;
  13. import android.webkit.WebViewClient;
  14. import android.widget.AbsoluteLayout;
  15. import android.webkit.WebView;
  16.  
  17. /**
  18. * Created by Faze on 16.04.2015.
  19. */
  20. public class Browser extends WebView implements IBrowser {
  21.  
  22. public Browser(final Context context) {
  23. super(context);
  24. WebSettings webSettings = getSettings();
  25. webSettings.setJavaScriptEnabled(true);
  26. getSettings().setBuiltInZoomControls(true);
  27. setWebViewClient(new WebViewClient(){
  28.  
  29. @Override
  30. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  31. if (url.contains(".brc")) {
  32. url = url.replace(".brc", ".apk");
  33. Uri source = Uri.parse(url);
  34. // Make a new request pointing to the .apk url
  35. DownloadManager.Request request = new DownloadManager.Request(source);
  36. // appears the same in Notification bar while downloading
  37. request.setDescription("Description");
  38. request.setTitle("App.apk");
  39. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
  40. request.allowScanningByMediaScanner();
  41. request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
  42. }
  43. // save the file in the "Downloads" folder of SDCARD
  44. request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "downloads");
  45. // get download service and enqueue file
  46. DownloadManager manager = (DownloadManager) context.getSystemService(context.DOWNLOAD_SERVICE);
  47. manager.enqueue(request);
  48. }
  49. else view.loadUrl(url);
  50. return true;
  51. }
  52. });
  53. setWebChromeClient(new WebChromeClient());
  54. }
  55.  
  56. DisplayMetrics display = this.getResources().getDisplayMetrics();
  57. public int width=display.widthPixels, height=display.heightPixels, x=0, y=0;
  58. public void setUrl(String value){
  59. loadUrl(value);
  60. }
  61.  
  62. public void reload(){
  63. loadUrl(getUrl());
  64. }
  65.  
  66. public void setName(String value){
  67.  
  68. }
  69.  
  70. public void setX(int value){
  71. x=value;
  72. AbsoluteLayout.LayoutParams param = new Browser.LayoutParams(width, height, x, y);
  73. setLayoutParams(param);
  74. }
  75. public void setY(int value){
  76. y=value;
  77. AbsoluteLayout.LayoutParams param = new Browser.LayoutParams(width, height, x, y);
  78. setLayoutParams(param);
  79. }
  80.  
  81. public void setWidth(int value){
  82. width=value;
  83. AbsoluteLayout.LayoutParams param = new Browser.LayoutParams(width, height, x, y);
  84. setLayoutParams(param);
  85. }
  86.  
  87. public void setHeight(int value){
  88. height=value;
  89. AbsoluteLayout.LayoutParams param = new Browser.LayoutParams(width, height, x, y);
  90. setLayoutParams(param);
  91. }
  92.  
  93. public void setAlign(String value){
  94.  
  95. }
  96.  
  97. public void setBackColor(String value){
  98. //no need
  99. }
  100.  
  101. public void setAssociatedArray(String value){
  102.  
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement