Android Open Source - pokedex Main Activity






From Project

Back to project page pokedex.

License

The source code is released under:

MIT License

If you think the Android project pokedex 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.andrescanales.pokedex;
//from w w  w .j  a v a  2  s . c o m
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity implements PokemonListFragment.Callbacks{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
            // So far the only change in this class is referencing to the PokemonListFragment
                    .add(R.id.container, new PokemonListFragment())
                    .commit();
        }
    }

    @Override
    public void onItemSelected(Pokemon pokemon) {
        Intent detailIntent = new Intent(this, PokemonDetail.class);
        //detailIntent.putExtra("nombre", nombre);
        detailIntent.putExtra("pokemon", pokemon);
        startActivity(detailIntent);
    }

    @Override
    public void onResume() {
        super.onResume();  // Always call the superclass method first

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        String unitType = sharedPrefs.getString(
                getString(R.string.pref_rotation_key),
                getString(R.string.pref_rotation_label_default));

        if (unitType.equals(getString(R.string.pref_rotation_label_landscape))) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            // Log.i("MainActivity", "MyClass.getView()  Entering to Landscape");
        }
        else if (unitType.equals(getString(R.string.pref_rotation_label_portrait))) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            // Log.i("MainActivity", "MyClass.getView()  Entering to Portrait");
        }
        else {
        }

    }


    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */

}




Java Source Code List

com.andrescanales.pokedex.ApplicationTest.java
com.andrescanales.pokedex.GsonRequest.java
com.andrescanales.pokedex.MainActivity.java
com.andrescanales.pokedex.PokedexApplication.java
com.andrescanales.pokedex.PokemonAdapter.java
com.andrescanales.pokedex.PokemonDetailFragment.java
com.andrescanales.pokedex.PokemonDetail.java
com.andrescanales.pokedex.PokemonListApiTask.java
com.andrescanales.pokedex.PokemonListFragment.java
com.andrescanales.pokedex.Pokemon.java
com.andrescanales.pokedex.SettingsActivity.java