I want to implement an about box in my wallpaper. For that, I want a window to show up which contains the information when a user clicks on it.
None of the available controls like checkbox, listview etc. can be used for this......
I also tried to make a Dialog Pref by following advice from some other questions I looked at but ended up with a dialog that just does not seem appropriate for an about box.
My DialogPref:
public class DialogPref extends DialogPreference {
public DialogPref(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
persistBoolean(positiveResult);
}
}
So can you help me implement a popup window for an about box?
Related
I am trying to customize the Google Cast SDK's Cast Dialog (shown when you tap the cast button and shows the list of available devices), but i haven't found a way to do it.
Currently, it just shows an AlertDialog with a list of the available devices to connect.
What i want to do instead, is open an Activity that will show the list of devices with my own UI implementation.
This is the dialog i am trying to modify:
I've found many customization aspects about this SDK, but nothing related to this dialog.
So i figured out a way to achieve this,
First i created a class that overrides MediaRouteActionProvider (which is the main class that controls that button's functionality)
public class CustomMediaRouteActionProvider extends androidx.mediarouter.app.MediaRouteActionProvider {
public CustomMediaRouteActionProvider(Context context) {
super(context);
}
#Override
public MediaRouteButton onCreateMediaRouteButton() {
return new CastButton(getContext());
}
}
Then you're gonna need to override the button's functionality with your own, in my case i open a new activity.
public class CastButton extends MediaRouteButton {
public CastButton(Context context) {
this(context, null);
}
public CastButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.mediaRouteButtonStyle);
}
public CastButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#Override
public boolean performClick() {
Intent i = new Intent(getContext(), RemoteDevicesActivity.class);
getContext().startActivity(i);
return true;
}
}
Finally, you need to modify your xml that contains this button (i assume that you already implemented this part)
Change the field app:actionProviderClass with your custom class (in this case CustomMediaRouteActionProvider) and you're done.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="#string/connect_to"
android:id="#+id/cast"
app:actionProviderClass="CustomMediaRouteActionProvider"
app:showAsAction="ifRoom" />
</menu>
Are you have more details of final result of this? I need to do something similar but I don't get it how did you achieve it
I have created a custom dialog that is used from a preference screen. Everything works fine except one thing: I want to switch the visibility of the Cancel button based on the status of an internal check.
Normally you have onPrepareDialog and onCreateDialog and you can do this in onCreateDialog. But here we have onPrepareDialogBuilder... so where is onCreateDialogBuilder? Where can I do something like
builder.setNegativeButton(null, null);
after onPrepareDialogBuilder? I cannot do it IN onPrepareDialogBuilder since I need the Cancel button in case the internal check fails.
Can you please help me to get into the right direction?
public UnlockPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setDialogLayoutResource(R.layout.dialog_enter_registration);
}
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.setTitle(R.string.label_enter_registration);
}
// would need something like
#Override
protected void onCreateDialogBuilder(AlertDialog.Builder builder) {
super.onCreateDialogBuilder(builder);
if (internalCheckOk())
builder.setNegativeButton(null, null);
else
builder.setNegativeButton(..., ...);
}
I use standart EditTextPreference but on different Android versions it looks differently:
API 7
API 10
How can I achieve good view? Maybe resize keyboard or something else?
This helped me solve the problem:
https://stackoverflow.com/a/8481314/1752613
public class MyEditTextPreference extends EditTextPreference
{
public MyEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void showDialog(Bundle bundle) {
super.showDialog(bundle);
Dialog dialog = getDialog();
if(dialog != null) {
Window window = dialog.getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
}
}
I've got with my own layout.
I would like to receive the text from the editText after positive button on the layout is clicked. But in onPreferenceChange, I always get only the default value.
It seems that I need to bind my own EditText to the preferences somehow, but I don't know how and where to do this.
Can anybody help me?
To answer my own question:
First of all, in PreferenceScreen, you need to state:
<full.path.to.your.OwnLayoutClass
android:name="whatevever"
android:dialogLayout="#layout/your_own_layout" />
your_own_layout can be anything you'd like, linearlayout with of buttons, editTexts, according to your wishes.
Essential is the class representing your own preference Dialog. Here is a simple example of how to do it:
public class YourOwnLayoutClass extends DialogPreference {
private LinearLayout mView;
public YourOwnLayoutClass(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
setDialogLayoutResource(R.layout.your_own_layout);
}
#Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
mView = (LinearLayout) view;
}
#Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
// get value from editFields, do whatever you want here :)
// you can acces them through mView variable very easily
}
}
}
Important references:
I need to have a custom dialog in Preferences
Concise way of writing new DialogPreference classes?
Android: launch a custom Preference from a PreferenceActivity
I have an EditTextPreference in the PreferenceActivity. When user click the EditTextPreference will show a dialog. In the dialog, user can input a value, and the dialog has "OK" and "Cancel" buttons. I want to call the click event of ok button to check the value, but I do not know how to call the click even.
I know I can use EditTextPreference.setOnPreferenceChangeListener(), but I want to know if I can use OK button click event.
You can extend EditTextPreference to get control over the click handler.
package myPackage;
public class CustomEditTextPreference extends EditTextPreference {
public CustomEditTextPreference(Context context) {
super(context);
}
public CustomEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
// add Handler here
}
super.onClick(dialog, which);
}
}
In the Xml instead of <EditTextPreference/> reference it like this:
<myPackage.CustomEditTextPreference android:dialogTitle="Registration Key" android:key="challengeKey" android:title="Registration Key" android:summary="Click here to enter the registration key you received by email."/>
Actually you can't since the preference is using an internal AlertDialog.Builder and creates a new dialog every time you click the preference. The next problem is that the dialog builder sets the click listener for you and if you override them you might destroy the close behavior of the button click.
This bothered me since I wanted a preference which only closes on valid input (otherwise a toast is shown and user should press cancel if he can't get it right).
(If you really need a solution for exactly this problem) You can find general solution of a validating DialogPreference here and a validating EditTextPreference here which I wrote myself.
Your preference activity doesn't appear to be implementing a
OnSharedPreferenceChangeListener
You may want to read over the excellent answer to the question: Updating EditPreference