move some shared activity code to CommonActivity

This commit is contained in:
Andrew Dolgov 2012-06-24 23:52:23 +04:00
parent ff63819a65
commit 099377a665
3 changed files with 120 additions and 143 deletions

View File

@ -0,0 +1,71 @@
package org.fox.ttrss;
import org.fox.ttrss.util.DatabaseHelper;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
public class CommonActivity extends FragmentActivity {
private final String TAG = this.getClass().getSimpleName();
private SQLiteDatabase m_readableDb;
private SQLiteDatabase m_writableDb;
private boolean m_smallScreenMode;
private boolean m_compatMode = false;
private void initDatabase() {
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
m_writableDb = dh.getWritableDatabase();
m_readableDb = dh.getReadableDatabase();
}
public synchronized SQLiteDatabase getReadableDb() {
return m_readableDb;
}
public synchronized SQLiteDatabase getWritableDb() {
return m_writableDb;
}
@Override
public void onDestroy() {
super.onDestroy();
m_readableDb.close();
m_writableDb.close();
}
@Override
public void onCreate(Bundle savedInstanceState) {
initDatabase();
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE;
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode);
Log.d(TAG, "m_compatMode=" + m_compatMode);
super.onCreate(savedInstanceState);
}
public boolean isSmallScreen() {
return m_smallScreenMode;
}
public boolean isCompatMode() {
return m_compatMode;
}
public int getOrientation() {
return getWindowManager().getDefaultDisplay().getOrientation();
}
}

View File

@ -19,7 +19,6 @@ import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.FeedCategory; import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.types.Label; import org.fox.ttrss.types.Label;
import org.fox.ttrss.util.AppRater; import org.fox.ttrss.util.AppRater;
import org.fox.ttrss.util.DatabaseHelper;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -34,15 +33,12 @@ import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager; 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.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
@ -66,7 +62,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 FragmentActivity implements OnlineServices { public class MainActivity extends CommonActivity implements OnlineServices {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
protected final static String FRAG_HEADLINES = "headlines"; protected final static String FRAG_HEADLINES = "headlines";
@ -83,10 +79,8 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
private Timer m_refreshTimer; private Timer m_refreshTimer;
private RefreshTask m_refreshTask; private RefreshTask m_refreshTask;
private Menu m_menu; private Menu m_menu;
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;
@ -95,9 +89,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
private int m_selectedProduct = -1; private int m_selectedProduct = -1;
private long m_lastRefresh = 0; private long m_lastRefresh = 0;
private SQLiteDatabase m_readableDb;
private SQLiteDatabase m_writableDb;
private ActionMode m_headlinesActionMode; private ActionMode m_headlinesActionMode;
private HeadlinesActionModeCallback m_headlinesActionModeCallback; private HeadlinesActionModeCallback m_headlinesActionModeCallback;
private NavigationListener m_navigationListener; private NavigationListener m_navigationListener;
@ -141,7 +132,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_selectedArticle = null; m_selectedArticle = null;
m_activeCategory = null; m_activeCategory = null;
if (m_smallScreenMode) { if (isSmallScreen()) {
if (m_enableCats) { if (m_enableCats) {
ft.replace(R.id.fragment_container, new FeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.fragment_container, new FeedCategoriesFragment(), FRAG_CATS);
@ -188,7 +179,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
Fragment hf = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); Fragment hf = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) ft.remove(hf); if (hf != null) ft.remove(hf);
@ -238,7 +229,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_selectedArticle = null; m_selectedArticle = null;
if (!m_smallScreenMode) if (!isSmallScreen())
findViewById(R.id.article_fragment).setVisibility(View.GONE); findViewById(R.id.article_fragment).setVisibility(View.GONE);
viewFeed(m_feed, false); viewFeed(m_feed, false);
@ -617,25 +608,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
return m_sessionId; return m_sessionId;
} }
@Override
public boolean isSmallScreen() {
return m_smallScreenMode;
}
@Override
public int getOrientation() {
return getWindowManager().getDefaultDisplay().getOrientation();
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
initDatabase();
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 {
@ -670,9 +647,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_enableCats = m_prefs.getBoolean("enable_cats", false); m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main); setContentView(R.layout.main);
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
@ -687,12 +661,10 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_isOffline = localPrefs.getBoolean("offline_mode_active", false); m_isOffline = localPrefs.getBoolean("offline_mode_active", false);
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_compatMode=" + m_compatMode);
if (!m_compatMode) { if (!isCompatMode()) {
if (!m_smallScreenMode) { if (!isSmallScreen()) {
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticle != null && getOrientation() % 2 != 0 ? View.GONE : View.VISIBLE); findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticle != null && getOrientation() % 2 != 0 ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(m_selectedArticle != null ? View.VISIBLE : View.GONE); findViewById(R.id.article_fragment).setVisibility(m_selectedArticle != null ? View.VISIBLE : View.GONE);
} }
@ -708,7 +680,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
getActionBar().setListNavigationCallbacks(m_navigationAdapter, m_navigationListener); getActionBar().setListNavigationCallbacks(m_navigationAdapter, m_navigationListener);
} }
if (m_smallScreenMode) { if (isSmallScreen()) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_selectedArticle != null) { if (m_selectedArticle != null) {
@ -742,20 +714,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
} }
} }
private void initDatabase() {
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
m_writableDb = dh.getWritableDatabase();
m_readableDb = dh.getReadableDatabase();
}
public synchronized SQLiteDatabase getReadableDb() {
return m_readableDb;
}
public synchronized SQLiteDatabase getWritableDb() {
return m_writableDb;
}
private void switchOffline() { private void switchOffline() {
if (m_offlineModeStatus == 2) { if (m_offlineModeStatus == 2) {
@ -977,7 +935,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_activeCategory = null; m_activeCategory = null;
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, new FeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.fragment_container, new FeedCategoriesFragment(), FRAG_CATS);
} else { } else {
ft.replace(R.id.feeds_fragment, new FeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.feeds_fragment, new FeedCategoriesFragment(), FRAG_CATS);
@ -1003,7 +961,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
} }
private void goBack(boolean allowQuit) { private void goBack(boolean allowQuit) {
if (m_smallScreenMode) { if (isSmallScreen()) {
if (m_selectedArticle != null) { if (m_selectedArticle != null) {
closeArticle(); closeArticle();
} else if (m_activeFeed != null) { } else if (m_activeFeed != null) {
@ -1100,7 +1058,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
goBack(false); goBack(false);
return true; return true;
case R.id.search: case R.id.search:
if (hf != null && m_compatMode) { if (hf != null && isCompatMode()) {
Dialog dialog = new Dialog(this); Dialog dialog = new Dialog(this);
final EditText edit = new EditText(this); final EditText edit = new EditText(this);
@ -1455,7 +1413,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.remove(getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE)); ft.remove(getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE));
ft.show(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES)); ft.show(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
} else { } else {
@ -1493,7 +1451,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
numSelected = hf.getSelectedArticles().size(); numSelected = hf.getSelectedArticles().size();
if (numSelected != 0) { if (numSelected != 0) {
if (m_compatMode) { if (isCompatMode()) {
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else { } else {
if (m_headlinesActionMode == null) if (m_headlinesActionMode == null)
@ -1509,7 +1467,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
search.setEnabled(m_apiLevel >= 2); search.setEnabled(m_apiLevel >= 2);
if (!m_compatMode) { if (!isCompatMode()) {
SearchView searchView = (SearchView) search.getActionView(); SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = ""; private String query = "";
@ -1552,7 +1510,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_headlinesActionMode.finish(); m_headlinesActionMode.finish();
} }
if (!m_compatMode) { if (!isCompatMode()) {
/* if (m_activeFeed != null) { /* if (m_activeFeed != null) {
getActionBar().setTitle(m_activeFeed.title); getActionBar().setTitle(m_activeFeed.title);
@ -1564,7 +1522,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
m_navigationAdapter.clear(); m_navigationAdapter.clear();
if (m_activeCategory != null || (m_activeFeed != null && m_smallScreenMode)) { if (m_activeCategory != null || (m_activeFeed != null && isSmallScreen())) {
getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
@ -1587,7 +1545,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
getActionBar().setTitle(R.string.app_name); getActionBar().setTitle(R.string.app_name);
} }
if (m_smallScreenMode) { if (isSmallScreen()) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null || m_activeFeed != null); getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null || m_activeFeed != null);
} else { } else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null); getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null);
@ -1637,10 +1595,6 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
super.onDestroy(); super.onDestroy();
unregisterReceiver(m_broadcastReceiver); unregisterReceiver(m_broadcastReceiver);
m_readableDb.close();
m_writableDb.close();
} }
private void syncOfflineData() { private void syncOfflineData() {
@ -1721,7 +1675,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
if (m_enableCats) { if (m_enableCats) {
FeedCategoriesFragment frag = new FeedCategoriesFragment(); FeedCategoriesFragment frag = new FeedCategoriesFragment();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, FRAG_CATS); ft.replace(R.id.fragment_container, frag, FRAG_CATS);
} else { } else {
ft.replace(R.id.feeds_fragment, frag, FRAG_CATS); ft.replace(R.id.feeds_fragment, frag, FRAG_CATS);
@ -1729,7 +1683,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
} else { } else {
FeedsFragment frag = new FeedsFragment(); FeedsFragment frag = new FeedsFragment();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, FRAG_FEEDS); ft.replace(R.id.fragment_container, frag, FRAG_FEEDS);
} else { } else {
ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS);
@ -1820,7 +1774,7 @@ public class MainActivity extends FragmentActivity 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 && !m_compatMode) { if (search != null && !isCompatMode()) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1831,7 +1785,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
Fragment cats = getSupportFragmentManager().findFragmentByTag(FRAG_CATS); Fragment cats = getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
if (cats != null) ft.hide(cats); if (cats != null) ft.hide(cats);
@ -1869,7 +1823,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, FRAG_FEEDS); ft.replace(R.id.fragment_container, frag, FRAG_FEEDS);
} else { } else {
ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS);
@ -1882,7 +1836,7 @@ public class MainActivity extends FragmentActivity 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 && !m_compatMode) { if (search != null && !isCompatMode()) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1910,14 +1864,14 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
Fragment frag; Fragment frag;
if (m_smallScreenMode || m_prefs.getBoolean("tablet_article_swipe", false)) { if (isSmallScreen() || m_prefs.getBoolean("tablet_article_swipe", false)) {
frag = new ArticlePager(article); frag = new ArticlePager(article);
} else { } else {
frag = new ArticleFragment(article); frag = new ArticleFragment(article);
} }
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES)); ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
ft.add(R.id.fragment_container, frag, FRAG_ARTICLE); ft.add(R.id.fragment_container, frag, FRAG_ARTICLE);
} else { } else {

View File

@ -2,13 +2,13 @@ package org.fox.ttrss.offline;
import java.util.ArrayList; import java.util.ArrayList;
import org.fox.ttrss.CommonActivity;
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.OnlineServices.RelativeArticle; import org.fox.ttrss.OnlineServices.RelativeArticle;
import org.fox.ttrss.PreferencesActivity; import org.fox.ttrss.PreferencesActivity;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.util.DatabaseHelper;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.app.ActionBar; import android.app.ActionBar;
@ -20,15 +20,12 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement; 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.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
@ -45,7 +42,7 @@ import android.widget.SearchView;
import android.widget.ShareActionProvider; import android.widget.ShareActionProvider;
import android.widget.Toast; import android.widget.Toast;
public class OfflineActivity extends FragmentActivity implements public class OfflineActivity extends CommonActivity implements
OfflineServices { OfflineServices {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
@ -57,10 +54,8 @@ public class OfflineActivity extends FragmentActivity implements
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
private String m_themeName = ""; private String m_themeName = "";
private Menu m_menu; private Menu m_menu;
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;
@ -68,14 +63,6 @@ public class OfflineActivity extends FragmentActivity implements
private int m_activeCatId = -1; private int m_activeCatId = -1;
private int m_selectedArticleId = 0; private int m_selectedArticleId = 0;
private SQLiteDatabase m_readableDb;
private SQLiteDatabase m_writableDb;
@Override
public boolean isSmallScreen() {
return m_smallScreenMode;
}
private ActionMode m_headlinesActionMode; private ActionMode m_headlinesActionMode;
private HeadlinesActionModeCallback m_headlinesActionModeCallback; private HeadlinesActionModeCallback m_headlinesActionModeCallback;
private NavigationListener m_navigationListener; private NavigationListener m_navigationListener;
@ -96,7 +83,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
if (m_enableCats) { if (m_enableCats) {
ft.replace(R.id.fragment_container, new OfflineFeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.fragment_container, new OfflineFeedCategoriesFragment(), FRAG_CATS);
@ -146,7 +133,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
Fragment hf = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); Fragment hf = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) ft.remove(hf); if (hf != null) ft.remove(hf);
@ -192,7 +179,7 @@ public class OfflineActivity extends FragmentActivity implements
m_selectedArticleId = 0; m_selectedArticleId = 0;
if (!m_smallScreenMode) if (!isSmallScreen())
findViewById(R.id.article_fragment).setVisibility(View.GONE); findViewById(R.id.article_fragment).setVisibility(View.GONE);
viewFeed(m_feed, false); viewFeed(m_feed, false);
@ -273,13 +260,9 @@ public class OfflineActivity extends FragmentActivity implements
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
initDatabase();
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 {
@ -307,16 +290,10 @@ public class OfflineActivity extends FragmentActivity implements
m_enableCats = m_prefs.getBoolean("enable_cats", false); m_enableCats = m_prefs.getBoolean("enable_cats", false);
m_smallScreenMode = m_compatMode || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) !=
Configuration.SCREENLAYOUT_SIZE_XLARGE;
setContentView(R.layout.main); setContentView(R.layout.main);
Log.d(TAG, "m_smallScreenMode=" + m_smallScreenMode); if (!isCompatMode()) {
Log.d(TAG, "m_compatMode=" + m_compatMode); if (!isSmallScreen()) {
if (!m_compatMode) {
if (!m_smallScreenMode) {
findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticleId != 0 && getOrientation() % 2 != 0 ? View.GONE : View.VISIBLE); findViewById(R.id.feeds_fragment).setVisibility(m_selectedArticleId != 0 && getOrientation() % 2 != 0 ? View.GONE : View.VISIBLE);
findViewById(R.id.article_fragment).setVisibility(m_selectedArticleId != 0 ? View.VISIBLE : View.GONE); findViewById(R.id.article_fragment).setVisibility(m_selectedArticleId != 0 ? View.VISIBLE : View.GONE);
} }
@ -353,7 +330,7 @@ public class OfflineActivity extends FragmentActivity implements
tag = FRAG_FEEDS; tag = FRAG_FEEDS;
} }
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, tag); ft.replace(R.id.fragment_container, frag, tag);
} else { } else {
ft.replace(R.id.feeds_fragment, frag, tag); ft.replace(R.id.feeds_fragment, frag, tag);
@ -363,22 +340,6 @@ public class OfflineActivity extends FragmentActivity implements
} }
} }
private void initDatabase() {
DatabaseHelper dh = new DatabaseHelper(getApplicationContext());
m_writableDb = dh.getWritableDatabase();
m_readableDb = dh.getReadableDatabase();
}
@Override
public synchronized SQLiteDatabase getReadableDb() {
return m_readableDb;
}
@Override
public synchronized SQLiteDatabase getWritableDb() {
return m_writableDb;
}
private void switchOnline() { private void switchOnline() {
SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE); SharedPreferences localPrefs = getSharedPreferences("localprefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = localPrefs.edit(); SharedPreferences.Editor editor = localPrefs.edit();
@ -477,7 +438,7 @@ public class OfflineActivity extends FragmentActivity implements
} }
private void goBack(boolean allowQuit) { private void goBack(boolean allowQuit) {
if (m_smallScreenMode) { if (isSmallScreen()) {
if (m_selectedArticleId != 0) { if (m_selectedArticleId != 0) {
closeArticle(); closeArticle();
} else if (m_activeFeedId != 0) { } else if (m_activeFeedId != 0) {
@ -542,8 +503,8 @@ public class OfflineActivity extends FragmentActivity implements
* @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if * @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if
* (keyCode == KeyEvent.KEYCODE_BACK) { * (keyCode == KeyEvent.KEYCODE_BACK) {
* *
* if (m_smallScreenMode) { if (m_selectedArticleId != 0) { closeArticle(); * if (isSmallScreen()) { if (m_selectedArticleId != 0) { closeArticle();
* } else if (m_activeFeedId != 0) { if (m_compatMode) { * } else if (m_activeFeedId != 0) { if (isCompatMode()) {
* findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, * findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this,
* R.anim.slide_right)); } * R.anim.slide_right)); }
*/ */
@ -646,7 +607,7 @@ public class OfflineActivity extends FragmentActivity implements
goBack(false); goBack(false);
return true; return true;
case R.id.search: case R.id.search:
if (ohf != null && m_compatMode) { if (ohf != null && isCompatMode()) {
Dialog dialog = new Dialog(this); Dialog dialog = new Dialog(this);
final EditText edit = new EditText(this); final EditText edit = new EditText(this);
@ -875,7 +836,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.remove(getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE)); ft.remove(getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE));
ft.show(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES)); ft.show(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
} else { } else {
@ -912,7 +873,7 @@ public class OfflineActivity extends FragmentActivity 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_compatMode) { if (isCompatMode()) {
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true);
} else { } else {
if (m_headlinesActionMode == null) if (m_headlinesActionMode == null)
@ -925,7 +886,7 @@ public class OfflineActivity extends FragmentActivity implements
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
if (!m_compatMode) { if (!isCompatMode()) {
SearchView searchView = (SearchView) search.getActionView(); SearchView searchView = (SearchView) search.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private String query = ""; private String query = "";
@ -968,7 +929,7 @@ public class OfflineActivity extends FragmentActivity implements
m_headlinesActionMode.finish(); m_headlinesActionMode.finish();
} }
if (!m_compatMode) { if (!isCompatMode()) {
/* if (m_activeFeedId != 0) { /* if (m_activeFeedId != 0) {
if (!m_activeFeedIsCat) { if (!m_activeFeedIsCat) {
@ -997,7 +958,7 @@ public class OfflineActivity extends FragmentActivity implements
m_navigationAdapter.clear(); m_navigationAdapter.clear();
if (m_activeCatId != -1 || (m_activeFeedId != 0 && m_smallScreenMode)) { if (m_activeCatId != -1 || (m_activeFeedId != 0 && isSmallScreen())) {
getActionBar().setDisplayShowTitleEnabled(false); getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
@ -1033,7 +994,7 @@ public class OfflineActivity extends FragmentActivity implements
getActionBar().setTitle(R.string.app_name); getActionBar().setTitle(R.string.app_name);
} }
if (m_smallScreenMode) { if (isSmallScreen()) {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0 || m_activeCatId != -1); getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0 || m_activeCatId != -1);
} else { } else {
getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeCatId != -1); getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeCatId != -1);
@ -1061,10 +1022,6 @@ public class OfflineActivity extends FragmentActivity implements
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
m_readableDb.close();
m_writableDb.close();
} }
private void refreshViews() { private void refreshViews() {
@ -1392,7 +1349,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, FRAG_FEEDS); ft.replace(R.id.fragment_container, frag, FRAG_FEEDS);
} else { } else {
ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, frag, FRAG_FEEDS);
@ -1405,7 +1362,7 @@ public class OfflineActivity extends FragmentActivity 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 && !m_compatMode) { if (search != null && !isCompatMode()) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1436,7 +1393,7 @@ public class OfflineActivity extends FragmentActivity 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 && !m_compatMode) { if (search != null && !isCompatMode()) {
SearchView sv = (SearchView) search.getActionView(); SearchView sv = (SearchView) search.getActionView();
sv.setQuery("", false); sv.setQuery("", false);
} }
@ -1445,7 +1402,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(feedId, isCat); OfflineHeadlinesFragment frag = new OfflineHeadlinesFragment(feedId, isCat);
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, frag, FRAG_HEADLINES); ft.replace(R.id.fragment_container, frag, FRAG_HEADLINES);
} else { } else {
findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE); findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE);
@ -1478,7 +1435,7 @@ public class OfflineActivity extends FragmentActivity implements
Fragment frag; Fragment frag;
if (m_smallScreenMode || m_prefs.getBoolean("tablet_article_swipe", false)) { if (isSmallScreen() || m_prefs.getBoolean("tablet_article_swipe", false)) {
frag = new OfflineArticlePager(articleId); frag = new OfflineArticlePager(articleId);
} else { } else {
frag = new OfflineArticleFragment(articleId); frag = new OfflineArticleFragment(articleId);
@ -1486,7 +1443,7 @@ public class OfflineActivity extends FragmentActivity implements
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES)); ft.hide(getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES));
ft.add(R.id.fragment_container, frag, FRAG_ARTICLE); ft.add(R.id.fragment_container, frag, FRAG_ARTICLE);
} else { } else {
@ -1516,7 +1473,7 @@ public class OfflineActivity extends FragmentActivity implements
m_activeCatId = -1; m_activeCatId = -1;
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_smallScreenMode) { if (isSmallScreen()) {
ft.replace(R.id.fragment_container, new OfflineFeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.fragment_container, new OfflineFeedCategoriesFragment(), FRAG_CATS);
} else { } else {
ft.replace(R.id.feeds_fragment, new OfflineFeedCategoriesFragment(), FRAG_CATS); ft.replace(R.id.feeds_fragment, new OfflineFeedCategoriesFragment(), FRAG_CATS);
@ -1532,9 +1489,4 @@ public class OfflineActivity extends FragmentActivity implements
public boolean activeFeedIsCat() { public boolean activeFeedIsCat() {
return m_activeFeedIsCat; return m_activeFeedIsCat;
} }
@Override
public int getOrientation() {
return getWindowManager().getDefaultDisplay().getOrientation();
}
} }