1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
package org.fox.ttcomics;
import java.io.File;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Display;
import android.view.MenuItem;
public class CommonActivity extends FragmentActivity {
private final String TAG = this.getClass().getSimpleName();
protected static final String FRAG_COMICS_PAGER = "comic_pager";
protected static final String FRAG_COMICS_LIST = "comics_list";
public static final String THUMBNAIL_PATH = "/data/org.fox.ttcomics/thumbnails/";
protected SharedPreferences m_prefs;
private boolean m_smallScreenMode = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
}
protected void setSmallScreen(boolean smallScreen) {
Log.d(TAG, "m_smallScreenMode=" + smallScreen);
m_smallScreenMode = smallScreen;
}
public boolean isSmallScreen() {
return m_smallScreenMode;
}
public void onComicArchiveSelected(String fileName) {
//
}
public void setSize(String fileName, int size) {
SharedPreferences lastread = getSharedPreferences("lastread", 0);
SharedPreferences.Editor editor = lastread.edit();
editor.putInt(fileName + ":size", size);
editor.commit();
}
public void setLastPosition(String fileName, int position) {
SharedPreferences lastread = getSharedPreferences("lastread", 0);
int lastPosition = getLastPosition(fileName);
SharedPreferences.Editor editor = lastread.edit();
editor.putInt(fileName + ":last", position);
editor.putInt(fileName + ":max", Math.max(lastPosition, position));
editor.commit();
}
public int getLastPosition(String fileName) {
SharedPreferences lastread = getSharedPreferences("lastread", 0);
return lastread.getInt(fileName + ":last", 0);
}
public int getMaxPosition(String fileName) {
SharedPreferences lastread = getSharedPreferences("lastread", 0);
return lastread.getInt(fileName + ":max", 0);
}
public int getSize(String fileName) {
SharedPreferences lastread = getSharedPreferences("lastread", 0);
return lastread.getInt(fileName + ":size", -1);
}
public void onComicSelected(String fileName, int position) {
setLastPosition(fileName, position);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_rescan:
ComicListFragment frag = (ComicListFragment) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_LIST);
if (frag != null && frag.isAdded()) {
frag.rescan();
}
return true;
case R.id.menu_settings:
Intent intent = new Intent(CommonActivity.this,
PreferencesActivity.class);
startActivityForResult(intent, 0);
return true;
default:
Log.d(TAG,
"onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
@SuppressWarnings("deprecation")
public boolean isPortrait() {
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
return width < height;
}
}
|