How to implement dialog that help users to know the app features? - java

I need to Implement the dialoges given in Image to introduce attributes of App, I couldn't find the way to implement it yet.
I have tried Firebase InAppMessaging but it's automatically being displayed just after the App starts. What I need is the Message dialog should display after a button gets clicked.
the code I putted in the button.OnclickListener
FirebaseInAppMessaging.getInstance().triggerEvent("CompaignId");
Link to Firebase InAppMessaging Docs from where I get the given code

You can use BubbleShowCase to achieve your dialog.
How to use it in the simplest way:
BubbleShowCaseBuilder(this) //Activity instance
.title("foo") //Any title for the bubble view
.targetView(view) //View to point out
.show() //Display the ShowCase
And if you will read more in the library page you can find info about making a custom dialog.

You can use full-screen dialog with transparent background and show whatever feature you have to show
e.g
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_layout);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
dialog.show()

There's a lot of libraries out there, but if you want a google like showcase, you can use ShowCaseView
ShowcaseViewBuilder showcaseViewBuilder;
showcaseViewBuilder = ShowcaseViewBuilder.init(this)
.setTargetView(fab)
.setBackgroundOverlayColor(0xdd4d4d4d)
.setRingColor(0xcc8e8e8e)
.setRingWidth((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics()))
.setMarkerDrawable(getResources().getDrawable(R.drawable.arrow_up), Gravity.LEFT)
.addCustomView(R.layout.description_view, Gravity.TOP)
.addCustomView(R.layout.skip_layout)
.setCustomViewMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 70, getResources().getDisplayMetrics()));

Related

Is there any alternative for setWindowAnimations(Android) in Harmony OS?

I am developing a Harmony application and I want to animate the Dialog window
this code is from android and this type of animation I want to add
Window dialogWindow = dialog.getWindow();
dialogWindow.setWindowAnimations(R.style.CustomDialogAnimation);
// properties that needs to be attached to Dialog window
duration="75"
fromXScale="0"
fromYScale="0"
toXScale="1"
toYScale="1"
I didn't find anything matching documentation like setWindowAnimations.
I tried writing this code but hit a dead end after getting the dialog window. How to add animation properties to this dialog window.
CommonDialog commonDialog = new CommonDialog(getContext);
Window dialogWindow = commonDialog.getWindow();
Is there any other way to code this?
According to the team, HarmonyOS does not currently support to add animation properties to dialog window. Please stay tuned on HarmonyOS official websites.

How to click Android phone "home" button programmatically in espresso

I need to simulate home button click in Espresso on Android phone.
I tried
onView(withId(android.R.id.home)).perform(click());
and onView(withContentDescription("Navigate up")).perform(click());
as some posts suggested but it always fails to find the view.
I'm new to Espresso and not sure how to debug it. Thanks.
Better to use withContentDescription(R.string.abc_action_bar_up_description) rather than "Navigate up" but it doesn't act like a home button click anyway, it only uses the navigation bar's "back" button, so it would only work if you have it in your app.
If you want to simulate the home button click and you are using the UI Automator library, you can simulate it like this
fun pressHome() {
// Might be a good idea to initialize it somewhere else
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.pressHome()
}
Alternatively, if you don't want to or can't use UI Automator, you might try calling Intrstumentation.sendKeyDownUpSync() with the KeyEvent.KEYCODE_HOME.

Setting width of controlsFX dialogs

I'm using controlsFX for dialogs and I can't figure out how to set the width. A lot of my messages only include the title, masthead and buttons. But the text in the buttons isn't fully display. For example:
Action deleteStuff = new DialogAction("Delete Stuff", ButtonBar.ButtonType.OTHER);
Action deleteMoreStuff = new DialogAction("Delete More Stuff", ButtonBar.ButtonType.OTHER);
Action response = Dialogs.create()
.owner(stage)
.title("Delete")
.masthead("This is a delete dialog")
.actions(deleteStuff,deleteMoreStuff,Dialog.ACTION_CANCEL)
.showConfirm();
And one of the buttons will show: "Delete Mo..."
And yes, I know I should be using the Alert class, but the project is for machines running older versions of Java. Thanks in advance.

Disabling Android Button depending on Permissions

I have an android app that uses the permission "CALL_PHONE". This simple app would just contain a button that would use the call intent to call a specific number. I would like to install this app on both tablets and phone but when it is installed on the tablet, I would like the button to be disabled during runtime so errors wouldn't show when the user tries to call using the tablet without a call function.
At the moment, I am using the setEnabled() and setClickable() method in my MainActivity.java and setting it to false when the user clicks on the button the first time. My question is whether the button can be disabled and the text changed during runtime or when the app is first opened (in a tablet) so the user wouldn't have to click the button first for it to show that the "call" button should be disabled and unclickable?
Refer to this
That will help you in identifying that your application is running on tablet. Now as for disabling your button, I would suggest something like this:
onCreate()
{
setContentView(R.layout.main);
boolean isTablet = checkDevice();
callBtn = (Button) findViewById(R.id.call);
if (isTablet)
{
callBtn.setEnabled(false);
callBtn.setText("Not allowed to make a call");
}
callBtn.setOnClickListener( new onClickListener(){
//Make a call
});
}
public boolean isTablet()
{
//Code for identifying. Return true if application is running on tablet
//return false otherwise
}
So you won't have to wait for user's click on Call button to disable it in tablet.
Hope that helps.
Use button.setEnabled(false); to make visible but user cant click and
button.setVisibility(View.GONE); to make button invisible.and button.setText("YOUR_NEW_TEXT"); to change the button text runtime
And this is not depend on the size of the screen.
Is this you wanted?? OR be more specific with your queston.
... the text changed during runtime?
You can use the setText(); method.
About the other part of your question, you need first to define "What is a tablet?". Is it a 7", 8", 10" screen? Is it a mdpi, hdpi, xhdpi screen? Is it a device which is able to do phone calls? What is a tablet for you or your project? Depending on your answer, you can filter your code (or xml in folders) to make them work the way you want.

How to make my activity transparent?

I am making a keyboard ( InputMethodService ), which needs to launch a dialog.
As I found out, a service can not launch a dialog. So I made a separate activity which is called from the service by
Intent dialogIntent = new Intent(getBaseContext(), dialog.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);
and show a dialog. The problem is that this activity replaces the previous one, where the user was typing something.
What do you think would be the best way to make it "transparent" ( i.e. not to push away the previous activity ) and also what would be the best way for this activity to talk back to the service, saying that dialog option was picked.
Thanks! :)
If this is an Activity (not a Dialog), you can add a dialog theme in the activity section of your AndroidManifest:
android:theme="#android:style/Theme.Dialog"
As for getting back what the user pressed, you should use startActivityForResult(...)
You should NOT launch an activity from an IME. This is a huge break in the IME flow -- the activity comes along and does an app switch from the current app, taking focus from it, and breaking your connection with its current editor.
Also there is no way to get a result back from it, because you can only use startActivityForResult() from an activity.
To show a Dialog in your IME, just use Dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG before showing the dialog.
To resume in code what have been said, let me share some code for those who need to test the solution:
// 1. CREATE THE DIALOG
val builder: AlertDialog.Builder = AlertDialog.Builder(this, R.style.Theme_AppCompat_Light)
builder.setTitle("Title").setMessage("This is the message for the user. ")
val mDialog = builder.create()
// 2. SET THE IME WINDOW TOKEN ATTRIBUTE WITH THE TOKEN OF THE KEYBOARD VIEW
mDialog.window?.attributes?.token = this.mKeyboardView.windowToken
// 3. SET THE TYPE OF THE DIALOG TO TYPE_APPLICATION_ATTACHED_DIALOG
mDialog.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG)
// 4. SHOW THE DIALOG
mDialog.show()

Categories

Resources