Android Open Source - APO-DZ-Android Link List Fragment






From Project

Back to project page APO-DZ-Android.

License

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.

Java Source Code

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);
    }
}




Java Source Code List

org.upennapo.app.activity.AlumModeActivity.java
org.upennapo.app.activity.DirectoryActivity.java
org.upennapo.app.activity.DirectoryDetailsActivity.java
org.upennapo.app.activity.EasterEggActivity.java
org.upennapo.app.activity.LoginActivity.java
org.upennapo.app.activity.MainActivity.java
org.upennapo.app.activity.WebActivity.java
org.upennapo.app.adapter.AlphabeticalAdapter.java
org.upennapo.app.adapter.LinkAdapter.java
org.upennapo.app.fragment.AlumDirectoryFragment.java
org.upennapo.app.fragment.BrotherStatusFragment.java
org.upennapo.app.fragment.DirectoryFragment.java
org.upennapo.app.fragment.LinkListFragment.java
org.upennapo.app.fragment.NavigationDrawerFragment.java
org.upennapo.app.fragment.WebFragment.java
org.upennapo.app.model.Brother.java
org.upennapo.app.model.DataManager.java
org.upennapo.app.model.User.java