use of android.widget.CheckBox in project android_frameworks_base by crdroidandroid.
the class MediaProjectionPermissionActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mPackageName = getCallingPackage();
IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
mService = IMediaProjectionManager.Stub.asInterface(b);
if (mPackageName == null) {
finish();
return;
}
PackageManager packageManager = getPackageManager();
ApplicationInfo aInfo;
try {
aInfo = packageManager.getApplicationInfo(mPackageName, 0);
mUid = aInfo.uid;
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "unable to look up package name", e);
finish();
return;
}
try {
if (mService.hasProjectionPermission(mUid, mPackageName)) {
setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName, false));
finish();
return;
}
} catch (RemoteException e) {
Log.e(TAG, "Error checking projection permissions", e);
finish();
return;
}
TextPaint paint = new TextPaint();
paint.setTextSize(42);
String label = aInfo.loadLabel(packageManager).toString();
// If the label contains new line characters it may push the security
// message below the fold of the dialog. Labels shouldn't have new line
// characters anyways, so just truncate the message the first time one
// is seen.
final int labelLength = label.length();
int offset = 0;
while (offset < labelLength) {
final int codePoint = label.codePointAt(offset);
final int type = Character.getType(codePoint);
if (type == Character.LINE_SEPARATOR || type == Character.CONTROL || type == Character.PARAGRAPH_SEPARATOR) {
label = label.substring(0, offset) + ELLIPSIS;
break;
}
offset += Character.charCount(codePoint);
}
if (label.isEmpty()) {
label = mPackageName;
}
String unsanitizedAppName = TextUtils.ellipsize(label, paint, MAX_APP_NAME_SIZE_PX, TextUtils.TruncateAt.END).toString();
String appName = BidiFormatter.getInstance().unicodeWrap(unsanitizedAppName);
String actionText = getString(R.string.media_projection_dialog_text, appName);
SpannableString message = new SpannableString(actionText);
int appNameIndex = actionText.indexOf(appName);
if (appNameIndex >= 0) {
message.setSpan(new StyleSpan(Typeface.BOLD), appNameIndex, appNameIndex + appName.length(), 0);
}
mDialog = new AlertDialog.Builder(this).setIcon(aInfo.loadIcon(packageManager)).setMessage(message).setPositiveButton(R.string.media_projection_action_text, this).setNegativeButton(android.R.string.cancel, this).setView(R.layout.remember_permission_checkbox).setOnCancelListener(this).create();
mDialog.create();
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setFilterTouchesWhenObscured(true);
((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this);
mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
mDialog.show();
}
use of android.widget.CheckBox in project LiveLessons by douglascraigschmidt.
the class CalculatorGUIVerbose method unCheckAll.
/** Resets the GUI. */
public void unCheckAll() {
checkRadioGroup(rg1, false);
checkRadioGroup(rg2, false);
checkRadioGroup(rg3, false);
CheckBox cb = (CheckBox) findViewById(R.id.cb);
cb.setChecked(false);
}
use of android.widget.CheckBox in project LiveLessons by douglascraigschmidt.
the class CalculatorGUIVerbose method enableCheckbox.
/** Enables/Disables the Check Box */
private void enableCheckbox(boolean enable) {
CheckBox cb = (CheckBox) findViewById(R.id.cb);
cb.setEnabled(enable);
}
use of android.widget.CheckBox in project LiveLessons by douglascraigschmidt.
the class AndroidPlatform method buttonToggled.
/**
* Retrieves textual input of the toggled button determined by the
* user.
*/
private String buttonToggled() {
Log.e("AndroidPlatform", "buttonToggled");
/** Checks the format radio group for checked buttons. */
RadioGroup rg = (RadioGroup) activity.findViewById(R.id.rad1);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
return ("format" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
/** Checks the print radio group for checked buttons. */
rg = (RadioGroup) activity.findViewById(R.id.rad2);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled()) {
((TextView) activity.findViewById(R.id.tv)).setText("");
return ("print" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
}
/** Checks the eval radio group for checked buttons. */
rg = (RadioGroup) activity.findViewById(R.id.rad3);
for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
return ("eval" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
/** Checks the set checkbox. */
CheckBox cb = (CheckBox) activity.findViewById(R.id.cb);
if (cb.isChecked() && cb.isEnabled())
return ("set" + (String) ((TextView) cb).getText()).toLowerCase();
return "expr";
}
use of android.widget.CheckBox in project double-espresso by JakeWharton.
the class ViewMatchersTest method testCheckBoxMatchers.
public void testCheckBoxMatchers() {
assertFalse(isChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
assertFalse(isNotChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
CheckBox checkBox = new CheckBox(getInstrumentation().getTargetContext());
checkBox.setChecked(true);
assertTrue(isChecked().matches(checkBox));
assertFalse(isNotChecked().matches(checkBox));
checkBox.setChecked(false);
assertFalse(isChecked().matches(checkBox));
assertTrue(isNotChecked().matches(checkBox));
RadioButton radioButton = new RadioButton(getInstrumentation().getTargetContext());
radioButton.setChecked(false);
assertFalse(isChecked().matches(radioButton));
assertTrue(isNotChecked().matches(radioButton));
radioButton.setChecked(true);
assertTrue(isChecked().matches(radioButton));
assertFalse(isNotChecked().matches(radioButton));
CheckedTextView checkedText = new CheckedTextView(getInstrumentation().getTargetContext());
checkedText.setChecked(false);
assertFalse(isChecked().matches(checkedText));
assertTrue(isNotChecked().matches(checkedText));
checkedText.setChecked(true);
assertTrue(isChecked().matches(checkedText));
assertFalse(isNotChecked().matches(checkedText));
Checkable checkable = new Checkable() {
@Override
public boolean isChecked() {
return true;
}
@Override
public void setChecked(boolean ignored) {
}
@Override
public void toggle() {
}
};
assertFalse(isChecked().matches(checkable));
assertFalse(isNotChecked().matches(checkable));
}
Aggregations