|
| 1 | +/* |
| 2 | + * Copyright (C) 2009 The Sipdroid Open Source Project |
| 3 | + * |
| 4 | + * This file is part of Sipdroid (http://www.sipdroid.org) |
| 5 | + * |
| 6 | + * Sipdroid is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This source code is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this source code; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | + */ |
| 20 | +package org.sipdroid.codecs; |
| 21 | + |
| 22 | +import org.sipdroid.sipua.ui.Receiver; |
| 23 | + |
| 24 | +import android.content.SharedPreferences; |
| 25 | +import android.preference.ListPreference; |
| 26 | +import android.preference.Preference; |
| 27 | +import android.preference.PreferenceManager; |
| 28 | + |
| 29 | +class CodecBase implements Preference.OnPreferenceChangeListener { |
| 30 | + protected String CODEC_NAME; |
| 31 | + protected String CODEC_USER_NAME; |
| 32 | + protected int CODEC_NUMBER; |
| 33 | + protected String CODEC_DESCRIPTION; |
| 34 | + protected String CODEC_DEFAULT_SETTING = "never"; |
| 35 | + |
| 36 | + private boolean loaded = false; |
| 37 | + private boolean enabled = false; |
| 38 | + private boolean edgeOnly = false; |
| 39 | + private String value; |
| 40 | + |
| 41 | + void load() { |
| 42 | + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); |
| 43 | + value = sp.getString(CODEC_NAME, CODEC_DEFAULT_SETTING); |
| 44 | + updateFlags(value); |
| 45 | + loaded = true; |
| 46 | + } |
| 47 | + |
| 48 | + public boolean isLoaded() { |
| 49 | + return loaded; |
| 50 | + } |
| 51 | + |
| 52 | + public void enable(boolean e) { |
| 53 | + enabled = e && loaded; |
| 54 | + } |
| 55 | + |
| 56 | + public boolean isEnabled() { |
| 57 | + return loaded && enabled; |
| 58 | + } |
| 59 | + |
| 60 | + public boolean edgeOnly() { |
| 61 | + return loaded && enabled && edgeOnly; |
| 62 | + } |
| 63 | + |
| 64 | + public String name() { |
| 65 | + return CODEC_NAME; |
| 66 | + } |
| 67 | + |
| 68 | + public String userName() { |
| 69 | + return CODEC_USER_NAME; |
| 70 | + } |
| 71 | + |
| 72 | + public String getTitle() { |
| 73 | + return CODEC_USER_NAME + " (" + CODEC_DESCRIPTION + ")"; |
| 74 | + } |
| 75 | + |
| 76 | + public int number() { |
| 77 | + return CODEC_NUMBER; |
| 78 | + } |
| 79 | + |
| 80 | + public void setListPreference(ListPreference l) { |
| 81 | + l.setOnPreferenceChangeListener(this); |
| 82 | + l.setValue(value); |
| 83 | + } |
| 84 | + |
| 85 | + public boolean onPreferenceChange(Preference p, Object newValue) { |
| 86 | + ListPreference l = (ListPreference)p; |
| 87 | + value = (String)newValue; |
| 88 | + |
| 89 | + updateFlags(value); |
| 90 | + |
| 91 | + l.setValue(value); |
| 92 | + l.setSummary(l.getEntry()); |
| 93 | + |
| 94 | + return true; |
| 95 | + } |
| 96 | + |
| 97 | + private void updateFlags(String v) { |
| 98 | + |
| 99 | + if (v.equals("never")) { |
| 100 | + enabled = false; |
| 101 | + } else { |
| 102 | + enabled = true; |
| 103 | + if (v.equals("edge")) |
| 104 | + edgeOnly = true; |
| 105 | + else |
| 106 | + edgeOnly = false; |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + public String toString() { |
| 111 | + return "CODEC{ " + CODEC_NUMBER + ": " + getTitle() + "}"; |
| 112 | + } |
| 113 | +} |
0 commit comments