com.kasungunathilaka.sarigama.fragment.ConnectionFailFragment.java Source code

Java tutorial

Introduction

Here is the source code for com.kasungunathilaka.sarigama.fragment.ConnectionFailFragment.java

Source

/*
 * </summary>
 * Source File   : ConnectionFailFragment.java
 * Project      : Sarigama
 * Owner      : Kasun
 * </summary>
 *
 * <license>
 * Copyright 2016 Kasun Gunathilaka
 *
 * 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.
 * </license>
 */

package com.kasungunathilaka.sarigama.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.kasungunathilaka.sarigama.R;
import com.kasungunathilaka.sarigama.ui.HomeActivity;

public class ConnectionFailFragment extends Fragment {

    IFragmentCommunicator iFragmentCommunicator;
    Toolbar toolbar;
    HomeActivity activity;
    RelativeLayout rvReload;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_connection_fail, container, false);
        toolbar = (Toolbar) view.findViewById(R.id.toolbar);
        activity = (HomeActivity) getActivity();
        activity.setSupportActionBar(toolbar);
        activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
        activity.getSupportActionBar().setHomeButtonEnabled(true);
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        rvReload = (RelativeLayout) view.findViewById(R.id.rlReload);
        rvReload.setOnClickListener(backPressed);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        iFragmentCommunicator = (IFragmentCommunicator) getActivity();
    }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);
        searchItem.setVisible(false);
        MenuItem refreshItem = menu.findItem(R.id.action_refresh);
        refreshItem.setVisible(false);
    }

    View.OnClickListener backPressed = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            activity.onBackPressed();
        }
    };

}