Android Open Source - photo-paper History Activity






From Project

Back to project page photo-paper.

License

The source code is released under:

MIT License

If you think the Android project photo-paper 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.lukekorth.android_500px;
/*  www.  j ava2  s.  c o m*/
import android.app.ActionBar;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lukekorth.android_500px.helpers.Utils;
import com.lukekorth.android_500px.models.Photos;
import com.lukekorth.android_500px.models.WallpaperChangedEvent;
import com.squareup.otto.Subscribe;
import com.squareup.picasso.Picasso;

import java.util.List;

public class HistoryActivity extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WallpaperApplication.getBus().register(this);

        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        updateHistory(null);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        WallpaperApplication.getBus().unregister(this);
    }

    @Subscribe
    public void updateHistory(WallpaperChangedEvent event) {
        setListAdapter(new PhotoAdapter(this, Photos.getSeenPhotos()));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
        }

        return false;
    }

    private static class PhotoAdapter extends BaseAdapter {

        private Context mContext;
        private List<Photos> mPhotos;
        private LayoutInflater mLayoutInflater;
        private Picasso mPicasso;
        private int mSize;

        public PhotoAdapter(Context context, List<Photos> photos) {
            mContext = context;
            mPhotos = photos;
            mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mPicasso = WallpaperApplication.getPicasso(context);
            mSize = Utils.dpToPx(context, 100);
        }

        @Override
        public int getCount() {
            return mPhotos.size();
        }

        @Override
        public Object getItem(int position) {
            return mPhotos.get(position);
        }

        @Override
        public long getItemId(int position) {
            return mPhotos.get(position).photo_id;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            final Photos photo = mPhotos.get(position);

            ViewHolderItem viewHolderItem;
            if(convertView == null){
                convertView = mLayoutInflater.inflate(R.layout.photo, parent, false);
                viewHolderItem = new ViewHolderItem();
                viewHolderItem.mPhoto = (ImageView) convertView.findViewById(R.id.thumbnail);
                viewHolderItem.mName = (TextView) convertView.findViewById(R.id.name);
                viewHolderItem.mPhotographer = (TextView) convertView.findViewById(R.id.photographer);
                viewHolderItem.mSeenAt = (TextView) convertView.findViewById(R.id.seen);
                convertView.setTag(viewHolderItem);
            } else {
                viewHolderItem = (ViewHolderItem) convertView.getTag();
            }

            CharSequence timeSeen = DateUtils.getRelativeTimeSpanString(photo.seenAt, System.currentTimeMillis(), 0);
            viewHolderItem.mName.setText(photo.name);
            viewHolderItem.mPhotographer.setText(" " + photo.userName + " / 500px");
            viewHolderItem.mSeenAt.setText("Seen " + timeSeen);
            mPicasso.load(photo.imageUrl).resize(mSize, mSize).centerCrop().into(viewHolderItem.mPhoto);
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ViewPhotoActivity.class)
                            .putExtra(ViewPhotoActivity.PHOTO_POSITION_KEY, position);
                    mContext.startActivity(intent);
                }
            });

            return convertView;
        }

        static class ViewHolderItem {
            ImageView mPhoto;
            TextView mName;
            TextView mPhotographer;
            TextView mSeenAt;
        }
    }

}




Java Source Code List

com.lukekorth.android_500px.HistoryActivity.java
com.lukekorth.android_500px.PhotoFragment.java
com.lukekorth.android_500px.SearchActivity.java
com.lukekorth.android_500px.SettingsActivity.java
com.lukekorth.android_500px.ViewPhotoActivity.java
com.lukekorth.android_500px.WallpaperApplication.java
com.lukekorth.android_500px.helpers.Cache.java
com.lukekorth.android_500px.helpers.LogReporting.java
com.lukekorth.android_500px.helpers.Settings.java
com.lukekorth.android_500px.helpers.ThreadBus.java
com.lukekorth.android_500px.helpers.Utils.java
com.lukekorth.android_500px.models.ActivityResumedEvent.java
com.lukekorth.android_500px.models.EnableCategoriesEvent.java
com.lukekorth.android_500px.models.Photos.java
com.lukekorth.android_500px.models.SearchCompleteEvent.java
com.lukekorth.android_500px.models.UserUpdatedEvent.java
com.lukekorth.android_500px.models.User.java
com.lukekorth.android_500px.models.WallpaperChangedEvent.java
com.lukekorth.android_500px.receivers.UserPresentReceiver.java
com.lukekorth.android_500px.receivers.WifiReceiver.java
com.lukekorth.android_500px.services.ApiService.java
com.lukekorth.android_500px.services.ClearCacheIntentService.java
com.lukekorth.android_500px.services.UserInfoIntentService.java
com.lukekorth.android_500px.services.WallpaperService.java
com.lukekorth.android_500px.views.FeatureListPreference.java
com.lukekorth.android_500px.views.SquareImageView.java
com.squareup.picasso.PicassoTools.java