mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-25 01:18:17 -05:00
Settings menu shows the font size
This commit is contained in:
parent
bb415d2d3d
commit
f9a831eb5d
@ -8,13 +8,15 @@
|
||||
<application
|
||||
android:name=".MinimalBible"
|
||||
android:allowBackup="true"
|
||||
android:debuggable="false"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".activity.downloader.DownloadActivity"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".activity.settings.MinimalBibleSettings"
|
||||
android:label="@string/app_name" />
|
||||
<activity
|
||||
android:name=".activity.viewer.BibleViewer"
|
||||
android:label="@string/app_name">
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
@ -5,16 +5,19 @@ import de.devland.esperandro.annotations.SharedPreferences;
|
||||
/**
|
||||
* SharedPreferences interface to be built by Esperandro
|
||||
*/
|
||||
@SharedPreferences(name="DownloadPrefs")
|
||||
@SharedPreferences
|
||||
public interface DownloadPrefs {
|
||||
|
||||
boolean hasEnabledDownload();
|
||||
|
||||
void hasEnabledDownload(boolean hasEnabledDownload);
|
||||
|
||||
boolean hasShownDownloadDialog();
|
||||
|
||||
void hasShownDownloadDialog(boolean hasShownDownloadDialog);
|
||||
|
||||
long downloadRefreshedOn();
|
||||
|
||||
void downloadRefreshedOn(long downloadRefreshedOn);
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseActivity;
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadActivity;
|
||||
import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment;
|
||||
import org.bspeice.minimalbible.activity.settings.MinimalBibleSettings;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -142,8 +143,9 @@ public class BibleViewer extends BaseActivity implements
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
} else if (id == R.id.action_downloads) {
|
||||
Intent i = new Intent(this, MinimalBibleSettings.class);
|
||||
startActivityForResult(i, 0);
|
||||
} else if (id == R.id.action_downloads) {
|
||||
startActivity(new Intent(this, DownloadActivity.class));
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -6,7 +6,7 @@ import de.devland.esperandro.annotations.SharedPreferences;
|
||||
/**
|
||||
* Created by bspeice on 7/11/14.
|
||||
*/
|
||||
@SharedPreferences(name = "BibleViewerPreferences")
|
||||
@SharedPreferences
|
||||
public interface BibleViewerPreferences {
|
||||
|
||||
String defaultBookName();
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -74,8 +74,8 @@ class BookAdapter(val b: Book, val prefs: BibleViewerPreferences)
|
||||
val emptyView = LayoutInflater.from(parent?.getContext())
|
||||
.inflate(R.layout.viewer_passage_view, parent, false) as TextView
|
||||
|
||||
// TODO: Prefs object for handling this?
|
||||
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
||||
// TODO: Listen for changes to the text size?
|
||||
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, prefs.baseTextSize().toFloat())
|
||||
|
||||
val passage = PassageView(emptyView, b)
|
||||
return passage
|
||||
|
21
app/src/main/res/layout/seekbardialogpreference_layout.xml
Normal file
21
app/src/main/res/layout/seekbardialogpreference_layout.xml
Normal 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>
|
@ -15,5 +15,13 @@
|
||||
<attr name="barLength" format="dimension" />
|
||||
<attr name="contourColor" format="color"/>
|
||||
<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>
|
17
app/src/main/res/xml/preferences.xml
Normal file
17
app/src/main/res/xml/preferences.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user