remove m_compatMode stuff; add missing FragmentStagePagerAdapter hack

This commit is contained in:
Andrew Dolgov 2012-06-19 14:05:04 +04:00
parent ca65a6cdfa
commit 01151df966
5 changed files with 333 additions and 224 deletions

View File

@ -15,15 +15,9 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;

View File

@ -1,18 +1,18 @@
package org.fox.ttrss;
import static org.fox.ttrss.BillingConstants.*;
import java.util.ArrayList;
import static org.fox.ttrss.BillingConstants.ACTION_NOTIFY;
import static org.fox.ttrss.BillingConstants.ACTION_PURCHASE_STATE_CHANGED;
import static org.fox.ttrss.BillingConstants.ACTION_RESPONSE_CODE;
import static org.fox.ttrss.BillingConstants.INAPP_REQUEST_ID;
import static org.fox.ttrss.BillingConstants.INAPP_RESPONSE_CODE;
import static org.fox.ttrss.BillingConstants.INAPP_SIGNATURE;
import static org.fox.ttrss.BillingConstants.INAPP_SIGNED_DATA;
import static org.fox.ttrss.BillingConstants.NOTIFICATION_ID;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.util.Log;
import org.fox.ttrss.BillingConstants;
import org.fox.ttrss.BillingSecurity.VerifiedPurchase;
public class BillingReceiver extends BroadcastReceiver {
private static final String TAG = "BillingService";

View File

@ -0,0 +1,226 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* 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 org.fox.ttrss;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
/**
* Implementation of {@link android.support.v4.view.PagerAdapter} that
* uses a {@link Fragment} to manage each page. This class also handles
* saving and restoring of fragment's state.
*
* <p>This version of the pager is more useful when there are a large number
* of pages, working more like a list view. When pages are not visible to
* the user, their entire fragment may be destroyed, only keeping the saved
* state of that fragment. This allows the pager to hold on to much less
* memory associated with each visited page as compared to
* {@link FragmentPagerAdapter} at the cost of potentially more overhead when
* switching between pages.
*
* <p>When using FragmentPagerAdapter the host ViewPager must have a
* valid ID set.</p>
*
* <p>Subclasses only need to implement {@link #getItem(int)}
* and {@link #getCount()} to have a working adapter.
*
* <p>Here is an example implementation of a pager containing fragments of
* lists:
*
* {@sample development/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentStatePagerSupport.java
* complete}
*
* <p>The <code>R.layout.fragment_pager</code> resource of the top-level fragment is:
*
* {@sample development/samples/Support4Demos/res/layout/fragment_pager.xml
* complete}
*
* <p>The <code>R.layout.fragment_pager_list</code> resource containing each
* individual fragment's layout is:
*
* {@sample development/samples/Support4Demos/res/layout/fragment_pager_list.xml
* complete}
*/
public abstract class FragmentStatePagerAdapter extends PagerAdapter {
private static final String TAG = "FragmentStatePagerAdapter";
private static final boolean DEBUG = false;
private final FragmentManager mFragmentManager;
private FragmentTransaction mCurTransaction = null;
private ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
private ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
private Fragment mCurrentPrimaryItem = null;
public FragmentStatePagerAdapter(FragmentManager fm) {
mFragmentManager = fm;
}
/**
* Return the Fragment associated with a specified position.
*/
public abstract Fragment getItem(int position);
@Override
public void startUpdate(ViewGroup container) {
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// If we already have this item instantiated, there is nothing
// to do. This can happen when we are restoring the entire pager
// from its saved state, where the fragment manager has already
// taken care of restoring the fragments we previously had instantiated.
if (mFragments.size() > position) {
Fragment f = mFragments.get(position);
if (f != null) {
return f;
}
}
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
Fragment fragment = getItem(position);
if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
if (mSavedState.size() > position) {
Fragment.SavedState fss = mSavedState.get(position);
if (fss != null) {
fragment.setInitialSavedState(fss);
}
}
while (mFragments.size() <= position) {
mFragments.add(null);
}
fragment.setMenuVisibility(false);
mFragments.set(position, fragment);
mCurTransaction.add(container.getId(), fragment);
return fragment;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment)object;
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
}
if (DEBUG) Log.v(TAG, "Removing item #" + position + ": f=" + object
+ " v=" + ((Fragment)object).getView());
while (mSavedState.size() <= position) {
mSavedState.add(null);
}
mSavedState.set(position, mFragmentManager.saveFragmentInstanceState(fragment));
mFragments.set(position, null);
mCurTransaction.remove(fragment);
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
Fragment fragment = (Fragment)object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
fragment.setMenuVisibility(false);
}
if (fragment != null) {
fragment.setMenuVisibility(true);
}
mCurrentPrimaryItem = fragment;
}
}
@Override
public void finishUpdate(ViewGroup container) {
if (mCurTransaction != null) {
mCurTransaction.commitAllowingStateLoss();
mCurTransaction = null;
mFragmentManager.executePendingTransactions();
}
}
@Override
public boolean isViewFromObject(View view, Object object) {
return ((Fragment)object).getView() == view;
}
@Override
public Parcelable saveState() {
Bundle state = null;
if (mSavedState.size() > 0) {
state = new Bundle();
Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
mSavedState.toArray(fss);
state.putParcelableArray("states", fss);
}
for (int i=0; i<mFragments.size(); i++) {
Fragment f = mFragments.get(i);
if (f != null) {
if (state == null) {
state = new Bundle();
}
String key = "f" + i;
mFragmentManager.putFragment(state, key, f);
}
}
return state;
}
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
if (state != null) {
Bundle bundle = (Bundle)state;
bundle.setClassLoader(loader);
Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
mFragments.clear();
if (fss != null) {
for (int i=0; i<fss.length; i++) {
mSavedState.add((Fragment.SavedState)fss[i]);
}
}
Iterable<String> keys = bundle.keySet();
for (String key: keys) {
if (key.startsWith("f")) {
int index = Integer.parseInt(key.substring(1));
Fragment f = mFragmentManager.getFragment(bundle, key);
if (f != null) {
while (mFragments.size() <= index) {
mFragments.add(null);
}
f.setMenuVisibility(false);
mFragments.set(index, f);
} else {
Log.w(TAG, "Bad fragment at key " + key);
}
}
}
}
}
}

View File

@ -63,7 +63,6 @@ public class MainActivity extends Activity implements OnlineServices {
private boolean m_smallScreenMode;
private boolean m_unreadOnly = true;
private boolean m_unreadArticlesOnly = true;
private boolean m_compatMode = false;
private boolean m_enableCats = false;
private int m_apiLevel = 0;
private boolean m_isLoggingIn = false;
@ -435,8 +434,6 @@ public class MainActivity extends Activity implements OnlineServices {
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
setTheme(R.style.DarkTheme);
} else {
@ -463,7 +460,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main);
@ -481,18 +478,11 @@ public class MainActivity extends Activity implements OnlineServices {
Log.d(TAG, "m_isOffline=" + m_isOffline);
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
Log.d(TAG, "m_compatMode=" + m_compatMode);
if (!m_compatMode) {
if (android.os.Build.VERSION.SDK_INT < 14 || android.os.Build.VERSION.SDK_INT == 15) {
if (!m_smallScreenMode) {
LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
}
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
}
LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
if (m_isOffline) {
Intent offline = new Intent(MainActivity.this,
@ -925,44 +915,6 @@ public class MainActivity extends Activity implements OnlineServices {
return true;
case android.R.id.home:
goBack(false);
return true;
case R.id.search:
if (hf != null && m_compatMode) {
Dialog dialog = new Dialog(this);
final EditText edit = new EditText(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.search)
.setPositiveButton(getString(R.string.search),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String query = edit.getText().toString().trim();
hf.setSearchQuery(query);
}
})
.setNegativeButton(getString(R.string.cancel),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//
}
}).setView(edit);
dialog = builder.create();
dialog.show();
}
return true;
case R.id.preferences:
Intent intent = new Intent(MainActivity.this,
@ -1312,12 +1264,8 @@ public class MainActivity extends Activity implements OnlineServices {
numSelected = hf.getSelectedArticles().size();
if (numSelected != 0) {
if (m_compatMode) {
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else {
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
}
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
} else if (m_selectedArticle != null) {
m_menu.setGroupVisible(R.id.menu_group_article, true);
@ -1328,40 +1276,38 @@ public class MainActivity extends Activity implements OnlineServices {
search.setEnabled(m_apiLevel >= 2);
if (!m_compatMode) {
SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
@Override
public boolean onQueryTextSubmit(String query) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
@Override
public boolean onQueryTextSubmit(String query) {
if (frag != null) {
frag.setSearchQuery(query);
this.query = query;
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(query);
this.query = query;
frag.setSearchQuery(newText);
this.query = newText;
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(newText);
this.query = newText;
}
}
return false;
}
return false;
}
});
}
} else {
m_menu.setGroupVisible(R.id.menu_group_feeds, true);
@ -1371,33 +1317,29 @@ public class MainActivity extends Activity implements OnlineServices {
m_headlinesActionMode.finish();
}
if (!m_compatMode) {
if (m_activeFeed != null) {
getActionBar().setTitle(m_activeFeed.title);
} else if (m_activeCategory != null) {
getActionBar().setTitle(m_activeCategory.title);
} else {
getActionBar().setTitle(R.string.app_name);
}
if (!m_smallScreenMode) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null);
} else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeFeed != null || m_activeCategory != null);
}
if (android.os.Build.VERSION.SDK_INT >= 14) {
ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider();
if (m_selectedArticle != null) {
Log.d(TAG, "setting up share provider");
shareProvider.setShareIntent(getShareIntent(m_selectedArticle));
}
}
if (m_activeFeed != null) {
getActionBar().setTitle(m_activeFeed.title);
} else if (m_activeCategory != null) {
getActionBar().setTitle(m_activeCategory.title);
} else {
getActionBar().setTitle(R.string.app_name);
}
if (!m_smallScreenMode) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null);
} else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeFeed != null || m_activeCategory != null);
}
if (android.os.Build.VERSION.SDK_INT >= 14) {
ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider();
if (m_selectedArticle != null) {
Log.d(TAG, "setting up share provider");
shareProvider.setShareIntent(getShareIntent(m_selectedArticle));
}
}
m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.donate).setVisible(BillingHelper.isBillingSupported());
@ -1615,7 +1557,7 @@ public class MainActivity extends Activity implements OnlineServices {
if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search);
if (search != null && !m_compatMode) {
if (search != null) {
SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false);
}
@ -1663,7 +1605,7 @@ public class MainActivity extends Activity implements OnlineServices {
if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search);
if (search != null && !m_compatMode) {
if (search != null) {
SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false);
}

View File

@ -46,7 +46,6 @@ public class OfflineActivity extends Activity implements
private boolean m_smallScreenMode;
private boolean m_unreadOnly = true;
private boolean m_unreadArticlesOnly = true;
private boolean m_compatMode = false;
private boolean m_enableCats = false;
private int m_activeFeedId = 0;
@ -99,8 +98,6 @@ public class OfflineActivity extends Activity implements
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
setTheme(R.style.DarkTheme);
} else {
@ -124,24 +121,21 @@ public class OfflineActivity extends Activity implements
m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main);
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
Log.d(TAG, "m_compatMode=" + m_compatMode);
if (!m_compatMode) {
if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) {
if (!m_smallScreenMode) {
LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) {
if (!m_smallScreenMode) {
LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
}
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
initMainMenu();
@ -482,44 +476,6 @@ public class OfflineActivity extends Activity implements
switch (item.getItemId()) {
case android.R.id.home:
goBack(false);
return true;
case R.id.search:
if (ohf != null && m_compatMode) {
Dialog dialog = new Dialog(this);
final EditText edit = new EditText(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.search)
.setPositiveButton(getString(R.string.search),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
String query = edit.getText().toString().trim();
ohf.setSearchQuery(query);
}
})
.setNegativeButton(getString(R.string.cancel),
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//
}
}).setView(edit);
dialog = builder.create();
dialog.show();
}
return true;
case R.id.preferences:
Intent intent = new Intent(this, PreferencesActivity.class);
@ -746,12 +702,8 @@ public class OfflineActivity extends Activity implements
m_menu.setGroupVisible(R.id.menu_group_article, false);
if (numSelected != 0) {
if (m_compatMode) {
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else {
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
}
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
} else if (m_selectedArticleId != 0) {
m_menu.setGroupVisible(R.id.menu_group_article, true);
} else if (m_activeFeedId != 0) {
@ -759,40 +711,38 @@ public class OfflineActivity extends Activity implements
MenuItem search = m_menu.findItem(R.id.search);
if (!m_compatMode) {
SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
@Override
public boolean onQueryTextSubmit(String query) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
@Override
public boolean onQueryTextSubmit(String query) {
if (frag != null) {
frag.setSearchQuery(query);
this.query = query;
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(query);
this.query = query;
frag.setSearchQuery(newText);
this.query = newText;
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(newText);
this.query = newText;
}
}
return false;
}
});
}
return false;
}
});
} else {
m_menu.setGroupVisible(R.id.menu_group_feeds, true);
@ -802,23 +752,20 @@ public class OfflineActivity extends Activity implements
m_headlinesActionMode.finish();
}
if (!m_compatMode) {
if (m_activeFeedId != 0) {
Cursor feed = getFeedById(m_activeFeedId);
if (m_activeFeedId != 0) {
Cursor feed = getFeedById(m_activeFeedId);
if (feed != null) {
getActionBar().setTitle(feed.getString(feed.getColumnIndex("title")));
}
} else {
getActionBar().setTitle(R.string.app_name);
}
if (!m_smallScreenMode) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0);
} else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0);
if (feed != null) {
getActionBar().setTitle(feed.getString(feed.getColumnIndex("title")));
}
} else {
getActionBar().setTitle(R.string.app_name);
}
if (!m_smallScreenMode) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0);
} else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0);
}
}
}
@ -1145,7 +1092,7 @@ public class OfflineActivity extends Activity implements
if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search);
if (search != null && !m_compatMode) {
if (search != null) {
SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false);
}