use of android.content.DialogInterface.OnCancelListener in project android_frameworks_base by crdroidandroid.
the class InputMethodManagerService method showInputMethodMenu.
private void showInputMethodMenu(boolean showAuxSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
final Context context = mContext;
final boolean isScreenLocked = isScreenLocked();
final String lastInputMethodId = mSettings.getSelectedInputMethod();
int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
if (DEBUG)
Slog.v(TAG, "Current IME: " + lastInputMethodId);
synchronized (mMethodMap) {
final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
}
}
final int N = imList.size();
mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N];
int checkedItem = 0;
for (int i = 0; i < N; ++i) {
final ImeSubtypeListItem item = imList.get(i);
mIms[i] = item.mImi;
mSubtypeIds[i] = item.mSubtypeId;
if (mIms[i].getId().equals(lastInputMethodId)) {
int subtypeId = mSubtypeIds[i];
if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
checkedItem = i;
}
}
}
final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
mDialogBuilder = new AlertDialog.Builder(settingsContext);
mDialogBuilder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
});
final Context dialogContext = mDialogBuilder.getContext();
final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
a.recycle();
mDialogBuilder.setIcon(dialogIcon);
final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mSettings.setShowImeWithHardKeyboard(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
final OnClickListener choiceListener = new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
final InputMethodInfo im = mIms[which];
int subtypeId = mSubtypeIds[which];
adapter.mCheckedItem = which;
adapter.notifyDataSetChanged();
hideInputMethodMenu();
if (im != null) {
if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
subtypeId = NOT_A_SUBTYPE_ID;
}
setInputMethodLocked(im.getId(), subtypeId);
}
}
}
};
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
mSwitchingDialog.show();
}
}
use of android.content.DialogInterface.OnCancelListener in project LiveLessons by douglascraigschmidt.
the class MainActivity method onStart.
/** onStart. */
public void onStart() {
super.onStart();
/** Alert dialog. */
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
dialog.setTitle("Options");
/** Set back pressed. */
dialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
finish();
}
});
/** Formats the succinct button. */
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Succinct", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/**
* Sets an intent for launching the
* succinct activity.
*/
Intent intent = new Intent(getApplicationContext(), CalculatorGUISuccinct.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
});
/** Formats the verbose button. */
dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Verbose", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/**
* Sets an intent for launching the
* verbose activity.
*/
Intent intent = new Intent(getApplicationContext(), CalculatorGUIVerbose.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
});
/** Displays dialog to screen. */
dialog.show();
}
use of android.content.DialogInterface.OnCancelListener in project collect by opendatakit.
the class GeoTraceOsmMapActivity method buildDialogs.
private void buildDialogs() {
builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.select_geotrace_mode));
builder.setView(null);
builder.setView(traceSettingsView).setPositiveButton(getString(R.string.start), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
startGeoTrace();
dialog.cancel();
alert.dismiss();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
alert.dismiss();
reset_trace_settings();
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
reset_trace_settings();
}
});
alert = builder.create();
polylineAlertBuilder = new AlertDialog.Builder(this);
polylineAlertBuilder.setTitle(getString(R.string.polyline_polygon_text));
polylineAlertBuilder.setView(polygonPolylineView).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.cancel();
alert.dismiss();
}
});
alertDialog = polylineAlertBuilder.create();
}
use of android.content.DialogInterface.OnCancelListener in project MDM-Android-Agent by wso2-attic.
the class EntryActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);
checkNotNull(CommonUtilities.SERVER_URL, "SERVER_URL");
checkNotNull(CommonUtilities.SENDER_ID, "SENDER_ID");
if (CommonUtilities.DEBUG_MODE_ENABLED) {
Log.e("SENDER ID : ", CommonUtilities.SENDER_ID);
}
info = new DeviceInfo(EntryActivity.this);
context = EntryActivity.this;
if ((info.getSdkVersion() >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) && !info.isRooted()) {
accessFlag = true;
} else {
accessFlag = false;
}
if (!(info.getSdkVersion() > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) && info.isRooted()) {
error = getString(R.string.device_not_compatible_error);
} else if (info.getSdkVersion() > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
error = getString(R.string.device_not_compatible_error_os);
} else if (info.isRooted()) {
error = getString(R.string.device_not_compatible_error_root);
}
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);
// mDisplay = (TextView) findViewById(R.id.display);
registerReceiver(mHandleMessageReceiver, new IntentFilter(CommonUtilities.DISPLAY_MESSAGE_ACTION));
// ImageView optionBtn = (ImageView) findViewById(R.id.option_button);
errorMessage = (TextView) findViewById(R.id.textView1);
errorMessage.setText(error);
if (!accessFlag) {
errorMessage.setVisibility(View.VISIBLE);
showAlert(error, getResources().getString(R.string.error_authorization_failed));
}
/*optionBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Entry.this,DisplayDeviceInfo.class);
intent.putExtra("from_activity_name", Entry.class.getSimpleName());
startActivity(intent);
}
});*/
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
regId = extras.getString(getResources().getString(R.string.intent_extra_regid));
}
}
if (regId == null || regId.equals("")) {
regId = GCMRegistrar.getRegistrationId(this);
}
SharedPreferences mainPref = context.getSharedPreferences(getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);
String success = mainPref.getString(getResources().getString(R.string.shared_pref_registered), "");
if (success.trim().equals(getResources().getString(R.string.shared_pref_reg_success))) {
state = true;
}
if (accessFlag) {
if (state) {
Intent intent = new Intent(EntryActivity.this, AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), regId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
if (CommonUtilities.DEBUG_MODE_ENABLED) {
Log.v("REGIDDDDD", regId);
}
if (regId.equals("") || regId == null) {
GCMRegistrar.register(context, CommonUtilities.SENDER_ID);
} else {
if (GCMRegistrar.isRegisteredOnServer(this)) {
if (CommonUtilities.DEBUG_MODE_ENABLED) {
Log.v("Check GCM is Registered Func", "RegisteredOnServer");
}
// mDisplay.append(getString(R.string.already_registered) + "\n");
} else {
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
// boolean registered = ServerUtilities.register(context, regId);
boolean registered = true;
if (!registered) {
GCMRegistrar.unregister(context);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (CommonUtilities.DEBUG_MODE_ENABLED) {
Log.v("REG IDDDD", regId);
}
mRegisterTask = null;
}
};
if (accessFlag) {
mRegisterTask.execute(null, null, null);
} else {
// Toast.makeText(getApplicationContext(), getString(R.string.device_not_compatible_error), Toast.LENGTH_LONG).show();
}
}
}
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
state = ServerUtilities.isRegistered(regId, context);
} catch (Exception e) {
e.printStackTrace();
// HandleNetworkError(e);
// Toast.makeText(getApplicationContext(), "No Connection", Toast.LENGTH_LONG).show();
}
return null;
}
// declare other objects as per your need
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(EntryActivity.this, getResources().getString(R.string.dialog_checking_reg), getResources().getString(R.string.dialog_please_wait), true);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(cancelListener);
// do initialization of required objects objects here
}
OnCancelListener cancelListener = new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
showAlert(getResources().getString(R.string.error_connect_to_server), getResources().getString(R.string.error_heading_connection));
}
};
@Override
protected void onPostExecute(Void result) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
SharedPreferences mainPref = context.getSharedPreferences(getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);
String success = mainPref.getString(getResources().getString(R.string.shared_pref_registered), "");
if (success.trim().equals(getResources().getString(R.string.shared_pref_reg_success))) {
state = true;
}
if (accessFlag) {
if (state) {
Intent intent = new Intent(EntryActivity.this, AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), regId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
// finish();
} else {
mLicenseTask = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
// boolean registered = ServerUtilities.register(context, regId);
String response = "";
try {
response = ServerUtilities.getEULA(context, "");
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result) {
if (CommonUtilities.DEBUG_MODE_ENABLED) {
Log.v("REG IDDDD", regId);
}
if (result != null) {
SharedPreferences mainPref = EntryActivity.this.getSharedPreferences(getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);
Editor editor = mainPref.edit();
editor.putString(getResources().getString(R.string.shared_pref_eula), result);
editor.commit();
}
mLicenseTask = null;
}
};
// mLicenseTask.execute();
Intent intent = new Intent(EntryActivity.this, AuthenticationActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), regId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
// finish();
}
}
mRegisterTask = null;
}
};
if (accessFlag) {
if (state) {
Intent intent = new Intent(EntryActivity.this, AlreadyRegisteredActivity.class);
intent.putExtra(getResources().getString(R.string.intent_extra_regid), regId);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
mRegisterTask.execute(null, null, null);
}
} else {
showAlert(getResources().getString(R.string.device_not_compatible_error), getResources().getString(R.string.error_authorization_failed));
}
}
use of android.content.DialogInterface.OnCancelListener in project MDM-Android-Agent by wso2-attic.
the class EntryActivity method onResume.
@Override
protected void onResume() {
// TODO Auto-generated method stub
mRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
state = ServerUtilities.isRegistered(regId, context);
} catch (Exception e) {
e.printStackTrace();
// HandleNetworkError(e);
// Toast.makeText(getApplicationContext(), "No Connection", Toast.LENGTH_LONG).show();
}
return null;
}
// declare other objects as per your need
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(EntryActivity.this, "Checking Registration Info", "Please wait", true);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(cancelListener);
// do initialization of required objects objects here
}
OnCancelListener cancelListener = new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
showAlert("Could not connect to server please check your internet connection and try again", "Connection Error");
// finish();
}
};
@Override
protected void onPostExecute(Void result) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
SharedPreferences mainPref = context.getSharedPreferences(getResources().getString(R.string.shared_pref_package), Context.MODE_PRIVATE);
String success = mainPref.getString(getResources().getString(R.string.shared_pref_registered), "");
if (success.trim().equals(getResources().getString(R.string.shared_pref_reg_success))) {
state = true;
}
mRegisterTask = null;
}
};
if (accessFlag) {
mRegisterTask.execute(null, null, null);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} else {
// Toast.makeText(getApplicationContext(), getString(R.string.device_not_compatible_error), Toast.LENGTH_LONG).show();
}
super.onResume();
}
Aggregations