Merge "Support contextual suggestion"
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
/** Interface should be implemented if you have added new suggestions */
|
||||
public interface SuggestionFeatureProvider {
|
||||
@@ -42,4 +43,9 @@ public interface SuggestionFeatureProvider {
|
||||
* Returns the {@link SharedPreferences} that holds metadata for suggestions.
|
||||
*/
|
||||
SharedPreferences getSharedPrefs(Context context);
|
||||
|
||||
/**
|
||||
* Returns the class of {@link Fragment} that supports contextual suggestion.
|
||||
*/
|
||||
Class<? extends Fragment> getContextualSuggestionFragment();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollSuggestionActivity;
|
||||
@@ -86,6 +87,11 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
return context.getSharedPreferences(SHARED_PREF_FILENAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Fragment> getContextualSuggestionFragment() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SuggestionFeatureProviderImpl(Context context) {
|
||||
final Context appContext = context.getApplicationContext();
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.app.ActivityManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
@@ -41,6 +42,9 @@ import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class SettingsHomepageActivity extends FragmentActivity {
|
||||
|
||||
private static final String TAG = "SettingsHomepageActivity";
|
||||
private int mSearchBoxHeight;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -50,7 +54,9 @@ public class SettingsHomepageActivity extends FragmentActivity {
|
||||
root.setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
|
||||
setHomepageContainerPaddingTop();
|
||||
final View appBar = findViewById(R.id.app_bar_container);
|
||||
appBar.setMinimumHeight(getSearchBoxHeight());
|
||||
setDefaultHomepageContainerPaddingTop();
|
||||
|
||||
final Toolbar toolbar = findViewById(R.id.search_action_bar);
|
||||
FeatureFactory.getFactory(this).getSearchFeatureProvider()
|
||||
@@ -60,16 +66,36 @@ public class SettingsHomepageActivity extends FragmentActivity {
|
||||
getLifecycle().addObserver(new AvatarViewMixin(this, avatarView));
|
||||
getLifecycle().addObserver(new HideNonSystemOverlayMixin(this));
|
||||
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.CONTEXTUAL_HOME)
|
||||
&& !getSystemService(ActivityManager.class).isLowRamDevice()) {
|
||||
// Only allow contextual feature on high ram devices.
|
||||
showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
|
||||
if (!getSystemService(ActivityManager.class).isLowRamDevice()) {
|
||||
// Only allow contextual features on high ram devices.
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME)) {
|
||||
showSuggestionFragment();
|
||||
}
|
||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.CONTEXTUAL_HOME)) {
|
||||
showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
|
||||
}
|
||||
}
|
||||
showFragment(new TopLevelSettings(), R.id.main_content);
|
||||
((FrameLayout) findViewById(R.id.main_content))
|
||||
.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
|
||||
}
|
||||
|
||||
private void showSuggestionFragment() {
|
||||
final Class<? extends Fragment> fragment = FeatureFactory.getFactory(this)
|
||||
.getSuggestionFeatureProvider(this).getContextualSuggestionFragment();
|
||||
if (fragment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
showFragment(fragment.newInstance(), R.id.contextual_suggestion_content);
|
||||
setHomepageContainerTopOffset(getResources()
|
||||
.getDimensionPixelSize(R.dimen.suggestion_height));
|
||||
} catch (IllegalAccessException | InstantiationException e) {
|
||||
Log.w(TAG, "Cannot show fragment", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showFragment(Fragment fragment, int id) {
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
@@ -84,18 +110,32 @@ public class SettingsHomepageActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setHomepageContainerPaddingTop() {
|
||||
final View view = this.findViewById(R.id.homepage_container);
|
||||
|
||||
final int searchBarHeight = getResources().getDimensionPixelSize(R.dimen.search_bar_height);
|
||||
final int searchBarMargin = getResources().getDimensionPixelSize(R.dimen.search_bar_margin);
|
||||
|
||||
// The top padding is the height of action bar(48dp) + top/bottom margins(16dp)
|
||||
final int paddingTop = searchBarHeight + searchBarMargin * 2;
|
||||
void setHomepageContainerTopOffset(int offset) {
|
||||
final View view = findViewById(R.id.homepage_container);
|
||||
final int paddingTop = getSearchBoxHeight() + offset;
|
||||
view.setPadding(0 /* left */, paddingTop, 0 /* right */, 0 /* bottom */);
|
||||
|
||||
// Prevent inner RecyclerView gets focus and invokes scrolling.
|
||||
view.setFocusableInTouchMode(true);
|
||||
view.requestFocus();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setDefaultHomepageContainerPaddingTop() {
|
||||
setHomepageContainerTopOffset(0);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getSearchBoxHeight() {
|
||||
if (mSearchBoxHeight != 0) {
|
||||
return mSearchBoxHeight;
|
||||
}
|
||||
|
||||
final int searchBarHeight = getResources().getDimensionPixelSize(R.dimen.search_bar_height);
|
||||
final int searchBarMargin = getResources().getDimensionPixelSize(R.dimen.search_bar_margin);
|
||||
|
||||
// The height of search box is the height of search bar(48dp) + top/bottom margins(24dp)
|
||||
mSearchBoxHeight = searchBarHeight + searchBarMargin * 2;
|
||||
return mSearchBoxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user