Remove NoSwipeWrapContentViewPager

This commit is contained in:
mar-v-in 2014-08-17 11:07:34 +02:00
parent 28df004cbb
commit 3cc57a092a
3 changed files with 23 additions and 88 deletions

View file

@ -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

View file

@ -1,62 +0,0 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -9,13 +9,11 @@
<include layout="@layout/notify_area"/>
<org.sufficientlysecure.keychain.ui.widget.NoSwipeWrapContentViewPager
<FrameLayout
android:id="@+id/encrypt_pager_mode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</org.sufficientlysecure.keychain.ui.widget.NoSwipeWrapContentViewPager>
android:layout_height="wrap_content"
android:orientation="vertical" />
<android.support.v4.view.ViewPager
android:id="@+id/encrypt_pager_content"