Search in sources :

Example 21 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project android-sms-relay by nyaruka.

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View title = getWindow().findViewById(android.R.id.title);
    title.setPadding(5, 0, 0, 0);
    addPreferencesFromResource(R.xml.preferences);
    // Add a listener for relay password
    Preference relayPassword = (Preference) findPreference("relay_password");
    relayPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String password = newValue.toString();
            Log.d(TAG, "New password " + password);
            return true;
        }
    });
    Preference prefNetwork = (Preference) findPreference("pref_net");
    prefNetwork.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.d(TAG, "Your preferred network has been changed to: " + newValue);
            return true;
        }
    });
    // Add a listener for our clear button, with a confirmation
    Preference clearMessages = (Preference) findPreference("clear_messages");
    clearMessages.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            // show a confirmation dialog
            new AlertDialog.Builder(SettingsActivity.this).setTitle("WARNING").setMessage("This will remove all messages, including ones not yet sent to the server or mobile phones.\n\nThis operation cannot be undone.").setPositiveButton("Reset", new OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    AndroidRelay.clearMessages(SettingsActivity.this);
                    Toast.makeText(SettingsActivity.this, "Messages cleared", Toast.LENGTH_LONG).show();
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
            return true;
        }
    });
    Preference sendLog = (Preference) findPreference("send_log");
    sendLog.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference preference) {
            RelayService.doSendLog = true;
            WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(1), getApplicationContext());
            Toast.makeText(SettingsActivity.this, "Log will be sent shortly.", Toast.LENGTH_LONG).show();
            return true;
        }
    });
    Preference updateInterval = (Preference) findPreference("update_interval");
    updateInterval.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            WakefulIntentService.scheduleAlarms(new com.nyaruka.androidrelay.AlarmListener(Long.parseLong(newValue.toString())), SettingsActivity.this);
            Log.d(TAG, "Rescheduling alarms based on new update_interval value: " + newValue);
            return true;
        }
    });
    Preference setRapidHost = (Preference) findPreference("router_hostname");
    setRapidHost.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String hostname = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String backend = prefs.getString("router_backend", "android");
            String password = prefs.getString("router_password", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
    Preference setRapidBackend = (Preference) findPreference("router_backend");
    setRapidBackend.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String backend = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String hostname = prefs.getString("router_hostname", null);
            String password = prefs.getString("router_password", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
    Preference setRapidPassword = (Preference) findPreference("router_password");
    setRapidPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String password = newValue.toString();
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
            String backend = prefs.getString("router_backend", "android");
            String hostname = prefs.getString("router_hostname", null);
            updateEndpoints(hostname, backend, password);
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference) DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) OnClickListener(android.content.DialogInterface.OnClickListener) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View)

Example 22 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project mobile-android by photo.

the class BordersPanel method showUpdateAlert.

private void showUpdateAlert(final CharSequence packageName, final PluginError error, boolean fromUseClick) {
    if (error != PluginError.NoError) {
        String errorString;
        if (fromUseClick)
            errorString = getError(error);
        else
            errorString = getErrors(error);
        if (error == PluginError.PluginTooOldError) {
            OnClickListener yesListener = new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    downloadPlugin((String) packageName);
                }
            };
            onGenericError(errorString, R.string.feather_update, yesListener, android.R.string.cancel, null);
        } else if (error == PluginError.PluginTooNewError) {
            OnClickListener yesListener = new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String pname = getContext().getBaseContext().getPackageName();
                    downloadPlugin(pname);
                }
            };
            onGenericError(errorString, R.string.feather_update, yesListener, android.R.string.cancel, null);
        } else {
            onGenericError(errorString);
        }
        return;
    }
}
Also used : DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) Point(android.graphics.Point)

Example 23 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project mobile-android by photo.

the class BordersPanel method showUpdateAlertMultiplePlugins.

/**
	 * Create a popup alert dialog when multiple plugins need to be updated
	 * 
	 * @param error
	 */
private void showUpdateAlertMultiplePlugins(final PluginError error, boolean fromUserClick) {
    if (error != PluginError.NoError) {
        final String errorString = getErrors(error);
        if (error == PluginError.PluginTooOldError) {
            OnClickListener yesListener = new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    searchPlugin();
                }
            };
            onGenericError(errorString, R.string.feather_update, yesListener, android.R.string.cancel, null);
        } else if (error == PluginError.PluginTooNewError) {
            OnClickListener yesListener = new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String pname = getContext().getBaseContext().getPackageName();
                    downloadPlugin(pname);
                }
            };
            onGenericError(errorString, R.string.feather_update, yesListener, android.R.string.cancel, null);
        } else {
            onGenericError(errorString);
        }
    }
}
Also used : DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) Point(android.graphics.Point)

Example 24 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project mobile-android by photo.

the class StickersPanel method onStickersPackListUpdated.

/**
	 * The PluginInstallTask is completed
	 * 
	 * @param result
	 */
private void onStickersPackListUpdated(List<StickerEffectPack> result) {
    mLogger.info("onStickersPackListUpdated: " + result.size());
    if (mExternalPacksEnabled) {
        StickerPacksAdapter adapter = new StickerPacksAdapter(getContext().getBaseContext(), R.layout.feather_sticker_pack2, R.layout.feather_sticker_pack2_external, R.layout.feather_stickers_pack_divider_empty, R.layout.feather_getmore_stickers_thumb, R.layout.feather_getmore_stickers_thumb_inverted, result);
        mListPacks.setAdapter(adapter);
        if (mViewFlipper.getDisplayedChild() != 1) {
            mViewFlipper.setDisplayedChild(1);
        }
        showIapPopup();
        if (mInstalledPackages.size() < 1 && mExternalPacksEnabled) {
            if (!mPreferenceService.containsValue(this.getClass().getSimpleName() + "-install-first-time")) {
                OnClickListener listener = new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        getContext().downloadPlugin(PluginService.FREE_STICKERS_PACKAGENAME, FeatherIntent.PluginType.TYPE_STICKER);
                        dialog.dismiss();
                    }
                };
                AlertDialog dialog = new AlertDialog.Builder(getContext().getBaseContext()).setMessage(R.string.feather_stickers_dialog_first_time).setPositiveButton(android.R.string.ok, listener).setNegativeButton(android.R.string.cancel, null).create();
                mPreferenceService.putBoolean(this.getClass().getSimpleName() + "-install-first-time", true);
                dialog.show();
            }
        }
    } else {
        if (result.size() > 0) {
            mPlugin = (InternalPlugin) result.get(0).mPluginRef;
            mStatus.setStatus(STATUS_STICKERS);
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 25 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project mobile-android by photo.

the class BordersPanel method onEffectListUpdated.

/**
	 * Called after the {@link PluginInstallTask} completed
	 * 
	 * @param result
	 *           - list of installed packs
	 * @param mErrors
	 *           - list of errors
	 */
private void onEffectListUpdated(List<EffectPack> result, List<EffectPackError> mErrors, int totalCount) {
    // we had errors during installation
    if (null != mErrors && mErrors.size() > 0) {
        if (!mUpdateErrorHandled) {
            handleErrors(mErrors);
        }
    }
    FIRST_POSITION = (mExternalPacksEnabled && mShowFirstGetMore) ? 1 : 0;
    FramesListAdapter adapter = createListAdapter(getContext().getBaseContext(), result);
    mHList.setAdapter(adapter);
    if (mViewFlipper.getDisplayedChild() != 1) {
        mViewFlipper.setDisplayedChild(1);
    }
    if (mSelectedPosition != FIRST_POSITION) {
        mHList.setSelectedPosition(FIRST_POSITION, false);
        if (mFirstTimeRenderer) {
            onItemSelected(mHList, null, FIRST_POSITION, -1);
        }
        mFirstTimeRenderer = true;
    }
    showIapPopup();
    // show the alert only the first time!!
    if (totalCount < 1 && mExternalPacksEnabled && mPluginType == FeatherIntent.PluginType.TYPE_BORDER) {
        if (!mPreferenceService.containsValue(this.getClass().getSimpleName() + "-install-first-time")) {
            OnClickListener listener = new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    getContext().downloadPlugin(PluginService.FREE_BORDERS_PACKAGENAME, FeatherIntent.PluginType.TYPE_BORDER);
                    dialog.dismiss();
                }
            };
            AlertDialog dialog = new AlertDialog.Builder(getContext().getBaseContext()).setMessage(R.string.feather_borders_dialog_first_time).setPositiveButton(android.R.string.ok, listener).setNegativeButton(android.R.string.cancel, null).create();
            mPreferenceService.putBoolean(this.getClass().getSimpleName() + "-install-first-time", true);
            dialog.show();
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener)

Aggregations

DialogInterface (android.content.DialogInterface)179 OnClickListener (android.content.DialogInterface.OnClickListener)179 AlertDialog (android.app.AlertDialog)118 View (android.view.View)45 SuppressLint (android.annotation.SuppressLint)36 TextView (android.widget.TextView)36 Intent (android.content.Intent)34 Context (android.content.Context)24 EditText (android.widget.EditText)22 Bundle (android.os.Bundle)21 LayoutInflater (android.view.LayoutInflater)16 Builder (android.app.AlertDialog.Builder)15 Paint (android.graphics.Paint)14 OnCancelListener (android.content.DialogInterface.OnCancelListener)12 KeyEvent (android.view.KeyEvent)12 Point (android.graphics.Point)11 AlertDialog (android.support.v7.app.AlertDialog)11 ContextThemeWrapper (android.view.ContextThemeWrapper)11 CompoundButton (android.widget.CompoundButton)11 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)11