Incoming Call Screen obstruction by an Activity (Theme Dialog) over it - android

I am trying to show an Activity (with Theme Dialog) over an Incoming call Screen to show some information. I am done with the that, but the problem is whenever the call comes, Activity Dialog pops up over it and it covers SLIDER ( for accepting/Rejecting calls) .
I want the Activity Dialog over Incoming call screen but still wants the user to pick/reject calls.
I did use this But now unable to finish activity(Dialog).
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
Warm Regards
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
setContentView(R.layout.notedialog);
this.setFinishOnTouchOutside(false);
initializeContent();
phone_no = getIntent().getExtras().getString("phone_no");
String note = getIntent().getExtras().getString("note");
tv_client.setText(phone_no + " is calling you");
note_mEditText.setText(note);
dialog_ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.this.finish();
// this.setFinishOnTouchOutside(false);
System.exit(0);
}
});

No need for an Activity with dialog style.
Call this method only when you want to show the dialog.
This will create a dialog on top of your phone.
final Dialog dialog;
public void showDialog(){
dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
// Setting dialogview
Window window = dialog.getWindow();
window.setGravity(Gravity.TOP);
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialog.setTitle(null);
dialog.setContentView(R.layout.notedialog);
dialog.setCancelable(true);
dialog.show();
}
And to cancel the dialog call this method.
public void cancelDialog(){
if(dialog!= null ){
dialog.dismiss()
}
}
OR
If you insist to use an Activity dialog You can use this method to change the position of window.
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
View view = getWindow().getDecorView();
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) view.getLayoutParams();
lp.gravity = Gravity.CENTER | Gravity.TOP
lp.x = 10;
lp.y = 10;
lp.width = 300;
lp.height = 300;
getWindowManager().updateViewLayout(view, lp);
}

Related

PopupWindow cannot display Unity3D views in Android, but Dialog does?

Here is some brief codes of my project, in which I'd like to display a Unity3D model to do something.
public class MainActivity extends FragmentActivity{
protected UnityPlayer mUnityPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
getWindow().setFormat(PixelFormat.RGBX_8888);
mUnityPlayer = new UnityPlayer(this);
...
mTestImageButton = ***;
mTestImageButton.setOnClickListener(mTestImageButtonClickListener);
}
private ImageButton mTestImageButton;
private View.OnClickListener mTestImageButtonClickListener = new
View.OnClickListener() {
#Override
public void onClick(View v) {
showUnity3D_dialog(v);
//showUnity3D_popupwindow(v);
}
};
private void showUnity3D_dialog(View v) {
Dialog dialog = new Dialog(v.getContext(), R.style.move_dialog);
dialog.setContentView(mUnityPlayer);
Window window = dialog.getWindow();
window.setWindowAnimations(R.style.move_dialog);
WindowManager.LayoutParams lp = window.getAttributes();
window.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
lp.width = 1179;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
window.setAttributes(lp);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
}
});
dialog.setCanceledOnTouchOutside(true);
dialog.show();
mUnityPlayer.resume();
}
private void showUnity3D_popupwindow(View v) {
PopupWindow pop = new PopupWindow(mUnityPlayer, 1000, 800);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setFocusable(true);
pop.setOutsideTouchable(false);
pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
}
});
pop.showAtLocation(v, Gravity.BOTTOM, 0, 0);
mUnityPlayer.resume();
}
}
As codes above, I tried to display a Unity3D-model in a PopupWindow, but the result makes me a bit confused, since there is nothing on screen when I called showUnity3D_popupwindow(v).
But when I called showUnity3D_dialog(v), the model by Unity3D shows.
I really can't understand what caused such scenario, and how can I display my model in a PopupWindow in android? Or, is it an impossible task?
I have my project under Android 4.3 & Unity 5.4.0.
Thanks a lot.
Looks like you are currently using the PopupWindow(View contentView, int width, int height) overload function. I've seen instances where functions that take View, Context or Activity does not work in Unity and you have to try other overloads.
You've tried the one takes View, now try the Context overload:
PopupWindow(Context context)
then set the width and height later on with the setWidth and setHeight function. You can get the current Context with UnityPlayer.currentActivity.getApplicationContext().
private void showUnity3D_popupwindow(View v)
{
Context mContext = UnityPlayer.currentActivity.getApplicationContext();
PopupWindow pop = new PopupWindow(mContext);
pop.setWidth(1000);
pop.setHeight(800);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setFocusable(true);
pop.setOutsideTouchable(false);
pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
}
});
pop.showAtLocation(v, Gravity.BOTTOM, 0, 0);
mUnityPlayer.resume();
}

Android full screen dialog fragment like calendar app

I am trying to achieve a full-screen dialog like the below image. I am able to show a full screen dialog but when the dialog is shown the status bar color changes to black and does not keep the primary-dark color.
Heres my dialog fragment
public class IconsDialogFragment extends DialogFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout to use as dialog or embedded fragment
return inflater.inflate(R.layout.fragment_icons_dialog, container, false);
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final RelativeLayout root = new RelativeLayout(getActivity());
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// creating the fullscreen dialog
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(root);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
dialog.getWindow().setWindowAnimations(R.style.DialogAnimation);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
}
To get DialogFragment on full screen
Override onStart of your DialogFragment like this:
#Override
public void onStart()
{
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
{
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
In order to setStatusBarColor you need to set the flag: FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
public void setStatusBarColorIfPossible(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(color);
}
}
One way is to change back your status bar color as theme programmatically whenever you open the dialog.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Your theme color);
}

Android Dialog UI scrambles with keyboard

I am using a custom dialog with EditTexts and Button.
But it gets scrambled whenever the keyboard is popped up..
I have tried this to solve this
d.getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
And My dialog code is this:
final Dialog d = new Dialog(NewOrderDetrails.this);
d.setContentView(R.layout.accept_dialog);
d.setTitle("Enter Details");
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Button dispatch,cal;
System.out.println("Delivery Phone" + getIntent().getStringExtra("Cphne") );
invoice=(EditText)d.findViewById(R.id.accept_invoice_no);
bill=(EditText)d.findViewById(R.id.accept_bill_amount);
discount=(EditText)d.findViewById(R.id.accept_discount);
dispatch = (Button) d.findViewById(R.id.accept_dispatch);
payblebill=(EditText)d.findViewById(R.id.accept_pay_amount);
etd=(EditText)d.findViewById(R.id.accept_etd);
cal=(Button)d.findViewById(R.id.accept_calculate);
cal.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
d.show();
d.getWindow().setAttributes(lp);
dispatch.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
}
});
I tried everything i could, but the problem is still there, And believe me it's annoying.. Please help.

Can't get transparent DialogFragment

I have a dialog Fragment which look like that.
AlertDialog ad = builder.create();
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
ad.getWindow().setBackgroundDrawable(d);
This code get background semi transparent. But I still got a white part on the bottom. I want to get rid of the white to just have semi transparent background
I already tried a lot of stuff that I saw in other posts.
I don't know what is the object that I must change between the DialogFragment, the AlertDialog and the LinearLayout.
It may not be the LinearLayout, because when I increase margin, nothing is moving.
Here is my code :
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// setStyle(DialogFragment.STYLE_NORMAL, 0);
// setStyle(STYLE_NO_FRAME, R.style.CustomDialog);
// setStyle(STYLE_NO_FRAME, 0);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(
R.layout.share_or_die, null);
AlertDialog ad = builder.create();
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
ad.getWindow().setBackgroundDrawable(d);
ad.setCanceledOnTouchOutside(true);
ad.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
ad.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
return ad;
}
I just call it in the mainActivity when user click back button:
#Override
public void onBackPressed() {
if (isUserConnected && !hasShared) {
shareOnExitDialog = new ShareOnExitDialog();
shareOnExitDialog.setCancelable(true);
shareOnExitDialog.show(getSupportFragmentManager(), "Exit");
} else {
finish();
}
}
Any help would be appreciated !
The issue is in default dialog theme. Based on this and this answers it's much easier to achieve your target.
The Activity should be like the following:
public class MyActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
#Override
public void onBackPressed() {
MyDialogFragment.newInstance("title title").show(getSupportFragmentManager(), "dialog");
}
}
And fragment:
public class MyDialogFragment extends android.support.v4.app.DialogFragment {
/**
* Create a new instance of MyDialogFragment, providing "title"
* as an argument.
*/
static MyDialogFragment newInstance(String title) {
MyDialogFragment frag = new MyDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
frag.setArguments(args);
return frag;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
final View view = getActivity().getLayoutInflater().inflate(R.layout.share_or_die, null);
final Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
dialog.getWindow().setBackgroundDrawable(d);
dialog.getWindow().setContentView(view);
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER;
dialog.setCanceledOnTouchOutside(true);
return dialog;
}
}
Also, be sure to do the following: before setContentView() in the activity, getWindow().requestFeature(Window.FEATURE_NO_TITLE) should be added in order to use *NoTitleBar style.
The result is (I've used LinearLayout with single TextView inside):
I hope it can help you
#Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.dimAmount = 0.0f;
window.setAttributes(windowParams);
}
None of the above solutions worked for me. What i found to work was to make sure that I had imported android.support.v7.app.AlertDialog instead of the generic app.alertdialog.
Hope this helps others too.
It works for me:
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Admob ad on custom Dialog

I am trying to implement Admob ads on app. What I want to do is to ad a banner ad on a custom Dialog. I have tried everything but can't find the solution.
I have made a custom xml for the dialog. When adding admob on xml, it won't run. So I tried do it programmatically. But still can't make it work.
public void OnClickButton(View paramView)
{
int btn_id = paramView.getId();
if (btn_id == R.id.hint_field)
{
//set up dialog
if (hint != null && hint.length()>0) {
final Dialog dialog = new Dialog(Activity.this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
//ad loading
dialog.setContentView(R.layout.custom_dialog);
RelativeLayout layout = (RelativeLayout)findViewById(R.id.dialog_l);
layout.addView(ad);
AdRequest r = new AdRequest();
ad.loadAd(r);
dialog.setTitle("Σχετικά με την λέξη :");
dialog.setCancelable(true);
//set up text
TextView text = (TextView) dialog.findViewById(R.id.hint_text);
text.setText(hint);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
// now that the dialog is set up, it's time to show it
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
}
}
On a button click I display a custom Dialog. In the OnCreate method of my Activity I have made the adView
AdView ad = new AdView(this, AdSize.BANNER, "a15xxxxxxxxxxx");
I get a NullPointerException at : layout.addView(ad);
Any ideas ?
Thanks in advance!
Problem solved! I had to inflate the custom dialog interface first. The code below is the working code!
public void OnClickButton(View paramView)
{
int btn_id = paramView.getId();
if (btn_id == R.id.hint_field)
{
//set up dialog
if (hint != null && hint.length()>0) {
final Dialog dialog = new Dialog(Activity.this, R.style.Theme_New);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.custom_dialog);
LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View main = inflater.inflate(R.layout.custom_dialog, null);
dialog.setContentView(main);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
LinearLayout linear = (LinearLayout)main.findViewById(R.id.ad_layout);
ad = new AdView(this, AdSize.IAB_MRECT, "a15xxxxxxxx");
AdRequest request = new AdRequest();
Set<String> keywords = new HashSet<String>();
keywords.add("game");
request.setKeywords(keywords);
linear.addView(ad);
ad.loadAd(request);
dialog.setTitle("Title :");
dialog.setCancelable(true);
//set up text
TextView text = (TextView) dialog.findViewById(R.id.hint_text);
text.setText(hint);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
// now that the dialog is set up, it's time to show it
lp.width = width;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
dialog.getWindow().setAttributes(lp);
dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
dialog.getWindow().getAttributes().height = LayoutParams.WRAP_CONTENT;
}
}
}

Categories

Resources