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.
Related
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();
}
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);
}
I am using AwesomeValidation to validate all forms in my app.
It works well for every other form other than a form which has a PopupWindow when user clicks a TextView.
When I click on the PopupWindow's button which validates the form inside it, it does nothing. But after I input anything inside the EditText, it shows
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W#15f1d142 is not valid; is your activity running?
Here's my code for the popup window :
View.OnClickListener phoneReinputHandler = new View.OnClickListener() {
public void onClick(View arg0) {
/*Intent intent = new Intent(SignupStepTwoActivity.this, PopupHandphone.class);
backDim = (RelativeLayout) findViewById(R.id.bac_dim_layout);
//backDim.setVisibility(View.VISIBLE);
startActivity(intent);*/
mainLayout = (RelativeLayout)findViewById(R.id.activity_signup_step_two_mainLayout);
backDim = (RelativeLayout)findViewById(R.id.bac_dim_layout);
backDim.setVisibility(View.VISIBLE);
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View popupLayoutInflater = inflater.inflate(R.layout.popup_handphone, mainLayout);
PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.popup_handphone, null, false),
(int)(width * .8),
(int)(height*.35),
true);
//pw.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
pw.setOutsideTouchable(true);
RelativeLayout popupFunctionalitiesWrapper = (RelativeLayout)pw.getContentView().findViewById(R.id.popup_handphone_functionalities);
//popupFunctionalitiesWrapper.setGravity(Gravity.CENTER);
int popupFunctionalitiesWrapperWidth = layoutResize.width(70);
RelativeLayout.LayoutParams popupFunctionalitiesWrapperParams = (RelativeLayout.LayoutParams)popupFunctionalitiesWrapper.getLayoutParams();
popupFunctionalitiesWrapperParams.width = popupFunctionalitiesWrapperWidth;
popupFunctionalitiesWrapperParams.addRule(Gravity.CENTER);
popupFunctionalitiesWrapper.setLayoutParams(popupFunctionalitiesWrapperParams);
userPhonePopup = (EditText)pw.getContentView().findViewById((R.id.popup_handphone_phoneNumber));
mAwesomeValidation.addValidation(userPhonePopup, Patterns.PHONE, "Phone number must not be empty");
userPhoneCfmPopup = (EditText)pw.getContentView().findViewById((R.id.popup_handphone_phoneNumberConfirm));
Button buttonPhoneCodeResend = (Button)pw.getContentView().findViewById(R.id.popup_handphone_phoneNumberButton);
buttonPhoneCodeResend.setOnClickListener(new View.OnClickListener() {
AwesomeValidation resendPhoneValidation = new AwesomeValidation(ValidationStyle.COLORATION);
#Override
public void onClick(View v) {
Context context = v.getContext();
if(!((Activity) context).isFinishing())
{
if (!userPhonePopup.getText().toString().equals(userPhoneCfmPopup.getText().toString())) {
resendPhoneValidation.addValidation(userPhoneCfmPopup, "/^" + userPhonePopup.getText().toString() + "$/", "Nomor handphone harus sama");
}
resendPhoneValidation.validate();
}
}
});
pw.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
backDim.setVisibility(View.GONE);
}
});
}
};
A problem with Context?
I have two Linear Layouts in single activity .
I want to display custom popups on each of them when clicked.
When I click on first layout, popup apperas,then on clicking on 2nd layout ,both popups are displayed. how can i have only single popup displayed at a time?
this is my code
workLinearLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater layoutInflater=
(LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate
(R.layout.activity_your_places__work__popup, null);
updateTextView = (TextView)
popupView.findViewById(R.id.UpdateTextView);
updateTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Your_Places2Activity.this,
UpdateWorkAddressActivity.class);
startActivity(i);
}
});
deleteTextView = (TextView)
popupView.findViewById(R.id.DeleteTextView);
deleteTextView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
//code to delete address
}
});
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
//dismiss other popup if is showing
if(popupWindowHome.isShowing())
{
popupWindowHome.dismiss();}
//display popup
popupWindowWork.showAsDropDown(workLinearLayout, 0, -70);
}
});
i have done same thing on other linear layout
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
if(popupWindowHome.isShowing())
{
popupWindowHome.dismiss();
}
in this line, you are dismissing the popupWindowHome dialog if popupWindowHome is showing, with popupWindowHome being the NEW dialog. Move the if statement before the constructor call.
if(popupWindowHome != null && popupWindowHome.isShowing())
{
popupWindowHome.dismiss();
}
popupWindowWork = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
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;
}
}
}