Ejemplo n.º 1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
      Util.showAlert(
          this,
          "Warning",
          "Facebook Applicaton ID must be "
              + "specified before running this example: see FbAPIs.java");
      return;
    }

    setContentView(R.layout.main);
    mHandler = new Handler();

    mText = (TextView) Hackbook.this.findViewById(R.id.txt);
    mUserPic = (ImageView) Hackbook.this.findViewById(R.id.user_pic);

    // Create the Facebook Object using the app id.
    Utility.mFacebook = new Facebook(APP_ID);
    // Instantiate the asynrunner object for asynchronous api calls.
    Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);

    mLoginButton = (LoginButton) findViewById(R.id.login);

    // restore session if one exists
    SessionStore.restore(Utility.mFacebook, this);
    SessionEvents.addAuthListener(new FbAPIsAuthListener());
    SessionEvents.addLogoutListener(new FbAPIsLogoutListener());

    /*
     * Source Tag: login_tag
     */
    mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);

    if (Utility.mFacebook.isSessionValid()) {
      requestUserData();
    }

    list = (ListView) findViewById(R.id.main_list);

    list.setOnItemClickListener(this);
    list.setAdapter(new ArrayAdapter<String>(this, R.layout.main_list_item, main_items));
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (Utility.APP_ID == null) {
      Util.showAlert(
          this,
          "Warning",
          "Facebook Applicaton ID must be "
              + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.main);

    /* Get Handles for all the controls on the screen which needs
     * manipulation
     */
    mLoginButton = (LoginButton) findViewById(R.id.login);
    btnSearchHotel = (Button) findViewById(R.id.btnSearch);
    lblWelcome = (TextView) findViewById(R.id.lblWelcome);
    txtCityName = (EditText) findViewById(R.id.txtCityName);
    layoutForm = (LinearLayout) findViewById(R.id.layoutForm);
    layoutForm.setVisibility(View.INVISIBLE);

    // Create an instance of Facebook object, passing the APP ID.
    Utility.mFacebook = new Facebook(Utility.APP_ID);

    Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook);

    SessionStore.restore(Utility.mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, Utility.mFacebook);

    Spinner spin = (Spinner) findViewById(R.id.ddlHotelChain);
    spin.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            // Set the Hotel Chain selected.
            strHotelChain = items_hotel_chain[position];
          }

          public void onNothingSelected(AdapterView<?> arg0) {
            // So, nothing comes here. ;)
          }
        });

    @SuppressWarnings({"rawtypes", "unchecked"})
    ArrayAdapter aa =
        new ArrayAdapter(this, android.R.layout.simple_spinner_item, items_hotel_chain);

    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(aa);

    btnSearchHotel.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            // If city name is entered, call new intent by passing,
            // city name and hotel chain to the new intent.
            if (!txtCityName.getText().toString().trim().equals("")) {
              Intent i = new Intent(getBaseContext(), HotelList.class);
              i.putExtra("cityName", txtCityName.getText().toString().replace(" ", "+").trim());
              i.putExtra("hotelChain", strHotelChain);
              startActivity(i);
            }
            // City name cannot be empty, so tell the user.
            else {
              Toast.makeText(getBaseContext(), "Please enter city name", Toast.LENGTH_SHORT).show();
            }
          }
        });

    if (Utility.mFacebook.isSessionValid()) {
      lblWelcome.setText("Welcome, " + Utility.strUsername);
      layoutForm.setVisibility(View.VISIBLE);
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
      Util.showAlert(
          this,
          "Warning",
          "Facebook Applicaton ID must be "
              + "specified before running this example: see FacebookInterfaceActivity.java");
    }

    setContentView(R.layout.facebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) FacebookInterfaceActivity.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, mFacebook);

    mRequestButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
          }
        });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
              uploadFileUrl =
                  new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
            try {
              HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
              conn.setDoInput(true);
              conn.connect();
              int length = conn.getContentLength();

              byte[] imgData = new byte[length];
              InputStream is = conn.getInputStream();
              is.read(imgData);
              params.putByteArray("picture", imgData);

            } catch (IOException e) {
              e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
          }
        });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            mFacebook.dialog(FacebookInterfaceActivity.this, "feed", new SampleDialogListener());
          }
        });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
  }