Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. package com.Justredial.helloggn;
  2.  
  3. import com.Justredial.helloggn.ads.R;
  4.  
  5. import android.app.Activity;
  6. import android.app.AlertDialog;
  7. import android.content.ActivityNotFoundException;
  8. import android.content.Context;
  9. import android.content.DialogInterface;
  10. import android.content.Intent;
  11. import android.net.Uri;
  12. import android.os.Bundle;
  13. import android.view.KeyEvent;
  14. import android.view.View;
  15. import android.view.Window;
  16. import android.webkit.WebSettings;
  17. import android.webkit.WebSettings.LayoutAlgorithm;
  18. import android.webkit.WebSettings.PluginState;
  19. import android.webkit.WebView;
  20. import android.webkit.WebViewClient;
  21. import android.widget.ProgressBar;
  22.  
  23.  
  24. public class DroidWebViewActivity extends Activity {
  25. /** Called when the activity is first created. */
  26. Context con;
  27. private WebView fweBview;
  28. private WebSettings webSettings;
  29. ProgressBar progressBar;
  30.  
  31. String url ="http://google.com";
  32.  
  33. @Override
  34. public void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. requestWindowFeature(Window.FEATURE_NO_TITLE);
  37. setContentView(R.layout.ll_web_view);
  38. con = this;
  39. try {
  40. /* if (!SharedPreferencesHelper.isOnline(con)) {
  41. AlertMessage.showMessage(con, "", "No internet connection");
  42. return;
  43. }*/
  44. updateWebView(url);
  45.  
  46. } catch (Exception e) {
  47. // TODO: handle exception
  48. }
  49. }
  50.  
  51.  
  52. private class HelloWebViewClient extends WebViewClient {
  53.  
  54. @Override
  55. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  56. view.loadUrl(url);
  57. return true;
  58. }
  59.  
  60. @Override
  61. public void onPageFinished(WebView view, String url) {
  62. // TODO Auto-generated method stub
  63. super.onPageFinished(view, url);
  64.  
  65. progressBar.setVisibility(View.GONE);
  66. }
  67. }
  68.  
  69. @Override
  70. public boolean onKeyDown(int keyCode, KeyEvent event) {
  71. if (keyCode == KeyEvent.KEYCODE_BACK && fweBview.canGoBack()) {
  72. fweBview.goBack();
  73. return true;
  74. }
  75. return super.onKeyDown(keyCode, event);
  76.  
  77. }
  78. public class AppWebViewClients extends WebViewClient {
  79. private ProgressBar progressBar;
  80.  
  81. public AppWebViewClients(ProgressBar progressBar) {
  82. this.progressBar=progressBar;
  83. progressBar.setVisibility(View.VISIBLE);
  84. }
  85. @Override
  86. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  87. // TODO Auto-generated method stub
  88. view.loadUrl(url);
  89. return true;
  90. }
  91.  
  92. @Override
  93. public void onPageFinished(WebView view, String url) {
  94. // TODO Auto-generated method stub
  95. super.onPageFinished(view, url);
  96. progressBar.setVisibility(View.GONE);
  97. }
  98. }
  99. private void updateWebView(String url) {
  100. // TODO Auto-generated method stub
  101. progressBar = (ProgressBar) findViewById(R.id.progressBar1);
  102. fweBview = (WebView) findViewById(R.id.webView1);
  103. fweBview.getSettings().setJavaScriptEnabled(true);
  104. fweBview.getSettings().setDomStorageEnabled(true);
  105. fweBview.getSettings().setPluginState(PluginState.ON);
  106. webSettings = fweBview.getSettings();
  107.  
  108. webSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
  109. webSettings.setBuiltInZoomControls(true);
  110.  
  111. fweBview.loadUrl(url);
  112.  
  113. fweBview.setWebViewClient(new HelloWebViewClient());
  114.  
  115. }
  116.  
  117. // /---- Rating Button-----------------------------
  118.  
  119. public void btnRating(View v) {
  120.  
  121. try {
  122.  
  123. alertbox(null, null);
  124.  
  125. } catch (Exception e) {
  126. // TODO: handle exception
  127. }
  128.  
  129. }
  130.  
  131. protected void alertbox(String title, String mymessage) {
  132. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  133. builder.setMessage("Encourage us By Rating Our App").setCancelable(
  134. false).setTitle("").setPositiveButton("Rate Now",
  135. new DialogInterface.OnClickListener() {
  136. public void onClick(DialogInterface dialog, int id) {
  137. // finish the current activity
  138. // AlertBoxAdvance.this.finish();
  139. /*
  140. * Intent myIntent = new Intent(
  141. * Settings.ACTION_SECURITY_SETTINGS);
  142. * startActivity(myIntent);
  143. */
  144. /* Intent viewIntent = new Intent(
  145. "android.intent.action.VIEW",
  146. Uri
  147. .parse(Info.GooglePlayAppUrl));
  148. startActivity(viewIntent);*/
  149. dialog.cancel();
  150. }
  151. }).setNegativeButton("Later",
  152. new DialogInterface.OnClickListener() {
  153. public void onClick(DialogInterface dialog, int id) {
  154. // cancel the dialog box
  155.  
  156. dialog.cancel();
  157. }
  158. });
  159. AlertDialog alert = builder.create();
  160. alert.show();
  161. }
  162.  
  163. // ------------ Share button---------------------
  164.  
  165. public void btnShare(View v) {
  166.  
  167. Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
  168. sharingIntent.setType("text/plain");
  169. sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
  170. " ");
  171. sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "shareBody");
  172. startActivity(Intent.createChooser(sharingIntent, "Share via"));
  173. }
  174.  
  175. // ------------ Home button---------------------
  176. public void btnHome(View v) {
  177. try {
  178. updateWebView(url);
  179. } catch (Exception e) {
  180. // TODO: handle exception
  181. }
  182.  
  183. // Intent i = new Intent(DroidWebViewActivity.this,
  184. // DroidWebViewActivity.class); // your class
  185. // startActivity(i);
  186.  
  187. }
  188.  
  189. // ------------ Email button---------------------
  190. public void btnEmail(View v) {
  191.  
  192. /* Intent email = new Intent(Intent.ACTION_SEND);
  193. email.putExtra(Intent.EXTRA_EMAIL,
  194. new String[] { "" });
  195. email.putExtra(Intent.EXTRA_SUBJECT, Info.eMailSubject);
  196. email.putExtra(Intent.EXTRA_TEXT, Info.eMailDetails);
  197. email.setType("message/rfc822");
  198. startActivity(Intent.createChooser(email, "Choose an Email client :"));*/
  199.  
  200. }
  201.  
  202. // ------------ Call button---------------------
  203. private void call() {
  204. try {
  205. /* Intent callIntent = new Intent(Intent.ACTION_CALL);
  206. callIntent.setData(Uri.parse("tel:"+Info.phoneNumber+""));
  207. startActivity(callIntent);*/
  208. } catch (ActivityNotFoundException activityException) {
  209.  
  210. }
  211. }
  212.  
  213. public void btnPhone(View v) {
  214.  
  215. try {
  216.  
  217. call();
  218.  
  219. } catch (Exception e) {
  220. // TODO: handle exception
  221. }
  222.  
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement