List of usage examples for android.widget Spinner Spinner
public Spinner(Context context)
From source file:website.openeng.anki.multimediacard.activity.TranslationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { boolean b = savedInstanceState.getBoolean(BUNDLE_KEY_SHUT_OFF, false); if (b) {/*w w w. j a v a2 s . co m*/ finishCancel(); return; } } setContentView(R.layout.activity_translation); try { mSource = getIntent().getExtras().getString(EXTRA_SOURCE).toString(); } catch (Exception e) { mSource = ""; } // If translation fails this is a default - source will be returned. mTranslation = mSource; LinearLayout linearLayout = (LinearLayout) findViewById(R.id.MainLayoutInTranslationActivity); TextView tv = new TextView(this); tv.setText(getText(R.string.multimedia_editor_trans_poweredglosbe)); linearLayout.addView(tv); TextView tvFrom = new TextView(this); tvFrom.setText(getText(R.string.multimedia_editor_trans_from)); linearLayout.addView(tvFrom); mLanguageLister = new LanguagesListerGlosbe(this); mSpinnerFrom = new Spinner(this); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mLanguageLister.getLanguages()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerFrom.setAdapter(adapter); linearLayout.addView(mSpinnerFrom); TextView tvTo = new TextView(this); tvTo.setText(getText(R.string.multimedia_editor_trans_to)); linearLayout.addView(tvTo); mSpinnerTo = new Spinner(this); ArrayAdapter<String> adapterTo = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mLanguageLister.getLanguages()); adapterTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinnerTo.setAdapter(adapterTo); linearLayout.addView(mSpinnerTo); final SharedPreferences preferences = KanjiDroidApp.getSharedPrefs(getBaseContext()); // Try to set spinner value to last selected position String fromLang = preferences.getString("translatorLastLanguageFrom", ""); String toLang = preferences.getString("translatorLastLanguageTo", ""); mSpinnerFrom.setSelection(getSpinnerIndex(mSpinnerFrom, fromLang)); mSpinnerTo.setSelection(getSpinnerIndex(mSpinnerTo, toLang)); // Setup button Button btnDone = new Button(this); btnDone.setText(getText(R.string.multimedia_editor_trans_translate)); btnDone.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Remember currently selected language String fromLang = mSpinnerFrom.getSelectedItem().toString(); String toLang = mSpinnerTo.getSelectedItem().toString(); preferences.edit().putString("translatorLastLanguageFrom", fromLang).commit(); preferences.edit().putString("translatorLastLanguageTo", toLang).commit(); // Get translation translate(); } }); linearLayout.addView(btnDone); }
From source file:com.nextgis.mobile.map.RemoteTMSLayer.java
protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, String layerUrl, int type, final RemoteTMSLayer layer) { final LinearLayout linearLayout = new LinearLayout(map.getContext()); final EditText input = new EditText(map.getContext()); input.setText(layerName);/*from w w w . j ava2 s . c o m*/ final EditText url = new EditText(map.getContext()); url.setText(layerUrl); final TextView stLayerName = new TextView(map.getContext()); stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":"); final TextView stLayerUrl = new TextView(map.getContext()); stLayerUrl.setText(map.getContext().getString(R.string.layer_url) + ":"); final TextView stLayerType = new TextView(map.getContext()); stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":"); final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(), android.R.layout.simple_spinner_item); final Spinner spinner = new Spinner(map.getContext()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); adapter.add(map.getContext().getString(R.string.tmstype_osm)); adapter.add(map.getContext().getString(R.string.tmstype_normal)); adapter.add(map.getContext().getString(R.string.tmstype_ngw)); if (type == TMSTYPE_OSM) { spinner.setSelection(0); } else { spinner.setSelection(1); } linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(stLayerName); linearLayout.addView(input); linearLayout.addView(stLayerUrl); linearLayout.addView(url); linearLayout.addView(stLayerType); linearLayout.addView(spinner); new AlertDialog.Builder(map.getContext()) .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties) // .setMessage(message) .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int tmsType = 0; switch (spinner.getSelectedItemPosition()) { case 0: case 1: tmsType = TMSTYPE_OSM; break; case 2: case 3: tmsType = TMSTYPE_NORMAL; break; } if (bCreate) { create(map, input.getText().toString(), url.getText().toString(), tmsType); } else { layer.setName(input.getText().toString()); layer.setTMSType(tmsType); map.onLayerChanged(layer); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show(); } }).show(); }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override// w ww. jav a2s . c o m public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beacon.expectedStability != null && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beacon.status = Beacon.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beacon.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i(TAG, "bi.id: " + beaconInstance.id + ", bi.googleType: " + beaconInstance.googleType); View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override//from w ww . j av a 2 s. c om public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beaconInstance.expectedStability != null && !beaconInstance.expectedStability.equals(BeaconInstance.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beaconInstance.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beaconInstance.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beaconInstance.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beaconInstance.status = BeaconInstance.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beaconInstance.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:com.nextgis.mobile.map.LocalTMSLayer.java
protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, int type, final Uri uri, final LocalTMSLayer layer) { final LinearLayout linearLayout = new LinearLayout(map.getContext()); final EditText input = new EditText(map.getContext()); input.setText(layerName);// w w w . j av a 2 s. c o m final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(), android.R.layout.simple_spinner_item); final Spinner spinner = new Spinner(map.getContext()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); adapter.add(map.getContext().getString(R.string.tmstype_qtiles)); adapter.add(map.getContext().getString(R.string.tmstype_osm)); adapter.add(map.getContext().getString(R.string.tmstype_normal)); adapter.add(map.getContext().getString(R.string.tmstype_ngw)); if (type == TMSTYPE_OSM) { spinner.setSelection(1); } else { spinner.setSelection(2); } final TextView stLayerName = new TextView(map.getContext()); stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":"); final TextView stLayerType = new TextView(map.getContext()); stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":"); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(stLayerName); linearLayout.addView(input); linearLayout.addView(stLayerType); linearLayout.addView(spinner); new AlertDialog.Builder(map.getContext()) .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties) // .setMessage(message) .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int tmsType = 0; switch (spinner.getSelectedItemPosition()) { case 0: case 1: tmsType = TMSTYPE_OSM; break; case 2: case 3: tmsType = TMSTYPE_NORMAL; break; } if (bCreate) { create(map, input.getText().toString(), tmsType, uri); } else { layer.setName(input.getText().toString()); layer.setTMSType(tmsType); map.onLayerChanged(layer); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show(); } }).show(); }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private void populateSecondForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title))); EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY); passwordEditText.setTransformationMethod(new PasswordTransformationMethod()); formLayout.addView(passwordEditText); formLayout.addView(createErrorView(PASSWORD_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);//from www .j a v a 2 s .c o m params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array, android.R.layout.simple_spinner_item); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt)); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(GENDER_KEY, adapter.getItem(pos).toString()); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); if (mFormData.get(GENDER_KEY) != null) { spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY))); } formLayout.addView(spinner); }
From source file:odoo.controls.OSelectionField.java
@Override public void initControl() { final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); removeAllViews();//ww w. j a v a 2 s .c om setOrientation(VERTICAL); createItems(); if (isEditable()) { if (mWidget != null) { switch (mWidget) { case RadioGroup: createRadioGroup(); return; case SelectionDialog: txvView = new TextView(mContext); txvView.setLayoutParams(params); mAdapter = new SpinnerAdapter(mContext, android.R.layout.simple_list_item_1, items); setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog = createSelectionDialog(getPos(), items, params); txvView.setTag(dialog); dialog.show(); } }); if (textSize > -1) { txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (appearance > -1) { txvView.setTextAppearance(mContext, appearance); } txvView.setTextColor(textColor); addView(txvView); return; case Searchable: case SearchableLive: txvView = new TextView(mContext); txvView.setLayoutParams(params); setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startSearchableActivity(); } }); if (textSize > -1) { txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (appearance > -1) { txvView.setTextAppearance(mContext, appearance); } txvView.setTextColor(textColor); addView(txvView); return; default: break; } } // Default View mSpinner = new Spinner(mContext); mSpinner.setLayoutParams(params); mAdapter = new SpinnerAdapter(mContext, android.R.layout.simple_list_item_1, items); mSpinner.setAdapter(mAdapter); mSpinner.setOnItemSelectedListener(this); addView(mSpinner); } else { setOnClickListener(null); txvView = new TextView(mContext); if (textSize > -1) { txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (appearance > -1) { txvView.setTextAppearance(mContext, appearance); } txvView.setTextColor(textColor); addView(txvView); } }
From source file:com.emobc.android.activities.generators.FormActivityGenerator.java
private View insertPickerField(Activity activity, FormDataItem dataItem) { Spinner spinner = new Spinner(activity); ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, dataItem.getParameters());//from w w w . j av a 2 s. c om spinner.setAdapter(adapter); return spinner; }
From source file:edu.cmu.cylab.starslinger.view.SaveActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_Safeslinger); super.onCreate(savedInstanceState); if (savedInstanceState == null) { mListTopOffset = 0;//from w ww . j a va 2 s . c o m mListVisiblePos = 0; } final ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); bar.setTitle(R.string.app_name); bar.setSubtitle(R.string.title_save); setContentView(R.layout.savedata); mListViewSaveContacts = (ListView) findViewById(R.id.SaveScrollViewMembers); mButtonSave = (Button) findViewById(R.id.SaveButtonSave); // init mContacts = new ArrayList<ContactStruct>(); Bundle extras = getIntent().getExtras(); if (extras != null) { byte[] data = null; int length = extras.size(); mMemData = new byte[length][]; int i = 0; do { data = extras.getByteArray(ExchangeConfig.extra.MEMBER_DATA + i); if (data != null) { mMemData[i] = data; i++; } } while (data != null); } // display names list so users can selectively choose which to save if (mMemData != null) { mContacts = parseVCards(mMemData); SaveContactAdapter adapter = new SaveContactAdapter(SaveActivity.this, mContacts); mListViewSaveContacts.setAdapter(adapter); // restore list position mListViewSaveContacts.setSelectionFromTop(mListVisiblePos, mListTopOffset); } mButtonSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SaveSelectedContactsTask saveSelected = new SaveSelectedContactsTask(); saveSelected.execute(new String()); } }); mListViewSaveContacts.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // nothing to do... } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // save list position if (visibleItemCount != 0) { mListVisiblePos = firstVisibleItem; View v = mListViewSaveContacts.getChildAt(0); mListTopOffset = (v == null) ? 0 : v.getTop(); } } }); mUnsyncName = getString(R.string.label_None); mUnsyncType = getString(R.string.label_phoneOnly); mPrefsSelected = false; mTableLayoutSpin = (TableLayout) findViewById(R.id.accountLayout); TextView textView = new TextView(this); mAccountSpinner = new Spinner(this); textView.setText(R.string.label_SaveAccount); textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mAccountSpinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); mTableLayoutSpin.addView(textView); mTableLayoutSpin.addView(mAccountSpinner); // Prepare model for account spinner mAccounts = new ArrayList<AccountData>(); mAccountAdapter = new AccountAdapter(this, this, mAccounts); mAccountSpinner.setAdapter(mAccountAdapter); // Load account preference if any mPrefAccountName = SafeSlingerPrefs.getAccountName(); mPrefAccountType = SafeSlingerPrefs.getAccountType(); // Prepare the system account manager. On registering the listener // below, we also ask for // an initial callback to pre-populate the account list. AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); // Register handlers for UI elements mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long i) { updateAccountSelection(); } @Override public void onNothingSelected(AdapterView<?> parent) { // We don't need to worry about nothing being selected, since // Spinners don't allow // this. } }); }
From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.OrgProfile.java
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); Intent i = this.getIntent(); Bundle b = i.getExtras();/*w ww . ja v a 2 s . c om*/ __keys = new CipherSuit[3]; __keys[KEY_IDX_ECDSA_BIG] = newCipherSuit(Cipher.ECDSA, Cipher.SHA384, ECDSA.P_521); __keys[KEY_IDX_ECDSA] = newCipherSuit(Cipher.ECDSA, Cipher.SHA1, ECDSA.P_256); __keys[KEY_IDX_RSA] = newCipherSuit(Cipher.RSA, Cipher.SHA512, 1024); // top panel setting organization_position = b.getInt(Orgs.O_ID); organization_LID = b.getString(Orgs.O_LID); organization_GIDH = b.getString(Orgs.O_GIDH); oLID = Util.lval(organization_LID, -1); if (oLID <= 0) return; this.org = D_Organization.getOrgByLID(oLID, true, false); if (org == null) return; try { Identity crt_identity = Identity.getCurrentConstituentIdentity(); if (crt_identity == null) { Log.d(TAG, "No identity"); } else constituent_LID = net.ddp2p.common.config.Identity.getDefaultConstituentIDForOrg(oLID); } catch (P2PDDSQLException e1) { e1.printStackTrace(); } if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, false); Log.d(TAG, "Got const: " + constituent); } setContentView(R.layout.org_profile); forename = (EditText) findViewById(R.id.profile_furname); surname = (EditText) findViewById(R.id.profile_surname); neiborhood = (Button) findViewById(R.id.profile_neiborhood); submit = (Button) findViewById(R.id.submit_profile); submit_new = (Button) findViewById(R.id.submit_profile_new); if (constituent == null) submit.setVisibility(Button.GONE); else submit.setVisibility(Button.VISIBLE); keys = (Spinner) findViewById(R.id.profile_keys); hasRightToVote = (CheckedTextView) findViewById(R.id.profile_hasRightToVote); email = (EditText) findViewById(R.id.profile_email); slogan = (EditText) findViewById(R.id.profile_slogan); slogan.setActivated(false); profilePic = (TextView) findViewById(R.id.profile_picture); profilePicImg = (ImageView) findViewById(R.id.profile_picture_img); // eligibility = (Spinner) findViewById(R.id.profile_eligibility); if (constituent != null) { forename.setText(constituent.getForename()); surname.setText(constituent.getSurname()); hasRightToVote.setChecked(Util.ival(constituent.getWeight(), 0) > 0); email.setText(constituent.getEmail()); slogan.setText(constituent.getSlogan()); } custom_fields = (LinearLayout) findViewById(R.id.profile_view); custom_index = 8; // custom_fields = (LinearLayout) findViewById(R.id.profile_custom); // custom_index = 0; custom_params = org.params.orgParam; if (custom_params == null || custom_params.length == 0) { custom_params = new D_OrgParam[0];// 3 /* * custom_params[0] = new D_OrgParam(); custom_params[0].label = * "School"; custom_params[0].entry_size = 5; custom_params[1] = new * D_OrgParam(); custom_params[1].label = "Street"; custom_params[2] * = new D_OrgParam(); custom_params[2].label = "Year"; * custom_params[2].list_of_values = new * String[]{"2010","2011","2012"}; */ } D_FieldValue[] field_values = null; if (constituent != null && constituent.address != null) field_values = constituent.address; for (int crt_field = 0; crt_field < custom_params.length; crt_field++) { D_OrgParam field = custom_params[crt_field]; LinearLayout custom_entry = new LinearLayout(this); custom_entry.setOrientation(LinearLayout.HORIZONTAL); custom_entry.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); TextView custom_label = new TextView(this); custom_label.setText(field.label); custom_entry.addView(custom_label); if (field.list_of_values != null && field.list_of_values.length > 0) { Log.d(TAG, "spinner:" + field); Spinner custom_spin = new Spinner(this); ArrayAdapter<String> custom_spin_Adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, field.list_of_values); custom_spin_Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); custom_spin.setAdapter(custom_spin_Adapter); custom_entry.addView(custom_spin); D_FieldValue fv = locateFV(field_values, field); if (fv != null) { int position = 0; for (int k = 0; k <= field.list_of_values.length; k++) { if (Util.equalStrings_null_or_not(field.list_of_values[k], fv.value)) { position = k; break; } } custom_spin.setSelection(position); } } else { Log.d(TAG, "edit: " + field); EditText edit_text = new EditText(this); edit_text.setText(field.default_value); edit_text.setInputType(InputType.TYPE_CLASS_TEXT); if (field.entry_size > 0) edit_text.setMinimumWidth(field.entry_size * 60); Log.d(TAG, "edit: size=" + field.entry_size); custom_entry.addView(edit_text); // Button child = new Button(this); // child.setText("Test"); D_FieldValue fv = locateFV(field_values, field); if (fv != null) edit_text.setText(fv.value); } custom_fields.addView(custom_entry, custom_index++); } ArrayAdapter<String> keysAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); keysAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); keys.setAdapter(keysAdapter); keys.setOnItemSelectedListener(new KeysListener()); if (constituent != null) { SK sk = constituent.getSK(); if (sk != null) { Cipher cipher = Cipher.getCipher(sk, null); if (cipher instanceof net.ddp2p.ciphersuits.RSA) { keys.setSelection(KEY_IDX_RSA, true); } if (cipher instanceof net.ddp2p.ciphersuits.ECDSA) { ECDSA ecdsa = (ECDSA) cipher; CipherSuit e = ECDSA.getCipherSuite(ecdsa.getPK()); if (e.hash_alg == Cipher.SHA1) { keys.setSelection(KEY_IDX_ECDSA, true); } else { keys.setSelection(KEY_IDX_ECDSA_BIG, true); } } } } ArrayAdapter<String> eligibilityAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, m); eligibilityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // eligibility.setAdapter(eligibilityAdapter); // eligibility.setOnItemSelectedListener(new EligibilityListener()); hasRightToVote.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hasRightToVote.setChecked(!hasRightToVote.isChecked()); } }); setProfilePhoto = (ImageView) findViewById(R.id.org_profile_set_profile_photo); /*TODO this part only make the whole stuff slow if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } */ /* boolean gotIcon = false; if (constituent != null) { if (constituent.getPicture() != null) { byte[] icon = constituent.getPicture(); Bitmap bmp = BitmapFactory.decodeByteArray(icon, 0, icon.length - 1); setProfilePhoto.setImageBitmap(bmp); gotIcon = true; } if (!gotIcon) { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } } else { int imgPath = R.drawable.constitutent_person_icon; Bitmap bmp = BitmapFactory.decodeResource(getResources(), imgPath); setProfilePhoto.setImageBitmap(bmp); } setProfilePhoto.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT < 19) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, SELECT_PROFILE_PHOTO); } else { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("image/*"); startActivityForResult(intent, SELECT_PPROFILE_PHOTO_KITKAT); } } });*/ submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; if (constituent == null) { D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved new constituent=" + new_const); constituent = new_const; } else { constituent = D_Constituent.getConstByConst_Keep(constituent); constituent.setEmail(_email); constituent.setForename(_forename); constituent.setSurname(_surname); constituent.setWeight(rightToVote); constituent.setSlogan(_slogan); constituent.setExternal(false); constituent.setCreationDate(); constituent.sign(); if (constituent.dirty_any()) constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent=" + constituent); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(constituent.getLID(), oLID); } catch (P2PDDSQLException e) { e.printStackTrace(); } Log.d(TAG, "saved constituent=" + constituent.getLID() + " oLID=" + oLID); } if (constituent != null) { constituent = D_Constituent.getConstByConst_Keep(constituent); if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); Log.d(TAG, "saved constituent Done"); finish(); } }); submit_new.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String _forename = forename.getText().toString(); String _surname = surname.getText().toString(); int _keys = OrgProfile._selectedKey; boolean rightToVote = hasRightToVote.isChecked(); String _weight = rightToVote ? "1" : "0"; String _email = email.getText().toString(); String _slogan = slogan.getText().toString(); boolean external = false; D_Constituent new_const = D_Constituent.createConstituent(_forename, _surname, _email, oLID, external, _weight, _slogan, OrgProfile.__keys[_keys].cipher, OrgProfile.__keys[_keys].hash_alg, OrgProfile.__keys[_keys].ciphersize, null, null); Log.d(TAG, "saved constituent=" + new_const.getNameFull()); try { // Identity.DEBUG = true; Identity.setCurrentConstituentForOrg(new_const.getLID(), oLID); Log.d("CONST", "No Set: oLID=" + oLID + " c=" + new_const.getLID()); } catch (P2PDDSQLException e) { e.printStackTrace(); } constituent = new_const; constituent_LID = new_const.getLID(); if (constituent_LID > 0) { constituent = D_Constituent.getConstByLID(constituent_LID, true, true); Log.d(TAG, "Got const: " + constituent); } if (constituent != null) { if (constituent.getSK() != null) { constituent.setPicture(byteIcon); constituent.setCreationDate(); constituent.sign(); constituent.storeRequest(); constituent.releaseReference(); Log.d(TAG, "saved constituent pic: " + constituent.getPicture()); } } if (!org.getBroadcasted()) { D_Organization _org = D_Organization.getOrgByOrg_Keep(org); if (_org != null) { _org.setBroadcasting(true); if (_org.dirty_any()) _org.storeRequest(); _org.releaseReference(); org = _org; } } Log.d(TAG, "saved constituent=" + new_const); finish(); } }); }