Back to project page APO-DZ-Android.
The source code is released under:
MIT License
If you think the Android project APO-DZ-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.
package org.upennapo.app.fragment; /*from w w w. j a v a 2s . c o m*/ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import org.upennapo.app.R; import org.upennapo.app.activity.WebActivity; import org.upennapo.app.adapter.LinkAdapter; /** * A fragment representing a list of Links. * <p/> * <p/> * Activities containing this fragment MUST implement the Callbacks * interface. */ public class LinkListFragment extends ListFragment { public static final String TITLES = "LINK_TITLES"; public static final String DESCRIPTIONS = "LINK_DESCRIPTIONS"; public static final String TARGETS = "LINK_TARGETS"; private String[] mLinkTargets, mLinkTitles; /** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */ public LinkListFragment() { } public static LinkListFragment newBrotherLinksInstance(Context context) { Bundle args = new Bundle(); args.putStringArray(TITLES, context.getResources().getStringArray(R.array.brother_link_titles)); args.putStringArray(DESCRIPTIONS, context.getResources().getStringArray(R.array.brother_link_descr)); args.putStringArray(TARGETS, context.getResources().getStringArray(R.array.brother_link_targets)); LinkListFragment instance = new LinkListFragment(); instance.setArguments(args); return instance; } public static LinkListFragment newAlumLinksInstance(Context context) { Bundle args = new Bundle(); args.putStringArray(TITLES, context.getResources().getStringArray(R.array.alumni_res_titles)); args.putStringArray(DESCRIPTIONS, context.getResources().getStringArray(R.array.alumni_res_descriptions)); args.putStringArray(TARGETS, context.getResources().getStringArray(R.array.alumni_res_targets)); LinkListFragment instance = new LinkListFragment(); instance.setArguments(args); return instance; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLinkTargets = getArguments().getStringArray(TARGETS); mLinkTitles = getArguments().getStringArray(TITLES); setListAdapter(new LinkAdapter(getActivity(), R.layout.fragment_links, getArguments())); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_links, container, false); } @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); final String targetUrl = mLinkTargets[position], targetTitle = mLinkTitles[position]; boolean targetIsAForm = targetUrl.startsWith("https://docs.google.com/forms/") || targetUrl.startsWith("http://form.jotform.us/form/"); Intent viewIntent = targetIsAForm ? new Intent(getActivity(), WebActivity.class) : new Intent(Intent.ACTION_VIEW, Uri.parse(targetUrl)); viewIntent.putExtra(WebFragment.URL_KEY, targetUrl); viewIntent.putExtra(WebActivity.TITLE, targetTitle); startActivity(viewIntent); } }