Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.36 KB | None | 0 0
  1. public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
  2.  
  3. final String LOG_TAG = "myLogs";
  4.  
  5. private WebView mWebView;
  6. private SwipeRefreshLayout mSwipeRefreshLayout;
  7. public String user = null;
  8. public String pass = null;
  9. private static final String TAG = MainActivity.class.getSimpleName();
  10. private String mCM;
  11. private ValueCallback<Uri> mUM;
  12. private ValueCallback<Uri[]> mUMA;
  13. private final static int FCR = 1;
  14. public Dialog login;
  15.  
  16. private class SSLTolerentWebViewClient extends WebViewClient {
  17.  
  18. @Override
  19. public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
  20.  
  21. return super.shouldInterceptRequest(view, request);
  22. }
  23.  
  24.  
  25. @Override
  26. public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
  27. Log.e("auth","recieved");
  28. if (user != null && pass != null) {
  29. handler.proceed(user, pass);
  30. user = null;
  31. pass = null;
  32. }
  33. super.onReceivedHttpAuthRequest(view, handler, host, realm);
  34. }
  35.  
  36. @Override
  37. public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
  38. Log.e("ProcessPayment", "onReceivedError = " + error.toString());
  39. super.onReceivedError(view, request, error);
  40. }
  41.  
  42.  
  43.  
  44. @Override
  45. public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
  46. Log.e("ProcessPayment", "onReceivedHttpError = ");
  47. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  48. errorResponse.getReasonPhrase();
  49. }
  50.  
  51. if(errorResponse != null && errorResponse.getResponseHeaders().get("Content-Length").equals("486")) {
  52. super.onReceivedHttpError(view, request, errorResponse);
  53. }
  54. }
  55.  
  56. @Override
  57. public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
  58. Log.d(LOG_TAG, "SSL IGNORE");
  59. handler.proceed();
  60. }
  61.  
  62. @Override
  63. public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  64. super.onReceivedError(view, errorCode, description, failingUrl);
  65. }
  66. }
  67.  
  68. @Override
  69. protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  70. super.onActivityResult(requestCode, resultCode, intent);
  71. if (Build.VERSION.SDK_INT >= 15) {
  72. Uri[] results = null;
  73. if (resultCode == Activity.RESULT_OK) {
  74. if (requestCode == FCR) {
  75. if (null == mUMA) {
  76. return;
  77. }
  78. if (intent == null) {
  79. if (mCM != null) {
  80. results = new Uri[]{Uri.parse(mCM)};
  81. }
  82. } else {
  83. String dataString = intent.getDataString();
  84. if (dataString != null) {
  85. results = new Uri[]{Uri.parse(dataString)};
  86. }
  87. }
  88. }
  89. }
  90. mUMA.onReceiveValue(results);
  91. mUMA = null;
  92. } else {
  93. if (requestCode == FCR) {
  94. if (null == mUM) return;
  95. Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
  96. mUM.onReceiveValue(result);
  97. mUM = null;
  98. }
  99. }
  100. }
  101.  
  102. @Override
  103. public void onCreate(Bundle savedInstanceState) {
  104. super.onCreate(savedInstanceState);
  105. setContentView(activity_main);
  106.  
  107. mWebView = (WebView) findViewById(webView);
  108. mWebView.setWebViewClient(new SSLTolerentWebViewClient());
  109. mWebView.getSettings().setAppCacheEnabled(true);
  110. mWebView.getSettings().setDatabaseEnabled(true);
  111. mWebView.getSettings().setDomStorageEnabled(true);
  112. mWebView.getSettings().setGeolocationEnabled(true);
  113. mWebView.getSettings().setLoadWithOverviewMode(true);
  114. mWebView.getSettings().setAllowContentAccess(true);
  115. mWebView.getSettings().setAllowFileAccess(true);
  116. mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
  117. mWebView.getSettings().setUseWideViewPort(true);
  118. mWebView.getSettings().setJavaScriptEnabled(true);
  119. mWebView.getSettings().setSaveFormData(false);
  120. mWebView.getSettings().setSavePassword(true);
  121. mWebView.getSettings().setGeolocationDatabasePath(getFilesDir().getPath());
  122. mWebView.getSettings().setDatabaseEnabled(true);
  123. mWebView.getSettings().setDomStorageEnabled(true);
  124. mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  125. mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  126. mWebView.setWebChromeClient(new WebChromeClient() {
  127.  
  128. //For Android 3.0+
  129. public void openFileChooser(ValueCallback<Uri> uploadMsg) {
  130. Log.d(LOG_TAG, "OPEN IMAGE");
  131. mUM = uploadMsg;
  132. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  133. i.addCategory(Intent.CATEGORY_OPENABLE);
  134. i.setType("*/*");
  135. MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR);
  136. }
  137.  
  138. // For Android 3.0+, above method not supported in some android 3+ versions, in such case we use this
  139. public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
  140. Log.d(LOG_TAG, "OPEN IMAGE");
  141. // mUM = uploadMsg;
  142. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  143. i.addCategory(Intent.CATEGORY_OPENABLE);
  144. i.setType("image/*");
  145. MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Browser"), FCR);
  146. }
  147.  
  148. //For Android 4.1+
  149. public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
  150. Log.d(LOG_TAG, "OPEN IMAGE");
  151. mUM = uploadMsg;
  152. Intent i = new Intent(Intent.ACTION_GET_CONTENT);
  153. i.addCategory(Intent.CATEGORY_OPENABLE);
  154. i.setType("image/*");
  155. MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FCR);
  156. }
  157.  
  158. //For Android 5.0+
  159. public boolean onShowFileChooser(
  160.  
  161. WebView webView, ValueCallback<Uri[]> filePathCallback,
  162. WebChromeClient.FileChooserParams fileChooserParams) {
  163. if (mUMA != null) {
  164. mUMA.onReceiveValue(null);
  165. }
  166. Log.d(LOG_TAG, "OPEN IMAGE");
  167. mUMA = filePathCallback;
  168. Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  169. if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
  170. File photoFile = null;
  171. try {
  172. photoFile = createImageFile();
  173. takePictureIntent.putExtra("PhotoPath", mCM);
  174. } catch (IOException ex) {
  175. Log.e(TAG, "Image file creation failed", ex);
  176. }
  177. if (photoFile != null) {
  178. mCM = "file:" + photoFile.getAbsolutePath();
  179. takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
  180. } else {
  181. takePictureIntent = null;
  182. }
  183. }
  184. Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
  185. contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
  186. contentSelectionIntent.setType("image/*");
  187. Intent[] intentArray;
  188. if (takePictureIntent != null) {
  189. intentArray = new Intent[]{takePictureIntent};
  190. } else {
  191. intentArray = new Intent[0];
  192. }
  193.  
  194. Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
  195. chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
  196. chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
  197. chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
  198. startActivityForResult(chooserIntent, FCR);
  199. return true;
  200. }
  201.  
  202. @Override
  203. public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
  204. callback.invoke(origin, true, false);
  205. }
  206. });
  207.  
  208. mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
  209. mSwipeRefreshLayout.setOnRefreshListener(this);
  210. mSwipeRefreshLayout.setColorSchemeColors(Color.LTGRAY, Color.GRAY, Color.DKGRAY, Color.BLACK);
  211.  
  212. login = new Dialog(MainActivity.this);
  213. login.setContentView(R.layout.login_dialog);
  214. login.setTitle("Login");
  215.  
  216. Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
  217. Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
  218. final EditText txtUsername = (EditText) login.findViewById(R.id.txtUsername);
  219. final EditText txtPassword = (EditText) login.findViewById(R.id.txtPassword);
  220. btnLogin.setOnClickListener(new View.OnClickListener() {
  221. @Override
  222. public void onClick(View v) {
  223. if (txtUsername.getText().toString().trim().length() > 0 && txtPassword.getText().toString().trim().length() > 0) {
  224. login.dismiss();
  225.  
  226. user = txtUsername.getText().toString();
  227. pass = txtPassword.getText().toString();
  228.  
  229. // mWebView.loadUrl("https://" + user + ":" + pass + "@support.antivor.ru");
  230. Log.d(LOG_TAG, "OPEN SUPPORT ANTIVOR");
  231.  
  232. mWebView.loadUrl("https://support.antivor.ru");
  233. // mWebView.setHttpAuthUsernamePassword("https://support.antivor.ru","User Visible Realm",user,pass);
  234.  
  235. // new Handler().postDelayed(new Runnable() {
  236. // @Override
  237. // public void run() {
  238. // Log.d(LOG_TAG, "REFRASH 1");
  239. // mWebView.loadUrl("https://support.antivor.ru");
  240. // }
  241. // }, 2000);
  242.  
  243. } else {
  244. Toast.makeText(MainActivity.this, "Please enter Username or Password", Toast.LENGTH_LONG).show();
  245. }
  246. }
  247. });
  248. btnCancel.setOnClickListener(new View.OnClickListener() {
  249. @Override
  250. public void onClick(View v) {
  251. login.dismiss();
  252. }
  253. });
  254. login.show();
  255. }
  256.  
  257. @Override
  258. public void onRefresh() {
  259. Log.d(LOG_TAG, "REFRASH");
  260. new Handler().postDelayed(new Runnable() {
  261. @Override
  262. public void run() {
  263. mSwipeRefreshLayout.setRefreshing(false);
  264. mWebView.loadUrl("https://support.antivor.ru");
  265. }
  266. }, 2000);
  267. }
  268.  
  269. @Override
  270. public void onBackPressed() {
  271. Log.d(LOG_TAG, "BUTTON BACK");
  272. if (mWebView.canGoBack()) {
  273. mWebView.goBack();
  274. } else {
  275. super.onBackPressed();
  276. }
  277. }
  278.  
  279. @Override
  280. public void onConfigurationChanged(Configuration newConfig) {
  281. super.onConfigurationChanged(newConfig);
  282. }
  283.  
  284. private File createImageFile() throws IOException {
  285. @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  286. String imageFileName = "img_" + timeStamp + "_";
  287. File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
  288. return File.createTempFile(imageFileName, ".jpg", storageDir);
  289. }
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement