Example usage for android.view View.OnClickListener View.OnClickListener

List of usage examples for android.view View.OnClickListener View.OnClickListener

Introduction

In this page you can find the example usage for android.view View.OnClickListener View.OnClickListener.

Prototype

View.OnClickListener

Source Link

Usage

From source file:cm.aptoide.pt.MainActivity.java

public void showFollow() {
    View socialNetworksView = LayoutInflater.from(this).inflate(R.layout.dialog_social_networks, null);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this).setView(socialNetworksView);
    final AlertDialog socialDialog = dialogBuilder.create();
    socialDialog.setIcon(android.R.drawable.ic_menu_share);
    socialDialog.setTitle(getString(R.string.social_networks));
    socialDialog.setCancelable(true);//from   ww w.j a  va  2  s. co m

    Button facebookButton = (Button) socialNetworksView.findViewById(R.id.find_facebook);
    facebookButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isAppInstalled("com.facebook.katana")) {
                Intent sharingIntent;
                try {
                    getPackageManager().getPackageInfo("com.facebook.katana", 0);
                    sharingIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/225295240870860"));
                    startActivity(sharingIntent);
                } catch (NameNotFoundException e) {
                    e.printStackTrace();
                }
            } else {
                Intent intent = new Intent(mContext, WebViewFacebook.class);
                startActivity(intent);
            }

        }
    });

    Button twitterButton = (Button) socialNetworksView.findViewById(R.id.follow_twitter);
    twitterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isAppInstalled("com.twitter.android")) {
                String url = "http://www.twitter.com/aptoide";
                Intent twitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(twitterIntent);
            } else {
                Intent intent = new Intent(mContext, WebViewTwitter.class);
                startActivity(intent);
            }
        }
    });
    socialDialog.show();
}