Android Open Source - kluster-android Search Fragment






From Project

Back to project page kluster-android.

License

The source code is released under:

Apache License

If you think the Android project kluster-android 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

package com.cs446.kluster.views.fragments;
/*from w w  w . ja  v a 2  s.  co  m*/
import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.cs446.kluster.R;
import com.cs446.kluster.views.fragments.FilterDialogFragment.FilterListener;

public class SearchFragment extends Fragment implements ActionBar.TabListener {
    private ViewPager mPager;  
    private DemoCollectionPagerAdapter mAdapter;
    private Bundle mFilters;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    mFilters = new Bundle();
    
    if (getArguments() != null) {
      mFilters.putString("location", getLocationString(getArguments().getString("query")));
    }
    else {
      mFilters.putString("location", "0,0");
    }
    }
    
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.search_layout, container, false);

        mPager = (ViewPager) view.findViewById(R.id.viewpager_noswipe);
        mAdapter = new DemoCollectionPagerAdapter(getChildFragmentManager());
        mPager.setAdapter(mAdapter);  
        
        Button btnFilter = (Button) view.findViewById(R.id.search_btnfilter);
        
        btnFilter.setOnClickListener(new OnClickListener() {      
      @Override
      public void onClick(View v) {
        FilterDialogFragment fragment = new FilterDialogFragment();

        fragment.setFilterListener((FilterListener)mAdapter.getItem(mPager.getCurrentItem()));
        
        fragment.show(getFragmentManager(), "filterDialog");  
      }
    });
        
    return view;
  }
    
  public String getLocationString(String name) {

    Geocoder geocoder = new Geocoder(getActivity());
    List<Address> addr = null;
    try {
      addr = geocoder.getFromLocationName(name, 1);
    }
    catch (IOException e) {
    }
    
    if (addr != null) {
      return String.format(Locale.US, "%f,%f", addr.get(0).getLatitude(), addr.get(0).getLongitude());
    }
    else {
      return "";
    }
  }

  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
      mPager.setCurrentItem(tab.getPosition());
  }

  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    
  }  
  
   public class DemoCollectionPagerAdapter extends FragmentPagerAdapter {
       public DemoCollectionPagerAdapter(FragmentManager fm) {
           super(fm);
       }
  
       @Override
       public Fragment getItem(int position) {

            if (position == 0) {
              Fragment fragment = new SearchGridFragment();
              fragment.setArguments(mFilters);
             return fragment;
           }
           else {
                Fragment fragment = new SearchMapFragment();
                fragment.setArguments(mFilters);
               return fragment;        
           }
       }
  
       @Override
       public int getCount() {
           return 2;
       }
       
       @Override
      public CharSequence getPageTitle(int position) {
              if (position == 0) {
               return "PHOTO";
             }
             else {
               return "MAP";           
             }
      }
   }
}




Java Source Code List

android.app.GridFragment.java
android.app.NonSwipeableViewPager.java
android.app.ScaleImageView.java
com.cs446.kluster.ConfigManager.java
com.cs446.kluster.KlusterApplication.java
com.cs446.kluster.cache.CacheUtils.java
com.cs446.kluster.cache.DiskLruCache.java
com.cs446.kluster.cache.DiskLruImageCache.java
com.cs446.kluster.cache.KlusterCache.java
com.cs446.kluster.data.AbstractContentStorageAdapter.java
com.cs446.kluster.data.EventProvider.java
com.cs446.kluster.data.EventStorageAdapter.java
com.cs446.kluster.data.PhotoProvider.java
com.cs446.kluster.data.PhotoStorageAdapter.java
com.cs446.kluster.data.SearchProvider.java
com.cs446.kluster.data.SearchStorageAdapter.java
com.cs446.kluster.data.StorageAdapter.java
com.cs446.kluster.data.StorageConstants.java
com.cs446.kluster.data.serialize.AuthUserAdapter.java
com.cs446.kluster.data.serialize.EventAdapter.java
com.cs446.kluster.data.serialize.PhotoAdapter.java
com.cs446.kluster.data.serialize.SerializerUtils.java
com.cs446.kluster.data.serialize.UserAdapter.java
com.cs446.kluster.map.MapUtils.java
com.cs446.kluster.models.AuthUser.java
com.cs446.kluster.models.Event.java
com.cs446.kluster.models.Photo.java
com.cs446.kluster.models.User.java
com.cs446.kluster.net.AuthInterceptor.java
com.cs446.kluster.net.AuthKlusterRestAdapter.java
com.cs446.kluster.net.EventsCallback.java
com.cs446.kluster.net.KlusterRestAdapter.java
com.cs446.kluster.net.KlusterService.java
com.cs446.kluster.net.NetworkUtils.java
com.cs446.kluster.net.PhotosCallback.java
com.cs446.kluster.net.UploadService.java
com.cs446.kluster.views.activities.LoginActivity.java
com.cs446.kluster.views.activities.MainActivity.java
com.cs446.kluster.views.activities.PhotoFactory.java
com.cs446.kluster.views.activities.PhotoGridActivity.java
com.cs446.kluster.views.fragments.DiscoverFragment.java
com.cs446.kluster.views.fragments.EventDialogFragment.java
com.cs446.kluster.views.fragments.EventGridAdapter.java
com.cs446.kluster.views.fragments.EventGridFragment.java
com.cs446.kluster.views.fragments.EventMapFragment.java
com.cs446.kluster.views.fragments.FilterDialogFragment.java
com.cs446.kluster.views.fragments.PhotoGridAdapter.java
com.cs446.kluster.views.fragments.PhotoGridFragment.java
com.cs446.kluster.views.fragments.PhotoViewerFragment.java
com.cs446.kluster.views.fragments.SearchFragment.java
com.cs446.kluster.views.fragments.SearchGridFragment.java
com.cs446.kluster.views.fragments.SearchMapFragment.java
com.cs446.kluster.views.fragments.SignupFragment.java
com.cs446.kluster.views.fragments.UserProfileFragment.java
com.cs446.kluster.views.map.PhotoInfoWindowAdapter.java