diff options
5 files changed, 210 insertions, 10 deletions
diff --git a/src/instrumentTest/java/com/anysoftkeyboard/dictionaries/BTreeDictionaryTest.java b/src/instrumentTest/java/com/anysoftkeyboard/dictionaries/BTreeDictionaryTest.java index 3abdd892e..57266079e 100644 --- a/src/instrumentTest/java/com/anysoftkeyboard/dictionaries/BTreeDictionaryTest.java +++ b/src/instrumentTest/java/com/anysoftkeyboard/dictionaries/BTreeDictionaryTest.java @@ -18,14 +18,14 @@ package com.anysoftkeyboard.dictionaries; import android.test.ActivityInstrumentationTestCase2; -import com.anysoftkeyboard.ui.settings.MainSettings; +import com.anysoftkeyboard.ui.settings.MainSettingsActivity; import junit.framework.Assert; -public class BTreeDictionaryTest extends ActivityInstrumentationTestCase2<MainSettings>/*need a valid Application object, so I use ActivityInstrumentationTestCase2*/ { +public class BTreeDictionaryTest extends ActivityInstrumentationTestCase2<MainSettingsActivity>/*need a valid Application object, so I use ActivityInstrumentationTestCase2*/ { public BTreeDictionaryTest() { - super(MainSettings.class); + super(MainSettingsActivity.class); } diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 0f3b9e70a..4377320f5 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -83,7 +83,7 @@ </intent-filter> </activity> <activity android:theme="@style/Theme.AppCompat.Light" - android:name="com.anysoftkeyboard.ui.settings.MainSettings" + android:name="com.anysoftkeyboard.ui.settings.MainSettingsActivity" android:icon="@drawable/ic_launcher_settings" android:label="@string/ime_name"> </activity> diff --git a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java index 1c17cc5c4..f06ec4e14 100644 --- a/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java +++ b/src/main/java/com/anysoftkeyboard/AnySoftKeyboard.java @@ -86,7 +86,7 @@ import com.anysoftkeyboard.receivers.SoundPreferencesChangedReceiver.SoundPrefer import com.anysoftkeyboard.theme.KeyboardTheme; import com.anysoftkeyboard.theme.KeyboardThemeFactory; import com.anysoftkeyboard.ui.dev.DeveloperUtils; -import com.anysoftkeyboard.ui.settings.MainSettings; +import com.anysoftkeyboard.ui.settings.MainSettingsActivity; import com.anysoftkeyboard.ui.tutorials.TipLayoutsSupport; import com.anysoftkeyboard.ui.tutorials.TutorialsProvider; import com.anysoftkeyboard.utils.IMEUtil.GCUtils; @@ -3104,8 +3104,6 @@ public class AnySoftKeyboard extends InputMethodService implements } private void loadSettings() { - // setting all values to default - PreferenceManager.setDefaultValues(this, R.xml.prefs, false); // Get the settings preferences SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(this); @@ -3272,7 +3270,7 @@ public class AnySoftKeyboard extends InputMethodService implements private void launchSettings() { handleClose(); Intent intent = new Intent(); - intent.setClass(AnySoftKeyboard.this, MainSettings.class); + intent.setClass(AnySoftKeyboard.this, MainSettingsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } diff --git a/src/main/java/com/anysoftkeyboard/ui/settings/MainSettingsActivity.java b/src/main/java/com/anysoftkeyboard/ui/settings/MainSettingsActivity.java new file mode 100644 index 000000000..19821fe65 --- /dev/null +++ b/src/main/java/com/anysoftkeyboard/ui/settings/MainSettingsActivity.java @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2013 Menny Even-Danan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.anysoftkeyboard.ui.settings; + +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.Fragment; +import android.support.v4.widget.DrawerLayout; +import android.view.Gravity; +import android.view.MenuItem; +import android.view.View; +import android.widget.TextView; + +import com.anysoftkeyboard.keyboards.KeyboardFactory; +import com.anysoftkeyboard.theme.KeyboardTheme; +import com.anysoftkeyboard.theme.KeyboardThemeFactory; +import com.menny.android.anysoftkeyboard.AnyApplication; +import com.menny.android.anysoftkeyboard.R; + +import net.evendanan.pushingpixels.FragmentChauffeurActivity; + +public class MainSettingsActivity extends FragmentChauffeurActivity { + + private static final String TAG = "ASK_MAIN"; + + private DrawerLayout mDrawerRootLayout; + private ActionBarDrawerToggle mDrawerToggle; + + private CharSequence mTitle; + private CharSequence mDrawerTitle; + private SharedPreferences.OnSharedPreferenceChangeListener menuExtraUpdaterOnConfigChange = new SharedPreferences.OnSharedPreferenceChangeListener() { + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + updateMenuExtraData(); + } + }; + + @Override + protected void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.main_ui); + + mTitle = mDrawerTitle = getTitle(); + + mDrawerRootLayout = (DrawerLayout) findViewById(R.id.main_root_layout); + mDrawerRootLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); + mDrawerToggle = new ActionBarDrawerToggle( + this, /* host Activity */ + mDrawerRootLayout, /* DrawerLayout object */ + R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ + R.string.drawer_open, /* "open drawer" description */ + R.string.drawer_close /* "close drawer" description */ + ) { + + /** Called when a drawer has settled in a completely closed state. */ + public void onDrawerClosed(View view) { + getSupportActionBar().setTitle(mTitle); + ActivityCompat.invalidateOptionsMenu(MainSettingsActivity.this);// creates call to onPrepareOptionsMenu() + } + + /** Called when a drawer has settled in a completely open state. */ + public void onDrawerOpened(View drawerView) { + getSupportActionBar().setTitle(mDrawerTitle); + ActivityCompat.invalidateOptionsMenu(MainSettingsActivity.this);// creates call to onPrepareOptionsMenu() + } + }; + + // Set the drawer toggle as the DrawerListener + mDrawerRootLayout.setDrawerListener(mDrawerToggle); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + AnyApplication.getConfig().addChangedListener(menuExtraUpdaterOnConfigChange); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Sync the toggle state after onRestoreInstanceState has occurred. + mDrawerToggle.syncState(); + } + + @Override + protected Fragment createRootFragmentInstance() { + return new MainFragment(); + } + + @Override + protected int getFragmentRootUiElementId() { + return R.id.main_ui_content; + } + + @Override + protected void onStart() { + super.onStart(); + //updating menu's data + updateMenuExtraData(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + AnyApplication.getConfig().removeChangedListener(menuExtraUpdaterOnConfigChange); + } + + private void updateMenuExtraData() { + TextView keyboardsData = (TextView)findViewById(R.id.keyboards_group_extra_data); + final int all = KeyboardFactory.getAllAvailableKeyboards(getApplicationContext()).size(); + final int enabled = KeyboardFactory.getEnabledKeyboards(getApplicationContext()).size(); + keyboardsData.setText(getString(R.string.keyboards_group_extra_template, enabled, all)); + + TextView themeData = (TextView)findViewById(R.id.theme_extra_data); + KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(getApplicationContext()); + if (theme == null) + theme = KeyboardThemeFactory.getCurrentKeyboardTheme(getApplicationContext()); + themeData.setText(getString(R.string.selected_add_on_summary, theme.getName())); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Pass the event to ActionBarDrawerToggle, if it returns + // true, then it has handled the app icon touch event + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + // Handle your other action bar items... + + return super.onOptionsItemSelected(item); + } + + @Override + public void setTitle(CharSequence title) { + mTitle = title; + getSupportActionBar().setTitle(mTitle); + } + + //side menu navigation methods + + public void onNavigateToAboutClicked(View v) { + mDrawerRootLayout.closeDrawers(); + returnToRootFragment(); + } + + public void onNavigateToKeyboardAddonSettings(View v) { + mDrawerRootLayout.closeDrawers(); + addFragmentToUi(new KeyboardAddOnSettingsFragment(), FragmentUiContext.RootFragment); + } + + public void onNavigateToDictionarySettings(View v) { + mDrawerRootLayout.closeDrawers(); + addFragmentToUi(new DictionariesFragment(), FragmentUiContext.RootFragment); + } + + public void onNavigateToLanguageSettings(View v) { + mDrawerRootLayout.closeDrawers(); + addFragmentToUi(new AdditionalLanguageSettingsFragment(), FragmentUiContext.RootFragment); + + } + + public void onNavigateToKeyboardThemeSettings(View v) { + mDrawerRootLayout.closeDrawers(); + addFragmentToUi(new KeyboardThemeSelectorFragment(), FragmentUiContext.RootFragment); + } + + public void onNavigateToEffectsSettings(View v) { + mDrawerRootLayout.closeDrawers(); + //TODO: start additional language settings fragment + } + + public void onNavigateToGestureSettings(View v) { + mDrawerRootLayout.closeDrawers(); + //TODO: start additional language settings fragment + } + + public void onNavigateToUserInterfaceSettings(View v) { + mDrawerRootLayout.closeDrawers(); + addFragmentToUi(new AdditionalUiSettingsFragment(), FragmentUiContext.RootFragment); + } +} diff --git a/src/main/java/com/menny/android/anysoftkeyboard/LauncherSettingsActivity.java b/src/main/java/com/menny/android/anysoftkeyboard/LauncherSettingsActivity.java index a69817c9b..c1d4f293f 100644 --- a/src/main/java/com/menny/android/anysoftkeyboard/LauncherSettingsActivity.java +++ b/src/main/java/com/menny/android/anysoftkeyboard/LauncherSettingsActivity.java @@ -20,7 +20,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import com.anysoftkeyboard.ui.settings.MainSettings; +import com.anysoftkeyboard.ui.settings.MainSettingsActivity; /* * Why is this class exists? @@ -30,7 +30,7 @@ public class LauncherSettingsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - startActivity(new Intent(this, MainSettings.class)); + startActivity(new Intent(this, MainSettingsActivity.class)); finish();//no need for this activity anymore. } } |
