net.gsantner.opoc.util.ContextUtils Java Examples

The following examples show how to use net.gsantner.opoc.util.ContextUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example #2
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example #3
Source File: SettingsMasterFragment.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    super.onPreferenceTreeClick(preference);
    HomeActivity homeActivity = HomeActivity._launcher;
    int key = new ContextUtils(homeActivity).getResId(ContextUtils.ResType.STRING, preference.getKey());
    switch (key) {
        case R.string.pref_key__cat_hide_apps:
            Intent intent = new Intent(getActivity(), HideAppsActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(intent);
            return true;
        case R.string.pref_key__cat_about:
            startActivity(new Intent(getActivity(), MoreInfoActivity.class));
            return true;
    }

    return false;
}
 
Example #4
Source File: SettingsActivity.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
public void onCreate(Bundle b) {
    // must be applied before setContentView
    super.onCreate(b);
    ContextUtils contextUtils = new ContextUtils(this);
    contextUtils.setAppLanguage(_appSettings.getLanguage());

    setContentView(R.layout.activity_settings);
    ButterKnife.bind(this);

    toolbar.setTitle(R.string.pref_title__settings);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white));
    toolbar.setNavigationOnClickListener(v -> onBackPressed());
    toolbar.setBackgroundColor(_appSettings.getPrimaryColor());

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.fragment_holder, new SettingsMasterFragment()).commit();

    // if system exit is called the app will open settings activity again
    // this pushes the user back out to the home activity
    if (_appSettings.getAppRestartRequired()) {
        startActivity(new Intent(this, HomeActivity.class));
    }
}
 
Example #5
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example #6
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
@Override
@Deprecated
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Activity activity = getActivity();
    _appSettings = getAppSettings(activity);
    _cu = new ContextUtils(activity);
    getPreferenceManager().setSharedPreferencesName(getSharedPreferencesName());
    addPreferencesFromResource(getPreferenceResourceForInflation());


    if (activity != null && activity.getTheme() != null) {
        TypedArray array = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.colorBackground});
        int bgcolor = array.getColor(0, 0xFFFFFFFF);
        _defaultIconTintColor = _cu.shouldColorOnTopBeLight(bgcolor) ? Color.WHITE : Color.BLACK;
    }

    // on bottom
    afterOnCreate(savedInstanceState, activity);
}
 
Example #7
Source File: LanguagePreferenceCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
private void loadLangs(Context context, @Nullable AttributeSet attrs) {
    setDefaultValue(SYSTEM_LANGUAGE_CODE);

    // Fetch readable details
    ContextUtils contextUtils = new ContextUtils(context);
    List<String> languages = new ArrayList<>();
    Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
    if (bcof instanceof String[]) {
        for (String langId : (String[]) bcof) {
            Locale locale = contextUtils.getLocaleByAndroidCode(langId);
            languages.add(summarizeLocale(locale, langId) + ";" + langId);
        }
    }

    // Sort languages naturally
    Collections.sort(languages);

    // Show in UI
    String[] entries = new String[languages.size() + 2];
    String[] entryval = new String[languages.size() + 2];
    for (int i = 0; i < languages.size(); i++) {
        entries[i + 2] = languages.get(i).split(";")[0];
        entryval[i + 2] = languages.get(i).split(";")[1];
    }
    entryval[0] = SYSTEM_LANGUAGE_CODE;
    entries[0] = _systemLanguageName + " » " + summarizeLocale(ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0), "");
    entryval[1] = _defaultLanguageCode;
    entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode), _defaultLanguageCode);

    setEntries(entries);
    setEntryValues(entryval);
}
 
Example #8
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 5 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(Preference preference) {
    if (preference != null && !TextUtils.isEmpty(preference.getKey())) {
        return _cu.getResId(ContextUtils.ResType.STRING, preference.getKey());
    }
    return 0;
}
 
Example #9
Source File: LanguagePreferenceCompat.java    From kimai-android with MIT License 5 votes vote down vote up
@Override
public CharSequence getSummary() {
    Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
    String prefix = TextUtils.isEmpty(super.getSummary())
            ? "" : super.getSummary() + "\n\n";
    return prefix + summarizeLocale(locale, getValue());
}
 
Example #10
Source File: LanguagePreferenceCompat.java    From kimai-android with MIT License 5 votes vote down vote up
private void loadLangs(Context context, @Nullable AttributeSet attrs) {
    setDefaultValue(SYSTEM_LANGUAGE_CODE);

    // Fetch readable details
    ContextUtils contextUtils = new ContextUtils(context);
    List<String> languages = new ArrayList<>();
    Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
    if (bcof instanceof String[]) {
        for (String langId : (String[]) bcof) {
            Locale locale = contextUtils.getLocaleByAndroidCode(langId);
            languages.add(summarizeLocale(locale, langId) + ";" + langId);
        }
    }

    // Sort languages naturally
    Collections.sort(languages);

    // Show in UI
    String[] entries = new String[languages.size() + 2];
    String[] entryval = new String[languages.size() + 2];
    for (int i = 0; i < languages.size(); i++) {
        entries[i + 2] = languages.get(i).split(";")[0];
        entryval[i + 2] = languages.get(i).split(";")[1];
    }
    entryval[0] = SYSTEM_LANGUAGE_CODE;
    entries[0] = _systemLanguageName + " » " + summarizeLocale(ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0), "");
    entryval[1] = _defaultLanguageCode;
    entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode), _defaultLanguageCode);

    setEntries(entries);
    setEntryValues(entryval);
}
 
Example #11
Source File: LanguagePreferenceCompat.java    From kimai-android with MIT License 5 votes vote down vote up
@Override
public boolean callChangeListener(Object newValue) {
    if (newValue instanceof String) {
        // Does not apply to existing UI, use recreate()
        new ContextUtils(getContext()).setAppLanguage((String) newValue);
    }
    return super.callChangeListener(newValue);
}
 
Example #12
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 5 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(Preference preference) {
    if (preference != null && !TextUtils.isEmpty(preference.getKey())) {
        return _cu.getResId(ContextUtils.ResType.STRING, preference.getKey());
    }
    return 0;
}
 
Example #13
Source File: LanguagePreferenceCompat.java    From Stringlate with MIT License 5 votes vote down vote up
@Override
public CharSequence getSummary() {
    Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
    String prefix = TextUtils.isEmpty(super.getSummary())
            ? "" : super.getSummary() + "\n\n";
    return prefix + summarizeLocale(locale, getValue());
}
 
Example #14
Source File: LanguagePreferenceCompat.java    From Stringlate with MIT License 5 votes vote down vote up
private void loadLangs(Context context, @Nullable AttributeSet attrs) {
    setDefaultValue(SYSTEM_LANGUAGE_CODE);

    // Fetch readable details
    ContextUtils contextUtils = new ContextUtils(context);
    List<String> languages = new ArrayList<>();
    Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
    if (bcof instanceof String[]) {
        for (String langId : (String[]) bcof) {
            Locale locale = contextUtils.getLocaleByAndroidCode(langId);
            languages.add(summarizeLocale(locale, langId) + ";" + langId);
        }
    }

    // Sort languages naturally
    Collections.sort(languages);

    // Show in UI
    String[] entries = new String[languages.size() + 2];
    String[] entryval = new String[languages.size() + 2];
    for (int i = 0; i < languages.size(); i++) {
        entries[i + 2] = languages.get(i).split(";")[0];
        entryval[i + 2] = languages.get(i).split(";")[1];
    }
    entryval[0] = SYSTEM_LANGUAGE_CODE;
    entries[0] = _systemLanguageName + " » " + summarizeLocale(context.getResources().getConfiguration().locale, "");
    entryval[1] = _defaultLanguageCode;
    entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode), _defaultLanguageCode);

    setEntries(entries);
    setEntryValues(entryval);
}
 
Example #15
Source File: LanguagePreferenceCompat.java    From Stringlate with MIT License 5 votes vote down vote up
@Override
public boolean callChangeListener(Object newValue) {
    if (newValue instanceof String) {
        // Does not apply to existing UI, use recreate()
        new ContextUtils(getContext()).setAppLanguage((String) newValue);
    }
    return super.callChangeListener(newValue);
}
 
Example #16
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(Preference preference) {
    if (preference != null && !TextUtils.isEmpty(preference.getKey())) {
        return _cu.getResId(ContextUtils.ResType.STRING, preference.getKey());
    }
    return 0;
}
 
Example #17
Source File: LanguagePreferenceCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence getSummary() {
    Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
    String prefix = TextUtils.isEmpty(super.getSummary())
            ? "" : super.getSummary() + "\n\n";
    return prefix + summarizeLocale(locale, getValue());
}
 
Example #18
Source File: LanguagePreferenceCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
private void loadLangs(Context context, @Nullable AttributeSet attrs) {
    setDefaultValue(SYSTEM_LANGUAGE_CODE);

    // Fetch readable details
    ContextUtils contextUtils = new ContextUtils(context);
    List<String> languages = new ArrayList<>();
    Object bcof = contextUtils.getBuildConfigValue("DETECTED_ANDROID_LOCALES");
    if (bcof instanceof String[]) {
        for (String langId : (String[]) bcof) {
            Locale locale = contextUtils.getLocaleByAndroidCode(langId);
            languages.add(summarizeLocale(locale, langId) + ";" + langId);
        }
    }

    // Sort languages naturally
    Collections.sort(languages);

    // Show in UI
    String[] entries = new String[languages.size() + 2];
    String[] entryval = new String[languages.size() + 2];
    for (int i = 0; i < languages.size(); i++) {
        entries[i + 2] = languages.get(i).split(";")[0];
        entryval[i + 2] = languages.get(i).split(";")[1];
    }
    entryval[0] = SYSTEM_LANGUAGE_CODE;
    entries[0] = _systemLanguageName + " » " + summarizeLocale(ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0), "");
    entryval[1] = _defaultLanguageCode;
    entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode), _defaultLanguageCode);

    setEntries(entries);
    setEntryValues(entryval);
}
 
Example #19
Source File: LanguagePreferenceCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean callChangeListener(Object newValue) {
    if (newValue instanceof String) {
        // Does not apply to existing UI, use recreate()
        new ContextUtils(getContext()).setAppLanguage((String) newValue);
    }
    return super.callChangeListener(newValue);
}
 
Example #20
Source File: HomeActivity.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
protected void onCreate(@Nullable Bundle savedInstanceState) {
    Companion.setLauncher(this);
    AndroidThreeTen.init(this);

    AppSettings appSettings = AppSettings.get();

    ContextUtils contextUtils = new ContextUtils(getApplicationContext());
    contextUtils.setAppLanguage(appSettings.getLanguage());
    super.onCreate(savedInstanceState);
    if (!Setup.wasInitialised()) {
        Setup.init(new HpInitSetup(this));
    }

    Companion.setLauncher(this);
    _db = Setup.dataManager();

    setContentView(getLayoutInflater().inflate(R.layout.activity_home, null));

    // transparent status and navigation
    if (VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        View decorView = window.getDecorView();
        decorView.setSystemUiVisibility(1536);
    }

    init();
}
 
Example #21
Source File: SettingsDesktopFragment.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    HomeActivity homeActivity = HomeActivity._launcher;
    int key = new ContextUtils(homeActivity).getResId(ContextUtils.ResType.STRING, preference.getKey());
    switch (key) {
        case R.string.pref_key__minibar:
            LauncherAction.RunAction(LauncherAction.Action.EditMinibar, getActivity());
            return true;
    }
    return false;
}
 
Example #22
Source File: SettingsAppearanceFragment.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    HomeActivity homeActivity = HomeActivity._launcher;
    int key = new ContextUtils(homeActivity).getResId(ContextUtils.ResType.STRING, preference.getKey());
    switch (key) {
        case R.string.pref_key__icon_pack:
            DialogHelper.startPickIconPackIntent(getActivity());
            return true;
    }
    return false;
}
 
Example #23
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(Preference preference) {
    if (preference != null && !TextUtils.isEmpty(preference.getKey())) {
        return _cu.getResId(ContextUtils.ResType.STRING, preference.getKey());
    }
    return 0;
}
 
Example #24
Source File: LanguagePreferenceCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CharSequence getSummary() {
    Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
    String prefix = TextUtils.isEmpty(super.getSummary())
            ? "" : super.getSummary() + "\n\n";
    return prefix + summarizeLocale(locale, getValue());
}
 
Example #25
Source File: LanguagePreferenceCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean callChangeListener(Object newValue) {
    if (newValue instanceof String) {
        // Does not apply to existing UI, use recreate()
        new ContextUtils(getContext()).setAppLanguage((String) newValue);
    }
    return super.callChangeListener(newValue);
}
 
Example #26
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 2 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(String keyAsString) {
    return _cu.getResId(ContextUtils.ResType.STRING, keyAsString);
}
 
Example #27
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 2 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(String keyAsString) {
    return _cu.getResId(ContextUtils.ResType.STRING, keyAsString);
}
 
Example #28
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(String keyAsString) {
    return _cu.getResId(ContextUtils.ResType.STRING, keyAsString);
}
 
Example #29
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 2 votes vote down vote up
/**
 * Try to fetch string resource id from key
 * This only works if the key is only defined once and value=key
 */
protected int keyToStringResId(String keyAsString) {
    return _cu.getResId(ContextUtils.ResType.STRING, keyAsString);
}