Weird behavior with custom indeterminate progress view - ProgressDialog - android

I'm trying to make a custom progress bar with custom indeterminate view using animation_list with multiple images .. i've got it to work but it does something weird a part of the image is repeated like so ..
Here is the code:
Dialog dialog = new Dialog(getActivity(), R.style.CustomProgressDialog);
View customView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.custom_loader_layout, null, false);
dialog.setContentView(customView);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
Here is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/imgProgreso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:background="#android:color/transparent"
android:indeterminateDrawable="#drawable/loader_drawable" />
<TextView
android:id="#+id/txtmensajedialogprogress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:background="#android:color/transparent"
android:gravity="center_vertical|center_horizontal"
android:text="Wait ..."
android:textColor="#android:color/black"
android:textSize="15dp"
android:textStyle="normal" />
and here is the custom style
<style name="CustomProgressDialog" parent="#android:Theme.Dialog" >
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
NOTE: worth mentioning this problem seems to happen when i use the custom style to make background transparent
Any help would be really appreciated :)

The answer was using an ImageView instead of a a custom layout resource while setting a background for the animation-list for some reason drawing that background for the animation-list got messed up.
It simply goes something like that ..
Dialog dialog = new Dialog(getActivity(), R.style.CustomProgressDialog);
ImageView customView = new ImageView(getActivity());
customView.setBackgroundResource(R.drawable.bg_loader);
customView.setImageDrawable(getResources().getDrawable(R.drawable.custom_loader));
while R.drawable.custom_loader is the animation-list

Related

How to set Custom Dialog background dim?

I made custom dialog and it doesn't make background color dim.
I tried this code and it shows with black background.
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Also tried this, but it shows same result. Background is still black.
window.setDimAmount(0.5f);
This is my CustomDialog layout Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardview"
android:background=""
style="#style/PopupView"
android:elevation="5dp"
card_view:cardCornerRadius="#dimen/card_band_radius">
<RelativeLayout android:orientation="vertical"
android:background="#drawable/twobtndialog_bg"
android:layout_width="wrap_content"
android:layout_height="160dp">
<TextView
android:id="#+id/tv_message"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:textColor="#color/dark"
android:fontFamily="#font/nanumsquareregular"
android:textSize="16sp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/ll_btn"
android:orientation="horizontal"
android:layout_marginTop="40dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/btn_left"
android:clickable="true"
android:src="#drawable/btn_no"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/btn_right"
android:clickable="true"
android:src="#drawable/btn_ok"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
And Style Codes are this.
<style name="PopupView" parent="CardView">
<item name="android:layout_width">#dimen/popup_width</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_margin">30dp</item>
<item name="cardBackgroundColor">#color/paleGrey</item>
</style>
These are dimen values
<resources>
<dimen name="popup_title_height">46.5dp</dimen>
<dimen name="popup_title_padding">5dp</dimen>
<dimen name="card_band_radius">10dp</dimen>
<dimen name="item_list_view_line_width">0.5dp</dimen>
<dimen name="popup_width">300dp</dimen>
</resources>
I want to make my dialog shows like this image below
You can try this.
<style name="NewDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:backgroundDimEnabled">true</item> <!--Background clear-->
<item name="android:background">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">false</item>
</style>
Important point is backgroundDimEnabled
dialog = new Dialog(activity, R.style.NewDialog);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
Me help this
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
/** set the dim amount of the settings activity */
lp.dimAmount = 0.5f;
dialog.getWindow().setAttributes(lp);
try this it's worked
dialog.getWindow().setBackgroundDrawable(new
ColorDrawable(android.graphics.Color.TRANSPARENT));

Android shared element to dialog actvitiy

I've got one activity with an image in a toolbar and an activity that is themed like a dialog with the same image in big. These are the layout files:
my_activity.xml:
...
<com.makeramen.roundedimageview.RoundedImageView
android:id="#+id/my_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="centerCrop"
android:src="#drawable/my_drawable"
android:transitionName="#string/my_image_transition"
app:riv_oval="true" />
...
my_dialog_activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#id/my_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/my_drawable"
android:tint="#color/accent"
android:transitionName="#string/my_image_transition" />
</LinearLayout>
The dialog activity becomes a dialog by applying this theme in the manifest:
<style name="MyDialogActivity" parent="Theme.AppCompat.Light.Dialog.MinWidth">
<item name="windowNoTitle">true</item>
<item name="android:windowMinWidthMajor">#dimen/abc_dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#dimen/abc_dialog_min_width_minor</item>
</style>
Both the activity and the dialog look exactly how I want them to look like.
Now I want to implement a shared element animation with these ImageViews: When the user clicks on the first activity's image, it has to grow and move into the middle of the screen so it fits the bigger dialog's image.
So I wrote this code:
Intent intent = new Intent(MyActivity.this, MyDialogActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
MyActivity.this, v, getString(R.string.my_image_transition)
);
startActivityForResult(intent, 999, options.toBundle());
} else {
startActivityForResult(intent, 999);
}
The animation does actually happen, but the moved image is only visible inside of the dialog's area. So you see an image that comes from the dialog's upper left corner, but you don't see it moving from the first activity outside of the dialog.
Here's a HTML version of how it should look like and what it currently looks like: https://jsfiddle.net/wutqdh9d/1/
The Share Element Animation was drawn in the second activity. As you use the Theme.AppCompat.Light.Dialog.MinWidth theme, the second activity's window size is smaller than the drawing area of animation.
Hence, just get rid of using the dialog theme. To change this below:
<style name="MyDialogActivity" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
The second activity layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="#id/my_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/your_icon"
android:transitionName="#string/my_image_transition"/>
Then it will be this effect(http://gph.is/1UzZZzV).
Hope it help.
Reference: https://stackoverflow.com/a/28508306/3171537
<style name="dialog_style_activity">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Above style is work for me. Reference this style in manifest.xml.

How to use circular progress drawable to add array colors

CircularProgressDrawable
This is the library i'm using in my project.
MY APPROACH IS :
<com.rey.material.widget.ProgressView
android:layout_width="48dp"
android:layout_height="48dp"
android:id="#+id/progressviewmain"
app:pv_progressStyle="#style/Material.Widget.ProgressView.Circular"
app:pv_circular="true"
android:background="#ffffff"
app:pv_progressMode="indeterminate"
app:pv_autostart="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
and Code is :
progressView = (ProgressView)findViewById(R.id.progressviewmain);
functions are :
private void startprogress(ListView listView, ProgressView progressView){
progressView.setVisibility(View.VISIBLE);
}
private void stopprogress(ListView listView, ProgressView progressView){
listView.setVisibility(View.VISIBLE);
progressView.setVisibility(View.GONE);
}
all of this is working fine but as there in documentation we can see CircularProgressDrawable with 2 different forms i'm not able to get 1st one in which colors are changing . How to give input the array of colors to that ?? how to use attr?
As it said in doc you can give the view array of colors with cpd_strokeColors
cpd_strokeColors - The array of colors will be used as stroke's color (for indeterminate mode).
Update 1:
To change the attributes you have to create a style in res/values/styles.xml like this:
<style name="CircularProgress">
<item name="cpd_padding">0dp</item>
<item name="cpd_initialAngle">0</item>
<item name="cpd_maxSweepAngle">270</item>
<item name="cpd_minSweepAngle">1</item>
<item name="cpd_strokeSize">4dp</item>
<item name="cpd_strokeColor">#color/colorAccent</item>
<item name="cpd_strokeSecondaryColor">#android:color/transparent</item>
<item name="cpd_reverse">false</item>
<item name="cpd_strokeColors">#array/rainbow</item>
<item name="cpd_rotateDuration">1000</item>
<item name="cpd_transformDuration">600</item>
<item name="cpd_keepDuration">200</item>
<item name="cpd_transformInterpolator">#android:anim/decelerate_interpolator</item>
<item name="pv_progressMode">buffer</item>
<item name="cpd_inAnimDuration">0</item>
<item name="cpd_outAnimDuration">#android:integer/config_mediumAnimTime</item>
</style>
Then assign it to your view:
<com.rey.material.widget.ProgressView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/progressviewmain"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
app:pv_autostart="true"
app:pv_circular="true"
app:pv_progressMode="indeterminate"
app:pv_progressStyle="#style/CircularProgress"/>
And it will work.

RelativeLayout match_parent not working

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#drawable/ic_shade"
android:layout_height="match_parent" >
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="54sp"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:text="مبروك \nلقد ربحت كوبون"/>
</RelativeLayout>
What happens, it doesnt take entire width/height and i dont see the background on entire page.I am using the activity to be transparent.
Below is code for activity, however if i add
< item name="android:windowFullscreen ">true</item>
to the below part it works.. but i dont want it to do it because its resizing my previous activity.
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
<!-- Application t
your textview is filling the whole screen, change layout_height and layout_width attributes of your text view to wrap_content. then textview will be in center and background will appear on entire screen

Styling dialog boxes in Android

I've been trying to set a basic (not at all custom) dialog box using a fragment, and having difficulties. As you can see in the attached in image, the background shadow isn't correct and the title has white at the left and right hand side.
Following advice from How to style AlertDialogs like a pro I tried setting the alert dialog style through my app, and copying the style out of the Android SDK but this doesn't seem to make much difference.
<!-- Local copy of android:Theme.Holo.Dialog.Alert -->
<style name="Theme_Holo_Dialog_Alert" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#drawable/dialog_full_holo_light</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:buttonBarStyle">#android:style/Holo.Light.ButtonBar.AlertDialog</item>
<item name="android:borderlessButtonStyle">#android:style/Widget.Holo.Light.Button.Borderless.Small</item>
<item name="listPreferredItemPaddingLeft">16dip</item>
<item name="listPreferredItemPaddingRight">16dip</item>
<item name="android:windowMinWidthMajor">#android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">#android:dimen/dialog_min_width_minor</item>
</style>
<!-- Local copy of android:DialogWindowTitle.Holo -->
<style name="DialogWindowTitle_Holo">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#android:style/TextAppearance.Holo.DialogWindowTitle</item>
</style>
and I tried setting the style directly using
ContextThemeWrapper ctw = new ContextThemeWrapper(getActivity(), R.style.Theme_Holo_Dialog_Alert);
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
and also
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
None of which make a difference to the background shadow or the title styling.
Any ideas?
Update 1: The layout of the dialog is set using a fragment and added to the builder as a view:
LayoutInflater inflater = getActivity().getLayoutInflater();
_layoutView = inflater.inflate(R.layout.fragment_edit_cycles, null);
builder.setView(_layoutView);
using the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="20dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editStageCyclesSpin" />
</LinearLayout>
Update 2: Removed the padding and changed the height/width in response to Alok Nair
I removed the padding and changed the layout width and height but unfortunately this had no effect on the white space in the title
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editStageCyclesSpin" />
</LinearLayout>

Categories

Resources