/** 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 Example.java"); } setContentView(R.layout.main); mLoginButton = (LoginButton) findViewById(R.id.login); mText = (TextView) FacebookApplicationActivity.this.findViewById(R.id.txt); mUserPic = (ImageView) FacebookApplicationActivity.this.findViewById(R.id.user_pic); // mFacebook = new Facebook(APP_ID); Utility.mFacebook = new Facebook(APP_ID); // Instantiate the asynrunner object for asynchronous api calls. Utility.mAsyncRunner = new AsyncFacebookRunner(Utility.mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new FbAPIsAuthListener()); SessionEvents.addLogoutListener(new FbAPIsLogoutListener()); 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); } }
@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { PswdInput = new javax.swing.JPasswordField(); RememberCheckBox = new javax.swing.JCheckBox(); LoginButton = new javax.swing.JButton(); UsrInput = new javax.swing.JTextField(); UsernameText = new javax.swing.JLabel(); PasswordText = new javax.swing.JLabel(); accountType = new javax.swing.JComboBox(); heading = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); addWindowListener( new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); RememberCheckBox.setText("Remember me"); RememberCheckBox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { RememberCheckBoxActionPerformed(evt); } }); LoginButton.setText("Login"); LoginButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { LoginButtonActionPerformed(evt); } }); UsrInput.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { UsrInputActionPerformed(evt); } }); UsernameText.setText("Username:"******"Password:"******"Student", "Foreleser", "Hjelpelærer"})); accountType.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { accountTypeActionPerformed(evt); } }); heading.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N heading.setText("IT og Informasjonssytem - IS-109 & IS-110"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(34, 34, 34) .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(heading, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup( layout .createSequentialGroup() .addGap(130, 130, 130) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( PswdInput, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( accountType, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createSequentialGroup() .addGap(6, 6, 6) .addComponent( RememberCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent( LoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( UsrInput, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( layout .createSequentialGroup() .addGap(36, 36, 36) .addComponent(PasswordText)) .addGroup( layout .createSequentialGroup() .addGap(32, 32, 32) .addComponent(UsernameText))) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 114, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(40, Short.MAX_VALUE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGap(54, 54, 54) .addComponent(heading) .addGap(43, 43, 43) .addComponent(UsernameText) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( UsrInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(PasswordText) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( PswdInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( accountType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(RememberCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( LoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(69, Short.MAX_VALUE))); pack(); } // </editor-fold>//GEN-END:initComponents
/** 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); }