Android Open Source - NavigationDrawer Main Activity






From Project

Back to project page NavigationDrawer.

License

The source code is released under:

Apache License

If you think the Android project NavigationDrawer 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

/*
* Copyright 2013 The Android Open Source Project
*//  w  w w . j a  v a  2s .co  m
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.navigationdrawer;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

/**
 * A simple launcher activity offering access to the individual samples in this project.
 */
public class MainActivity extends Activity implements AdapterView.OnItemClickListener {
  private Sample[] mSamples;
  private GridView mGridView;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Prepare list of samples in this dashboard.
    mSamples = new Sample[]{
        new Sample(R.string.navigationdraweractivity_title, R.string.navigationdraweractivity_description,
            NavigationDrawerActivity.class),
    };

    // Prepare the GridView
    mGridView = (GridView) findViewById(android.R.id.list);
    mGridView.setAdapter(new SampleAdapter());
    mGridView.setOnItemClickListener(this);
  }

  @Override
  public void onItemClick(AdapterView<?> container, View view, int position, long id) {
    startActivity(mSamples[position].intent);
  }

  private class SampleAdapter extends BaseAdapter {
    @Override
    public int getCount() {
      return mSamples.length;
    }

    @Override
    public Object getItem(int position) {
      return mSamples[position];
    }

    @Override
    public long getItemId(int position) {
      return mSamples[position].hashCode();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
      if (convertView == null) {
        convertView = getLayoutInflater().inflate(R.layout.sample_dashboard_item,
            container, false);
      }

      ((TextView) convertView.findViewById(android.R.id.text1)).setText(
          mSamples[position].titleResId);
      ((TextView) convertView.findViewById(android.R.id.text2)).setText(
          mSamples[position].descriptionResId);
      return convertView;
    }
  }

  private class Sample {
    int titleResId;
    int descriptionResId;
    Intent intent;

    private Sample(int titleResId, int descriptionResId, Intent intent) {
      this.intent = intent;
      this.titleResId = titleResId;
      this.descriptionResId = descriptionResId;
    }

    private Sample(int titleResId, int descriptionResId,
                   Class<? extends Activity> activityClass) {
      this(titleResId, descriptionResId,
          new Intent(MainActivity.this, activityClass));
    }
  }
}




Java Source Code List

com.example.android.common.logger.LogFragment.java
com.example.android.common.logger.LogNode.java
com.example.android.common.logger.LogView.java
com.example.android.common.logger.LogWrapper.java
com.example.android.common.logger.Log.java
com.example.android.common.logger.MessageOnlyLogFilter.java
com.example.android.navigationdrawer.MainActivity.java
com.example.android.navigationdrawer.NavigationDrawerActivity.java
com.example.android.navigationdrawer.PlanetAdapter.java
com.example.android.navigationdrawer.PlanetBitmap.java