com.unovo.apartment.ui.main.MainActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.unovo.apartment.ui.main.MainActivity.java

Source

/*
 * Copyright (c) 2016 ?. All Rights Reserved.
 * Use of this source code is governed by a Shanghai Unovo Information Technology Co.,Ltd license
 * that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.unovo.com.cn
 *
 * An additional intellectual property rights grant can be found
 * in the file PATENTS.  All contributing project authors may
 * be found in the AUTHORS file in the root of the source tree.
 *
 */

package com.unovo.apartment.ui.main;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.animation.LinearInterpolator;
import com.unovo.frame.uikit.base.BaseActivity;
import com.unovo.apartment.R;
import com.unovo.apartment.ui.main.nav.NavFragment;
import com.unovo.apartment.ui.main.nav.NavigationButton;
import com.unovo.apartment.ui.main.tab.OnTabReselectListener;

public class MainActivity extends BaseActivity implements NavFragment.OnNavigationReselectListener {
    public static final String ACTION_HOME = "ACTION_HOME";
    private static String EXTRA_KEY = "key";
    private NavFragment mNavBar;

    public static Intent getCallingIntent(Context context, String value) {
        Intent callingIntent = new Intent(context, MainActivity.class);
        callingIntent.putExtra(EXTRA_KEY, value);
        return callingIntent;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        FragmentManager manager = getSupportFragmentManager();
        mNavBar = ((NavFragment) manager.findFragmentById(R.id.fag_nav));
        mNavBar.setup(this, manager, R.id.main_container, this);
        mNavBar.select(1);

        checkUpdate();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        doNewIntent(getIntent(), true);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        doNewIntent(intent, false);
    }

    private void doNewIntent(Intent intent, boolean isCreate) {
        if (intent == null || intent.getAction() == null)
            return;
        String action = intent.getAction();
        if (action.equals(ACTION_HOME)) {
            NavFragment bar = mNavBar;
            if (bar != null) {
                bar.select(1);
            }
        }
    }

    @Override
    public void onReselect(NavigationButton navigationButton) {
        Fragment fragment = navigationButton.getFragment();
        if (fragment != null && fragment instanceof OnTabReselectListener) {
            OnTabReselectListener listener = (OnTabReselectListener) fragment;
            listener.onTabReselect();
        }
    }

    // ??tab
    public void toggleNavTabView(boolean isShowOrHide) {
        final View view = mNavBar.getView();
        if (view == null)
            return;
        // hide
        view.setVisibility(View.VISIBLE);
        if (!isShowOrHide) {
            view.animate().translationY(view.getHeight()).setDuration(180).setInterpolator(new LinearInterpolator())
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            view.setTranslationY(view.getHeight());
                            view.setVisibility(View.GONE);
                        }
                    });
        } else {
            view.animate().translationY(0).setDuration(180).setInterpolator(new LinearInterpolator())
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            // fix:bug > ???
                            view.setVisibility(View.VISIBLE);
                            view.setTranslationY(0);
                        }
                    });
        }
    }

    private void checkUpdate() {
        //if (!AppContext.get(AppConfig.KEY_CHECK_UPDATE, true)) {
        //  return;
        //}
        //CheckUpdateManager manager = new CheckUpdateManager(this, false);
        //manager.setCaller(this);
        //manager.checkUpdate();
    }

    @Override
    protected boolean initUMengEnable() {
        return false;
    }
}