コード例 #1
1
  // 인텐트 받아왔을 때.. 근데 이거 있으면 onStart 호출 불가
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);

    //        if (intent.hasExtra("bm")) {
    //            Log.d("MainActivity : ", "bm is not null");
    //
    //            bm = intent.getParcelableExtra("bm");
    //            adapterViewPager.setImageView(bm);
    //
    //        } else {
    //            Log.d("MainActivity : ", "bm is null");
    //        }

    if (intent.hasExtra("card")) {
      adapterViewPager.setCardItem((Card) intent.getParcelableExtra("card"));
    }

    if (intent.hasExtra("keyword")) {
      keyword = intent.getStringArrayListExtra("keyword");
      Log.d("In mainActivity : ", keyword.get(0));
      Log.d("In mainActivity : ", keyword.get(1));
      Log.d("In mainActivity : ", keyword.get(2));
      Log.d("In mainActivity : ", keyword.get(3));
      Log.d("In mainActivity : ", keyword.get(4));

      //            FirstFragment fragment = new FirstFragment();
      //            Bundle bundle = new Bundle();
      //            bundle.putStringArrayList("keyword", keyword);
      //            fragment.setArguments(bundle);

      adapterViewPager.getFirstFragment().getkeyword(keyword);
    }
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (start_flag) {
      startActivity(new Intent(this, Splash.class));
      start_flag = false;
      finish();
    }
    setLayout();

    Intent intent = getIntent();

    if (intent.hasExtra("kakaoID")) {
      kakaoID = intent.getStringExtra("kakaoID");
      kakaoNICKNAME = intent.getStringExtra("kakaoNICKNAME");
      Log.d("MainActivity: ", "카카오 정보 가져오기 성공!");
    } else {
      Log.d("MainActivity : ", "intent가 kakaoID를 가지고 있지 않습니다.");
    }

    // Attach the page change listener inside the activity
    adapterViewPager = new MainAdapter(getSupportFragmentManager(), kakaoID, kakaoNICKNAME);
    adapterViewPager.setKakaoID(kakaoID);

    vpPager.setAdapter(adapterViewPager);

    if (getIntent().hasExtra("bm")) {
      Log.d("MainActivity : ", "has extra bm");
      vpPager.setCurrentItem(1);
    }
    vpPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

          // This method will be invoked when a new page becomes selected.
          @Override
          public void onPageSelected(int position) {}

          // This method will be invoked when the current page is scrolled
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            // Code goes here
            if (position == 0) {
              btn_one.setBackgroundResource(R.drawable.actionbar_selected_peoplelist);
              btn_two.setBackgroundResource(R.drawable.actionbar_unselected_editcard);
              btn_three.setBackgroundResource(R.drawable.actionbar_unselected_interest);
              btn_four.setBackgroundResource(R.drawable.actionbar_unselected_option);
              add_new_card.setVisibility(View.INVISIBLE);
              add_interests.setVisibility(View.VISIBLE);
            } else if (position == 1) {
              btn_one.setBackgroundResource(R.drawable.actionbar_unselected_peoplelist);
              btn_two.setBackgroundResource(R.drawable.actionbar_selected_editcard);
              btn_three.setBackgroundResource(R.drawable.actionbar_unselected_interest);
              btn_four.setBackgroundResource(R.drawable.actionbar_unselected_option);
              add_new_card.setVisibility(View.VISIBLE);
              add_interests.setVisibility(View.INVISIBLE);
            } else if (position == 2) {
              btn_one.setBackgroundResource(R.drawable.actionbar_unselected_peoplelist);
              btn_two.setBackgroundResource(R.drawable.actionbar_unselected_editcard);
              btn_three.setBackgroundResource(R.drawable.actionbar_selected_interest);
              btn_four.setBackgroundResource(R.drawable.actionbar_unselected_option);
              add_new_card.setVisibility(View.INVISIBLE);
              add_interests.setVisibility(View.INVISIBLE);

            } else {
              btn_one.setBackgroundResource(R.drawable.actionbar_unselected_peoplelist);
              btn_two.setBackgroundResource(R.drawable.actionbar_unselected_editcard);
              btn_three.setBackgroundResource(R.drawable.actionbar_unselected_interest);
              btn_four.setBackgroundResource(R.drawable.actionbar_selected_option);
              add_new_card.setVisibility(View.INVISIBLE);
              add_interests.setVisibility(View.INVISIBLE);
            }
          }

          // Called when the scroll state changes:
          // SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING
          @Override
          public void onPageScrollStateChanged(int state) {
            // Code goes here
          }
        });

    add_new_card.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent newActivity = new Intent(MainActivity.this, Add_Profile.class);
            newActivity.putExtra("kakaoID", kakaoID);
            newActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(newActivity);
          }
        });

    add_interests.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent newActivity = new Intent(MainActivity.this, Pick_Interests.class);
            startActivity(newActivity);
          }
        });
  }