Guest User

Untitled

a guest
Oct 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. package com.yoalfaaz.yoalfaaz;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.design.widget.FloatingActionButton;
  6. import android.support.design.widget.Snackbar;
  7. import android.support.v4.widget.SwipeRefreshLayout;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.support.v7.widget.ShareActionProvider;
  10. import android.support.v7.widget.Toolbar;
  11. import android.view.View;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.webkit.WebSettings;
  15. import android.webkit.WebView;
  16. import android.webkit.WebViewClient;
  17. import android.support.v4.view.MenuItemCompat;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20. private WebView YoWeb;
  21. private ShareActionProvider mShareActionProvider;
  22.  
  23. SwipeRefreshLayout swipe;
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  30. setSupportActionBar(toolbar);
  31.  
  32. YoWeb = (WebView)findViewById(R.id.webview); // Move your declaration up here
  33. swipe = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
  34. swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  35. @Override
  36. public void onRefresh() {
  37. LoadWeb(YoWeb.getUrl()); // Pass in the current url to refresh
  38. }
  39. });
  40.  
  41. LoadWeb("https://www.yoalfaaz.com"); // load the home page only once
  42. }
  43.  
  44. public void LoadWeb(String url) // Pass in URL you want to load
  45. {
  46.  
  47. WebSettings webSettings = YoWeb.getSettings();
  48. webSettings.setJavaScriptEnabled(true);
  49. YoWeb.loadUrl(url); // Load the URL passed into the method
  50. swipe.setRefreshing(true);
  51. YoWeb.setWebViewClient(new WebViewClient() {
  52.  
  53. //onPageFinished Method
  54. public void onPageFinished(WebView view, String url) {
  55. //Hide the SwipeRefreshLayout
  56. swipe.setRefreshing(false);
  57. }
  58. });
  59. }
  60.  
  61. @Override
  62. public void onBackPressed() {
  63. if (YoWeb.canGoBack()) {
  64. YoWeb.goBack();
  65. } else {
  66. super.onBackPressed();
  67. }
  68. }
  69.  
  70. @Override
  71. public boolean onOptionsItemSelected(MenuItem item) {
  72. // Handle action bar item clicks here. The action bar will
  73. // automatically handle clicks on the Home/Up button, so long
  74. // as you specify a parent activity in AndroidManifest.xml.
  75. switch (item.getItemId()) {
  76. case R.id.action_settings:
  77. return true;
  78.  
  79. default:
  80. return super.onOptionsItemSelected(item);
  81. }
  82. }
  83.  
  84. @Override
  85. public boolean onCreateOptionsMenu(Menu menu) {
  86. // Inflate menu resource file.
  87. getMenuInflater().inflate(R.menu.menu_main, menu);
  88.  
  89. // Locate MenuItem with ShareActionProvider
  90. MenuItem item = menu.findItem(R.id.menu_item_share);
  91.  
  92. // Fetch and store ShareActionProvider
  93. mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
  94.  
  95. // Return true to display menu
  96. return true;
  97. }
  98.  
  99. // Call to update the share intent
  100. private void setShareIntent(Intent shareIntent) {
  101. if (mShareActionProvider != null) {
  102. mShareActionProvider.setShareIntent(shareIntent);
  103. }
  104. }
  105.  
  106. //private Intent setShareIntent() {
  107. // Intent shareIntent = new Intent();
  108. // shareIntent.setAction(Intent.ACTION_SEND);
  109. // shareIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
  110. // shareIntent.setType("text/plain");
  111. // startActivity(shareIntent);
  112. // return shareIntent;
  113. //}
  114. }
  115.  
  116. <?xml version="1.0" encoding="utf-8"?>
  117. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  118. package="com.yoalfaaz.yoalfaaz">
  119.  
  120. <uses-permission android:name="android.permission.INTERNET" />
  121.  
  122. <application
  123. android:allowBackup="true"
  124. android:icon="@mipmap/ic_launcher"
  125. android:label="@string/app_name"
  126. android:roundIcon="@mipmap/ic_launcher_round"
  127. android:supportsRtl="true"
  128. android:theme="@style/AppTheme">
  129. <activity
  130. android:name=".MainActivity"
  131. android:configChanges="orientation|keyboardHidden"
  132. android:label="@string/app_name"
  133. android:theme="@style/AppTheme.NoActionBar">
  134. <intent-filter>
  135. <action android:name="android.intent.action.MAIN" />
  136.  
  137. <category android:name="android.intent.category.DEFAULT" />
  138. </intent-filter>
  139. <intent-filter >
  140. <action android:name="android.intent.action.VIEW"/>
  141. <category android:name="android.intent.category.DEFAULT"/>
  142. <category android:name="android.intent.category.BROWSABLE"/>
  143. <data android:host="www.yoalfaaz.com" android:scheme="https"/>
  144. </intent-filter>
  145. </activity>
  146. <activity android:name=".SplashScreen">
  147. <intent-filter>
  148. <action android:name="android.intent.action.MAIN" />
  149.  
  150. <category android:name="android.intent.category.LAUNCHER" />
  151. </intent-filter>
  152. </activity>
  153. </application>
  154.  
  155. </manifest>
Add Comment
Please, Sign In to add comment