Android Open Source - android-sms-relay Main Activity






From Project

Back to project page android-sms-relay.

License

The source code is released under:

GNU General Public License

If you think the Android project android-sms-relay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nyaruka.androidrelay;
/*from  w  w w .ja  v  a  2  s. c o  m*/
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.commonsware.cwac.wakeful.WakefulIntentService;
import com.nyaruka.android.actionbarcompat.ActionBarActivity;
import com.nyaruka.androidrelay.data.TextMessage;

public class MainActivity extends ActionBarActivity {

  public static final String TAG = MainActivity.class.getSimpleName();
    public final static String LINE_SEPARATOR = System.getProperty("line.separator");//$NON-NLS-1$
  
  private static MainActivity s_this;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    s_this = this;
  }
  
  public static boolean alive(){
    return s_this != null;
  }
  
  public static MessageListFragment getMessageList(){
    return (MessageListFragment) s_this.getSupportFragmentManager().findFragmentById(R.id.message_list);
  }
  
  public static void updateMessage(TextMessage message){
    if (alive() && getMessageList() != null){
      getMessageList().updateMessage(message);
    }
  }
  
  public static void clearMessages(){
    if (alive() && getMessageList() != null){
      getMessageList().clearMessages();
    }
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ( keyCode == KeyEvent.KEYCODE_MENU ) {
      Intent settingsActivity = new Intent(getBaseContext(), SettingsActivity.class);
      startActivity(settingsActivity);
      return true;
    }
    return super.onKeyDown(keyCode, event);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
        case R.id.settings:
          Intent settingsActivity = new Intent(getBaseContext(), SettingsActivity.class);
          startActivity(settingsActivity);
          return true;
           
        case R.id.refresh:
            WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(1), getApplicationContext());
            Toast.makeText(MainActivity.this, "Syncing messages", Toast.LENGTH_LONG).show();
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  protected void onResume() {
    super.onResume();    
    startService(new Intent(this, RelayService.class));
  }
  

}




Java Source Code List

com.commonsware.cwac.wakeful.AlarmReceiver.java
com.commonsware.cwac.wakeful.WakefulIntentService.java
com.nyaruka.android.actionbarcompat.ActionBarActivity.java
com.nyaruka.android.actionbarcompat.ActionBarHelperBase.java
com.nyaruka.android.actionbarcompat.ActionBarHelperHoneycomb.java
com.nyaruka.android.actionbarcompat.ActionBarHelperICS.java
com.nyaruka.android.actionbarcompat.ActionBarHelper.java
com.nyaruka.android.actionbarcompat.SimpleMenuItem.java
com.nyaruka.android.actionbarcompat.SimpleMenu.java
com.nyaruka.androidrelay.AlarmListener.java
com.nyaruka.androidrelay.AndroidRelay.java
com.nyaruka.androidrelay.BootStrapper.java
com.nyaruka.androidrelay.CheckService.java
com.nyaruka.androidrelay.MainActivity.java
com.nyaruka.androidrelay.MessageListFragment.java
com.nyaruka.androidrelay.RebootService.java
com.nyaruka.androidrelay.RelayService.java
com.nyaruka.androidrelay.SMSModem.java
com.nyaruka.androidrelay.SettingsActivity.java
com.nyaruka.androidrelay.data.TextMessageHelper.java
com.nyaruka.androidrelay.data.TextMessage.java
com.nyaruka.log.LogCollector.java