Example usage for twitter4j TwitterException getMessage

List of usage examples for twitter4j TwitterException getMessage

Introduction

In this page you can find the example usage for twitter4j TwitterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:org.sonar.plugins.twitter.TwitterPublisher.java

License:Open Source License

private void authenticate(Configuration configuration) throws TwitterException, IOException {

    String key = configuration.getString(USERNAME_PROPERTY);
    String secret = configuration.getString(PASSWORD_PROPERTY);
    twitter.setOAuthConsumer(key, secret);

    RequestToken requestToken = twitter.getOAuthRequestToken();
    AccessToken accessToken = null;//from   ww  w. jav a  2s .  c  o  m
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (null == accessToken) {
        LOG.info("Open the following URL and grant access to your account:");
        LOG.info(requestToken.getAuthorizationURL());
        LOG.info("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
        String pin = br.readLine();
        try {
            if (pin.length() > 0) {
                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
            } else {
                accessToken = twitter.getOAuthAccessToken();
            }
        } catch (TwitterException te) {
            if (401 == te.getStatusCode()) {
                LOG.error("Unable to get the access token.");
            } else {
                LOG.error("Unexpected Twitter error: " + te.getMessage(), te);
            }
        }
    }
    int id = twitter.verifyCredentials().getId();
    // persist to the accessToken for future reference.
    storeAccessToken(configuration, id, accessToken);

    // unset clear password on the configuration
    configuration.setProperty(USERNAME_PROPERTY, null);
    configuration.setProperty(PASSWORD_PROPERTY, null);
}

From source file:org.timur.justin.JustInActivity.java

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (showTouchAreaView != null)
        showTouchAreaView.showButtons(false);

    switch (item.getItemId()) {
    case R.id.MENU_NEW_TWEET:
        if (serviceClientObject != null) {
            TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
            TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
            if (twitterService != null) {
                final Twitter twitter = twitterService.getTwitterObject();
                if (twitter != null) {
                    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                    final EditText editText = new EditText(context);
                    int maxLength = 140;
                    InputFilter[] FilterArray = new InputFilter[1];
                    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
                    editText.setFilters(FilterArray);
                    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                            case DialogInterface.BUTTON_POSITIVE:
                                String inputText = editText.getText().toString();
                                try {
                                    twitter.updateStatus(inputText);
                                } catch (twitter4j.TwitterException twex) {
                                    Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex);
                                    Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show();
                                }//  www  . j  a va  2  s.com
                                break;
                            case DialogInterface.BUTTON_NEGATIVE:
                                break;
                            }
                        }
                    };
                    alertDialogBuilder.setTitle("New tweet");
                    alertDialogBuilder.setView(editText);
                    alertDialogBuilder.setPositiveButton("Send", dialogClickListener)
                            .setNegativeButton("Abort", dialogClickListener).show();
                }
            }
        }
        return true;

    case R.id.MENU_HELP:
        GlTickerView.openInBrowser("http://timur.mobi/justin-app/");
        return true;

    case R.id.MENU_AUTO_FORWARD:
        if (glView != null) {
            if (glView.autoForward)
                glView.autoForward = false;
            else
                glView.autoForward = true;
            lastJingleTime = SystemClock.uptimeMillis();
            if (Config.LOGD)
                Log.i(LOGTAG, "onOptionsItemSelected() autoForward=" + glView.autoForward);
        }
        return true;

    case R.id.MENU_TOUCHAREAS:
        if (showTouchAreaView != null) {
            if (showTouchAreaViewActiveSince == 0l) {
                showTouchAreaView.showButtons(true);
                showTouchAreaViewActiveSince = SystemClock.uptimeMillis();
            } else {
                showTouchAreaView.showButtons(false);
                showTouchAreaViewActiveSince = 0l;
            }
        }
        return true;

    case R.id.MENU_PROCESS_MSG:
        if (Config.LOGD)
            Log.i(LOGTAG, "onOptionsItemSelected() -> showDialog(DIALOG_USE_MSG)");
        showDialog(DIALOG_USE_MSG);
        return true;

    case R.id.MENU_MORE:
        showDialog(DIALOG_MORE);
        return true;
    }

    //return super.onOptionsItemSelected(item);
    return false;
}

From source file:org.timur.justin.JustInActivity.java

License:Apache License

@Override
public Dialog onCreateDialog(final int id) {
    Dialog menuDialog = null;/*from w  ww . j a  va  2s  .co m*/

    if (id == DIALOG_ABOUT) {
        if (Config.LOGD)
            Log.i(LOGTAG, "onCreateDialog id==DIALOG_ABOUT setContentView(R.layout.about_dialog)");
        menuDialog = new Dialog(this, R.style.NoTitleDialog);
        menuDialog.setContentView(R.layout.about_dialog);

        PackageInfo pinfo;
        int versionNumber = 0;
        String versionName = "";
        try {
            pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            versionNumber = pinfo.versionCode;
            versionName = pinfo.versionName;
            if (Config.LOGD)
                Log.i(LOGTAG, "onCreateDialog id==DIALOG_ABOUT manifest versionName=" + versionName);
            TextView textView = (TextView) menuDialog.findViewById(R.id.aboutVersion);
            textView.setText((CharSequence) ("v" + versionName), TextView.BufferType.NORMAL);
        } catch (android.content.pm.PackageManager.NameNotFoundException nnfex) {
            Log.e(LOGTAG, "onClick btnAbout FAILED on getPackageManager().getPackageInfo(getPackageName(), 0) "
                    + nnfex);
        }

        return menuDialog;
    }

    final GradientDrawable mBackgroundGradient = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { 0x30606060, 0x30000000 });

    if (currentEntryTopic != null) {
        if (Config.LOGD)
            Log.i(LOGTAG, "onCreateDialog() id=" + id + " link=" + currentEntryTopic.link);
    }
    menuDialog = new Dialog(this, R.style.NoTitleDialog);

    if (id == DIALOG_USE_MSG) {
        menuDialog.setContentView(R.layout.open_dialog);
        menuDialog.findViewById(R.id.buttonLayout).setBackgroundDrawable(mBackgroundGradient);

        // tweet
        Button btnTweetReply = (Button) menuDialog.findViewById(R.id.buttonOpenTweetReply);
        if (btnTweetReply != null) {
            btnTweetReply.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnTweetReply");
                    if (currentEntryTopic != null) {
                        if (serviceClientObject != null) {
                            TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                            TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                            if (twitterService != null) {
                                final Twitter twitter = twitterService.getTwitterObject();
                                if (twitter != null) {
                                    final EditText editText = new EditText(context);
                                    int maxLength = 140;
                                    InputFilter[] FilterArray = new InputFilter[1];
                                    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
                                    editText.setFilters(FilterArray);
                                    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            switch (which) {
                                            case DialogInterface.BUTTON_POSITIVE:
                                                String inputText = editText.getText().toString();
                                                try {
                                                    twitter.updateStatus(inputText);
                                                } catch (twitter4j.TwitterException twex) {
                                                    Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex);
                                                    Toast.makeText(context, twex.getMessage(),
                                                            Toast.LENGTH_LONG).show();
                                                }
                                                break;
                                            case DialogInterface.BUTTON_NEGATIVE:
                                                break;
                                            }
                                        }
                                    };
                                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                                    alertDialogBuilder.setTitle("Reply tweet");
                                    alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title));
                                    editText.setText(
                                            "@" + currentEntryTopic.shortName + " "
                                                    + ripTags(currentEntryTopic.title),
                                            TextView.BufferType.EDITABLE);
                                    // todo: should show length of message (or rather: 140 - number of characters)
                                    alertDialogBuilder.setView(editText);
                                    alertDialogBuilder.setPositiveButton("Send", dialogClickListener)
                                            .setNegativeButton("Abort", dialogClickListener).show();
                                }
                            }
                        }
                    }
                    dismissDialog(id);
                }
            });
        }

        // retweet
        Button btnRetweet = (Button) menuDialog.findViewById(R.id.buttonOpenRetweet);
        if (btnRetweet != null) {
            btnRetweet.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnRetweet");
                    if (currentEntryTopic != null) {
                        if (serviceClientObject != null) {
                            TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                            TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                            if (twitterService != null) {
                                final Twitter twitter = twitterService.getTwitterObject();
                                if (twitter != null) {
                                    // yes/no dialog
                                    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            switch (which) {
                                            case DialogInterface.BUTTON_POSITIVE:
                                                try {
                                                    twitter.retweetStatus(currentEntryTopic.id);
                                                    Toast.makeText(context, "delivered retweet",
                                                            Toast.LENGTH_SHORT).show();
                                                } catch (twitter4j.TwitterException twex) {
                                                    Log.e(LOGTAG, "FAILED on twitter.retweetStatus() " + twex);
                                                    Toast.makeText(context, twex.getMessage(),
                                                            Toast.LENGTH_LONG).show();
                                                }
                                                break;
                                            case DialogInterface.BUTTON_NEGATIVE:
                                                break;
                                            }
                                        }
                                    };
                                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                                    alertDialogBuilder.setTitle("Retweet");
                                    alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title));
                                    alertDialogBuilder.setPositiveButton("Send", dialogClickListener)
                                            .setNegativeButton("Abort", dialogClickListener).show();
                                }
                            }
                        }
                    }
                    dismissDialog(id);
                }
            });
        }

        // mark as Favorit
        Button btnMarkFavorit = (Button) menuDialog.findViewById(R.id.buttonMarkFavorit);
        if (btnMarkFavorit != null) {
            btnMarkFavorit.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnMarkFavorit");
                    if (currentEntryTopic != null) {
                        if (serviceClientObject != null) {
                            if (Config.LOGD)
                                Log.i(LOGTAG, "onClick btnMarkFavorit get tickerService...");
                            TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                            TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                            if (twitterService != null) {
                                if (Config.LOGD)
                                    Log.i(LOGTAG, "onClick btnMarkFavorit got twitterService");
                                final Twitter twitter = twitterService.getTwitterObject();
                                if (twitter != null) {
                                    if (Config.LOGD)
                                        Log.i(LOGTAG, "onClick btnMarkFavorit got twitterObject");
                                    // yes/no dialog
                                    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            switch (which) {
                                            case DialogInterface.BUTTON_POSITIVE:
                                                try {
                                                    twitter.createFavorite(currentEntryTopic.id);
                                                } catch (twitter4j.TwitterException twex) {
                                                    Log.e(LOGTAG, "FAILED on twitter.retweetStatus() " + twex);
                                                    Toast.makeText(context, twex.getMessage(),
                                                            Toast.LENGTH_LONG).show();
                                                }
                                                break;
                                            case DialogInterface.BUTTON_NEGATIVE:
                                                break;
                                            }
                                        }
                                    };
                                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                                    if (Config.LOGD)
                                        Log.i(LOGTAG, "onClick btnMarkFavorit got alertDialogBuilder");
                                    alertDialogBuilder.setTitle("Mark as favorit");
                                    alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title));
                                    if (Config.LOGD)
                                        Log.i(LOGTAG, "onClick btnMarkFavorit alertDialogBuilder start...");
                                    alertDialogBuilder.setPositiveButton("Favorit", dialogClickListener)
                                            .setNegativeButton("Abort", dialogClickListener).show();
                                    if (Config.LOGD)
                                        Log.i(LOGTAG, "onClick btnMarkFavorit alertDialogBuilder started");
                                }
                            }
                        }
                    }
                    dismissDialog(id);
                }
            });
        }

        // Browse...
        Button btnBrowse = (Button) menuDialog.findViewById(R.id.buttonOpenBrowse);
        if (btnBrowse != null) {
            btnBrowse.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "btnBrowse currentEntryTopic=" + currentEntryTopic);
                    if (currentEntryTopic != null) {
                        glView.openCurrentMsgInBrowser(currentEntryTopic);
                    }
                    dismissDialog(id);
                }
            });
        }

        // Send by Mail
        Button btnEmail = (Button) menuDialog.findViewById(R.id.buttonOpenEmail);
        if (btnEmail != null) {
            btnEmail.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "btnEmail currentEntryTopic=" + currentEntryTopic);
                    if (currentEntryTopic != null && currentEntryTopic.title != null) {
                        Intent sendMailIntent = new Intent(Intent.ACTION_SEND);
                        sendMailIntent.putExtra(Intent.EXTRA_SUBJECT, currentEntryTopic.channelName + ": "
                                + ripTags(currentEntryTopic.title).substring(0, 40) + "...");
                        sendMailIntent.putExtra(Intent.EXTRA_TEXT, ripTags(currentEntryTopic.title));
                        sendMailIntent.setType("message/rfc822");
                        startActivity(sendMailIntent);
                    }
                    dismissDialog(id);
                }
            });
        }

        // Send by SMS
        Button btnSMS = (Button) menuDialog.findViewById(R.id.buttonOpenSMS);
        if (btnSMS != null) {
            btnSMS.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "btnSMS currentEntryTopic=" + currentEntryTopic);
                    if (currentEntryTopic != null) {
                        Uri smsUri = Uri.parse("smsto:");
                        Intent sendSmsIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
                        sendSmsIntent.putExtra("sms_body",
                                currentEntryTopic.channelName + ": " + ripTags(currentEntryTopic.title));
                        //sendSmsIntent.setType("vnd.android-dir/mms-sms");
                        try {
                            startActivity(sendSmsIntent);
                        } catch (Exception ex) {
                            String errMsg = ex.getMessage();
                            Toast.makeText(context, errMsg, Toast.LENGTH_LONG).show();
                        }
                    }
                    dismissDialog(id);
                }
            });
        }

        //      // bluetooth
        //      Button btnBluetooth = (Button)menuDialog.findViewById(R.id.buttonOpenBluetooth);
        //      if(btnBluetooth!=null) {
        //        btnBluetooth.setOnClickListener(new View.OnClickListener() {
        //            public void onClick(View view) { 
        //              if(currentEntryTopic!=null) {
        //                // todo: must implement
        //                Toast.makeText(context, "bluetooth not yet implemented", Toast.LENGTH_LONG).show();
        //              }
        //              dismissDialog(id);
        //            } 
        //          }
        //        );
        //      }

        // close
        Button btnClose = (Button) menuDialog.findViewById(R.id.buttonClose);
        if (btnClose != null) {
            btnClose.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    dismissDialog(id);
                }
            });
        }

    } else if (id == DIALOG_MORE) {
        menuDialog.setContentView(R.layout.more_dialog);
        menuDialog.findViewById(R.id.buttonLayout).setBackgroundDrawable(mBackgroundGradient);

        // browse Favorits
        Button btnBrowseFavorits = (Button) menuDialog.findViewById(R.id.buttonBrowseFavorits);
        if (btnBrowseFavorits != null) {
            btnBrowseFavorits.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnBrowseFavorits glView=" + glView);
                    if (glView != null) {
                        if (serviceClientObject != null) {
                            TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                            TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                            if (Config.LOGD)
                                Log.i(LOGTAG, "onClick btnBrowseFavorits twitterService=" + twitterService);
                            if (twitterService != null) {
                                final Twitter twitter = twitterService.getTwitterObject();
                                if (twitter != null) {
                                    try {
                                        glView.openInBrowser(
                                                "http://twitter.com/" + twitter.getScreenName() + "/favorites");
                                    } catch (twitter4j.TwitterException twex) {
                                        Log.e(LOGTAG, "FAILED on twitter.getScreenName() " + twex);
                                        Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show();
                                    }
                                }
                            }
                        }
                    }
                    dismissDialog(id);
                }
            });
        }

        // re-login / clear password
        Button btnClearPassword = (Button) menuDialog.findViewById(R.id.buttonClearPassword);
        if (btnClearPassword != null) {
            btnClearPassword.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnClearPassword serviceClientObject=" + serviceClientObject);
                    if (serviceClientObject != null) {
                        final TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                        final TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                        if (Config.LOGD)
                            Log.i(LOGTAG, "onClick btnClearPassword twitterService=" + twitterService);
                        if (twitterService != null) {

                            // yes/no dialog
                            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch (which) {
                                    case DialogInterface.BUTTON_POSITIVE:
                                        if (Config.LOGD)
                                            Log.i(LOGTAG, "onClick btnClearPassword MENU_CLEAR_PASSWORD");
                                        twitterService.clearTwitterLogin();
                                        // restart activity
                                        if (Config.LOGD)
                                            Log.i(LOGTAG, "onClick btnClearPassword restart activity");
                                        Intent intent = getIntent();
                                        overridePendingTransition(0, 0);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                                        finish();
                                        try {
                                            Thread.sleep(1500);
                                        } catch (Exception ex2) {
                                        }
                                        ;
                                        if (Config.LOGD)
                                            Log.i(LOGTAG,
                                                    "onClick btnClearPassword finish() done, starting...");
                                        overridePendingTransition(0, 0);
                                        startActivity(intent);
                                        // on restart, OAuthActivity will be opened
                                        break;
                                    case DialogInterface.BUTTON_NEGATIVE:
                                        break;
                                    }
                                }
                            };
                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                            if (Config.LOGD)
                                Log.i(LOGTAG, "onClick btnClearPassword got alertDialogBuilder");
                            alertDialogBuilder.setTitle("Re-Login");
                            if (Config.LOGD)
                                Log.i(LOGTAG, "onClick btnClearPassword alertDialogBuilder start...");
                            alertDialogBuilder.setPositiveButton("Re-Login", dialogClickListener)
                                    .setNegativeButton("Abort", dialogClickListener).show();
                            if (Config.LOGD)
                                Log.i(LOGTAG, "onClick btnClearPassword alertDialogBuilder started");
                        }
                    }

                    dismissDialog(id);
                }
            });
        }

        // shutdown all
        Button btnShutdownAll = (Button) menuDialog.findViewById(R.id.buttonShutdownAll);
        if (btnShutdownAll != null) {
            btnShutdownAll.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnShutdownAll serviceClientObject=" + serviceClientObject);

                    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                            case DialogInterface.BUTTON_POSITIVE:
                                if (serviceClientObject != null) {
                                    TickerServiceAbstract tickerService = serviceClientObject
                                            .getServiceObject();
                                    if (tickerService != null) {
                                        if (Config.LOGD)
                                            Log.i(LOGTAG, "onClick btnShutdownAll tickerService.stopSelf()");
                                        tickerService.stopSelf();
                                    }
                                }
                                if (Config.LOGD)
                                    Log.i(LOGTAG, "onClick btnShutdownAll System.exit(0)");
                                System.exit(0);
                                break;
                            case DialogInterface.BUTTON_NEGATIVE:
                                break;
                            }
                        }
                    };
                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                    alertDialogBuilder.setTitle("Shutdown all");
                    alertDialogBuilder.setPositiveButton("Shut down", dialogClickListener)
                            .setNegativeButton("Keep running", dialogClickListener).show();
                    dismissDialog(id);
                }
            });
        }

        // about
        Button btnAbout = (Button) menuDialog.findViewById(R.id.buttonAbout);
        if (btnAbout != null) {
            btnAbout.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnAbout");
                    showDialog(DIALOG_ABOUT);
                    dismissDialog(id);
                }
            });
        }

        // promote
        Button btnPromote = (Button) menuDialog.findViewById(R.id.buttonPromote);
        if (btnPromote != null) {
            btnPromote.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnPromote");
                    showDialog(DIALOG_PROMOTE);
                    dismissDialog(id);
                }
            });
        }

        // close
        Button btnClose = (Button) menuDialog.findViewById(R.id.buttonClose);
        if (btnClose != null) {
            btnClose.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    dismissDialog(id);
                }
            });
        }
    } else if (id == DIALOG_PROMOTE) {
        if (Config.LOGD)
            Log.i(LOGTAG, "onCreateDialog id==DIALOG_PROMOTE setContentView(R.layout.promote_dialog)");
        menuDialog = new Dialog(this, R.style.NoTitleDialog);
        menuDialog.setContentView(R.layout.promote_dialog);

        // promote mail
        Button btnPromoteMail = (Button) menuDialog.findViewById(R.id.buttonPromoteMail);
        if (btnPromoteMail != null) {
            btnPromoteMail.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnPromoteMail");

                    Intent sendMailIntent = new Intent(Intent.ACTION_SEND);
                    sendMailIntent.putExtra(Intent.EXTRA_SUBJECT, "Just in... for Android");
                    sendMailIntent.putExtra(Intent.EXTRA_TEXT,
                            "Hi \ncheck this out...\n\nJust in... OpenGL Twitter reader free download from Android Market\nhttp://market.android.com/details?id=org.timur.justin\n");
                    sendMailIntent.setType("message/rfc822");
                    startActivity(sendMailIntent);

                    dismissDialog(id);
                }
            });
        }

        // promote SMS
        Button btnPromoteSMS = (Button) menuDialog.findViewById(R.id.buttonPromoteSMS);
        if (btnPromoteSMS != null) {
            btnPromoteSMS.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnPromoteSMS");

                    Uri smsUri = Uri.parse("smsto:");
                    Intent sendSmsIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
                    sendSmsIntent.putExtra("sms_body",
                            "Just in... OpenGL Twitter reader free DL from Android Market http://market.android.com/details?id=org.timur.justin");
                    //sendSmsIntent.setType("vnd.android-dir/mms-sms");
                    try {
                        startActivity(sendSmsIntent);
                    } catch (Exception ex) {
                        String errMsg = ex.getMessage();
                        Toast.makeText(context, errMsg, Toast.LENGTH_LONG).show();
                    }

                    dismissDialog(id);
                }
            });
        }

        // promote tweet
        Button btnPromoteTweet = (Button) menuDialog.findViewById(R.id.buttonPromoteTweet);
        if (btnPromoteTweet != null) {
            btnPromoteTweet.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    if (Config.LOGD)
                        Log.i(LOGTAG, "onClick btnPromoteTweet");

                    if (serviceClientObject != null) {
                        TickerServiceAbstract tickerService = serviceClientObject.getServiceObject();
                        TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService;
                        if (twitterService != null) {
                            final Twitter twitter = twitterService.getTwitterObject();
                            if (twitter != null) {
                                final EditText editText = new EditText(context);
                                int maxLength = 140;
                                InputFilter[] FilterArray = new InputFilter[1];
                                FilterArray[0] = new InputFilter.LengthFilter(maxLength);
                                editText.setFilters(FilterArray);
                                DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        switch (which) {
                                        case DialogInterface.BUTTON_POSITIVE:
                                            String inputText = editText.getText().toString();
                                            try {
                                                twitter.updateStatus(inputText);
                                            } catch (twitter4j.TwitterException twex) {
                                                Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex);
                                                Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG)
                                                        .show();
                                            }
                                            break;
                                        case DialogInterface.BUTTON_NEGATIVE:
                                            break;
                                        }
                                    }
                                };
                                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                                alertDialogBuilder.setTitle("Tweet");
                                //alertDialogBuilder.setMessage("");
                                editText.setText(
                                        "'Just in...' #OpenGL #Twitter reader free DL from #Android Market http://market.android.com/details?id=org.timur.justin",
                                        TextView.BufferType.EDITABLE);
                                // todo: should show length of message (or rather: 140 - number of characters)
                                alertDialogBuilder.setView(editText);
                                alertDialogBuilder.setPositiveButton("Send", dialogClickListener)
                                        .setNegativeButton("Abort", dialogClickListener).show();
                            }
                        }
                    }

                    dismissDialog(id);
                }
            });
        }
    }

    return menuDialog;
}

From source file:org.tomitribe.chatterbox.twitter.adapter.TwitterResourceAdapter.java

License:Apache License

private void processResponse(final Status status, final Object result) {
    if (Response.class.isInstance(result)) {
        final Response response = Response.class.cast(result);
        RESPONSE_MAP.put(status.getUser().getScreenName(), response);
        try {//from w ww  . ja  v  a 2s  . co  m
            replyTo(status, response.getMessage());
        } catch (TwitterException e) {
            LOGGER.severe("Unable to send tweet" + e.getMessage());
        }
    } else {
        RESPONSE_MAP.remove(status.getUser().getScreenName());
    }

    if (String.class.isInstance(result)) {
        RESPONSE_MAP.remove(status.getUser().getScreenName());
        try {
            replyTo(status, String.class.cast(result));
        } catch (TwitterException e) {
            LOGGER.severe("Unable to send tweet" + e.getMessage());
        }
    }
}

From source file:org.wandora.application.tools.extractors.twitter.AbstractTwitterExtractor.java

License:Open Source License

public void searchTwitter(Query[] queries, int pages, TopicMap tm) {
    if (tm == null || queries == null || queries.length == 0)
        return;//w  w w  .jav a  2s.  c  o  m

    initializeTwitter();

    if (pin == null || pin.length() == 0) {
        try {
            AccessToken accessToken = null;
            String authorizationURL = requestToken.getAuthorizationURL();

            TwitterAuthorizationDialog authorizer = new TwitterAuthorizationDialog();
            authorizer.open(authorizationURL);

            if (authorizer.wasAccepted()) {
                pin = authorizer.getPin();
            } else {
                return;
            }

            if (pin != null && pin.length() > 0) {
                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
            } else {
                accessToken = twitter.getOAuthAccessToken();
            }
        } catch (TwitterException ex) {
            log("Invalid Twitter authorization. Please, check the PIN code '" + pin + "' and try again.");
            //log(ex);
            pin = null;
            return;
        }
    }

    try {
        Topic twitterSearchTopic = tm.createTopic();
        if (twitterSearchTopic != null) {
            long stamp = System.currentTimeMillis();
            twitterSearchTopic.addSubjectIdentifier(new Locator(TWITTER_SEARCH_BODY + "/" + stamp));
            twitterSearchTopic.setBaseName("Twitter search " + stamp);
            twitterSearchTopic.addType(getTwitterSearchType(tm));

            Topic twitterSearchDateType = getTwitterSearchDateType(tm);
            if (twitterSearchDateType != null) {
                Date d = new Date(stamp);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dStr = sdf.format(d);
                twitterSearchTopic.setData(twitterSearchDateType,
                        TMBox.getLangTopic(twitterSearchTopic, DEFAULT_LANG), dStr);
            }

            for (Query currentQuery : queries) {
                if (currentQuery == null)
                    continue;
                int currentPage = 0;
                log("Processing Twitter query '" + currentQuery.getQuery() + "'");
                while (currentQuery != null) {
                    if (forceStop()) {
                        log("Aborting...");
                        break;
                    }
                    currentPage++;
                    hlog("Requesting search result page " + currentPage + (pages == 0 ? "" : " of " + pages));

                    QueryResult result = twitter.search(currentQuery);

                    Topic twitterSearchQueryType = getTwitterSearchQueryType(tm);
                    if (twitterSearchQueryType != null) {
                        twitterSearchTopic.setData(twitterSearchQueryType,
                                TMBox.getLangTopic(twitterSearchTopic, DEFAULT_LANG), currentQuery.getQuery());
                    }

                    ArrayList tweets = (ArrayList) result.getTweets();
                    for (Object tweet : tweets) {
                        if (tweet != null && tweet instanceof Status) {
                            Status t = (Status) tweet;
                            Topic topic = reifyTweet(t, tm);
                            topic.addType(twitterSearchTopic);
                        }
                    }

                    try {
                        Thread.currentThread().sleep(SLEEP_TIME_BETWEEN_SEARCHES);
                    } catch (Exception e) {
                        // ...WAKE UP...
                    }

                    if (pages == 0 || currentPage < pages) {
                        currentQuery = result.nextQuery();
                    } else {
                        currentQuery = null;
                    }
                }
                log("Number of processed search result pages is " + currentPage);
            }
        }
    } catch (TopicMapException tme) {
        log("A topic map exception " + tme.getMessage() + " occurred while searching Twitter messages.");
        tme.printStackTrace();
    } catch (TwitterException te) {
        log("A Twitter exception " + te.getMessage() + " occurred while searching messages.");
        te.printStackTrace();
    }
    ;
}

From source file:org.wso2.carbon.connector.twitter.TwiterGetAvailableTrends.java

License:Apache License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    // TODO Auto-generated method stub
    try {//  w  ww  . ja va  2  s .c o m
        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();
        List<Location> locations = twitter.getAvailableTrends();
        OMElement resultElement = AXIOMUtil.stringToOM("<jsonObject><trends/></jsonObject>");
        for (Location location : locations) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("{ \"trend\" : ");
            String json = DataObjectFactory.getRawJSON(location);
            stringBuilder.append(json);
            stringBuilder.append("} ");
            OMElement element = super.parseJsonToXml(stringBuilder.toString());
            resultElement.addChild(element);
        }

        if (locations.size() == 0) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("{ \"trend\" :{} ");
            stringBuilder.append("} ");
            OMElement element = super.parseJsonToXml(stringBuilder.toString());
            resultElement.addChild(element);
        }

        super.preparePayload(messageContext, resultElement);

    } catch (TwitterException te) {
        log.error("Failed to load  available trends: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        // TODO Auto-generated catch block
        log.error("Failed to load  available trends: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }

}

From source file:org.wso2.carbon.connector.twitter.TwitterDestroyStatus.java

License:Open Source License

public void connect(MessageContext messageContext) throws ConnectException {
    try {// w w  w .  j av  a 2  s.  c o  m
        String statusId = TwitterUtils.lookupTemplateParamater(messageContext, STATUSID);
        if (statusId == null || "".equals(statusId.trim())) {
            log.error("Required status Id: ");
            return;
        }
        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();
        Status status = twitter.destroyStatus(Long.parseLong(statusId));
        TwitterUtils.storeResponseStatus(messageContext, status);
    } catch (TwitterException te) {
        log.error("Failed to destroy the status: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}

From source file:org.wso2.carbon.connector.twitter.TwitterGetDirectMessages.java

License:Open Source License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    if (log.isDebugEnabled()) {
        log.info("executing twitter get user time line");
    }/*from ww w .j  a  v  a2  s  .  c o m*/

    try {
        String page = (TwitterUtils.lookupTemplateParamater(messageContext, PAGE) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, PAGE).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, PAGE)
                        : null;

        String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT)
                        : null;

        String sinceID = (TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID)
                        : null;

        String maxID = (TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID)
                        : null;

        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();

        List<DirectMessage> results = null;
        if (page != null && !page.isEmpty()) {
            if (count == null && sinceID == null && maxID == null) {
                results = twitter.getDirectMessages(new Paging(Long.parseLong(page)));
            } else if (count != null && sinceID == null && maxID == null) {

                results = twitter
                        .getDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count)));
            } else if (count != null && sinceID != null && maxID == null) {
                results = twitter.getDirectMessages(
                        new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID)));
            } else {
                results = twitter.getDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count),
                        Long.parseLong(sinceID), Long.parseLong(maxID)));
            }
        } else if (page == null && sinceID != null) {
            results = twitter.getDirectMessages(new Paging(Integer.parseInt(sinceID)));
        } else {
            results = twitter.getDirectMessages();
        }
        OMElement element = this.performSearchMessages(results);

        super.preparePayload(messageContext, element);

    } catch (TwitterException te) {
        log.error("Failed to search twitter : " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        log.error("Failed to search generic: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}

From source file:org.wso2.carbon.connector.twitter.TwitterGetFollowers.java

License:Open Source License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    if (log.isDebugEnabled()) {
        log.info("executing twitter get user time line");
    }//from  w w  w  .ja  v a  2 s . co  m

    try {

        String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME)
                        : null;

        String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID)
                        : null;

        String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT)
                        : null;

        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();

        List<User> results = null;

        if (screenName != null && !screenName.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                results = twitter.getFollowersList(screenName, Long.parseLong(count));
            } else {
                results = twitter.getFollowersList(screenName, -1);
            }
        } else if (userID != null && !userID.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                results = twitter.getFollowersList(Long.parseLong(userID), Long.parseLong(count));
            } else {
                results = twitter.getFollowersList(Long.parseLong(userID), -1);
            }
        }

        if (log.isDebugEnabled()) {
            log.error("Retrived results : " + results.toString());
        }

        OMElement element = this.performSearchMessages(results);

        super.preparePayload(messageContext, element);

    } catch (TwitterException te) {
        log.error("Failed to search twitter : " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        log.error("Failed to search generic: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}

From source file:org.wso2.carbon.connector.twitter.TwitterGetFollowersIds.java

License:Open Source License

@Override
public void connect(MessageContext messageContext) throws ConnectException {
    if (log.isDebugEnabled()) {
        log.info("executing twitter get user time line");
    }/*w ww. j a v a 2  s .  co  m*/

    try {

        String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME)
                        : null;

        String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty())

                        ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID)
                        : null;

        String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null
                && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty())
                        ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT)
                        : null;

        Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient();

        IDs ids = null;

        if (screenName != null && !screenName.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                ids = twitter.getFollowersIDs(screenName, Long.parseLong(count));
            } else {
                ids = twitter.getFollowersIDs(screenName, -1);
            }
        } else if (userID != null && !userID.isEmpty()) {
            if (count != null && !count.isEmpty()) {
                ids = twitter.getFollowersIDs(Long.parseLong(userID), Long.parseLong(count));
            } else {
                ids = twitter.getFollowersIDs(Long.parseLong(userID), -1);
            }
        }

        if (log.isDebugEnabled()) {
            log.error("Retrived result: " + ids.toString());
        }

        OMElement element = this.performSearchMessages(ids.getIDs());

        super.preparePayload(messageContext, element);

    } catch (TwitterException te) {
        log.error("Failed to search twitter : " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    } catch (Exception te) {
        log.error("Failed to search generic: " + te.getMessage(), te);
        TwitterUtils.storeErrorResponseStatus(messageContext, te);
    }
}