Firebase realtime freezes UI android java - android

I have a few years android/Firebase experience . I ve seen several mentions of firebase actions not being able to freeze the UI while in fact me and other people have experienced it and I never saw any proper solution . Back thread doesn t help .
Writing on an already quite populated node (non populated node doesnt freeze)
This example is built in purpose to underline the fact that "firebase writes in Bg" , hence no action on the UI doesn t apply here
GC is called in the traces and UI Freezes . If not using any specific drawable , UI doesn t freeze (if no other action taken on the UI, if any GC called and app freezes)
Handler handlerGlow = new Handler();
Runnable glowRunnable = new Runnable() {
public void run() {
new Thread(() -> {
Random random = new Random();
FirebaseDatabase.getInstance().getReference().child("AAA").setValue(random.nextBoolean());
}).start();
handlerGlow.postDelayed(this, 300);
}
};
glowRunnable.run();
To make the UI freeze :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="#android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
and in the activity :
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="500dp"
android:minWidth="500dp"
android:indeterminateDrawable="#drawable/aaa"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

Related

How to increase size of switch control Xamarin forms?

I recently just started working with Xamarin Forms and have the task of switching a working iOS project to Droid. It's a multiplatform project so I'm creating the switch in the shared project, but trying to manage its style in .Droid styles.xml or a custom renderer. I'm needing the control to be a bit larger for the tablets.
Using styles.xml, I was able to change the width of the switch control using this line:
<item name="switchMinWidth">120dp</item>
But to my knowledge there's no way to change the height of the control in this manner. I've tried using a custom renderer and used the SetHeight, SetMinHeight, and SetMinimumHeight methods of the Control (Android.Switch.Widget) but nothing is working.
Here's what the switches look like currently:
https://imgur.com/XIPp6vV
I've also tried doing a HeightRequest in the xaml itself but it doesn't change the actual height of the control. Is there anything I can do to make these switches a little taller?
How to increase size of switch control Xamarin forms?
Switch height is controlled by <switch android:track="#drawable/shape_mythumb".../>, and the track's height determines the Switch's overall height. So yo could add this property in your custom SwitchRenderer :
public class MySwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Switch> e)
{
base.OnElementChanged(e);
if(Control != null)
{
Control.SetTrackResource(Resource.Drawable.track);
}
}
}
You need custom a Track layout, you could draw a shape whatever you want.
Example :
track.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/switch_track_on"
android:state_checked="true"/>
<item
android:drawable="#drawable/switch_track_off"
android:state_checked="false"/>
</selector>
switch_track_on.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="15dp" />
<size
android:width="75dp"
android:height="25dp" />
<solid
android:color="#6decacec" />
</shape>
switch_track_off.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="15dp" />
<size
android:width="75dp"
android:height="25dp" />
<solid
android:color="#6db3b1b3" />
</shape>

How to get dashed Horizontal Progressbar in Android?

I need to design a dashed progressbar as shown in attached.
This is what I have done so far, It displays a normal progressbar with two different colors, one for progress and another for other.
<ProgressBar
android:id="#+id/progress_bar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="3dp"
android:progressDrawable="#drawable/bg_progress_bar_green"
/>
And bg_progress_bar_green is here
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<solid android:color="#E0E1EA" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<solid android:color="#66BA6B" />
</shape>
</clip>
</item>
And this is how I update the progressbar :
progressBar.setProgress(numOfHours);
How do I get dashed line of bar as shown?
You can use this library for your work Step Progress Bar. I'm providing code in case of link changed.
Gradle
dependencies {
...
compile 'com.marcok.stepprogressbar:stepprogressbar:1.0.1'
}
Usage
<com.marcok.stepprogressbar.StepProgressBar
android:layout_centerVertical="true"
android:layout_height="0dp"
android:layout_width="wrap_content"
android:id="#+id/stepProgressBar"
app:cumulativeDots="false"
app:activeDotIndex="0"
app:activeDotColor="#color/material_deep_teal_500"
app:inactiveDotColor="#color/material_blue_grey_800"
app:activeDotIcon="#drawable/active_dot.png"
app:inactiveDotIcon="#drawable/inactive_dot.png"
app:numberDots="6"
app:dotSize="20dp"
app:spacing="20dp"/>
If dot icons are provided, they override dot colors
Layout height is irrelevant and determined by the dotSize
Java Code
To move to the next dot or previous dot:
StepProgressBar mStepProgressBar =(StepProgressBar)findViewById(R.id.stepProgressBar);
mStepProgressBar.next();
mStepProgressBar.previous();
To set the dots to be cumulative (all dots <= the specified index will show as active), call setCumulativeDots(true)
Calling setCurrentProgressDot(-1) will prevent any dots from showing as active. Any lower values will throw IndexOutOfBoundsExeption.
Other methods:
setCurrentProgressDot();
setNumDots();
setActiveColor();
setInactiveColor();
setActiveDrawable();
setInactiveDrawable();
DRAWABLES FOR RECTANGLE PROGRESS
use these two drawbles..
inactive_dot.png
active_dot.png

Special background for a custom seekbar in Android

I have a custom Seekbar that I have made using 9 patch images so I can have different aspects for the main progress, the secondary progress and the background.
As of now, this is the result I have:
And the code to generate it is:
<item
android:id="#android:id/secondaryProgress">
<clip>
<nine-patch android:src="#drawable/dw_sec_prog" android:dither="true"/>
</clip>
</item>
<item
android:id="#android:id/progress">
<clip>
<nine-patch android:src="#drawable/dw_prog" android:dither="true"/>
</clip>
</item>
<item
android:id="#android:id/background">
<nine-patch android:src="#drawable/dw_bg" android:dither="true"/>
</item>
The problem is that for the secondary progress (dw_sec_prog) I have a transparent background and the background (dw_bg) is being shown below it.
The desired result shall be something like this:
This result shall keep the background of the secondary progress transparent. I know that in the layer-list there is an option to write a layer mask (mentioned here) but that is not useful for me since I'm restricted to api 16 and this solution only works on 21.
Is there then a way to make that happen ?
EDIT: Small clarification

Android ProgressBar set progress rounded corners

I have created the following progressbar style and set the corner radius to both shapes (background, and pogress). But it seems that when I animate / set progress below 90 my progressbar current progress shows rectangle shaped borders, without any radius. I would like to know if it is possible to have the corner radius all the time, even if the progress is 30 or less than 90,95. Can anyone explain why this is not working?
Also I need this to work with the API LEVEL 8
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="#android:id/background">
<shape>
<corners android:radius="25dp" />
<solid android:color="#00000000"></solid>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="25dp" />
<gradient
android:startColor="#fff"
android:centerColor="#fff"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
Update: I've added the right code that explains my problem
Ok. After researching and doing some more tries to accomplish this I only got to the solution of using a 9patched PNG file to make this work.
It is definately possible to have corner radius all the time. I did it by adding this line before setcontentview method of your custom progress bar.
customProgressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
This will make your whole view transparent. So fill the boundary inside your corners with some color.

android - seekbar progress does not get painted all the way

does anybody know why I am getting this (see photo)?
Here is how I set it:
this._seekBar.setProgressDrawable(_context.getResources().getDrawable(R.drawable.common_controls_player_progressbar_bg_expanded));
this._seekBar.setThumb(_context.getResources().getDrawable(R.drawable.ringtone_scrub));
this._seekBar.setThumbOffset(0);
this._seekBar.setMax(1000);
this._seekBar.setMinimumHeight(6);
Seekbar itself:
<SeekBar android:id="#+id/seekbar_ctrl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxHeight="6dp"/>
Expanded view xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<solid android:color="#color/player_progressbar_gray"/>
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#color/player_progressbar_gray"/>
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<solid android:color="#color/player_progressbar_green"/>
</shape>
</clip>
</item>
</layer-list>
It does happen in both expanded and collapsed view. What am I missing?
Thank you in advance
this was due to the launch of two controls that I was toggling. 1. expanded mode 2. collapsed. State of the progress was lost between toggles since I was only setting one control at a time. So what I did to fix this was: I placed 2 progress bar controls on the control holder and was setting them both at the same time. One remained hidden the other one was shown. During toggle event I switched the visability. That solved the issue. The second issue we had with same control was the progress on tap would flicker back and forth before being set. It turned out to be the issue with the OS of the phone and related to the player itself. We got a new OS build release and that fixed the issue.

Categories

Resources