Search in sources :

Example 11 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class PhotosetGridFragment method onPhotosReady.

@Override
public void onPhotosReady(List<Photo> photos, Exception e) {
    super.onPhotosReady(photos, e);
    mActivity.setProgressBarIndeterminateVisibility(Boolean.FALSE);
    if (mPhotoset != null) {
        User owner = mPhotoset.getOwner();
        if (owner != null) {
            for (Photo p : photos) {
                p.setOwner(owner);
                p.setUrl(String.format("%s%s%s%s", "http://flickr.com/photos/", owner.getId(), "/", p.getId()));
            }
        }
        if (photos != null && photos.isEmpty()) {
            mMorePages = false;
        }
    }
}
Also used : User(com.googlecode.flickrjandroid.people.User) Photo(com.googlecode.flickrjandroid.photos.Photo)

Example 12 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class StackRemoteViewsFactory method getViewAt.

/**
     * You can do heaving lifting in here, synchronously. For example, if you
     * need to process an image, fetch something from the network, etc., it is
     * ok to do it here, synchronously. A loading view will show up in lieu of
     * the actual contents in the interim.
     */
public RemoteViews getViewAt(int position) {
    final RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.stackview_widget_item);
    if (mPhotos.size() == 0) {
        updatePhotos();
    }
    /* Fetch the photo synchronously */
    final Photo photo = mPhotos.get(position);
    Bitmap bitmap = null;
    try {
        bitmap = Picasso.with(mContext).load(photo.getSmallUrl()).get();
    } catch (IOException e) {
        e.printStackTrace();
    }
    rv.setImageViewBitmap(R.id.image_item, bitmap);
    /* Set the overlay views and owner info */
    rv.setViewVisibility(R.id.imageOverlay, View.VISIBLE);
    String viewsText = String.format("%s: %s", mContext.getString(R.string.views), String.valueOf(photo.getViews()));
    rv.setTextViewText(R.id.viewsText, viewsText);
    if (photo.getOwner() != null) {
        rv.setTextViewText(R.id.ownerText, photo.getOwner().getUsername());
    }
    /* Show ribbon in corner if photo is new */
    // TODO: create list of new photos to enable this
    //rv.setVisibility(R.id.imageNewRibbon, View.INVISIBLE);
    //if (mNewPhotos != null) {
    //for (Photo p : mNewPhotos) {
    //if (p.getId().equals(photo.getId())) {
    //holder.imageNewRibbon.setVisibility(View.VISIBLE);
    //}
    //}
    //}
    /* Next, we set a fill-intent which will be used to fill-in the pending
         * intent template which is set on the collection view in
         * StackWidgetProvider. */
    Bundle extras = new Bundle();
    extras.putInt(StackWidgetProvider.VIEW_INDEX, position);
    extras.putString(PhotoViewerActivity.KEY_PHOTO_LIST_FILE, PhotoViewerActivity.PHOTO_LIST_FILE);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.image_layout, fillInIntent);
    return rv;
}
Also used : RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) Bundle(android.os.Bundle) Photo(com.googlecode.flickrjandroid.photos.Photo) Intent(android.content.Intent) IOException(java.io.IOException)

Example 13 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class PhotoGridFragment method checkForNewPhotos.

/**
     * If we have a most recent id stored, see if it exists in the photo
     * list we just fetched. If so, all photos before that id in the list
     * are said to be new.
     */
protected void checkForNewPhotos(List<Photo> photos) {
    if (photos == null || photos.isEmpty()) {
        if (BuildConfig.DEBUG)
            Log.d(getLogTag(), "checkForNewPhotos: photos null or empty");
        return;
    }
    mNewPhotos = new ArrayList<Photo>();
    String newestId = getNewestPhotoId();
    if (newestId != null) {
        for (int i = 0; i < photos.size(); i++) {
            Photo p = photos.get(i);
            if (p.getId().equals(newestId)) {
                mNewPhotos = photos.subList(0, i);
                if (BuildConfig.DEBUG)
                    Log.d(getLogTag(), String.format("Found %d new photos", mNewPhotos.size()));
                break;
            }
        }
    }
    if (mNewPhotos != null && !mNewPhotos.isEmpty()) {
        storeNewestPhotoId(mNewPhotos.get(0));
    } else {
        if (BuildConfig.DEBUG)
            Log.d(getLogTag(), "mNewPhotos null or empty, using most " + "recent fetched photo as newest");
        storeNewestPhotoId(photos.get(0));
    }
}
Also used : Photo(com.googlecode.flickrjandroid.photos.Photo)

Example 14 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class PhotoViewerActivity method handleIntent.

private void handleIntent(Intent intent) {
    if (intent.getBooleanExtra(KEY_INTENT_CONSUMED, false)) {
        /* prevent the intent getting executed twice on rotate */
        if (BuildConfig.DEBUG)
            Log.d(TAG, "KEY_INTENT_CONSUMED true");
        return;
    }
    final int startIndex = intent.getIntExtra(KEY_START_INDEX, 0);
    if (intent.getAction().equals(ACTION_VIEW_PHOTO_BY_ID)) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Received ACTION_VIEW_PHOTO_BY_ID intent");
        intent.putExtra(KEY_INTENT_CONSUMED, true);
        String photoId = intent.getStringExtra(KEY_PHOTO_ID);
        new LoadPhotoInfoTask(this, photoId).execute(mOAuth);
    } else if (intent.getAction().equals(ACTION_VIEW_PHOTOLIST)) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Received ACTION_VIEW_PHOTOLIST intent");
        intent.putExtra(KEY_INTENT_CONSUMED, true);
        String photoListFile = intent.getStringExtra(KEY_PHOTO_LIST_FILE);
        GsonHelper gsonHelper = new GsonHelper(this);
        String json = gsonHelper.loadJson(photoListFile);
        if (json.length() > 0) {
            Type collectionType = new TypeToken<Collection<Photo>>() {
            }.getType();
            mPhotos = new Gson().fromJson(json, collectionType);
            initViewPager(startIndex, true);
        } else {
            Log.e(TAG, String.format("Error reading '%s'", photoListFile));
        }
    } else {
        Log.e(TAG, "Unknown intent action: " + intent.getAction());
    }
}
Also used : GsonHelper(com.bourke.glimmr.common.GsonHelper) Type(java.lang.reflect.Type) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Photo(com.googlecode.flickrjandroid.photos.Photo) LoadPhotoInfoTask(com.bourke.glimmr.tasks.LoadPhotoInfoTask)

Example 15 with Photo

use of com.googlecode.flickrjandroid.photos.Photo in project glimmr by brk3.

the class AddToGroupDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mLayout = (LinearLayout) inflater.inflate(R.layout.add_to_group_fragment, container, false);
    mTitleView = (TextView) mLayout.findViewById(R.id.titleText);
    mTextUtils.setFont(mTitleView, TextUtils.FONT_ROBOTOBOLD);
    mProgressBar = (ProgressBar) mLayout.findViewById(R.id.progressIndicator);
    mProgressBar.setVisibility(View.VISIBLE);
    /* Nested fragments have to be added this way, not from xml */
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    final boolean retainInstance = false;
    final PhotoStreamGridFragment frag = PhotoStreamGridFragment.newInstance(mOAuth.getUser(), retainInstance, ListView.CHOICE_MODE_MULTIPLE);
    ft.replace(R.id.photoStreamFragment, frag);
    ft.commit();
    /* When add button is clicked, get selected ids and add to queue */
    mLayout.findViewById(R.id.buttonAddToGroup).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            List<Photo> selectedPhotos = frag.getSelectedPhotos();
            if (mRemaining < 0 || selectedPhotos.size() == 0) {
                Log.e(TAG, "None or too many items selected");
                return;
            }
            for (Photo photo : selectedPhotos) {
                mQueue.add(new AddItemToGroupTask(mGroup.getId(), photo.getId(), mOAuth));
            }
            mActivity.startService(new Intent(mActivity, AddToGroupTaskQueueService.class));
            dismiss();
            Crouton.makeText(mActivity, R.string.photos_will_be_added, Style.CONFIRM).show();
        }
    });
    return mLayout;
}
Also used : AddItemToGroupTask(com.bourke.glimmr.tasks.AddItemToGroupTask) FragmentTransaction(android.support.v4.app.FragmentTransaction) PhotoStreamGridFragment(com.bourke.glimmr.fragments.home.PhotoStreamGridFragment) List(java.util.List) Photo(com.googlecode.flickrjandroid.photos.Photo) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView)

Aggregations

Photo (com.googlecode.flickrjandroid.photos.Photo)18 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)3 LoadPhotoInfoTask (com.bourke.glimmr.tasks.LoadPhotoInfoTask)3 Bitmap (android.graphics.Bitmap)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 View (android.view.View)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 IPhotoInfoReadyListener (com.bourke.glimmr.event.Events.IPhotoInfoReadyListener)2 PhotoStreamGridFragment (com.bourke.glimmr.fragments.home.PhotoStreamGridFragment)2 List (java.util.List)2 Bundle (android.os.Bundle)1 Toolbar (android.support.v7.widget.Toolbar)1 SparseBooleanArray (android.util.SparseBooleanArray)1 MenuItem (android.view.MenuItem)1 RemoteViews (android.widget.RemoteViews)1 SpannableBuilder (com.alexvasilkov.android.commons.texts.SpannableBuilder)1 Background (com.alexvasilkov.events.Events.Background)1 Subscribe (com.alexvasilkov.events.Events.Subscribe)1