Search in sources :

Example 1 with PreferenceViewHolder

use of android.support.v7.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ToggleFeaturePreferenceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    setPreferenceScreen(preferenceScreen);
    mSummaryPreference = new Preference(getPrefContext()) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder view) {
            super.onBindViewHolder(view);
            view.setDividerAllowedAbove(false);
            view.setDividerAllowedBelow(false);
            final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
            summaryView.setText(getSummary());
            sendAccessibilityEvent(summaryView);
        }

        private void sendAccessibilityEvent(View view) {
            // Since the view is still not attached we create, populate,
            // and send the event directly since we do not know when it
            // will be attached and posting commands is not as clean.
            AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
            if (accessibilityManager.isEnabled()) {
                AccessibilityEvent event = AccessibilityEvent.obtain();
                event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
                view.onInitializeAccessibilityEvent(event);
                view.dispatchPopulateAccessibilityEvent(event);
                accessibilityManager.sendAccessibilityEvent(event);
            }
        }
    };
    mSummaryPreference.setSelectable(false);
    mSummaryPreference.setPersistent(false);
    mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
    preferenceScreen.addPreference(mSummaryPreference);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) AccessibilityManager(android.view.accessibility.AccessibilityManager) Preference(android.support.v7.preference.Preference) TextView(android.widget.TextView) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) TextView(android.widget.TextView) View(android.view.View)

Example 2 with PreferenceViewHolder

use of android.support.v7.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiSettings method onAccessPointsChanged.

/**
     * Shows the latest access points available with supplemental information like
     * the strength of network and the security for it.
     */
@Override
public synchronized void onAccessPointsChanged() {
    // Safeguard from some delayed event handling
    if (getActivity() == null)
        return;
    if (isUiRestricted()) {
        if (!isUiRestrictedByOnlyAdmin()) {
            addMessagePreference(R.string.wifi_empty_list_user_restricted);
        }
        getPreferenceScreen().removeAll();
        return;
    }
    final int wifiState = mWifiManager.getWifiState();
    switch(wifiState) {
        case WifiManager.WIFI_STATE_ENABLED:
            // AccessPoints are automatically sorted with TreeSet.
            final Collection<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
            boolean hasAvailableAccessPoints = false;
            int index = 0;
            cacheRemoveAllPrefs(getPreferenceScreen());
            for (AccessPoint accessPoint : accessPoints) {
                // Ignore access points that are out of range.
                if (accessPoint.getLevel() != -1) {
                    String key = accessPoint.getBssid();
                    if (TextUtils.isEmpty(key)) {
                        key = accessPoint.getSsidStr();
                    }
                    hasAvailableAccessPoints = true;
                    LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
                    if (pref != null) {
                        pref.setOrder(index++);
                        continue;
                    }
                    LongPressAccessPointPreference preference = new LongPressAccessPointPreference(accessPoint, getPrefContext(), mUserBadgeCache, false, R.drawable.ic_wifi_signal_0, this);
                    preference.setKey(key);
                    preference.setOrder(index++);
                    if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && !accessPoint.isSaved() && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
                        onPreferenceTreeClick(preference);
                        mOpenSsid = null;
                    }
                    getPreferenceScreen().addPreference(preference);
                    accessPoint.setListener(this);
                    preference.refresh();
                }
            }
            removeCachedPrefs(getPreferenceScreen());
            if (!hasAvailableAccessPoints) {
                setProgressBarVisible(true);
                Preference pref = new Preference(getContext()) {

                    @Override
                    public void onBindViewHolder(PreferenceViewHolder holder) {
                        super.onBindViewHolder(holder);
                        // Show a line on each side of add network.
                        holder.setDividerAllowedBelow(true);
                    }
                };
                pref.setSelectable(false);
                pref.setSummary(R.string.wifi_empty_list_wifi_on);
                pref.setOrder(0);
                pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
                getPreferenceScreen().addPreference(pref);
                mAddPreference.setOrder(1);
                getPreferenceScreen().addPreference(mAddPreference);
            } else {
                mAddPreference.setOrder(index++);
                getPreferenceScreen().addPreference(mAddPreference);
                setProgressBarVisible(false);
            }
            if (mScanMenuItem != null) {
                mScanMenuItem.setEnabled(true);
            }
            break;
        case WifiManager.WIFI_STATE_ENABLING:
            getPreferenceScreen().removeAll();
            setProgressBarVisible(true);
            break;
        case WifiManager.WIFI_STATE_DISABLING:
            addMessagePreference(R.string.wifi_stopping);
            setProgressBarVisible(true);
            break;
        case WifiManager.WIFI_STATE_DISABLED:
            setOffMessage();
            setProgressBarVisible(false);
            if (mScanMenuItem != null) {
                mScanMenuItem.setEnabled(false);
            }
            break;
    }
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Preference(android.support.v7.preference.Preference) AccessPoint(com.android.settingslib.wifi.AccessPoint) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 3 with PreferenceViewHolder

use of android.support.v7.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ProgressCategory method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    final View progressBar = view.findViewById(R.id.scanning_progress);
    boolean noDeviceFound = (getPreferenceCount() == 0 || (getPreferenceCount() == 1 && getPreference(0) == mNoDeviceFoundPreference));
    progressBar.setVisibility(mProgress ? View.VISIBLE : View.GONE);
    if (mProgress || !noDeviceFound) {
        if (mNoDeviceFoundAdded) {
            removePreference(mNoDeviceFoundPreference);
            mNoDeviceFoundAdded = false;
        }
    } else {
        if (!mNoDeviceFoundAdded) {
            if (mNoDeviceFoundPreference == null) {
                mNoDeviceFoundPreference = new Preference(getPreferenceManager().getContext());
                mNoDeviceFoundPreference.setLayoutResource(R.layout.preference_empty_list);
                mNoDeviceFoundPreference.setTitle(mEmptyTextRes);
                mNoDeviceFoundPreference.setSelectable(false);
            }
            addPreference(mNoDeviceFoundPreference);
            mNoDeviceFoundAdded = true;
        }
    }
}
Also used : Preference(android.support.v7.preference.Preference) View(android.view.View)

Example 4 with PreferenceViewHolder

use of android.support.v7.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeveloperPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    mViewHolder = holder;
    if (donateLink != null) {
        final OnClickListener openDonate = new OnClickListener() {

            @Override
            public void onClick(View v) {
                Uri donateURL = Uri.parse(donateLink);
                final Intent intent = new Intent(Intent.ACTION_VIEW, donateURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
        };
        donateButton.setOnClickListener(openDonate);
    } else {
        donateButton.setVisibility(View.GONE);
    }
    final OnPreferenceClickListener opengplus = new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplusName != null) {
                Uri gplusURL = Uri.parse("https://plus.google.com/+" + gplusName);
                final Intent intent = new Intent(Intent.ACTION_VIEW, gplusURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
            return true;
        }
    };
    // changed to clicking the preference to open gplus
    // it was a hit or miss to click the gplus icon
    this.setOnPreferenceClickListener(opengplus);
    UrlImageViewHelper.setUrlDrawable(this.photoView, getGravatarUrl(devEmail), R.drawable.ic_null, UrlImageViewHelper.CACHE_DURATION_ONE_WEEK);
    if (gplusName == null)
        gplusButton.setVisibility(View.INVISIBLE);
    devName.setText(nameDev);
}
Also used : Preference(android.support.v7.preference.Preference) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 5 with PreferenceViewHolder

use of android.support.v7.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ToggleBackupSettingFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    setPreferenceScreen(preferenceScreen);
    mSummaryPreference = new Preference(getPrefContext()) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder view) {
            super.onBindViewHolder(view);
            final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
            summaryView.setText(getSummary());
        }
    };
    mSummaryPreference.setPersistent(false);
    mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
    preferenceScreen.addPreference(mSummaryPreference);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) TextView(android.widget.TextView) PreferenceViewHolder(android.support.v7.preference.PreferenceViewHolder)

Aggregations

Preference (android.support.v7.preference.Preference)6 PreferenceViewHolder (android.support.v7.preference.PreferenceViewHolder)4 View (android.view.View)4 TextView (android.widget.TextView)4 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1 Button (android.widget.Button)1 AccessPoint (com.android.settingslib.wifi.AccessPoint)1 AccessPointPreference (com.android.settingslib.wifi.AccessPointPreference)1