Android Open Source - MixtioMD1Studio Item Detail Fragment






From Project

Back to project page MixtioMD1Studio.

License

The source code is released under:

Apache License

If you think the Android project MixtioMD1Studio 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 2014 Mixtio Software LLC/* w  w  w  . j a va2s .  c o 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.mixtio.md1studio;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Roger on 2/8/14.
 */
public class ItemDetailFragment extends Fragment {

    /**The fragment argument representing the item ID that this fragment represents. */
    public static final String ARG_ITEM_ID = "item_id";

    /** id passed over from bundle based on Square Model's id.  */
    protected int mId;

    /**List variable of the SquareModel*/
    List<SquareModel> mData;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public ItemDetailFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getArguments().containsKey(ARG_ITEM_ID)) {
            mId = getArguments().getInt(ARG_ITEM_ID);
        }
        mData = Utilities.readJsonFile(this.getActivity().getApplicationContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = null;
        view = inflater.inflate(R.layout.item_detail_layout, container,false);

        if(mData != null) {
            final ViewHolder viewHolder = new ViewHolder();

            int resId = Utilities.getImageId(getActivity().getApplicationContext(), mData.get(mId).getImage());
            viewHolder.mCode = (TextView)view.findViewById(R.id.tv_detail_code);
            viewHolder.mDescription = (TextView)view.findViewById(R.id.tv_detail_description);
            viewHolder.mHistory = (TextView)view.findViewById(R.id.tv_detail_history);
            viewHolder.mShape = (TextView)view.findViewById(R.id.tv_detail_shape);
            viewHolder.mTitle = (TextView)view.findViewById(R.id.tv_detail_color);
            viewHolder.mImage = (ImageView)view.findViewById(R.id.iv_detail_color);

            viewHolder.mCode.setText(mData.get(mId).getHexCode());
            viewHolder.mDescription.setText(mData.get(mId).getDescription());
            viewHolder.mHistory.setText(mData.get(mId).getHistory());
            viewHolder.mShape.setText(mData.get(mId).getShape());
            viewHolder.mImage.setImageResource(resId);

            /**
             * This Textview is only on Tablets.
             * */
            if(viewHolder.mTitle != null) {
                viewHolder.mTitle.setText(mData.get(mId).getColor());
            }

        }

        return view;
    }

    /**
     * ViewHolder Pattern
     * */
    static class ViewHolder {
        ImageView mImage;
        TextView mTitle;
        TextView mShape;
        TextView mCode;
        TextView mDescription;
        TextView mHistory;
    }
}




Java Source Code List

com.mixtio.md1studio.ItemAdapter.java
com.mixtio.md1studio.ItemDetailActivity.java
com.mixtio.md1studio.ItemDetailFragment.java
com.mixtio.md1studio.ItemListFragment.java
com.mixtio.md1studio.MainActivity.java
com.mixtio.md1studio.SquareModel.java
com.mixtio.md1studio.Utilities.java