New setting: "Small screen" to avoid ellipsizing on small screens

This commit is contained in:
Daniel Martí 2014-01-10 22:12:57 +01:00
parent 7c472c8e18
commit a5c66a8c6e
7 changed files with 59 additions and 8 deletions

View File

@ -163,6 +163,9 @@
<string name="compactlayout">Compact Layout</string> <string name="compactlayout">Compact Layout</string>
<string name="compactlayout_on">Show icons at a smaller size</string> <string name="compactlayout_on">Show icons at a smaller size</string>
<string name="compactlayout_off">Show icons at regular size</string> <string name="compactlayout_off">Show icons at regular size</string>
<string name="small_density">Small screen</string>
<string name="small_density_on">Adapt layouts to smaller screens</string>
<string name="small_density_off">Use normal layouts</string>
<string name="theme">Theme</string> <string name="theme">Theme</string>
<string name="unsigned">Unsigned</string> <string name="unsigned">Unsigned</string>
<string name="repo_url">URL</string> <string name="repo_url">URL</string>

View File

@ -25,6 +25,9 @@
<CheckBoxPreference android:title="@string/compactlayout" <CheckBoxPreference android:title="@string/compactlayout"
android:defaultValue="false" android:defaultValue="false"
android:key="compactlayout"/> android:key="compactlayout"/>
<CheckBoxPreference android:title="@string/small_density"
android:defaultValue="false"
android:key="smallDensity"/>
<ListPreference android:title="@string/theme" <ListPreference android:title="@string/theme"
android:key="theme" android:key="theme"
android:defaultValue="dark" android:defaultValue="dark"

View File

@ -180,8 +180,10 @@ public class AppDetails extends ListActivity {
if (apk.minSdkVersion > 0) { if (apk.minSdkVersion > 0) {
holder.api.setText(getString(R.string.minsdk_or_later, holder.api.setText(getString(R.string.minsdk_or_later,
Utils.getAndroidVersionName(apk.minSdkVersion))); Utils.getAndroidVersionName(apk.minSdkVersion)));
holder.api.setEnabled(apk.compatible);
holder.api.setVisibility(View.VISIBLE);
} else { } else {
holder.api.setText(""); holder.api.setVisibility(View.GONE);
} }
if (apk.srcname != null) { if (apk.srcname != null) {
@ -325,6 +327,7 @@ public class AppDetails extends ListActivity {
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext()); .getDefaultSharedPreferences(getBaseContext());
pref_smallDensity = prefs.getBoolean("smallDensity", false);
pref_expert = prefs.getBoolean("expert", false); pref_expert = prefs.getBoolean("expert", false);
pref_permissions = prefs.getBoolean("showPermissions", false); pref_permissions = prefs.getBoolean("showPermissions", false);
pref_incompatibleVersions = prefs.getBoolean( pref_incompatibleVersions = prefs.getBoolean(
@ -334,6 +337,7 @@ public class AppDetails extends ListActivity {
} }
private boolean pref_smallDensity;
private boolean pref_expert; private boolean pref_expert;
private boolean pref_permissions; private boolean pref_permissions;
private boolean pref_incompatibleVersions; private boolean pref_incompatibleVersions;

View File

@ -35,17 +35,21 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
public static final String PREF_THEME = "theme"; public static final String PREF_THEME = "theme";
public static final String PREF_PERMISSIONS = "showPermissions"; public static final String PREF_PERMISSIONS = "showPermissions";
public static final String PREF_COMPACT_LAYOUT = "compactlayout"; public static final String PREF_COMPACT_LAYOUT = "compactlayout";
public static final String PREF_SMALL_DENSITY = "smallDensity";
public static final String PREF_IGN_TOUCH = "ignoreTouchscreen"; public static final String PREF_IGN_TOUCH = "ignoreTouchscreen";
public static final String PREF_CACHE_APK = "cacheDownloaded"; public static final String PREF_CACHE_APK = "cacheDownloaded";
public static final String PREF_EXPERT = "expert"; public static final String PREF_EXPERT = "expert";
public static final String PREF_DB_SYNC = "dbSyncMode"; public static final String PREF_DB_SYNC = "dbSyncMode";
private static final boolean DEFAULT_COMPACT_LAYOUT = false; private static final boolean DEFAULT_COMPACT_LAYOUT = false;
private static final boolean DEFAULT_SMALL_DENSITY = false;
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT; private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
private boolean smallDensity = DEFAULT_SMALL_DENSITY;
private Map<String,Boolean> initialized = new HashMap<String,Boolean>(); private Map<String,Boolean> initialized = new HashMap<String,Boolean>();
private List<ChangeListener> compactLayoutListeners = new ArrayList<ChangeListener>(); private List<ChangeListener> compactLayoutListeners = new ArrayList<ChangeListener>();
private List<ChangeListener> smallDensityListeners = new ArrayList<ChangeListener>();
private boolean isInitialized(String key) { private boolean isInitialized(String key) {
return initialized.containsKey(key) && initialized.get(key); return initialized.containsKey(key) && initialized.get(key);
@ -67,6 +71,14 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
return compactLayout; return compactLayout;
} }
public boolean hasSmallDensity() {
if (!isInitialized(PREF_SMALL_DENSITY)) {
initialize(PREF_SMALL_DENSITY);
smallDensity = preferences.getBoolean(PREF_SMALL_DENSITY, DEFAULT_SMALL_DENSITY);
}
return smallDensity;
}
public void registerCompactLayoutChangeListener(ChangeListener listener) { public void registerCompactLayoutChangeListener(ChangeListener listener) {
compactLayoutListeners.add(listener); compactLayoutListeners.add(listener);
} }
@ -75,6 +87,14 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
compactLayoutListeners.remove(listener); compactLayoutListeners.remove(listener);
} }
public void registerSmallDensityChangeListener(ChangeListener listener) {
smallDensityListeners.add(listener);
}
public void unregisterSmallDensityChangeListener(ChangeListener listener) {
smallDensityListeners.remove(listener);
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d("FDroid", "Invalidating preference '" + key + "'."); Log.d("FDroid", "Invalidating preference '" + key + "'.");
@ -85,6 +105,12 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
listener.onPreferenceChange(); listener.onPreferenceChange();
} }
} }
if (key.equals(PREF_SMALL_DENSITY)) {
for ( ChangeListener listener : smallDensityListeners ) {
listener.onPreferenceChange();
}
}
} }
private static Preferences instance; private static Preferences instance;

View File

@ -51,6 +51,7 @@ public class PreferencesActivity extends PreferenceActivity implements
Preferences.PREF_THEME, Preferences.PREF_THEME,
Preferences.PREF_PERMISSIONS, Preferences.PREF_PERMISSIONS,
Preferences.PREF_COMPACT_LAYOUT, Preferences.PREF_COMPACT_LAYOUT,
Preferences.PREF_SMALL_DENSITY,
Preferences.PREF_IGN_TOUCH, Preferences.PREF_IGN_TOUCH,
Preferences.PREF_CACHE_APK, Preferences.PREF_CACHE_APK,
Preferences.PREF_EXPERT, Preferences.PREF_EXPERT,
@ -67,11 +68,7 @@ public class PreferencesActivity extends PreferenceActivity implements
protected void onoffSummary(String key, int on, int off) { protected void onoffSummary(String key, int on, int off) {
CheckBoxPreference pref = (CheckBoxPreference)findPreference(key); CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
if (pref.isChecked()) { pref.setSummary(pref.isChecked() ? on : off);
pref.setSummary(on);
} else {
pref.setSummary(off);
}
} }
protected void entrySummary(String key) { protected void entrySummary(String key) {
@ -119,6 +116,10 @@ public class PreferencesActivity extends PreferenceActivity implements
onoffSummary(key, R.string.compactlayout_on, onoffSummary(key, R.string.compactlayout_on,
R.string.compactlayout_off); R.string.compactlayout_off);
} else if (key.equals(Preferences.PREF_SMALL_DENSITY)) {
onoffSummary(key, R.string.small_density_on,
R.string.small_density_off);
} else if (key.equals(Preferences.PREF_THEME)) { } else if (key.equals(Preferences.PREF_THEME)) {
entrySummary(key); entrySummary(key);
if (changing) { if (changing) {

View File

@ -91,6 +91,7 @@ abstract public class AppListAdapter extends BaseAdapter {
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
boolean compact = Preferences.get().hasCompactLayout(); boolean compact = Preferences.get().hasCompactLayout();
boolean small = Preferences.get().hasSmallDensity();
DB.App app = items.get(position); DB.App app = items.get(position);
ViewHolder holder; ViewHolder holder;
@ -116,8 +117,19 @@ abstract public class AppListAdapter extends BaseAdapter {
ImageLoader.getInstance().displayImage(app.iconUrl, holder.icon, ImageLoader.getInstance().displayImage(app.iconUrl, holder.icon,
displayImageOptions); displayImageOptions);
holder.status.setText(getVersionInfo(app)); if (small) {
holder.license.setText(app.license); holder.status.setVisibility(View.GONE);
} else {
holder.status.setVisibility(View.VISIBLE);
holder.status.setText(getVersionInfo(app));
}
if (small) {
holder.license.setVisibility(View.GONE);
} else {
holder.license.setVisibility(View.VISIBLE);
holder.license.setText(app.license);
}
// Disable it all if it isn't compatible... // Disable it all if it isn't compatible...
View[] views = { View[] views = {

View File

@ -26,12 +26,14 @@ abstract class AppListFragment extends Fragment implements AdapterView.OnItemCli
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Preferences.get().registerCompactLayoutChangeListener(this); Preferences.get().registerCompactLayoutChangeListener(this);
Preferences.get().registerSmallDensityChangeListener(this);
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
Preferences.get().unregisterCompactLayoutChangeListener(this); Preferences.get().unregisterCompactLayoutChangeListener(this);
Preferences.get().unregisterSmallDensityChangeListener(this);
} }
@Override @Override