Java tutorial
/******************************************************************************* * Copyright 2014 Sergey Tarasevich * <p/> * 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.nostra13.universalimageloader.sample.ui.activity.activity; import android.app.FragmentTransaction; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.Menu; import android.view.MenuItem; import com.google.android.gms.plus.Plus; import com.nostra13.universalimageloader.sample.Constants; import com.nostra13.universalimageloader.sample.R; import com.nostra13.universalimageloader.sample.fragment.ProductListFragment; /** * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class ProductListActivity extends FragmentActivity { private ProductListFragment mAdapter = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); displayListFragment(getFragmentManager().beginTransaction()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main_menu, menu); return true; } private void displayListFragment(FragmentTransaction ft) { if (mAdapter == null) { mAdapter = new ProductListFragment(); } ft.replace(android.R.id.content, mAdapter).commit(); } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.item_logout: onSignOutClicked(); return true; default: return super.onOptionsItemSelected(item); } } protected void onSignOutClicked() { // Clear the default account so that GoogleApiClient will not automatically // connect in the future. if (Constants.mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(Constants.mGoogleApiClient); Constants.mGoogleApiClient.disconnect(); } finish(); } @Override public void onBackPressed() { // Preventing user from back action } }