by.gdgminsk.animationguide.GuideMainMenuActivity.java Source code

Java tutorial

Introduction

Here is the source code for by.gdgminsk.animationguide.GuideMainMenuActivity.java

Source

/*
 * Copyright 2015 GDG Minsk
 *
 * 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 by.gdgminsk.animationguide;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import by.gdgminsk.animationguide.adapter.SamplesAdapter;
import by.gdgminsk.animationguide.util.AnimUtils;

public class GuideMainMenuActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private static final String LOG_TAG = "GuideMainMenuActivity";

    private SamplesAdapter mSamplesAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_main_menu);

        ListView samples = (ListView) findViewById(R.id.samples);
        samples.setOnItemClickListener(this);
        mSamplesAdapter = new SamplesAdapter(this);
        samples.setAdapter(mSamplesAdapter);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Sample sample = mSamplesAdapter.getItem(position);
        if (sample == null) {
            Log.e(LOG_TAG, "Invalid position = " + position);
            return; // early exit
        }

        switch (sample) {
        case SLIDE_DIAL_PAD: {
            View bullet = view.findViewById(R.id.bullet);
            ViewCompat.setTransitionName(bullet, getString(R.string.shared_view_bullet));
            ActivityOptionsCompat options = AnimUtils.makeSharedViewOptions(this, bullet);
            ActivityCompat.startActivity(this, new Intent(this, DialPadActivity.class), options.toBundle());
        }
            break;
        case CONTACT_DETAILS: {
            ActivityCompat.startActivity(this, new Intent(this, ContactListActivity.class), null);
            overridePendingTransition(R.anim.slide_in_start_activity, R.anim.slide_out_start_activity);
        }
            break;
        case REVEAL_FROM_FAB: {
            View bullet = view.findViewById(R.id.bullet);
            ViewCompat.setTransitionName(bullet, getString(R.string.shared_view_bullet));
            ActivityOptionsCompat options = AnimUtils.makeSharedViewOptions(this, bullet);
            ActivityCompat.startActivity(this, new Intent(this, RevealListActivity.class), options.toBundle());
        }
            break;
        default:
            Log.w(LOG_TAG, "Unsupported sample type. Sample = " + sample);
            break;
        }
    }
}