com.sunho.nating.fragments.ThemeFragment.java Source code

Java tutorial

Introduction

Here is the source code for com.sunho.nating.fragments.ThemeFragment.java

Source

/*
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sunho.nating.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.GridView;

import com.sunho.nating.adapter.ThemeAdapter;
import com.sunho.nating.listviewfeed.MainActivity;
import com.sunho.nating.listviewfeed.R;
import com.sunho.nating.listviewfeed.data.Theme;

public class ThemeFragment extends Fragment implements AdapterView.OnItemClickListener {

    private static final String TAG = "FragmentTransitionFragment";

    private ThemeAdapter mAdapter;
    private String myLocationStringData = null;
    private String result = null;
    private String totalURL = null;
    private String myLocationDistanceData = "5000";
    private String myLocationLat, myLocationLong;

    public ThemeFragment() {
    }

    public ThemeFragment(String result, String result2, String result3, String result4, String result5) {
        this.result = result;
        this.myLocationStringData = result2;
        this.totalURL = result3;
        this.myLocationLat = result4;
        this.myLocationLong = result5;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        MainActivity.aBar.show();
        // This is the adapter we use to populate the grid.
        mAdapter = new ThemeAdapter(inflater, R.layout.item_gridview);
        // Inflate the layout with a GridView in it.
        return inflater.inflate(R.layout.fragment_fragment_transition, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        GridView grid = (GridView) view.findViewById(R.id.grid);
        grid.setAdapter(mAdapter);
        grid.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Theme theme = mAdapter.getItem(position);
        // We start the fragment transaction here. It is just an ordinary fragment transaction.
        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.frame_container,
                DetailPlaceFragment.newInstance(theme.resourceId, theme.title, (int) view.getX(), (int) view.getY(),
                        view.getWidth(), view.getHeight(), position, myLocationLat, myLocationLong))
                // We push the fragment transaction to back stack. User can go back to the
                // previous fragment by pressing back button.
                .addToBackStack("detail").commit();
    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return AnimationUtils.loadAnimation(MainActivity.mActivity,
                enter ? android.R.anim.fade_in : android.R.anim.fade_out);
    }

}