diff --git a/README.md b/README.md index ac5e22e..e1cdf81 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- A system information fetch tool (or neofetch like program), which its focus point is the perfomance and customizability + A system information fetch tool (or neofetch like program), which its focus point is the performance and customizability

diff --git a/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt b/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt index 4d7e723..2279eaf 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/SettingsActivity.kt @@ -31,12 +31,10 @@ class SettingsActivity : AppCompatActivity() { if (!Environment.isExternalStorageManager()) { AlertDialog.Builder(this) .setTitle("Grant external storage management permission") - .setMessage("Customfetch needs permissions to manage external storage for writing config files\n"+ + .setMessage("Customfetch needs permissions to manage external storage for writing config files.\n"+ "By default we going to read/write the following directories:\n"+ "/storage/emulated/0/.config/\n"+ "/storage/emulated/0/.config/customfetch/") - // The dialog is automatically dismissed when a dialog button is clicked. - .setPositiveButton("Grant permission" ) { _, _ -> val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) diff --git a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt index 3fe4583..b4ae083 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetch.kt @@ -5,6 +5,7 @@ import android.appwidget.AppWidgetProvider import android.content.Context import android.content.res.Configuration.ORIENTATION_PORTRAIT import android.os.Bundle +import android.text.TextPaint import android.util.Log import android.widget.RemoteViews import org.toni.customfetch_android.R @@ -38,17 +39,7 @@ class customfetch : AppWidgetProvider() { appWidgetId: Int, newOptions: Bundle ) { - // Get the new widget size - val widgetSize = WidgetSizeProvider(context) - val width = (widgetSize.getWidgetsSize(appWidgetId).first * 0.237f) // getWidgetSize(minWidthDp, maxWidthDp, context) - Log.d("widthTesting", "width = $width") - Log.d("wrappingTest", "disableLineWrap = $disableLineWrap") - - val parsedContent = customfetchRender.getParsedContent(context, appWidgetId, width, disableLineWrap) - - val views = RemoteViews(context.packageName, R.layout.customfetch) - views.setTextViewText(R.id.customfetch_text, parsedContent) - appWidgetManager.updateAppWidget(appWidgetId, views) + updateAppWidget(context, appWidgetManager, appWidgetId) } override fun onEnabled(context: Context) { @@ -102,12 +93,24 @@ internal fun updateAppWidget( appWidgetManager: AppWidgetManager, appWidgetId: Int ) { - val widgetSize = WidgetSizeProvider(context) - val width = (widgetSize.getWidgetsSize(appWidgetId).first * 0.237f) + // create a TextPaint to be used to measure text size + val textPaint = TextPaint() + val textSizeSp = 14f + val textSizePx = textSizeSp * context.resources.displayMetrics.scaledDensity + textPaint.textSize = textSizePx + + val width = WidgetSizeProvider(context).getWidgetsSize(appWidgetId).first.toFloat() + Log.d("widthTesting", "textSizePx = $textSizePx") Log.d("widthTesting", "width = $width") Log.d("wrappingTest", "disableLineWrap = $disableLineWrap") - val parsedContent = customfetchRender.getParsedContent(context, appWidgetId, width, disableLineWrap) + val parsedContent = customfetchRender.getParsedContent( + context, + appWidgetId, + width, + disableLineWrap, + textPaint + ) // Construct the RemoteViews object val views = RemoteViews(context.packageName, R.layout.customfetch) @@ -115,4 +118,4 @@ internal fun updateAppWidget( // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, views) -} \ No newline at end of file +} diff --git a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt index a510037..0483bf7 100644 --- a/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt +++ b/android/app/src/main/java/org/toni/customfetch_android/widget/customfetchConfigureActivity.kt @@ -27,7 +27,7 @@ var disableLineWrap = false */ class customfetchConfigureActivity : Activity() { private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID - private lateinit var appWidgetText: EditText + private lateinit var argumentsConfig: EditText private lateinit var argsHelp: TextView private lateinit var showModulesList: CheckBox private lateinit var disableWrapLines: CheckBox @@ -35,7 +35,7 @@ class customfetchConfigureActivity : Activity() { val context = this@customfetchConfigureActivity // When the button is clicked, store the string locally - val widgetText = appWidgetText.text.toString() + val widgetText = argumentsConfig.text.toString() saveTitlePref(context, appWidgetId, widgetText) // It is the responsibility of the configuration activity to update the app widget @@ -63,7 +63,7 @@ class customfetchConfigureActivity : Activity() { if (!Files.exists(Path(filesDir.absolutePath + "ascii"))) copyToAssetFolder(assets, filesDir.absolutePath, "ascii") - appWidgetText = binding.appwidgetText + argumentsConfig = binding.argumentsConfigure argsHelp = binding.argsHelp showModulesList = binding.showModulesList disableWrapLines = binding.disableWrapLines @@ -83,7 +83,7 @@ class customfetchConfigureActivity : Activity() { return } - appWidgetText.setText(loadTitlePref(this@customfetchConfigureActivity, appWidgetId)) + argumentsConfig.setText(loadTitlePref(this@customfetchConfigureActivity, appWidgetId)) argsHelp.text = customfetchRender.mainAndroid("customfetch --help") showModulesList.setOnCheckedChangeListener { _, isChecked -> @@ -99,7 +99,7 @@ class customfetchConfigureActivity : Activity() { } class CustomfetchMainRender { - fun getParsedContent(context: Context, appWidgetId: Int, width: Float, disableLineWrap: Boolean, otherArguments: String = ""): SpannableStringBuilder { + fun getParsedContent(context: Context, appWidgetId: Int, width: Float, disableLineWrap: Boolean, paint: TextPaint, otherArguments: String = ""): SpannableStringBuilder { val parsedContent = SpannableStringBuilder() val arguments = otherArguments.ifEmpty { loadTitlePref(context, appWidgetId) @@ -109,7 +109,6 @@ class CustomfetchMainRender { if (disableLineWrap) { val eachLine = htmlContent!!.split("
").map { it.trim() } - val paint = TextPaint()//.apply { textSize = 7f } for (line in eachLine) { var parsedLine = HtmlCompat.fromHtml(line, HtmlCompat.FROM_HTML_MODE_COMPACT) parsedLine = @@ -118,10 +117,7 @@ class CustomfetchMainRender { } } else { parsedContent.append(htmlContent?.let { - HtmlCompat.fromHtml( - it, - HtmlCompat.FROM_HTML_MODE_COMPACT - ) + HtmlCompat.fromHtml(it, HtmlCompat.FROM_HTML_MODE_COMPACT) }) } @@ -144,6 +140,7 @@ private const val PREF_PREFIX_KEY = "appwidget_" internal fun saveTitlePref(context: Context, appWidgetId: Int, text: String) { val prefs = context.getSharedPreferences(PREFS_NAME, 0).edit() prefs.putString(PREF_PREFIX_KEY + appWidgetId, text) + prefs.putBoolean(PREF_PREFIX_KEY + "bool_" + appWidgetId, disableLineWrap) prefs.apply() } @@ -152,6 +149,7 @@ internal fun saveTitlePref(context: Context, appWidgetId: Int, text: String) { internal fun loadTitlePref(context: Context, appWidgetId: Int): String { val prefs = context.getSharedPreferences(PREFS_NAME, 0) val titleValue = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null) + disableLineWrap = prefs.getBoolean(PREF_PREFIX_KEY + "bool_" + appWidgetId, false) return titleValue ?: "-D ${context.filesDir.absolutePath} -a small" } diff --git a/android/app/src/main/res/layout/customfetch_configure.xml b/android/app/src/main/res/layout/customfetch_configure.xml index c5248b5..ca66ebd 100644 --- a/android/app/src/main/res/layout/customfetch_configure.xml +++ b/android/app/src/main/res/layout/customfetch_configure.xml @@ -9,16 +9,23 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" - android:labelFor="@id/appwidget_text" + android:labelFor="@id/arguments_configure" android:text="@string/configure" /> + +