Search in sources :

Example 96 with Preference

use of android.support.v7.preference.Preference in project wire-android by wireapp.

the class RootPreferences method onCreatePreferences2.

@Override
public void onCreatePreferences2(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences2(savedInstanceState, rootKey);
    if (BuildConfig.SHOW_DEVELOPER_OPTIONS) {
        addPreferencesFromResource(R.xml.preference_root__developer);
        findPreference(getString(R.string.pref_dev_avs_screen_key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                getChildFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).add(AvsOptionsDialogFragment.newInstance(), AvsOptionsDialogFragment.TAG).addToBackStack(AvsOptionsDialogFragment.TAG).commit();
                return true;
            }
        });
    } else {
        addPreferencesFromResource(R.xml.preference_root);
    }
    inviteButtonPreference = (ButtonPreference) findPreference(getString(R.string.pref_invite_key));
    inviteButtonPreference.setAccentColor(getControllerFactory().getAccentColorController().getColor());
    inviteButtonPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            sendGenericInvite();
            return true;
        }
    });
    devicesPreferenceScreenLike = (BadgeablePreferenceScreenLike) findPreference(getString(R.string.pref_devices_screen_key));
    devicesPreferenceScreenLike.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (otrClients != null) {
                for (OtrClient client : otrClients) {
                    client.setVerified(false);
                }
            }
            return false;
        }
    });
    getStoreFactory().getZMessagingApiStore().getApi().onInit(new InitListener() {

        @Override
        public void onInitialized(Self user) {
            otrClientsObserver.setAndUpdate(getStoreFactory().getZMessagingApiStore().getApi().getSelf().getIncomingOtrClients());
        }
    });
    if (savedInstanceState == null) {
        boolean showSpotifyLogin = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_SPOTIFY_LOGIN, false);
        boolean showOtrDevices = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_OTR_DEVICES, false);
        boolean showAccount = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_ACCOUNT, false);
        boolean showUsernameEdit = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_USERNAME_EDIT);
        final PreferenceManager.OnNavigateToScreenListener navigateToScreenListener = getPreferenceManager().getOnNavigateToScreenListener();
        PreferenceScreen preference = null;
        if (showAccount) {
            preference = (PreferenceScreen) findPreference(getString(R.string.pref_account_screen_key));
        } else if (showSpotifyLogin) {
            preference = (PreferenceScreen) findPreference(getString(R.string.pref_options_screen_key));
            getControllerFactory().getSpotifyController().login(getActivity());
        } else if (showOtrDevices) {
            preference = devicesPreferenceScreenLike.getPreferenceScreen();
        } else if (showUsernameEdit) {
            preference = ((BadgeablePreferenceScreenLike) findPreference(getString(R.string.pref_account_screen_key))).getPreferenceScreen();
        }
        if (preference != null) {
            preference.getExtras().putAll(getArguments());
            navigateToScreenListener.onNavigateToScreen(preference);
        }
    }
}
Also used : InitListener(com.waz.api.InitListener) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) Self(com.waz.api.Self) OtrClient(com.waz.api.OtrClient) PreferenceManager(android.support.v7.preference.PreferenceManager)

Example 97 with Preference

use of android.support.v7.preference.Preference in project wire-android by wireapp.

the class AboutPreferences method onCreatePreferences2.

@Override
public void onCreatePreferences2(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences2(savedInstanceState, rootKey);
    addPreferencesFromResource(R.xml.preferences_about);
    Preference versionPreference = findPreference(getString(R.string.pref_about_version_key));
    versionPreference.setTitle(getString(R.string.pref_about_version_title, getSimpleVersion()));
    versionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            clickCounter++;
            if (clickCounter >= A_BUNCH_OF_CLICKS_TO_PREVENT_ACCIDENTAL_TRIGGERING) {
                Toast.makeText(getActivity(), DebugUtils.getVersion(getContext()), Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
}
Also used : Preference(android.support.v7.preference.Preference)

Example 98 with Preference

use of android.support.v7.preference.Preference in project wire-android by wireapp.

the class DeveloperPreferences method onCreatePreferences2.

@Override
public void onCreatePreferences2(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences2(savedInstanceState, rootKey);
    addPreferencesFromResource(R.xml.preferences_developer);
    lastCallSessionIdPreference = findPreference(getString(R.string.pref_dev_avs_last_call_session_id_key));
    lastCallSessionIdPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            copyLastCallSessionIdToClipboard();
            return true;
        }
    });
    networkDebugInfoPreference = findPreference(getString(R.string.pref_dev_net_debug_key));
    networkDebugInfoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            updateNetworkDebugInfo();
            return true;
        }
    });
    final String lastCallSessionId = preferenceManager.getSharedPreferences().getString(getString(R.string.pref_dev_avs_last_call_session_id_key), getString(R.string.pref_dev_avs_last_call_session_id_not_available));
    lastCallSessionIdPreference.setSummary(lastCallSessionId);
    Preference versionInfoPrefs = findPreference(getString(R.string.pref_dev_version_info_id_key));
    versionInfoPrefs.setSummary(DebugUtils.getVersion(getContext()));
}
Also used : Preference(android.support.v7.preference.Preference)

Example 99 with Preference

use of android.support.v7.preference.Preference in project wire-android by wireapp.

the class DevicesPreferences method addDeviceWarning.

private void addDeviceWarning(PreferenceGroup preferenceGroup) {
    Preference preference = new Preference(getActivity());
    preference.setSummary(getString(R.string.pref_devices_warning_summary));
    preferenceGroup.addPreference(preference);
}
Also used : Preference(android.support.v7.preference.Preference)

Example 100 with Preference

use of android.support.v7.preference.Preference in project NetGuard by M66B.

the class ActivityLog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.logging);
    running = true;
    // Action bar
    View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false);
    SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);
    getSupportActionBar().setTitle(R.string.menu_log);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Get settings
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    resolve = prefs.getBoolean("resolve", false);
    organization = prefs.getBoolean("organization", false);
    boolean log = prefs.getBoolean("log", false);
    // Show disabled message
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
    // Set enabled switch
    swEnabled.setChecked(log);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            prefs.edit().putBoolean("log", isChecked).apply();
        }
    });
    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);
    lvLog = (ListView) findViewById(R.id.lvLog);
    boolean udp = prefs.getBoolean("proto_udp", true);
    boolean tcp = prefs.getBoolean("proto_tcp", true);
    boolean other = prefs.getBoolean("proto_other", true);
    boolean allowed = prefs.getBoolean("traffic_allowed", true);
    boolean blocked = prefs.getBoolean("traffic_blocked", true);
    adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization);
    adapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(CharSequence constraint) {
            return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString());
        }
    });
    lvLog.setAdapter(adapter);
    try {
        vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1"));
        vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"));
    } catch (UnknownHostException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PackageManager pm = getPackageManager();
            Cursor cursor = (Cursor) adapter.getItem(position);
            long time = cursor.getLong(cursor.getColumnIndex("time"));
            int version = cursor.getInt(cursor.getColumnIndex("version"));
            int protocol = cursor.getInt(cursor.getColumnIndex("protocol"));
            final String saddr = cursor.getString(cursor.getColumnIndex("saddr"));
            final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport")));
            final String daddr = cursor.getString(cursor.getColumnIndex("daddr"));
            final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport")));
            final String dname = cursor.getString(cursor.getColumnIndex("dname"));
            final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid")));
            int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed")));
            // Get external address
            InetAddress addr = null;
            try {
                addr = InetAddress.getByName(daddr);
            } catch (UnknownHostException ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }
            String ip;
            int port;
            if (addr.equals(vpn4) || addr.equals(vpn6)) {
                ip = saddr;
                port = sport;
            } else {
                ip = daddr;
                port = dport;
            }
            // Build popup menu
            PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor));
            popup.inflate(R.menu.log);
            // Application name
            if (uid >= 0)
                popup.getMenu().findItem(R.id.menu_application).setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this)));
            else
                popup.getMenu().removeItem(R.id.menu_application);
            // Destination IP
            popup.getMenu().findItem(R.id.menu_protocol).setTitle(Util.getProtocolName(protocol, version, false));
            // Whois
            final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip));
            if (pm.resolveActivity(lookupIP, 0) == null)
                popup.getMenu().removeItem(R.id.menu_whois);
            else
                popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip));
            // Lookup port
            final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port));
            if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null)
                popup.getMenu().removeItem(R.id.menu_port);
            else
                popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port));
            if (!prefs.getBoolean("filter", false)) {
                popup.getMenu().removeItem(R.id.menu_allow);
                popup.getMenu().removeItem(R.id.menu_block);
            }
            final Packet packet = new Packet();
            packet.version = version;
            packet.protocol = protocol;
            packet.daddr = daddr;
            packet.dport = dport;
            packet.time = time;
            packet.uid = uid;
            packet.allowed = (allowed > 0);
            // Time
            popup.getMenu().findItem(R.id.menu_time).setTitle(SimpleDateFormat.getDateTimeInstance().format(time));
            // Handle click
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    switch(menuItem.getItemId()) {
                        case R.id.menu_application:
                            {
                                Intent main = new Intent(ActivityLog.this, ActivityMain.class);
                                main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
                                startActivity(main);
                                return true;
                            }
                        case R.id.menu_whois:
                            startActivity(lookupIP);
                            return true;
                        case R.id.menu_port:
                            startActivity(lookupPort);
                            return true;
                        case R.id.menu_allow:
                            if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) {
                                DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0);
                                ServiceSinkhole.reload("allow host", ActivityLog.this);
                                Intent main = new Intent(ActivityLog.this, ActivityMain.class);
                                main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
                                startActivity(main);
                            } else
                                startActivity(new Intent(ActivityLog.this, ActivityPro.class));
                            return true;
                        case R.id.menu_block:
                            if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) {
                                DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1);
                                ServiceSinkhole.reload("block host", ActivityLog.this);
                                Intent main = new Intent(ActivityLog.this, ActivityMain.class);
                                main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
                                startActivity(main);
                            } else
                                startActivity(new Intent(ActivityLog.this, ActivityPro.class));
                            return true;
                        default:
                            return false;
                    }
                }
            });
            // Show
            popup.show();
        }
    });
    live = true;
}
Also used : Cursor(android.database.Cursor) FilterQueryProvider(android.widget.FilterQueryProvider) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) UnknownHostException(java.net.UnknownHostException) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) MenuItem(android.view.MenuItem) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) InetAddress(java.net.InetAddress) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) PopupMenu(android.widget.PopupMenu)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7