cylonu87 / MaterialPreference

A library designed to replace default preferences on Android framework with something beauty.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Material Preference Download

A library designed for people who love simplicity. Hate the old preference style? Try this library.

It combines libraries from androidx.preference and net.xpece.android.support.preference. Available from API 17.
Google Play


Screenshots

Material Preference Material Preference DatePreference ListPreference

Note

This library is available in 2 versions:

  1. Version 2.x.x, built in Java
  2. Version 3.x.x and higher, built in Kotlin

This Java library will be the second priority. So I will be more active in Kotlin library. You can fork this Java branch and build your own version if you feel it is slow in maintenance.

Writing code in Java is slow, and that's why I decided to migrate to Kotlin.

Usage

dependencies {
    implementation 'com.anggrayudi:materialpreference-java:2.2.0'
}

Note: If you encounter error Failed to resolve com.anggrayudi:materialpreference-java:x.x.x, then add the following config:

repositories {
    maven { url 'https://dl.bintray.com/anggrayudi/maven/' }
}

From your preferences.xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- To make Preferences floating, you must wrap them inside PreferenceCategory -->
    <PreferenceCategory>
        <Preference
            android:key="about"
            android:title="About"
            android:icon="@drawable/..."
            app:tintIcon="?colorAccent"
            app:legacySummary="false"/>
    </PreferenceCategory>
</PreferenceScreen>

From your SettingsFragment:

public class SettingsFragment extends PreferenceFragmentMaterial {
    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.preferences); 
    }

    public static SettingsFragment newInstance(String rootKey) {
        Bundle args = new Bundle();
        args.putString(ARG_PREFERENCE_ROOT, rootKey);
        SettingsFragment fragment = new SettingsFragment();
        fragment.setArguments(args);
        return fragment; 
    }
}

From your SettingsActivity:

public class SettingsActivity extends PreferenceActivityMaterial {

    private SettingsFragment mSettingsFragment;
    private static final String TAG = "SettingsFragment.YOUR_TAG";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        
        if (savedInstanceState == null) {
            mSettingsFragment = SettingsFragment.newInstance(null);
            getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mSettingsFragment, TAG).commit();
        } else {
            // refresh this activity's title
            onBackStackChanged();
        }
    }

    @Override
    protected PreferenceFragmentMaterial onBuildPreferenceFragment(String rootKey) {
        return SettingsFragment.newInstance(rootKey);
    }

    @Override
    public void onBackStackChanged() {
        mSettingsFragment = (SettingsFragment) getSupportFragmentManager().findFragmentByTag(TAG);
        setTitle(mSettingsFragment.getPreferenceFragmentTitle());
    }
}

Preferences

  • Preference
  • CheckBoxPreference
  • SwitchPreference
  • EditTextPreference
  • ListPreference
  • MultiSelectListPreference
  • SeekBarDialogPreference
  • SeekBarPreference
  • RingtonePreference
  • IndicatorPreference
  • DatePreference
  • TimePreference
  • FolderPreference (requires API 21)

RingtonePreference

RingtonePreference will show only system ringtone sounds by default. If you want to include sounds from the external storage your app needs to request android.permission.READ_EXTERNAL_STORAGE permission in its manifest. Don't forget to check this runtime permission before opening ringtone picker on API 23.

Donation

Any donation you give is really helpful for us to develop this library. It feels like energy from power stone.

Donate with PayPal

License

Copyright 2018-2019 Anggrayudi Hardiannicko A.

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.

About

A library designed to replace default preferences on Android framework with something beauty.

License:Apache License 2.0


Languages

Language:Java 100.0%