Android 4.0.3 Progress Dialog Closing - java

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".

Related

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

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);

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.

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.

Admob(Ads) in Custom Alert Dialog

In the market I saw an app is displaying admob in the alert dialog . after I reading this and this and this ,
I still can't figure out how to display the ads in alert dialog same like the one below. (or any others method , that can display the ads in a alert dialog)
I've been scratching my head trying to figure out how
to do that.
Could anyone be kind enough to guide me through how
to go about this?
XML :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="#id/tablayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx">
<TableRow>
<com.admob.android.ads.AdView android:id="#id/myad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#ff000000"
myapp:primaryTextColor="#ffffffff"
myapp:secondaryTextColor="#ffcccccc" />
</TableRow>
</TableLayout>
Java :
public void onBackPressed() {
//set up dialog
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout.exitdialog);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
});
}
Thanks.
I found another solution to do this.
AdMob offers a JavaScript integration solution for Android and iPhone sites/web apps.
Instead of using XML and a custom dialog.
We can use Admob web ads and a HTML that contain the admob code and load it with webview in the dialog.
I believe it's not possible unless you're on landscape mode. The reason is that the ad needs something close to the device width (in portrait mode, e.g. 480) for the ad, so it is only available in landscape mode when you're adding it inside a dialog

Categories