Merge "Create SettingsTransitionActivity" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2305704ba5
@@ -32,7 +32,7 @@ android_library {
|
||||
"src/**/*.kt",
|
||||
],
|
||||
|
||||
min_sdk_version: "21",
|
||||
min_sdk_version: "29",
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,4 +18,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.settingslib">
|
||||
|
||||
<uses-sdk android:minSdkVersion="29" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -17,9 +17,10 @@ android_library {
|
||||
"androidx.annotation_annotation",
|
||||
"androidx.core_core",
|
||||
"com.google.android.material_material",
|
||||
"SettingsLibSettingsTransition",
|
||||
],
|
||||
sdk_version: "system_current",
|
||||
min_sdk_version: "21",
|
||||
min_sdk_version: "29",
|
||||
apex_available: [
|
||||
"//apex_available:platform",
|
||||
"com.android.cellbroadcast",
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.settingslib.collapsingtoolbar">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" />
|
||||
<uses-sdk android:minSdkVersion="29" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/content_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:transitionGroup="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
@@ -47,6 +46,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="?android:attr/actionBarTheme"
|
||||
android:transitionName="shared_element_view"
|
||||
app:layout_collapseMode="pin"/>
|
||||
|
||||
</com.android.settingslib.collapsingtoolbar.AdjustableToolbarLayout>
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
|
||||
@@ -32,9 +31,10 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
* A base Activity that has a collapsing toolbar layout is used for the activities intending to
|
||||
* enable the collapsing toolbar function.
|
||||
*/
|
||||
public class CollapsingToolbarBaseActivity extends FragmentActivity {
|
||||
public class CollapsingToolbarBaseActivity extends SettingsTransitionActivity {
|
||||
|
||||
private CollapsingToolbarLayout mCollapsingToolbarLayout;
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -43,8 +43,8 @@ public class CollapsingToolbarBaseActivity extends FragmentActivity {
|
||||
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
||||
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
||||
|
||||
final Toolbar toolbar = findViewById(R.id.action_bar);
|
||||
setActionBar(toolbar);
|
||||
mToolbar = findViewById(R.id.action_bar);
|
||||
setActionBar(mToolbar);
|
||||
|
||||
// Enable title and home button by default
|
||||
final ActionBar actionBar = getActionBar();
|
||||
@@ -98,6 +98,11 @@ public class CollapsingToolbarBaseActivity extends FragmentActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Toolbar getToolbar() {
|
||||
return mToolbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of collapsing toolbar.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* 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.android.settingslib.collapsingtoolbar;
|
||||
|
||||
import android.app.ActivityOptions;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
|
||||
/**
|
||||
* A base Activity for Settings-specific page transition. Activities extending it will get
|
||||
* Settings transition applied.
|
||||
*/
|
||||
public abstract class SettingsTransitionActivity extends FragmentActivity {
|
||||
private static final String TAG = "SettingsTransitionActivity";
|
||||
private static final int DEFAULT_REQUEST = -1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
|
||||
SettingsTransitionHelper.applyForwardTransition(this);
|
||||
SettingsTransitionHelper.applyBackwardTransition(this);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
super.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
final Toolbar toolbar = getToolbar();
|
||||
if (toolbar == null) {
|
||||
Log.w(TAG, "Toolbar is null. Cannot apply settings transition!");
|
||||
super.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
super.startActivity(intent, getActivityOptionsBundle(toolbar));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent, @Nullable Bundle options) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
super.startActivity(intent, options);
|
||||
return;
|
||||
}
|
||||
final Toolbar toolbar = getToolbar();
|
||||
if (toolbar == null) {
|
||||
Log.w(TAG, "Toolbar is null. Cannot apply settings transition!");
|
||||
super.startActivity(intent, options);
|
||||
return;
|
||||
}
|
||||
super.startActivity(intent, getActivityOptionsBundle(toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || requestCode == DEFAULT_REQUEST) {
|
||||
super.startActivityForResult(intent, requestCode);
|
||||
return;
|
||||
}
|
||||
|
||||
final Toolbar toolbar = getToolbar();
|
||||
if (toolbar == null) {
|
||||
Log.w(TAG, "Toolbar is null. Cannot apply settings transition!");
|
||||
super.startActivityForResult(intent, requestCode);
|
||||
return;
|
||||
}
|
||||
super.startActivityForResult(intent, requestCode, getActivityOptionsBundle(toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || requestCode == DEFAULT_REQUEST) {
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
return;
|
||||
}
|
||||
|
||||
final Toolbar toolbar = getToolbar();
|
||||
if (toolbar == null) {
|
||||
Log.w(TAG, "Toolbar is null. Cannot apply settings transition!");
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
return;
|
||||
}
|
||||
super.startActivityForResult(intent, requestCode, getActivityOptionsBundle(toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
final int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
// Make the up button behave the same as the back button.
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this method and return their {@link Toolbar}.
|
||||
*/
|
||||
public abstract Toolbar getToolbar();
|
||||
|
||||
private Bundle getActivityOptionsBundle(Toolbar toolbar) {
|
||||
return ActivityOptions.makeSceneTransitionAnimation(this, toolbar,
|
||||
"shared_element_view").toBundle();
|
||||
}
|
||||
}
|
||||
@@ -18,5 +18,10 @@ android_library {
|
||||
],
|
||||
|
||||
sdk_version: "system_current",
|
||||
min_sdk_version: "21",
|
||||
min_sdk_version: "29",
|
||||
apex_available: [
|
||||
"//apex_available:platform",
|
||||
"com.android.cellbroadcast",
|
||||
"com.android.permission",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.settingslib.transition">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" />
|
||||
<uses-sdk android:minSdkVersion="29" />
|
||||
|
||||
</manifest>
|
||||
|
||||
Reference in New Issue
Block a user