Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.63 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. tools:context="net.panomaps.guide.Website">
  9.  
  10.  
  11. <android.support.v4.widget.SwipeRefreshLayout
  12. android:id="@+id/swipeContainer"
  13. android:layout_width="match_parent"
  14. android:layout_height="match_parent"
  15. app:layout_behavior="@string/appbar_scrolling_view_behavior">
  16.  
  17.  
  18. <WebView
  19. android:id="@+id/webView"
  20. android:layout_width="match_parent"
  21. android:layout_height="match_parent">
  22.  
  23. </WebView>
  24.  
  25. </android.support.v4.widget.SwipeRefreshLayout>
  26.  
  27.  
  28. <FrameLayout
  29. android:id="@+id/frameLayout"
  30. android:layout_width="match_parent"
  31. android:layout_height="3dp"
  32. android:background="@android:color/transparent">
  33.  
  34. <ProgressBar
  35. android:id="@+id/progressBar"
  36. style="?android:attr/progressBarStyleHorizontal"
  37. android:layout_width="match_parent"
  38. android:layout_height="8dp"
  39. android:layout_gravity="top"
  40. android:layout_marginTop="-3dp"
  41. android:background="@android:color/transparent"
  42. android:progress="20"
  43. android:progressDrawable="@drawable/custom_progress" />
  44.  
  45. </FrameLayout>
  46.  
  47. </RelativeLayout>
  48.  
  49. import android.annotation.SuppressLint;
  50. import android.content.Context;
  51. import android.content.DialogInterface;
  52. import android.content.Intent;
  53. import android.net.ConnectivityManager;
  54. import android.net.NetworkInfo;
  55. import android.net.Uri;
  56. import android.os.Bundle;
  57. import android.support.v4.widget.SwipeRefreshLayout;
  58. import android.support.v7.app.AlertDialog;
  59. import android.support.v7.app.AppCompatActivity;
  60. import android.util.Log;
  61. import android.view.ContextThemeWrapper;
  62. import android.view.View;
  63. import android.webkit.WebChromeClient;
  64. import android.webkit.WebSettings;
  65. import android.webkit.WebView;
  66. import android.webkit.WebViewClient;
  67. import android.widget.FrameLayout;
  68. import android.widget.ProgressBar;
  69.  
  70. import java.io.File;
  71.  
  72.  
  73.  
  74. public class Website extends AppCompatActivity {
  75.  
  76. private SwipeRefreshLayout mySwipeRefreshLayout;
  77. private WebView webView;
  78. private ProgressBar progressbar;
  79. private FrameLayout frameLayout;
  80.  
  81. private static boolean deleteDir(File dir) {
  82. if (dir != null && dir.isDirectory()) {
  83. String[] children = dir.list();
  84. for (String aChildren : children) {
  85. boolean success = deleteDir(new File(dir, aChildren));
  86. if (!success) {
  87. return false;
  88. }
  89. }
  90. }
  91.  
  92. return dir == null || dir.delete();
  93. }
  94.  
  95. @SuppressLint("SetJavaScriptEnabled")
  96. @Override
  97. protected void onCreate(Bundle savedInstanceState) {
  98. super.onCreate(savedInstanceState);
  99. setContentView(R.layout.website);
  100.  
  101. frameLayout = findViewById(R.id.frameLayout);
  102. progressbar = findViewById(R.id.progressBar);
  103.  
  104. progressbar.setMax(100);
  105.  
  106. webView = findViewById(R.id.webView);
  107. mySwipeRefreshLayout = this.findViewById(R.id.swipeContainer);
  108.  
  109. mySwipeRefreshLayout.setOnRefreshListener(
  110. new SwipeRefreshLayout.OnRefreshListener() {
  111. @Override
  112. public void onRefresh() {
  113. if (!haveNetworkConnection()) {
  114. android.app.AlertDialog.Builder Checkbuilder = new android.app.AlertDialog.Builder(Website.this);
  115. Checkbuilder.setMessage("Por favor conecte-se à internet!");
  116. android.app.AlertDialog alert = Checkbuilder.create();
  117. alert.show();
  118. } else {
  119. if (haveNetworkConnection()) {
  120. webView.reload();
  121. }
  122. }
  123. }
  124. }
  125. );
  126.  
  127.  
  128. webView.setWebViewClient(new HelpClient());
  129. WebSettings webSettings = webView.getSettings();
  130. webSettings.setJavaScriptEnabled(true);
  131.  
  132. webView.setWebChromeClient(new WebChromeClient() {
  133. public void onProgressChanged(WebView view, int progress) {
  134. frameLayout.setVisibility(View.VISIBLE);
  135. progressbar.setProgress(progress);
  136.  
  137. setTitle("Carregando...");
  138.  
  139. if (progress == 100) {
  140. frameLayout.setVisibility(View.GONE);
  141. setTitle(view.getTitle());
  142. }
  143. super.onProgressChanged(view, progress);
  144. }
  145. });
  146.  
  147. webView.getSettings().setJavaScriptEnabled(true);
  148. webView.clearCache(true);
  149. webView.clearHistory();
  150. webView.setVerticalScrollBarEnabled(false);
  151. webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
  152. webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  153. webView.getSettings().setAppCacheEnabled(true);
  154. webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  155. webView.getSettings().setLoadWithOverviewMode(true);
  156. webView.getSettings().setUseWideViewPort(true);
  157. String userAgent = "Opera/9.80 (Android 4.1.2; Linux; Opera Mobi/ADR-1305251841) Presto/2.11.355 Version/12.10";
  158. webView.getSettings().setUserAgentString(userAgent);
  159. webSettings.setPluginState(WebSettings.PluginState.ON);
  160. webSettings.setSupportMultipleWindows(true);
  161. webSettings.setDomStorageEnabled(true);
  162. webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
  163. webSettings.setUseWideViewPort(true);
  164. webSettings.setSavePassword(true);
  165. webSettings.setSaveFormData(true);
  166. webSettings.setEnableSmoothTransition(true);
  167. progressbar.setProgress(0);
  168.  
  169.  
  170. if (!haveNetworkConnection()) {
  171. android.app.AlertDialog.Builder Checkbuilder = new android.app.AlertDialog.Builder(Website.this);
  172. Checkbuilder.setMessage("Por favor conecte-se à internet!");
  173. android.app.AlertDialog alert = Checkbuilder.create();
  174. alert.show();
  175. } else {
  176. webView.loadUrl("https://panomaps.net/");
  177. }
  178.  
  179. webView.setWebViewClient(new WebViewClient() {
  180. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  181. String url2 = "https://panomaps.net";
  182. // all links within ur site will be open inside the webview
  183. if (url != null && url.startsWith(url2)) {
  184. return false;
  185. }
  186. // all links that points outside the site will be open in a normal android browser
  187. else {
  188. view.getContext().startActivity(
  189. new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  190. return true;
  191. }
  192. }
  193.  
  194. @Override
  195. public void onPageFinished(WebView view, String url) {
  196. mySwipeRefreshLayout.setRefreshing(false);
  197. super.onPageFinished(view, url);
  198. }
  199.  
  200. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  201. view.loadUrl("about:blank");
  202. }
  203. });
  204. }
  205.  
  206. private boolean haveNetworkConnection() {
  207. ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
  208. NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
  209. return activeNetworkInfo != null;
  210.  
  211. }
  212.  
  213.  
  214. @Override
  215. public void onBackPressed() {
  216. if (webView.canGoBack()) {
  217. webView.goBack();
  218.  
  219. } else {
  220. ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.PanomapsTheme);
  221. AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
  222. builder.setMessage("Fechar o Panomaps?")
  223. .setCancelable(false)
  224. .setPositiveButton("sim", new DialogInterface.OnClickListener() {
  225. public void onClick(DialogInterface dialog, int id) {
  226. finish();
  227. }
  228. })
  229. .setNegativeButton("Não", new DialogInterface.OnClickListener() {
  230. public void onClick(DialogInterface dialog, int id) {
  231. dialog.cancel();
  232. }
  233. });
  234. AlertDialog alert = builder.create();
  235. alert.show();
  236. }
  237. }
  238.  
  239. @Override
  240. protected void onDestroy() {
  241. // TODO Auto-generated method stub
  242. super.onDestroy();
  243. clearApplicationData();
  244. }
  245.  
  246. private void clearApplicationData() {
  247. File cache = getCacheDir();
  248. File appDir = new File(cache.getParent());
  249. if (appDir.exists()) {
  250. String[] children = appDir.list();
  251. for (String s : children) {
  252. if (!s.equals("lib")) {
  253. deleteDir(new File(appDir, s));
  254. Log.i("EEEEEERRRRRRROOOOOORRRR", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
  255. }
  256. }
  257. }
  258. }
  259.  
  260. private class HelpClient extends WebViewClient {
  261. @Override
  262. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  263. view.loadUrl(url);
  264. frameLayout.setVisibility(View.VISIBLE);
  265.  
  266. return true;
  267. }
  268. }
  269. }
  270.  
  271. import android.annotation.SuppressLint;
  272. import android.content.Context;
  273. import android.content.DialogInterface;
  274. import android.content.Intent;
  275. import android.net.ConnectivityManager;
  276. import android.net.NetworkInfo;
  277. import android.net.Uri;
  278. import android.os.Bundle;
  279. import android.support.v4.widget.SwipeRefreshLayout;
  280. import android.support.v7.app.AlertDialog;
  281. import android.support.v7.app.AppCompatActivity;
  282. import android.util.Log;
  283. import android.view.ContextThemeWrapper;
  284. import android.view.View;
  285. import android.webkit.WebChromeClient;
  286. import android.webkit.WebSettings;
  287. import android.webkit.WebView;
  288. import android.webkit.WebViewClient;
  289. import android.widget.FrameLayout;
  290. import android.widget.ProgressBar;
  291.  
  292. import java.io.File;
  293.  
  294.  
  295.  
  296. public class Website extends AppCompatActivity {
  297.  
  298. private SwipeRefreshLayout mySwipeRefreshLayout;
  299. private WebView webView;
  300. private ProgressBar progressbar;
  301. private FrameLayout frameLayout;
  302.  
  303. private static boolean deleteDir(File dir) {
  304. if (dir != null && dir.isDirectory()) {
  305. String[] children = dir.list();
  306. for (String aChildren : children) {
  307. boolean success = deleteDir(new File(dir, aChildren));
  308. if (!success) {
  309. return false;
  310. }
  311. }
  312. }
  313.  
  314. return dir == null || dir.delete();
  315. }
  316.  
  317. @SuppressLint("SetJavaScriptEnabled")
  318. @Override
  319. protected void onCreate(Bundle savedInstanceState) {
  320. super.onCreate(savedInstanceState);
  321. setContentView(R.layout.website);
  322.  
  323. frameLayout = findViewById(R.id.frameLayout);
  324. progressbar = findViewById(R.id.progressBar);
  325.  
  326. progressbar.setMax(100);
  327.  
  328. webView = findViewById(R.id.webView);
  329. mySwipeRefreshLayout = this.findViewById(R.id.swipeContainer);
  330.  
  331. mySwipeRefreshLayout.setOnRefreshListener(
  332. new SwipeRefreshLayout.OnRefreshListener() {
  333. @Override
  334. public void onRefresh() {
  335. if (!haveNetworkConnection()) {
  336. android.app.AlertDialog.Builder Checkbuilder = new android.app.AlertDialog.Builder(Website.this);
  337. Checkbuilder.setMessage("Por favor conecte-se à internet!");
  338. android.app.AlertDialog alert = Checkbuilder.create();
  339. alert.show();
  340. } else {
  341. if (haveNetworkConnection()) {
  342. webView.reload();
  343. }
  344. }
  345. }
  346. }
  347. );
  348.  
  349.  
  350. webView.setWebViewClient(new HelpClient());
  351. WebSettings webSettings = webView.getSettings();
  352. webSettings.setJavaScriptEnabled(true);
  353.  
  354. webView.setWebChromeClient(new WebChromeClient() {
  355. public void onProgressChanged(WebView view, int progress) {
  356. frameLayout.setVisibility(View.VISIBLE);
  357. progressbar.setProgress(progress);
  358.  
  359. setTitle("Carregando...");
  360.  
  361. if (progress == 100) {
  362. frameLayout.setVisibility(View.GONE);
  363. setTitle(view.getTitle());
  364. }
  365. super.onProgressChanged(view, progress);
  366. }
  367. });
  368.  
  369. webView.getSettings().setJavaScriptEnabled(true);
  370. webView.clearCache(true);
  371. webView.clearHistory();
  372. webView.setVerticalScrollBarEnabled(false);
  373. webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
  374. webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  375. webView.getSettings().setAppCacheEnabled(true);
  376. webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  377. webView.getSettings().setLoadWithOverviewMode(true);
  378. webView.getSettings().setUseWideViewPort(true);
  379. String userAgent = "Opera/9.80 (Android 4.1.2; Linux; Opera Mobi/ADR-1305251841) Presto/2.11.355 Version/12.10";
  380. webView.getSettings().setUserAgentString(userAgent);
  381. webSettings.setPluginState(WebSettings.PluginState.ON);
  382. webSettings.setSupportMultipleWindows(true);
  383. webSettings.setDomStorageEnabled(true);
  384. webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
  385. webSettings.setUseWideViewPort(true);
  386. webSettings.setSavePassword(true);
  387. webSettings.setSaveFormData(true);
  388. webSettings.setEnableSmoothTransition(true);
  389. progressbar.setProgress(0);
  390.  
  391.  
  392. if (!haveNetworkConnection()) {
  393. android.app.AlertDialog.Builder Checkbuilder = new android.app.AlertDialog.Builder(Website.this);
  394. Checkbuilder.setMessage("Por favor conecte-se à internet!");
  395. android.app.AlertDialog alert = Checkbuilder.create();
  396. alert.show();
  397. } else {
  398. webView.loadUrl("https://panomaps.net/");
  399. }
  400.  
  401. webView.setWebViewClient(new WebViewClient() {
  402. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  403. if (url != null && url.startsWith("https://panomaps.net/")) {
  404. //open url contents in webview
  405. return false;
  406. }
  407. if (url != null && url.equals("https://panomaps.net/wp-login.php?loginFacebook=1%26redirect=https://panomaps.net")) {
  408. //open url contents in webview
  409. return false;
  410. }
  411. if (url != null && url.startsWith("https://www.facebook.com/")) {
  412. //open url contents in webview
  413. return false;
  414. }
  415. if (url != null && url.startsWith("https://m.facebook.com/")) {
  416. //open url contents in webview
  417. return false;
  418. }
  419. if (url != null && url.startsWith("https://mpago.la/")) {
  420. //open url contents in webview
  421. return false;
  422. }
  423. if (url != null && url.startsWith("https://www.mercadopago.com/")) {
  424. //open url contents in webview
  425. return false;
  426. }
  427. // all links that points outside the site will be open in a normal android browser
  428. else {
  429. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  430. startActivity(intent);
  431. return true;
  432. }
  433. }
  434.  
  435. @Override
  436. public void onPageFinished(WebView view, String url) {
  437. mySwipeRefreshLayout.setRefreshing(false);
  438. super.onPageFinished(view, url);
  439. }
  440.  
  441. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  442. view.loadUrl("about:blank");
  443. }
  444. });
  445. }
  446.  
  447. private boolean haveNetworkConnection() {
  448. ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
  449. NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
  450. return activeNetworkInfo != null;
  451.  
  452. }
  453.  
  454.  
  455. @Override
  456. public void onBackPressed() {
  457. if (webView.canGoBack()) {
  458. webView.goBack();
  459.  
  460. } else {
  461. ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.PanomapsTheme);
  462. AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
  463. builder.setMessage("Fechar o Panomaps?")
  464. .setCancelable(false)
  465. .setPositiveButton("sim", new DialogInterface.OnClickListener() {
  466. public void onClick(DialogInterface dialog, int id) {
  467. finish();
  468. }
  469. })
  470. .setNegativeButton("Não", new DialogInterface.OnClickListener() {
  471. public void onClick(DialogInterface dialog, int id) {
  472. dialog.cancel();
  473. }
  474. });
  475. AlertDialog alert = builder.create();
  476. alert.show();
  477. }
  478. }
  479.  
  480. @Override
  481. protected void onDestroy() {
  482. // TODO Auto-generated method stub
  483. super.onDestroy();
  484. clearApplicationData();
  485. }
  486.  
  487. private void clearApplicationData() {
  488. File cache = getCacheDir();
  489. File appDir = new File(cache.getParent());
  490. if (appDir.exists()) {
  491. String[] children = appDir.list();
  492. for (String s : children) {
  493. if (!s.equals("lib")) {
  494. deleteDir(new File(appDir, s));
  495. Log.i("EEEEEERRRRRRROOOOOORRRR", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
  496. }
  497. }
  498. }
  499. }
  500.  
  501. private class HelpClient extends WebViewClient {
  502. @Override
  503. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  504. view.loadUrl(url);
  505. frameLayout.setVisibility(View.VISIBLE);
  506.  
  507. return true;
  508. }
  509. }
  510. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement