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 ww w . j av a 2 s. com*/ // 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 messages.detector; import fiesta.share.ShareActivity; import helpers.admob.AdMobHelper; import helpers.audio.AudioHelper; import helpers.fonts.FontsHelper; import java.util.Vector; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.PopupWindow; import android.widget.PopupWindow.OnDismissListener; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; public class ImportantMessagesDetectorActivity extends Activity { PopupWindow popupHelp = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.configureSpinnerOptions(); this.configureCustomFonts(); this.configureAudioHelper(); this.configureSelectedWords(); this.setCorrectStateForToggleButton(); this.addAdsView(); } private void configureCustomFonts() { FontsHelper fontsHelper = new FontsHelper(this.getApplicationContext()); Typeface mainFont = fontsHelper.getMainFont(); TextView configureWords = (TextView) findViewById(R.id.textConfigureWords); TextView chooseSounds = (TextView) findViewById(R.id.textChooseSound); Button buttonPlay = (Button) findViewById(R.id.buttonPlay); Button buttonSave = (Button) findViewById(R.id.buttonSave); ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton); TextView appEnabled = (TextView) findViewById(R.id.textViewEnableApp); configureWords.setTypeface(mainFont); chooseSounds.setTypeface(mainFont); buttonPlay.setTypeface(mainFont); buttonSave.setTypeface(mainFont); toggleButton.setTypeface(mainFont); appEnabled.setTypeface(mainFont); } private void setCorrectStateForToggleButton() { ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton); SharedPreferences settings = getSharedPreferences( getString(R.string.PREFERENCES_FILENAME), 0); boolean isAppEnabled = settings.getBoolean( getString(R.string.PREFERENCES_ENABLE_APP), false); toggleButton.setChecked(isAppEnabled); } private void addAdsView() { FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayoutBanner); AdMobHelper adMobHelper = AdMobHelper.getInstance(); adMobHelper.addNewAdViewToView(layout, this); } private void configureSelectedWords() { SharedPreferences settings = getSharedPreferences( getString(R.string.PREFERENCES_FILENAME), 0); String configuredWords = settings.getString( getString(R.string.PREFERENCES_CODE), ""); EditText selectedWords = (EditText) findViewById(R.id.editTextConfigureWords); selectedWords.setText(configuredWords); } private void configureSpinnerOptions() { Spinner spinnerSounds = (Spinner) findViewById(R.id.spinnerChooseSound); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.SOUNDS, R.layout.spinner_layout); spinnerSounds.setAdapter(adapter); } private void configureAudioHelper() { // load the audio helper Vector<String> resourcesIds = new Vector<String>(); resourcesIds.add(String.valueOf(R.raw.sound1)); resourcesIds.add(String.valueOf(R.raw.sound2)); resourcesIds.add(String.valueOf(R.raw.sound3)); resourcesIds.add(String.valueOf(R.raw.sound4)); resourcesIds.add(String.valueOf(R.raw.sound5)); resourcesIds.add(String.valueOf(R.raw.sound6)); resourcesIds.add(String.valueOf(R.raw.sound7)); AudioHelper helper = AudioHelper.getInstance(); helper.setContext(this); helper.configureWithSoundsResourcesIds(resourcesIds); helper.setMaxConcurrentSounds(3); } @Override protected void onDestroy() { // release audio helper AudioHelper.getInstance().release(); super.onDestroy(); } public void saveButtonClicked(View v) { Spinner spinnerSound = (Spinner) findViewById(R.id.spinnerChooseSound); EditText editTextCode = (EditText) findViewById(R.id.editTextConfigureWords); // read the selected sound and look for the raw identifier associated String soundName = (String) spinnerSound.getSelectedItem(); int soundRawIndentifier = this.rawIdentifierForSelectedSound(soundName); // read the configured text code to awake the phone String code = editTextCode.getText().toString(); // save the selected information to users settings SharedPreferences settings = getSharedPreferences( getString(R.string.PREFERENCES_FILENAME), 0); Editor editor = settings.edit(); editor.putInt(getString(R.string.PREFERENCES_SOUND_RAW_ID), soundRawIndentifier); editor.putString(getString(R.string.PREFERENCES_CODE), code); // commit the configuration changes! boolean didSaveChanges = editor.commit(); // display a feedback message String text = getString(R.string.TEXT_SUCCESSFUL_SAVE); if (!didSaveChanges) { text = getString(R.string.TEXT_ERRONEOUS_SAVE); } Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT); toast.show(); } public void toggleButtonClicked(View v) { ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton); boolean isAppEnabled = toggleButton.isChecked(); SharedPreferences settings = getSharedPreferences( getString(R.string.PREFERENCES_FILENAME), 0); Editor editor = settings.edit(); editor.putBoolean(getString(R.string.PREFERENCES_ENABLE_APP), isAppEnabled); boolean didSaveChanges = editor.commit(); // display a feedback message String text = getString(R.string.TEXT_SUCCESSFUL_ENABLING); if (!didSaveChanges) { text = getString(R.string.TEXT_ERRONEOUS_ENABLING); } Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT); toast.show(); } public void contactButtonClicked(View v) { // Intent ACTION_SENDTO to filter only email application (discard // bluetooth and other apps) Intent send = new Intent(Intent.ACTION_SENDTO); String uriText; uriText = "mailto:contact-importantmessagesdetector@widgetsfactory.com.ar" + "?subject=Important Message Detector Contact"; uriText = uriText.replace(" ", "%20"); Uri uri = Uri.parse(uriText); send.setData(uri); try { startActivity(Intent.createChooser(send, "Send email")); } catch (ActivityNotFoundException exception) { Context context = getApplicationContext(); CharSequence text = "Sorry, we can not send emails right now. \nPlease contact us to contact-heyjohnny@widgetsfactory.com.ar."; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.itemHelp: this.helpButtonClicked(null); return true; case R.id.itemShare: this.shareButtonClicked(null); return true; default: return super.onOptionsItemSelected(item); } } public void helpButtonClicked(View v) { if (popupHelp == null) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.help_view, (ViewGroup) findViewById(R.id.popup_node)); View mainView = findViewById(R.id.mainLayout); int height = mainView.getHeight(); int width = mainView.getWidth(); FontsHelper fonstHelper = new FontsHelper(this.getApplicationContext()); Typeface mainFont = fonstHelper.getMainFont(); TextView textView1 = (TextView) layout.findViewById(R.id.textView1); TextView textView3 = (TextView) layout.findViewById(R.id.textView3); TextView textView5 = (TextView) layout.findViewById(R.id.textView5); Button btnClose = (Button) layout.findViewById(R.id.btnClose); textView1.setTypeface(mainFont); textView3.setTypeface(mainFont); textView5.setTypeface(mainFont); btnClose.setTypeface(mainFont); popupHelp = new PopupWindow(layout, width - 20, height - 20, true); /* * This is needed for proper handling of the Back Key, because the * popup window does not respond to onTouch or onKey events unless * it has a background != null. */ popupHelp.setBackgroundDrawable(new BitmapDrawable()); popupHelp.showAtLocation(layout, Gravity.CENTER, 0, 0); popupHelp.setOnDismissListener(new OnDismissListener() { public void onDismiss() { popupHelp.dismiss(); popupHelp = null; } }); } } public void closeButtonClicked(View v) { popupHelp.dismiss(); popupHelp = null; } public void playButtonClicked(View v) { // read the selected sound and look for the raw identifier associated Spinner spinnerSound = (Spinner) findViewById(R.id.spinnerChooseSound); String soundName = (String) spinnerSound.getSelectedItem(); int soundRawIndentifier = this.rawIdentifierForSelectedSound(soundName); int looping = 0; float volume = 1.0f; AudioHelper.getInstance().playSoundsWithResourceId(soundRawIndentifier, looping, volume); } private int rawIdentifierForSelectedSound(String soundName) { if (soundName.contains("-1-")) { return R.raw.sound1; } if (soundName.contains("-2-")) { return R.raw.sound2; } if (soundName.contains("-3-")) { return R.raw.sound3; } if (soundName.contains("-4-")) { return R.raw.sound4; } if (soundName.contains("-5-")) { return R.raw.sound5; } if (soundName.contains("-6-")) { return R.raw.sound6; } if (soundName.contains("-7-")) { return R.raw.sound7; } return R.raw.sound1; } public void shareButtonClicked(View v) { Intent intent = new Intent(this.getApplicationContext(), ShareActivity.class); startActivity(intent); } }