How to set up Chip and ChipGroup attributes properly? - android-chips

I figured out that app: namespace attributes are not applied to Chip view in my project, though documentation and some sample code I have seen state that they do. What do I do wrong?
<com.google.android.material.chip.Chip
style="#style/Widget.Material3.Chip.Filter"
android:id="#+id/chip1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginHorizontal="20dp"
app:chipStrokeColor="#F0F"
app:chipStrokeWidth="1dp"
app:chipBackgroundColor="#color/biz_500"
app:chipMinHeight="48dp"
app:chipCornerRadius="7dp"
android:text="#string/text_input_girl"
android:textSize="11sp"
android:textAlignment="center" />
I also use Theme.Material3.Light.NoActionBar in application manifest.
I tried to switch to MaterialComponents, but it looks even worse.

Chips Attitude is Normal
<com.google.android.material.chip.Chip
style="#style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/_10sdp"
android:text="#string/app_name"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/_10sdp"
android:textStyle="bold"
app:checkedIcon="#drawable/ic_close_24"
app:checkedIconEnabled="false"
app:checkedIconTint="#color/white"
app:checkedIconVisible="true"
app:chipBackgroundColor="#color/purple_500"
app:chipCornerRadius="#dimen/_10sdp"
app:chipEndPadding="#dimen/_10sdp"
app:chipIconSize="#dimen/_100sdp"
app:chipMinTouchTargetSize="#dimen/_50sdp"
app:closeIcon="#drawable/ic_close_24"
app:rippleColor="#color/white" />
Chip Four Type
style="#style/Widget.MaterialComponents.Chip.Entry"
style="#style/Widget.MaterialComponents.Chip.Action"
style="#style/Widget.MaterialComponents.Chip.Choice"
style="#style/Widget.MaterialComponents.Chip.Filter"

Related

BottomAppBar height gets bigger when using window.setDecorFitsSystemWindows(false)

I am trying to achieve transparent status bar by using window.setDecorFitsSystemWindows(false) and statusBarColor = Color.TRANSPARENT. I achieved my goal, but when I introduced BottomAppBar, its size (padding to be exact) is doubled. What might be the issue?
With window.setDecorFitsSystemWindows(false):
Without window.setDecorFitsSystemWindows(false):
Main Activity Layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityMain">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainer"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:defaultNavHost="true"
app:navGraph="#navigation/main" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
app:elevation="1dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemHorizontalTranslationEnabled="false"
android:background="#android:color/transparent"
app:elevation="0dp"
app:labelVisibilityMode="auto"
app:menu="#menu/nav_bar_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Got to the answer quickly than I thought I would. I forgot to calculate the insets, so adding this piece of code made everything working again:
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(bottom = insets.bottom)
WindowInsetsCompat.CONSUMED
}

How can I get an element from within a ListViewItem's ItemTemplate?

I have a ListView that uses a custom ItemTemplate (doesn't everyone?):
<ListView>
<!-- ... -->
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<MyGreatControl Thing="{x:Bind}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MyGreatControl today has extensive keyboard handling code built-in, but due to some refactoring, I need to move the actual handlers to the ListView itself. However, I don't want to move all of the code in MyGreatControl to the ListView (for many reasons).
If I have an arbitrary ListViewItem (which, for example, I can get from an event handler), how can I access the MyGreatControl instance in its DataTemplate?
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
// ???
}
Disclaimer: I work for Microsoft.
You want to use ContentTemplateRoot!
MyGreatControl^ GetMyGreatControlFromListViewItem(ListViewItem^ listViewItem) {
return safe_cast<MyGreatControl^>(listViewItem->ContentTemplateRoot);
}
This also works for any arbitrary element—if you have a StackPanel, for example, ContentTemplateRoot will return the StackPanel instance you want:
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<StackPanel><!-- This is what you get! -->
<TextBlock Text="{x:Bind}" />
<Button Content="Foo" IsTabStop="False" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
You can then use normal visual tree navigation to find Children, etc.

Qt5 custom widget - Curved slider

I'm starting my next electronics project which is to create my own version of Google's Nest Thermostat. I like the whole circular dial for temperature selection and I've been having a think about how to create this myself. GUI programming is not my area of expertise (CLI all the way!).
So far I'm think along one of two lines, both involving custom widgets:
Create a widget that inherits from the pushbutton class. This subclass will contain lots of buttons, one for each step in the temperature scale, arranged in a 3/4 circle.
Create a widget that inherits from the slider class, defining an object that is curved around 3/4 of a circle. Each step is a temperature.
Now... I have no idea if these are practical solutions to this problem or if there is a much easier way of doing this. I've had a look at the style sheets and I don't THINK that is going to do it. I've had a root around Google for anything similar and not found anything yet; that said, AnalogWidgets from 3electrons at least creates dials, but these are for output rather than input.
I tried this out yesterday and it works rather nicely if you want to simulate the nest thermostat in an app this includes the js and SVG image:
https://www.svidget.io/examples/nestthermostat
HTML snippet:
<object id="nestThermostatWidget" role="svidget" data="nestThermostatWidget.svg" type="image/svg+xml" width="400" height="400">
<param name="targetTemp" value="77" />
<param name="ambientTemp" value="80" />
<param name="unit" value="F" />
<param name="state" value="cooling" />
<param name="showLeaf" value="1" />
<param name="awayMode" value="0" />
</object>

Way to nest multiple voice triggers when launching an app with GDK

Is there a way to nest voice triggers when launching an app on Google Glass using the GDK? For example instead of just saying "ok, glass" -> "What's its power level?" I'd like to have the app present an option. For example "ok, glass" -> "What's its power level?" -> "Over 9000" OR "Under 9000". Any help would be great!
If you have multiple activities/services installed on Glass that have the same voice trigger intent filter, all of their names (based on the android:label attribute of the <activity> or <service> tag in AndroidManifest.xml) will appear in a disambiguation "submenu" when you speak that voice trigger.
For example (assume that res/xml/play_a_game_trigger.xml represents a voice trigger for the string "play a game"):
<activity android:label="Tennis">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/play_a_game_trigger" />
</activity>
<activity android:label="Bowling">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/play_a_game_trigger" />
</activity>
would give you a voice menu flow that looks like
ok glass → play a game → Tennis
Bowling
Do note, however, that this menu would also include activities/services from other APKs that use the same voice trigger as well.
You can find more details at the Voice Input page of the GDK documentation.
The proper way to do this is using an input tag inside the trigger
<trigger keyword="#string/start_app" >
<input prompt="#string/promt_text" />
</trigger>
This prompts an input and waits for more audio speech.
Then in your activity you can capture this text with:
ArrayList<String> text = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);

keeping data during orientation changes by using fragments

I am trying to understand fragments. All the examples I read is about having a main activity and then two sub fragments.
The issue is that my program has only 1 activity. Can I make it a fragment?
Current ui main class
public class MainActivity extends Activity {}
Can I make it
public class MainActivity extends Fragment {}
The program I am trying to create will constantly monitor phone variables and display logs in a textView. I don't want to lose the logs when the user changes the orientation or some other change when the os destroys the ui.
The UI is basically 1 textView that gets filled by a runnable that updates the textView every 5 seconds with the content of a linked list. I don't want to lose the content of the linked list basically.
I checked getLastNonConfigurationInstance() but it seems it's depreciated so I don't want to use that
Any help would be highly appreciated.
Amish
Found answer here:
http://blog.webagesolutions.com/archives/458
So after a lot of searching I found that if you add the following:
android:configChanges="orientation|screenSize"
in the androidManifest.xml, the os will not destroy the activity when switching from portrait mode to landscape mode.
My xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.axr0284.phonecontrol"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.axr0284.phonecontrol.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hope this helps somebody,
Amish