Commit 4b73b403 authored by Grigory Fedorov's avatar Grigory Fedorov

appcompat-v7, single dark theme.

All activities uses support action bars. BaseSettingsActivity and ManagedPreferenceActivity removed - deprecated PreferenceActivity replaced by PreferenceFragment.
parent 0de94da4
...@@ -22,5 +22,5 @@ android { ...@@ -22,5 +22,5 @@ android {
dependencies { dependencies {
compile files('libs/otr4j.jar') 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 @@ ...@@ -37,7 +37,7 @@
android:label="@string/application_name" android:label="@string/application_name"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:name="com.xabber.android.data.Application" android:name="com.xabber.android.data.Application"
android:theme="@style/Theme.Light" android:theme="@style/Theme"
android:allowBackup="true"> android:allowBackup="true">
<activity <activity
android:label="@string/application_name" android:label="@string/application_name"
...@@ -210,7 +210,7 @@ ...@@ -210,7 +210,7 @@
<activity <activity
android:label="@string/chat_settings" 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" android:parentActivityName="com.xabber.android.ui.ChatViewer"
> >
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
<activity <activity
android:label="@string/contact_viewer" 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:icon="@drawable/ic_information"
android:parentActivityName="com.xabber.android.ui.ContactList" android:parentActivityName="com.xabber.android.ui.ContactList"
> >
......
...@@ -14,24 +14,21 @@ ...@@ -14,24 +14,21 @@
*/ */
package com.xabber.android.data; 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.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
import com.xabber.android.data.SettingsManager.InterfaceTheme;
import com.xabber.android.ui.ContactList; import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.LoadActivity; import com.xabber.android.ui.LoadActivity;
import com.xabber.android.ui.preferences.PreferenceEditor;
import com.xabber.androiddev.R; 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. * Activity stack manager.
* *
...@@ -123,28 +120,14 @@ public class ActivityManager implements OnUnloadListener { ...@@ -123,28 +120,14 @@ public class ActivityManager implements OnUnloadListener {
return false; return false;
} }
/** /**
* Apply theme settings. * Apply theme settings.
* *
* @param activity * @param activity
*/ */
private void applyTheme(Activity activity) { private void applyTheme(Activity activity) {
TypedArray title = activity.getTheme().obtainStyledAttributes( activity.setTheme(R.style.Theme);
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);
}
/** /**
* Push activity to stack. * Push activity to stack.
...@@ -210,9 +193,9 @@ public class ActivityManager implements OnUnloadListener { ...@@ -210,9 +193,9 @@ public class ActivityManager implements OnUnloadListener {
LogManager.i(this, "Wait for loading"); LogManager.i(this, "Wait for loading");
activity.startActivity(LoadActivity.createIntent(activity)); activity.startActivity(LoadActivity.createIntent(activity));
} }
if (onErrorListener != null) if (onErrorListener != null) {
application application.removeUIListener(OnErrorListener.class, onErrorListener);
.removeUIListener(OnErrorListener.class, onErrorListener); }
onErrorListener = new OnErrorListener() { onErrorListener = new OnErrorListener() {
@Override @Override
public void onError(final int resourceId) { public void onError(final int resourceId) {
......
...@@ -91,7 +91,7 @@ public class AccountAdd extends ManagedActivity implements ...@@ -91,7 +91,7 @@ public class AccountAdd extends ManagedActivity implements
inputManager.hideSoftInputFromWindow(findViewById(R.id.ok) inputManager.hideSoftInputFromWindow(findViewById(R.id.ok)
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @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.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 ...@@ -50,7 +50,7 @@ public class ChatList extends ManagedListActivity implements
setListAdapter(listAdapter); setListAdapter(listAdapter);
getListView().setOnItemClickListener(this); getListView().setOnItemClickListener(this);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -115,7 +115,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -115,7 +115,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
if (actionWithUser == null) if (actionWithUser == null)
actionWithUser = user; actionWithUser = user;
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
selectChat(actionWithAccount, actionWithUser); selectChat(actionWithAccount, actionWithUser);
} }
...@@ -179,7 +179,6 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -179,7 +179,6 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
String account = getAccount(intent); String account = getAccount(intent);
String user = getUser(intent); String user = getUser(intent);
if (account == null || user == null) { if (account == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
return; return;
} }
if (hasAttention(intent)) if (hasAttention(intent))
......
...@@ -57,6 +57,7 @@ import com.xabber.android.ui.adapter.ChatMessageAdapter; ...@@ -57,6 +57,7 @@ import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment; import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.AbstractAvatarInflaterHelper; import com.xabber.android.ui.helper.AbstractAvatarInflaterHelper;
import com.xabber.android.ui.helper.ContactTitleInflater; import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.android.ui.widget.PageSwitcher; import com.xabber.android.ui.widget.PageSwitcher;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
......
...@@ -62,7 +62,7 @@ public class ContactAdd extends GroupListActivity implements ...@@ -62,7 +62,7 @@ public class ContactAdd extends GroupListActivity implements
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -47,7 +47,7 @@ public class ContactEditor extends GroupListActivity implements ...@@ -47,7 +47,7 @@ public class ContactEditor extends GroupListActivity implements
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -120,7 +120,7 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -120,7 +120,7 @@ public class FingerprintViewer extends ManagedActivity implements
copyView.setOnClickListener(this); copyView.setOnClickListener(this);
isUpdating = false; isUpdating = false;
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -72,7 +72,7 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -72,7 +72,7 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
setContentView(R.layout.muc_editor); setContentView(R.layout.muc_editor);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
accountView = (Spinner) findViewById(R.id.contact_account); accountView = (Spinner) findViewById(R.id.contact_account);
serverView = (EditText) findViewById(R.id.muc_server); serverView = (EditText) findViewById(R.id.muc_server);
......
...@@ -99,7 +99,7 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -99,7 +99,7 @@ public class QuestionViewer extends ManagedActivity implements
findViewById(R.id.cancel).setOnClickListener(this); findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this); findViewById(R.id.send).setOnClickListener(this);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -72,7 +72,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -72,7 +72,7 @@ public class StatusEditor extends ManagedListActivity implements
setContentView(R.layout.status_editor); setContentView(R.layout.status_editor);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent(); Intent intent = getIntent();
account = StatusEditor.getAccount(intent); account = StatusEditor.getAccount(intent);
......
...@@ -37,7 +37,7 @@ import com.xabber.android.ui.preferences.AccountEditor; ...@@ -37,7 +37,7 @@ import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.ChatViewer; import com.xabber.android.ui.ChatViewer;
import com.xabber.android.ui.ContactAdd; import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactEditor; 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.MUCEditor;
import com.xabber.android.ui.StatusEditor; import com.xabber.android.ui.StatusEditor;
import com.xabber.android.ui.adapter.UpdatableAdapter; import com.xabber.android.ui.adapter.UpdatableAdapter;
......
...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper; ...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v7.app.ActionBarActivity;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
...@@ -28,7 +28,7 @@ import com.xabber.android.data.ActivityManager; ...@@ -28,7 +28,7 @@ import com.xabber.android.data.ActivityManager;
* @author alexander.ivanov * @author alexander.ivanov
* *
*/ */
public abstract class ManagedActivity extends FragmentActivity { public abstract class ManagedActivity extends ActionBarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper; ...@@ -16,7 +16,7 @@ package com.xabber.android.ui.helper;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v7.app.ActionBarActivity;
import android.widget.ListAdapter; import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
...@@ -30,7 +30,7 @@ import com.xabber.android.data.ActivityManager; ...@@ -30,7 +30,7 @@ import com.xabber.android.data.ActivityManager;
* @author alexander.ivanov * @author alexander.ivanov
* *
*/ */
public abstract class ManagedListActivity extends FragmentActivity { public abstract class ManagedListActivity extends ActionBarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
......
/**
* 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 android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import com.xabber.android.data.ActivityManager;
/**
* Base class for all PreferenceActivities.
*
* Adds custom activity logic.
*
* @author alexander.ivanov
*
*/
public abstract class ManagedPreferenceActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
ActivityManager.getInstance().onCreate(this);
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
ActivityManager.getInstance().onResume(this);
super.onResume();
}
@Override
protected void onPause() {
ActivityManager.getInstance().onPause(this);
super.onPause();
}
@Override
protected void onDestroy() {
ActivityManager.getInstance().onDestroy(this);
super.onDestroy();
}
@Override
protected void onNewIntent(Intent intent) {
ActivityManager.getInstance().onNewIntent(this, intent);
super.onNewIntent(intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ActivityManager.getInstance().onActivityResult(this, requestCode,
resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void startActivity(Intent intent) {
ActivityManager.getInstance().updateIntent(this, intent);
super.startActivity(intent);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
ActivityManager.getInstance().updateIntent(this, intent);
super.startActivityForResult(intent, requestCode);
}
}
...@@ -39,7 +39,7 @@ public class AboutViewer extends ManagedActivity { ...@@ -39,7 +39,7 @@ public class AboutViewer extends ManagedActivity {
((TextView) findViewById(R.id.about_license)) ((TextView) findViewById(R.id.about_license))
.setMovementMethod(LinkMovementMethod.getInstance()); .setMovementMethod(LinkMovementMethod.getInstance());
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
private String getVersionName() { private String getVersionName() {
......
...@@ -43,7 +43,7 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -43,7 +43,7 @@ public class AccountList extends BaseListEditor<String> implements
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_accounts))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_accounts)));
} }
......
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());
}
}
@Override
public void onStop() {
super.onStop();
operation(Operation.save);
}
/**
* 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(), 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 ((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);
}
/**
* 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
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();
}
}
...@@ -18,7 +18,7 @@ public class ChatSettings extends ManagedActivity { ...@@ -18,7 +18,7 @@ public class ChatSettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.chat_viewer))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.chat_viewer)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
...@@ -18,7 +18,7 @@ public class ConnectionSettings extends ManagedActivity { ...@@ -18,7 +18,7 @@ public class ConnectionSettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_connection))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_connection)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
...@@ -17,7 +17,7 @@ public class ContactListSettings extends ManagedActivity { ...@@ -17,7 +17,7 @@ public class ContactListSettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_contacts))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_contacts)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
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;
}
}
...@@ -18,7 +18,7 @@ public class DebugSettings extends ManagedActivity { ...@@ -18,7 +18,7 @@ public class DebugSettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_debug))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_debug)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
...@@ -19,7 +19,7 @@ public class NotificationsSettings extends ManagedActivity { ...@@ -19,7 +19,7 @@ public class NotificationsSettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_events))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_events)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
...@@ -14,25 +14,19 @@ ...@@ -14,25 +14,19 @@
*/ */
package com.xabber.android.ui.preferences; package com.xabber.android.ui.preferences;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.PatternSyntaxException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.widget.Toast;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.intent.SegmentIntentBuilder; import com.xabber.android.data.intent.SegmentIntentBuilder;
import com.xabber.android.data.message.phrase.Phrase; import com.xabber.android.data.message.phrase.Phrase;
import com.xabber.android.data.message.phrase.PhraseManager; import com.xabber.android.data.message.phrase.PhraseManager;
import com.xabber.android.ui.helper.BaseSettingsActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class PhraseEditor extends BaseSettingsActivity { public class PhraseEditor extends ManagedActivity
implements PhraseEditorFragment.OnPhraseEditorFragmentInteractionListener {
private Phrase phrase; private Phrase phrase;
...@@ -40,90 +34,63 @@ public class PhraseEditor extends BaseSettingsActivity { ...@@ -40,90 +34,63 @@ public class PhraseEditor extends BaseSettingsActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override Integer index = getPhraseIndex(getIntent());
protected void onInflate(Bundle savedInstanceState) { if (index == null) {
addPreferencesFromResource(R.xml.phrase_editor); phrase = null;
Integer index = getPhraseIndex(getIntent()); setTitle(R.string.phrase_add);
if (index == null) { } else {
phrase = null; phrase = PhraseManager.getInstance().getPhrase(index);
setTitle(R.string.phrase_add); if (phrase == null) {
} else { finish();
phrase = PhraseManager.getInstance().getPhrase(index); return;
if (phrase == null) { }
finish(); String title = phrase.getText();
return; if ("".equals(title))
} title = Application.getInstance().getString(
String title = phrase.getText(); R.string.phrase_empty);
if ("".equals(title)) setTitle(title);
title = Application.getInstance().getString( }
R.string.phrase_empty);
setTitle(title);
}
}
@Override setContentView(R.layout.activity_preferences);
protected Map<String, Object> getValues() {
Map<String, Object> source = new HashMap<String, Object>(); if (savedInstanceState == null) {
putValue(source, R.string.phrase_text_key, getFragmentManager().beginTransaction()
phrase == null ? "" : phrase.getText()); .add(R.id.preferences_activity_container, new PhraseEditorFragment()).commit();
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) { public static Intent createIntent(Context context) {
return createIntent(context, null); return createIntent(context, null);
} }
public static Intent createIntent(Context context, Integer phraseIndex) { public static Intent createIntent(Context context, Integer phraseIndex) {
SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<SegmentIntentBuilder<?>>( SegmentIntentBuilder<?> builder = new SegmentIntentBuilder<>(
context, PhraseEditor.class); context, PhraseEditor.class);
if (phraseIndex != null) if (phraseIndex != null)
builder.addSegment(phraseIndex.toString()); builder.addSegment(phraseIndex.toString());
return builder.build(); return builder.build();
} }
private Integer getPhraseIndex(Intent intent) { private Integer getPhraseIndex(Intent intent) {
String value = SegmentIntentBuilder.getSegment(intent, 0); String value = SegmentIntentBuilder.getSegment(intent, 0);
if (value == null) if (value == null)
return null; return null;
else else
return Integer.valueOf(value); return Integer.valueOf(value);
} }
@Override
public Phrase getPhrase() {
return phrase;
}
@Override
public void setPhrase(Phrase phrase) {
this.phrase = phrase;
}
} }
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);
}
}
...@@ -31,7 +31,7 @@ public class PhraseList extends BaseListEditor<Integer> { ...@@ -31,7 +31,7 @@ public class PhraseList extends BaseListEditor<Integer> {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@Override @Override
......
...@@ -39,7 +39,7 @@ public class PreferenceEditor extends ManagedActivity ...@@ -39,7 +39,7 @@ public class PreferenceEditor extends ManagedActivity
.add(R.id.preferences_activity_container, new PreferencesFragment()).commit(); .add(R.id.preferences_activity_container, new PreferencesFragment()).commit();
} }
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Force request sound. This will set default value if not specified. // Force request sound. This will set default value if not specified.
SettingsManager.eventsSound(); SettingsManager.eventsSound();
......
...@@ -18,7 +18,7 @@ public class SecuritySettings extends ManagedActivity { ...@@ -18,7 +18,7 @@ public class SecuritySettings extends ManagedActivity {
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_security))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_security)));
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
......
...@@ -19,7 +19,7 @@ public class ThemeSettings extends ManagedActivity ...@@ -19,7 +19,7 @@ public class ThemeSettings extends ManagedActivity
setContentView(R.layout.activity_preferences); setContentView(R.layout.activity_preferences);
getActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_interface))); setTitle(PreferenceSummaryHelper.getPreferenceTitle(getString(R.string.preference_interface)));
......
<?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 @@ ...@@ -13,30 +13,7 @@
along with this program. If not, see http://www.gnu.org/licenses/. along with this program. If not, see http://www.gnu.org/licenses/.
--> -->
<resources> <resources>
<style name="Theme" parent="Theme.AppCompat">
<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">
<item name="expanderBackground">@drawable/expander_background_dark</item> <item name="expanderBackground">@drawable/expander_background_dark</item>
<item name="expanderGroupColor">?android:attr/textColorPrimary</item> <item name="expanderGroupColor">?android:attr/textColorPrimary</item>
<item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item> <item name="expanderAccountColor">?android:attr/textColorPrimaryInverse</item>
...@@ -46,38 +23,4 @@ ...@@ -46,38 +23,4 @@
<item name="titleAccountBackground">@drawable/title_account_background_dark</item> <item name="titleAccountBackground">@drawable/title_account_background_dark</item>
<item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item> <item name="textColorPrimaryNoSelected">@color/bright_foreground_dark</item>
</style> </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> </resources>
\ 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