Android Open Source - android-data-persistence Main Activity






From Project

Back to project page android-data-persistence.

License

The source code is released under:

MIT License

If you think the Android project android-data-persistence 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.teamtreehouse.mememaker.ui.activities;
//  w w  w  . j ava2  s. c  om
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.view.ViewPager;
import android.widget.Toast;

import com.teamtreehouse.mememaker.R;
import com.teamtreehouse.mememaker.adapters.SectionsPagerAdapter;
import com.teamtreehouse.mememaker.ui.fragments.ImageGridFragment;
import com.teamtreehouse.mememaker.utils.FileUtilities;

import java.io.File;

public class MainActivity extends Activity implements ActionBar.TabListener {

    ViewPager mViewPager;
    SectionsPagerAdapter mSectionsPagerAdapter;

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

        final ActionBar actionBar = this.getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);

        mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });

        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
            actionBar.addTab(
                    actionBar.newTab()
                            .setText(mSectionsPagerAdapter.getPageTitle(i))
                            .setTabListener(this));
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == ImageGridFragment.RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            File file = new File(picturePath);
            Bitmap bitmap = BitmapFactory.decodeFile(picturePath.toString());

            FileUtilities.saveImage(this, bitmap, file.getName());
        } else if (requestCode != RESULT_CANCELED) {
            Toast.makeText(this, R.string.general_error, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        /* Intentionally blank */
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        /* Intentionally blank */
    }
}




Java Source Code List

com.teamtreehouse.mememaker.MemeMakerApplicationSettings.java
com.teamtreehouse.mememaker.MemeMakerApplication.java
com.teamtreehouse.mememaker.adapters.GridViewAdapter.java
com.teamtreehouse.mememaker.adapters.MemeItemListAdapter.java
com.teamtreehouse.mememaker.adapters.SectionsPagerAdapter.java
com.teamtreehouse.mememaker.database.MemeDatasource.java
com.teamtreehouse.mememaker.database.MemeSQLiteHelper.java
com.teamtreehouse.mememaker.models.ImageGridItem.java
com.teamtreehouse.mememaker.models.ImageItem.java
com.teamtreehouse.mememaker.models.MemeAnnotation.java
com.teamtreehouse.mememaker.models.Meme.java
com.teamtreehouse.mememaker.ui.activities.CreateMemeActivity.java
com.teamtreehouse.mememaker.ui.activities.MainActivity.java
com.teamtreehouse.mememaker.ui.activities.MemeSettingsActivity.java
com.teamtreehouse.mememaker.ui.fragments.ImageGridFragment.java
com.teamtreehouse.mememaker.ui.fragments.MemeItemFragment.java
com.teamtreehouse.mememaker.ui.fragments.MemeSettingsFragment.java
com.teamtreehouse.mememaker.ui.views.MemeImageView.java
com.teamtreehouse.mememaker.utils.FileUtilities.java
com.teamtreehouse.mememaker.utils.ImageResizer.java
com.teamtreehouse.mememaker.utils.StorageType.java