mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Add string attribute editor
This commit is contained in:
Generated
+1
@@ -36,6 +36,7 @@
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_completion_item.xml" value="0.20512820512820512" />
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_dimension_editor.xml" value="0.264" />
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_simple_icon_text.xml" value="0.30128205128205127" />
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_string_attr_editor.xml" value="0.264" />
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_widget_group_item.xml" value="0.33" />
|
||||
<entry key="..\:/Projects/AndroidStudioProjects/android-ide/app/src/main/res/layout/layout_widget_item.xml" value="0.33" />
|
||||
<entry key="..\:/Users/Akash Yadav/AndroidStudioProjects/android-ide/app/src/main/res/drawable/ic_website.xml" value="0.2189873417721519" />
|
||||
|
||||
@@ -19,6 +19,7 @@ More features will be implemented as we continue to develop this app.
|
||||
- [ ] UI Designer
|
||||
- [x] Layout inflater
|
||||
- [ ] Resolve resource references
|
||||
- [ ] Auto-complete resource values when user edits attributes using the attribute editor
|
||||
- [ ] Drag & Drop (*)
|
||||
- [ ] Visual attribute editor (*)
|
||||
- [ ] Android Widgets (*)
|
||||
|
||||
@@ -136,8 +136,6 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
}
|
||||
|
||||
private void showEditorDialog (@NonNull XMLAttribute attribute) {
|
||||
final var attr = attribute.getAttr ();
|
||||
|
||||
final AttributeDialogs.OnClickListener onDone = (dialog, which, newValue) -> {
|
||||
if (!this.selectedView.updateAttribute (attribute.getNamespace (), attribute.getAttributeName (), newValue)) {
|
||||
StudioApp.getInstance ().toast ("Unable to update this attribute", Toaster.Type.ERROR);
|
||||
@@ -150,11 +148,9 @@ public class AttrEditorSheet extends BottomSheetDialogFragment implements Simple
|
||||
|
||||
AlertDialog dialog = null;
|
||||
if (attribute.hasFormat (DIMENSION)) {
|
||||
if (attr == null) {
|
||||
throw new IllegalStateException ("The provided attribute has not been resolved.");
|
||||
}
|
||||
|
||||
dialog = AttributeDialogs.dimensionEditor (attribute.getValue (), onDone);
|
||||
} else if (attribute.hasFormat (STRING)) {
|
||||
dialog = AttributeDialogs.stringEditor (onDone);
|
||||
}
|
||||
|
||||
if (dialog != null) {
|
||||
|
||||
@@ -29,13 +29,14 @@ import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.itsaky.androidide.R;
|
||||
import com.itsaky.androidide.app.StudioApp;
|
||||
import com.itsaky.androidide.databinding.LayoutDimensionEditorBinding;
|
||||
import com.itsaky.androidide.databinding.LayoutDimensionAttrEditorBinding;
|
||||
import com.itsaky.androidide.databinding.LayoutStringAttrEditorBinding;
|
||||
import com.itsaky.toaster.Toaster;
|
||||
|
||||
/**
|
||||
* Helper class for creating dialogs for editing view attributes.
|
||||
*
|
||||
* TODO Should we merge this into {@link DialogUtils}
|
||||
* <br>
|
||||
* TODO Should we merge this into {@link DialogUtils}?
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
public class AttributeDialogs {
|
||||
@@ -61,16 +62,50 @@ public class AttributeDialogs {
|
||||
|
||||
/**
|
||||
* Release the context instance stored in this class.
|
||||
*
|
||||
*
|
||||
* @see #init(Context)
|
||||
*/
|
||||
public static void release () {
|
||||
mContext = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new value for editing an attribute with format STRING.
|
||||
* @param onSubmit The listener that will be invoked when the user clicks the
|
||||
* positive button.
|
||||
* @return The newly created dialog instance.
|
||||
*/
|
||||
@NonNull
|
||||
public static AlertDialog stringEditor (OnClickListener onSubmit) {
|
||||
final var binding = LayoutStringAttrEditorBinding.inflate (LayoutInflater.from (mContext));
|
||||
final var builder = newMaterialDialogBuilder (mContext);
|
||||
builder.setTitle (mContext.getString(R.string.msg_new_str_value));
|
||||
builder.setView (binding.getRoot ());
|
||||
builder.setPositiveButton (android.R.string.ok, (dialog, which) -> {
|
||||
final var newValue = binding.valueField.getEditText ().getText ().toString ().trim ();
|
||||
if (newValue.length () <= 0) {
|
||||
StudioApp.getInstance ().toast (mContext.getString (R.string.msg_invalid_attr_value), Toaster.Type.ERROR);
|
||||
return;
|
||||
}
|
||||
if (onSubmit != null) {
|
||||
onSubmit.onClick (dialog, which, newValue);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton (android.R.string.cancel, (dialog, which) -> dialog.dismiss ());
|
||||
|
||||
return builder.create ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new dialog for editing an attribute which accepts dimension values.
|
||||
* @param value The current value of the attribute. Used for determining which item must be selected by default.
|
||||
* @param onSubmit A listener that will be invoked when the user presses the positive button of the dialog.
|
||||
* This listener is invoked only when the user passes a valid dimension value.
|
||||
* @return The newly created dialog instance. Note that this dialog is not shown by default.
|
||||
*/
|
||||
@NonNull
|
||||
public static AlertDialog dimensionEditor (CharSequence value, OnClickListener onSubmit) {
|
||||
final var binding = LayoutDimensionEditorBinding.inflate(LayoutInflater.from (mContext));
|
||||
final var binding = LayoutDimensionAttrEditorBinding.inflate(LayoutInflater.from (mContext));
|
||||
binding.choices.setOnCheckedChangeListener ((group, checkedId) -> {
|
||||
binding.otherValue.setVisibility (binding.other.isChecked () ? View.VISIBLE : View.GONE);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ This file is part of AndroidIDE.
|
||||
~
|
||||
~ AndroidIDE is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ AndroidIDE is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/value_field"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hint_new_attr_value">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -330,5 +330,6 @@
|
||||
<string name="msg_no_attr_format">No attribute format is available for this attribute.</string>
|
||||
<string name="msg_attr_editor_null">Unable to create attribute editor for this attribute</string>
|
||||
<string name="msg_invalid_attr_value">Invalid value</string>
|
||||
<string name="msg_new_str_value">New string value</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user