Example usage for android.webkit WebView setWebViewClient

List of usage examples for android.webkit WebView setWebViewClient

Introduction

In this page you can find the example usage for android.webkit WebView setWebViewClient.

Prototype

public void setWebViewClient(WebViewClient client) 

Source Link

Document

Sets the WebViewClient that will receive various notifications and requests.

Usage

From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java

/**
 * Closes the dialog//from   w  ww  .j  a v  a  2  s  .co  m
 */
public void closeDialog() {
    final WebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new WebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(WebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}

From source file:org.zeroxlab.benchmark.Benchmark.java

private void initViews() {
    /*/*from w w  w.jav  a2s .  com*/
    mRun = (Button)findViewById(R.id.btn_run);
    mRun.setOnClickListener(this);
            
    mShow = (Button)findViewById(R.id.btn_show);
    mShow.setOnClickListener(this);
    mShow.setClickable(false);
            
    mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
    mMainView = (LinearLayout)findViewById(R.id.main_view);
            
    mBannerInfo = (TextView)findViewById(R.id.banner_info);
    mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
    */

    mTabHost = getTabHost();

    int length = mCases.size();
    mCheckList = new CheckBox[length];
    mDesc = new TextView[length];
    for (int i = 0; i < length; i++) {
        mCheckList[i] = new CheckBox(this);
        mCheckList[i].setText(mCases.get(i).getTitle());
        mDesc[i] = new TextView(this);
        mDesc[i].setText(mCases.get(i).getDescription());
        mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
        mDesc[i].setPadding(42, 0, 10, 10);
    }

    TabContentFactory mTCF = new TabContentFactory() {
        public View createTabContent(String tag) {
            ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT);
            ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            wrapContent.gravity = Gravity.CENTER;
            LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            weightedFillWrap.weight = 1;

            if (tag.equals(MAIN)) {
                LinearLayout mMainView = new LinearLayout(Benchmark.this);
                mMainView.setOrientation(1);
                ScrollView mListScroll = new ScrollView(Benchmark.this);

                LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this);
                mMainViewContainer.setOrientation(1);
                ImageView mIconView = new ImageView(Benchmark.this);
                mIconView.setImageResource(R.drawable.icon);

                TextView mBannerInfo = new TextView(Benchmark.this);
                mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:");

                d2CheckBox = new CheckBox(Benchmark.this);
                d2CheckBox.setText(D2);
                d2CheckBox.setOnClickListener(Benchmark.this);

                d2HWCheckBox = new CheckBox(Benchmark.this);
                d2HWCheckBox.setText(D2HW);
                d2HWCheckBox.setOnClickListener(Benchmark.this);

                d2SW1CheckBox = new CheckBox(Benchmark.this);
                d2SW1CheckBox.setText(D2SW1);
                d2SW1CheckBox.setOnClickListener(Benchmark.this);

                d2SW2CheckBox = new CheckBox(Benchmark.this);
                d2SW2CheckBox.setText(D2SW2);
                d2SW2CheckBox.setOnClickListener(Benchmark.this);

                d3CheckBox = new CheckBox(Benchmark.this);
                d3CheckBox.setText(D3);
                d3CheckBox.setOnClickListener(Benchmark.this);

                mathCheckBox = new CheckBox(Benchmark.this);
                mathCheckBox.setText(MATH);
                mathCheckBox.setOnClickListener(Benchmark.this);

                vmCheckBox = new CheckBox(Benchmark.this);
                vmCheckBox.setText(VM);
                vmCheckBox.setOnClickListener(Benchmark.this);

                nativeCheckBox = new CheckBox(Benchmark.this);
                nativeCheckBox.setText(NATIVE);
                nativeCheckBox.setOnClickListener(Benchmark.this);

                miscCheckBox = new CheckBox(Benchmark.this);
                miscCheckBox.setText(MISC);
                miscCheckBox.setOnClickListener(Benchmark.this);

                filterBitmapCheckBox = new CheckBox(Benchmark.this);
                filterBitmapCheckBox.setText("Filter Bitmap in Draw Image");
                filterBitmapCheckBox.setOnClickListener(Benchmark.this);

                useGradientCheckBox = new CheckBox(Benchmark.this);
                useGradientCheckBox.setText("Use Gradient in Draw Canvas/Circle/Rect/Arc");
                useGradientCheckBox.setOnClickListener(Benchmark.this);

                useTextureCheckBox = new CheckBox(Benchmark.this);
                useTextureCheckBox.setText("Use Texture in Draw Canvas/Circle/Rect/Arc");
                useTextureCheckBox.setOnClickListener(Benchmark.this);

                TextView mWebInfo = new TextView(Benchmark.this);
                mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com");

                LinearLayout mButtonContainer = new LinearLayout(Benchmark.this);
                mRun = new Button(Benchmark.this);
                mShow = new Button(Benchmark.this);
                mRun.setText("Run");
                mShow.setText("Show");
                mRun.setOnClickListener(Benchmark.this);
                mShow.setOnClickListener(Benchmark.this);
                mButtonContainer.addView(mRun, weightedFillWrap);
                mButtonContainer.addView(mShow, weightedFillWrap);
                WebView mTracker = new WebView(Benchmark.this);
                mTracker.clearCache(true);
                mTracker.setWebViewClient(new WebViewClient() {
                    public void onPageFinished(WebView view, String url) {
                        Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url);
                    }

                    public void onReceivedError(WebView view, int errorCode, String description,
                            String failingUrl) {
                        Log.e(TAG, "Track err: " + description);
                    }
                });
                mTracker.loadUrl(trackerUrl);
                mMainViewContainer.addView(mIconView, wrapContent);
                mMainViewContainer.addView(mBannerInfo);
                mMainViewContainer.addView(mathCheckBox);
                mMainViewContainer.addView(d2CheckBox);
                mMainViewContainer.addView(d2HWCheckBox);
                mMainViewContainer.addView(d2SW1CheckBox);
                mMainViewContainer.addView(d2SW2CheckBox);
                mMainViewContainer.addView(d3CheckBox);
                mMainViewContainer.addView(vmCheckBox);
                mMainViewContainer.addView(nativeCheckBox);
                mMainViewContainer.addView(miscCheckBox);
                mMainViewContainer.addView(filterBitmapCheckBox);
                mMainViewContainer.addView(useGradientCheckBox);
                mMainViewContainer.addView(useTextureCheckBox);
                mMainViewContainer.addView(mWebInfo);
                mMainViewContainer.addView(mButtonContainer, fillWrap);
                mMainViewContainer.addView(mTracker, 0, 0);
                mListScroll.addView(mMainViewContainer, fillParent);
                mMainView.addView(mListScroll, fillWrap);

                return mMainView;

            }

            LinearLayout mMainView = new LinearLayout(Benchmark.this);
            mMainView.setOrientation(1);
            ScrollView mListScroll = new ScrollView(Benchmark.this);
            LinearLayout mListContainer = new LinearLayout(Benchmark.this);
            mListContainer.setOrientation(1);
            mListScroll.addView(mListContainer, fillParent);
            mMainView.addView(mListScroll, fillWrap);

            boolean gray = true;
            int length = mCases.size();
            Log.i(TAG, "L: " + length);
            Log.i(TAG, "TCF: " + tag);
            for (int i = 0; i < length; i++) {
                if (!mCategory.get(tag).contains(mCases.get(i)))
                    continue;
                Log.i(TAG, "Add: " + i);
                mListContainer.addView(mCheckList[i], fillWrap);
                mListContainer.addView(mDesc[i], fillWrap);
                if (gray) {
                    int color = 0xFF333333; //ARGB
                    mCheckList[i].setBackgroundColor(color);
                    mDesc[i].setBackgroundColor(color);
                }
                gray = !gray;
            }
            return mMainView;
        }
    };

    mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2HW).setIndicator(D2HW, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2SW1).setIndicator(D2SW1, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2SW2).setIndicator(D2SW2, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(NATIVE)
            .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc))
            .setContent(mTCF));
}

From source file:de.uni_weimar.m18.anatomiederstadt.element.LatexFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_latex, container, false);
    WebView latexView = (WebView) root.findViewById(R.id.latexWebView);
    latexView.getSettings().setJavaScriptEnabled(true);
    latexView.getSettings().setBuiltInZoomControls(false);
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = getActivity().getTheme();
    theme.resolveAttribute(R.color.windowBackgroundColor, typedValue, true);
    latexView.setBackgroundColor(typedValue.data);

    latexView.loadDataWithBaseURL("http://bar",
            "<script type='text/x-mathjax-config'>" + "MathJax.Hub.Config({ " + "messageStyle: 'none',"
                    + "showMathMenu: false, " + "jax: ['input/TeX','output/HTML-CSS'], "
                    + "extensions: ['tex2jax.js'], " + "TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
                    + "'noErrors.js','noUndefined.js'] } " + "});</script>" + "<script type='text/javascript' "
                    + "src='file:///android_asset/MathJax/MathJax.js'" + "></script><span id='math'></span>",
            "text/html", "utf-8", "");

    Log.v(LOG_TAG, "Loading latexCode: " + mLatexCode);
    latexView.setWebViewClient(new WebViewClient() {
        private String mLatexCode = null;

        @Override/* w  w  w . j av  a  2s  .  c  o  m*/
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (Build.VERSION.SDK_INT < 19) {
                view.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\["
                        + doubleEscapeTeX(getLatexCode()) + "\\\\]'");
                view.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
            } else {
                view.evaluateJavascript("javascript:document.getElementById('math').innerHTML='\\\\["
                        + doubleEscapeTeX(getLatexCode()) + "\\\\]'", null);
                view.evaluateJavascript("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);", null);
            }
        }
    });

    return root;
}

From source file:info.alni.comete.android.Comete.java

private AlertDialog createHelpDialog() {
    final WebView wv = new WebView(this);
    wv.setTag("help");
    wv.getSettings().setJavaScriptEnabled(true);
    wv.setWebViewClient(internalWebViewClient);
    wv.loadUrl(URL_HELP_MAIN);/*w w w. j a  v  a2  s. co  m*/
    return new AlertDialog.Builder(this).setTitle("Help").setView(wv)
            .setPositiveButton("Close", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:com.likemag.cordova.inappbrowsercustom.InAppBrowser.java

/**
 * Closes the dialog/* ww w  . j ava 2  s. co  m*/
 */
public void closeDialog() {
    final WebView childView = this.inAppWebView;
    // The JS protects against multiple calls, so this should happen only when
    // closeDialog() is called by other native code.
    if (childView == null) {
        return;
    }
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            childView.setWebViewClient(new WebViewClient() {
                // NB: wait for about:blank before dismissing
                public void onPageFinished(WebView view, String url) {
                    if (dialog != null) {
                        dialog.dismiss();
                    }
                }
            });
            // NB: From SDK 19: "If you call methods on WebView from any thread 
            // other than your app's UI thread, it can cause unexpected results."
            // http://developer.android.com/guide/webapps/migrating.html#Threads
            childView.loadUrl("about:blank");
        }
    });

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", EXIT_EVENT);
        sendUpdate(obj, false);
    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }
}

From source file:com.phonegap.DroidGap.java

/**
 * Set the WebViewClient.//from   w  w w.j  a va  2s .c  om
 * 
 * @param appView
 * @param client
 */
protected void setWebViewClient(WebView appView, WebViewClient client) {
    this.webViewClient = client;
    appView.setWebViewClient(client);
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

private void showChangelog() {
    if (version_changed) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(R.string.changelog);
        WebView changes = new WebView(mContext);
        changes.setWebViewClient(new WebViewClient());
        changes.loadUrl("http://forum.xda-developers.com/showpost.php?p=42839595&postcount=3");
        dialog.setView(changes);/* ww w.j  av  a 2  s.  c o m*/
        dialog.show();
    }
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * Dialog ???//from   w  ww  .  j a  va  2s . c om
 * @param mContext
 * @return
 */
private Dialog showLicenseChoiceDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_license_choice, null);
    final Dialog dialog = new Dialog(mContext, R.style.mystyle);

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.layout_rule:
                if (isAgree) {
                    isAgree = false;
                    ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose);
                    //                            TextView textView = (TextView)v.findViewById(R.id.tv_rule);
                    imageView.setImageResource(R.drawable.icon_choose);
                    //                            textView.setBackgroundColor(getResources().getColor(R.color.bg_gray_color_level_0));
                    //                            textView.setTextColor(getResources().getColor(R.color.tv_gray_color_level_3));
                } else {
                    isAgree = true;
                    ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose);
                    //                            TextView textView = (TextView)v.findViewById(R.id.tv_rule);
                    imageView.setImageResource(R.drawable.icon_choose_selected);
                    //                            textView.setBackgroundResource(R.drawable.btn_select_base_shape_0);
                    //                            textView.setTextColor(getResources().getColor(R.color.white_color));
                }
                break;
            }
            if (onLicenseDialogClickListener != null) {
                onLicenseDialogClickListener.onClick(v, isAgree);
            }
        }
    };

    TitleBar titleBar;
    SwipeRefreshLayout swipeLayout;
    final WebView webView;
    ProgressBar progressBar;
    LinearLayout layoutRule;
    LinearLayout layoutConfirm;

    titleBar = (TitleBar) convertView.findViewById(R.id.title_bar);
    swipeLayout = (SwipeRefreshLayout) convertView.findViewById(R.id.swipe_layout);
    webView = (WebView) convertView.findViewById(R.id.webView);
    progressBar = (ProgressBar) convertView.findViewById(R.id.progress_bar);
    layoutRule = (LinearLayout) convertView.findViewById(R.id.layout_rule);
    layoutConfirm = (LinearLayout) convertView.findViewById(R.id.layout_confirm);

    WebChromeClient client = new AppChromeWebClient(titleBar, progressBar, swipeLayout);
    webView.setWebChromeClient(client);
    webView.setWebViewClient(new AppWebClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(webViewURL);
    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                    webView.goBack(); //?
                    return true; //?
                }
            }
            return false;
        }
    });

    titleBar.initTitleBarInfo("", R.drawable.arrow_left, -1, "", "");
    titleBar.setOnTitleBarClickListener(new TitleBar.OnTitleBarClickListener() {
        @Override
        public void onLeftButtonClick(View v) {
            if (webView.canGoBack()) {
                webView.goBack(); //?
                return; //?
            }

            if (onLicenseDialogClickListener != null) {
                onLicenseDialogClickListener.onClick(v, isAgree);
                dismiss();
            }
        }

        @Override
        public void onRightButtonClick(View v) {

        }
    });
    UIUtils.initSwipeRefreshLayout(swipeLayout);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            webView.reload();
        }
    });

    layoutConfirm.setOnClickListener(listener);
    layoutRule.setOnClickListener(listener);

    dialog.setContentView(convertView);
    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    return dialog;
}

From source file:com.example.prasadnr.traquad.TraQuad.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tra_quad);
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(TraQuad.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    Builder alert = new AlertDialog.Builder(TraQuad.this);

    WifiManager managerWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    Method[] wmMethods = managerWifi.getClass().getDeclaredMethods();
    for (Method method : wmMethods) {
        if (method.getName().equals("isWifiApEnabled")) {

            try {
                isWifiAPenabled = (boolean) method.invoke(managerWifi);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();/* w  w  w.  j a  v a2  s .c  o  m*/
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }

    final ProgressDialog pDialog;
    MediaController mediaController = new MediaController(this);

    pDialog = new ProgressDialog(TraQuad.this);
    pDialog.setTitle("TraQuad app (Connecting...)");
    pDialog.setMessage("Buffering...Please wait...");
    pDialog.setCancelable(true);

    if (!isWifiAPenabled) {

        alert.setTitle("WiFi Hotspot Settings");
        alert.setMessage("Can you please connect WiFi-hotspot?");
        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                irritation = true;
                startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                pDialog.show();
            }
        });
        alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //Dismiss AlertDialog
                pDialog.show();
                Toast.makeText(getApplicationContext(), "Please connect your WiFi!", Toast.LENGTH_LONG).show();
            }
        });
        alert.setCancelable(false);
        AlertDialog alertDialog = alert.create();
        alertDialog.show();
    }

    WebView webView = (WebView) findViewById(R.id.webView);

    if (irritation == true | isWifiAPenabled) {
        pDialog.show();
    }

    mediaController.setAnchorView(webView);
    mediaController.setVisibility(View.GONE);

    extra = getIntent().getStringExtra("VideosId");
    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
    final String IPaddressNew = globalVariable.getIP();
    final String httpString = "http://";
    final String commandPort = String.valueOf(1500);
    final String streamPort = String.valueOf(8080);
    final String IPaddressStream = httpString + IPaddressNew + ":" + streamPort;
    final String IPaddressCommand = httpString + IPaddressNew + ":" + commandPort;
    TextView sendCharacter = (TextView) findViewById(R.id.sendCharacter);

    try {
        webView.loadUrl(IPaddressStream);
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), IPaddressNew + ":Error!", Toast.LENGTH_LONG).show();
    }

    webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            pDialog.dismiss();
        }
    });

    final Button switchact = (Button) findViewById(R.id.btn2);
    switchact.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent act1 = new Intent(view.getContext(), Joypad.class);
            startActivity(act1);

        }
    });

    final Button hometraquad = (Button) findViewById(R.id.button5);

    hometraquad.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent acthometraquad = new Intent(TraQuad.this, MainActivity.class);
            startActivity(acthometraquad);
        }
    });

}

From source file:com.openatk.fieldnotebook.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.main_menu_add) {
        addFieldMapView();/*from   w  w  w  .  j av a 2s .  c  o m*/
        return true;
    } else if (item.getItemId() == R.id.main_menu_current_location) {
        Location myLoc = map.getMyLocation();
        if (myLoc == null) {
            Toast.makeText(this, "Still searching for your location", Toast.LENGTH_SHORT).show();
        } else {
            CameraPosition oldPos = map.getCameraPosition();
            CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()),
                    map.getMaxZoomLevel(), oldPos.tilt, oldPos.bearing);
            map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos));
        }
        return true;
    } else if (item.getItemId() == R.id.main_menu_list_view) {
        /*if(sliderIsShowing == 0){
           showSlider(true);
        } else {
           hideSlider(true);
        }
        if (mCurrentState == STATE_LIST_VIEW) {
           // Show map view
           Log.d("MainActivity", "Showing map view");
           setState(STATE_DEFAULT);
           //item.setIcon(R.drawable.list_view);
        } else {
           // Show list view
           Log.d("MainActivity", "Showing list view");
           setState(STATE_LIST_VIEW);
           //item.setIcon(R.drawable.map_view);
        }*/
        return true;
    } else if (item.getItemId() == R.id.main_menu_help) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Help");
        WebView wv = new WebView(this);
        wv.loadUrl("file:///android_asset/Help.html");
        wv.getSettings().setSupportZoom(true);
        wv.getSettings().setBuiltInZoomControls(true);
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        alert.setView(wv);
        alert.setNegativeButton("Close", null);
        alert.show();
        return true;
    } else if (item.getItemId() == R.id.main_menu_legal) {
        CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n"
                + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy "
                + "of this software and associated documentation files (the \"Software\"), to deal "
                + "in the Software without restriction, including without limitation the rights "
                + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
                + "copies of the Software, and to permit persons to whom the Software is "
                + "furnished to do so, subject to the following conditions:" + "\n"
                + "The above copyright notice and this permission notice shall be included in "
                + "all copies or substantial portions of the Software.\n" + "\n"
                + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
                + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
                + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
                + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
                + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, "
                + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN "
                + "THE SOFTWARE.\n";
        new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence)
                .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}