Commit 155af8df authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'feature/new_preferences' into develop

parents 828972a5 e3b2429e
......@@ -8,8 +8,8 @@ android {
applicationId "com.xabber.androiddev"
minSdkVersion 14
targetSdkVersion 21
versionCode 87
versionName '0.10.2'
versionCode 88
versionName '0.10.3'
}
buildTypes {
......@@ -22,5 +22,5 @@ android {
dependencies {
compile files('libs/otr4j.jar')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
}
......@@ -37,7 +37,7 @@
android:label="@string/application_name"
android:icon="@drawable/ic_launcher"
android:name="com.xabber.android.data.Application"
android:theme="@style/Theme.Light"
android:theme="@style/Theme"
android:allowBackup="true">
<activity
android:label="@string/application_name"
......@@ -81,34 +81,34 @@
/>
<activity
android:label="@string/about_viewer"
android:name="com.xabber.android.ui.AboutViewer"
android:parentActivityName="com.xabber.android.ui.PreferenceEditor"
android:name="com.xabber.android.ui.preferences.AboutViewer"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.PreferenceEditor" />
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:label="@string/preference_accounts"
android:name="com.xabber.android.ui.AccountList"
android:parentActivityName="com.xabber.android.ui.PreferenceEditor"
android:name="com.xabber.android.ui.preferences.AccountList"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.PreferenceEditor" />
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:label="@string/account_editor"
android:name="com.xabber.android.ui.AccountEditor"
android:parentActivityName="com.xabber.android.ui.AccountList"
android:name="com.xabber.android.ui.preferences.AccountEditor"
android:parentActivityName="com.xabber.android.ui.preferences.AccountList"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.AccountList" />
android:value="com.xabber.android.ui.preferences.AccountList" />
</activity>
<activity
android:label="@string/chat_list"
......@@ -155,22 +155,22 @@
<activity
android:label="@string/contact_add"
android:name="com.xabber.android.ui.ContactAdd"
android:parentActivityName="com.xabber.android.ui.AccountList"
android:parentActivityName="com.xabber.android.ui.preferences.AccountList"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.AccountList" />
android:value="com.xabber.android.ui.preferences.AccountList" />
</activity>
<activity
android:label="@string/account_add"
android:name="com.xabber.android.ui.AccountAdd"
android:parentActivityName="com.xabber.android.ui.AccountList"
android:parentActivityName="com.xabber.android.ui.preferences.AccountList"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.AccountList" />
android:value="com.xabber.android.ui.preferences.AccountList" />
</activity>
<activity
android:label="@string/account_oauth"
......@@ -198,7 +198,7 @@
</activity>
<activity
android:label="@string/preference_editor"
android:name="com.xabber.android.ui.PreferenceEditor"
android:name="com.xabber.android.ui.preferences.PreferenceEditor"
android:parentActivityName="com.xabber.android.ui.ContactList"
>
......@@ -210,7 +210,7 @@
<activity
android:label="@string/chat_settings"
android:name="com.xabber.android.ui.ChatEditor"
android:name="com.xabber.android.ui.preferences.ChatEditor"
android:parentActivityName="com.xabber.android.ui.ChatViewer"
>
......@@ -222,7 +222,7 @@
<activity
android:label="@string/contact_viewer"
android:name="com.xabber.android.ui.ContactViewer"
android:name="com.xabber.android.ui.preferences.ContactViewer"
android:icon="@drawable/ic_information"
android:parentActivityName="com.xabber.android.ui.ContactList"
>
......@@ -277,12 +277,33 @@
android:name="com.xabber.android.ui.ArchiveRequest"
/>
<activity
android:name="com.xabber.android.ui.PhraseList"
android:name="com.xabber.android.ui.preferences.PhraseList"
android:label="@string/events_phrases_title"
/>
android:parentActivityName="com.xabber.android.ui.preferences.NotificationsSettings">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.NotificationsSettings" />
</activity>
<activity
android:name="com.xabber.android.ui.PhraseEditor"
/>
android:name="com.xabber.android.ui.preferences.PhraseEditor"
android:parentActivityName="com.xabber.android.ui.preferences.PhraseList">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PhraseList" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.PhraseAdder"
android:parentActivityName="com.xabber.android.ui.preferences.PhraseList">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PhraseList" />
</activity>
<activity
android:name="com.xabber.android.ui.ReconnectionActivity"
/>
......@@ -296,6 +317,68 @@
android:excludeFromRecents="true"
/>
<activity
android:name="com.xabber.android.ui.preferences.ThemeSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.ContactListSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.ChatSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.NotificationsSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.ConnectionSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.SecuritySettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<activity
android:name="com.xabber.android.ui.preferences.DebugSettings"
android:parentActivityName="com.xabber.android.ui.preferences.PreferenceEditor">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.preferences.PreferenceEditor" />
</activity>
<service android:name="com.xabber.android.service.XabberService" />
<service
......
......@@ -14,24 +14,21 @@
*/
package com.xabber.android.data;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.WeakHashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.widget.Toast;
import com.xabber.android.data.SettingsManager.InterfaceTheme;
import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.LoadActivity;
import com.xabber.android.ui.PreferenceEditor;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.WeakHashMap;
/**
* Activity stack manager.
*
......@@ -129,23 +126,7 @@ public class ActivityManager implements OnUnloadListener {
* @param activity
*/
private void applyTheme(Activity activity) {
if (activity instanceof PreferenceEditor)
return;
TypedArray title = activity.getTheme().obtainStyledAttributes(
new int[] { android.R.attr.windowNoTitle,
android.R.attr.windowIsFloating });
boolean noTitle = title.getBoolean(0, false);
boolean isFloating = title.getBoolean(1, false);
title.recycle();
if (isFloating)
return;
InterfaceTheme theme = SettingsManager.interfaceTheme();
if (theme == SettingsManager.InterfaceTheme.light)
activity.setTheme(noTitle ? R.style.Theme_Light_NoTitleBar
: R.style.Theme_Light);
else if (theme == SettingsManager.InterfaceTheme.dark)
activity.setTheme(noTitle ? R.style.Theme_Dark_NoTitleBar
: R.style.Theme_Dark);
activity.setTheme(R.style.Theme);
}
/**
......@@ -212,9 +193,9 @@ public class ActivityManager implements OnUnloadListener {
LogManager.i(this, "Wait for loading");
activity.startActivity(LoadActivity.createIntent(activity));
}
if (onErrorListener != null)
application
.removeUIListener(OnErrorListener.class, onErrorListener);
if (onErrorListener != null) {
application.removeUIListener(OnErrorListener.class, onErrorListener);
}
onErrorListener = new OnErrorListener() {
@Override
public void onError(final int resourceId) {
......
......@@ -19,7 +19,7 @@ import android.content.Intent;
import com.xabber.android.data.Application;
import com.xabber.android.data.entity.AccountRelated;
import com.xabber.android.data.notification.AccountNotificationItem;
import com.xabber.android.ui.AccountEditor;
import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.androiddev.R;
public class AccountAuthorizationError extends AccountRelated implements
......
......@@ -91,7 +91,7 @@ public class AccountAdd extends ManagedActivity implements
inputManager.hideSoftInputFromWindow(findViewById(R.id.ok)
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import java.util.HashMap;
import java.util.Map;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountProtocol;
import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.BaseSettingsActivity;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R;
public class AccountEditor extends BaseSettingsActivity implements
OnPreferenceClickListener {
private static final int OAUTH_WML_REQUEST_CODE = 1;
private static final String SAVED_TOKEN = "com.xabber.android.ui.AccountEditor.TOKEN";
private static final String INVALIDATED_TOKEN = "com.xabber.android.ui.AccountEditor.INVALIDATED";
private static final int ORBOT_DIALOG_ID = 9050;
private String account;
private AccountItem accountItem;
private String token;
private Preference oauthPreference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onInflate(Bundle savedInstanceState) {
account = AccountEditor.getAccount(getIntent());
if (account == null) {
finish();
return;
}
accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
finish();
return;
}
AccountProtocol protocol = accountItem.getConnectionSettings()
.getProtocol();
if (protocol == AccountProtocol.xmpp)
addPreferencesFromResource(R.xml.account_editor_xmpp);
else if (protocol == AccountProtocol.gtalk)
addPreferencesFromResource(R.xml.account_editor_xmpp);
else if (protocol == AccountProtocol.wlm)
addPreferencesFromResource(R.xml.account_editor_oauth);
else
throw new IllegalStateException();
if (!Application.getInstance().isContactsSupported())
getPreferenceScreen().removePreference(
findPreference(getString(R.string.account_syncable_key)));
setTitle(getString(R.string.account_editor_title,
getString(protocol.getShortResource()), AccountManager
.getInstance().getVerboseName(account)));
if (savedInstanceState == null)
token = accountItem.getConnectionSettings().getPassword();
else
token = savedInstanceState.getString(SAVED_TOKEN);
oauthPreference = findPreference(getString(R.string.account_oauth_key));
if (oauthPreference != null)
oauthPreference.setOnPreferenceClickListener(this);
onOAuthChange();
AccountManager.getInstance().removeAuthorizationError(account);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_TOKEN, token);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OAUTH_WML_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
if (OAuthActivity.isInvalidated(data)) {
token = INVALIDATED_TOKEN;
} else {
String value = OAuthActivity.getToken(data);
if (value == null)
Application.getInstance().onError(
R.string.AUTHENTICATION_FAILED);
else
token = value;
}
onOAuthChange();
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (getString(R.string.account_port_key).equals(preference.getKey()))
try {
Integer.parseInt((String) newValue);
} catch (NumberFormatException e) {
Toast.makeText(this, getString(R.string.account_invalid_port),
Toast.LENGTH_LONG).show();
return false;
}
if (getString(R.string.account_tls_mode_key)
.equals(preference.getKey())
|| getString(R.string.account_archive_mode_key).equals(
preference.getKey())
|| getString(R.string.account_proxy_type_key).equals(
preference.getKey()))
preference.setSummary((String) newValue);
else if (!getString(R.string.account_password_key).equals(
preference.getKey())
&& !getString(R.string.account_proxy_password_key).equals(
preference.getKey())
&& !getString(R.string.account_priority_key).equals(
preference.getKey()))
super.onPreferenceChange(preference, newValue);
if (getString(R.string.account_proxy_type_key).equals(
preference.getKey())) {
boolean enabled = !getString(R.string.account_proxy_type_none)
.equals(newValue)
&& !getString(R.string.account_proxy_type_orbot).equals(
newValue);
for (int id : new Integer[] { R.string.account_proxy_host_key,
R.string.account_proxy_port_key,
R.string.account_proxy_user_key,
R.string.account_proxy_password_key, }) {
Preference proxyPreference = findPreference(getString(id));
if (proxyPreference != null)
proxyPreference.setEnabled(enabled);
}
}
return true;
}
private void onOAuthChange() {
if (oauthPreference == null)
return;
if (INVALIDATED_TOKEN.equals(token))
oauthPreference.setSummary(R.string.account_oauth_invalidated);
else
oauthPreference.setSummary(R.string.account_oauth_summary);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (getString(R.string.account_oauth_key).equals(preference.getKey())) {
startActivityForResult(OAuthActivity.createIntent(this, accountItem
.getConnectionSettings().getProtocol()),
OAUTH_WML_REQUEST_CODE);
return true;
}
return false;
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> source = new HashMap<String, Object>();
putValue(source, R.string.account_custom_key, accountItem
.getConnectionSettings().isCustom());
putValue(source, R.string.account_host_key, accountItem
.getConnectionSettings().getHost());
putValue(source, R.string.account_port_key, accountItem
.getConnectionSettings().getPort());
putValue(source, R.string.account_server_key, accountItem
.getConnectionSettings().getServerName());
putValue(source, R.string.account_username_key, accountItem
.getConnectionSettings().getUserName());
putValue(source, R.string.account_store_password_key,
accountItem.isStorePassword());
putValue(source, R.string.account_password_key, accountItem
.getConnectionSettings().getPassword());
putValue(source, R.string.account_resource_key, accountItem
.getConnectionSettings().getResource());
putValue(source, R.string.account_priority_key,
accountItem.getPriority());
putValue(source, R.string.account_enabled_key, accountItem.isEnabled());
putValue(source, R.string.account_sasl_key, accountItem
.getConnectionSettings().isSaslEnabled());
putValue(
source,
R.string.account_tls_mode_key,
Integer.valueOf(accountItem.getConnectionSettings()
.getTlsMode().ordinal()));
putValue(source, R.string.account_compression_key, accountItem
.getConnectionSettings().useCompression());
putValue(
source,
R.string.account_proxy_type_key,
Integer.valueOf(accountItem.getConnectionSettings()
.getProxyType().ordinal()));
putValue(source, R.string.account_proxy_host_key, accountItem
.getConnectionSettings().getProxyHost());
putValue(source, R.string.account_proxy_port_key, accountItem
.getConnectionSettings().getProxyPort());
putValue(source, R.string.account_proxy_user_key, accountItem
.getConnectionSettings().getProxyUser());
putValue(source, R.string.account_proxy_password_key, accountItem
.getConnectionSettings().getProxyPassword());
putValue(source, R.string.account_syncable_key,
accountItem.isSyncable());
putValue(source, R.string.account_archive_mode_key,
Integer.valueOf(accountItem.getArchiveMode().ordinal()));
return source;
}
@Override
protected Map<String, Object> getPreferences(Map<String, Object> source) {
Map<String, Object> result = super.getPreferences(source);
if (oauthPreference != null)
putValue(result, R.string.account_password_key, token);
return result;
}
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
ProxyType proxyType = ProxyType.values()[getInt(result,
R.string.account_proxy_type_key)];
if (proxyType == ProxyType.orbot && !OrbotHelper.isOrbotInstalled()) {
showDialog(ORBOT_DIALOG_ID);
return false;
}
AccountManager
.getInstance()
.updateAccount(
account,
getBoolean(result, R.string.account_custom_key),
getString(result, R.string.account_host_key),
getInt(result, R.string.account_port_key),
getString(result, R.string.account_server_key),
getString(result, R.string.account_username_key),
getBoolean(result, R.string.account_store_password_key),
getString(result, R.string.account_password_key),
getString(result, R.string.account_resource_key),
getInt(result, R.string.account_priority_key),
getBoolean(result, R.string.account_enabled_key),
getBoolean(result, R.string.account_sasl_key),
TLSMode.values()[getInt(result,
R.string.account_tls_mode_key)],
getBoolean(result, R.string.account_compression_key),
proxyType,
getString(result, R.string.account_proxy_host_key),
getInt(result, R.string.account_proxy_port_key),
getString(result, R.string.account_proxy_user_key),
getString(result, R.string.account_proxy_password_key),
getBoolean(result, R.string.account_syncable_key),
ArchiveMode.values()[getInt(result,
R.string.account_archive_mode_key)]);
return true;
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ORBOT_DIALOG_ID) {
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID)
.create();
}
return super.onCreateDialog(id);
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, AccountEditor.class)
.setAccount(account).build();
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import java.util.HashMap;
import java.util.Map;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.ui.helper.BaseSettingsActivity;
import com.xabber.androiddev.R;
public class ChatEditor extends BaseSettingsActivity {
private String account;
private String user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onInflate(Bundle savedInstanceState) {
account = getAccount(getIntent());
user = getUser(getIntent());
AccountItem accountItem = AccountManager.getInstance().getAccount(
account);
if (accountItem == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
addPreferencesFromResource(R.xml.chat_editor);
if (accountItem.getArchiveMode() == ArchiveMode.server
|| accountItem.getArchiveMode() == ArchiveMode.dontStore)
getPreferenceScreen().removePreference(
getPreferenceScreen().findPreference(
getString(R.string.chat_save_history_key)));
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> map = new HashMap<String, Object>();
putValue(map, R.string.chat_save_history_key, ChatManager.getInstance()
.isSaveMessages(account, user));
putValue(map, R.string.chat_events_visible_chat_key, ChatManager
.getInstance().isNotifyVisible(account, user));
putValue(map, R.string.chat_events_show_text_key, ChatManager
.getInstance().isShowText(account, user));
putValue(map, R.string.chat_events_vibro_key, ChatManager.getInstance()
.isMakeVibro(account, user));
putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance()
.getSound(account, user));
return map;
}
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
if (hasChanges(source, result, R.string.chat_save_history_key))
ChatManager.getInstance().setSaveMessages(account, user,
getBoolean(result, R.string.chat_save_history_key));
if (hasChanges(source, result, R.string.chat_events_visible_chat_key))
ChatManager.getInstance().setNotifyVisible(account, user,
getBoolean(result, R.string.chat_events_visible_chat_key));
if (hasChanges(source, result, R.string.chat_events_show_text_key))
ChatManager.getInstance().setShowText(account, user,
getBoolean(result, R.string.chat_events_show_text_key));
if (hasChanges(source, result, R.string.chat_events_vibro_key))
ChatManager.getInstance().setMakeVibro(account, user,
getBoolean(result, R.string.chat_events_vibro_key));
if (hasChanges(source, result, R.string.chat_events_sound_key))
ChatManager.getInstance().setSound(account, user,
getUri(result, R.string.chat_events_sound_key));
return true;
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatEditor.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
}
......@@ -50,7 +50,7 @@ public class ChatList extends ManagedListActivity implements
setListAdapter(listAdapter);
getListView().setOnItemClickListener(this);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
......@@ -115,7 +115,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
if (actionWithUser == null)
actionWithUser = user;
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
selectChat(actionWithAccount, actionWithUser);
}
......@@ -179,7 +179,6 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
String account = getAccount(intent);
String user = getUser(intent);
if (account == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
return;
}
if (hasAttention(intent))
......
......@@ -57,6 +57,7 @@ import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.AbstractAvatarInflaterHelper;
import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.android.ui.widget.PageSwitcher;
import com.xabber.androiddev.R;
......
......@@ -62,7 +62,7 @@ public class ContactAdd extends GroupListActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
......@@ -47,7 +47,7 @@ public class ContactEditor extends GroupListActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
......@@ -24,7 +24,6 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
......@@ -55,6 +54,7 @@ import com.xabber.android.ui.dialog.AccountChooseDialogFragment.OnChoosedListene
import com.xabber.android.ui.dialog.ContactIntegrationDialogFragment;
import com.xabber.android.ui.dialog.StartAtBootDialogFragment;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.PreferenceEditor;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.uri.XMPPUri;
......
......@@ -39,6 +39,7 @@ import com.xabber.android.ui.adapter.ContactListState;
import com.xabber.android.ui.adapter.GroupConfiguration;
import com.xabber.android.ui.adapter.UpdatableAdapter;
import com.xabber.android.ui.helper.ContextMenuHelper;
import com.xabber.android.ui.preferences.AccountList;
import com.xabber.androiddev.R;
public class ContactListFragment extends Fragment implements
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.extension.vcard.OnVCardListener;
import com.xabber.android.data.extension.vcard.VCardManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ResourceItem;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.ManagedPreferenceActivity;
import com.xabber.android.ui.widget.StatusPreference;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.vcard.Address;
import com.xabber.xmpp.vcard.AddressProperty;
import com.xabber.xmpp.vcard.AddressType;
import com.xabber.xmpp.vcard.Email;
import com.xabber.xmpp.vcard.EmailType;
import com.xabber.xmpp.vcard.NameProperty;
import com.xabber.xmpp.vcard.Organization;
import com.xabber.xmpp.vcard.Telephone;
import com.xabber.xmpp.vcard.TelephoneType;
import com.xabber.xmpp.vcard.VCard;
import com.xabber.xmpp.vcard.VCardProperty;
import com.xabber.xmpp.vcard.VCardProvider;
public class ContactViewer extends ManagedPreferenceActivity implements
OnVCardListener, OnContactChangedListener, OnAccountChangedListener {
private static final String SAVED_VCARD = "com.xabber.android.ui.ContactViewer.SAVED_VCARD";
private static final String SAVED_VCARD_ERROR = "com.xabber.android.ui.ContactViewer.SAVED_VCARD_ERROR";
private String account;
private String bareAddress;
private VCard vCard;
private boolean vCardError;
private List<PreferenceCategory> addresses;
private List<PreferenceCategory> telephones;
private List<PreferenceCategory> emails;
private static final Map<AddressType, Integer> ADDRESS_TYPE_MAP = new HashMap<AddressType, Integer>();
private static final Map<AddressProperty, Integer> ADDRESS_PROPERTY_MAP = new HashMap<AddressProperty, Integer>();
private static final Map<TelephoneType, Integer> TELEPHONE_TYPE_MAP = new HashMap<TelephoneType, Integer>();
private static final Map<EmailType, Integer> EMAIL_TYPE_MAP = new HashMap<EmailType, Integer>();
static {
ADDRESS_TYPE_MAP.put(AddressType.DOM, R.string.vcard_type_dom);
ADDRESS_TYPE_MAP.put(AddressType.HOME, R.string.vcard_type_home);
ADDRESS_TYPE_MAP.put(AddressType.INTL, R.string.vcard_type_intl);
ADDRESS_TYPE_MAP.put(AddressType.PARCEL, R.string.vcard_type_parcel);
ADDRESS_TYPE_MAP.put(AddressType.POSTAL, R.string.vcard_type_postal);
ADDRESS_TYPE_MAP.put(AddressType.PREF, R.string.vcard_type_pref);
ADDRESS_TYPE_MAP.put(AddressType.WORK, R.string.vcard_type_work);
if (ADDRESS_TYPE_MAP.size() != AddressType.values().length)
throw new IllegalStateException();
ADDRESS_PROPERTY_MAP.put(AddressProperty.CTRY,
R.string.vcard_address_ctry);
ADDRESS_PROPERTY_MAP.put(AddressProperty.EXTADR,
R.string.vcard_address_extadr);
ADDRESS_PROPERTY_MAP.put(AddressProperty.LOCALITY,
R.string.vcard_address_locality);
ADDRESS_PROPERTY_MAP.put(AddressProperty.PCODE,
R.string.vcard_address_pcode);
ADDRESS_PROPERTY_MAP.put(AddressProperty.POBOX,
R.string.vcard_address_pobox);
ADDRESS_PROPERTY_MAP.put(AddressProperty.REGION,
R.string.vcard_address_region);
ADDRESS_PROPERTY_MAP.put(AddressProperty.STREET,
R.string.vcard_address_street);
if (ADDRESS_PROPERTY_MAP.size() != AddressProperty.values().length)
throw new IllegalStateException();
TELEPHONE_TYPE_MAP.put(TelephoneType.BBS, R.string.vcard_type_bbs);
TELEPHONE_TYPE_MAP.put(TelephoneType.CELL, R.string.vcard_type_cell);
TELEPHONE_TYPE_MAP.put(TelephoneType.FAX, R.string.vcard_type_fax);
TELEPHONE_TYPE_MAP.put(TelephoneType.HOME, R.string.vcard_type_home);
TELEPHONE_TYPE_MAP.put(TelephoneType.ISDN, R.string.vcard_type_isdn);
TELEPHONE_TYPE_MAP.put(TelephoneType.MODEM, R.string.vcard_type_modem);
TELEPHONE_TYPE_MAP.put(TelephoneType.MSG, R.string.vcard_type_msg);
TELEPHONE_TYPE_MAP.put(TelephoneType.PAGER, R.string.vcard_type_pager);
TELEPHONE_TYPE_MAP.put(TelephoneType.PCS, R.string.vcard_type_pcs);
TELEPHONE_TYPE_MAP.put(TelephoneType.PREF, R.string.vcard_type_pref);
TELEPHONE_TYPE_MAP.put(TelephoneType.VIDEO, R.string.vcard_type_video);
TELEPHONE_TYPE_MAP.put(TelephoneType.VOICE, R.string.vcard_type_voice);
TELEPHONE_TYPE_MAP.put(TelephoneType.WORK, R.string.vcard_type_work);
if (TELEPHONE_TYPE_MAP.size() != TelephoneType.values().length)
throw new IllegalStateException();
EMAIL_TYPE_MAP.put(EmailType.HOME, R.string.vcard_type_home);
EMAIL_TYPE_MAP.put(EmailType.INTERNET, R.string.vcard_type_internet);
EMAIL_TYPE_MAP.put(EmailType.PREF, R.string.vcard_type_pref);
EMAIL_TYPE_MAP.put(EmailType.WORK, R.string.vcard_type_work);
EMAIL_TYPE_MAP.put(EmailType.X400, R.string.vcard_type_x400);
if (EMAIL_TYPE_MAP.size() != EmailType.values().length)
throw new IllegalStateException();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.contact_viewer);
addresses = new ArrayList<PreferenceCategory>();
telephones = new ArrayList<PreferenceCategory>();
emails = new ArrayList<PreferenceCategory>();
if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
// View information about contact from system contact list
Uri data = getIntent().getData();
if (data != null && "content".equals(data.getScheme())) {
List<String> segments = data.getPathSegments();
if (segments.size() == 2 && "data".equals(segments.get(0))) {
Long id;
try {
id = Long.valueOf(segments.get(1));
} catch (NumberFormatException e) {
id = null;
}
if (id != null)
// FIXME: Will be empty while application is loading
for (RosterContact rosterContact : RosterManager
.getInstance().getContacts())
if (id.equals(rosterContact.getViewId())) {
account = rosterContact.getAccount();
bareAddress = rosterContact.getUser();
break;
}
}
}
} else {
account = getAccount(getIntent());
bareAddress = Jid.getBareAddress(getUser(getIntent()));
}
if (account == null || bareAddress == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
vCard = null;
vCardError = false;
if (savedInstanceState != null) {
vCardError = savedInstanceState
.getBoolean(SAVED_VCARD_ERROR, false);
String xml = savedInstanceState.getString(SAVED_VCARD);
if (xml != null)
try {
XmlPullParser parser = XmlPullParserFactory.newInstance()
.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
true);
parser.setInput(new StringReader(xml));
int eventType = parser.next();
if (eventType != XmlPullParser.START_TAG)
throw new IllegalStateException(
String.valueOf(eventType));
if (!VCard.ELEMENT_NAME.equals(parser.getName()))
throw new IllegalStateException(parser.getName());
if (!VCard.NAMESPACE.equals(parser.getNamespace()))
throw new IllegalStateException(parser.getNamespace());
vCard = (VCard) (new VCardProvider()).parseIQ(parser);
} catch (Exception e) {
LogManager.exception(this, e);
}
}
setTitle(getString(R.string.contact_viewer_for, bareAddress));
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnVCardListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
if (vCard == null && !vCardError)
VCardManager.getInstance().request(account, bareAddress, null);
updateContact();
updateVCard();
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(OnVCardListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(SAVED_VCARD_ERROR, vCardError);
if (vCard != null)
outState.putString(SAVED_VCARD, vCard.getChildElementXML());
}
@Override
public void onVCardReceived(String account, String bareAddress, VCard vCard) {
if (!this.account.equals(account)
|| !this.bareAddress.equals(bareAddress))
return;
this.vCard = vCard;
this.vCardError = false;
updateVCard();
}
@Override
public void onVCardFailed(String account, String bareAddress) {
if (!this.account.equals(account)
|| !this.bareAddress.equals(bareAddress))
return;
this.vCard = null;
this.vCardError = true;
updateVCard();
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
}
@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
for (BaseEntity entity : entities)
if (entity.equals(account, bareAddress)) {
updateContact();
break;
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
if (accounts.contains(account))
updateContact();
}
/**
* Sets value for the preference by its id.
*
* @param resourceId
* @param value
*/
private void setValue(int resourceId, String value) {
if (value == null)
value = "";
findPreference(getString(resourceId)).setSummary(value);
}
/**
* @param source
* @param value
* @param splitter
* @return Concatenated source and value with splitter if necessary.
*/
private String addString(String source, String value, String splitter) {
if (value == null || "".equals(value))
return source;
if (source == null || "".equals(source))
return value;
return source + splitter + value;
}
private void updateContact() {
setValue(R.string.contact_viewer_jid, bareAddress);
RosterContact rosterContact = RosterManager.getInstance()
.getRosterContact(account, bareAddress);
setValue(R.string.contact_viewer_name, rosterContact == null ? null
: rosterContact.getRealName());
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference(getString(R.string.contact_viewer_resources));
preferenceCategory.removeAll();
if (rosterContact != null && rosterContact.isConnected())
for (ResourceItem resourceItem : PresenceManager.getInstance()
.getResourceItems(account, bareAddress)) {
StatusPreference preference = new StatusPreference(this);
preference.setLayoutResource(R.layout.info_preference);
preference.setStatusMode(resourceItem.getStatusMode());
String user = resourceItem.getUser(bareAddress);
ClientInfo clientInfo = CapabilitiesManager.getInstance()
.getClientInfo(account, user);
String client;
if (clientInfo == null) {
CapabilitiesManager.getInstance().request(account, user);
client = getString(R.string.please_wait);
} else if (clientInfo == CapabilitiesManager.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name == null)
name = getString(R.string.unknown);
String type = clientInfo.getType();
if (type == null)
type = getString(R.string.unknown);
client = getString(R.string.contact_viewer_client_info,
name, type);
}
preference.setTitle(getString(
R.string.contact_viewer_resource_summary,
resourceItem.getVerbose(), resourceItem.getPriority(),
client));
preference.setSummary(resourceItem.getStatusText());
preferenceCategory.addPreference(preference);
}
}
private void updateVCard() {
if (vCard == null)
return;
setValue(R.string.vcard_nick_name,
vCard.getField(VCardProperty.NICKNAME));
setValue(R.string.vcard_formatted_name, vCard.getFormattedName());
setValue(R.string.vcard_prefix_name,
vCard.getField(NameProperty.PREFIX));
setValue(R.string.vcard_given_name, vCard.getField(NameProperty.GIVEN));
setValue(R.string.vcard_middle_name,
vCard.getField(NameProperty.MIDDLE));
setValue(R.string.vcard_family_name,
vCard.getField(NameProperty.FAMILY));
setValue(R.string.vcard_suffix_name,
vCard.getField(NameProperty.SUFFIX));
setValue(R.string.vcard_birth_date, vCard.getField(VCardProperty.BDAY));
setValue(R.string.vcard_title, vCard.getField(VCardProperty.TITLE));
setValue(R.string.vcard_role, vCard.getField(VCardProperty.ROLE));
List<Organization> organizations = vCard.getOrganizations();
String organization;
if (organizations.isEmpty())
organization = null;
else {
organization = organizations.get(0).getName();
for (String unit : organizations.get(0).getUnits())
organization = addString(organization, unit, "\n");
}
setValue(R.string.vcard_organization, organization);
setValue(R.string.vcard_url, vCard.getField(VCardProperty.URL));
String categories = null;
for (String category : vCard.getCategories())
categories = addString(categories, category, "\n");
setValue(R.string.vcard_categories, categories);
setValue(R.string.vcard_note, vCard.getField(VCardProperty.NOTE));
setValue(R.string.vcard_decsription, vCard.getField(VCardProperty.DESC));
PreferenceScreen screen = getPreferenceScreen();
for (PreferenceCategory category : addresses)
screen.removePreference(category);
for (PreferenceCategory category : telephones)
screen.removePreference(category);
for (PreferenceCategory category : emails)
screen.removePreference(category);
for (Address address : vCard.getAddresses()) {
String types = null;
for (AddressType type : address.getTypes())
types = addString(types, getString(ADDRESS_TYPE_MAP.get(type)),
", ");
String value = null;
for (AddressProperty property : AddressProperty.values())
value = addString(value, address.getProperties().get(property),
"\n");
PreferenceScreen addressScreen = createTypedCategory(
R.string.vcard_address, types, value);
for (AddressProperty property : AddressProperty.values())
addPreferenceScreen(addressScreen,
ADDRESS_PROPERTY_MAP.get(property), address
.getProperties().get(property));
}
for (Telephone telephone : vCard.getTelephones()) {
String types = null;
for (TelephoneType type : telephone.getTypes())
types = addString(types,
getString(TELEPHONE_TYPE_MAP.get(type)), ", ");
createTypedCategory(R.string.vcard_telephone, types,
telephone.getValue());
}
for (Email email : vCard.getEmails()) {
String types = null;
for (EmailType type : email.getTypes())
types = addString(types, getString(EMAIL_TYPE_MAP.get(type)),
", ");
createTypedCategory(R.string.vcard_email, types, email.getValue());
}
}
private PreferenceScreen createTypedCategory(int title, String types,
String value) {
PreferenceCategory preferenceCategory = new PreferenceCategory(this);
preferenceCategory.setTitle(title);
getPreferenceScreen().addPreference(preferenceCategory);
addPreferenceScreen(preferenceCategory, R.string.vcard_type, types);
return addPreferenceScreen(preferenceCategory, title, value);
}
private PreferenceScreen addPreferenceScreen(PreferenceGroup container,
int title, String summary) {
PreferenceScreen preference = getPreferenceManager()
.createPreferenceScreen(this);
preference.setLayoutResource(R.layout.info_preference);
preference.setTitle(title);
preference.setSummary(summary == null ? "" : summary);
container.addPreference(preference);
return preference;
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactViewer.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
}
......@@ -120,7 +120,7 @@ public class FingerprintViewer extends ManagedActivity implements
copyView.setOnClickListener(this);
isUpdating = false;
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
......@@ -72,7 +72,7 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
setContentView(R.layout.muc_editor);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
accountView = (Spinner) findViewById(R.id.contact_account);
serverView = (EditText) findViewById(R.id.muc_server);
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.PatternSyntaxException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.ui.helper.BaseSettingsActivity;
import com.xabber.androiddev.R;
public class PhraseEditor extends BaseSettingsActivity {
private Phrase phrase;
@Override
protected void onInflate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.phrase_editor);
Integer index = getPhraseIndex(getIntent());
if (index == null) {
phrase = null;
setTitle(R.string.phrase_add);
} else {
phrase = PhraseManager.getInstance().getPhrase(index);
if (phrase == null) {
finish();
return;
}
String title = phrase.getText();
if ("".equals(title))
title = Application.getInstance().getString(
R.string.phrase_empty);
setTitle(title);
}
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> source = new HashMap<String, Object>();
putValue(source, R.string.phrase_text_key,
phrase == null ? "" : phrase.getText());
putValue(source, R.string.phrase_user_key,
phrase == null ? "" : phrase.getUser());
putValue(source, R.string.phrase_group_key, phrase == null ? ""
: phrase.getGroup());
putValue(source, R.string.phrase_regexp_key, phrase == null ? false
: phrase.isRegexp());
putValue(source, R.string.phrase_sound_key,
phrase == null ? Settings.System.DEFAULT_NOTIFICATION_URI
: phrase.getSound());
return source;
}
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
String text = getString(result, R.string.phrase_text_key);
String user = getString(result, R.string.phrase_user_key);
String group = getString(result, R.string.phrase_group_key);
boolean regexp = getBoolean(result, R.string.phrase_regexp_key);
Uri sound = getUri(result, R.string.phrase_sound_key);
if (regexp)
try {
Phrase.compile(text);
Phrase.compile(user);
Phrase.compile(group);
} catch (PatternSyntaxException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
return false;
}
if (phrase == null && "".equals(text) && "".equals(user)
&& "".equals(group))
return true;
PhraseManager.getInstance().updateOrCreatePhrase(phrase, text, user,
group, regexp, sound);
return true;
}
public static Intent createIntent(Context context) {
return createIntent(context, null);
}
public static Intent createIntent(Context context, Integer phraseIndex) {
SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<SegmentIntentBuilder<?>>(
context, PhraseEditor.class);
if (phraseIndex != null)
builder.addSegment(phraseIndex.toString());
return builder.build();
}
private Integer getPhraseIndex(Intent intent) {
String value = SegmentIntentBuilder.getSegment(intent, 0);
if (value == null)
return null;
else
return Integer.valueOf(value);
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.connection.CertificateManager;
import com.xabber.android.data.connection.ConnectionManager;
import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.ManagedPreferenceActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class PreferenceEditor extends ManagedPreferenceActivity implements
OnPreferenceClickListener, OnSharedPreferenceChangeListener,
ConfirmDialogListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
getActionBar().setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preference_editor);
getPreferenceScreen().findPreference(
getString(R.string.preference_accounts_key)).setIntent(
AccountList.createIntent(this));
getPreferenceScreen()
.findPreference(getString(R.string.events_phrases)).setIntent(
PhraseList.createIntent(this));
getPreferenceScreen().findPreference(
getString(R.string.cache_clear_key))
.setOnPreferenceClickListener(this);
getPreferenceScreen().findPreference(
getString(R.string.security_clear_certificate_key))
.setOnPreferenceClickListener(this);
getPreferenceScreen().findPreference(
getString(R.string.contacts_reset_offline_key))
.setOnPreferenceClickListener(this);
getPreferenceScreen().findPreference(getString(R.string.debug_log_key))
.setEnabled(LogManager.isDebugable());
// Force request sound. This will set default value if not specified.
SettingsManager.eventsSound();
SettingsManager.chatsAttentionSound();
PreferenceScreen about = (PreferenceScreen) getPreferenceScreen()
.findPreference(getString(R.string.preference_about_key));
about.setSummary(getString(R.string.application_name) + "\n" + getVersionName());
about.setIntent(AboutViewer.createIntent(this));
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
private String getVersionName() {
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
return pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
@Override
protected void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
}
private void changeGrouping() {
boolean grouped = SettingsManager.contactsShowAccounts()
|| SettingsManager.contactsShowGroups();
((CheckBoxPreference) getPreferenceScreen().findPreference(
getString(R.string.contacts_stay_active_chats_key)))
.setChecked(grouped);
((CheckBoxPreference) getPreferenceScreen().findPreference(
getString(R.string.contacts_show_empty_groups_key)))
.setEnabled(grouped);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (key.equals(getString(R.string.contacts_show_accounts_key))) {
changeGrouping();
} else if (key.equals(getString(R.string.contacts_show_groups_key))) {
changeGrouping();
} else if (key.equals(getString(R.string.interface_theme_key))) {
ActivityManager.getInstance().clearStack(true);
startActivity(ContactList.createIntent(this));
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(getString(R.string.cache_clear_key))) {
showDialog(R.string.cache_clear_warning);
} else if (preference.getKey().equals(
getString(R.string.security_clear_certificate_key))) {
showDialog(R.string.security_clear_certificate_warning);
} else if (preference.getKey().equals(
getString(R.string.contacts_reset_offline_key))) {
showDialog(R.string.contacts_reset_offline_warning);
}
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
switch (id) {
case R.string.cache_clear_warning:
return new ConfirmDialogBuilder(this, R.string.cache_clear_warning,
this).setMessage(R.string.cache_clear_warning).create();
case R.string.security_clear_certificate_warning:
return new ConfirmDialogBuilder(this,
R.string.security_clear_certificate_warning, this)
.setMessage(R.string.security_clear_certificate_warning)
.create();
case R.string.contacts_reset_offline_warning:
return new ConfirmDialogBuilder(this,
R.string.contacts_reset_offline_warning, this).setMessage(
R.string.contacts_reset_offline_warning).create();
case R.string.application_state_closing:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog
.setMessage(getString(R.string.application_state_closing));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
default:
return null;
}
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
switch (dialogBuilder.getDialogId()) {
case R.string.cache_clear_warning:
AccountManager.getInstance()
.setStatus(StatusMode.unavailable, null);
((Application) getApplication()).requestToClear();
Application.getInstance().requestToClose();
showDialog(R.string.application_state_closing);
break;
case R.string.security_clear_certificate_warning:
CertificateManager.getInstance().removeCertificates();
ConnectionManager.getInstance().updateConnections(true);
break;
case R.string.contacts_reset_offline_warning:
GroupManager.getInstance().resetShowOfflineModes();
break;
}
}
@Override
public void onDecline(DialogBuilder dialogBuilder) {
}
@Override
public void onCancel(DialogBuilder dialogBuilder) {
}
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
}
}
......@@ -99,7 +99,7 @@ public class QuestionViewer extends ManagedActivity implements
findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
......
......@@ -72,7 +72,7 @@ public class StatusEditor extends ManagedListActivity implements
setContentView(R.layout.status_editor);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
account = StatusEditor.getAccount(intent);
......
......@@ -29,7 +29,7 @@ import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.connection.ConnectionState;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.ui.AccountList;
import com.xabber.android.ui.preferences.AccountList;
import com.xabber.androiddev.R;
/**
......
......@@ -21,7 +21,7 @@ import java.util.List;
import android.app.Activity;
import android.widget.BaseAdapter;
import com.xabber.android.ui.helper.BaseListEditor;
import com.xabber.android.ui.preferences.BaseListEditor;
/**
* This class manage abstract list for {@link BaseListEditor}.
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.helper;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import com.xabber.android.ui.widget.RingtonePreference;
import com.xabber.androiddev.R;
/**
* Provide possibility to edit, apply and discard settings.
*
* String resource id is used to identify preferences.
*
* @author alexander.ivanov
*
* @param <T>
*/
public abstract class BaseSettingsActivity extends ManagedPreferenceActivity
implements Preference.OnPreferenceChangeListener {
private static final int MENU_SAVE = Menu.FIRST;
private static final int MENU_CANCEL = Menu.FIRST + 1;
private static final int CONFIRM_DIALOG_ID = 0;
/**
* Set of initial values is in progress.
*/
private boolean initialChange;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
onInflate(savedInstanceState);
if (isFinishing())
return;
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
if (savedInstanceState == null)
operation(Operation.read);
PreferenceScreen preferenceScreen = getPreferenceScreen();
initialChange = true;
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
preference.setOnPreferenceChangeListener(this);
if (preference instanceof EditTextPreference)
onPreferenceChange(preference,
((EditTextPreference) preference).getText());
else if (preference instanceof CheckBoxPreference)
onPreferenceChange(preference,
((CheckBoxPreference) preference).isChecked());
else if (preference instanceof ListPreference)
onPreferenceChange(preference,
((ListPreference) preference).getValue());
}
initialChange = false;
}
protected boolean isInitialChange() {
return initialChange;
}
/**
* Inflates layout.
*
* @param savedInstanceState
*/
protected abstract void onInflate(Bundle savedInstanceState);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_SAVE, 0, android.R.string.ok).setIcon(
android.R.drawable.ic_menu_save);
menu.add(0, MENU_CANCEL, 0, android.R.string.cancel).setIcon(
android.R.drawable.ic_menu_close_clear_cancel);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_SAVE:
if (operation(Operation.save))
finish();
return true;
case MENU_CANCEL:
if (operation(Operation.discard))
finish();
else
showDialog(CONFIRM_DIALOG_ID);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference instanceof EditTextPreference)
preference.setSummary((String) newValue);
return true;
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == CONFIRM_DIALOG_ID) {
return new AlertDialog.Builder(this)
.setTitle(android.R.string.dialog_alert_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(R.string.confirm_cancellation)
.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int w) {
finish();
}
}).setNegativeButton(android.R.string.no, null)
.create();
}
return super.onCreateDialog(id);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (operation(Operation.save))
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Possible operations.
*/
private static enum Operation {
save, discard, read
};
protected void putValue(Map<String, Object> map, int resoureId, Object value) {
map.put(getString(resoureId), value);
}
protected String getString(Map<String, Object> map, int resoureId) {
return (String) map.get(getString(resoureId));
}
protected int getInt(Map<String, Object> map, int resoureId) {
return (Integer) map.get(getString(resoureId));
}
protected boolean getBoolean(Map<String, Object> map, int resoureId) {
return (Boolean) map.get(getString(resoureId));
}
protected Uri getUri(Map<String, Object> map, int resoureId) {
return (Uri) map.get(getString(resoureId));
}
/**
* @param intent
* @return Whether an operation succeed.
*/
private boolean operation(Operation selected) {
Map<String, Object> source = getValues();
if (selected == Operation.read)
setPreferences(source);
else {
Map<String, Object> result = getPreferences(source);
for (Entry<String, Object> entry : source.entrySet())
if (!result.containsKey(entry.getKey()))
result.put(entry.getKey(), entry.getValue());
if (selected == Operation.save)
return setValues(source, result);
else if (selected == Operation.discard) {
for (String key : source.keySet())
if (hasChanges(source, result, key))
return false;
} else
throw new IllegalStateException();
}
return true;
}
/**
* @param source
* @param result
* @param key
* @return Whether value has been changed.
*/
protected boolean hasChanges(Map<String, Object> source,
Map<String, Object> result, String key) {
Object sourceValue = source.get(key);
Object targetValue = result.get(key);
return (sourceValue == null && targetValue != null)
|| (sourceValue != null && !sourceValue.equals(targetValue));
}
/**
* @param source
* @param result
* @param resourceId
* @return Whether value has been changed.
*/
protected boolean hasChanges(Map<String, Object> source,
Map<String, Object> result, int resourceId) {
return hasChanges(source, result, getString(resourceId));
}
/**
* @return Map with source values.
*/
protected abstract Map<String, Object> getValues();
/**
* Set values to the UI elements.
*
* @param source
*/
protected void setPreferences(Map<String, Object> source) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
Object value = source.get(preference.getKey());
setPreference(preference, value);
}
}
/**
* Set value to the UI element.
*
* @param preference
* @param value
*/
protected void setPreference(Preference preference, Object value) {
if (preference instanceof EditTextPreference)
((EditTextPreference) preference)
.setText(value instanceof Integer ? String.valueOf(value)
: (String) value);
else if (preference instanceof CheckBoxPreference)
((CheckBoxPreference) preference).setChecked((Boolean) value);
else if (preference instanceof ListPreference)
((ListPreference) preference).setValueIndex((Integer) value);
else if (preference instanceof RingtonePreference)
((RingtonePreference) preference).setUri((Uri) value);
}
/**
* Get values from the UI elements.
*
* @param source
* @return
*/
protected Map<String, Object> getPreferences(Map<String, Object> source) {
Map<String, Object> result = new HashMap<String, Object>();
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
result.put(preference.getKey(), getPrefecence(preference, source));
}
return result;
}
/**
* Get value from the UI element.
*
* @param preference
* @param source
* @return
*/
protected Object getPrefecence(Preference preference,
Map<String, Object> source) {
if (preference instanceof PreferenceScreen)
return null;
else if (preference instanceof EditTextPreference) {
String value = ((EditTextPreference) preference).getText();
if (source.get(preference.getKey()) instanceof Integer)
try {
return Integer.parseInt(value);
} catch (Exception NumberFormatException) {
return null;
}
else
return value;
} else if (preference instanceof CheckBoxPreference)
return ((CheckBoxPreference) preference).isChecked();
else if (preference instanceof ListPreference)
return Integer
.valueOf(((ListPreference) preference)
.findIndexOfValue(((ListPreference) preference)
.getValue()));
else if (preference instanceof RingtonePreference)
return ((RingtonePreference) preference).getUri();
throw new IllegalStateException();
}
/**
* Apply result values.
*
* @param source
* @param result
* @return Whether operation succeed.
*/
protected abstract boolean setValues(Map<String, Object> source,
Map<String, Object> result);
}
......@@ -33,11 +33,11 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.AccountEditor;
import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.ChatViewer;
import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactEditor;
import com.xabber.android.ui.ContactViewer;
import com.xabber.android.ui.preferences.ContactViewer;
import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.StatusEditor;
import com.xabber.android.ui.adapter.UpdatableAdapter;
......
......@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import com.xabber.android.data.ActivityManager;
......@@ -28,7 +28,7 @@ import com.xabber.android.data.ActivityManager;
* @author alexander.ivanov
*
*/
public abstract class ManagedActivity extends FragmentActivity {
public abstract class ManagedActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
......
......@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.widget.ListAdapter;
import android.widget.ListView;
......@@ -30,7 +30,7 @@ import com.xabber.android.data.ActivityManager;
* @author alexander.ivanov
*
*/
public abstract class ManagedListActivity extends FragmentActivity {
public abstract class ManagedListActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
......
......@@ -32,19 +32,41 @@ public final class PreferenceSummaryHelper {
public static void updateSummary(PreferenceGroup group) {
for (int index = 0; index < group.getPreferenceCount(); index++) {
Preference preference = group.getPreference(index);
if (preference instanceof PreferenceGroup)
if (preference instanceof PreferenceGroup) {
updateSummary((PreferenceGroup) preference);
String title = preference.getTitle().toString();
int delimeter = title.indexOf("\n");
if (delimeter == -1)
}
String titleAndSummary = preference.getTitle().toString();
if (!isTitleAndSummary(titleAndSummary)) {
continue;
preference.setTitle(title.substring(0, delimeter));
if (preference instanceof DialogPreference)
((DialogPreference) preference).setDialogTitle(preference
.getTitle());
preference
.setSummary(title.substring(delimeter + 1, title.length()));
}
preference.setTitle(getPreferenceTitle(titleAndSummary));
if (preference instanceof DialogPreference) {
((DialogPreference) preference).setDialogTitle(preference.getTitle());
}
preference.setSummary(getPreferenceSummary(titleAndSummary));
}
}
private static boolean isTitleAndSummary(String titleAndSummary) {
return titleAndSummary.contains("\n");
}
public static String getPreferenceTitle(String titleAndSummary) {
int delimiter = titleAndSummary.indexOf("\n");
if (delimiter == -1) {
return titleAndSummary;
}
return titleAndSummary.substring(0, delimiter);
}
private static String getPreferenceSummary(String titleAndSummary) {
int delimiter = titleAndSummary.indexOf("\n");
if (delimiter == -1) {
return "";
}
return titleAndSummary.substring(delimiter + 1, titleAndSummary.length());
}
}
......@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
......@@ -39,7 +39,7 @@ public class AboutViewer extends ManagedActivity {
((TextView) findViewById(R.id.about_license))
.setMovementMethod(LinkMovementMethod.getInstance());
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
private String getVersionName() {
......
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.preferences;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.ui.OAuthActivity;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class AccountEditor extends ManagedActivity implements
OnPreferenceClickListener, AccountEditorFragment.AccountEditorFragmentInteractionListener {
private static final int OAUTH_WML_REQUEST_CODE = 1;
private static final String SAVED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.TOKEN";
public static final String INVALIDATED_TOKEN = "com.xabber.android.ui.preferences.AccountEditor.INVALIDATED";
private static final int ORBOT_DIALOG_ID = 9050;
private String account;
private AccountItem accountItem;
private String token;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
account = AccountEditor.getAccount(getIntent());
if (account == null) {
finish();
return;
}
accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
finish();
return;
}
if (savedInstanceState == null) {
token = accountItem.getConnectionSettings().getPassword();
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new AccountEditorFragment()).commit();
} else {
token = savedInstanceState.getString(SAVED_TOKEN);
}
setTitle(AccountManager.getInstance().getVerboseName(account));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_preferences);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_TOKEN, token);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OAUTH_WML_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
if (OAuthActivity.isInvalidated(data)) {
token = INVALIDATED_TOKEN;
} else {
String value = OAuthActivity.getToken(data);
if (value == null)
Application.getInstance().onError(
R.string.AUTHENTICATION_FAILED);
else
token = value;
}
((AccountEditorFragment)getFragmentManager().findFragmentById(
R.id.preferences_activity_container)).onOAuthChange();
}
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (getString(R.string.account_oauth_key).equals(preference.getKey())) {
startActivityForResult(OAuthActivity.createIntent(this, accountItem
.getConnectionSettings().getProtocol()),
OAUTH_WML_REQUEST_CODE);
return true;
}
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
if (id == ORBOT_DIALOG_ID) {
return new OrbotInstallerDialogBuilder(this, ORBOT_DIALOG_ID)
.create();
}
return super.onCreateDialog(id);
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
public static Intent createIntent(Context context, String account) {
return new AccountIntentBuilder(context, AccountEditor.class)
.setAccount(account).build();
}
@Override
public String getAccount() {
return account;
}
@Override
public AccountItem getAccountItem() {
return accountItem;
}
@Override
public String getToken() {
return token;
}
@Override
public void onOAuthClick() {
startActivityForResult(OAuthActivity.createIntent(this, accountItem
.getConnectionSettings().getProtocol()),
OAUTH_WML_REQUEST_CODE);
}
@Override
public void showOrbotDialog() {
showDialog(ORBOT_DIALOG_ID);
}
}
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.AccountProtocol;
import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.connection.ProxyType;
import com.xabber.android.data.connection.TLSMode;
import com.xabber.android.ui.helper.OrbotHelper;
import com.xabber.androiddev.R;
import java.util.HashMap;
import java.util.Map;
public class AccountEditorFragment extends BaseSettingsFragment
implements Preference.OnPreferenceClickListener {
private AccountEditorFragmentInteractionListener mListener;
private Preference oauthPreference;
@Override
protected void onInflate(Bundle savedInstanceState) {
AccountProtocol protocol = mListener.getAccountItem().getConnectionSettings()
.getProtocol();
if (protocol == AccountProtocol.xmpp)
addPreferencesFromResource(R.xml.account_editor_xmpp);
else if (protocol == AccountProtocol.gtalk)
addPreferencesFromResource(R.xml.account_editor_xmpp);
else if (protocol == AccountProtocol.wlm)
addPreferencesFromResource(R.xml.account_editor_oauth);
else
throw new IllegalStateException();
if (!Application.getInstance().isContactsSupported())
getPreferenceScreen().removePreference(
findPreference(getString(R.string.account_syncable_key)));
oauthPreference = findPreference(getString(R.string.account_oauth_key));
if (oauthPreference != null) {
oauthPreference.setOnPreferenceClickListener(this);
}
onOAuthChange();
AccountManager.getInstance().removeAuthorizationError(mListener.getAccount());
}
@Override
public void onPause() {
super.onPause();
saveChanges();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (getString(R.string.account_port_key).equals(preference.getKey()))
try {
Integer.parseInt((String) newValue);
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), getString(R.string.account_invalid_port),
Toast.LENGTH_LONG).show();
return false;
}
if (getString(R.string.account_tls_mode_key)
.equals(preference.getKey())
|| getString(R.string.account_archive_mode_key).equals(
preference.getKey())
|| getString(R.string.account_proxy_type_key).equals(
preference.getKey()))
preference.setSummary((String) newValue);
else if (!getString(R.string.account_password_key).equals(
preference.getKey())
&& !getString(R.string.account_proxy_password_key).equals(
preference.getKey())
&& !getString(R.string.account_priority_key).equals(
preference.getKey()))
super.onPreferenceChange(preference, newValue);
if (getString(R.string.account_proxy_type_key).equals(
preference.getKey())) {
boolean enabled = !getString(R.string.account_proxy_type_none)
.equals(newValue)
&& !getString(R.string.account_proxy_type_orbot).equals(
newValue);
for (int id : new Integer[] { R.string.account_proxy_host_key,
R.string.account_proxy_port_key,
R.string.account_proxy_user_key,
R.string.account_proxy_password_key, }) {
Preference proxyPreference = findPreference(getString(id));
if (proxyPreference != null)
proxyPreference.setEnabled(enabled);
}
}
return true;
}
public void onOAuthChange() {
if (oauthPreference == null)
return;
if (AccountEditor.INVALIDATED_TOKEN.equals(mListener.getToken()))
oauthPreference.setSummary(R.string.account_oauth_invalidated);
else
oauthPreference.setSummary(R.string.account_oauth_summary);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (getString(R.string.account_oauth_key).equals(preference.getKey())) {
mListener.onOAuthClick();
return true;
}
return false;
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> source = new HashMap<>();
AccountItem accountItem = mListener.getAccountItem();
putValue(source, R.string.account_custom_key, accountItem
.getConnectionSettings().isCustom());
putValue(source, R.string.account_host_key, accountItem
.getConnectionSettings().getHost());
putValue(source, R.string.account_port_key, accountItem
.getConnectionSettings().getPort());
putValue(source, R.string.account_server_key, accountItem
.getConnectionSettings().getServerName());
putValue(source, R.string.account_username_key, accountItem
.getConnectionSettings().getUserName());
putValue(source, R.string.account_store_password_key, accountItem.isStorePassword());
putValue(source, R.string.account_password_key, accountItem
.getConnectionSettings().getPassword());
putValue(source, R.string.account_resource_key, accountItem
.getConnectionSettings().getResource());
putValue(source, R.string.account_priority_key, accountItem.getPriority());
putValue(source, R.string.account_enabled_key, accountItem.isEnabled());
putValue(source, R.string.account_sasl_key, accountItem
.getConnectionSettings().isSaslEnabled());
putValue(source, R.string.account_tls_mode_key,
accountItem.getConnectionSettings().getTlsMode().ordinal());
putValue(source, R.string.account_compression_key, accountItem
.getConnectionSettings().useCompression());
putValue(source, R.string.account_proxy_type_key,
accountItem.getConnectionSettings().getProxyType().ordinal());
putValue(source, R.string.account_proxy_host_key, accountItem
.getConnectionSettings().getProxyHost());
putValue(source, R.string.account_proxy_port_key, accountItem
.getConnectionSettings().getProxyPort());
putValue(source, R.string.account_proxy_user_key, accountItem
.getConnectionSettings().getProxyUser());
putValue(source, R.string.account_proxy_password_key, accountItem
.getConnectionSettings().getProxyPassword());
putValue(source, R.string.account_syncable_key,
accountItem.isSyncable());
putValue(source, R.string.account_archive_mode_key,
accountItem.getArchiveMode().ordinal());
return source;
}
@Override
protected Map<String, Object> getPreferences(Map<String, Object> source) {
Map<String, Object> result = super.getPreferences(source);
if (oauthPreference != null)
putValue(result, R.string.account_password_key, mListener.getAccount());
return result;
}
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
ProxyType proxyType = ProxyType.values()[getInt(result,
R.string.account_proxy_type_key)];
if (proxyType == ProxyType.orbot && !OrbotHelper.isOrbotInstalled()) {
mListener.showOrbotDialog();
return false;
}
AccountManager.getInstance().updateAccount(
mListener.getAccount(),
getBoolean(result, R.string.account_custom_key),
getString(result, R.string.account_host_key),
getInt(result, R.string.account_port_key),
getString(result, R.string.account_server_key),
getString(result, R.string.account_username_key),
getBoolean(result, R.string.account_store_password_key),
getString(result, R.string.account_password_key),
getString(result, R.string.account_resource_key),
getInt(result, R.string.account_priority_key),
getBoolean(result, R.string.account_enabled_key),
getBoolean(result, R.string.account_sasl_key),
TLSMode.values()[getInt(result, R.string.account_tls_mode_key)],
getBoolean(result, R.string.account_compression_key),
proxyType,
getString(result, R.string.account_proxy_host_key),
getInt(result, R.string.account_proxy_port_key),
getString(result, R.string.account_proxy_user_key),
getString(result, R.string.account_proxy_password_key),
getBoolean(result, R.string.account_syncable_key),
ArchiveMode.values()[getInt(result, R.string.account_archive_mode_key)]);
return true;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (AccountEditorFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement AccountEditorFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface AccountEditorFragmentInteractionListener {
public String getAccount();
public AccountItem getAccountItem();
public String getToken();
public void onOAuthClick();
public void showOrbotDialog();
}
}
......@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
package com.xabber.android.ui.preferences;
import java.util.Collection;
......@@ -26,9 +26,11 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.ui.AccountAdd;
import com.xabber.android.ui.StatusEditor;
import com.xabber.android.ui.adapter.AccountListAdapter;
import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.helper.BaseListEditor;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class AccountList extends BaseListEditor<String> implements
......@@ -40,12 +42,19 @@ public class AccountList extends BaseListEditor<String> implements
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_accounts)));
}
@Override
protected int getOptionsMenuId() {
return R.menu.add_account;
}
@Override
protected int getAddTextResourceId() {
return R.string.account_add;
protected int getAddActionId() {
return R.id.action_add_account;
}
@Override
......
......@@ -12,26 +12,25 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.helper;
package com.xabber.android.ui.preferences;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.TextView;
import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.dialog.ConfirmDialogBuilder;
import com.xabber.android.ui.dialog.ConfirmDialogListener;
import com.xabber.android.ui.dialog.DialogBuilder;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
/**
......@@ -46,7 +45,6 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
private static final String SAVED_ACTION_WITH = "com.xabber.android.ui.BaseListActivity.SAVED_ACTION_WITH";
private static final int OPTION_MENU_ADD_ID = Menu.FIRST;
private static final int CONTEXT_MENU_DELETE_ID = 0x10;
private static final int DIALOG_DELETE_ID = 0x100;
......@@ -65,11 +63,6 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
else
actionWith = null;
ListView listView = getListView();
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.add_item, null, true);
((TextView) view.findViewById(android.R.id.message))
.setText(getAddTextResourceId());
listView.addFooterView(view, null, true);
listView.setOnItemClickListener(this);
registerForContextMenu(listView);
adapter = createListAdapter();
......@@ -90,7 +83,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
protected abstract void putSavedValue(Bundle bundle, String key,
T actionWith);
protected abstract int getAddTextResourceId();
protected abstract int getOptionsMenuId();
protected abstract int getAddActionId();
protected abstract Intent getAddIntent();
......@@ -124,9 +119,8 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_ADD_ID, 0, getString(getAddTextResourceId()))
.setIcon(android.R.drawable.ic_menu_add)
.setIntent(getAddIntent());
getMenuInflater().inflate(getOptionsMenuId(), menu);
menu.findItem(getAddActionId()).setIntent(getAddIntent());
return true;
}
......@@ -175,13 +169,11 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
T actionWith = (T) parent.getAdapter().getItem(position);
Intent intent;
if (actionWith == null)
intent = getAddIntent();
else
intent = getEditIntent(actionWith);
if (actionWith != null) {
Intent intent = getEditIntent(actionWith);
startActivity(intent);
}
}
@Override
public void onAccept(DialogBuilder dialogBuilder) {
......
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public abstract class BasePhrasePreferences extends ManagedActivity
implements PhraseEditorFragment.OnPhraseEditorFragmentInteractionListener {
private Phrase phrase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_preferences);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
}
}
@Override
public Phrase getPhrase() {
return phrase;
}
@Override
public void setPhrase(Phrase phrase) {
this.phrase = phrase;
}
}
package com.xabber.android.ui.preferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.android.ui.widget.RingtonePreference;
import java.util.HashMap;
import java.util.Map;
public abstract class BaseSettingsFragment extends PreferenceFragment
implements Preference.OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onInflate(savedInstanceState);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
if (savedInstanceState == null)
operation(Operation.read);
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
preference.setOnPreferenceChangeListener(this);
if (preference instanceof EditTextPreference)
onPreferenceChange(preference,
((EditTextPreference) preference).getText());
else if (preference instanceof CheckBoxPreference)
onPreferenceChange(preference,
((CheckBoxPreference) preference).isChecked());
else if (preference instanceof ListPreference)
onPreferenceChange(preference,
((ListPreference) preference).getValue());
}
}
/**
* Inflates layout.
*
* @param savedInstanceState
*/
protected abstract void onInflate(Bundle savedInstanceState);
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference instanceof EditTextPreference)
preference.setSummary((String) newValue);
return true;
}
/**
* Possible operations.
*/
private static enum Operation {
save, discard, read
}
protected void putValue(Map<String, Object> map, int resoureId, Object value) {
map.put(getString(resoureId), value);
}
protected String getString(Map<String, Object> map, int resoureId) {
return (String) map.get(getString(resoureId));
}
protected int getInt(Map<String, Object> map, int resoureId) {
return (Integer) map.get(getString(resoureId));
}
protected boolean getBoolean(Map<String, Object> map, int resoureId) {
return (Boolean) map.get(getString(resoureId));
}
protected Uri getUri(Map<String, Object> map, int resoureId) {
return (Uri) map.get(getString(resoureId));
}
/**
* @param intent
* @return Whether an operation succeed.
*/
private boolean operation(Operation selected) {
Map<String, Object> source = getValues();
if (selected == Operation.read)
setPreferences(source);
else {
Map<String, Object> result = getPreferences(source);
for (Map.Entry<String, Object> entry : source.entrySet())
if (!result.containsKey(entry.getKey()))
result.put(entry.getKey(), entry.getValue());
if (selected == Operation.save)
return setValues(source, result);
else if (selected == Operation.discard) {
for (String key : source.keySet())
if (hasChanges(source, result, key))
return false;
} else
throw new IllegalStateException();
}
return true;
}
/**
* @param source
* @param result
* @param key
* @return Whether value has been changed.
*/
protected boolean hasChanges(Map<String, Object> source,
Map<String, Object> result, String key) {
Object sourceValue = source.get(key);
Object targetValue = result.get(key);
return (sourceValue == null && targetValue != null)
|| (sourceValue != null && !sourceValue.equals(targetValue));
}
/**
* @param source
* @param result
* @param resourceId
* @return Whether value has been changed.
*/
protected boolean hasChanges(Map<String, Object> source,
Map<String, Object> result, int resourceId) {
return hasChanges(source, result, getString(resourceId));
}
/**
* @return Map with source values.
*/
protected abstract Map<String, Object> getValues();
/**
* Set values to the UI elements.
*
* @param source
*/
protected void setPreferences(Map<String, Object> source) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
Object value = source.get(preference.getKey());
setPreference(preference, value);
}
}
/**
* Set value to the UI element.
*
* @param preference
* @param value
*/
protected void setPreference(Preference preference, Object value) {
if (preference instanceof EditTextPreference)
((EditTextPreference) preference)
.setText(value instanceof Integer ? String.valueOf(value)
: (String) value);
else if (preference instanceof CheckBoxPreference)
((CheckBoxPreference) preference).setChecked((Boolean) value);
else if (preference instanceof ListPreference)
((ListPreference) preference).setValueIndex((Integer) value);
else if (preference instanceof RingtonePreference)
((RingtonePreference) preference).setUri((Uri) value);
}
/**
* Get values from the UI elements.
*
* @param source
* @return
*/
protected Map<String, Object> getPreferences(Map<String, Object> source) {
Map<String, Object> result = new HashMap<>();
PreferenceScreen preferenceScreen = getPreferenceScreen();
for (int index = 0; index < preferenceScreen.getPreferenceCount(); index++) {
Preference preference = preferenceScreen.getPreference(index);
result.put(preference.getKey(), getPreference(preference, source));
}
return result;
}
/**
* Get value from the UI element.
*
* @param preference
* @param source
* @return
*/
protected Object getPreference(Preference preference, Map<String, Object> source) {
if (preference instanceof PreferenceScreen) {
return null;
} else if (preference instanceof EditTextPreference) {
String value = ((EditTextPreference) preference).getText();
if (source.get(preference.getKey()) instanceof Integer)
try {
return Integer.parseInt(value);
} catch (Exception NumberFormatException) {
return null;
}
else
return value;
} else if (preference instanceof CheckBoxPreference)
return ((CheckBoxPreference) preference).isChecked();
else if (preference instanceof ListPreference)
return ((ListPreference) preference)
.findIndexOfValue(((ListPreference) preference).getValue());
else if (preference instanceof RingtonePreference)
return ((RingtonePreference) preference).getUri();
throw new IllegalStateException();
}
/**
* Apply result values.
*
* @param source
* @param result
* @return Whether operation succeed.
*/
protected abstract boolean setValues(Map<String, Object> source, Map<String, Object> result);
protected boolean saveChanges() {
return operation(Operation.save);
}
}
package com.xabber.android.ui.preferences;
import android.app.ProgressDialog;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.androiddev.R;
public class CacheClearDialog extends DialogPreference {
public CacheClearDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
AccountManager.getInstance().setStatus(StatusMode.unavailable, null);
Application.getInstance().requestToClear();
Application.getInstance().requestToClose();
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getContext().getString(R.string.application_state_closing));
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
}
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
public class ChatEditor extends ManagedActivity
implements ChatEditorFragment.ChatEditorFragmentInteractionListener {
private String account;
private String user;
private AccountItem accountItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
account = getAccount(getIntent());
user = getUser(getIntent());
accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
setContentView(R.layout.activity_preferences);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ChatEditorFragment()).commit();
}
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ChatEditor.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return EntityIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
@Override
public String getAccount() {
return account;
}
@Override
public AccountItem getAccountItem() {
return accountItem;
}
@Override
public String getUser() {
return user;
}
}
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.os.Bundle;
import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.ArchiveMode;
import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.androiddev.R;
import java.util.HashMap;
import java.util.Map;
public class ChatEditorFragment extends BaseSettingsFragment {
private ChatEditorFragmentInteractionListener mListener;
@Override
protected void onInflate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.chat_editor);
AccountItem accountItem = mListener.getAccountItem();
if (accountItem.getArchiveMode() == ArchiveMode.server
|| accountItem.getArchiveMode() == ArchiveMode.dontStore) {
getPreferenceScreen().removePreference(getPreferenceScreen()
.findPreference(getString(R.string.chat_save_history_key)));
}
}
@Override
public void onPause() {
super.onPause();
saveChanges();
}
@Override
protected Map<String, Object> getValues() {
Map<String, Object> map = new HashMap<>();
String account = mListener.getAccount();
String user = mListener.getUser();
putValue(map, R.string.chat_save_history_key, ChatManager.getInstance()
.isSaveMessages(account, user));
putValue(map, R.string.chat_events_visible_chat_key, ChatManager
.getInstance().isNotifyVisible(account, user));
putValue(map, R.string.chat_events_show_text_key, ChatManager
.getInstance().isShowText(account, user));
putValue(map, R.string.chat_events_vibro_key, ChatManager.getInstance()
.isMakeVibro(account, user));
putValue(map, R.string.chat_events_sound_key, ChatManager.getInstance()
.getSound(account, user));
return map;
}
@Override
protected boolean setValues(Map<String, Object> source, Map<String, Object> result) {
String account = mListener.getAccount();
String user = mListener.getUser();
if (hasChanges(source, result, R.string.chat_save_history_key))
ChatManager.getInstance().setSaveMessages(account, user,
getBoolean(result, R.string.chat_save_history_key));
if (hasChanges(source, result, R.string.chat_events_visible_chat_key))
ChatManager.getInstance().setNotifyVisible(account, user,
getBoolean(result, R.string.chat_events_visible_chat_key));
if (hasChanges(source, result, R.string.chat_events_show_text_key))
ChatManager.getInstance().setShowText(account, user,
getBoolean(result, R.string.chat_events_show_text_key));
if (hasChanges(source, result, R.string.chat_events_vibro_key))
ChatManager.getInstance().setMakeVibro(account, user,
getBoolean(result, R.string.chat_events_vibro_key));
if (hasChanges(source, result, R.string.chat_events_sound_key))
ChatManager.getInstance().setSound(account, user,
getUri(result, R.string.chat_events_sound_key));
return true;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (ChatEditorFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement ChatEditorFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface ChatEditorFragmentInteractionListener {
public String getAccount();
public AccountItem getAccountItem();
public String getUser();
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ChatSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.chat_viewer)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ChatSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ChatSettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_chat);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ConnectionSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_connection)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ConnectionSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ConnectionSettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_connection);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ContactListSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_contacts)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ContactListSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ContactListSettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences_contact_list);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.contacts_show_accounts_key))
|| key.equals(getString(R.string.contacts_show_groups_key))) {
changeGrouping();
}
}
private void changeGrouping() {
boolean grouped = SettingsManager.contactsShowAccounts()
|| SettingsManager.contactsShowGroups();
((CheckBoxPreference) getPreferenceScreen().findPreference(
getString(R.string.contacts_stay_active_chats_key)))
.setChecked(grouped);
getPreferenceScreen().findPreference(getString(R.string.contacts_show_empty_groups_key))
.setEnabled(grouped);
}
}
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.xabber.android.data.roster.GroupManager;
public class ContactResetOfflineSettingsDialog extends DialogPreference {
public ContactResetOfflineSettingsDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
GroupManager.getInstance().resetShowOfflineModes();
}
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.vcard.OnVCardListener;
import com.xabber.android.data.extension.vcard.VCardManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.vcard.AddressProperty;
import com.xabber.xmpp.vcard.AddressType;
import com.xabber.xmpp.vcard.EmailType;
import com.xabber.xmpp.vcard.TelephoneType;
import com.xabber.xmpp.vcard.VCard;
import com.xabber.xmpp.vcard.VCardProvider;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.StringReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ContactViewer extends ManagedActivity implements
OnVCardListener, OnContactChangedListener, OnAccountChangedListener {
private static final String SAVED_VCARD = "com.xabber.android.ui.preferences.ContactViewer.SAVED_VCARD";
private static final String SAVED_VCARD_ERROR = "com.xabber.android.ui.preferences.ContactViewer.SAVED_VCARD_ERROR";
private String account;
private String bareAddress;
private VCard vCard;
private boolean vCardError;
private static final Map<AddressType, Integer> ADDRESS_TYPE_MAP = new HashMap<>();
private static final Map<AddressProperty, Integer> ADDRESS_PROPERTY_MAP = new HashMap<>();
private static final Map<TelephoneType, Integer> TELEPHONE_TYPE_MAP = new HashMap<>();
private static final Map<EmailType, Integer> EMAIL_TYPE_MAP = new HashMap<>();
static {
ADDRESS_TYPE_MAP.put(AddressType.DOM, R.string.vcard_type_dom);
ADDRESS_TYPE_MAP.put(AddressType.HOME, R.string.vcard_type_home);
ADDRESS_TYPE_MAP.put(AddressType.INTL, R.string.vcard_type_intl);
ADDRESS_TYPE_MAP.put(AddressType.PARCEL, R.string.vcard_type_parcel);
ADDRESS_TYPE_MAP.put(AddressType.POSTAL, R.string.vcard_type_postal);
ADDRESS_TYPE_MAP.put(AddressType.PREF, R.string.vcard_type_pref);
ADDRESS_TYPE_MAP.put(AddressType.WORK, R.string.vcard_type_work);
if (ADDRESS_TYPE_MAP.size() != AddressType.values().length)
throw new IllegalStateException();
ADDRESS_PROPERTY_MAP.put(AddressProperty.CTRY,
R.string.vcard_address_ctry);
ADDRESS_PROPERTY_MAP.put(AddressProperty.EXTADR,
R.string.vcard_address_extadr);
ADDRESS_PROPERTY_MAP.put(AddressProperty.LOCALITY,
R.string.vcard_address_locality);
ADDRESS_PROPERTY_MAP.put(AddressProperty.PCODE,
R.string.vcard_address_pcode);
ADDRESS_PROPERTY_MAP.put(AddressProperty.POBOX,
R.string.vcard_address_pobox);
ADDRESS_PROPERTY_MAP.put(AddressProperty.REGION,
R.string.vcard_address_region);
ADDRESS_PROPERTY_MAP.put(AddressProperty.STREET,
R.string.vcard_address_street);
if (ADDRESS_PROPERTY_MAP.size() != AddressProperty.values().length)
throw new IllegalStateException();
TELEPHONE_TYPE_MAP.put(TelephoneType.BBS, R.string.vcard_type_bbs);
TELEPHONE_TYPE_MAP.put(TelephoneType.CELL, R.string.vcard_type_cell);
TELEPHONE_TYPE_MAP.put(TelephoneType.FAX, R.string.vcard_type_fax);
TELEPHONE_TYPE_MAP.put(TelephoneType.HOME, R.string.vcard_type_home);
TELEPHONE_TYPE_MAP.put(TelephoneType.ISDN, R.string.vcard_type_isdn);
TELEPHONE_TYPE_MAP.put(TelephoneType.MODEM, R.string.vcard_type_modem);
TELEPHONE_TYPE_MAP.put(TelephoneType.MSG, R.string.vcard_type_msg);
TELEPHONE_TYPE_MAP.put(TelephoneType.PAGER, R.string.vcard_type_pager);
TELEPHONE_TYPE_MAP.put(TelephoneType.PCS, R.string.vcard_type_pcs);
TELEPHONE_TYPE_MAP.put(TelephoneType.PREF, R.string.vcard_type_pref);
TELEPHONE_TYPE_MAP.put(TelephoneType.VIDEO, R.string.vcard_type_video);
TELEPHONE_TYPE_MAP.put(TelephoneType.VOICE, R.string.vcard_type_voice);
TELEPHONE_TYPE_MAP.put(TelephoneType.WORK, R.string.vcard_type_work);
if (TELEPHONE_TYPE_MAP.size() != TelephoneType.values().length)
throw new IllegalStateException();
EMAIL_TYPE_MAP.put(EmailType.HOME, R.string.vcard_type_home);
EMAIL_TYPE_MAP.put(EmailType.INTERNET, R.string.vcard_type_internet);
EMAIL_TYPE_MAP.put(EmailType.PREF, R.string.vcard_type_pref);
EMAIL_TYPE_MAP.put(EmailType.WORK, R.string.vcard_type_work);
EMAIL_TYPE_MAP.put(EmailType.X400, R.string.vcard_type_x400);
if (EMAIL_TYPE_MAP.size() != EmailType.values().length)
throw new IllegalStateException();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
// View information about contact from system contact list
Uri data = getIntent().getData();
if (data != null && "content".equals(data.getScheme())) {
List<String> segments = data.getPathSegments();
if (segments.size() == 2 && "data".equals(segments.get(0))) {
Long id;
try {
id = Long.valueOf(segments.get(1));
} catch (NumberFormatException e) {
id = null;
}
if (id != null)
// FIXME: Will be empty while application is loading
for (RosterContact rosterContact : RosterManager
.getInstance().getContacts())
if (id.equals(rosterContact.getViewId())) {
account = rosterContact.getAccount();
bareAddress = rosterContact.getUser();
break;
}
}
}
} else {
account = getAccount(getIntent());
bareAddress = Jid.getBareAddress(getUser(getIntent()));
}
if (account == null || bareAddress == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish();
return;
}
vCard = null;
vCardError = false;
if (savedInstanceState != null) {
vCardError = savedInstanceState
.getBoolean(SAVED_VCARD_ERROR, false);
String xml = savedInstanceState.getString(SAVED_VCARD);
if (xml != null)
try {
XmlPullParser parser = XmlPullParserFactory.newInstance()
.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
true);
parser.setInput(new StringReader(xml));
int eventType = parser.next();
if (eventType != XmlPullParser.START_TAG)
throw new IllegalStateException(
String.valueOf(eventType));
if (!VCard.ELEMENT_NAME.equals(parser.getName()))
throw new IllegalStateException(parser.getName());
if (!VCard.NAMESPACE.equals(parser.getNamespace()))
throw new IllegalStateException(parser.getNamespace());
vCard = (VCard) (new VCardProvider()).parseIQ(parser);
} catch (Exception e) {
LogManager.exception(this, e);
}
}
setTitle(getString(R.string.contact_viewer));
setContentView(R.layout.activity_preferences);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ContactViewerFragment()).commit();
}
}
@Override
protected void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnVCardListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
if (vCard == null && !vCardError)
VCardManager.getInstance().request(account, bareAddress, null);
ContactViewerFragment contactViewerFragment = getFragment();
contactViewerFragment.updateContact(account, bareAddress);
contactViewerFragment.updateVCard(vCard);
}
private ContactViewerFragment getFragment() {
return (ContactViewerFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container);
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(OnVCardListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(SAVED_VCARD_ERROR, vCardError);
if (vCard != null)
outState.putString(SAVED_VCARD, vCard.getChildElementXML());
}
@Override
public void onVCardReceived(String account, String bareAddress, VCard vCard) {
if (!this.account.equals(account)
|| !this.bareAddress.equals(bareAddress))
return;
this.vCard = vCard;
this.vCardError = false;
getFragment().updateVCard(vCard);
}
@Override
public void onVCardFailed(String account, String bareAddress) {
if (!this.account.equals(account)
|| !this.bareAddress.equals(bareAddress))
return;
this.vCard = null;
this.vCardError = true;
getFragment().updateVCard(vCard);
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
}
@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
for (BaseEntity entity : entities)
if (entity.equals(account, bareAddress)) {
getFragment().updateContact(account, bareAddress);
break;
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
if (accounts.contains(account))
getFragment().updateContact(account, bareAddress);
}
public static Intent createIntent(Context context, String account,
String user) {
return new EntityIntentBuilder(context, ContactViewer.class)
.setAccount(account).setUser(user).build();
}
private static String getAccount(Intent intent) {
return AccountIntentBuilder.getAccount(intent);
}
private static String getUser(Intent intent) {
return EntityIntentBuilder.getUser(intent);
}
public static Map<AddressType, Integer> getAddressTypeMap() {
return ADDRESS_TYPE_MAP;
}
public static Map<AddressProperty, Integer> getAddressPropertyMap() {
return ADDRESS_PROPERTY_MAP;
}
public static Map<TelephoneType, Integer> getTelephoneTypeMap() {
return TELEPHONE_TYPE_MAP;
}
public static Map<EmailType, Integer> getEmailTypeMap() {
return EMAIL_TYPE_MAP;
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ResourceItem;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.android.ui.widget.StatusPreference;
import com.xabber.androiddev.R;
import com.xabber.xmpp.vcard.Address;
import com.xabber.xmpp.vcard.AddressProperty;
import com.xabber.xmpp.vcard.AddressType;
import com.xabber.xmpp.vcard.Email;
import com.xabber.xmpp.vcard.EmailType;
import com.xabber.xmpp.vcard.NameProperty;
import com.xabber.xmpp.vcard.Organization;
import com.xabber.xmpp.vcard.Telephone;
import com.xabber.xmpp.vcard.TelephoneType;
import com.xabber.xmpp.vcard.VCard;
import com.xabber.xmpp.vcard.VCardProperty;
import java.util.ArrayList;
import java.util.List;
public class ContactViewerFragment extends android.preference.PreferenceFragment {
private List<PreferenceCategory> addresses;
private List<PreferenceCategory> telephones;
private List<PreferenceCategory> emails;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addresses = new ArrayList<>();
telephones = new ArrayList<>();
emails = new ArrayList<>();
addPreferencesFromResource(R.xml.contact_viewer);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
/**
* Sets value for the preference by its id.
*
* @param resourceId
* @param value
*/
private void setValue(int resourceId, String value) {
if (value == null)
value = "";
findPreference(getString(resourceId)).setSummary(value);
}
/**
* @param source
* @param value
* @param splitter
* @return Concatenated source and value with splitter if necessary.
*/
private String addString(String source, String value, String splitter) {
if (value == null || "".equals(value))
return source;
if (source == null || "".equals(source))
return value;
return source + splitter + value;
}
public void updateContact(String account, String bareAddress) {
setValue(R.string.contact_viewer_jid, bareAddress);
RosterContact rosterContact = RosterManager.getInstance()
.getRosterContact(account, bareAddress);
setValue(R.string.contact_viewer_name, rosterContact == null ? null
: rosterContact.getRealName());
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference(getString(R.string.contact_viewer_resources));
preferenceCategory.removeAll();
if (rosterContact != null && rosterContact.isConnected())
for (ResourceItem resourceItem : PresenceManager.getInstance()
.getResourceItems(account, bareAddress)) {
StatusPreference preference = new StatusPreference(getActivity());
preference.setLayoutResource(R.layout.info_preference);
preference.setStatusMode(resourceItem.getStatusMode());
String user = resourceItem.getUser(bareAddress);
ClientInfo clientInfo = CapabilitiesManager.getInstance()
.getClientInfo(account, user);
String client;
if (clientInfo == null) {
CapabilitiesManager.getInstance().request(account, user);
client = getString(R.string.please_wait);
} else if (clientInfo == CapabilitiesManager.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name == null)
name = getString(R.string.unknown);
String type = clientInfo.getType();
if (type == null)
type = getString(R.string.unknown);
client = getString(R.string.contact_viewer_client_info,
name, type);
}
preference.setTitle(getString(
R.string.contact_viewer_resource_summary,
resourceItem.getVerbose(), resourceItem.getPriority(),
client));
preference.setSummary(resourceItem.getStatusText());
preferenceCategory.addPreference(preference);
}
}
public void updateVCard(VCard vCard) {
if (vCard == null)
return;
setValue(R.string.vcard_nick_name,
vCard.getField(VCardProperty.NICKNAME));
setValue(R.string.vcard_formatted_name, vCard.getFormattedName());
setValue(R.string.vcard_prefix_name,
vCard.getField(NameProperty.PREFIX));
setValue(R.string.vcard_given_name, vCard.getField(NameProperty.GIVEN));
setValue(R.string.vcard_middle_name,
vCard.getField(NameProperty.MIDDLE));
setValue(R.string.vcard_family_name,
vCard.getField(NameProperty.FAMILY));
setValue(R.string.vcard_suffix_name,
vCard.getField(NameProperty.SUFFIX));
setValue(R.string.vcard_birth_date, vCard.getField(VCardProperty.BDAY));
setValue(R.string.vcard_title, vCard.getField(VCardProperty.TITLE));
setValue(R.string.vcard_role, vCard.getField(VCardProperty.ROLE));
List<Organization> organizations = vCard.getOrganizations();
String organization;
if (organizations.isEmpty())
organization = null;
else {
organization = organizations.get(0).getName();
for (String unit : organizations.get(0).getUnits())
organization = addString(organization, unit, "\n");
}
setValue(R.string.vcard_organization, organization);
setValue(R.string.vcard_url, vCard.getField(VCardProperty.URL));
String categories = null;
for (String category : vCard.getCategories())
categories = addString(categories, category, "\n");
setValue(R.string.vcard_categories, categories);
setValue(R.string.vcard_note, vCard.getField(VCardProperty.NOTE));
setValue(R.string.vcard_decsription, vCard.getField(VCardProperty.DESC));
PreferenceScreen screen = getPreferenceScreen();
for (PreferenceCategory category : addresses)
screen.removePreference(category);
for (PreferenceCategory category : telephones)
screen.removePreference(category);
for (PreferenceCategory category : emails)
screen.removePreference(category);
for (Address address : vCard.getAddresses()) {
String types = null;
for (AddressType type : address.getTypes())
types = addString(types, getString(ContactViewer.getAddressTypeMap().get(type)),
", ");
String value = null;
for (AddressProperty property : AddressProperty.values())
value = addString(value, address.getProperties().get(property),
"\n");
PreferenceScreen addressScreen = createTypedCategory(
R.string.vcard_address, types, value);
for (AddressProperty property : AddressProperty.values())
addPreferenceScreen(addressScreen,
ContactViewer.getAddressPropertyMap().get(property), address
.getProperties().get(property));
}
for (Telephone telephone : vCard.getTelephones()) {
String types = null;
for (TelephoneType type : telephone.getTypes())
types = addString(types,
getString(ContactViewer.getTelephoneTypeMap().get(type)), ", ");
createTypedCategory(R.string.vcard_telephone, types,
telephone.getValue());
}
for (Email email : vCard.getEmails()) {
String types = null;
for (EmailType type : email.getTypes())
types = addString(types, getString(ContactViewer.getEmailTypeMap().get(type)),
", ");
createTypedCategory(R.string.vcard_email, types, email.getValue());
}
}
private PreferenceScreen createTypedCategory(int title, String types,
String value) {
PreferenceCategory preferenceCategory = new PreferenceCategory(getActivity());
preferenceCategory.setTitle(title);
getPreferenceScreen().addPreference(preferenceCategory);
addPreferenceScreen(preferenceCategory, R.string.vcard_type, types);
return addPreferenceScreen(preferenceCategory, title, value);
}
private PreferenceScreen addPreferenceScreen(PreferenceGroup container,
int title, String summary) {
PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
preference.setLayoutResource(R.layout.info_preference);
preference.setTitle(title);
preference.setSummary(summary == null ? "" : summary);
container.addPreference(preference);
return preference;
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class DebugSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_debug)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new DebugSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.data.LogManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class DebugSettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_debug);
getPreferenceScreen().findPreference(getString(R.string.debug_log_key)).setEnabled(LogManager.isDebugable());
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class NotificationsSettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_events)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new NotificationsSettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class NotificationsSettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_notifications);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.androiddev.R;
public class PhraseAdder extends BasePhrasePreferences {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.phrase_add);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.save, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_save:
boolean success = ((PhraseEditorFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container)).saveChanges();
if (success) {
finish();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public static Intent createIntent(Context context) {
return new SegmentIntentBuilder<>(context, PhraseAdder.class).build();
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.xabber.android.data.Application;
import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.androiddev.R;
public class PhraseEditor extends BasePhrasePreferences {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Integer index = getPhraseIndex(getIntent());
if (index == null) {
finish();
return;
}
Phrase phrase = PhraseManager.getInstance().getPhrase(index);
if (phrase == null) {
finish();
return;
}
setPhrase(phrase);
String title = phrase.getText();
if ("".equals(title))
title = Application.getInstance().getString(
R.string.phrase_empty);
setTitle(title);
}
@Override
protected void onPause() {
super.onPause();
((PhraseEditorFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container)).saveChanges();
}
private Integer getPhraseIndex(Intent intent) {
String value = SegmentIntentBuilder.getSegment(intent, 0);
if (value == null)
return null;
else
return Integer.valueOf(value);
}
public static Intent createIntent(Context context, Integer phraseIndex) {
SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<>(
context, PhraseEditor.class);
if (phraseIndex != null)
builder.addSegment(phraseIndex.toString());
return builder.build();
}
}
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;
import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.androiddev.R;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.PatternSyntaxException;
public class PhraseEditorFragment extends BaseSettingsFragment {
private OnPhraseEditorFragmentInteractionListener mListener;
@Override
protected void onInflate(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.phrase_editor);
}
@Override
protected Map<String, Object> getValues() {
Phrase phrase = mListener.getPhrase();
Map<String, Object> source = new HashMap<>();
putValue(source, R.string.phrase_text_key,
phrase == null ? "" : phrase.getText());
putValue(source, R.string.phrase_user_key,
phrase == null ? "" : phrase.getUser());
putValue(source, R.string.phrase_group_key, phrase == null ? ""
: phrase.getGroup());
putValue(source, R.string.phrase_regexp_key, phrase != null && phrase.isRegexp());
putValue(source, R.string.phrase_sound_key,
phrase == null ? Settings.System.DEFAULT_NOTIFICATION_URI
: phrase.getSound());
return source;
}
@Override
protected boolean setValues(Map<String, Object> source,
Map<String, Object> result) {
String text = getString(result, R.string.phrase_text_key);
String user = getString(result, R.string.phrase_user_key);
String group = getString(result, R.string.phrase_group_key);
boolean regexp = getBoolean(result, R.string.phrase_regexp_key);
Uri sound = getUri(result, R.string.phrase_sound_key);
Log.i("PhraseEditorFragment", "setValues. text: " + text);
if (regexp) {
try {
Phrase.compile(text);
Phrase.compile(user);
Phrase.compile(group);
} catch (PatternSyntaxException e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
return false;
}
}
Phrase phrase = mListener.getPhrase();
if (phrase == null && "".equals(text) && "".equals(user) && "".equals(group)) {
return true;
}
Log.i("PhraseEditorFragment", "updateOrCreatePhrase");
PhraseManager.getInstance().updateOrCreatePhrase(phrase, text, user, group, regexp, sound);
mListener.setPhrase(phrase);
return true;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnPhraseEditorFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnThemeSettingsFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnPhraseEditorFragmentInteractionListener {
public Phrase getPhrase();
public void setPhrase(Phrase phrase);
}
}
......@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
......@@ -22,19 +22,30 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.ui.adapter.BaseListEditorAdapter;
import com.xabber.android.ui.adapter.PhraseListAdapter;
import com.xabber.android.ui.helper.BaseListEditor;
import com.xabber.androiddev.R;
public class PhraseList extends BaseListEditor<Integer> {
@Override
protected int getAddTextResourceId() {
return R.string.phrase_add;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected int getOptionsMenuId() {
return R.menu.add_phrase;
}
@Override
protected int getAddActionId() {
return R.id.action_add_phrase;
}
@Override
protected Intent getAddIntent() {
return PhraseEditor.createIntent(this);
return PhraseAdder.createIntent(this);
}
@Override
......
......@@ -12,71 +12,51 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui.helper;
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
/**
* Base class for all PreferenceActivities.
*
* Adds custom activity logic.
*
* @author alexander.ivanov
*
*/
public abstract class ManagedPreferenceActivity extends PreferenceActivity {
public class PreferenceEditor extends ManagedActivity
implements PreferencesFragment.OnPreferencesFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
ActivityManager.getInstance().onCreate(this);
super.onCreate(savedInstanceState);
}
if (isFinishing())
return;
@Override
protected void onResume() {
ActivityManager.getInstance().onResume(this);
super.onResume();
}
setContentView(R.layout.activity_preferences);
@Override
protected void onPause() {
ActivityManager.getInstance().onPause(this);
super.onPause();
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new PreferencesFragment()).commit();
}
@Override
protected void onDestroy() {
ActivityManager.getInstance().onDestroy(this);
super.onDestroy();
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@Override
protected void onNewIntent(Intent intent) {
ActivityManager.getInstance().onNewIntent(this, intent);
super.onNewIntent(intent);
}
// Force request sound. This will set default value if not specified.
SettingsManager.eventsSound();
SettingsManager.chatsAttentionSound();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ActivityManager.getInstance().onActivityResult(this, requestCode,
resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
public static Intent createIntent(Context context) {
return new Intent(context, PreferenceEditor.class);
}
@Override
public void startActivity(Intent intent) {
ActivityManager.getInstance().updateIntent(this, intent);
super.startActivity(intent);
public String getVersionName() {
try {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
ActivityManager.getInstance().updateIntent(this, intent);
super.startActivityForResult(intent, requestCode);
return "";
}
}
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class PreferencesFragment extends android.preference.PreferenceFragment {
private OnPreferencesFragmentInteractionListener mListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_editor);
Preference about = getPreferenceScreen().findPreference(getString(R.string.preference_about_key));
about.setSummary(getString(R.string.application_name) + "\n" + mListener.getVersionName());
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnPreferencesFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnPreferencesFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnPreferencesFragmentInteractionListener {
String getVersionName();
}
}
package com.xabber.android.ui.preferences;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import com.xabber.android.data.connection.CertificateManager;
import com.xabber.android.data.connection.ConnectionManager;
public class SecurityClearCertificateDialog extends DialogPreference {
public SecurityClearCertificateDialog(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
CertificateManager.getInstance().removeCertificates();
ConnectionManager.getInstance().updateConnections(true);
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class SecuritySettings extends ManagedActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_security)));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new SecuritySettingsFragment()).commit();
}
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class SecuritySettingsFragment extends android.preference.PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_security);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
}
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import com.xabber.android.data.ActivityManager;
import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ThemeSettings extends ManagedActivity
implements ThemeSettingsFragment.OnThemeSettingsFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
setContentView(R.layout.activity_preferences);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_interface)));
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ThemeSettingsFragment()).commit();
}
}
@Override
public void onThemeChanged() {
ActivityManager.getInstance().clearStack(true);
startActivity(ContactList.createIntent(this));
}
}
package com.xabber.android.ui.preferences;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.androiddev.R;
public class ThemeSettingsFragment extends android.preference.PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
private OnThemeSettingsFragmentInteractionListener mListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_theme);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.interface_theme_key))) {
mListener.onThemeChanged();
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnThemeSettingsFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnThemeSettingsFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnThemeSettingsFragmentInteractionListener {
public void onThemeChanged();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/preferences_activity_container"
>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_add_account"
android:title="@string/account_add"
app:showAsAction="always"
android:icon="@drawable/ic_add_white_24dp"/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_add_phrase"
android:title="@string/phrase_add"
app:showAsAction="always"
android:icon="@drawable/ic_add_white_24dp"/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_save"
android:title="@string/save"
app:showAsAction="always"
/>
</menu>
\ No newline at end of file
......@@ -26,4 +26,6 @@
<string name="required">Обязательно</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/preference_editor_security_otr.png -->
<string name="auto">Автоматически</string>
<string name="save">Сохранить</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved.
This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.
Xabber is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<resources>
<style name="Theme" parent="@android:style/Theme.DeviceDefault">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.NoTitleBar" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Dark" parent="@android:style/Theme.DeviceDefault">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_dark</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Dark.NoTitleBar" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_dark</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Light" parent="@android:style/Theme.DeviceDefault.Light">
<item name="expanderBackground">@drawable/expander_background_light</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimary</item>
<item name="expanderIndicator">@drawable/expander_indicator_light</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_light</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_light</item>
</style>
<style name="Theme.Light.NoTitleBar" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="expanderBackground">@drawable/expander_background_light</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimary</item>
<item name="expanderIndicator">@drawable/expander_indicator_light</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_light</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_light</item>
</style>
</resources>
\ No newline at end of file
......@@ -13,30 +13,7 @@
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<resources>
<style name="Theme" parent="@android:style/Theme">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.NoTitleBar" parent="@android:style/Theme.NoTitleBar">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Dark" parent="@android:style/Theme.Black">
<style name="Theme" parent="Theme.AppCompat">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
......@@ -46,38 +23,4 @@
<item name="titleAccountBackground">@drawable/title_account_background_dark</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Dark.NoTitleBar" parent="@android:style/Theme.Black.NoTitleBar">
<item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
<item name="expanderIndicator">@drawable/expander_indicator_dark</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_dark</item>
<item name="titleAccountBackground">@drawable/title_account_background_dark</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style>
<style name="Theme.Light" parent="@android:style/Theme.Light">
<item name="expanderBackground">@drawable/expander_background_light</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimary</item>
<item name="expanderIndicator">@drawable/expander_indicator_light</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_light</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_light</item>
</style>
<style name="Theme.Light.NoTitleBar" parent="@android:style/Theme.Light.NoTitleBar">
<item name="expanderBackground">@drawable/expander_background_light</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimary</item>
<item name="expanderIndicator">@drawable/expander_indicator_light</item>
<item name="accountBackground">@drawable/account_background</item>
<item name="titleMainBackground">@drawable/title_main_background_light</item>
<item name="titleAccountBackground">@drawable/title_account_background_light</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_light</item>
</style>
</resources>
\ No newline at end of file
......@@ -26,4 +26,6 @@
<string name="required">Required</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/preference_editor_security_otr.png -->
<string name="auto">Automatically</string>
<string name="save">Save</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/chats_show_avatars"
android:key="@string/chats_show_avatars_key"
android:defaultValue="@bool/chats_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/chats_send_by_enter"
android:key="@string/chats_send_by_enter_key"
android:defaultValue="@bool/chats_send_by_enter_default"
/>
<ListPreference
android:title="@string/chats_show_status_change"
android:summary="@string/chats_show_status_change"
android:key="@string/chats_show_status_change_key"
android:entries="@array/chats_show_status_change_entries"
android:entryValues="@array/chats_show_status_change_entryvalues"
android:defaultValue="@string/chats_show_status_change_default"
/>
<ListPreference
android:title="@string/chats_hide_keyboard"
android:key="@string/chats_hide_keyboard_key"
android:entries="@array/chats_hide_keyboard_entries"
android:entryValues="@array/chats_hide_keyboard_entryvalues"
android:defaultValue="@string/chats_hide_keyboard_default"
/>
<ListPreference
android:title="@string/chats_font_size"
android:key="@string/chats_font_size_key"
android:entries="@array/chats_font_size_entries"
android:entryValues="@array/chats_font_size_entryvalues"
android:defaultValue="@string/chats_font_size_default"
/>
<ListPreference
android:title="@string/chats_divide"
android:key="@string/chats_divide_key"
android:entries="@array/chats_divide_entries"
android:entryValues="@array/chats_divide_entryvalues"
android:defaultValue="@string/chats_divide_default"
/>
<CheckBoxPreference
android:title="@string/chats_state_notification"
android:key="@string/chats_state_notification_key"
android:defaultValue="@bool/chats_state_notification_default"
/>
<CheckBoxPreference
android:title="@string/chats_attention"
android:key="@string/chats_attention_key"
android:defaultValue="@bool/chats_attention_default"
/>
<RingtonePreference
android:title="@string/chats_attention_sound"
android:key="@string/chats_attention_sound_key"
android:defaultValue="@string/chats_attention_sound_default"
android:ringtoneType="ringtone"
android:dependency="@string/chats_attention_key"
android:showSilent="true"
android:showDefault="true"
/>
</PreferenceScreen>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/connection_start_at_boot"
android:key="@string/connection_start_at_boot_key"
android:defaultValue="@bool/connection_start_at_boot_default"
/>
<ListPreference
android:title="@string/connection_go_away"
android:key="@string/connection_go_away_key"
android:entries="@array/connection_go_away_entries"
android:entryValues="@array/connection_go_away_entryvalues"
android:defaultValue="@string/connection_go_away_default"
/>
<ListPreference
android:title="@string/connection_go_xa"
android:key="@string/connection_go_xa_key"
android:entries="@array/connection_go_xa_entries"
android:entryValues="@array/connection_go_xa_entryvalues"
android:defaultValue="@string/connection_go_xa_default"
/>
<CheckBoxPreference
android:title="@string/connection_wifi_lock"
android:key="@string/connection_wifi_lock_key"
android:defaultValue="@bool/connection_wifi_lock_default"
/>
<CheckBoxPreference
android:title="@string/connection_wake_lock"
android:key="@string/connection_wake_lock_key"
android:defaultValue="@bool/connection_wake_lock_default"
/>
<CheckBoxPreference
android:title="@string/connection_load_vcard"
android:key="@string/connection_load_vcard_key"
android:defaultValue="@bool/connection_load_vcard_default"
/>
<PreferenceCategory
android:title="@string/connection_priority"
>
<CheckBoxPreference
android:title="@string/connection_adjust_priority"
android:key="@string/connection_adjust_priority_key"
android:defaultValue="@bool/connection_adjust_priority_default"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_chat_key"
android:defaultValue="@string/connection_priority_chat_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/chat"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_available_key"
android:defaultValue="@string/connection_priority_available_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/available"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_away_key"
android:defaultValue="@string/connection_priority_away_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/away"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_xa_key"
android:defaultValue="@string/connection_priority_xa_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/xa"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_dnd_key"
android:defaultValue="@string/connection_priority_dnd_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/dnd"
android:singleLine="true"
/>
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/debug_log"
android:key="@string/debug_log_key"
android:defaultValue="@bool/debug_log_default"
/>
<com.xabber.android.ui.preferences.CacheClearDialog
android:title="@string/cache_clear"
android:key="@string/cache_clear_key"
android:dialogMessage="@string/cache_clear_warning"/>
</PreferenceScreen>
\ No newline at end of file
......@@ -14,334 +14,75 @@
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
<Preference
android:title="@string/preference_accounts"
android:key="@string/preference_accounts_key"
/>
<PreferenceScreen
android:key="@string/preference_accounts_key">
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.AccountList"/>
</Preference>
<Preference
android:title="@string/preference_interface"
android:key="@string/preference_interface"
>
<ListPreference
android:title="@string/interface_theme"
android:key="@string/interface_theme_key"
android:entries="@array/interface_theme_entries"
android:entryValues="@array/interface_theme_entryvalues"
android:defaultValue="@string/interface_theme_default"
/>
<ListPreference
android:title="@string/interface_smiles"
android:key="@string/interface_smiles_key"
android:entries="@array/interface_smiles_entries"
android:entryValues="@array/interface_smiles_entryvalues"
android:defaultValue="@string/interface_smiles_default"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ThemeSettings"/>
</Preference>
<Preference
android:title="@string/preference_contacts"
android:key="@string/preference_contacts"
>
<CheckBoxPreference
android:title="@string/contacts_show_panel"
android:key="@string/contacts_show_panel_key"
android:defaultValue="@bool/contacts_show_panel_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_avatars"
android:key="@string/contacts_show_avatars_key"
android:defaultValue="@bool/contacts_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_offline"
android:key="@string/contacts_show_offline_key"
android:defaultValue="@bool/contacts_show_offline_default"
/>
<PreferenceScreen
android:title="@string/contacts_reset_offline"
android:key="@string/contacts_reset_offline_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_groups"
android:key="@string/contacts_show_groups_key"
android:defaultValue="@bool/contacts_show_groups_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_accounts"
android:key="@string/contacts_show_accounts_key"
android:defaultValue="@bool/contacts_show_accounts_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_active_chats"
android:key="@string/contacts_show_active_chats_key"
android:defaultValue="@bool/contacts_show_active_chats_default"
/>
<CheckBoxPreference
android:title="@string/contacts_stay_active_chats"
android:key="@string/contacts_stay_active_chats_key"
android:defaultValue="@bool/contacts_stay_active_chats_default"
android:dependency="@string/contacts_show_active_chats_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_empty_groups"
android:key="@string/contacts_show_empty_groups_key"
android:defaultValue="@bool/contacts_show_empty_groups_default"
/>
<ListPreference
android:title="@string/contacts_order"
android:key="@string/contacts_order_key"
android:entries="@array/contacts_order_entries"
android:entryValues="@array/contacts_order_entryvalues"
android:defaultValue="@string/contacts_order_default"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ContactListSettings"/>
</Preference>
<Preference
android:title="@string/preference_chats"
android:key="@string/preference_chats"
>
<CheckBoxPreference
android:title="@string/chats_show_avatars"
android:key="@string/chats_show_avatars_key"
android:defaultValue="@bool/chats_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/chats_send_by_enter"
android:key="@string/chats_send_by_enter_key"
android:defaultValue="@bool/chats_send_by_enter_default"
/>
<ListPreference
android:title="@string/chats_show_status_change"
android:summary="@string/chats_show_status_change"
android:key="@string/chats_show_status_change_key"
android:entries="@array/chats_show_status_change_entries"
android:entryValues="@array/chats_show_status_change_entryvalues"
android:defaultValue="@string/chats_show_status_change_default"
/>
<ListPreference
android:title="@string/chats_hide_keyboard"
android:key="@string/chats_hide_keyboard_key"
android:entries="@array/chats_hide_keyboard_entries"
android:entryValues="@array/chats_hide_keyboard_entryvalues"
android:defaultValue="@string/chats_hide_keyboard_default"
/>
<ListPreference
android:title="@string/chats_font_size"
android:key="@string/chats_font_size_key"
android:entries="@array/chats_font_size_entries"
android:entryValues="@array/chats_font_size_entryvalues"
android:defaultValue="@string/chats_font_size_default"
/>
<ListPreference
android:title="@string/chats_divide"
android:key="@string/chats_divide_key"
android:entries="@array/chats_divide_entries"
android:entryValues="@array/chats_divide_entryvalues"
android:defaultValue="@string/chats_divide_default"
/>
<CheckBoxPreference
android:title="@string/chats_state_notification"
android:key="@string/chats_state_notification_key"
android:defaultValue="@bool/chats_state_notification_default"
/>
<CheckBoxPreference
android:title="@string/chats_attention"
android:key="@string/chats_attention_key"
android:defaultValue="@bool/chats_attention_default"
/>
<RingtonePreference
android:title="@string/chats_attention_sound"
android:key="@string/chats_attention_sound_key"
android:defaultValue="@string/chats_attention_sound_default"
android:ringtoneType="ringtone"
android:dependency="@string/chats_attention_key"
android:showSilent="true"
android:showDefault="true"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ChatSettings"/>
</Preference>
<Preference
android:title="@string/preference_events"
android:key="@string/preference_events"
>
<RingtonePreference
android:title="@string/events_sound"
android:key="@string/events_sound_key"
android:defaultValue="@string/events_sound_default"
android:ringtoneType="notification"
android:showSilent="true"
android:showDefault="true"
/>
<CheckBoxPreference
android:title="@string/events_vibro"
android:key="@string/events_vibro_key"
android:defaultValue="@bool/events_vibro_default"
/>
<CheckBoxPreference
android:title="@string/events_ignore_system_vibro"
android:key="@string/events_ignore_system_vibro_key"
android:defaultValue="@bool/events_ignore_system_vibro_default"
android:dependency="@string/events_vibro_key"
/>
<CheckBoxPreference
android:title="@string/events_lightning"
android:key="@string/events_lightning_key"
android:defaultValue="@bool/events_lightning_default"
/>
<CheckBoxPreference
android:title="@string/events_persistent"
android:key="@string/events_persistent_key"
android:defaultValue="@bool/events_persistent_default"
/>
<CheckBoxPreference
android:title="@string/events_show_text"
android:key="@string/events_show_text_key"
android:defaultValue="@bool/events_show_text_default"
/>
<ListPreference
android:title="@string/events_message"
android:key="@string/events_message_key"
android:entries="@array/events_message_entries"
android:entryValues="@array/events_message_entryvalues"
android:defaultValue="@string/events_message_default"
/>
<CheckBoxPreference
android:title="@string/events_visible_chat"
android:key="@string/events_visible_chat_key"
android:defaultValue="@bool/events_visible_chat_default"
/>
<CheckBoxPreference
android:title="@string/events_first_only"
android:key="@string/events_first_only_key"
android:defaultValue="@bool/events_first_only_default"
/>
<PreferenceScreen
android:title="@string/events_phrases"
android:key="@string/events_phrases"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.NotificationsSettings"/>
</Preference>
<Preference
android:title="@string/preference_connection"
android:key="@string/preference_connection"
>
<CheckBoxPreference
android:title="@string/connection_start_at_boot"
android:key="@string/connection_start_at_boot_key"
android:defaultValue="@bool/connection_start_at_boot_default"
/>
<ListPreference
android:title="@string/connection_go_away"
android:key="@string/connection_go_away_key"
android:entries="@array/connection_go_away_entries"
android:entryValues="@array/connection_go_away_entryvalues"
android:defaultValue="@string/connection_go_away_default"
/>
<ListPreference
android:title="@string/connection_go_xa"
android:key="@string/connection_go_xa_key"
android:entries="@array/connection_go_xa_entries"
android:entryValues="@array/connection_go_xa_entryvalues"
android:defaultValue="@string/connection_go_xa_default"
/>
<CheckBoxPreference
android:title="@string/connection_wifi_lock"
android:key="@string/connection_wifi_lock_key"
android:defaultValue="@bool/connection_wifi_lock_default"
/>
<CheckBoxPreference
android:title="@string/connection_wake_lock"
android:key="@string/connection_wake_lock_key"
android:defaultValue="@bool/connection_wake_lock_default"
/>
<CheckBoxPreference
android:title="@string/connection_load_vcard"
android:key="@string/connection_load_vcard_key"
android:defaultValue="@bool/connection_load_vcard_default"
/>
<PreferenceCategory
android:title="@string/connection_priority"
>
<CheckBoxPreference
android:title="@string/connection_adjust_priority"
android:key="@string/connection_adjust_priority_key"
android:defaultValue="@bool/connection_adjust_priority_default"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_chat_key"
android:defaultValue="@string/connection_priority_chat_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/chat"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_available_key"
android:defaultValue="@string/connection_priority_available_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/available"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_away_key"
android:defaultValue="@string/connection_priority_away_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/away"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_xa_key"
android:defaultValue="@string/connection_priority_xa_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/xa"
android:singleLine="true"
/>
<com.xabber.android.ui.widget.PriorityPreference
android:key="@string/connection_priority_dnd_key"
android:defaultValue="@string/connection_priority_dnd_default"
android:dependency="@string/connection_adjust_priority_key"
android:title="@string/dnd"
android:singleLine="true"
/>
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.ConnectionSettings"/>
</Preference>
<Preference
android:title="@string/preference_security"
android:key="@string/preference_security"
>
<CheckBoxPreference
android:title="@string/security_check_certificate"
android:key="@string/security_check_certificate_key"
android:defaultValue="@bool/security_check_certificate_default"
/>
<PreferenceScreen
android:title="@string/security_clear_certificate"
android:key="@string/security_clear_certificate_key"
/>
<ListPreference
android:title="@string/security_otr_mode"
android:key="@string/security_otr_mode_key"
android:entries="@array/security_otr_mode_entries"
android:entryValues="@array/security_otr_mode_entryvalues"
android:defaultValue="@string/security_otr_mode_default"
/>
<CheckBoxPreference
android:title="@string/security_otr_history"
android:key="@string/security_otr_history_key"
android:defaultValue="@bool/security_otr_history_default"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.SecuritySettings"/>
</Preference>
<Preference
android:title="@string/preference_debug"
android:key="@string/preference_debug"
>
<CheckBoxPreference
android:title="@string/debug_log"
android:key="@string/debug_log_key"
android:defaultValue="@bool/debug_log_default"
/>
<PreferenceScreen
android:title="@string/cache_clear"
android:key="@string/cache_clear_key"
/>
</PreferenceScreen>
<PreferenceScreen
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.DebugSettings"/>
</Preference>
<Preference
android:title="@string/preference_about"
android:key="@string/preference_about_key"
/>
android:key="@string/preference_about_key">
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.AboutViewer"/>
</Preference>
</PreferenceScreen>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<RingtonePreference
android:title="@string/events_sound"
android:key="@string/events_sound_key"
android:defaultValue="@string/events_sound_default"
android:ringtoneType="notification"
android:showSilent="true"
android:showDefault="true"
/>
<CheckBoxPreference
android:title="@string/events_vibro"
android:key="@string/events_vibro_key"
android:defaultValue="@bool/events_vibro_default"
/>
<CheckBoxPreference
android:title="@string/events_ignore_system_vibro"
android:key="@string/events_ignore_system_vibro_key"
android:defaultValue="@bool/events_ignore_system_vibro_default"
android:dependency="@string/events_vibro_key"
/>
<CheckBoxPreference
android:title="@string/events_lightning"
android:key="@string/events_lightning_key"
android:defaultValue="@bool/events_lightning_default"
/>
<CheckBoxPreference
android:title="@string/events_persistent"
android:key="@string/events_persistent_key"
android:defaultValue="@bool/events_persistent_default"
/>
<CheckBoxPreference
android:title="@string/events_show_text"
android:key="@string/events_show_text_key"
android:defaultValue="@bool/events_show_text_default"
/>
<ListPreference
android:title="@string/events_message"
android:key="@string/events_message_key"
android:entries="@array/events_message_entries"
android:entryValues="@array/events_message_entryvalues"
android:defaultValue="@string/events_message_default"
/>
<CheckBoxPreference
android:title="@string/events_visible_chat"
android:key="@string/events_visible_chat_key"
android:defaultValue="@bool/events_visible_chat_default"
/>
<CheckBoxPreference
android:title="@string/events_first_only"
android:key="@string/events_first_only_key"
android:defaultValue="@bool/events_first_only_default"
/>
<Preference
android:title="@string/events_phrases"
android:key="@string/events_phrases">
<intent
android:targetPackage="@string/application_package"
android:targetClass="com.xabber.android.ui.preferences.PhraseList"/>
</Preference>
</PreferenceScreen>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/security_check_certificate"
android:key="@string/security_check_certificate_key"
android:defaultValue="@bool/security_check_certificate_default"
/>
<com.xabber.android.ui.preferences.SecurityClearCertificateDialog
android:title="@string/security_clear_certificate"
android:key="@string/security_clear_certificate_key"
android:dialogMessage="@string/security_clear_certificate_warning"/>
<ListPreference
android:title="@string/security_otr_mode"
android:key="@string/security_otr_mode_key"
android:entries="@array/security_otr_mode_entries"
android:entryValues="@array/security_otr_mode_entryvalues"
android:defaultValue="@string/security_otr_mode_default"
/>
<CheckBoxPreference
android:title="@string/security_otr_history"
android:key="@string/security_otr_history_key"
android:defaultValue="@bool/security_otr_history_default"
/>
</PreferenceScreen>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:title="@string/interface_smiles"
android:key="@string/interface_smiles_key"
android:entries="@array/interface_smiles_entries"
android:entryValues="@array/interface_smiles_entryvalues"
android:defaultValue="@string/interface_smiles_default"
/>
</PreferenceScreen>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/contacts_show_panel"
android:key="@string/contacts_show_panel_key"
android:defaultValue="@bool/contacts_show_panel_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_avatars"
android:key="@string/contacts_show_avatars_key"
android:defaultValue="@bool/contacts_show_avatars_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_offline"
android:key="@string/contacts_show_offline_key"
android:defaultValue="@bool/contacts_show_offline_default"
/>
<com.xabber.android.ui.preferences.ContactResetOfflineSettingsDialog
android:title="@string/contacts_reset_offline"
android:key="@string/contacts_reset_offline_key"
android:dialogMessage="@string/contacts_reset_offline_warning"/>
<CheckBoxPreference
android:title="@string/contacts_show_groups"
android:key="@string/contacts_show_groups_key"
android:defaultValue="@bool/contacts_show_groups_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_accounts"
android:key="@string/contacts_show_accounts_key"
android:defaultValue="@bool/contacts_show_accounts_default"
/>
<CheckBoxPreference
android:title="@string/contacts_show_active_chats"
android:key="@string/contacts_show_active_chats_key"
android:defaultValue="@bool/contacts_show_active_chats_default"
/>
<CheckBoxPreference
android:title="@string/contacts_stay_active_chats"
android:key="@string/contacts_stay_active_chats_key"
android:defaultValue="@bool/contacts_stay_active_chats_default"
android:dependency="@string/contacts_show_active_chats_key"
/>
<CheckBoxPreference
android:title="@string/contacts_show_empty_groups"
android:key="@string/contacts_show_empty_groups_key"
android:defaultValue="@bool/contacts_show_empty_groups_default"
/>
<ListPreference
android:title="@string/contacts_order"
android:key="@string/contacts_order_key"
android:entries="@array/contacts_order_entries"
android:entryValues="@array/contacts_order_entryvalues"
android:defaultValue="@string/contacts_order_default"
/>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment