Enable a Button when Progress bar has Loaded Completely. In android studio - java

When progress bar is loading enable button click in android studio using java .
When progress bar is loading button click enable .

I suggest, define max progress a progress bar can gain, using XML or programmatically.
In XML,
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:progress="0"/>
Assuming, You will be using CountDownTimer, to track the progress, when the progress will hit the max [May use If condition inside the onTick() or onFinish() can do the job],and then you may enable the button.
progress_bar.setProgress(100); //setMax()
myButton.setEnabled(true);

Related

How to show progressbar with blurry background and disabled UI

so I am making an app which has a lot of connections to the database, so there is a "waiting" time everywhere.
I want to put a progress bar everywhere where is a connection to the database. It should look like this:
-The progress bar is shown after clicking the Login button with the blurry background.
In short - Show progress bar, blur the background, deactivate UI controls while progressbar is activated.
I'll try to show you the pseudo code here:
loginBtn.setOnClickListener {
progressBar.visibility = View.VISIBLE
BlurTheBackground()
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
DoTheLoginStuff()
}
And after Login I want to disable progress bar and reactivate fully UI.
PS: After Login the activity changes to another,but after hitting back button on the smartphone it comes back without refresh
You can try https://android-arsenal.com/details/1/4409 this library. I think it can help You.
<RelativeLayout
android:id="#+id/progressBar_blurLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.armboldmind.natalipharm.view.customViews.RealtimeBlurView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:realtimeBlurRadius="15dp"
app:realtimeOverlayColor="#99FFFFFF" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
Set it on top of your layout, and on login button click change visibility of progress bar layout.

Android progress bar keeps spinning

I'm trying to use a progress bar (the normal one, not the horizontal one) as a compass of sorts, but for some reason the bar just keeps spinning without control. I've set the indeterminate to false, both in the xml and in the attached Java code, but it seems to do nothing.
This is the xml code for the View:
<ProgressBar
android:id="#+id/brujula"
style="?android:attr/progressBarStyle"
android:layout_width="229dp"
android:layout_height="507dp"
android:layout_marginStart="91dp"
android:layout_marginTop="90dp"
android:layout_marginEnd="91dp"
android:layout_marginBottom="135dp"
android:visibility="invisible"
android:indeterminate="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The code I'm using to set it to false in Java too is
ProgressBar brujula = (ProgressBar) FindViewById(R.id.brujula);
brujula.setIndeterminate(false);
I have no idea whatsoever of why it keeps doing that, so any help at all will be appreciated
hi try this if you want to show progressbar do like this.
ProgressBar brujula = (ProgressBar) FindViewById(R.id.brujula);
brujula.setVisibility(View.VISIBLE);
and where you want to stop loading and want to hide progressbar use
brujula.setVisibility(View.GONE);
If you want to use the Progress bar again it's better to just hide it:
brujula.setVisibility(View.GONE);
Or you can remove it completely:
((ViewGroup) brujula.getParent()).removeView(brujula);

How to resolve focus snatching issue in Activity?

Background
Development Tool: Android Studio 2.1.3
Device: Android OS Ver. 4.4.2
I have an Activity with multiple Views. I wanted to focus a certain view (editText1 in this case) programatically based on user's previous actions. So I employed View.requestFocus() for this. Before this, I have set focusable and focusableInThouchMode of editText1 to true XML design file:
<EditText
android:id="#+id/editText1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".15"
android:inputType="numberDecimal"
android:maxLength="3"
android:text="1"
android:focusableInTouchMode="true"
android:focusable="true"
android:enabled="true" />
Ideally the scenario would be: If user has checked a certain myCheckBox before current action, move focus to dditText1, if else, return.
if(myCheckBox.isChecked()){
editText1.selectAll();
if(adet.requestFocusFromTouch()) {
Log.i(General.LOG_TAG, "editText1 has focus");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText1, InputMethodManager.SHOW_IMPLICIT);
}
return;
}
But In reality, some other View snatches focus instantly from editText1. I can even see that editText1 got focus and have selected a text inside it for an instant. Also, I can see in log that editText1 got focus.
My activity contains a LinearLayout and all other Views(CheckBox, EditText, ListView etc.) are inside it. Also I have set focusable and focusableInThouchMode to false for other views than editText1
Question
How can I prevent other views than my editText from getting/snatching focus in my scenario?
Is there an alternative approach for what I am trying to do here?
You could try to set android:focusable="false" for the components that should not get focused. Not sure I got your question right.

Dialog changes the orientation by itself. How to fix the orientation of a dialog to landscape

I am showing a custom dialog in an activity of which the orientation is set to landscape. But the orientation is getting changed to portrait mode from the inital landscape(only the dialog, below activity remains in landscape mode). This is happening without any outside action like tilting the tablet or something.
I could not find any help in fixing the orientation of dialog anywhere.
Any ideas?
Dialog mDialog = new Dialog(MainActivity.this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mDialog.setContentView(R.layout.alert);
mDialog.show();
This is the code used for showing the dialog.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dip"
android:layout_height="300dip"
android:background="#drawable/alert_bg"
android:orientation="vertical" >
------------------------------
---------------------------
</LinearLayout>
This is the xml element parent tag used.
If you are using an Activity as a dialog then you can set
android:screenOrientation="landscape"
in your manifest file.
If you are using custom dialog then you can use
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
before you use setContentView(); method.

Android 4.0.3 Progress Dialog Closing

On android 4.0.3 apparently the progress dialog closes when you click on the grayed area.
Is there any way to prevent the Progress Dialog from Closing on tap?
SOLVED-
PROGRESSDIALOG.setCancelable(false);
_progress.setCanceledOnTouchOutside(false);
prevents the dialog from being closed on tap but still allows the back button to be used.
I guess that can be disabled.
In the XML declaration of the progress bar,set
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false".

Categories