Back to project page Android-SMSDetector.
The source code is released under:
Apache License
If you think the Android project Android-SMSDetector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
// // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at ////from w ww . j ava 2s .c o m // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. // package fiesta.share; import helpers.facebook.BaseDialogListener; import helpers.facebook.BaseRequestListener; import helpers.facebook.LoginButton; import helpers.facebook.SessionEvents; import helpers.facebook.SessionEvents.AuthListener; import helpers.facebook.SessionEvents.LogoutListener; import helpers.facebook.SessionStore; import helpers.fonts.FontsHelper; import java.util.List; import messages.detector.R; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.Typeface; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toast; import com.facebook.android.AsyncFacebookRunner; import com.facebook.android.Facebook; /* * ShareActivity * * Is responsible to manage Twitter, Facebook and Messsage channels to * share an application and post messages to users walls. * */ public class ShareActivity extends Activity { Facebook facebook = null; private AsyncFacebookRunner asyncRunner = null; private LoginButton facebookLoginButton; private ImageButton facebookShareButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.share); this.applyCustomFonts(); this.initializeFacebook(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { facebook.authorizeCallback(requestCode, resultCode, data); } private void applyCustomFonts() { FontsHelper fontsHelper = new FontsHelper(this); Typeface mainFont = fontsHelper.getMainFont(); TextView shareDescription = (TextView) findViewById(R.id.textViewShareDescription); shareDescription.setTypeface(mainFont); } private void initializeFacebook() { facebook = new Facebook(getString(R.string.FACEBOOK_APP_ID)); asyncRunner = new AsyncFacebookRunner(facebook); SessionStore.restore(facebook, this); SessionEvents.addAuthListener(new SampleAuthListener(this)); SessionEvents.addLogoutListener(new SampleLogoutListener()); facebookShareButton = (ImageButton) findViewById(R.id.btn_share_facebook); facebookShareButton .setVisibility(facebook.isSessionValid() ? View.VISIBLE : View.GONE); facebookShareButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle parameters = new Bundle(); parameters.putString("message", getString(R.string.TEXT_SHARE_BY_FACEBOOK)); parameters.putString("description", getString(R.string.TEXT_SHARE_BY_FACEBOOK)); facebook.dialog(ShareActivity.this, "stream.publish", parameters, new ShareDialogListener(ShareActivity.this)); } }); facebookLoginButton = (LoginButton) findViewById(R.id.btn_login_facebook); String[] permissions = new String[] { "publish_stream", "read_stream", "offline_access" }; facebookLoginButton.init(this, facebook, permissions); } public void twitterButtonClicked(View v) { Intent intent = this.findTwitterClient(); if (intent != null) { intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, R.string.TEXT_SHARE_BY_TWITTER); startActivity(intent); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(getString(R.string.TEXT_SHARE_BY_TWITTER)))); startActivity(intent); } } public void mailButtonClicked(View v) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_EMAIL, getString(R.string.CONTACT_EMAIL)); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.TEXT_SHARE_EMAIL_SUBJECT)); intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.TEXT_SHARE_EMAIL_BODY)); try { startActivity(Intent.createChooser(intent, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(this, getString(R.string.TEXT_ERROR_NO_EMAIL_APPS), Toast.LENGTH_SHORT).show(); } } private Intent findTwitterClient() { final String[] twitterApps = { // package // name - nb installs (thousands) "com.twitter.android", // official - 10 000 "com.twidroid", // twidroyd - 5 000 "com.handmark.tweetcaster", // Tweecaster - 5 000 "com.thedeck.android" // TweetDeck - 5 000 }; Intent tweetIntent = new Intent(); tweetIntent.setType("text/plain"); final PackageManager packageManager = getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities( tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); for (int i = 0; i < twitterApps.length; i++) { for (ResolveInfo resolveInfo : list) { String p = resolveInfo.activityInfo.packageName; if (p != null && p.startsWith(twitterApps[i])) { tweetIntent.setPackage(p); return tweetIntent; } } } return null; } public class SampleAuthListener implements AuthListener { private Context context = null; public SampleAuthListener(Context context) { super(); this.context = context; } public void onAuthSucceed() { facebookShareButton.setVisibility(View.VISIBLE); } public void onAuthFail(String error) { Toast.makeText(this.context, getString(R.string.TEXT_ERROR_FACEBOOK_AUTH), Toast.LENGTH_SHORT).show(); } } public class SampleLogoutListener implements LogoutListener { public void onLogoutBegin() { } public void onLogoutFinish() { facebookShareButton.setVisibility(View.INVISIBLE); } } public class ShareDialogListener extends BaseDialogListener { private Context context; public ShareDialogListener(Context context) { super(); this.context = context; } public void onComplete(Bundle values) { final String postId = values.getString("post_id"); if (postId != null) { asyncRunner.request(postId, new PostToWallListener()); } else { Toast.makeText(this.context, getString(R.string.TEXT_ERROR_POST), Toast.LENGTH_SHORT) .show(); } } } public class PostToWallListener extends BaseRequestListener { public void onComplete(final String response, final Object state) { ShareActivity.this.runOnUiThread(new Runnable() { public void run() { Toast.makeText(ShareActivity.this.getApplicationContext(), getString(R.string.TEXT_SUCCESS_POST), Toast.LENGTH_SHORT).show(); } }); } } }