revert ics fragment stuff

This commit is contained in:
Andrew Dolgov 2012-06-19 18:24:22 +04:00
parent 82035f4003
commit f5547cc4ac
16 changed files with 306 additions and 412 deletions

View File

@ -5,7 +5,7 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="C:/Users/fox/workspace/org.fox.ttrss/libs/gson-1.7.1.jar"/> <classpathentry kind="lib" path="C:/Users/fox/workspace/org.fox.ttrss/libs/gson-1.7.1.jar"/>
<classpathentry kind="lib" path="C:/Users/fox/workspace/org.fox.ttrss/libs/jsoup-1.6.1.jar"/> <classpathentry kind="lib" path="C:/Users/fox/workspace/org.fox.ttrss/libs/jsoup-1.6.1.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/> <classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss" package="org.fox.ttrss"
android:versionCode="73" android:versionCode="72"
android:versionName="0.6.0" > android:versionName="0.5.7" >
<uses-sdk android:minSdkVersion="14" /> <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Binary file not shown.

View File

@ -1,5 +1,6 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -15,27 +16,32 @@ import org.jsoup.select.Elements;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class ArticleFragment extends Fragment { public class ArticleFragment extends Fragment {
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -1,12 +1,12 @@
package org.fox.ttrss; package org.fox.ttrss;
import org.fox.ttrss.types.Article; import org.fox.ttrss.types.Article;
import org.fox.ttrss.util.FragmentStatePagerAdapter;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -57,7 +57,7 @@ public class ArticlePager extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.article_pager, container, false); View view = inflater.inflate(R.layout.article_pager, container, false);
m_adapter = new PagerAdapter(getActivity().getFragmentManager()); m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager());
ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager); ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager);
@ -96,7 +96,7 @@ public class ArticlePager extends Fragment {
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
m_hf = (HeadlinesFragment) getActivity().getFragmentManager().findFragmentById(R.id.headlines_fragment); m_hf = (HeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
m_onlineServices = (OnlineServices)activity; m_onlineServices = (OnlineServices)activity;
} }

View File

@ -1,7 +1,7 @@
package org.fox.ttrss; package org.fox.ttrss;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

View File

@ -10,12 +10,12 @@ import java.util.List;
import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategory;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;

View File

@ -7,6 +7,7 @@ import java.io.InputStream;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -20,8 +21,14 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.ClientContext; 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.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.BasicCredentialsProvider; 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.BasicHttpContext;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.Feed;
@ -29,7 +36,6 @@ import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.util.EasySSLSocketFactory; import org.fox.ttrss.util.EasySSLSocketFactory;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@ -40,6 +46,7 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;

View File

@ -1,5 +1,6 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.io.File;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -17,7 +18,6 @@ import org.fox.ttrss.types.Feed;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -26,6 +26,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.Html.ImageGetter; import android.text.Html.ImageGetter;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;

View File

@ -19,11 +19,8 @@ import org.fox.ttrss.util.AppRater;
import org.fox.ttrss.util.DatabaseHelper; import org.fox.ttrss.util.DatabaseHelper;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -39,6 +36,9 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -60,7 +60,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
public class MainActivity extends Activity implements OnlineServices { public class MainActivity extends FragmentActivity implements OnlineServices {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
@ -75,6 +75,7 @@ public class MainActivity extends Activity implements OnlineServices {
private boolean m_smallScreenMode; private boolean m_smallScreenMode;
private boolean m_unreadOnly = true; private boolean m_unreadOnly = true;
private boolean m_unreadArticlesOnly = true; private boolean m_unreadArticlesOnly = true;
private boolean m_compatMode = false;
private boolean m_enableCats = false; private boolean m_enableCats = false;
private int m_apiLevel = 0; private int m_apiLevel = 0;
private boolean m_isLoggingIn = false; private boolean m_isLoggingIn = false;
@ -144,7 +145,7 @@ public class MainActivity extends Activity implements OnlineServices {
}; };
public void updateHeadlines() { public void updateHeadlines() {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (frag != null) { if (frag != null) {
frag.notifyUpdated(); frag.notifyUpdated();
@ -362,7 +363,7 @@ public class MainActivity extends Activity implements OnlineServices {
private synchronized void refreshFeeds() { private synchronized void refreshFeeds() {
if (m_sessionId != null) { if (m_sessionId != null) {
FeedsFragment frag = (FeedsFragment) getFragmentManager() FeedsFragment frag = (FeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
Log.d(TAG, "Refreshing feeds..."); Log.d(TAG, "Refreshing feeds...");
@ -375,7 +376,7 @@ public class MainActivity extends Activity implements OnlineServices {
private synchronized void refreshHeadlines() { private synchronized void refreshHeadlines() {
if (m_sessionId != null) { if (m_sessionId != null) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
Log.d(TAG, "Refreshing headlines..."); Log.d(TAG, "Refreshing headlines...");
@ -388,7 +389,7 @@ public class MainActivity extends Activity implements OnlineServices {
private synchronized void refreshCategories() { private synchronized void refreshCategories() {
if (m_sessionId != null) { if (m_sessionId != null) {
FeedCategoriesFragment frag = (FeedCategoriesFragment) getFragmentManager() FeedCategoriesFragment frag = (FeedCategoriesFragment) getSupportFragmentManager()
.findFragmentById(R.id.cats_fragment); .findFragmentById(R.id.cats_fragment);
Log.d(TAG, "Refreshing categories..."); Log.d(TAG, "Refreshing categories...");
@ -418,7 +419,7 @@ public class MainActivity extends Activity implements OnlineServices {
* = unread; * = unread;
* *
* HeadlinesFragment frag = * HeadlinesFragment frag =
* (HeadlinesFragment)getFragmentManager().findFragmentById * (HeadlinesFragment)getSupportFragmentManager().findFragmentById
* (R.id.headlines_fragment); * (R.id.headlines_fragment);
* *
* if (frag != null) frag.refresh(false); } * if (frag != null) frag.refresh(false); }
@ -446,6 +447,8 @@ public class MainActivity extends Activity implements OnlineServices {
m_prefs = PreferenceManager m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()); .getDefaultSharedPreferences(getApplicationContext());
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
setTheme(R.style.DarkTheme); setTheme(R.style.DarkTheme);
} else { } else {
@ -472,7 +475,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_enableCats = m_prefs.getBoolean("enable_cats", false); m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE; Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main); setContentView(R.layout.main);
@ -490,11 +493,18 @@ public class MainActivity extends Activity implements OnlineServices {
Log.d(TAG, "m_isOffline=" + m_isOffline); Log.d(TAG, "m_isOffline=" + m_isOffline);
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode); Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
Log.d(TAG, "m_compatMode=" + m_compatMode);
LayoutTransition transitioner = new LayoutTransition(); if (!m_compatMode) {
((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) {
m_headlinesActionModeCallback = new HeadlinesActionModeCallback(); LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
}
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
}
if (m_isOffline) { if (m_isOffline) {
Intent offline = new Intent(MainActivity.this, Intent offline = new Intent(MainActivity.this,
@ -756,7 +766,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_activeCategory = null; m_activeCategory = null;
FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager()
.findFragmentById(R.id.cats_fragment); .findFragmentById(R.id.cats_fragment);
if (cf != null) { if (cf != null) {
@ -769,7 +779,7 @@ public class MainActivity extends Activity implements OnlineServices {
} }
private void deselectAllArticles() { private void deselectAllArticles() {
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null) { if (hf != null) {
@ -799,11 +809,11 @@ public class MainActivity extends Activity implements OnlineServices {
findViewById(R.id.cats_fragment) findViewById(R.id.cats_fragment)
.setVisibility(View.VISIBLE); .setVisibility(View.VISIBLE);
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.replace(R.id.headlines_fragment, new HeadlinesFragment());
ft.commit(); ft.commit();
FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager()
.findFragmentById(R.id.cats_fragment); .findFragmentById(R.id.cats_fragment);
if (cf != null) { if (cf != null) {
@ -818,14 +828,14 @@ public class MainActivity extends Activity implements OnlineServices {
findViewById(R.id.feeds_fragment).setVisibility( findViewById(R.id.feeds_fragment).setVisibility(
View.VISIBLE); View.VISIBLE);
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.replace(R.id.headlines_fragment, new HeadlinesFragment());
ft.commit(); ft.commit();
refreshFeeds(); refreshFeeds();
} }
FeedsFragment ff = (FeedsFragment) getFragmentManager() FeedsFragment ff = (FeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
if (ff != null) { if (ff != null) {
@ -857,7 +867,7 @@ public class MainActivity extends Activity implements OnlineServices {
findViewById(R.id.headlines_fragment).setVisibility( findViewById(R.id.headlines_fragment).setVisibility(
View.INVISIBLE); View.INVISIBLE);
FeedsFragment ff = (FeedsFragment) getFragmentManager() FeedsFragment ff = (FeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
if (ff != null) { if (ff != null) {
@ -866,7 +876,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_activeFeed = null; m_activeFeed = null;
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new HeadlinesFragment()); ft.replace(R.id.headlines_fragment, new HeadlinesFragment());
ft.commit(); ft.commit();
@ -882,7 +892,7 @@ public class MainActivity extends Activity implements OnlineServices {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
final HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
switch (item.getItemId()) { switch (item.getItemId()) {
@ -927,6 +937,44 @@ public class MainActivity extends Activity implements OnlineServices {
return true; return true;
case android.R.id.home: case android.R.id.home:
goBack(false); 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; return true;
case R.id.preferences: case R.id.preferences:
Intent intent = new Intent(MainActivity.this, Intent intent = new Intent(MainActivity.this,
@ -1240,7 +1288,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_selectedArticle = null; m_selectedArticle = null;
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, new DummyFragment()); ft.replace(R.id.article_fragment, new DummyFragment());
ft.commit(); ft.commit();
@ -1267,7 +1315,7 @@ public class MainActivity extends Activity implements OnlineServices {
m_menu.setGroupVisible(R.id.menu_group_logged_in, true); m_menu.setGroupVisible(R.id.menu_group_logged_in, true);
m_menu.setGroupVisible(R.id.menu_group_logged_out, false); m_menu.setGroupVisible(R.id.menu_group_logged_out, false);
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
int numSelected = 0; int numSelected = 0;
@ -1276,8 +1324,12 @@ public class MainActivity extends Activity implements OnlineServices {
numSelected = hf.getSelectedArticles().size(); numSelected = hf.getSelectedArticles().size();
if (numSelected != 0) { if (numSelected != 0) {
if (m_headlinesActionMode == null) if (m_compatMode) {
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else {
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
}
} else if (m_selectedArticle != null) { } else if (m_selectedArticle != null) {
m_menu.setGroupVisible(R.id.menu_group_article, true); m_menu.setGroupVisible(R.id.menu_group_article, true);
@ -1288,38 +1340,40 @@ public class MainActivity extends Activity implements OnlineServices {
search.setEnabled(m_apiLevel >= 2); search.setEnabled(m_apiLevel >= 2);
SearchView searchView = (SearchView) search.getActionView(); if (!m_compatMode) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { SearchView searchView = (SearchView) search.getActionView();
private String query = ""; searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
@Override
public boolean onQueryTextSubmit(String query) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) { @Override
frag.setSearchQuery(query); public boolean onQueryTextSubmit(String query) {
this.query = query; HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager()
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (frag != null) { if (frag != null) {
frag.setSearchQuery(newText); frag.setSearchQuery(query);
this.query = newText; this.query = query;
} }
return false;
} }
return false; @Override
} public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(newText);
this.query = newText;
}
}
return false;
}
}); });
}
} else { } else {
m_menu.setGroupVisible(R.id.menu_group_feeds, true); m_menu.setGroupVisible(R.id.menu_group_feeds, true);
@ -1329,28 +1383,32 @@ public class MainActivity extends Activity implements OnlineServices {
m_headlinesActionMode.finish(); m_headlinesActionMode.finish();
} }
if (m_activeFeed != null) { if (!m_compatMode) {
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) { if (m_activeFeed != null) {
Log.d(TAG, "setting up share provider"); getActionBar().setTitle(m_activeFeed.title);
shareProvider.setShareIntent(getShareIntent(m_selectedArticle)); } 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.set_labels).setEnabled(m_apiLevel >= 1);
@ -1463,7 +1521,7 @@ public class MainActivity extends Activity implements OnlineServices {
if (hasPendingOfflineData()) if (hasPendingOfflineData())
syncOfflineData(); syncOfflineData();
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_enableCats) { if (m_enableCats) {
FeedCategoriesFragment frag = new FeedCategoriesFragment(); FeedCategoriesFragment frag = new FeedCategoriesFragment();
@ -1569,7 +1627,7 @@ public class MainActivity extends Activity implements OnlineServices {
if (m_menu != null) { if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
if (search != null) { if (search != null && !m_compatMode) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1577,12 +1635,12 @@ public class MainActivity extends Activity implements OnlineServices {
HeadlinesFragment hf = new HeadlinesFragment(); HeadlinesFragment hf = new HeadlinesFragment();
FragmentTransaction ft = getFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
ft.replace(R.id.headlines_fragment, hf); ft.replace(R.id.headlines_fragment, hf);
ft.commit(); ft.commit();
} else { } else {
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null) { if (hf != null) {
hf.refresh(true); hf.refresh(true);
@ -1602,7 +1660,7 @@ public class MainActivity extends Activity implements OnlineServices {
FeedsFragment frag = new FeedsFragment(); FeedsFragment frag = new FeedsFragment();
FragmentTransaction ft = getFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
ft.replace(R.id.feeds_fragment, frag); ft.replace(R.id.feeds_fragment, frag);
ft.commit(); ft.commit();
@ -1617,7 +1675,7 @@ public class MainActivity extends Activity implements OnlineServices {
if (m_menu != null) { if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
if (search != null) { if (search != null && !m_compatMode) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1625,7 +1683,7 @@ public class MainActivity extends Activity implements OnlineServices {
HeadlinesFragment frag = new HeadlinesFragment(); HeadlinesFragment frag = new HeadlinesFragment();
FragmentTransaction ft = getFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
ft.replace(R.id.headlines_fragment, frag); ft.replace(R.id.headlines_fragment, frag);
ft.commit(); ft.commit();
@ -1645,7 +1703,7 @@ public class MainActivity extends Activity implements OnlineServices {
initMainMenu(); initMainMenu();
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null) { if (hf != null) {
@ -1669,7 +1727,7 @@ public class MainActivity extends Activity implements OnlineServices {
frag = new ArticleFragment(article); frag = new ArticleFragment(article);
} }
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, frag); ft.replace(R.id.article_fragment, frag);
ft.commit(); ft.commit();
@ -1764,11 +1822,11 @@ public class MainActivity extends Activity implements OnlineServices {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo(); .getMenuInfo();
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
FeedsFragment ff = (FeedsFragment) getFragmentManager() FeedsFragment ff = (FeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
FeedCategoriesFragment cf = (FeedCategoriesFragment) getFragmentManager() FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager()
.findFragmentById(R.id.cats_fragment); .findFragmentById(R.id.cats_fragment);
switch (item.getItemId()) { switch (item.getItemId()) {
@ -1926,7 +1984,7 @@ public class MainActivity extends Activity implements OnlineServices {
@Override @Override
public Article getRelativeArticle(Article article, RelativeArticle ra) { public Article getRelativeArticle(Article article, RelativeArticle ra) {
HeadlinesFragment frag = (HeadlinesFragment) getFragmentManager() HeadlinesFragment frag = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (frag != null) { if (frag != null) {
ArticleList articles = frag.getAllArticles(); ArticleList articles = frag.getAllArticles();
@ -1960,7 +2018,7 @@ public class MainActivity extends Activity implements OnlineServices {
switch (keyCode) { switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null && m_activeFeed != null) { if (hf != null && m_activeFeed != null) {
@ -1987,7 +2045,7 @@ public class MainActivity extends Activity implements OnlineServices {
return true; return true;
case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) { if (action == KeyEvent.ACTION_UP) {
HeadlinesFragment hf = (HeadlinesFragment) getFragmentManager() HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null && m_activeFeed != null) { if (hf != null && m_activeFeed != null) {

View File

@ -3,23 +3,14 @@ package org.fox.ttrss.offline;
import org.fox.ttrss.DummyFragment; import org.fox.ttrss.DummyFragment;
import org.fox.ttrss.MainActivity; import org.fox.ttrss.MainActivity;
import org.fox.ttrss.OnlineServices; import org.fox.ttrss.OnlineServices;
import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R;
import org.fox.ttrss.OnlineServices.RelativeArticle; import org.fox.ttrss.OnlineServices.RelativeArticle;
import org.fox.ttrss.R.anim; import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R.id;
import org.fox.ttrss.R.layout;
import org.fox.ttrss.R.menu;
import org.fox.ttrss.R.string;
import org.fox.ttrss.R.style;
import org.fox.ttrss.util.DatabaseHelper; import org.fox.ttrss.util.DatabaseHelper;
import org.fox.ttrss.R;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -33,6 +24,9 @@ import android.database.sqlite.SQLiteStatement;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -48,7 +42,7 @@ import android.widget.SearchView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class OfflineActivity extends Activity implements public class OfflineActivity extends FragmentActivity implements
OfflineServices { OfflineServices {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
@ -58,6 +52,7 @@ public class OfflineActivity extends Activity implements
private boolean m_smallScreenMode; private boolean m_smallScreenMode;
private boolean m_unreadOnly = true; private boolean m_unreadOnly = true;
private boolean m_unreadArticlesOnly = true; private boolean m_unreadArticlesOnly = true;
private boolean m_compatMode = false;
private boolean m_enableCats = false; private boolean m_enableCats = false;
private int m_activeFeedId = 0; private int m_activeFeedId = 0;
@ -110,6 +105,8 @@ public class OfflineActivity extends Activity implements
m_prefs = PreferenceManager m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext()); .getDefaultSharedPreferences(getApplicationContext());
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
setTheme(R.style.DarkTheme); setTheme(R.style.DarkTheme);
} else { } else {
@ -133,21 +130,24 @@ public class OfflineActivity extends Activity implements
m_enableCats = m_prefs.getBoolean("enable_cats", false); m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE; Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main); setContentView(R.layout.main);
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode); Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
Log.d(TAG, "m_compatMode=" + m_compatMode);
if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) { if (!m_compatMode) {
if (!m_smallScreenMode) { if (android.os.Build.VERSION.SDK_INT < 14 /* || android.os.Build.VERSION.SDK_INT == 15 */) {
LayoutTransition transitioner = new LayoutTransition(); if (!m_smallScreenMode) {
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner); LayoutTransition transitioner = new LayoutTransition();
((ViewGroup) findViewById(R.id.main)).setLayoutTransition(transitioner);
}
} }
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
} }
m_headlinesActionModeCallback = new HeadlinesActionModeCallback();
initMainMenu(); initMainMenu();
@ -196,7 +196,7 @@ public class OfflineActivity extends Activity implements
} }
if (m_activeFeedId == 0) { if (m_activeFeedId == 0) {
FragmentTransaction ft = getFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
OfflineFeedsFragment frag = new OfflineFeedsFragment(); OfflineFeedsFragment frag = new OfflineFeedsFragment();
ft.replace(R.id.feeds_fragment, frag); ft.replace(R.id.feeds_fragment, frag);
@ -343,14 +343,14 @@ public class OfflineActivity extends Activity implements
// } // }
m_activeFeedId = 0; m_activeFeedId = 0;
OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
if (ff != null) { if (ff != null) {
ff.setSelectedFeedId(0); ff.setSelectedFeedId(0);
} }
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment());
ft.commit(); ft.commit();
@ -367,14 +367,14 @@ public class OfflineActivity extends Activity implements
findViewById(R.id.headlines_fragment).setVisibility(View.INVISIBLE); findViewById(R.id.headlines_fragment).setVisibility(View.INVISIBLE);
m_activeFeedId = 0; m_activeFeedId = 0;
OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
if (ff != null) { if (ff != null) {
ff.setSelectedFeedId(0); ff.setSelectedFeedId(0);
} }
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment()); ft.replace(R.id.headlines_fragment, new OfflineHeadlinesFragment());
ft.commit(); ft.commit();
@ -472,7 +472,7 @@ public class OfflineActivity extends Activity implements
} }
private void refreshHeadlines() { private void refreshHeadlines() {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (ohf != null) { if (ohf != null) {
@ -482,12 +482,50 @@ public class OfflineActivity extends Activity implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
goBack(false); 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; return true;
case R.id.preferences: case R.id.preferences:
Intent intent = new Intent(this, PreferencesActivity.class); Intent intent = new Intent(this, PreferencesActivity.class);
@ -657,7 +695,7 @@ public class OfflineActivity extends Activity implements
} }
private void refreshFeeds() { private void refreshFeeds() {
OfflineFeedsFragment frag = (OfflineFeedsFragment) getFragmentManager() OfflineFeedsFragment frag = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
if (frag != null) { if (frag != null) {
@ -685,7 +723,7 @@ public class OfflineActivity extends Activity implements
m_selectedArticleId = 0; m_selectedArticleId = 0;
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, new DummyFragment()); ft.replace(R.id.article_fragment, new DummyFragment());
ft.commit(); ft.commit();
@ -714,8 +752,12 @@ public class OfflineActivity extends Activity implements
m_menu.setGroupVisible(R.id.menu_group_article, false); m_menu.setGroupVisible(R.id.menu_group_article, false);
if (numSelected != 0) { if (numSelected != 0) {
if (m_headlinesActionMode == null) if (m_compatMode) {
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else {
if (m_headlinesActionMode == null)
m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback);
}
} else if (m_selectedArticleId != 0) { } else if (m_selectedArticleId != 0) {
m_menu.setGroupVisible(R.id.menu_group_article, true); m_menu.setGroupVisible(R.id.menu_group_article, true);
} else if (m_activeFeedId != 0) { } else if (m_activeFeedId != 0) {
@ -723,38 +765,40 @@ public class OfflineActivity extends Activity implements
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
SearchView searchView = (SearchView) search.getActionView(); if (!m_compatMode) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { SearchView searchView = (SearchView) search.getActionView();
private String query = ""; searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = "";
@Override
public boolean onQueryTextSubmit(String query) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) { @Override
frag.setSearchQuery(query); public boolean onQueryTextSubmit(String query) {
this.query = query; OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager()
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.equals("") && !newText.equals(this.query)) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (frag != null) { if (frag != null) {
frag.setSearchQuery(newText); frag.setSearchQuery(query);
this.query = newText; this.query = query;
} }
return false;
} }
return false; @Override
} public boolean onQueryTextChange(String newText) {
}); if (newText.equals("") && !newText.equals(this.query)) {
OfflineHeadlinesFragment frag = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment);
if (frag != null) {
frag.setSearchQuery(newText);
this.query = newText;
}
}
return false;
}
});
}
} else { } else {
m_menu.setGroupVisible(R.id.menu_group_feeds, true); m_menu.setGroupVisible(R.id.menu_group_feeds, true);
@ -764,20 +808,23 @@ public class OfflineActivity extends Activity implements
m_headlinesActionMode.finish(); m_headlinesActionMode.finish();
} }
if (m_activeFeedId != 0) { if (!m_compatMode) {
Cursor feed = getFeedById(m_activeFeedId);
if (feed != null) { if (m_activeFeedId != 0) {
getActionBar().setTitle(feed.getString(feed.getColumnIndex("title"))); 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);
} }
} else {
getActionBar().setTitle(R.string.app_name);
}
if (!m_smallScreenMode) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0);
} else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0);
} }
} }
} }
@ -807,9 +854,9 @@ public class OfflineActivity extends Activity implements
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo(); .getMenuInfo();
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getFragmentManager() OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
OfflineFeedsFragment ff = (OfflineFeedsFragment) getFragmentManager() OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager()
.findFragmentById(R.id.feeds_fragment); .findFragmentById(R.id.feeds_fragment);
switch (item.getItemId()) { switch (item.getItemId()) {
@ -972,7 +1019,7 @@ public class OfflineActivity extends Activity implements
case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
int nextId = getRelativeArticleId(m_selectedArticleId, int nextId = getRelativeArticleId(m_selectedArticleId,
@ -1001,7 +1048,7 @@ public class OfflineActivity extends Activity implements
case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) { if (action == KeyEvent.ACTION_UP) {
OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getFragmentManager() OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
int prevId = getRelativeArticleId(m_selectedArticleId, int prevId = getRelativeArticleId(m_selectedArticleId,
@ -1104,13 +1151,13 @@ public class OfflineActivity extends Activity implements
if (m_menu != null) { if (m_menu != null) {
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
if (search != null) { if (search != null && !m_compatMode) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
} }
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(); OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment();
ft.replace(R.id.headlines_fragment, frag); ft.replace(R.id.headlines_fragment, frag);
ft.commit(); ft.commit();
@ -1123,7 +1170,7 @@ public class OfflineActivity extends Activity implements
initMainMenu(); initMainMenu();
OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getFragmentManager() OfflineHeadlinesFragment hf = (OfflineHeadlinesFragment) getSupportFragmentManager()
.findFragmentById(R.id.headlines_fragment); .findFragmentById(R.id.headlines_fragment);
if (hf != null) { if (hf != null) {
@ -1146,7 +1193,7 @@ public class OfflineActivity extends Activity implements
frag = new OfflineArticleFragment(articleId); frag = new OfflineArticleFragment(articleId);
} }
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_fragment, frag); ft.replace(R.id.article_fragment, frag);
ft.commit(); ft.commit();

View File

@ -15,20 +15,20 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.TextView; import android.widget.TextView;

View File

@ -3,14 +3,15 @@ package org.fox.ttrss.offline;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.R.id; import org.fox.ttrss.R.id;
import org.fox.ttrss.R.layout; import org.fox.ttrss.R.layout;
import org.fox.ttrss.util.FragmentStatePagerAdapter;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.database.Cursor;
import android.app.FragmentManager;
import android.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
import android.os.Bundle; import android.os.Bundle;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -61,7 +62,7 @@ public class OfflineArticlePager extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.article_pager, container, false); View view = inflater.inflate(R.layout.article_pager, container, false);
m_adapter = new PagerAdapter(getActivity().getFragmentManager()); m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager());
ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager); ViewPager pager = (ViewPager) view.findViewById(R.id.article_pager);
@ -104,7 +105,7 @@ public class OfflineArticlePager extends Fragment {
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
m_hf = (OfflineHeadlinesFragment) getActivity().getFragmentManager().findFragmentById(R.id.headlines_fragment); m_hf = (OfflineHeadlinesFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.headlines_fragment);
m_offlineServices = (OfflineServices)activity; m_offlineServices = (OfflineServices)activity;
} }

View File

@ -9,7 +9,6 @@ import org.fox.ttrss.R.layout;
import org.fox.ttrss.R.menu; import org.fox.ttrss.R.menu;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@ -20,6 +19,8 @@ import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -31,7 +32,6 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView; import android.widget.TextView;
public class OfflineFeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener { public class OfflineFeedsFragment extends Fragment implements OnItemClickListener, OnSharedPreferenceChangeListener {

View File

@ -14,7 +14,6 @@ import org.fox.ttrss.R.string;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
@ -24,6 +23,8 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SimpleCursorAdapter;
import android.text.Html; import android.text.Html;
import android.text.Html.ImageGetter; import android.text.Html.ImageGetter;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
@ -40,7 +41,6 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView; import android.widget.TextView;
public class OfflineHeadlinesFragment extends Fragment implements OnItemClickListener { public class OfflineHeadlinesFragment extends Fragment implements OnItemClickListener {

View File

@ -1,226 +0,0 @@
/*
* 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.util;
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);
}
}
}
}
}
}