I have an android dialog with button "feedback"
I want the user to write his input.
how can I create flip animation to flip this dialog a "enter feedback" dialog ?
I have tried:
private void flipCard() {
View rootLayout = (View) mDialog.findViewById(R.id.main_activity_root);
View cardFace = (View) mDialog
.findViewById(R.id.main_activity_card_face);
View cardBack = (View) mDialog
.findViewById(R.id.main_activity_card_back);
FlipAnimation flipAnimation = new FlipAnimation(cardFace, cardBack);
if (cardFace.getVisibility() == View.GONE) {
flipAnimation.reverse();
}
rootLayout.startAnimation(flipAnimation);
}
Related
I have a PopupWindow that has a TextView in it. I am trying to change the text in this TextView dynamically but can't seem to get it to work. The code executes, but it does nothing and gives no errors, making it hard to understand what's happening (as there is nothing that shows up in the debug logs). It's important to note that this TextView is not in the same layout as the layout given to setContentView - and that menu is called when a button is pushed in the main layout. Does anybody have any idea why this could be happening?
Here is my code:
public void popupView(View view, int viewPointer){//viewPointer is R.id.popup_layout
LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(viewPointer, null);
// create the popup window
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
popupWindow = new PopupWindow(popupView, width, height,true);//add another parameter here (true) to make it so it goes away when clicked outside the menu itself
popupWindow.setElevation(20);
// show the popup window
// which view you pass in doesn't matter
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
// dismiss the popup window when touched
popupView.setOnTouchListener(new View.OnTouchListener() {
#SuppressLint("ClickableViewAccessibility")
#Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return true;
}
});
}
and
public void menu(View view){
textView.setText("this won't change the text but will execute with zero errors...");
popupView(view, R.layout.popup_layout);
}
and in onCreate:
LayoutInflater layoutInflater = getLayoutInflater();
View text_view = layoutInflater.inflate(R.layout.popup_layout, null);
textView = text_view.findViewById(R.id.textViewID);
For the app i'm currently building i inflate a popup on the activity if there is no internet connection, the problem is that if the user presses their phone's back button, the popup disappears but u still get to see the activity without any information.
I would like to find out a way to finish the activity as well, when the back button is pressed.
Heres the code for the popup im currently inflating:
public void connection_error(final Class<?> clss){
if(!Functions.isOnline(getApplicationContext())) {
LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.popup_nointernet, null);
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.MATCH_PARENT;
boolean focusable = true; // lets taps outside the popup also dismiss it
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
popupWindow.showAtLocation(findViewById(R.id.drawer_layout), Gravity.CENTER, 0, 0);
Button btn_retry = popupView.findViewById(R.id.btn_retry);
btn_retry.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Functions.isOnline(getApplicationContext())) {
finish();
popupWindow.dismiss();
launchActivity(clss);
} else {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.label_no_internet), Toast.LENGTH_LONG).show();
}
}
});
}
}
Set a boolean that's set to true if your popup is open. Something like,
boolean popUpOpen = true;
Override the onBackPressed Method:
#Override
public void onBackPressed() {
if(popUpOpen){
super.onBackPressed(); // Closes Popup.
}
super.onBackPressed(); // Normal Behaviour - Finishes Activity if popup is open
}
I have this project App demo video that needs 6 types of images to be added in a horizontal scroll view each will have dialog fragment.
How can i find the position of images in horizontal scroll view and delete view when slide down.
final String[] AddCustomitems = {"Blink single message", "Blink double message", "Message", "Scroll", "Split", "Temp"}; //list of items that can be added in layout
int[] customviewsDrawable = new int[]{R.drawable.custom_blink, R.drawable.custom_blink_double, R.drawable.custom_message, R.drawable.custom_scroll, R.drawable.custom_split_double, R.drawable.temp};
public void CustomAnimationList(final Activity activity) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//set the title for alert dialog
builder.setTitle("Dot Matrix Add view");
//set items to alert dialog. i.e. our array , which will be shown as list view in alert dialog
builder.setItems(AddCustomitems, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
// setting the button text to the selected item from the list
AddItem(item);
}
});
//Creating CANCEL button in alert dialog, to dismiss the dialog box when nothing is selected
builder.setCancelable(false)
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
//When clicked on CANCEL button the dalog will be dismissed
dialog.dismiss();
}
});
// Creating alert dialog
AlertDialog alert = builder.create();
//Showing alert dialog
alert.show();
}
void AddItem(final int itemNum) {
if (countItem < 9) {
final float scale = getResources().getDisplayMetrics().density;
int dpWidthInPx = (int) (175 * scale); //rescalling views
int dpHeightInPx = (int) (250 * scale); //rescalling views
final LinearLayout sv = (LinearLayout) findViewById(R.id.horizontalLayout);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(dpWidthInPx, dpHeightInPx);
layoutParams.setMargins(10, 0, 0, 10); //adding margin
final ImageView iv = new ImageView(this);
iv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertView(itemNum); //this will send itemNum to switch case for corresponding dialog fragment.
}
});
iv.setLayoutParams(layoutParams);
iv.setBackgroundResource(customviewsDrawable[itemNum]);
sv.addView(iv);
countItem++;
} else {
alertItem(); //alert message if items are more then 8
}
System.out.println("count items :" + countItem);
}
I have implemented this by using ItemTouchHelper class.I have also added some features
1)Custom multiple dialog fragment added in Horizontal Scroll View.
2)Drag and drop feature to move items or delete item when swiped up or down
3)List the Order of items when Button is pressed
4)Alert dialog if items are more then the 8 elements.
I have committed the code on github for anyone to try out.[https://github.com/parmarravi/HorizontalRecyclerView ]
i am having an custom alert view which pop ups on a button click event.all the things are going fine.but the problem is:
if user clicks outside alert dialog it disappear.i want to restrict user for clicking out side.I am giving him the choice of cancel/cross button to close alert dialog.
so how to restrict user clicking outside the alert box?
code:
the code in onCreate for button click where i am calling show dialog:
final Button cdButton = (Button) findViewById(R.id.denonCdImage);
cdButton.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
showDialog(CD_CATG_ID);
}
});
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder;
Context mContext = this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.categorydialog,(ViewGroup) findViewById(R.id.layout_root));
GridView gridview = (GridView)layout.findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
/** Check the id for the device type for image tobe change */
switch(id) {
case 1 : // for the cd image
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,final int position, long id) {
Toast.makeText(view.getContext(), "Image selected for CD", 3000).show();
cdImageId = getImageId(position);
int elementId = getApplicationContext().getResources().getIdentifier(cdImageId, "drawable", getPackageName());
cdImageView.setImageResource(elementId);
Log.d("CdImageid", ""+cdImageId);
closeDialog(view);
}
});
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
dialog = builder.create();
break;
default:
dialog = null;
}
/** onclick listner for the close button */
ImageView close = (ImageView) layout.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
dialog.dismiss();
}
});
return dialog;
}
any suggestions?
thanks!
There are two methods concerning this behaviour: setCancelable() and setCanceledOnTouchOutside() as you can see in the reference.
How do I add a popup dialog over the call screen? I'll be using the BroadcastReceiver to listen for incoming calls and show it. I need an idea about how to write an activity that allows a dialog over an incoming call. Also, how do I make the dialog movable to any part of the screen? I already have the BroadcastRceiver implemented and performing other functions, so I could just use an intent and start the activity from this BroadcastRceiver
start an activity, then use AlertDialog Builder from that activity to prompt a dialog
set custom view to customize the dialog appearence
Try this
AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
LayoutInflater inflater = LayoutInflater.from(context);
View dialogView = inflater.inflate(R.layout.caller_dialog, null);
ImageView button = dialogView.findViewById(R.id.close_btn);
builder.setView(dialogView);
final AlertDialog alert = builder.create();
alert.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
alert.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
alert.setCanceledOnTouchOutside(true);
alert.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = alert.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setGravity(Gravity.TOP);
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//close the service and remove the from from the window
alert.dismiss();
}
});