Android Open Source - Gloggr Main Activity






From Project

Back to project page Gloggr.

License

The source code is released under:

GNU General Public License

If you think the Android project Gloggr 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.JordHan.Gloggr.Activities;
/*from  www .j  av  a2 s  .c o m*/
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.JordHan.Gloggr.R;
import com.JordHan.Gloggr.Helper.MenuHelper;
import com.JordHan.Gloggr.db.DatabaseManager;

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); // Push instance of activity to
                      // super

    // Setup interface
    setContentView(R.layout.main_activity); // Load interface

    // Get access to views
    ImageView imgProfilePicture = (ImageView) findViewById(R.id.imgProfilePicture);
    TextView txtWelcomeMessage = (TextView) findViewById(R.id.txtProfileWelcomeMessage);
    Button btnSearchAdd = (Button) findViewById(R.id.btnSearchAdd);

    // Get values from resources
    String welcomeMessage = getString(R.string.profileWelcomeMessage);
    SharedPreferences preferences = PreferenceManager
        .getDefaultSharedPreferences(MainActivity.this);
    String first_name = preferences.getString("first_name", "Current User");

    // Customise interface values
    txtWelcomeMessage.setText("* " + first_name + welcomeMessage + " *");

    // Create listeners for controls
    // Header image
    imgProfilePicture.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        Toast.makeText(getApplicationContext(), "Image clicked",
            Toast.LENGTH_SHORT).show();
      }
    });

    // Search and Add new game button
    btnSearchAdd.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View view) {
        Intent intent = new Intent(getBaseContext(), SearchActivity.class);
        startActivity(intent);
      }
    });

    DatabaseManager.init(this); // Create instance of DatabaseManager ready
                  // for ORM
  }

  // Used to refresh activity on resume (mainly for refreshing after
  // preference change)
  @Override
  public void onResume() {
    super.onResume();
    this.onCreate(null);
  }

  // When Menu button clicked
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Populate menu with items in XML file
    getMenuInflater().inflate(R.menu.main_menu, menu);

    return true;
  }

  // When item in menu selected
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Call MenuHelper class to operate on menu item clicked, get an intent
    // back
    Intent activityToOpen = MenuHelper.performMenuOperation(item,
        getBaseContext(), getApplicationContext());

    if (activityToOpen != null) { // If Intent to an activity returned
      startActivity(activityToOpen); // Open it
      return true;
    }

    return false; // Else return that there was an error
  }
}




Java Source Code List

com.JordHan.Gloggr.Activities.CurrentlyPlayingActivity.java
com.JordHan.Gloggr.Activities.GameListActivity.java
com.JordHan.Gloggr.Activities.MainActivity.java
com.JordHan.Gloggr.Activities.PreferencesActivity.java
com.JordHan.Gloggr.Activities.SearchActivity.java
com.JordHan.Gloggr.Activities.Notification.AboutAppActivity.java
com.JordHan.Gloggr.Activities.Notification.AboutDeveloperActivity.java
com.JordHan.Gloggr.Helper.MenuHelper.java
com.JordHan.Gloggr.Model.Game.java
com.JordHan.Gloggr.Services.AbstractService.java
com.JordHan.Gloggr.Services.GameSearchService.java
com.JordHan.Gloggr.Services.IServiceListener.java
com.JordHan.Gloggr.db.DatabaseHelper.java
com.JordHan.Gloggr.db.DatabaseManager.java