Settings menu shows the font size

This commit is contained in:
Bradlee Speice 2014-12-01 15:48:19 -05:00
parent bb415d2d3d
commit f9a831eb5d
10 changed files with 210 additions and 8 deletions

View File

@ -8,13 +8,15 @@
<application <application
android:name=".MinimalBible" android:name=".MinimalBible"
android:allowBackup="true" android:allowBackup="true"
android:debuggable="false"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".activity.downloader.DownloadActivity" android:name=".activity.downloader.DownloadActivity"
android:label="@string/app_name" /> android:label="@string/app_name" />
<activity
android:name=".activity.settings.MinimalBibleSettings"
android:label="@string/app_name" />
<activity <activity
android:name=".activity.viewer.BibleViewer" android:name=".activity.viewer.BibleViewer"
android:label="@string/app_name"> android:label="@string/app_name">

View File

@ -0,0 +1,133 @@
/**
* Copyright CMW Mobile.com, 2010.
*/
package com.cmwmobile.android.samples;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import org.bspeice.minimalbible.R;
import org.jetbrains.annotations.NotNull;
/**
* The SeekBarDialogPreference class is a DialogPreference based and provides a
* seekbar preference.
*
* @author Casper Wakkers
*/
public class SeekBarDialogPreference extends
DialogPreference implements SeekBar.OnSeekBarChangeListener {
// Layout widgets.
private SeekBar seekBar = null;
private TextView valueText = null;
// Custom xml attributes.
private int maximumValue = 0;
private int minimumValue = 0;
private int stepSize = 0;
private String units = null;
private int value = 0;
/**
* The SeekBarDialogPreference constructor.
*
* @param context of this preference.
* @param attrs custom xml attributes.
*/
public SeekBarDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs,
R.styleable.SeekBarDialogPreference);
maximumValue = typedArray.getInteger(
R.styleable.SeekBarDialogPreference_maximumValue, 0);
minimumValue = typedArray.getInteger(
R.styleable.SeekBarDialogPreference_minimumValue, 0);
stepSize = typedArray.getInteger(
R.styleable.SeekBarDialogPreference_stepSize, 1);
units = typedArray.getString(
R.styleable.SeekBarDialogPreference_units);
typedArray.recycle();
}
/**
* {@inheritDoc}
*/
@Override
protected View onCreateDialogView() {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
View view = layoutInflater.inflate(
R.layout.seekbardialogpreference_layout, null);
seekBar = (SeekBar) view.findViewById(R.id.preference_seekbar);
valueText = (TextView) view.findViewById(R.id.preference_text);
// Get the persistent value and correct it for the minimum value.
value = getPersistedInt(minimumValue) - minimumValue;
// You're never know...
if (value < 0) {
value = 0;
}
seekBar.setKeyProgressIncrement(stepSize);
seekBar.setMax(maximumValue - minimumValue);
// setProgress must come before we start listening to events, otherwise
// we may receive the initialization (i.e. 0) event destroying our value
seekBar.setProgress(value);
updateValueText(value);
seekBar.setOnSeekBarChangeListener(this);
return view;
}
/**
* {@inheritDoc}
*/
@Override
public void onProgressChanged(@NotNull SeekBar seek, int newValue,
boolean fromTouch) {
// Round the value to the closest integer value.
if (stepSize >= 1) {
value = Math.round(newValue / stepSize) * stepSize;
} else {
value = newValue;
}
updateValueText(value);
callChangeListener(value);
}
private void updateValueText(int value) {
valueText.setText(String.valueOf(value + minimumValue) +
(units == null ? "" : units));
}
@Override
public void onDialogClosed(boolean positiveResult) {
if (positiveResult && shouldPersist())
persistInt(value + minimumValue);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}

View File

@ -5,16 +5,19 @@ import de.devland.esperandro.annotations.SharedPreferences;
/** /**
* SharedPreferences interface to be built by Esperandro * SharedPreferences interface to be built by Esperandro
*/ */
@SharedPreferences(name="DownloadPrefs") @SharedPreferences
public interface DownloadPrefs { public interface DownloadPrefs {
boolean hasEnabledDownload(); boolean hasEnabledDownload();
void hasEnabledDownload(boolean hasEnabledDownload); void hasEnabledDownload(boolean hasEnabledDownload);
boolean hasShownDownloadDialog(); boolean hasShownDownloadDialog();
void hasShownDownloadDialog(boolean hasShownDownloadDialog); void hasShownDownloadDialog(boolean hasShownDownloadDialog);
long downloadRefreshedOn(); long downloadRefreshedOn();
void downloadRefreshedOn(long downloadRefreshedOn); void downloadRefreshedOn(long downloadRefreshedOn);
} }

View File

@ -17,6 +17,7 @@ import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activity.BaseActivity; import org.bspeice.minimalbible.activity.BaseActivity;
import org.bspeice.minimalbible.activity.downloader.DownloadActivity; import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment; import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment;
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Book;
import javax.inject.Inject; import javax.inject.Inject;
@ -142,7 +143,8 @@ public class BibleViewer extends BaseActivity implements
// as you specify a parent activity in AndroidManifest.xml. // as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.action_settings) { if (id == R.id.action_settings) {
return true; Intent i = new Intent(this, MinimalBibleSettings.class);
startActivityForResult(i, 0);
} else if (id == R.id.action_downloads) { } else if (id == R.id.action_downloads) {
startActivity(new Intent(this, DownloadActivity.class)); startActivity(new Intent(this, DownloadActivity.class));
} }

View File

@ -6,7 +6,7 @@ import de.devland.esperandro.annotations.SharedPreferences;
/** /**
* Created by bspeice on 7/11/14. * Created by bspeice on 7/11/14.
*/ */
@SharedPreferences(name = "BibleViewerPreferences") @SharedPreferences
public interface BibleViewerPreferences { public interface BibleViewerPreferences {
String defaultBookName(); String defaultBookName();

View File

@ -0,0 +1,16 @@
package org.bspeice.minimalbible.activity.settings
import android.preference.PreferenceActivity
import android.os.Bundle
import org.bspeice.minimalbible.R
/**
* Created by bspeice on 12/1/14.
*/
class MinimalBibleSettings() : PreferenceActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super<PreferenceActivity>.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.preferences)
}
}

View File

@ -74,8 +74,8 @@ class BookAdapter(val b: Book, val prefs: BibleViewerPreferences)
val emptyView = LayoutInflater.from(parent?.getContext()) val emptyView = LayoutInflater.from(parent?.getContext())
.inflate(R.layout.viewer_passage_view, parent, false) as TextView .inflate(R.layout.viewer_passage_view, parent, false) as TextView
// TODO: Prefs object for handling this? // TODO: Listen for changes to the text size?
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f) emptyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, prefs.baseTextSize().toFloat())
val passage = PassageView(emptyView, b) val passage = PassageView(emptyView, b)
return passage return passage

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip">
<TextView
android:id="@+id/preference_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="32sp" />
<SeekBar
android:id="@+id/preference_seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -16,4 +16,12 @@
<attr name="contourColor" format="color"/> <attr name="contourColor" format="color"/>
<attr name="contourSize" format="dimension"/> <attr name="contourSize" format="dimension"/>
</declare-styleable> </declare-styleable>
<!-- Copyright CMW Mobile.com, 2010. -->
<declare-styleable name="SeekBarDialogPreference">
<attr name="maximumValue" format="integer" />
<attr name="minimumValue" format="integer" />
<attr name="stepSize" format="integer" />
<attr name="units" format="string" />
</declare-styleable>
</resources> </resources>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?><!-- I have to change the namespace slightly since this is part of the org.bspeice.minimalbible
package as defined in AndroidManifest.xml. Otherwise, everything is intact as supplied,
but I will likely want to re-implement this in the future -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cmwmobile="http://schemas.android.com/apk/res/org.bspeice.minimalbible">
<com.cmwmobile.android.samples.SeekBarDialogPreference
android:defaultValue="14"
android:key="baseTextSize"
android:summary="Font Size"
android:title="Font Size"
cmwmobile:maximumValue="28"
cmwmobile:minimumValue="8"
cmwmobile:stepSize="1"
cmwmobile:units="pt." />
</PreferenceScreen>