From 3cc57a092a7ba59390b2d892db028cc1990cdbd1 Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Sun, 17 Aug 2014 11:07:34 +0200 Subject: [PATCH] Remove NoSwipeWrapContentViewPager --- .../keychain/ui/EncryptActivity.java | 41 ++++++------ .../widget/NoSwipeWrapContentViewPager.java | 62 ------------------- .../src/main/res/layout/encrypt_content.xml | 8 +-- 3 files changed, 23 insertions(+), 88 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NoSwipeWrapContentViewPager.java diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java index 7e08f6b7c..59a433af3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -73,16 +73,13 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryption_key_ids"; // view - ViewPager mViewPagerMode; - //PagerTabStrip mPagerTabStripMode; - PagerTabStripAdapter mTabsAdapterMode; - ViewPager mViewPagerContent; - PagerTabStrip mPagerTabStripContent; - PagerTabStripAdapter mTabsAdapterContent; + private int mCurrentMode = PAGER_MODE_ASYMMETRIC; + private ViewPager mViewPagerContent; + private PagerTabStrip mPagerTabStripContent; + private PagerTabStripAdapter mTabsAdapterContent; // tabs - int mSwitchToMode = PAGER_MODE_ASYMMETRIC; - int mSwitchToContent = PAGER_CONTENT_MESSAGE; + private int mSwitchToContent = PAGER_CONTENT_MESSAGE; private static final int PAGER_MODE_ASYMMETRIC = 0; private static final int PAGER_MODE_SYMMETRIC = 1; @@ -102,7 +99,7 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn private String mMessage = ""; public boolean isModeSymmetric() { - return PAGER_MODE_SYMMETRIC == mViewPagerMode.getCurrentItem(); + return PAGER_MODE_SYMMETRIC == mCurrentMode; } public boolean isContentMessage() { @@ -474,13 +471,9 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn } private void initView() { - mViewPagerMode = (ViewPager) findViewById(R.id.encrypt_pager_mode); - //mPagerTabStripMode = (PagerTabStrip) findViewById(R.id.encrypt_pager_tab_strip_mode); mViewPagerContent = (ViewPager) findViewById(R.id.encrypt_pager_content); mPagerTabStripContent = (PagerTabStrip) findViewById(R.id.encrypt_pager_tab_strip_content); - mTabsAdapterMode = new PagerTabStripAdapter(this); - mViewPagerMode.setAdapter(mTabsAdapterMode); mTabsAdapterContent = new PagerTabStripAdapter(this); mViewPagerContent.setAdapter(mTabsAdapterContent); } @@ -502,10 +495,7 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn // Handle intent actions handleActions(getIntent()); - - mTabsAdapterMode.addTab(EncryptAsymmetricFragment.class, null, getString(R.string.label_asymmetric)); - mTabsAdapterMode.addTab(EncryptSymmetricFragment.class, null, getString(R.string.label_symmetric)); - mViewPagerMode.setCurrentItem(mSwitchToMode); + updateModeFragment(); mTabsAdapterContent.addTab(EncryptMessageFragment.class, null, getString(R.string.label_message)); mTabsAdapterContent.addTab(EncryptFileFragment.class, null, getString(R.string.label_files)); @@ -521,6 +511,16 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn return super.onCreateOptionsMenu(menu); } + private void updateModeFragment() { + getSupportFragmentManager().beginTransaction() + .replace(R.id.encrypt_pager_mode, + mCurrentMode == PAGER_MODE_SYMMETRIC + ? new EncryptSymmetricFragment() + : new EncryptAsymmetricFragment()) + .commitAllowingStateLoss(); + getSupportFragmentManager().executePendingTransactions(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.isCheckable()) { @@ -528,9 +528,8 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn } switch (item.getItemId()) { case R.id.check_use_symmetric: - mSwitchToMode = item.isChecked() ? PAGER_MODE_SYMMETRIC : PAGER_MODE_ASYMMETRIC; - - mViewPagerMode.setCurrentItem(mSwitchToMode); + mCurrentMode = item.isChecked() ? PAGER_MODE_SYMMETRIC : PAGER_MODE_ASYMMETRIC; + updateModeFragment(); notifyUpdate(); break; case R.id.check_use_armor: @@ -604,7 +603,7 @@ public class EncryptActivity extends DrawerActivity implements EncryptActivityIn mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS); // preselect keys given by intent - mSwitchToMode = PAGER_MODE_ASYMMETRIC; + mCurrentMode = PAGER_MODE_ASYMMETRIC; /** * Main Actions diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NoSwipeWrapContentViewPager.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NoSwipeWrapContentViewPager.java deleted file mode 100644 index a48d2a026..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/NoSwipeWrapContentViewPager.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 . - */ - -package org.sufficientlysecure.keychain.ui.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; - -public class NoSwipeWrapContentViewPager extends android.support.v4.view.ViewPager { - public NoSwipeWrapContentViewPager(Context context) { - super(context); - } - - public NoSwipeWrapContentViewPager(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - - int height; - View child = getChildAt(getCurrentItem()); - if (child != null) { - child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - height = child.getMeasuredHeight(); - } else { - height = 0; - } - - heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); - - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent arg0) { - // Never allow swiping to switch between pages - return false; - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - // Never allow swiping to switch between pages - return false; - } -} diff --git a/OpenKeychain/src/main/res/layout/encrypt_content.xml b/OpenKeychain/src/main/res/layout/encrypt_content.xml index e5edc6657..d029e7b83 100644 --- a/OpenKeychain/src/main/res/layout/encrypt_content.xml +++ b/OpenKeychain/src/main/res/layout/encrypt_content.xml @@ -9,13 +9,11 @@ - - - + android:layout_height="wrap_content" + android:orientation="vertical" />