SHOW:
|
|
- or go back to the newest paste.
| 1 | package ge.msinfo.msinfo; | |
| 2 | ||
| 3 | import android.content.Intent; | |
| 4 | import android.net.Uri; | |
| 5 | import android.os.Bundle; | |
| 6 | import android.support.design.widget.FloatingActionButton; | |
| 7 | import android.support.design.widget.Snackbar; | |
| 8 | import android.support.v7.app.AppCompatActivity; | |
| 9 | import android.support.v7.widget.Toolbar; | |
| 10 | import android.view.View; | |
| 11 | import android.view.Menu; | |
| 12 | import android.view.MenuItem; | |
| 13 | import android.webkit.WebView; | |
| 14 | import android.webkit.WebViewClient; | |
| 15 | ||
| 16 | public class MainActivity extends AppCompatActivity {
| |
| 17 | - | public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
| 17 | + | |
| 18 | - | if (url != null && url.startsWith("http://www.msinfo.ge/")) {
|
| 18 | + | |
| 19 | - | view.getContext().startActivity( |
| 19 | + | |
| 20 | - | new Intent(Intent.ACTION_VIEW, Uri.parse(url))); |
| 20 | + | |
| 21 | setContentView(R.layout.activity_main); | |
| 22 | - | } else {
|
| 22 | + | |
| 23 | - | return false; |
| 23 | + | webview.setWebViewClient(new WebViewClient(){
|
| 24 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
| |
| 25 | ||
| 26 | String url2="http://www.playbuzz.org/"; | |
| 27 | // all links with in ur site will be open inside the webview | |
| 28 | //links that start ur domain example(http://www.example.com/) | |
| 29 | if (url != null && url.startsWith(url2)){
| |
| 30 | return false; | |
| 31 | } | |
| 32 | // all links that points outside the site will be open in a normal android browser | |
| 33 | else {
| |
| 34 | view.getContext().startActivity( | |
| 35 | new Intent(Intent.ACTION_VIEW, Uri.parse(url))); | |
| 36 | return true; | |
| 37 | } | |
| 38 | } | |
| 39 | }); | |
| 40 | myWebView.loadUrl("http://www.msinfo.ge/");
| |
| 41 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 42 | setSupportActionBar(toolbar); | |
| 43 | ||
| 44 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
| 45 | fab.setOnClickListener(new View.OnClickListener() {
| |
| 46 | @Override | |
| 47 | public void onClick(View view) {
| |
| 48 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | |
| 49 | .setAction("Action", null).show();
| |
| 50 | } | |
| 51 | }); | |
| 52 | } | |
| 53 | ||
| 54 | @Override | |
| 55 | public boolean onCreateOptionsMenu(Menu menu) {
| |
| 56 | // Inflate the menu; this adds items to the action bar if it is present. | |
| 57 | getMenuInflater().inflate(R.menu.menu_main, menu); | |
| 58 | return true; | |
| 59 | } | |
| 60 | ||
| 61 | @Override | |
| 62 | public boolean onOptionsItemSelected(MenuItem item) {
| |
| 63 | // Handle action bar item clicks here. The action bar will | |
| 64 | // automatically handle clicks on the Home/Up button, so long | |
| 65 | // as you specify a parent activity in AndroidManifest.xml. | |
| 66 | int id = item.getItemId(); | |
| 67 | ||
| 68 | //noinspection SimplifiableIfStatement | |
| 69 | if (id == R.id.action_settings) {
| |
| 70 | return true; | |
| 71 | } | |
| 72 | ||
| 73 | return super.onOptionsItemSelected(item); | |
| 74 | } | |
| 75 | } |