Java tutorial
/* * Copyright 2012 The Android Open Source Project * * 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.xogrp.planner.fragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; import com.nostra13.universalimageloader.core.ImageLoader; import com.xogrp.planner.PlannerApplication; import com.xogrp.planner.R; import com.xogrp.planner.model.VendorProfileMedia; /** * @author fchen * */ public class PortfolioSlidePageFragment extends Fragment { private static final String IMAGE_COUNT = "image_count"; private static final String PORTFOLIO_SLIDE_MEDIA = "portfolio_slide_MEDIA"; private static final String MEDIA_TYPE = "VIDEO"; private VendorProfileMedia mMediaItem; private OnClickListener mOnClickListener; public static PortfolioSlidePageFragment create(VendorProfileMedia mediaItem, int imageCount) { PortfolioSlidePageFragment fragment = new PortfolioSlidePageFragment(); Bundle args = new Bundle(); args.putSerializable(PORTFOLIO_SLIDE_MEDIA, mediaItem); args.putInt(IMAGE_COUNT, imageCount); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mMediaItem = (VendorProfileMedia) getArguments().getSerializable(PORTFOLIO_SLIDE_MEDIA); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_portfolio_images_slide_page, container, false); ImageView ivImage = (ImageView) rootView.findViewById(R.id.iv_pic); RelativeLayout rlPlay = (RelativeLayout) rootView.findViewById(R.id.rl_play); rlPlay.setVisibility(mMediaItem.getMediaType().equalsIgnoreCase(MEDIA_TYPE) ? View.VISIBLE : View.GONE); String imageUrl = mMediaItem.getMediaType().equalsIgnoreCase(MEDIA_TYPE) ? mMediaItem.getThumbnailUrl() : mMediaItem.getVideoUrl(); ImageLoader.getInstance().displayImage(imageUrl, ivImage, PlannerApplication.getDefaultDisplayImageOptions(R.drawable.vendor_summary_item_bg_default), null); ivImage.setOnClickListener(mOnClickListener); return rootView; } public void setOnClickListener(OnClickListener onClickListener) { mOnClickListener = onClickListener; } }