Back to project page Wardrobe_app.
The source code is released under:
Apache License
If you think the Android project Wardrobe_app 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.android.busolo.apps.wardrobe.engine; /*from w ww . ja v a 2s.c o m*/ /** * Created by s-brian on 5/24/2014. */ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.AsyncTaskLoader; import android.support.v4.content.Loader; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.android.busolo.apps.wardrobe.engine.adapter.GridViewPhotoAdapter; import com.android.busolo.apps.wardrobe.engine.model.Stream; import com.android.busolo.apps.wardrobe.utils.ImageLoader; import com.android.busolo.apps.wardrobe.widget.BezelImageView; import com.android.busolo.apps.wardrobe.widget.EllipsizedTextView; import com.makeramen.RoundedImageView; import java.io.InputStream; import java.util.ArrayList; import static com.android.busolo.apps.wardrobe.utils.LogUtils.LOGE; public class ProfileFragment extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<String>>{ private final static String LOG_TAG = "ProfileFragment"; private final static String ARG_SECTION_NUMBER = "section_number"; private RoundedImageView user_profpic; private TextView user_name; private TextView user_location; private ImageView call_biz; private ImageView text_biz; private ImageView email_biz; private ImageView show_grid; private ImageView show_list; private GridView photosGridview; private ListView photoListView; private View layout_priv_profile; private View layout_biz_profile; //private profile private Button btn_show_biz; private Button btn_priv_posts; private Button btn_priv_followers; private Button btn_priv_following; private View section_contact; //biz profile private Button btn_show_priv; private Button btn_biz_posts; private Button btn_biz_followers; private static final String STATE_POSITION = "position"; private static final String STATE_TOP = "top"; private static final int STREAM_LOADER_ID = 0; private Activity activity; ArrayList<String> mStream = new ArrayList<String>(); private StreamAdapter mStreamAdapter; private int mListViewStatePosition; private int mListViewStateTop; private ImageLoader mImageLoader; private ArrayList<Stream> streamList; private GridViewPhotoAdapter gridViewPhotoAdapter; public ProfileFragment(){} public static ProfileFragment newInstance(int sectionNumber) { ProfileFragment fragment = new ProfileFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; } @Override public void onAttach(Activity activity){ super.onAttach(activity); this.activity = activity; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View rootView = inflater.inflate(R.layout.fragment_profile, container, false); //init ui here call_biz = (ImageView)rootView.findViewById(R.id.img_call_biz); text_biz = (ImageView)rootView.findViewById(R.id.img_text_biz); email_biz = (ImageView)rootView.findViewById(R.id.img_email_biz); show_grid = (ImageView)rootView.findViewById(R.id.img_show_grid); show_list = (ImageView)rootView.findViewById(R.id.img_show_list); photosGridview = (GridView)rootView.findViewById(R.id.photosGridview); photoListView = (ListView)rootView.findViewById(R.id.photoListView); layout_biz_profile = (LinearLayout)rootView.findViewById(R.id.layout_biz_profile); layout_priv_profile = (LinearLayout)rootView.findViewById(R.id.layout_priv_profile); //private ui btn_show_biz = (Button)rootView.findViewById(R.id.btn_priv_switch_profile); btn_priv_posts = (Button)rootView.findViewById(R.id.btn_priv_posts); btn_priv_followers = (Button)rootView.findViewById(R.id.btn_priv_followers); btn_priv_following = (Button)rootView.findViewById(R.id.btn_priv_following); //public ui btn_show_priv = (Button)rootView.findViewById(R.id.btn_biz_switch_profile); btn_biz_posts = (Button)rootView.findViewById(R.id.btn_profile_biz_posts); btn_biz_followers = (Button)rootView.findViewById(R.id.btn_profile_biz_followers); section_contact = (LinearLayout)rootView.findViewById(R.id.section_contact); //TODO show section_contact when not viewing profile section_contact.setVisibility(View.GONE); //TODO add listeners call_biz.setOnClickListener(clickListener); text_biz.setOnClickListener(clickListener); email_biz.setOnClickListener(clickListener); show_grid.setOnClickListener(clickListener); show_list.setOnClickListener(clickListener); btn_show_biz.setOnClickListener(clickListener); btn_priv_posts.setOnClickListener(clickListener); btn_priv_followers.setOnClickListener(clickListener); btn_priv_following.setOnClickListener(clickListener); btn_show_priv.setOnClickListener(clickListener); btn_biz_posts.setOnClickListener(clickListener); btn_biz_followers.setOnClickListener(clickListener); return rootView; } @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setHasOptionsMenu(true); setRetainInstance(true); } //change ui stuff..frag is live @Override public void onStart(){ super.onStart(); streamList = new ArrayList<Stream>(); //dummy data for(int i=0; i<20; i++) streamList.add(new Stream()); //dummy data for(int i=0; i<10;i++) mStream.add(""); gridViewPhotoAdapter = new GridViewPhotoAdapter(activity, streamList); photosGridview.setAdapter(gridViewPhotoAdapter); mStreamAdapter = new StreamAdapter(); photoListView.setAdapter(mStreamAdapter); } View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View view) { Animation animation = null; Intent intent; Bundle args; switch (view.getId()){ case R.id.img_call_biz: //call user callUser(); break; case R.id.img_text_biz: //text user sendText(); break; case R.id.img_email_biz: //email biz emailBiz(); break; case R.id.img_show_grid: //show photo grid photosGridview.setVisibility(View.VISIBLE); photoListView.setVisibility(View.GONE); break; case R.id.img_show_list: //show list photoListView.setVisibility(View.VISIBLE); photosGridview.setVisibility(View.GONE); break; case R.id.btn_priv_switch_profile: //show biz profile animation = AnimationUtils.loadAnimation(ProfileFragment.this.activity, R.anim.right_to_left); animation.setAnimationListener(rightLeftAnimListener); layout_biz_profile.setAnimation(animation); layout_biz_profile.startAnimation(animation); break; case R.id.btn_biz_switch_profile: //show priv profile if(animation != null) animation.cancel(); animation = AnimationUtils.loadAnimation(ProfileFragment.this.activity, R.anim.left_to_right); animation.setAnimationListener(leftRightAnimListener); layout_priv_profile.setAnimation(animation); layout_priv_profile.startAnimation(animation); break; case R.id.btn_priv_following: //show following list toast("show following list"); intent = new Intent(ProfileFragment.this.activity, FollowActivity.class); args = new Bundle(); args.putInt(FollowActivity.FOLLOW_TYPE, FollowActivity.KEY_PRIV_FOLLOWING); intent.putExtras(args); startActivity(intent); break; case R.id.btn_priv_followers: //show followers list toast("show followers list"); intent = new Intent(ProfileFragment.this.activity, FollowActivity.class); args = new Bundle(); args.putInt(FollowActivity.FOLLOW_TYPE, FollowActivity.KEY_PRIV_FOLLOWER); intent.putExtras(args); startActivity(intent); break; case R.id.btn_profile_biz_followers: //show biz followers list toast("show biz followers list"); intent = new Intent(ProfileFragment.this.activity, FollowActivity.class); args = new Bundle(); args.putInt(FollowActivity.FOLLOW_TYPE, FollowActivity.KEY_BIZ_FOLLOWER); intent.putExtras(args); startActivity(intent); break; default: break; } } }; Animation.AnimationListener rightLeftAnimListener = new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { layout_priv_profile.setVisibility(View.INVISIBLE); } @Override public void onAnimationEnd(Animation animation) { layout_priv_profile.setVisibility(View.GONE); layout_biz_profile.setVisibility(View.VISIBLE); Log.e(LOG_TAG, "animation complete!"); } @Override public void onAnimationRepeat(Animation animation) {} }; Animation.AnimationListener leftRightAnimListener = new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { layout_biz_profile.setVisibility(View.INVISIBLE); } @Override public void onAnimationEnd(Animation animation) { layout_biz_profile.setVisibility(View.GONE); layout_priv_profile.setVisibility(View.VISIBLE); Log.e(LOG_TAG, "animation complete!"); } @Override public void onAnimationRepeat(Animation animation) {} }; void callUser(){ String phoneNo = "123456789"; Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+phoneNo)); activity.startActivity(callIntent); } void sendText(){ String phoneNo = "123456789"; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.fromParts("sms", phoneNo, null)); activity.startActivity(intent); } void emailBiz(){ //TODO awesomenize email stuff String destEmail = "uptown.botiques@gmail.com"; String subject = "Price Catalogue"; String message = "Provide me with ur price catalog."; sendEmail(destEmail, null, subject, message); } private void sendEmail(String destEmail, String cc, String subject, String message){ Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{destEmail}); // emailIntent.putExtra(Intent.EXTRA_CC, new String[]{cc}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); startActivity(Intent.createChooser(emailIntent, "Choose an Email Client")); } @Override public void onResume(){ super.onResume(); } @Override public void onPause(){ super.onPause(); } @Override public void onPrepareOptionsMenu(Menu menu){ super.onPrepareOptionsMenu(menu); } public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){ super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.profile, menu); } @Override public boolean onOptionsItemSelected(MenuItem item){ super.onOptionsItemSelected(item); switch (item.getItemId()){ default: break; } return super.onOptionsItemSelected(item); } @Override public void onSaveInstanceState(Bundle outState){ super.onSaveInstanceState(outState); } @Override public Loader<ArrayList<String>> onCreateLoader(int id, Bundle args) { return null; } @Override public void onLoadFinished(Loader<ArrayList<String>> loader, ArrayList<String> data) { } @Override public void onLoaderReset(Loader<ArrayList<String>> loader) { } //TODO optimize this point downwards void toast(String text){ Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show(); } private boolean isStreamLoading() { if (isAdded()) { final Loader loader = getLoaderManager().getLoader(STREAM_LOADER_ID); if (loader != null) { return ((StreamLoader) loader).isLoading(); } } return true; } private boolean streamHasMoreResults() { if (isAdded()) { final Loader loader = getLoaderManager().getLoader(STREAM_LOADER_ID); if (loader != null) { return ((StreamLoader) loader).hasMoreResults(); } } return false; } private boolean streamHasError() { if (isAdded()) { final Loader loader = getLoaderManager().getLoader(STREAM_LOADER_ID); if (loader != null) { return ((StreamLoader) loader).hasError(); } } return false; } public static class StreamLoader extends AsyncTaskLoader<ArrayList<String>> { ArrayList<String> mActivities; private String mSearchString; private String mNextPageToken; private boolean mIsLoading; private boolean mHasError; public StreamLoader(Context context, String searchString) { super(context); init(searchString); } private void init(String searchString) { mSearchString = searchString; mHasError = false; mNextPageToken = null; mIsLoading = true; mActivities = null; } @Override public ArrayList<String> loadInBackground() { mIsLoading = true; ArrayList<String> activities = new ArrayList<String>(); for(int i = 0; i < 9; i++) activities.add(""); return activities; } @Override public void deliverResult(ArrayList<String> activities) { mIsLoading = false; if (activities != null) { mActivities = null; if (mActivities == null) { mActivities = activities; } else { mActivities.addAll(activities); } } if (isStarted()) { // Need to return new ArrayList for some reason or onLoadFinished() is not called super.deliverResult(mActivities == null ? null : new ArrayList<String>(mActivities)); } } @Override protected void onStartLoading() { if (mActivities != null) { // If we already have results and are starting up, deliver what we already have. deliverResult(null); } else { forceLoad(); } } @Override protected void onStopLoading() { mIsLoading = false; cancelLoad(); } @Override protected void onReset() { super.onReset(); onStopLoading(); mActivities = null; } public boolean isLoading() { return mIsLoading; } public boolean hasMoreResults() { return mNextPageToken != null; } public boolean hasError() { return mHasError; } public void setSearchString(String searchString) { mSearchString = searchString; } public void refresh() { reset(); startLoading(); } } public class StreamAdapter extends BaseAdapter { private static final int VIEW_TYPE_ACTIVITY = 0; private static final int VIEW_TYPE_LOADING = 1; @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { return getItemViewType(position) == VIEW_TYPE_ACTIVITY; } @Override public int getViewTypeCount() { return 2; } @Override public boolean hasStableIds() { return true; } @Override public int getCount() { return mStream.size() + ( // show the status list row if... ((isStreamLoading() && mStream.size() == 0) // ...this is the first load || streamHasMoreResults() // ...or there's another page || streamHasError()) // ...or there's an error ? 1 : 0); } @Override public int getItemViewType(int position) { return (position >= mStream.size()) ? VIEW_TYPE_LOADING : VIEW_TYPE_ACTIVITY; } @Override public Object getItem(int position) { return (getItemViewType(position) == VIEW_TYPE_ACTIVITY) ? mStream.get(position) : null; } @Override public long getItemId(int position) { // TODO: better unique ID heuristic return position; } int pos = 0; public String getURL(){ String url = "http://www.wwd.com/images/processed/footwear-news/2011/10/25/landscape/01-large/sexy-shoe01.jpg"; switch (pos){ case 1: url="http://blogs.sun-sentinel.com/features_fashion/files/2011/12/SexyShoeJimmyChoo.jpg"; break; case 2: url="http://buybestdesignerhandbags.com/wp-content/uploads/2013/08/Designer-Handbags.jpg"; break; case 3: url="http://www.bharatmoms.com/uploads/Image/Latest%20handmade%20rose%20flower%202013%20collection%20of%20hand%20bags.jpg"; break; case 4: url="http://fc09.deviantart.net/fs70/i/2013/219/9/d/dress_evora__somnia_romantica_by_marjolein_turin_by_somniaromantica-d6h1n04.jpg"; break; case 5: url="http://www.handbagsexpert.com/wp-content/uploads/2013/03/277514_AKZ5A_2816_001_web_doublehero.png"; break; case 6: url="http://images6.fanpop.com/image/photos/33900000/Sexy-shoes-womens-shoes-33981381-870-675.jpg"; break; } return url; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (getItemViewType(position) == VIEW_TYPE_LOADING) { if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate( R.layout.list_item_stream_status, parent, false); } if (streamHasError()) { convertView.findViewById(android.R.id.progress).setVisibility(View.GONE); ((TextView) convertView.findViewById(android.R.id.text1)).setText( R.string.stream_error); } else { convertView.findViewById(android.R.id.progress).setVisibility(View.VISIBLE); ((TextView) convertView.findViewById(android.R.id.text1)).setText( R.string.loading); } return convertView; } else { pos++; if (convertView == null) { convertView = getActivity().getLayoutInflater().inflate( R.layout.list_item_stream, parent, false); } //init list item ui RoundedImageView stream_user_image = (RoundedImageView) convertView.findViewById(R.id.stream_user_image); TextView txt_stream_username = (TextView) convertView.findViewById(R.id.stream_user_name); TextView txt_stream_time = (TextView) convertView.findViewById(R.id.stream_time); EllipsizedTextView txt_stream_content = (EllipsizedTextView) convertView.findViewById(R.id.stream_content); View stream_original_container = (LinearLayout)convertView.findViewById(R.id.stream_original_container); TextView stream_original_author = (TextView)convertView.findViewById(R.id.stream_original_author); EllipsizedTextView stream_original_content = (EllipsizedTextView)convertView.findViewById(R.id.stream_original_content); ImageView stream_media_background = (ImageView)convertView.findViewById(R.id.stream_media_background); ImageView stream_media_overlay = (ImageView)convertView.findViewById(R.id.stream_media_overlay); TextView stream_price = (TextView)convertView.findViewById(R.id.stream_price); TextView stream_size = (TextView)convertView.findViewById(R.id.stream_size); //View stream_color_viewer_1 = (View)convertView.findViewById(R.id.stream_color_viewer_1); //View stream_color_viewer_2 = (View)convertView.findViewById(R.id.stream_color_viewer_2); ImageView btn_stream_like = (ImageView)convertView.findViewById(R.id.btn_stream_like); ImageView btn_stream_comment = (ImageView)convertView.findViewById(R.id.btn_stream_comment); ImageView btn_stream_share = (ImageView)convertView.findViewById(R.id.btn_stream_share); txt_stream_username.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("open user profile"); } }); txt_stream_content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("expand view, if ellipsized"); } }); stream_original_author.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("open original stream"); } }); stream_original_content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("open original stream"); } }); btn_stream_like.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("liking current item"); } }); btn_stream_comment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("comment"); } }); btn_stream_share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toast("reshare"); } }); //TODO set data //Interactions // LinearLayout stream_interactions_container = (LinearLayout) convertView.findViewById(R.id.stream_interactions_container); // stream_interactions_container.setVisibility(View.VISIBLE); // TextView stream_likes = (TextView) convertView.findViewById(R.id.stream_likes); // stream_likes.setVisibility(View.VISIBLE); // stream_likes.setText(" 25"); // TextView stream_shares = (TextView) convertView.findViewById(R.id.stream_shares); // stream_shares.setText(" 18"); // stream_shares.setVisibility(View.VISIBLE); // TextView stream_comments = (TextView) convertView.findViewById(R.id.stream_comments); // stream_comments.setText(" 31"); // stream_comments.setVisibility(View.VISIBLE); //Media shit RelativeLayout stream_media_container = (RelativeLayout) convertView.findViewById(R.id.stream_media_container); stream_media_container.setVisibility(View.VISIBLE); // show The Image // new DownloadImageTask(stream_media_overlay).execute(getURL()); // stream_media_overlay.setVisibility(View.VISIBLE); // txt_stream_username.setText("User name"); // txt_stream_time.setText("May 25"); // txt_stream_content.setText("A sample stream from user!!"); // txt_stream_content.setVisibility(View.VISIBLE); // txt_stream_content.animate(); String DUMMY_IMG_URL = "https://avatars0.githubusercontent.com/u/4123209?s=140"; if (mImageLoader != null) { String url = getURL(); LOGE("streamFrag", "URL: "+url); mImageLoader.get(DUMMY_IMG_URL, stream_user_image, getResources().getDrawable(R.drawable.person_image_empty)); mImageLoader.get(getURL(), stream_media_background,getResources().getDrawable(R.drawable.shoes_4)); }else{ LOGE("streamFrag", "ImageLoader is empty!"); } return convertView; } } } public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageView bmImage; public DownloadImageTask(ImageView bmImage) { this.bmImage = bmImage; } protected Bitmap doInBackground(String... urls) { String urldisplay = urls[0]; Bitmap mIcon11 = null; try { InputStream in = new java.net.URL(urldisplay).openStream(); mIcon11 = BitmapFactory.decodeStream(in); } catch (Exception e) { LOGE("Error", e.getMessage()); e.printStackTrace(); } return mIcon11; } protected void onPostExecute(Bitmap result) { bmImage.setImageBitmap(result); } } }