Android Open Source - Pairs Main Activity






From Project

Back to project page Pairs.

License

The source code is released under:

MIT License

If you think the Android project Pairs 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.example.pairs;
//from w w w  .  j av  a 2  s.com
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
  
  Button setAlarm;
  Button setContact;
  Button help;
  Button exit;
  SharedPreferences sharedPreferences;
  SharedPreferences.Editor editor;
  
  //?????????????????????????????????????????Home????????????????????????????????????????
  @Override 
  public boolean onKeyDown(int keyCode, KeyEvent event)
  {
    if(keyCode == KeyEvent.KEYCODE_BACK)
    {
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.addCategory(Intent.CATEGORY_HOME);
      startActivity(intent);
      return true;
    }
    //??????????????????
    else
    {
      return super.onKeyDown(keyCode, event); 
    }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    
    //????????????
    sharedPreferences = getSharedPreferences("pairsInbox", Activity.MODE_PRIVATE);
    editor = sharedPreferences.edit();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    //????
    setAlarm = (Button) findViewById(R.id.setAlarm);
    setContact = (Button) findViewById(R.id.setContact);
    help = (Button) findViewById(R.id.help);
    exit = (Button) findViewById(R.id.exit);
    
    //?setAlarm??????????
    setAlarm.setOnClickListener(new OnClickListener()
    {
      @Override
      public void onClick(View v)
      {
        int i = 0;
        //?????????????????????????????????????????????????
        Cursor cursor = getContentResolver().query(Uri.parse("content://sms/outbox"), null, null, null, null);
        while (cursor.moveToNext())
          i++;
        editor.putInt("inbox", i);
        editor.commit();
        //???????????????????????????????
        Intent intent = new Intent(MainActivity.this, SMSReceiver.class);
        startActivity(intent);
      }
    });
    
    //?setContact??????????
    setContact.setOnClickListener(new OnClickListener()
    {
      @Override
      public void onClick(View v)
      {
        //???????????????????
        Intent intent = new Intent(MainActivity.this, SetContactActivity.class);
        startActivity(intent);
      }
    });
    
    //?help??????????
    help.setOnClickListener(new OnClickListener()
    {
      @Override
      public void onClick(View v)
      {
        //????????????????????
        Intent intent = new Intent(MainActivity.this, HelpActivity.class);
        startActivity(intent);
      }
    });
    
    //?exit??????????????????????????????????????????????????
    exit.setOnClickListener(new OnClickListener()
    {
      @Override
      public void onClick(View v)
      {
        //?????????
        finish();
      }
    });
    }

  //???????????????????????
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

}




Java Source Code List

com.example.pairs.AlarmActivity.java
com.example.pairs.ChooseContactActivity.java
com.example.pairs.Function.java
com.example.pairs.HelpActivity.java
com.example.pairs.Help.java
com.example.pairs.MainActivity.java
com.example.pairs.OurPage.java
com.example.pairs.Ours.java
com.example.pairs.PhotoActivity.java
com.example.pairs.SMSReceiver.java
com.example.pairs.SetContactActivity.java