Adding settings - 5

This commit is contained in:
hajdam
2024-09-12 20:55:13 +02:00
parent 919b1b7499
commit 89ee04ed2e
18 changed files with 184 additions and 302 deletions
+6 -9
View File
@@ -15,16 +15,13 @@ Features
UNDER DEVELOPMENT
* Data as hexadecimal codes and text preview
* Visualize data as numerical (hexadecimal) codes and text representation
* Codes can be also binary, octal or decimal
* Support for Unicode, UTF-8 and other charsets
* Insert and overwrite edit modes
* TODO: Support for selection and clipboard actions
* TODO: Support for showing unprintable/whitespace characters
* TODO: Support for undo/redo
* TODO: Support for charset/encoding selection
* TODO: Codes can be also binary, octal or decimal
* TODO: Searching for text / hexadecimal code with found matches highlighting
* TODO: Support for huge files
* TODO: Delta mode - Only changes are stored in memory
* TODO: Searching for text / hexadecimal code with matching highlighting
* Support for undo/redo
* TODO: Support for files with size up to exabytes
Compiling
---------
-4
View File
@@ -18,10 +18,6 @@
android:name=".SettingsActivity"
android:exported="false"
android:label="@string/title_activity_settings" />
<activity
android:name=".SinglePreferenceFragment"
android:exported="false"
android:label="@string/title_activity_settings" />
<activity
android:name=".MainActivity"
android:exported="true"
@@ -1,207 +0,0 @@
/*
* Copyright (C) ExBin Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.exbin.bined.editor.android;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* About application view.
*/
@ParametersAreNonnullByDefault
public class AboutView extends View {
private String mExampleString; // TODO: use a default from R.string...
private int mExampleColor = Color.RED; // TODO: use a default from R.color...
private float mExampleDimension = 1; // TODO: use a default from R.dimen...
private Drawable mExampleDrawable;
private TextPaint mTextPaint;
private float mTextWidth;
private float mTextHeight;
public AboutView(Context context) {
super(context);
init(null, 0);
}
public AboutView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public AboutView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
private void init(AttributeSet attrs, int defStyle) {
// Load attributes
final TypedArray a = getContext().obtainStyledAttributes(
attrs, R.styleable.AboutView, defStyle, 0);
mExampleString = a.getString(
R.styleable.AboutView_exampleString);
mExampleColor = a.getColor(
R.styleable.AboutView_exampleColor,
mExampleColor);
// Use getDimensionPixelSize or getDimensionPixelOffset when dealing with
// values that should fall on pixel boundaries.
mExampleDimension = a.getDimension(
R.styleable.AboutView_exampleDimension,
mExampleDimension);
if (a.hasValue(R.styleable.AboutView_exampleDrawable)) {
mExampleDrawable = a.getDrawable(
R.styleable.AboutView_exampleDrawable);
mExampleDrawable.setCallback(this);
}
a.recycle();
// Set up a default TextPaint object
mTextPaint = new TextPaint();
mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setTextAlign(Paint.Align.LEFT);
// Update TextPaint and text measurements from attributes
invalidateTextPaintAndMeasurements();
}
private void invalidateTextPaintAndMeasurements() {
mTextPaint.setTextSize(mExampleDimension);
mTextPaint.setColor(mExampleColor);
mTextWidth = mTextPaint.measureText(mExampleString);
Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics();
mTextHeight = fontMetrics.bottom;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// TODO: consider storing these as member variables to reduce
// allocations per draw cycle.
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int contentWidth = getWidth() - paddingLeft - paddingRight;
int contentHeight = getHeight() - paddingTop - paddingBottom;
// Draw the text.
canvas.drawText(mExampleString,
paddingLeft + (contentWidth - mTextWidth) / 2,
paddingTop + (contentHeight + mTextHeight) / 2,
mTextPaint);
// Draw the example drawable on top of the text.
if (mExampleDrawable != null) {
mExampleDrawable.setBounds(paddingLeft, paddingTop,
paddingLeft + contentWidth, paddingTop + contentHeight);
mExampleDrawable.draw(canvas);
}
}
/**
* Gets the example string attribute value.
*
* @return The example string attribute value.
*/
public String getExampleString() {
return mExampleString;
}
/**
* Sets the view"s example string attribute value. In the example view, this string
* is the text to draw.
*
* @param exampleString The example string attribute value to use.
*/
public void setExampleString(String exampleString) {
mExampleString = exampleString;
invalidateTextPaintAndMeasurements();
}
/**
* Gets the example color attribute value.
*
* @return The example color attribute value.
*/
public int getExampleColor() {
return mExampleColor;
}
/**
* Sets the view"s example color attribute value. In the example view, this color
* is the font color.
*
* @param exampleColor The example color attribute value to use.
*/
public void setExampleColor(int exampleColor) {
mExampleColor = exampleColor;
invalidateTextPaintAndMeasurements();
}
/**
* Gets the example dimension attribute value.
*
* @return The example dimension attribute value.
*/
public float getExampleDimension() {
return mExampleDimension;
}
/**
* Sets the view"s example dimension attribute value. In the example view, this dimension
* is the font size.
*
* @param exampleDimension The example dimension attribute value to use.
*/
public void setExampleDimension(float exampleDimension) {
mExampleDimension = exampleDimension;
invalidateTextPaintAndMeasurements();
}
/**
* Gets the example drawable attribute value.
*
* @return The example drawable attribute value.
*/
public Drawable getExampleDrawable() {
return mExampleDrawable;
}
/**
* Sets the view"s example drawable attribute value. In the example view, this drawable is
* drawn above the text.
*
* @param exampleDrawable The example drawable attribute value to use.
*/
public void setExampleDrawable(Drawable exampleDrawable) {
mExampleDrawable = exampleDrawable;
}
}
@@ -26,6 +26,9 @@ import androidx.fragment.app.FragmentResultListener;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class SettingsActivity extends AppCompatActivity implements
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
@@ -100,6 +103,7 @@ public class SettingsActivity extends AppCompatActivity implements
return true;
}
@ParametersAreNonnullByDefault
public static class HeaderFragment extends PreferenceFragmentCompat {
@Override
@@ -108,6 +112,16 @@ public class SettingsActivity extends AppCompatActivity implements
}
}
@ParametersAreNonnullByDefault
public static class AppearanceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.appearance_preferences, rootKey);
}
}
@ParametersAreNonnullByDefault
public static class ViewFragment extends PreferenceFragmentCompat {
@Override
@@ -116,14 +130,7 @@ public class SettingsActivity extends AppCompatActivity implements
}
}
public static class MessagesFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.messages_preferences, rootKey);
}
}
@ParametersAreNonnullByDefault
public static class SyncFragment extends PreferenceFragmentCompat {
@Override
@@ -0,0 +1,50 @@
/*
* Copyright (C) ExBin Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.exbin.bined.editor.android.preference;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.EditTextPreference;
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class EncodingPreference extends EditTextPreference {
public EncodingPreference(@NonNull Context context) {
super(context);
}
public EncodingPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public EncodingPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public EncodingPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setOnBindEditTextListener(@Nullable OnBindEditTextListener onBindEditTextListener) {
super.setOnBindEditTextListener(onBindEditTextListener);
}
}
@@ -16,13 +16,36 @@
package org.exbin.bined.editor.android.preference;
import android.content.Context;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.DialogPreference;
import androidx.preference.EditTextPreference;
public class FontPreference extends DialogPreference {
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class FontPreference extends EditTextPreference {
public FontPreference(@NonNull Context context) {
super(context);
}
public FontPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public FontPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public FontPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setOnBindEditTextListener(@Nullable OnBindEditTextListener onBindEditTextListener) {
super.setOnBindEditTextListener(onBindEditTextListener);
}
}
-12
View File
@@ -3,18 +3,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- <org.exbin.bined.editor.android.AboutView
android:id="@+id/aboutView"
style="@style/Widget.AppTheme.MyView"
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingLeft="20dp"
android:paddingBottom="40dp"
app:exampleDimension="24sp"
app:exampleDrawable="@android:drawable/ic_menu_add"
app:exampleString="Hello, AboutView" /> -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
+15
View File
@@ -41,6 +41,9 @@
<item
android:id="@+id/code_type"
android:title="@string/code_type" />
<item
android:id="@+id/position_code_type"
android:title="@string/position_code_type" />
<item
android:id="@+id/hex_chars_case"
android:title="@string/hex_characters_case" />
@@ -63,6 +66,18 @@
android:id="@+id/go_to_position"
android:enabled="false"
android:title="@string/go_to_position" />
<item
android:id="@+id/edit_selection"
android:enabled="false"
android:title="@string/edit_selection" />
<item
android:id="@+id/insert_data"
android:enabled="false"
android:title="@string/insert_data" />
<item
android:id="@+id/convert_data"
android:enabled="false"
android:title="@string/convert_data" />
</menu>
</item>
<item
-1
View File
@@ -2,6 +2,5 @@
<style name="Widget.AppTheme.MyView" parent="">
<item name="android:background">@color/gray_600</item>
<item name="exampleColor">@color/light_blue_600</item>
</style>
</resources>
+32 -7
View File
@@ -1,13 +1,26 @@
<resources>
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>
<item>Reply to all</item>
<string-array name="theme_entries">
<item>Automatic (system)</item>
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="reply_values">
<item>reply</item>
<item>reply_all</item>
<string-array name="theme_values">
<item>automatic</item>
<item>light</item>
<item>dark</item>
</string-array>
<string-array name="language_entries">
<item>Default (system)</item>
<item>English</item>
<item>Česky</item>
</string-array>
<string-array name="language_values">
<item>default</item>
<item>en_US</item>
<item>cs_CZ</item>
</string-array>
<string-array name="view_mode_entries">
@@ -36,6 +49,18 @@
<item>hexadecimal</item>
</string-array>
<string-array name="position_code_type_entries">
<item>Octal</item>
<item>Decimal</item>
<item>Hexadecimal</item>
</string-array>
<string-array name="position_code_type_values">
<item>octal</item>
<item>decimal</item>
<item>hexadecimal</item>
</string-array>
<string-array name="hex_chars_case_entries">
<item>Upper Case</item>
<item>Lower Case</item>
@@ -1,8 +0,0 @@
<resources>
<declare-styleable name="AboutView">
<attr name="exampleString" format="string"/>
<attr name="exampleDimension" format="dimension" />
<attr name="exampleColor" format="color" />
<attr name="exampleDrawable" format="color|reference" />
</declare-styleable>
</resources>
+6 -3
View File
@@ -47,10 +47,7 @@
<string name="pref_header_appearance">Appearance</string>
<string name="title_activity_settings2">SettingsActivity2</string>
<string name="view_header">View</string>
<string name="messages_header">Messages</string>
<string name="sync_header">Sync</string>
<string name="signature_title">Your signature</string>
<string name="reply_title">Default reply action</string>
<string name="sync_title">Sync email periodically</string>
<string name="attachment_title">Download incoming attachments</string>
<string name="attachment_summary_on">Automatically download attachments for incoming emails
@@ -59,12 +56,18 @@
<!-- Preference Titles -->
<string name="attachment_summary_off">Only download attachments when manually requested</string>
<string name="view_menu">View</string>
<string name="visual_theme">Visual Theme</string>
<string name="language">Language</string>
<string name="view_mode">View Mode</string>
<string name="code_type">Code Type</string>
<string name="position_code_type">Position Code Type</string>
<string name="hex_characters_case">Hex Characters Case</string>
<string name="encoding">Encoding</string>
<string name="non_printing_characters">Non-printing Characters</string>
<string name="go_to_position">Go To Position</string>
<string name="edit_selection">Edit Selection</string>
<string name="insert_data">Insert Data</string>
<string name="convert_data">Convert Data</string>
<string name="edit_menu">Edit</string>
<string name="action_search">Search</string>
<string name="action_undo">Undo</string>
-1
View File
@@ -19,7 +19,6 @@
<style name="Widget.AppTheme.MyView" parent="">
<item name="android:background">@color/gray_400</item>
<item name="exampleColor">@color/light_blue_400</item>
</style>
<style name="MyButtonSmallStyle" parent="android:Widget.Button.Small">
@@ -0,0 +1,21 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
app:defaultValue="automatic"
app:entries="@array/theme_entries"
app:entryValues="@array/theme_values"
app:key="theme"
app:enabled="false"
app:title="@string/visual_theme"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="default"
app:entries="@array/language_entries"
app:entryValues="@array/language_values"
app:key="language"
app:enabled="false"
app:title="@string/language"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
+5 -6
View File
@@ -1,17 +1,16 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
app:fragment="org.exbin.bined.editor.android.SettingsActivity$AppearanceFragment"
app:icon="@drawable/ic_info_black_24dp"
app:title="@string/pref_header_appearance" />
<Preference
app:fragment="org.exbin.bined.editor.android.SettingsActivity$ViewFragment"
app:icon="@drawable/messages"
app:key="view_header"
app:title="@string/view_header" />
<Preference
app:fragment="org.exbin.bined.editor.android.SettingsActivity$MessagesFragment"
app:icon="@drawable/messages"
app:key="messages_header"
app:title="@string/messages_header" />
<Preference
app:fragment="org.exbin.bined.editor.android.SettingsActivity$SyncFragment"
app:icon="@drawable/sync"
@@ -1,16 +0,0 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
-17
View File
@@ -1,22 +1,5 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/messages_header">
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/sync_header">
<SwitchPreferenceCompat
+10 -2
View File
@@ -1,12 +1,12 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
<org.exbin.bined.editor.android.preference.FontPreference
app:key="font"
app:title="@string/font"
app:defaultValue="Font"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
<org.exbin.bined.editor.android.preference.EncodingPreference
app:key="encoding"
app:title="@string/encoding"
app:defaultValue="UTF-8"
@@ -28,6 +28,14 @@
app:title="@string/code_type"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="hexadecimal"
app:entries="@array/position_code_type_entries"
app:entryValues="@array/position_code_type_values"
app:key="position_code_type"
app:title="@string/position_code_type"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="lower"
app:entries="@array/hex_chars_case_entries"