Search in sources :

Example 11 with FeatureFactory

use of com.android.settings.overlay.FeatureFactory in project android_packages_apps_Settings by omnirom.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    long startTime = System.currentTimeMillis();
    final FeatureFactory factory = FeatureFactory.getFactory(this);
    mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
    mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
    // Should happen before any call to getIntent()
    getMetaData();
    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }
    mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
    mAppPreferences = getSharedPreferences(APP_PREFERENCES_NAME, Context.MODE_PRIVATE);
    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
    mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
    final ComponentName cn = intent.getComponent();
    final String className = cn.getClassName();
    mIsShowingDashboard = className.equals(Settings.class.getName());
    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = this instanceof SubSettings || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
    // insets
    if (isSubSettings) {
        setTheme(R.style.Theme_SubSettings);
    }
    setContentView(mIsShowingDashboard ? R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
    mContent = findViewById(R.id.main_content);
    getFragmentManager().addOnBackStackChangedListener(this);
    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.
        setTitleFromIntent(intent);
        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }
        mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
    } else {
        launchSettingFragment(initialFragmentName, isSubSettings, intent);
    }
    if (mIsShowingDashboard) {
        findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
        findViewById(R.id.action_bar).setVisibility(View.GONE);
        Toolbar toolbar = findViewById(R.id.search_action_bar);
        toolbar.setOnClickListener(this);
        setActionBar(toolbar);
        // Please forgive me for what I am about to do.
        // 
        // Need to make the navigation icon non-clickable so that the entire card is clickable
        // and goes to the search UI. Also set the background to null so there's no ripple.
        View navView = toolbar.getNavigationView();
        navView.setClickable(false);
        navView.setBackground(null);
    }
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
        actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
    }
    mSwitchBar = findViewById(R.id.switch_bar);
    if (mSwitchBar != null) {
        mSwitchBar.setMetricsTag(getMetricsTag());
    }
    // see if we should show Back/Next buttons
    if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
        View buttonBar = findViewById(R.id.button_bar);
        if (buttonBar != null) {
            buttonBar.setVisibility(View.VISIBLE);
            Button backButton = (Button) findViewById(R.id.back_button);
            backButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_CANCELED, null);
                    finish();
                }
            });
            Button skipButton = (Button) findViewById(R.id.skip_button);
            skipButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_OK, null);
                    finish();
                }
            });
            mNextButton = (Button) findViewById(R.id.next_button);
            mNextButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_OK, null);
                    finish();
                }
            });
            // set our various button parameters
            if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    mNextButton.setVisibility(View.GONE);
                } else {
                    mNextButton.setText(buttonText);
                }
            }
            if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    backButton.setVisibility(View.GONE);
                } else {
                    backButton.setText(buttonText);
                }
            }
            if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
                skipButton.setVisibility(View.VISIBLE);
            }
        }
    }
    if (DEBUG_TIMING) {
        Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Intent(android.content.Intent) View(android.view.View) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) ComponentName(android.content.ComponentName) ActionBar(android.app.ActionBar) FeatureFactory(com.android.settings.overlay.FeatureFactory) Toolbar(android.widget.Toolbar)

Example 12 with FeatureFactory

use of com.android.settings.overlay.FeatureFactory in project android_packages_apps_Settings by omnirom.

the class AutomaticStorageManagerSwitchBarControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mSwitchBar = new SwitchBar(mContext);
    Context fakeContextForFakeProvider = mock(Context.class, RETURNS_DEEP_STUBS);
    FakeFeatureFactory.setupForTest(fakeContextForFakeProvider);
    FeatureFactory featureFactory = FakeFeatureFactory.getFactory(fakeContextForFakeProvider);
    mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
    mPreference = new Preference(mContext);
    mController = new AutomaticStorageManagerSwitchBarController(mContext, mSwitchBar, mMetricsFeatureProvider, mPreference, mFragmentManager);
}
Also used : SwitchBar(com.android.settings.widget.SwitchBar) Context(android.content.Context) Preference(android.support.v7.preference.Preference) FeatureFactory(com.android.settings.overlay.FeatureFactory) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Example 13 with FeatureFactory

use of com.android.settings.overlay.FeatureFactory in project android_packages_apps_Settings by DirtyUnicorns.

the class AutomaticStorageManagementSwitchPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application.getApplicationContext();
    FeatureFactory factory = FeatureFactory.getFactory(mContext);
    mMetricsFeature = factory.getMetricsFeatureProvider();
    mController = new AutomaticStorageManagementSwitchPreferenceController(mContext, mMetricsFeature, mFragmentManager);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
Also used : FeatureFactory(com.android.settings.overlay.FeatureFactory) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Example 14 with FeatureFactory

use of com.android.settings.overlay.FeatureFactory in project android_packages_apps_Settings by DirtyUnicorns.

the class AutomaticStorageManagerSwitchBarControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mSwitchBar = new SwitchBar(mContext);
    Context fakeContextForFakeProvider = mock(Context.class, RETURNS_DEEP_STUBS);
    FakeFeatureFactory.setupForTest(fakeContextForFakeProvider);
    FeatureFactory featureFactory = FakeFeatureFactory.getFactory(fakeContextForFakeProvider);
    mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
    mPreference = new Preference(mContext);
    mController = new AutomaticStorageManagerSwitchBarController(mContext, mSwitchBar, mMetricsFeatureProvider, mPreference, mFragmentManager);
}
Also used : SwitchBar(com.android.settings.widget.SwitchBar) Context(android.content.Context) Preference(android.support.v7.preference.Preference) FeatureFactory(com.android.settings.overlay.FeatureFactory) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Before(org.junit.Before)

Example 15 with FeatureFactory

use of com.android.settings.overlay.FeatureFactory in project android_packages_apps_Settings by crdroidandroid.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    long startTime = System.currentTimeMillis();
    final FeatureFactory factory = FeatureFactory.getFactory(this);
    mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
    mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
    // Should happen before any call to getIntent()
    getMetaData();
    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }
    mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE);
    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
    mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
    final ComponentName cn = intent.getComponent();
    final String className = cn.getClassName();
    mIsShowingDashboard = className.equals(Settings.class.getName());
    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = this instanceof SubSettings || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
    // insets
    if (isSubSettings) {
        setTheme(R.style.Theme_SubSettings);
    }
    setContentView(mIsShowingDashboard ? R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
    mContent = findViewById(R.id.main_content);
    getFragmentManager().addOnBackStackChangedListener(this);
    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.
        setTitleFromIntent(intent);
        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }
        mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
    } else {
        launchSettingFragment(initialFragmentName, isSubSettings, intent);
    }
    if (mIsShowingDashboard) {
        findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
        findViewById(R.id.action_bar).setVisibility(View.GONE);
        Toolbar toolbar = findViewById(R.id.search_action_bar);
        toolbar.setOnClickListener(this);
        setActionBar(toolbar);
        // Please forgive me for what I am about to do.
        // 
        // Need to make the navigation icon non-clickable so that the entire card is clickable
        // and goes to the search UI. Also set the background to null so there's no ripple.
        View navView = toolbar.getNavigationView();
        navView.setClickable(false);
        navView.setBackground(null);
    }
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
        actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
    }
    mSwitchBar = findViewById(R.id.switch_bar);
    if (mSwitchBar != null) {
        mSwitchBar.setMetricsTag(getMetricsTag());
    }
    // see if we should show Back/Next buttons
    if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
        View buttonBar = findViewById(R.id.button_bar);
        if (buttonBar != null) {
            buttonBar.setVisibility(View.VISIBLE);
            Button backButton = (Button) findViewById(R.id.back_button);
            backButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_CANCELED, null);
                    finish();
                }
            });
            Button skipButton = (Button) findViewById(R.id.skip_button);
            skipButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_OK, null);
                    finish();
                }
            });
            mNextButton = (Button) findViewById(R.id.next_button);
            mNextButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    setResult(RESULT_OK, null);
                    finish();
                }
            });
            // set our various button parameters
            if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    mNextButton.setVisibility(View.GONE);
                } else {
                    mNextButton.setText(buttonText);
                }
            }
            if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    backButton.setVisibility(View.GONE);
                } else {
                    backButton.setText(buttonText);
                }
            }
            if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
                skipButton.setVisibility(View.VISIBLE);
            }
        }
    }
    if (DEBUG_TIMING) {
        Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Intent(android.content.Intent) View(android.view.View) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) ComponentName(android.content.ComponentName) ActionBar(android.app.ActionBar) FeatureFactory(com.android.settings.overlay.FeatureFactory) Toolbar(android.widget.Toolbar)

Aggregations

FeatureFactory (com.android.settings.overlay.FeatureFactory)19 FakeFeatureFactory (com.android.settings.testutils.FakeFeatureFactory)12 Before (org.junit.Before)12 ActionBar (android.app.ActionBar)7 Intent (android.content.Intent)7 View (android.view.View)7 Button (android.widget.Button)7 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)7 ComponentName (android.content.ComponentName)6 Context (android.content.Context)6 Preference (android.support.v7.preference.Preference)6 OnClickListener (android.view.View.OnClickListener)6 Toolbar (android.widget.Toolbar)6 SwitchBar (com.android.settings.widget.SwitchBar)6