List of usage examples for android.os Bundle getByteArray
@Override @Nullable public byte[] getByteArray(@Nullable String key)
From source file:com.nextgis.mobile.fragment.MapFragment.java
@Override public void onViewStateRestored(@Nullable Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); if (null == savedInstanceState) { mMode = MODE_NORMAL;/* w w w . j a v a2 s . c om*/ } else { mMode = savedInstanceState.getInt(KEY_MODE); int layerId = savedInstanceState.getInt(BUNDLE_KEY_LAYER); ILayer layer = mMap.getLayerById(layerId); Feature feature = null; if (null != layer && layer instanceof VectorLayer) { mSelectedLayer = (VectorLayer) layer; if (savedInstanceState.containsKey(BUNDLE_KEY_SAVED_FEATURE)) { GeoGeometry geometry = null; try { geometry = GeoGeometryFactory .fromBlob(savedInstanceState.getByteArray(BUNDLE_KEY_SAVED_FEATURE)); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } feature = new Feature(); feature.setId(savedInstanceState.getLong(BUNDLE_KEY_FEATURE_ID)); feature.setGeometry(geometry); } } mEditLayerOverlay.setSelectedLayer(mSelectedLayer); mEditLayerOverlay.setSelectedFeature(feature); } if (WalkEditService.isServiceRunning(getContext())) { SharedPreferences preferences = getContext().getSharedPreferences(WalkEditService.TEMP_PREFERENCES, Constants.MODE_MULTI_PROCESS); int layerId = preferences.getInt(ConstantsUI.KEY_LAYER_ID, NOT_FOUND); long featureId = preferences.getLong(ConstantsUI.KEY_FEATURE_ID, NOT_FOUND); ILayer layer = mMap.getMap().getLayerById(layerId); if (layer != null && layer instanceof VectorLayer) { mSelectedLayer = (VectorLayer) layer; mEditLayerOverlay.setSelectedLayer(mSelectedLayer); if (featureId > NOT_FOUND) mEditLayerOverlay.setSelectedFeature(featureId); else mEditLayerOverlay.newGeometryByWalk(); GeoGeometry geometry = GeoGeometryFactory.fromWKT( preferences.getString(ConstantsUI.KEY_GEOMETRY, ""), GeoConstants.CRS_WEB_MERCATOR); if (geometry != null) mEditLayerOverlay.setGeometryFromWalkEdit(geometry); mMode = MODE_EDIT_BY_WALK; } } setMode(mMode); if (savedInstanceState != null && savedInstanceState.getBoolean(BUNDLE_KEY_IS_MEASURING, false)) startMeasuring(); }
From source file:org.jnrain.mobile.accounts.kbs.KBSRegisterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.kbs_register); mHandler = new Handler() { @Override//from ww w . jav a 2s . co m public void handleMessage(Message msg) { loadingDlg = DialogHelper.showProgressDialog(KBSRegisterActivity.this, R.string.check_updates_dlg_title, R.string.please_wait, false, false); } }; lastUIDCheckTime = 0; initValidationMapping(); // instance state if (savedInstanceState != null) { /* * editNewUID.onRestoreInstanceState(savedInstanceState * .getParcelable("newUID")); * editNewEmail.onRestoreInstanceState(savedInstanceState * .getParcelable("newEmail")); * editNewPassword.onRestoreInstanceState(savedInstanceState * .getParcelable("newPass")); * editRetypeNewPassword.onRestoreInstanceState * (savedInstanceState .getParcelable("repeatPass")); * editNewNickname.onRestoreInstanceState(savedInstanceState * .getParcelable("newNickname")); * editStudID.onRestoreInstanceState(savedInstanceState * .getParcelable("studID")); * editRealName.onRestoreInstanceState(savedInstanceState * .getParcelable("realname")); * editPhone.onRestoreInstanceState(savedInstanceState * .getParcelable("phone")); * editCaptcha.onRestoreInstanceState(savedInstanceState * .getParcelable("captcha")); */ // captcha image byte[] captchaPNG = savedInstanceState.getByteArray("captchaImage"); ByteArrayInputStream captchaStream = new ByteArrayInputStream(captchaPNG); try { Drawable captchaDrawable = BitmapDrawable.createFromStream(captchaStream, "src"); imageRegCaptcha.setImageDrawable(captchaDrawable); } finally { try { captchaStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // event handlers // UID editNewUID.addTextChangedListener(new StrippedDownTextWatcher() { long lastCheckTime = 0; String lastUID; @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // FIXME: use monotonic clock... long curtime = System.currentTimeMillis(); if (curtime - lastCheckTime >= KBSUIConstants.REG_CHECK_UID_INTERVAL_MILLIS) { String uid = s.toString(); // don't check at the first char if (uid.length() > 1) { checkUIDAvailability(uid, curtime); } lastCheckTime = curtime; lastUID = uid; // schedule a new delayed check if (delayedUIDChecker != null) { delayedUIDChecker.cancel(); delayedUIDChecker.purge(); } delayedUIDChecker = new Timer(); delayedUIDChecker.schedule(new TimerTask() { @Override public void run() { final String uid = getUID(); if (uid != lastUID) { runOnUiThread(new Runnable() { @Override public void run() { checkUIDAvailability(uid, System.currentTimeMillis()); } }); lastUID = uid; } } }, KBSUIConstants.REG_CHECK_UID_INTERVAL_MILLIS); } } }); editNewUID.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { // lost focus, force check uid availability checkUIDAvailability(getUID(), System.currentTimeMillis()); } else { // inputting, temporarily clear that notice updateUIDAvailability(false, 0); } } }); // E-mail editNewEmail.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editNewEmail, false, true, R.string.reg_email_empty); return; } if (!EMAIL_CHECKER.matcher(s).matches()) { updateValidation(editNewEmail, false, true, R.string.reg_email_malformed); return; } updateValidation(editNewEmail, true, true, R.string.ok_short); } }); // Password editNewPassword.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editNewPassword, false, true, R.string.reg_psw_empty); return; } if (s.length() < 6) { updateValidation(editNewPassword, false, true, R.string.reg_psw_too_short); return; } if (s.length() > 39) { updateValidation(editNewPassword, false, true, R.string.reg_psw_too_long); return; } if (getUID().equalsIgnoreCase(s.toString())) { updateValidation(editNewPassword, false, true, 0); } updateValidation(editNewPassword, true, true, R.string.ok_short); updateRetypedPasswordCorrectness(); } }); // Retype password editRetypeNewPassword.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateRetypedPasswordCorrectness(); } }); // Nickname editNewNickname.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editNewNickname, false, true, R.string.reg_nick_empty); return; } updateValidation(editNewNickname, true, true, R.string.ok_short); } }); // Student ID editStudID.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editStudID, false, true, R.string.reg_stud_id_empty); return; } if (!IDENT_CHECKER.matcher(s).matches()) { updateValidation(editStudID, false, true, R.string.reg_stud_id_malformed); return; } updateValidation(editStudID, true, true, R.string.ok_short); } }); // Real name editRealName.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editRealName, false, true, R.string.reg_realname_empty); return; } updateValidation(editRealName, true, true, R.string.ok_short); } }); // Phone editPhone.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editPhone, false, true, R.string.reg_phone_empty); return; } if (!TextUtils.isDigitsOnly(s)) { updateValidation(editPhone, false, true, R.string.reg_phone_onlynumbers); return; } updateValidation(editPhone, true, true, R.string.ok_short); } }); // Captcha editCaptcha.addTextChangedListener(new StrippedDownTextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (TextUtils.isEmpty(s)) { updateValidation(editCaptcha, false, true, R.string.reg_captcha_empty); return; } updateValidation(editCaptcha, true, true, R.string.ok_short); } }); // Use current phone checkUseCurrentPhone.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { setUseCurrentPhone(isChecked); } }); // Is ethnic minority checkIsEthnicMinority.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { setEthnicMinority(isChecked); } }); // Submit form! btnSubmitRegister.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // progress dialog mHandler.sendMessage(new Message()); // prevent repeated requests setSubmitButtonEnabled(false); // fire our biiiiiig request! // TODO: ??23333 final String uid = getUID(); final String psw = editNewPassword.getText().toString(); makeSpiceRequest( new KBSRegisterRequest(uid, psw, editNewNickname.getText().toString(), getRealName(), editStudID.getText().toString(), editNewEmail.getText().toString(), getPhone(), editCaptcha.getText().toString(), 2), new KBSRegisterRequestListener(KBSRegisterActivity.this, uid, psw)); } }); // interface init // UID availability updateUIDAvailability(false, 0); // HTML-formatted register disclaimer FormatHelper.setHtmlText(this, textRegisterDisclaimer, R.string.register_disclaimer); textRegisterDisclaimer.setMovementMethod(LinkMovementMethod.getInstance()); // is ethnic minority defaults to false checkIsEthnicMinority.setChecked(false); setEthnicMinority(false); // current phone number currentPhoneNumber = TelephonyHelper.getPhoneNumber(this); isCurrentPhoneNumberAvailable = currentPhoneNumber != null; if (isCurrentPhoneNumberAvailable) { // display the obtained number as hint FormatHelper.setHtmlText(this, checkUseCurrentPhone, R.string.field_use_current_phone, currentPhoneNumber); } else { // phone number unavailable, disable the choice checkUseCurrentPhone.setEnabled(false); checkUseCurrentPhone.setVisibility(View.GONE); } // default to use current phone number if available checkUseCurrentPhone.setChecked(isCurrentPhoneNumberAvailable); setUseCurrentPhone(isCurrentPhoneNumberAvailable); if (savedInstanceState == null) { // issue preflight request // load captcha in success callback this.makeSpiceRequest(new KBSRegisterRequest(), new KBSRegisterRequestListener(this)); } }
From source file:com.ijiaban.yinxiang.MainActivity.java
@SuppressLint("HandlerLeak") @Override/* www.j a v a 2 s. c om*/ protected void onCreate(Bundle savedInstanceState) { Log.w("MainActivity: onCreate()", "ONCREATE"); super.onCreate(savedInstanceState); ANIMAL = getResources().getString(R.string.Animal); CARTOON = getResources().getString(R.string.Cartoon); LOVE = getResources().getString(R.string.Love); MUSIC = getResources().getString(R.string.Music); SPORTS = getResources().getString(R.string.Sports); BUSINESS = getResources().getString(R.string.Business); CARS = getResources().getString(R.string.Cars); DISHES = getResources().getString(R.string.Dishes); LOCAL = getResources().getString(R.string.Local); setContentView(R.layout.activity_main); MobclickAgent.updateOnlineConfig(this); LinearLayout layout = (LinearLayout) findViewById(R.id.adlayoutmainfragment); mAdView = new AdView(this); mAdView.setAdUnitId(getResources().getString(R.string.ad_unit_id)); mAdView.setAdSize(AdSize.BANNER); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); layout.addView(mAdView, params); mAdView.loadAd(new AdRequest.Builder().build()); // mNameTextView = (TextView) findViewById(R.id.nameTextView); // mDescriptionTextView = (TextView) findViewById(R.id.descriptionTextView); mIconImageView = (ImageView) findViewById(R.id.iconImageView); tabs = (PagerSlidingTabStrip) findViewById(R.id.maintabs); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new CommonPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); pager.setPageMargin(pageMargin); tabs.setViewPager(pager); // Check whether we're recreating a previously destroyed instance if (savedInstanceState != null) { Log.d("MainActivity", "onRestoreInstanceState()"); // Always call the superclass so it can restore the view hierarchy super.onRestoreInstanceState(savedInstanceState); // Restore state members from saved instance byte[] imageBytes = savedInstanceState.getByteArray(STORED_IMAGE); if (imageBytes != null) { mGeneratedBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); } mContact = savedInstanceState.getParcelable(STORED_CONTACT); mHasPickedContact = savedInstanceState.getBoolean(STORED_PICKED); mScreenWidthInPixels = savedInstanceState.getInt(STORED_WIDTH); if (mHasPickedContact && mContact != null && mGeneratedBitmap != null) { Log.d("Restoring generated bitmap", mGeneratedBitmap.getHeight() + ""); Log.d("Restoring contact object", mContact.getFullName()); showContactData(); } } if (!mHasPickedContact) { Log.d("MainActivity: onCreate()", "No contact picked yet."); pickContact(); } }
From source file:com.android.calculator2.Calculator.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculator); setActionBar((Toolbar) findViewById(R.id.toolbar)); // Hide all default options in the ActionBar. getActionBar().setDisplayOptions(0); mDisplayView = findViewById(R.id.display); mModeView = (TextView) findViewById(R.id.mode); mFormulaText = (CalculatorText) findViewById(R.id.formula); mResultText = (CalculatorResult) findViewById(R.id.result); mPadViewPager = (ViewPager) findViewById(R.id.pad_pager); mDeleteButton = findViewById(R.id.del); mClearButton = findViewById(R.id.clr); mEqualButton = findViewById(R.id.pad_numeric).findViewById(R.id.eq); if (mEqualButton == null || mEqualButton.getVisibility() != View.VISIBLE) { mEqualButton = findViewById(R.id.pad_operator).findViewById(R.id.eq); }/*from ww w . j av a2 s . co m*/ mInverseToggle = (TextView) findViewById(R.id.toggle_inv); mModeToggle = (TextView) findViewById(R.id.toggle_mode); mInvertibleButtons = new View[] { findViewById(R.id.fun_sin), findViewById(R.id.fun_cos), findViewById(R.id.fun_tan), findViewById(R.id.fun_ln), findViewById(R.id.fun_log), findViewById(R.id.op_sqrt) }; mInverseButtons = new View[] { findViewById(R.id.fun_arcsin), findViewById(R.id.fun_arccos), findViewById(R.id.fun_arctan), findViewById(R.id.fun_exp), findViewById(R.id.fun_10pow), findViewById(R.id.op_sqr) }; mEvaluator = new Evaluator(this, mResultText); mResultText.setEvaluator(mEvaluator); KeyMaps.setActivity(this); if (savedInstanceState != null) { setState(CalculatorState.values()[savedInstanceState.getInt(KEY_DISPLAY_STATE, CalculatorState.INPUT.ordinal())]); CharSequence unprocessed = savedInstanceState.getCharSequence(KEY_UNPROCESSED_CHARS); if (unprocessed != null) { mUnprocessedChars = unprocessed.toString(); } byte[] state = savedInstanceState.getByteArray(KEY_EVAL_STATE); if (state != null) { try (ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(state))) { mEvaluator.restoreInstanceState(in); } catch (Throwable ignored) { // When in doubt, revert to clean state mCurrentState = CalculatorState.INPUT; mEvaluator.clear(); } } } else { mCurrentState = CalculatorState.INPUT; mEvaluator.clear(); } mFormulaText.setOnKeyListener(mFormulaOnKeyListener); mFormulaText.setOnTextSizeChangeListener(this); mFormulaText.setOnPasteListener(this); mDeleteButton.setOnLongClickListener(this); onInverseToggled(mInverseToggle.isSelected()); onModeChanged(mEvaluator.getDegreeMode()); if (mCurrentState != CalculatorState.INPUT) { // Just reevaluate. redisplayFormula(); setState(CalculatorState.INIT); mEvaluator.requireResult(); } else { redisplayAfterFormulaChange(); } // TODO: We're currently not saving and restoring scroll position. // We probably should. Details may require care to deal with: // - new display size // - slow recomputation if we've scrolled far. }
From source file:org.mozilla.gecko.GeckoApp.java
/** Called when the activity is first created. */ @Override//from w w w . ja va2 s . co m public void onCreate(Bundle savedInstanceState) { mAppContext = this; // StrictMode is set by defaults resource flag |enableStrictMode|. if (getResources().getBoolean(R.bool.enableStrictMode)) { enableStrictMode(); } System.loadLibrary("mozglue"); mMainHandler = new GeckoAppHandler(); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); if (savedInstanceState != null) { mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE); mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT); mLastScreen = savedInstanceState.getByteArray(SAVED_STATE_SCREEN); mRestoreSession = savedInstanceState.getBoolean(SAVED_STATE_SESSION); } super.onCreate(savedInstanceState); mOrientation = getResources().getConfiguration().orientation; setContentView(R.layout.gecko_app); if (Build.VERSION.SDK_INT >= 11) { mBrowserToolbar = (BrowserToolbar) GeckoActionBar.getCustomView(this); } else { mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar); } // setup gecko layout mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout); mMainLayout = (LinearLayout) findViewById(R.id.main_layout); mConnectivityFilter = new IntentFilter(); mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mConnectivityReceiver = new GeckoConnectivityReceiver(); }
From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java
private AlertDialog.Builder xshowIntroductionInvite(final Activity act, final Bundle args) { String exchName = args.getString(extra.EXCH_NAME); final String introName = args.getString(extra.INTRO_NAME); final byte[] introPhoto = args.getByteArray(extra.PHOTO); final byte[] introPush = args.getByteArray(extra.PUSH_REGISTRATION_ID); final byte[] introPubKey = args.getByteArray(extra.INTRO_PUBKEY); final long msgRowId = args.getLong(extra.MESSAGE_ROW_ID); AlertDialog.Builder ad = new AlertDialog.Builder(act); View layout;// www .j a va 2s .c o m if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { layout = View.inflate(new ContextThemeWrapper(act, R.style.Theme_AppCompat), R.layout.secureinvite, null); } else { LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layout = inflater.inflate(R.layout.secureinvite, null); } TextView textViewExchName = (TextView) layout.findViewById(R.id.textViewExchName); TextView textViewIntroName = (TextView) layout.findViewById(R.id.textViewIntroName); ImageView imageViewIntroPhoto = (ImageView) layout.findViewById(R.id.imageViewIntroPhoto); ad.setTitle(R.string.title_SecureIntroductionInvite); textViewExchName.setText(exchName); textViewIntroName.setText(introName); if (introPhoto != null) { try { Bitmap bm = BitmapFactory.decodeByteArray(introPhoto, 0, introPhoto.length, null); imageViewIntroPhoto.setImageBitmap(bm); } catch (OutOfMemoryError e) { imageViewIntroPhoto.setImageDrawable(getResources().getDrawable(R.drawable.ic_silhouette)); } } ad.setView(layout); ad.setCancelable(false); ad.setPositiveButton(getString(R.string.btn_Accept), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); // accept secure introduction? int selected = 0; args.putString(extra.NAME + selected, introName); args.putByteArray(extra.PHOTO + selected, introPhoto); args.putByteArray(SafeSlingerConfig.APP_KEY_PUBKEY + selected, introPubKey); args.putByteArray(SafeSlingerConfig.APP_KEY_PUSHTOKEN + selected, introPush); String contactLookupKey = getContactLookupKeyByName(introName); args.putString(extra.CONTACT_LOOKUP_KEY + selected, contactLookupKey); MessageRow inviteMsg = null; MessageDbAdapter dbMessage = MessageDbAdapter.openInstance(getApplicationContext()); Cursor c = dbMessage.fetchMessageSmall(msgRowId); if (c != null) { try { if (c.moveToFirst()) { inviteMsg = new MessageRow(c, false); } } finally { c.close(); } } if (inviteMsg == null) { showNote(R.string.error_InvalidIncomingMessage); return; } // import the new contacts args.putInt(extra.RECIP_SOURCE, RecipientDbAdapter.RECIP_SOURCE_INTRODUCTION); args.putString(extra.KEYID, inviteMsg.getKeyId()); ImportFromExchangeTask importFromExchange = new ImportFromExchangeTask(); importFromExchange.execute(args); setTab(Tabs.MESSAGE); refreshView(); } }); ad.setNegativeButton(getString(R.string.btn_Refuse), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); showNote(String.format(getString(R.string.state_SomeContactsImported), 0)); refreshView(); } }); return ad; }
From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java
protected AlertDialog.Builder xshowChangeSenderOptions(final Activity act, Bundle args) { final ArrayList<UseContactItem> items = new ArrayList<UseContactItem>(); boolean isContactInUse = args.getBoolean(extra.CREATED); final String pName = args.getString(extra.NAME); byte[] pPhoto = args.getByteArray(extra.PHOTO); String pLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY); if (!TextUtils.isEmpty(pName)) { items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseProfilePerson), pName), pPhoto, pLookupKey, UCType.PROFILE)); }//w ww . j a v a 2 s. com int i = 0; String cName = args.getString(extra.NAME + i); byte[] cPhoto = args.getByteArray(extra.PHOTO + i); String cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i); while (!TextUtils.isEmpty(cName)) { items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseContactPerson), cName), cPhoto, cLookupKey, UCType.CONTACT)); i++; cName = args.getString(extra.NAME + i); cPhoto = args.getByteArray(extra.PHOTO + i); cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i); } items.add(new UseContactItem(act.getString(R.string.menu_UseNoContact), UCType.NONE)); items.add(new UseContactItem(act.getString(R.string.menu_UseAnother), UCType.ANOTHER)); items.add(new UseContactItem(act.getString(R.string.menu_CreateNew), UCType.NEW)); items.add(new UseContactItem(act.getString(R.string.menu_EditName), UCType.EDIT_NAME)); if (isContactInUse) { items.add(new UseContactItem(act.getString(R.string.menu_EditContact), UCType.EDIT_CONTACT)); } AlertDialog.Builder ad = new AlertDialog.Builder(act); ad.setTitle(R.string.title_MyIdentity); ad.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); } }); ListAdapter adapter = new ArrayAdapter<UseContactItem>(act, android.R.layout.select_dialog_item, android.R.id.text1, items) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); UseContactItem item = items.get(position); if (item.contact) { Drawable d; if (item.icon != null) { Bitmap bm = BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length, null); d = new BitmapDrawable(getResources(), bm); } else { d = getResources().getDrawable(R.drawable.ic_silhouette); } int avatar_size_list = (int) getResources().getDimension(R.dimen.avatar_size_list); d.setBounds(0, 0, avatar_size_list, avatar_size_list); tv.setCompoundDrawables(null, null, d, null); tv.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.size_5dp)); } else { tv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } return v; } }; ad.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); switch (items.get(item).type) { case PROFILE: // user wants to use found profile as a personal contact // save these for lookup and display purposes SafeSlingerPrefs.setContactName(pName); SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey); refreshView(); break; case CONTACT: // user wants to use found contact as a personal contact SafeSlingerPrefs.setContactName(getContactName(items.get(item).contactLookupKey)); SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey); refreshView(); break; case ANOTHER: // user wants to choose new contact for themselves showPickContact(RESULT_PICK_CONTACT_SENDER); break; case NONE: // user wants to remove link to address book SafeSlingerPrefs.setContactLookupKey(null); refreshView(); break; case NEW: // user wants to create new contact showAddContact(SafeSlingerPrefs.getContactName()); break; case EDIT_CONTACT: // user wants to edit contact showEditContact(RESULT_PICK_CONTACT_SENDER); break; case EDIT_NAME: // user wants to edit name showSettings(); refreshView(); break; } } }); return ad; }
From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java
public void sendAutomaticMessage(Bundle args, int recipSource) { long groupSentTime = System.currentTimeMillis(); CryptoMsgProvider p = CryptoMsgProvider.createInstance(SafeSlinger.isLoggable()); byte[] keyBytes = null; List<String> keyStr = new ArrayList<String>(); String keyId = null;/*from w ww . j av a 2 s. c o m*/ RecipientRow recip = null; int exchanged = 0; do { keyBytes = args.getByteArray(SafeSlingerConfig.APP_KEY_PUBKEY + exchanged); if (keyBytes != null) { keyStr.add(new String(keyBytes)); exchanged++; } } while (keyBytes != null); List<MessageTransport> verifyMsgs = new ArrayList<MessageTransport>(); for (int i = 0; i < keyStr.size(); i++) { String keyString = keyStr.get(i); if (!TextUtils.isEmpty(keyString)) { try { keyId = p.ExtractKeyIDfromSafeSlingerString(keyString); } catch (CryptoMsgPeerKeyFormatException e) { e.printStackTrace(); } } if (!TextUtils.isEmpty(keyId) && recipSource == RecipientDbAdapter.RECIP_SOURCE_EXCHANGE) { RecipientDbAdapter dbRecipient = RecipientDbAdapter.openInstance(getApplicationContext()); Cursor cr = dbRecipient.fetchRecipientByKeyId(keyId); if (cr != null) { try { if (cr.moveToFirst()) { recip = new RecipientRow(cr); } } finally { cr.close(); } } } if (recip == null) { // attempt to send other messages and continue continue; } MessageData sendMsg = new MessageData(); // set sent time closest to UI command sendMsg.setDateSent(groupSentTime); String message = String.format(getString(R.string.label_messageYouAreVerified), recip.getName()); sendMsg.setText(message); // user wants to post the file and notify recipient if (recip.getNotify() == SafeSlingerConfig.NOTIFY_NOPUSH) { // attempt to send other messages and continue continue; } // automatic, do not keep sling keys tab drafts verifyMsgs.add(new MessageTransport(recip, sendMsg, false)); } doSendMessageStart(verifyMsgs.toArray(new MessageTransport[verifyMsgs.size()])); }
From source file:org.mdc.chess.MDChess.java
/** * Called when the activity is first created. *//*from w w w . j a v a 2s .c om*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Pair<String, String> pair = getPgnOrFenIntent(); String intentPgnOrFen = pair.first; String intentFilename = pair.second; createDirectories(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settings = PreferenceManager.getDefaultSharedPreferences(this); setWakeLock(false); figNotation = Typeface.createFromAsset(getAssets(), "fonts/KlinicSlabBold.otf"); setPieceNames(PGNOptions.PT_LOCAL); initUI(); gameTextListener = new PgnScreenText(pgnOptions); moveList.setOnLinkClickListener(gameTextListener); moveList.setBackgroundColor(Color.WHITE); if (ctrl != null) { ctrl.shutdownEngine(); } ctrl = new MDChessController(this, gameTextListener, pgnOptions); egtbForceReload = true; readPrefs(); TimeControlData tcData = new TimeControlData(); tcData.setTimeControl(timeControl, movesPerSession, timeIncrement); ctrl.newGame(gameMode, tcData); setAutoMode(AutoMode.OFF); { byte[] data = null; int version = 1; if (savedInstanceState != null) { data = savedInstanceState.getByteArray("gameState"); version = savedInstanceState.getInt("gameStateVersion", version); } else { String dataStr = settings.getString("gameState", null); version = settings.getInt("gameStateVersion", version); if (dataStr != null) { data = strToByteArr(dataStr); } } if (data != null) { ctrl.fromByteArray(data, version); } } ctrl.setGuiPaused(true); ctrl.setGuiPaused(false); ctrl.startGame(); if (intentPgnOrFen != null) { try { ctrl.setFENOrPGN(intentPgnOrFen); setBoardFlip(true); } catch (ChessParseError e) { // If FEN corresponds to illegal chess position, go into edit board mode. try { TextIO.readFEN(intentPgnOrFen); } catch (ChessParseError e2) { if (e2.pos != null) { startEditBoard(intentPgnOrFen); } } } } else if (intentFilename != null) { if (intentFilename.toLowerCase(Locale.US).endsWith(".fen") || intentFilename.toLowerCase(Locale.US).endsWith(".epd")) { loadFENFromFile(intentFilename); } else { loadPGNFromFile(intentFilename); } } }
From source file:org.petero.droidfish.DroidFish.java
/** Called when the activity is first created. */ @Override/*from w w w. ja v a 2s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Pair<String, String> pair = getPgnOrFenIntent(); String intentPgnOrFen = pair.first; String intentFilename = pair.second; createDirectories(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { handlePrefsChange(); } }); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); setWakeLock(false); wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "droidfish"); wakeLock.setReferenceCounted(false); custom1ButtonActions = new ButtonActions("custom1", CUSTOM1_BUTTON_DIALOG, R.string.select_action); custom2ButtonActions = new ButtonActions("custom2", CUSTOM2_BUTTON_DIALOG, R.string.select_action); custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG, R.string.select_action); figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf"); setPieceNames(PGNOptions.PT_LOCAL); requestWindowFeature(Window.FEATURE_NO_TITLE); initUI(); gameTextListener = new PgnScreenText(this, pgnOptions); if (ctrl != null) ctrl.shutdownEngine(); ctrl = new DroidChessController(this, gameTextListener, pgnOptions); egtbForceReload = true; readPrefs(); TimeControlData tcData = new TimeControlData(); tcData.setTimeControl(timeControl, movesPerSession, timeIncrement); ctrl.newGame(gameMode, tcData); setAutoMode(AutoMode.OFF); { byte[] data = null; int version = 1; if (savedInstanceState != null) { data = savedInstanceState.getByteArray("gameState"); version = savedInstanceState.getInt("gameStateVersion", version); } else { String dataStr = settings.getString("gameState", null); version = settings.getInt("gameStateVersion", version); if (dataStr != null) data = strToByteArr(dataStr); } if (data != null) ctrl.fromByteArray(data, version); } ctrl.setGuiPaused(true); ctrl.setGuiPaused(false); ctrl.startGame(); if (intentPgnOrFen != null) { try { ctrl.setFENOrPGN(intentPgnOrFen); setBoardFlip(true); } catch (ChessParseError e) { // If FEN corresponds to illegal chess position, go into edit board mode. try { TextIO.readFEN(intentPgnOrFen); } catch (ChessParseError e2) { if (e2.pos != null) startEditBoard(intentPgnOrFen); } } } else if (intentFilename != null) { if (intentFilename.toLowerCase(Locale.US).endsWith(".fen") || intentFilename.toLowerCase(Locale.US).endsWith(".epd")) loadFENFromFile(intentFilename); else loadPGNFromFile(intentFilename); } }