Java tutorial
/* * 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.frame.uikit.base.title; import android.app.Activity; import android.content.Intent; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import com.unovo.frame.R; import com.unovo.frame.uikit.base.container.ContainerActivity; import com.unovo.frame.uikit.widget.TitleBar; /** * Created by Aeatho on 2016/12/28 13:27 * * Prject: unovo-guest-app * Description: * email: aeatho@gmail.com */ public final class SimpleBackActivity extends ContainerActivity { private static final String FRAGMENT_NAME = "fragmentName"; private static final String FRAGMENT_ARGS = "fragmentArgs"; protected TitleBar mTitleBar; protected FrameLayout mContainer; /** * * 1?toolbar?? * 2?toolbar? */ private static int[] ATTRS = { R.attr.toolBarOverly, R.attr.actionBarSize, R.attr.toolBarVisible }; /** * ?? */ public static void launch(Activity activity, Class<? extends Fragment> clazz) { launch(activity, clazz, null); } public static void launch(Fragment fragment, Class<? extends Fragment> clazz) { launch(fragment, clazz); } public static void launch(Activity activity, Class<? extends Fragment> clazz, Bundle args) { Intent intent = new Intent(activity, SimpleBackActivity.class); intent.putExtra(FRAGMENT_NAME, clazz.getName()); if (args != null) intent.putExtra(FRAGMENT_ARGS, args); activity.startActivity(intent); } public static void launch4Result(Fragment fragment, Class<? extends Fragment> clazz, Bundle args, int requestCode) { if (fragment.getActivity() == null) return; Activity activity = fragment.getActivity(); Intent intent = new Intent(activity, SimpleBackActivity.class); intent.putExtra(FRAGMENT_NAME, clazz.getName()); if (args != null) intent.putExtra(FRAGMENT_ARGS, args); fragment.startActivityForResult(intent, requestCode); } @Override protected int getLayoutId() { return R.layout.activity_simpleback; } @Override protected void initWindow() { super.initWindow(); mTitleBar = (TitleBar) findViewById(R.id.titlebar); mContainer = (FrameLayout) findViewById(R.id.fragmentContainer); initContainerViewByAttrs(); mTitleBar.setOnTitleBarClickListener(listener); } @SuppressWarnings("all") private void initContainerViewByAttrs() { TypedArray typedArray = getTheme().obtainStyledAttributes(ATTRS); boolean visible = typedArray.getBoolean(2, true); if (visible) { boolean overly = typedArray.getBoolean(0, false); // ?toolbar int toolBarSize = (int) typedArray.getDimension(1, (int) mContext.getResources().getDimension(R.dimen.titlebar_size)); typedArray.recycle(); // ???? FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); params.topMargin = overly ? 0 : toolBarSize; mContainer.setLayoutParams(params); } else { mTitleBar.setVisibility(View.GONE); } } public TitleBar getTitleBar() { return mTitleBar; } private TitleBar.OnTitleBarClickListener listener = new TitleBar.OnTitleBarClickListener() { @Override public void onClickLeftCtv() { onBackClick(); } @Override public void onClickTitleCtv() { onTitleClick(); } @Override public void onClickRightCtv() { onMenuClick(); } }; }