Back to project page WineDB.
The source code is released under:
MIT License
If you think the Android project WineDB listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.selesse.android.winedb.activity; //from www .j a v a 2s . co m import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RatingBar; import android.widget.TextView; import com.selesse.android.winedb.R; import com.selesse.android.winedb.async.AsyncImageLoader; import com.selesse.android.winedb.database.Wine; import com.selesse.android.winedb.database.WineDatabaseHandler; import com.selesse.android.winedb.model.WineColor; public class SingleWineFragment extends Fragment { private static final String TAG = SingleWineFragment.class.getSimpleName(); private Context context; private ImageView imageView; private TextView nameText; private TextView countryText; private TextView yearText; private TextView colorText; private TextView descText; private RatingBar ratingBar; private TextView priceText; private TextView commentText; public SingleWineFragment() {} public static SingleWineFragment newInstance(long wineId) { Log.i(TAG, "New instance creation requested for id " + wineId); SingleWineFragment fragment = new SingleWineFragment(); Bundle args = new Bundle(); args.putLong("id", wineId); fragment.setArguments(args); return fragment; } @Override public void onAttach(Activity activity) { super.onAttach(activity); this.context = activity.getApplicationContext(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.single_wine_fragment, container, false); Bundle args = getArguments(); Wine wine = new Wine(); if (args.containsKey("id")) { Long id = args.getLong("id"); wine = WineDatabaseHandler.getInstance(context).getWine(id); } initializeViews(rootView); setupView(wine); return rootView; } private void initializeViews(View rootView) { nameText = (TextView) rootView.findViewById(R.id.wineNameText); countryText = (TextView) rootView.findViewById(R.id.countryText); yearText = (TextView) rootView.findViewById(R.id.yearText); colorText = (TextView) rootView.findViewById(R.id.colorText); descText = (TextView) rootView.findViewById(R.id.descText); ratingBar = (RatingBar) rootView.findViewById(R.id.ratingBar); priceText = (TextView) rootView.findViewById(R.id.priceText); commentText = (TextView) rootView.findViewById(R.id.commentText); imageView = (ImageView) rootView.findViewById(R.id.image); } private void setupView(Wine wine) { nameText.setText(wine.getName()); countryText.setText(wine.getCountry()); if (wine.getYear() != -1) { yearText.setText("" + wine.getYear()); } else { yearText.setText(""); } if (wine.getColor() != WineColor.UNKNOWN) { colorText.setText(WineColor.getLocalizedString(context.getResources(), wine .getColor().toString())); } descText.setText(wine.getDescription()); if (wine.getRating() != -1) { ratingBar.setRating(wine.getRating() / 2.0f); } else { ratingBar.setRating(0); } priceText.setText(wine.getPrice()); if (!wine.getComment().equals("")) { commentText.setText(wine.getComment()); } else { commentText.setText(context.getString(R.string.not_yet_commented)); } if (wine.getImageUrl() != null && wine.getImageUrl().startsWith("http")) { AsyncTask<String, Void, Bitmap> imageLoader = new AsyncImageLoader(imageView); imageLoader.execute(wine.getImageUrl()); } else { imageView.setImageBitmap(null); } } }