@Override public boolean onOptionsItemSelected(MenuItem item) { // ViewPager viewPager = (ViewPager) super.findViewById(R.id.pager); switch (item.getItemId()) { case R.id.menu_search: // viewPager.setCurrentItem(PAGE_FIND, true); navigationDrawerFragment.selectItem(PAGE_FIND); break; case R.id.menu_settings: // viewPager.setCurrentItem(PAGE_SETTINGS, true); navigationDrawerFragment.selectItem(PAGE_SETTINGS); break; case R.id.menu_edit_user: navigationDrawerFragment.selectItem(PAGE_MYCONTACT); /*Intent edit_intent = new Intent(); edit_intent.setClass(this, EditMyContactActivity.class); startActivity(edit_intent);*/ break; case R.id.menu_about: Intent about_intent = new Intent(); about_intent.setClass(this, AboutActivity.class); startActivity(about_intent); break; case R.id.menu_share: Functions.share(this); break; case R.id.menu_logout: logout(); break; } return super.onOptionsItemSelected(item); }
public void showDataInMyContact(View myContactView) { if (myContactView == null) return; // lade Daten in UI try { SQLiteConnection db_conn = new SQLiteConnection(this); String[] user_res = db_conn.getUser(); if (user_res != null) { TextView tv_name = (TextView) myContactView.findViewById(R.id.mycontact_tv_name); TextView tv_frontname = (TextView) myContactView.findViewById(R.id.mycontact_tv_frontname); ImageView iv_pic = (ImageView) myContactView.findViewById(R.id.mycontact_iv_picture); tv_name.setText(user_res[2]); tv_frontname.setText(user_res[3]); if (!(user_res[6] == null || user_res[6].equals("") || user_res[6].equals("null"))) { byte[] imageAsBytes = Base64.decode(user_res[6].getBytes(), Base64.DEFAULT); Bitmap bmPic = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length); int x = Functions.dpsToPx(this, 64); bmPic = Functions.scaleCenterCrop(bmPic, x, x); iv_pic.setImageBitmap(bmPic); } } LinearLayout ll_telephone = (LinearLayout) myContactView.findViewById(R.id.mycontact_ll_data_telephone); LinearLayout ll_email = (LinearLayout) myContactView.findViewById(R.id.mycontact_ll_data_email); LinearLayout ll_other = (LinearLayout) myContactView.findViewById(R.id.mycontact_ll_data_other); // jetzigen Inhalt l�schen ll_telephone.removeAllViews(); ll_email.removeAllViews(); ll_other.removeAllViews(); Cursor mycontact_data = db_conn.query( "SELECT entrynames_id,value FROM " + SQLiteConnection.TABLE_USER_DATA + " ORDER BY entrynames_id"); for (int i = 0; i < mycontact_data.getCount(); i++) { mycontact_data.moveToPosition(i); String name = array_en_name[Functions.indexOf(array_en_id, mycontact_data.getInt(0))]; String type = array_en_type[Functions.indexOf(array_en_id, mycontact_data.getInt(0))]; String value = mycontact_data.getString(1); String[] splitedValue = value.split("\\|"); createNewContactObject(type, myContactView); LinearLayout container; if (type.equals("number")) { container = ll_telephone; } else if (type.equals("email")) { container = ll_email; } else { container = ll_other; } LinearLayout child = (LinearLayout) container.getChildAt(container.getChildCount() - 1); Spinner spinner = (Spinner) child.getChildAt(1); String items[] = new String[spinner.getAdapter().getCount()]; for (int a = 0; a < spinner.getAdapter().getCount(); a++) { items[a] = ((String) spinner.getItemAtPosition(a)).toLowerCase(new Locale("en")); } if (splitedValue.length >= 2) { String[] newItems = new String[items.length + 1]; System.arraycopy(items, 0, newItems, 0, items.length); newItems[newItems.length - 1] = splitedValue[0]; MySpinnerArrayAdapter adapter = new MySpinnerArrayAdapter( this, newItems, ((MySpinnerArrayAdapter) spinner.getAdapter()).getLargeScreen()); spinner.setAdapter(adapter); spinner.setSelection(newItems.length - 1); ((EditText) child.getChildAt(0)).setText(splitedValue[1]); } else { spinner.setSelection(Functions.indexOf(items, name.toLowerCase(new Locale("en")))); ((EditText) child.getChildAt(0)).setText(value); } } mycontact_data.close(); db_conn.close(); myContactIsLoaded = true; } catch (Exception e) { e.printStackTrace(); } }
public boolean saveDataFromMyContact() { // speichere Daten von der UI try { SQLiteConnection db_conn = new SQLiteConnection(this); String[][] ui_data = getMyContactObjects(); if ((!myContactIsLoaded) || (ui_data == null)) { db_conn.close(); return false; } Cursor data = db_conn.query("SELECT entrynames_id,value FROM " + SQLiteConnection.TABLE_USER_DATA); String[][] data_edit = new String[data.getCount()][]; for (int i = 0; i < data.getCount(); i++) { data.moveToPosition(i); data_edit[i] = new String[] {String.valueOf(data.getInt(0)), data.getString(1)}; } if (!Functions.equalsArray(ui_data, data_edit)) { // Mein Kontakt in lokale db schreiben db_conn.executeQuery("DELETE FROM " + SQLiteConnection.TABLE_USER_DATA); for (int i = 0; i < ui_data.length; i++) { String[] str_tmp = ui_data[i]; ContentValues values = new ContentValues(); values.put("id", i); values.put("entrynames_id", Integer.parseInt(str_tmp[0])); values.put("value", str_tmp[1]); db_conn.insert(SQLiteConnection.TABLE_USER_DATA, values); } db_conn.executeQuery( "UPDATE " + SQLiteConnection.TABLE_USER + " SET change_date=CURRENT_TIMESTAMP"); String checksums = db_conn.getChecksums(); db_conn.setChecksums( checksums.replace(checksums.substring(32, 64), "00000000000000000000000000000000")); try { if (thread_sync != null) thread_sync.interrupt(); } finally { } thread_sync = new Thread( new Runnable() { public void run() { new UserFunctions(getApplicationContext()).sync(); } }); thread_sync.start(); } data.close(); db_conn.close(); } catch (Exception ex) { ex.printStackTrace(); return false; } return true; }
private void createNewContactObject(String type, View my_contact_view) { if (my_contact_view == null) { my_contact_view = fragment_mycontact.getView(); } if (my_contact_view == null) return; LinearLayout ll_data; List<String> list = new ArrayList<String>(); int it = android.text.InputType.TYPE_CLASS_TEXT; int hint = 0; // Typen setzen: List<Integer> list_number = new ArrayList<Integer>(); for (int i = 0; i < array_en_type.length; i++) { if (array_en_type[i].equals(type)) { list_number.add(i); } } for (int i = 0; i < list_number.size(); i++) { list.add((array_en_name[list_number.get(i)])); } final String[] spinnerArray = list.toArray(new String[list.size()]); // ----------- LinearLayout ll_telephone = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_telephone); LinearLayout ll_email = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_email); LinearLayout ll_other = (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_other); // new row LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); DisplayMetrics tmp_metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(tmp_metrics); int resolution_width = tmp_metrics.widthPixels; final boolean large_screen = (resolution_width >= 720); final EditText et = new EditText(this); LayoutParams lp_et; lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1); if (type.equals("number")) { ll_data = ll_telephone; it = InputType.TYPE_CLASS_PHONE; hint = R.string.telephone; } else if (type.equals("email")) { ll_data = ll_email; it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; hint = R.string.email; } else { ll_data = ll_other; if (type.equals("address")) { et.setMinLines(1); et.setMaxLines(3); et.setLines(2); hint = R.string.address; it = InputType.TYPE_CLASS_TEXT | InputType .TYPE_TEXT_FLAG_MULTI_LINE; // android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS; lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, large_screen ? 130 : 90, 1); row.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, (large_screen ? 130 : 90) + 20)); et.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); // et.setGravity(Gravity.LEFT | Gravity.TOP ); } else if (type.equals("website")) { hint = R.string.website; it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI; } } ((LinearLayout) ll_data.getParent()).setVisibility(LinearLayout.VISIBLE); et.setTextSize(large_screen ? 16 : 14); // EditText-Textgr��e et.setEms(10); et.setHint(hint); et.setInputType(it); lp_et.setMargins(0, 3, 0, 0); et.setLayoutParams(lp_et); Spinner spinner = new Spinner(this); LayoutParams lp_spinner = new LayoutParams( large_screen ? Functions.dpsToPx(this, 100) : Functions.dpsToPx(this, 80), /*300 : 200*/ LayoutParams.MATCH_PARENT); lp_spinner.setMargins(0, 3, 0, 0); MySpinnerArrayAdapter dataAdapter = new MySpinnerArrayAdapter(this, list, large_screen); dataAdapter.setDropDownViewResource( android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); spinner.setLayoutParams(lp_spinner); spinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected( final AdapterView<?> adapterView, final View view, int arg2, long arg3) { final Spinner spinner = (Spinner) adapterView; MySpinnerArrayAdapter adapter = (MySpinnerArrayAdapter) spinner.getAdapter(); if (adapter .getItem(arg2) .toLowerCase(new Locale("en")) .equals(getString(R.string.en_custom).toLowerCase(new Locale("en")))) { LinearLayout ll = new LinearLayout(MainActivity.this); final EditText et = new EditText(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(0, 20, 0, 0); et.setTextColor(Color.BLACK); et.requestFocus(); // et.setHint(R.string.place); ll.addView(et, layoutParams); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder .setView(ll) .setTitle(R.string.message_custom_en) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String[] newItems = new String[spinnerArray.length + 1]; System.arraycopy(spinnerArray, 0, newItems, 0, spinnerArray.length); newItems[newItems.length - 1] = et.getText().toString(); MySpinnerArrayAdapter adapter = new MySpinnerArrayAdapter( getApplicationContext(), newItems, ((MySpinnerArrayAdapter) spinner.getAdapter()).getLargeScreen()); spinner.setAdapter(adapter); spinner.setSelection(newItems.length - 1); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) {} }) .create() .show(); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); Button btn = new Button(this); btn.setText("x"); LayoutParams lp_btn = new LayoutParams(Functions.dpsToPx(this, 32), LayoutParams.WRAP_CONTENT); lp_btn.setMargins(-10, 0, -10, 0); btn.setLayoutParams(lp_btn); btn.setBackgroundColor(Color.TRANSPARENT); btn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (((LinearLayout) v.getParent().getParent()).getChildCount() == 1) { ((LinearLayout) v.getParent().getParent().getParent()).setVisibility(View.GONE); } ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent()); } }); row.addView(et); row.addView(spinner); row.addView(btn); row.setTag(type); ll_data.addView(row); }
private String[][] getMyContactObjects() { try { View view = fragment_mycontact.getView(); if (view == null) return null; List<String[]> list_objects = new ArrayList<String[]>(); LinearLayout ll; for (int i = 0; i < 3; i++) { if (i == 0) { ll = (LinearLayout) view.findViewById(R.id.mycontact_ll_data_telephone); } else if (i == 1) { ll = (LinearLayout) view.findViewById(R.id.mycontact_ll_data_email); } else { ll = (LinearLayout) view.findViewById(R.id.mycontact_ll_data_other); } for (int a = 0; a < ll.getChildCount(); a++) { LinearLayout object = (LinearLayout) ll.getChildAt(a); EditText object_et = (EditText) object.getChildAt(0); Spinner object_spinner = (Spinner) object.getChildAt(1); String tmp_object_values[] = new String[3]; tmp_object_values[0] = object.getTag().toString(); tmp_object_values[1] = object_spinner.getSelectedItem().toString(); tmp_object_values[2] = object_et.getText().toString(); /* * for (int c = 0; c < tmp_object_values.length; c++) { * tmp_object_values[c] = tmp_object_values[c].replace( "|", * ""); } */ if (tmp_object_values[2] != "") list_objects.add(tmp_object_values); } } String[][] res = new String[list_objects.size()][]; res = list_objects.toArray(res); String[][] ui_data_edit = new String[res.length][]; for (int i = 0; i < res.length; i++) { String[] str_tmp = res[i]; List<Integer> ids_names = new ArrayList<Integer>(); List<Integer> ids_types = new ArrayList<Integer>(); int tmpId = -1; boolean custom = !Functions.inArray(array_en_name, str_tmp[1]); for (int a = 0; a < array_en_id.length; a++) { if (array_en_type[a].equals(str_tmp[0])) { ids_types.add(a); } if ((array_en_name[a] .toLowerCase(new Locale("en")) .equals( (custom ? getString(R.string.en_custom) : str_tmp[1]) .toLowerCase(new Locale("en"))))) { ids_names.add(a); } } for (int a = 0; a < ids_types.size(); a++) { for (int b = 0; b < ids_names.size(); b++) { if (ids_types.get(a) == ids_names.get(b)) { tmpId = ids_names.get(b); } } } tmpId = array_en_id[tmpId]; if (!custom) { ui_data_edit[i] = new String[] {String.valueOf(tmpId), str_tmp[2]}; } else { ui_data_edit[i] = new String[] {String.valueOf(tmpId), str_tmp[1] + "|" + str_tmp[2]}; } } return ui_data_edit; } catch (Exception ex) { ex.printStackTrace(); return null; } }