2012-06-24 19:52:23 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
|
|
import org.fox.ttrss.util.DatabaseHelper;
|
|
|
|
|
2012-09-19 09:37:12 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2013-04-04 06:41:34 +00:00
|
|
|
import android.content.SharedPreferences;
|
2012-06-24 19:52:23 +00:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.Bundle;
|
2013-04-04 06:41:34 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2012-06-24 19:52:23 +00:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
|
|
|
import android.util.Log;
|
2012-09-01 18:22:13 +00:00
|
|
|
import android.view.Display;
|
2012-09-21 06:56:49 +00:00
|
|
|
import android.view.View;
|
2012-09-16 09:25:28 +00:00
|
|
|
import android.widget.TextView;
|
2012-06-24 20:00:14 +00:00
|
|
|
import android.widget.Toast;
|
2012-06-24 19:52:23 +00:00
|
|
|
|
|
|
|
public class CommonActivity extends FragmentActivity {
|
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
2012-06-24 19:55:56 +00:00
|
|
|
public final static String FRAG_HEADLINES = "headlines";
|
|
|
|
public final static String FRAG_ARTICLE = "article";
|
|
|
|
public final static String FRAG_FEEDS = "feeds";
|
|
|
|
public final static String FRAG_CATS = "cats";
|
|
|
|
|
2012-06-24 19:52:23 +00:00
|
|
|
private SQLiteDatabase m_readableDb;
|
|
|
|
private SQLiteDatabase m_writableDb;
|
|
|
|
|
2012-09-01 19:51:38 +00:00
|
|
|
private boolean m_smallScreenMode = true;
|
2012-06-24 19:52:23 +00:00
|
|
|
private boolean m_compatMode = false;
|
|
|
|
|
2013-04-04 06:41:34 +00:00
|
|
|
protected SharedPreferences m_prefs;
|
|
|
|
|
2012-09-01 19:51:38 +00:00
|
|
|
protected void setSmallScreen(boolean smallScreen) {
|
|
|
|
Log.d(TAG, "m_smallScreenMode=" + smallScreen);
|
|
|
|
m_smallScreenMode = smallScreen;
|
|
|
|
}
|
|
|
|
|
2012-09-19 09:44:35 +00:00
|
|
|
public boolean getUnreadOnly() {
|
2013-04-04 06:42:09 +00:00
|
|
|
return m_prefs.getBoolean("show_unread_only", true);
|
2012-09-19 09:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setUnreadOnly(boolean unread) {
|
2013-04-04 06:41:34 +00:00
|
|
|
SharedPreferences.Editor editor = m_prefs.edit();
|
|
|
|
editor.putBoolean("show_unread_only", unread);
|
|
|
|
editor.commit();
|
2012-09-19 09:44:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
public void setLoadingStatus(int status, boolean showProgress) {
|
2012-09-16 09:25:28 +00:00
|
|
|
TextView tv = (TextView) findViewById(R.id.loading_message);
|
|
|
|
|
|
|
|
if (tv != null) {
|
|
|
|
tv.setText(status);
|
|
|
|
}
|
|
|
|
|
2012-09-21 06:56:49 +00:00
|
|
|
findViewById(R.id.loading_container).setVisibility(status == R.string.blank ? View.GONE : View.VISIBLE);
|
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
setProgressBarIndeterminateVisibility(showProgress);
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:00:02 +00:00
|
|
|
public void toast(int msgId) {
|
|
|
|
Toast toast = Toast.makeText(CommonActivity.this, msgId, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void toast(String msg) {
|
|
|
|
Toast toast = Toast.makeText(CommonActivity.this, msg, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:52:23 +00:00
|
|
|
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) {
|
2013-04-04 06:41:34 +00:00
|
|
|
m_prefs = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
2012-06-24 19:52:23 +00:00
|
|
|
initDatabase();
|
|
|
|
|
|
|
|
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
|
|
|
|
|
|
|
|
Log.d(TAG, "m_compatMode=" + m_compatMode);
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSmallScreen() {
|
|
|
|
return m_smallScreenMode;
|
|
|
|
}
|
2012-09-02 13:10:57 +00:00
|
|
|
|
2012-06-24 19:52:23 +00:00
|
|
|
public boolean isCompatMode() {
|
|
|
|
return m_compatMode;
|
|
|
|
}
|
|
|
|
|
2012-09-19 09:37:12 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-09-01 18:22:13 +00:00
|
|
|
public boolean isPortrait() {
|
|
|
|
Display display = getWindowManager().getDefaultDisplay();
|
|
|
|
|
|
|
|
int width = display.getWidth();
|
|
|
|
int height = display.getHeight();
|
|
|
|
|
|
|
|
return width < height;
|
2012-06-24 19:52:23 +00:00
|
|
|
}
|
2012-06-24 20:00:14 +00:00
|
|
|
|
2012-09-19 09:37:12 +00:00
|
|
|
@SuppressLint("NewApi")
|
|
|
|
@SuppressWarnings("deprecation")
|
2012-06-24 20:00:14 +00:00
|
|
|
public void copyToClipboard(String str) {
|
|
|
|
if (android.os.Build.VERSION.SDK_INT < 11) {
|
|
|
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(str);
|
|
|
|
} else {
|
|
|
|
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
Toast toast = Toast.makeText(this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
|
2012-06-24 19:52:23 +00:00
|
|
|
}
|