Java tutorial
/* * Copyright 2016 Google Inc. All Rights Reserved. * * 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.example.bobbyranjan.ybsandroid; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.transition.Explode; public class BaseActivity extends AppCompatActivity { private static final String TAG_DIALOG_FRAGMENT = "tagDialogFragment"; protected ActionBar supportActionBar; protected void showProgressDialog(String title, String message, boolean isCancellable) { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment prev = getExistingDialogFragment(); if (prev == null) { ProgressDialogFragment fragment = ProgressDialogFragment.newInstance(title, message, isCancellable); fragment.show(ft, TAG_DIALOG_FRAGMENT); } } protected void dismissProgressDialog() { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); Fragment prev = getExistingDialogFragment(); if (prev != null) { ft.remove(prev).commit(); } } private Fragment getExistingDialogFragment() { return getSupportFragmentManager().findFragmentByTag(TAG_DIALOG_FRAGMENT); } protected void setupToolbar(Toolbar toolbar) { setSupportActionBar(toolbar); supportActionBar = getSupportActionBar(); assert supportActionBar != null; supportActionBar.setDisplayHomeAsUpEnabled(true); } protected void setUpAnimation() { Explode enterTransition = new Explode(); enterTransition.setDuration(getResources().getInteger(R.integer.anim_duration)); getWindow().setEnterTransition(enterTransition); } }