List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.xplink.android.carchecklist.CarCheckListActivity.java
/** Called when the activity is first created. */ @Override/* ww w.j a v a 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { // end 480 super.onCreate(savedInstanceState); setContentView(R.layout.main); // deleteAllData(); // ************************************************************************************ listValue = restoreCheckList(); if (listValue != null) { SharedPreferences restoreShared = getSharedPreferences("mysettings", Context.MODE_PRIVATE); Editor edit = restoreShared.edit(); Map<String, Boolean> mapList = listValue.get(0); Map<String, Integer> mapSetting = listValue.get(1); int countChecknum = 0; int numPowerChecked = 0; int numEngineChecked = 0; int numExteriorChecked = 0; int numInteriorChecked = 0; int numDocumentChecked = 0; for (Map.Entry<String, Boolean> entry : mapList.entrySet()) { String[] tmp = entry.getKey().split("\\_"); Log.i("checkkeyvalue", tmp[0] + " : " + tmp[1]); String key = tmp[0]; if ("inside".equals(key)) { if (entry.getValue()) { getTotalInterior(true); numInteriorChecked++; Log.i("checkbox", "numInteriorChecked : " + numInteriorChecked); } } else if ("power".equals(key)) { if (entry.getValue()) { getTotalPower(true); numPowerChecked++; Log.i("checkbox", "numPowerChecked : " + numPowerChecked); } } else if ("engine".equals(key)) { if (entry.getValue()) { getTotalEngine(true); numEngineChecked++; Log.i("checkbox", "numEngineChecked : " + numEngineChecked); } } else if ("outside".equals(key)) { if (entry.getValue()) { getTotalExterior(true); numExteriorChecked++; Log.i("checkbox", "numExteriorChecked : " + numExteriorChecked); } } else if ("doc".equals(key)) { if (entry.getValue()) { getTotalDocument(true); numDocumentChecked++; Log.i("checkbox", "numDocumentChecked : " + numDocumentChecked); } } edit.putBoolean(entry.getKey(), entry.getValue()); // println(entry.getKey() + " : " + entry.getValue()); } Checknum = countChecknum; edit.putInt("CheckPowerTotal", numPowerChecked); edit.putInt("CheckEngineTotal", numEngineChecked); edit.putInt("CheckExteriorTotal", numExteriorChecked); edit.putInt("CheckInteriorTotal", numInteriorChecked); edit.putInt("CheckDocumentTotal", numDocumentChecked); edit.commit(); CheckPowerTotal = restoreShared.getInt("CheckPowerTotal", 0); CheckEngineTotal = restoreShared.getInt("CheckEngineTotal", 0); CheckExteriorTotal = restoreShared.getInt("CheckExteriorTotal", 0); CheckInteriorTotal = restoreShared.getInt("CheckInteriorTotal", 0); CheckDocumentTotal = restoreShared.getInt("CheckDocumentTotal", 0); Log.i("checklist", "in listValue - numPowerChecked : " + numPowerChecked); Log.i("checklist", "numEngineChecked : " + numEngineChecked); Log.i("checklist", "numExteriorChecked : " + numExteriorChecked); Log.i("checklist", "numInteriorChecked : " + numInteriorChecked); Log.i("checklist", "numDocumentChecked : " + numDocumentChecked); Log.i("checklist", "CheckPowerTotal : " + CheckPowerTotal); Log.i("checklist", "CheckEngineTotal : " + CheckEngineTotal); Log.i("checklist", "CheckExteriorTotal : " + CheckExteriorTotal); Log.i("checklist", "CheckInteriorTotal : " + CheckInteriorTotal); Log.i("checklist", "CheckDocumentTotal : " + CheckDocumentTotal); //edit.commit(); for (Map.Entry<String, Integer> entry : mapSetting.entrySet()) { if ("interior".equals(entry.getKey())) { edit.putInt("Interiorbar", entry.getValue()); } else if ("power".equals(entry.getKey())) { edit.putInt("Powerbar", entry.getValue()); } else if ("engine".equals(entry.getKey())) { edit.putInt("Enginebar", entry.getValue()); } else if ("exterior".equals(entry.getKey())) { edit.putInt("Exteriorbar", entry.getValue()); } else { edit.putInt("Documentbar", entry.getValue()); } // Log.i("checkSettingsName", "checkSettingsName : " + // entry.getKey()); } edit.commit(); /* * ProgressBar PowerProgress, EngineProgress, ExteriorProgress, * InteriorProgress, DocumentProgress, RatioProgress; TextView * percenpower, percenengine, percenexterior, perceninterior, * percendocument, Ratiotext; */ } // ************************************************************************************ // isSaveCheckBox(); store = new Bundle(); db = new DBCarCheckList(this); intent = new Intent(getApplicationContext(), RecordActivity.class); // getSettingShared(); // Log.i("dbcarchecklist", "create object DBCarCheckList"); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); float height = metrics.heightPixels; float width = metrics.widthPixels; Log.d("height", "" + height); Log.d("width", "" + width); int left195 = (int) ((width / 100) * 15.3); int left200 = (int) ((width / 100) * 16.25); int leftt200 = (int) ((width / 100) * 17); int left230 = (int) ((width / 100) * 18); int left475 = (int) ((width / 100) * 37.1); int left480 = (int) ((width / 100) * 38); int left495 = (int) ((width / 100) * 38.7); int left500 = (int) ((width / 100) * 40.5); int left510 = (int) ((width / 100) * 39.7); int left530 = (int) ((width / 100) * 41.2); int left865 = (int) ((width / 100) * 67.6); int left870 = (int) ((width / 100) * 69.5); int leftt870 = (int) ((width / 100) * 68); int leftt900 = (int) ((width / 100) * 70); int left950 = (int) ((width / 100) * 75); int left1150 = (int) ((width / 100) * 93); int left1180 = (int) ((width / 100) * 92); int top10 = (int) ((height / 100) * 3); int top20 = (int) ((height / 100) * 6.5); int top40 = (int) ((height / 100) * 5); int top95 = (int) ((height / 100) * 12); int top100 = (int) ((height / 100) * 12.5); int top110 = (int) ((height / 100) * 16.5); int top130 = (int) ((height / 100) * 19); int top135 = (int) ((height / 100) * 17.5); int top225 = (int) ((height / 100) * 28.8); int top390 = (int) ((height / 100) * 53); int top410 = (int) ((height / 100) * 51.5); int top480 = (int) ((height / 100) * 64.5); int top500 = (int) ((height / 100) * 63); int top505 = (int) ((height / 100) * 63.8); int top595 = (int) ((height / 100) * 75); int top610 = (int) ((height / 100) * 76); Intent intent = getIntent(); PercenPower = intent.getIntExtra("power", PercenPower); PercenEngine = intent.getIntExtra("engine", PercenEngine); PercenExterior = intent.getIntExtra("exterior", PercenExterior); PercenInterior = intent.getIntExtra("interior", PercenInterior); PercenDocument = intent.getIntExtra("document", PercenDocument); // follow : get data from shared preferences /* * SharedPreferences memo = getSharedPreferences("mysettings", * Context.MODE_PRIVATE); PercenPower = memo.getInt("PercenPower", 0); * PercenEngine = memo.getInt("PercenEngine", 0); PercenExterior = * memo.getInt("PercenExterior", 0); PercenInterior = * memo.getInt("PercenInterior", 0); PercenDocument = * memo.getInt("PercenDocument", 0); */ CheckPowerTotal = intent.getIntExtra("numpower", CheckPowerTotal); CheckEngineTotal = intent.getIntExtra("numengine", CheckEngineTotal); CheckExteriorTotal = intent.getIntExtra("numexterior", CheckExteriorTotal); CheckInteriorTotal = intent.getIntExtra("numinterior", CheckInteriorTotal); CheckDocumentTotal = intent.getIntExtra("numdocument", CheckDocumentTotal); // Log.d("percen", "" + PercenPower); type = Typeface.createFromAsset(getAssets(), "Circular.ttf"); MyCustomPanel view = new MyCustomPanel(this); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(1200, 800); params.width = 1200; params.height = 800; addContentView(view, params); RelativeLayout.LayoutParams imgpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgpower.setMargins(left480, top20, 0, 0); RelativeLayout.LayoutParams bdpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdpower.setMargins(left475, top40, 0, 0); RelativeLayout.LayoutParams txtpower = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtpower.setMargins(left510, top135, 0, 0); ImageView borderpower = (ImageView) findViewById(R.id.powerborder); borderpower.setLayoutParams(bdpower); percenpower = (TextView) findViewById(R.id.percenpower); percenpower.setLayoutParams(txtpower); percenpower.setTypeface(type); percenpower.setText("" + PercenPower + "%"); PowerProgress = (ProgressBar) findViewById(R.id.PowerProgressbar); PowerProgress.setMax(100); PowerProgress.setProgress(PercenPower); headpower = (ImageView) findViewById(R.id.headpower); btnPower = (ImageButton) findViewById(R.id.battery_button); btnPower.setLayoutParams(imgpower); btnPower.setOnClickListener(new OnClickListener() { public void onClick(View v) { // startAnimation SlidePowerLayout(); } }); RelativeLayout.LayoutParams imgengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgengine.setMargins(left200, top110, 0, 0); RelativeLayout.LayoutParams bdengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdengine.setMargins(left195, top110, 0, 0); RelativeLayout.LayoutParams txtengine = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtengine.setMargins(left230, top225, 0, 0); ImageView borderengine = (ImageView) findViewById(R.id.engineborder); borderengine.setLayoutParams(bdengine); percenengine = (TextView) findViewById(R.id.percenengine); percenengine.setLayoutParams(txtengine); percenengine.setTypeface(type); percenengine.setText("" + PercenEngine + "%"); EngineProgress = (ProgressBar) findViewById(R.id.EngineProgressbar); EngineProgress.setMax(100); EngineProgress.setProgress(PercenEngine); headengine = (ImageView) findViewById(R.id.headengine); btnEngine = (ImageButton) findViewById(R.id.engine_button); btnEngine.setLayoutParams(imgengine); btnEngine.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideEngineLayout(); } }); RelativeLayout.LayoutParams imgexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgexterior.setMargins(leftt200, top390, 0, 0); RelativeLayout.LayoutParams bdexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdexterior.setMargins(left195, top410, 0, 0); RelativeLayout.LayoutParams txtexterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtexterior.setMargins(left230, top505, 0, 0); ImageView borderexterior = (ImageView) findViewById(R.id.exteriorborder); borderexterior.setLayoutParams(bdexterior); percenexterior = (TextView) findViewById(R.id.percenexterior); percenexterior.setLayoutParams(txtexterior); percenexterior.setTypeface(type); percenexterior.setText("" + PercenExterior + "%"); ExteriorProgress = (ProgressBar) findViewById(R.id.ExteriorProgressbar); ExteriorProgress.setMax(100); ExteriorProgress.setProgress(PercenExterior); headexterior = (ImageView) findViewById(R.id.headexterior); btnExterior = (ImageButton) findViewById(R.id.outside_button); btnExterior.setLayoutParams(imgexterior); btnExterior.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideExteriorLayout(); } }); RelativeLayout.LayoutParams imginterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imginterior.setMargins(left500, top480, 0, 0); RelativeLayout.LayoutParams bdinterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bdinterior.setMargins(left495, top500, 0, 0); RelativeLayout.LayoutParams txtinterior = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtinterior.setMargins(left530, top595, 0, 0); ImageView borderinterior = (ImageView) findViewById(R.id.interiorborder); borderinterior.setLayoutParams(bdinterior); perceninterior = (TextView) findViewById(R.id.perceninterior); perceninterior.setLayoutParams(txtinterior); perceninterior.setTypeface(type); perceninterior.setText("" + PercenInterior + "%"); InteriorProgress = (ProgressBar) findViewById(R.id.InteriorProgressbar); InteriorProgress.setMax(100); InteriorProgress.setProgress(PercenInterior); headinterior = (ImageView) findViewById(R.id.headinterior); btnInterior = (ImageButton) findViewById(R.id.inside_button); btnInterior.setLayoutParams(imginterior); btnInterior.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // startAnimation SlideInteriorLayout(); } }); RelativeLayout.LayoutParams imgdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgdocument.setMargins(left870, top480, 0, 0); RelativeLayout.LayoutParams bddocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); bddocument.setMargins(left865, top500, 0, 0); RelativeLayout.LayoutParams txtdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtdocument.setMargins(leftt900, top595, 0, 0); RelativeLayout.LayoutParams progdocument = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); progdocument.setMargins(leftt870, top610, 0, 0); ImageView borderdocument = (ImageView) findViewById(R.id.documentborder); borderdocument.setLayoutParams(bddocument); percendocument = (TextView) findViewById(R.id.percendocument); percendocument.setLayoutParams(txtdocument); percendocument.setTypeface(type); percendocument.setText("" + PercenDocument + "%"); DocumentProgress = (ProgressBar) findViewById(R.id.DocumentProgressbar); DocumentProgress.setMax(100); DocumentProgress.setProgress(PercenDocument); headdocument = (ImageView) findViewById(R.id.headdocument); btnDocument = (ImageButton) findViewById(R.id.document_button); btnDocument.setLayoutParams(imgdocument); btnDocument.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SlideDocumentLayout(); } }); RelativeLayout.LayoutParams imgsetting = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); imgsetting.setMargins(left1180, top10, 0, 0); RelativeLayout.LayoutParams txtratio = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); txtratio.setMargins(left950, top95, 0, 0); RelativeLayout.LayoutParams ratioprog = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); ratioprog.setMargins(left1150, top100, 0, 0); Ratiotext = (TextView) findViewById(R.id.ratiotext); Ratiotext.setLayoutParams(txtratio); RatioProgress = (ProgressBar) findViewById(R.id.ratio); RatioProgress.setLayoutParams(ratioprog); RatioProgress.setMax(100); headsetting = (ImageView) findViewById(R.id.headsetting); btnSetting = (ImageButton) findViewById(R.id.setting_button); btnSetting.setLayoutParams(imgsetting); btnSetting.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SlideSettingLayout(); } }); // addMob LinearLayout layout = (LinearLayout) findViewById(R.id.admob); adView = new AdView(getApplicationContext()); adView.setAdSize(AdSize.LEADERBOARD); adView.setAdUnitId(admonId); //adView.setAdUnitId("C17E5F3A146EC7E805175C72634D8098"); // Add the adView to it layout.addView(adView); // Initiate a generic request to load it with an ad AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); adRequestBuilder.addTestDevice("C17E5F3A146EC7E805175C72634D8098"); // adRequestBuilder.addTestDevice("9F5DF3C9768A51CB506B68902F766B40"); adView.loadAd(adRequestBuilder.build()); // adView.loadAd(new AdRequest.Builder().build()); SharedPreferences shared = getSharedPreferences("mysettings", Context.MODE_PRIVATE); // Log.i("checksum", // "before call CheckRatio : " + shared.getInt("checknum", 0)); CheckRatio(); // Log.i("checklist", "checking percenpower : " + // shared.getInt("PercenPower", -1)); // restoreProgressCheckList(); }
From source file:com.nest5.businessClient.Initialactivity.java
@Override public void OnPayClicked(String method, double value, double discount, int tipp) { currentOrder = cookingOrders.get(currentSelectedPosition); int togo = 0; int delivery = 0; try {//from w w w . j ava 2 s. co m togo = cookingOrdersTogo.get(currentOrder) != null ? cookingOrdersTogo.get(currentOrder) : 0; delivery = cookingOrdersDelivery.get(currentOrder) != null ? cookingOrdersDelivery.get(currentOrder) : 0; } catch (Exception e) { e.printStackTrace(); } int number = checkSaleNumber(); //si falla se resta un numero de las ventas actuales mas adelante,. if (number > 0) { saveSale(method, value, discount, delivery, togo, tipp); Date date = new Date(); String fecha = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss").format(date); //String fecha = DateFormat.getDateFormat(Initialactivity.this).format( // date); // imprimir, conectar por wifi y enviar el texto arregladito a la app de // puente String mesa = "DOMICILIO / PARA LLEVAR"; if (currentTable != null) { mesa = currentTable.getTable().getName().toUpperCase(Locale.getDefault()); } int lines = 0; StringBuilder factura = new StringBuilder(); //factura.append("MR. PASTOR COMIDA\r\nRaPIDA MEXICANA" + "\r\n"); SharedPreferences prefs = Util.getSharedPreferences(mContext); String empresa = prefs.getString(Setup.COMPANY_NAME, "Nombre de Empresa"); String nit = prefs.getString(Setup.COMPANY_NIT, "000000000-0"); String email = prefs.getString(Setup.COMPANY_EMAIL, "email@empresa.com"); String pagina = prefs.getString(Setup.COMPANY_URL, "http://www.empresa.com"); String direccion = prefs.getString(Setup.COMPANY_ADDRESS, "Direccin Fsica Empresa"); String telefono = prefs.getString(Setup.COMPANY_TEL, "555-55-55"); String mensaje = prefs.getString(Setup.COMPANY_MESSAGE, "No hay ningn mensaje configurado an. En el mensaje es recomendable mencionar tus redes sociales, benficios y promociones que tengas, adems de informacin de inters paratus clientes. "); String propina = prefs.getString(Setup.TIP_MESSAGE, "No hay ningn mensaje de propina configurado an. "); String resolution = prefs.getString(Setup.RESOLUTION_MESSAGE, "Resolucin de facturacin No. 00000-0000 de 1970 DIAN"); int currentSale = prefs.getInt(Setup.CURRENT_SALE, 0); factura.append(empresa + "\r\n"); factura.append(nit + "\r\n"); factura.append(direccion + "\r\n"); factura.append(telefono + "\r\n"); factura.append(email + "\r\n"); factura.append(pagina + "\r\n"); factura.append(resolution + "\r\n"); factura.append("Factura de Venta No. " + String.valueOf(currentSale) + "\r\n"); lines++; factura.append("\r\n"); factura.append(fecha); factura.append("\r\n"); factura.append(mesa); lines++; lines++; lines++; factura.append("\r\n"); factura.append(" Item Cantidad Precio\r\n"); lines++; Iterator<Entry<Registrable, Integer>> it = currentOrder.entrySet().iterator(); //////Log.i("MISPRUEBAS","Valor de currentOrder"+String.valueOf(currentOrder.size())); // Log.d(TAG,String.valueOf(currentOrder.size())); LinkedHashMap<Registrable, Integer> currentObjects = new LinkedHashMap<Registrable, Integer>(); float base = 0; float iva = 0; float total = 0; ArrayList<String> productos = new ArrayList<String>(); ArrayList<String> quantities = new ArrayList<String>(); ArrayList<String> precios = new ArrayList<String>(); while (it.hasNext()) { LinkedHashMap.Entry<Registrable, Integer> pairs = (LinkedHashMap.Entry<Registrable, Integer>) it .next(); currentObjects.put(pairs.getKey(), pairs.getValue()); String name = pairs.getKey().name; int longName = name.length(); int subLength = 14 - longName; if (subLength < 0) name = name.substring(0, 14); int espacios1 = 4; int espacios2 = 12; if (name.length() < 14) { espacios1 += 14 - name.length(); } factura.append(name); productos.add(name); int qtyL = String.valueOf(pairs.getValue()).length(); float precioiva = (float) Math .round(pairs.getKey().price + pairs.getKey().price * pairs.getKey().tax); base += (float) Math.round(pairs.getKey().price * pairs.getValue()); iva += (float) Math.round((pairs.getKey().price * pairs.getKey().tax) * pairs.getValue()); total += precioiva * pairs.getValue(); int priceL = String.valueOf(precioiva).length(); espacios1 = espacios1 - qtyL < 1 ? espacios1 = 1 : espacios1 - qtyL; espacios2 = espacios2 - priceL < 1 ? espacios2 = 1 : espacios2 - priceL; espacios2 = espacios2 - qtyL < 1 ? espacios2 = 1 : espacios2 - qtyL; for (int k = 0; k < espacios1; k++) { factura.append(" "); } factura.append(pairs.getValue()); for (int k = 0; k < espacios2; k++) { factura.append(" "); } quantities.add(String.valueOf(pairs.getValue())); factura.append("$"); factura.append(precioiva); factura.append("\r\n"); precios.add("$" + precioiva); lines++; } float propvalue = 0; if (tipp == 1) propvalue = (float) Math.round(total * 0.1); float descuento = 0; if (discount > 0) { descuento = (float) Math.round(base - (base * (discount / 0))); } lines++; lines++; factura.append("\r\n"); factura.append("<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>\r\n"); factura.append("BASE: $" + base + "\r\n"); factura.append("Descuento (" + discount + "): $" + descuento + "\r\n"); factura.append("Imp.: $" + iva + "\r\n"); factura.append("SUBTOTAL: $" + Math.round(total - descuento) + "\r\n"); factura.append("PROPINA: $" + propvalue + "\r\n"); float precfinal = propvalue + total - descuento; factura.append("TOTAL: $" + precfinal + "\r\n"); factura.append("\r\n"); factura.append("<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>\r\n"); factura.append("\r\n"); lines++; factura.append(propina + "\r\n"); factura.append(mensaje); String send = factura.toString(); //////Log.i("MISPRUEBAS",factura.toString()); // Enviar un string diferente que lleva la orden actual. // new WiFiSend().execute(comanda.toString());// enviar el mensaje de // verdad int[] arrayOfInt = new int[2]; arrayOfInt[0] = 27; arrayOfInt[1] = 64; int[] array2 = new int[3]; array2[0] = 27; array2[1] = 74; array2[2] = 2; StringBuilder builder1 = new StringBuilder(); for (int h = 0; h < 2; h++) { builder1.append(Character.toChars(arrayOfInt[h])); } StringBuilder builder2 = new StringBuilder(); builder2.append(Character.toChars(10)); StringBuilder complete = new StringBuilder(String.valueOf(builder1.toString())) .append(String.valueOf(builder2.toString())); String enviar = complete.toString(); Boolean printed = true; try { if (mChatService.getState() == mChatService.STATE_CONNECTED) { try { mChatService.write(factura.toString().getBytes("x-UnicodeBig")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } else { printed = false; Toast.makeText(mContext, "No hay impresora bluetooth conectada.", Toast.LENGTH_LONG).show(); } } catch (NullPointerException e) { printed = false; e.printStackTrace(); } if (!printed) {//buscar impresora TCP/IP StringBuilder formateado = new StringBuilder(); formateado.append(CLEAR_PRINTER); formateado.append(INITIALIZE_PRINTER); formateado.append(JUSTIFICATION_CENTER); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append(empresa); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(nit); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(direccion); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(telefono); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(email); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(pagina); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("Factura de Venta No." + String.valueOf(currentSale)); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(resolution); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(fecha); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(mesa); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append(JUSTIFICATION_LEFT); formateado.append("ITEM"); formateado.append(HORIZONTAL_TAB); formateado.append("CANT."); formateado.append(HORIZONTAL_TAB); formateado.append("PRECIO"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_ONE_LINE); for (String actual : productos) { int pos = productos.indexOf(actual); String cantidad = quantities.get(pos); String precio = precios.get(pos); formateado.append(actual); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("x" + cantidad); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(precio); formateado.append(PRINT_FEED_ONE_LINE); } formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append("______________________"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append("BASE:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + base); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("DESCUENTO (:" + discount + "%)"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + descuento); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("Impuesto:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + iva); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("SUBTOTAL:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + Math.round(total - descuento)); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("PROPINA:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + propvalue); formateado.append(PRINT_FEED_ONE_LINE); formateado.append("TOTAL:"); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append(HORIZONTAL_TAB); formateado.append("$" + precfinal); formateado.append(PRINT_FEED_ONE_LINE); formateado.append(DOUBLE_WIDE_CHARACTERS); formateado.append("______________________"); formateado.append(SINGLE_WIDE_CHARACTERS); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(ITALIC_STYLE); formateado.append(propina); formateado.append(PRINT_FEED_N_LINES); formateado.append((char) 0x02); formateado.append(mensaje); formateado.append(ITALIC_CANCEL); formateado.append(FINALIZE_TICKET); formateado.append(FULL_CUT); if (mTCPPrint != null) { if (mTCPPrint.getStatus() == TCPPrint.CONNECTED) { mTCPPrint.sendMessage(formateado.toString()); mTCPPrint.sendMessage(formateado.toString()); } else { mTCPPrint.stopClient(); new connectTask().execute(formateado.toString()); alertbox("Oops!", "Al Parecer no hay impresora disponible. Estamos tratando de reconectarnos e imprimir. Si no funciona, reinicia la Red o la impresora y ve a rdenes para imprimir el pedido."); } } else { alertbox("Oops!", "Al Parecer no hay impresora disponible. Trataremos en este momento de nuevo de imprimir el pedido. Si no funciona, reinicia la red o la impreso y ve a rdenes para imprimir de nuevo la orden."); new connectTask().execute(formateado.toString()); } } currentOrder.clear(); //NUEVOO makeTable("NA"); } else { alertbox("!ATENCIN!", "Esta venta no se puede facturar. Este dispositivo no tiene ms facturas autorizadas. Consulta el administrador, o si tu lo eres, ve a tu panel de control Nest5 y autoriza ms facturas. Para ms informacin: http://soporte.nest5.com"); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_conversation_group, container, false); activity = getActivity();//from w w w . jav a 2 s. com f = new Finder(activity); ButterKnife.inject(this, view); ((MainActivity) activity).menuBottom.setVisibility(View.GONE); ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE); // if (!setted) if (BackgroundFragment.getBackgroundChat(activity) != 0) backgroundChat.setImageDrawable( activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity))); messageText.conversationGroupFragment = this; TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD); TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT); temporizadorAcept.setVisibility(View.INVISIBLE); TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKON); messageText.setOnClickListener(this); messageTranslate.setOnClickListener(this); messageClock.setOnClickListener(this); temporizadorAcept.setOnClickListener(this); temporizadorCancel.setOnClickListener(this); adjuntContact.setOnClickListener(this); adjuntPhoto.setOnClickListener(this); adjuntAudio.setOnClickListener(this); adjuntLocation.setOnClickListener(this); adjuntVideo.setOnClickListener(this); adjuntImage.setOnClickListener(this); time1.setOnClickListener(this); time2.setOnClickListener(this); time3.setOnClickListener(this); time4.setOnClickListener(this); time5.setOnClickListener(this); time6.setOnClickListener(this); time7.setOnClickListener(this); time8.setOnClickListener(this); time9.setOnClickListener(this); time10.setOnClickListener(this); time11.setOnClickListener(this); time12.setOnClickListener(this); recordAudioButton.setOnTouchListener(this); messageText.requestFocus(); messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString()); messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString()); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); sv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); sv.setVerticalScrollBarEnabled(false); sv.setHorizontalScrollBarEnabled(false); final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); keyBoardHeight = settings.getInt("INPUTKEY", 0); if (keyBoardHeight == 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); messageText.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub InputMethodManager keyboard = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.showSoftInput(messageText, 0); } }, 50); isShowKeyboard = true; final Window mRootWindow = activity.getWindow(); final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content); mRootView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { Rect r = new Rect(); View view = mRootWindow.getDecorView(); view.getWindowVisibleDisplayFrame(r); if (prevSize == 0) prevSize = r.bottom; else if (prevSize != r.bottom) { if (prevSize - r.bottom > 150) { keyBoardHeight = prevSize - r.bottom; SharedPreferences.Editor editor = settings.edit(); editor.putInt("INPUTKEY", keyBoardHeight); editor.apply(); keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight)); isShowKeyboard = true; isShowKeyboard = true; isShowCustomKeyboard = false; mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } // r.left, r.top, r.right, r.bottom }//2464 -- 1772 -- 692 //1184 -- 660 -- 524 }); } else { isShowKeyboard = false; getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); keyboardLayout.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight)); Log.e("tamao teclado", keyBoardHeight + " : " + pxFromDp(activity, 240) + " : " + pxFromDp(activity, 180)); if (keyBoardHeight > pxFromDp(activity, 240)) { ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity, 180); ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity, 140); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity, 140); temporizadorSeek.atributesCode(20, 16, 25); temporLanel.setTextSize(18); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60); } else if (keyBoardHeight > pxFromDp(activity, 180)) { ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity, 130); ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity, 110); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity, 110); temporizadorSeek.atributesCode(15, 16, 9); temporLanel.setTextSize(14); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45); } } messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (scrollOnBottom) { messagesListScroll.scrollTo(0, messagesList.getBottom()); } else { messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue) + (scrollHeight - messagesListScroll.getHeight())); messagesListScroll.setVerticalScrollBarEnabled(true); } } }); messagesListScroll.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll .getHeight()) { scrollOnBottom = true; } else { scrollOnBottom = false; messagesValuePrev = messagesList.getHeight(); scrollValue = messagesListScroll.getScrollY(); scrollHeight = messagesListScroll.getHeight(); } } }); messageSend.setOnClickListener(this); messageText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (messageText.getText().length() > 0) { messageSend.setVisibility(View.VISIBLE); messageSednDivider.setVisibility(View.VISIBLE); } else { messageSend.setVisibility(View.GONE); messageSednDivider.setVisibility(View.GONE); } } }); u = new Select().from(User.class).executeSingle(); ((MainActivity) activity).setOnBackPressedListener(null); return view; }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_conversation_chat, container, false); activity = getActivity();/*from www .j ava2 s .com*/ f = new Finder(activity); ButterKnife.inject(this, view); ((MainActivity) activity).actionBar.setVisibility(View.VISIBLE); ((MainActivity) activity).menuBottom.setVisibility(View.GONE); if (BackgroundFragment.getBackgroundChat(activity) != 0) backgroundChat.setImageDrawable( activity.getResources().getDrawable(BackgroundFragment.getBackgroundChat(activity))); messageText.conversationChatFragment = this; TFCache.apply(activity, messageSend, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageTranslate, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageClock, TFCache.TF_SPEAKALL); TFCache.apply(activity, messageText, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, temporLanel, TFCache.TF_WHITNEY_BOLD); TFCache.apply(activity, addToContacts, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, temporizadorCancel, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, temporizadorAcept, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, textRecording, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, textRecordingPress, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, timerAudio, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, cancelAudio, TFCache.TF_WHITNEY_LIGHT); TFCache.apply(activity, audioRecordBackground, TFCache.TF_WHITNEY_LIGHT); temporizadorAcept.setVisibility(View.INVISIBLE); longclick = false; saveAudio = false; TFCache.apply(activity, adjuntContact, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntPhoto, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntAudio, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntLocation, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntVideo, TFCache.TF_SPEAKALL); TFCache.apply(activity, adjuntImage, TFCache.TF_SPEAKALL); messageText.setOnClickListener(this); messageTranslate.setOnClickListener(this); messageClock.setOnClickListener(this); temporizadorAcept.setOnClickListener(this); temporizadorCancel.setOnClickListener(this); adjuntContact.setOnClickListener(this); adjuntPhoto.setOnClickListener(this); adjuntAudio.setOnClickListener(this); adjuntLocation.setOnClickListener(this); adjuntVideo.setOnClickListener(this); adjuntImage.setOnClickListener(this); addToContacts.setOnClickListener(this); time1.setOnClickListener(this); time2.setOnClickListener(this); time3.setOnClickListener(this); time4.setOnClickListener(this); time5.setOnClickListener(this); time6.setOnClickListener(this); time7.setOnClickListener(this); time8.setOnClickListener(this); time9.setOnClickListener(this); time10.setOnClickListener(this); time11.setOnClickListener(this); time12.setOnClickListener(this); recordAudioButton.setOnTouchListener(this); messageText.requestFocus(); dateDay1 = new SimpleDateFormat("d"); dateDayText1 = new SimpleDateFormat("EEEE"); dateMonth1 = new SimpleDateFormat("MMMM"); dateYear1 = new SimpleDateFormat("yyyy"); timeFormat1 = new SimpleDateFormat("h:mm a"); messageSend.setText(Finder.STRING.ICN_SEND_MSJ.toString()); messageTranslate.setText(Finder.STRING.ICN_TRANSLATE.toString()); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); sv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); sv.setVerticalScrollBarEnabled(false); sv.setHorizontalScrollBarEnabled(false); final SharedPreferences settings = activity.getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); keyBoardHeight = settings.getInt("INPUTKEY", 0); if (keyBoardHeight == 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); messageText.postDelayed(new Runnable() { @Override public void run() { InputMethodManager keyboard = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.showSoftInput(messageText, 0); } }, 50); isShowKeyboard = true; final Window mRootWindow = activity.getWindow(); final View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content); mRootView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { Rect r = new Rect(); View view = mRootWindow.getDecorView(); view.getWindowVisibleDisplayFrame(r); if (prevSize == 0) prevSize = r.bottom; else if (prevSize != r.bottom) { if (prevSize - r.bottom > 150) { keyBoardHeight = prevSize - r.bottom; SharedPreferences.Editor editor = settings.edit(); editor.putInt("INPUTKEY", keyBoardHeight); editor.apply(); keyboardLayout.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight)); isShowKeyboard = true; isShowCustomKeyboard = false; mRootView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } } }); } else { isShowKeyboard = false; getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); keyboardLayout.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, keyBoardHeight)); if (keyBoardHeight > pxFromDp(activity, 240)) { ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity, 180); ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity, 180); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity, 140); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity, 140); temporizadorSeek.atributesCode(20, 16, 25); temporLanel.setTextSize(18); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 128); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 115); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 90); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 118); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 92); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 65); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 24); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 35); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 37); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 30); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 25); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 60); } else if (keyBoardHeight > pxFromDp(activity, 180)) { ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).width = (int) pxFromDp(activity, 130); ((LinearLayout.LayoutParams) seekBarContent.getLayoutParams()).height = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).width = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) tapsContent.getLayoutParams()).height = (int) pxFromDp(activity, 130); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).width = (int) pxFromDp(activity, 110); ((RelativeLayout.LayoutParams) temporizadorSeek.getLayoutParams()).height = (int) pxFromDp(activity, 110); temporizadorSeek.atributesCode(15, 16, 9); temporLanel.setTextSize(14); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19); ((RelativeLayout.LayoutParams) time1.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29); ((RelativeLayout.LayoutParams) time2.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47); ((RelativeLayout.LayoutParams) time3.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67); ((RelativeLayout.LayoutParams) time4.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 94); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time5.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95); ((RelativeLayout.LayoutParams) time6.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 66); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).topMargin = (int) pxFromDp(activity, 95); ((RelativeLayout.LayoutParams) time7.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).topMargin = (int) pxFromDp(activity, 85); ((RelativeLayout.LayoutParams) time8.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).topMargin = (int) pxFromDp(activity, 67); ((RelativeLayout.LayoutParams) time9.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).topMargin = (int) pxFromDp(activity, 47); ((RelativeLayout.LayoutParams) time10.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 18); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).topMargin = (int) pxFromDp(activity, 29); ((RelativeLayout.LayoutParams) time11.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 28); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).height = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).width = (int) pxFromDp(activity, 20); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).topMargin = (int) pxFromDp(activity, 19); ((RelativeLayout.LayoutParams) time12.getLayoutParams()).leftMargin = (int) pxFromDp(activity, 45); } } messagesList.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (scrollOnBottom) { messagesListScroll.scrollTo(0, messagesList.getBottom()); } else { messagesListScroll.scrollTo(0, ((messagesList.getHeight() - messagesValuePrev) + scrollValue) + (scrollHeight - messagesListScroll.getHeight())); messagesListScroll.setVerticalScrollBarEnabled(true); } } }); messagesListScroll.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (messagesList.getHeight() - messagesListScroll.getScrollY() <= messagesListScroll .getHeight()) { scrollOnBottom = true; } else { scrollOnBottom = false; messagesValuePrev = messagesList.getHeight(); scrollValue = messagesListScroll.getScrollY(); scrollHeight = messagesListScroll.getHeight(); } } }); messageSend.setOnClickListener(this); messageText.addTextChangedListener(new TextWatcher() { boolean delayed = false; @Override public void afterTextChanged(Editable arg0) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } private void sendWritingStatus() { if (SpeakSocket.isRunning()) { try { JSONObject data = new JSONObject(); data.put("source", u.id); data.put("target", contact.idContacto); data.put("type", 1); if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) SpeakSocket.mSocket.emit("contact-status", data); Log.e("STATUS WRITE", data.toString()); } catch (JSONException e) { e.printStackTrace(); } } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (messageText.getText().length() > 0) { messageSend.setVisibility(View.VISIBLE); messageSednDivider.setVisibility(View.VISIBLE); if (!delayed) { delayed = true; sendWritingStatus(); new Handler().postDelayed(new Runnable() { @Override public void run() { delayed = false; } }, C.CONTACT_STATUS_DELAY_MS); } } else { messageSend.setVisibility(View.GONE); messageSednDivider.setVisibility(View.GONE); } } }); u = new Select().from(User.class).executeSingle(); handlerContactStatus = new Handler(); runnableContactStatus = new Runnable() { @Override public void run() { JSONObject dataLastSeen = new JSONObject(); try { dataLastSeen.put("source", u.id); dataLastSeen.put("target", contact.idContacto); if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { Log.e("Pidiendo lastseen", dataLastSeen.toString()); SpeakSocket.mSocket.emit("contact-lastseen", dataLastSeen); } } catch (JSONException e) { e.printStackTrace(); } handlerContactStatus.postDelayed(runnableContactStatus, 5000); } }; handlerContactStatus.postDelayed(runnableContactStatus, 500); Contact contAdd = new Select().from(Contact.class).where("id_contact = ?", contact.idContacto) .executeSingle(); if (contAdd == null) { addToContacts.setVisibility(View.VISIBLE); } else { addToContacts.setVisibility(View.GONE); } return view; }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.icn_message_send: String message = messageText.getText().toString(); MsgGroups msgGroup = new MsgGroups(); try {// w w w.j a va2 s. c om Calendar fecha = Calendar.getInstance(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); String contactosId = null; if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } } msgGroup.grupoId = grupo.grupoId; msgGroup.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis() + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msgGroup.emisor = u.id; msgGroup.receptores = targets.toString(); msgGroup.mensaje = message; msgGroup.emisorEmail = u.email; msgGroup.emisorLang = u.lang; msgGroup.translation = translate; msgGroup.emitedAt = fecha.getTimeInMillis(); msgGroup.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_TEXT)); if (tiempoMensaje) { msgGroup.delay = temporizadorSeek.getValue(); } else { msgGroup.delay = 0; } } catch (JSONException e) { e.printStackTrace(); } msgGroup.save(); messageText.setText(""); showNewMessage(msgGroup); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); tiempoMensaje = false; break; case R.id.message_text: SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings.getInt("INPUTKEY", 0) == 0) { customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); keyboardLayout.setVisibility(View.GONE); isShowCustomKeyboard = false; if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } isShowKeyboard = true; } else { if (!isShowKeyboard) { if (!isShowCustomKeyboard) { messagesListScroll.setVerticalScrollBarEnabled(false); final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } imm.showSoftInput(messageText, 0); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); keyboardLayout .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; ((MainActivity) activity).setOnBackPressedListener(null); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } else { keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); ((MainActivity) activity).setOnBackPressedListener(null); messagesListScroll.setVerticalScrollBarEnabled(false); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(messageText, 0); keyboardLayout .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } } break; case R.id.icn_message_translate: if (translate) messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red)); else messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray)); //initAdapter(); break; case R.id.icn_message_clock: tiempoMensaje = false; temporizadorAcept.setVisibility(View.INVISIBLE); temporizadorSeek.setInitPosition(0); SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings1.getInt("INPUTKEY", 0) != 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (!isShowCustomKeyboard) { if (!isShowKeyboard) { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); customKeyboardLayout.setVisibility(View.VISIBLE); customKeyboardAudio.setVisibility(View.GONE); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); isShowCustomKeyboard = true; isShowKeyboard = false; } else { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); hideKeyBoard(); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } customKeyboardLayout.setVisibility(View.VISIBLE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = true; isShowKeyboard = false; } } else { customKeyboardAudio.setVisibility(View.GONE); if (!customKeyboardLayout.isShown()) { customKeyboardLayout.setVisibility(View.VISIBLE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } } else { temporizadorAcept.setVisibility(View.INVISIBLE); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; tiempoMensaje = false; if (tiempoMensaje) { messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } } } break; case R.id.temporizador_cancel: temporizadorAcept.setVisibility(View.INVISIBLE); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); temporizadorSeek.setInitPosition(0); isShowCustomKeyboard = false; tiempoMensaje = false; break; case R.id.temporizador_acept: temporizadorAcept.setVisibility(View.INVISIBLE); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); temporizadorSeek.setInitPosition(15); isShowCustomKeyboard = false; tiempoMensaje = true; if (!isShowKeyboard) { if (!isShowCustomKeyboard) { messagesListScroll.setVerticalScrollBarEnabled(false); final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } imm.showSoftInput(messageText, 0); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; ((MainActivity) activity).setOnBackPressedListener(null); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } else { keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); ((MainActivity) activity).setOnBackPressedListener(null); messagesListScroll.setVerticalScrollBarEnabled(false); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(messageText, 0); keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } break; case R.id._1: temporizadorSeek.setInitPosition(15); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._2: temporizadorSeek.setInitPosition(30); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._3: temporizadorSeek.setInitPosition(45); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._4: temporizadorSeek.setInitPosition(60); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._5: temporizadorSeek.setInitPosition(75); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._6: temporizadorSeek.setInitPosition(90); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._7: temporizadorSeek.setInitPosition(105); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._8: temporizadorSeek.setInitPosition(120); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._9: temporizadorSeek.setInitPosition(135); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._10: temporizadorSeek.setInitPosition(150); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._11: temporizadorSeek.setInitPosition(165); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._12: temporizadorSeek.setInitPosition(180); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id.adjunt_image: System.gc(); getFragmentManager().beginTransaction().replace(R.id.container3, CreatePollFragment.newInstance(grupo)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_contact: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(i, 34); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_audio: menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); AnimatorSet set3 = new AnimatorSet(); set3.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0)); set3.setDuration(200).start(); SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings2.getInt("INPUTKEY", 0) != 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (!isShowCustomKeyboard) { if (!isShowKeyboard) { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } keyboardLayout.setVisibility(View.GONE); AnimatorSet set4 = new AnimatorSet(); set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set4.setDuration(220).start(); set4.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.VISIBLE); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); isShowCustomKeyboard = true; isShowKeyboard = false; } else { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); keyboardLayout.setVisibility(View.GONE); AnimatorSet set5 = new AnimatorSet(); set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set5.setDuration(220).start(); set5.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); hideKeyBoard(); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.VISIBLE); isShowCustomKeyboard = true; isShowKeyboard = false; } } else { customKeyboardLayout.setVisibility(View.GONE); if (!customKeyboardAudio.isShown()) { customKeyboardAudio.setVisibility(View.VISIBLE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } } else { temporizadorAcept.setVisibility(View.INVISIBLE); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } break; case R.id.adjunt_photo: System.gc(); choosePicture(); break; case R.id.adjunt_video: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent videoPickerIntent = new Intent(Intent.ACTION_PICK); videoPickerIntent.setType("video/*"); startActivityForResult(videoPickerIntent, 18); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_location: adjuntLayout.setVisibility(View.GONE); hideKeyBoard(); menuAdjunt = false; milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> allProviders = milocManager.getAllProviders(); boolean gpsProvider = false; boolean netProvider = false; for (String providerName : allProviders) { if (providerName.equals(LocationManager.GPS_PROVIDER)) { gpsProvider = true; } if (providerName.equals(LocationManager.NETWORK_PROVIDER)) { netProvider = true; } } checkCountryLocation(gpsProvider, netProvider); break; } }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.icn_message_send: temporizadorAcept.setVisibility(View.INVISIBLE); String message = messageText.getText().toString(); Message msjNew = new Message(); Calendar fecha = Calendar.getInstance(); String id = u.id + contact.idContacto + fecha.getTimeInMillis() + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msjNew.mensajeId = id;/*from w w w . ja v a 2 s .c o m*/ msjNew.emisor = u.id; msjNew.receptor = contact.idContacto; msjNew.mensaje = message; msjNew.emisorEmail = u.email; msjNew.receptorEmail = contact.email; msjNew.emisorLang = u.lang; msjNew.receptorLang = contact.lang; msjNew.emitedAt = fecha.getTimeInMillis(); msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_TEXT)); if (tiempoMensaje) msjNew.delay = temporizadorSeek.getValue(); else msjNew.delay = 0; msjNew.translation = translate; if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { msjNew.status = 1; } else { msjNew.status = -1; } msjNew.save(); Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor).executeSingle(); if (chat == null) { Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor) .executeSingle(); Chats newChat = new Chats(); newChat.mensajeId = msjNew.mensajeId; newChat.idContacto = msjNew.receptor; newChat.isLockedConversation = false; newChat.lastStatus = msjNew.status; newChat.email = msjNew.receptorEmail; if (contact != null) { newChat.photo = contact.photo; newChat.fullName = contact.fullName; newChat.lang = contact.lang; newChat.screenName = contact.screenName; newChat.photoload = true; newChat.phone = contact.phone; } else { newChat.photo = null; newChat.photoload = false; newChat.fullName = msjNew.receptorEmail; newChat.lang = msjNew.receptorLang; newChat.screenName = msjNew.receptorEmail; newChat.phone = null; } newChat.emitedAt = msjNew.emitedAt; newChat.notRead = 0; newChat.lastMessage = msjNew.mensaje; newChat.show = true; newChat.save(); } else { if (!chat.photoload) { Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.emisor) .executeSingle(); if (contact != null) { chat.photo = contact.photo; chat.photoload = true; } else { chat.photo = null; chat.photoload = false; } } chat.mensajeId = msjNew.mensajeId; chat.lastStatus = msjNew.status; chat.emitedAt = msjNew.emitedAt; chat.notRead = 0; chat.lastMessage = msjNew.mensaje; chat.save(); } messageText.setText(""); showNewMessage(msjNew); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); tiempoMensaje = false; break; case R.id.message_text: SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings.getInt("INPUTKEY", 0) == 0) { customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); keyboardLayout.setVisibility(View.GONE); isShowCustomKeyboard = false; if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } isShowKeyboard = true; } else { if (!isShowKeyboard) { if (!isShowCustomKeyboard) { messagesListScroll.setVerticalScrollBarEnabled(false); final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } imm.showSoftInput(messageText, 0); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); keyboardLayout .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; ((MainActivity) activity).setOnBackPressedListener(null); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } else { keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); ((MainActivity) activity).setOnBackPressedListener(null); messagesListScroll.setVerticalScrollBarEnabled(false); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(messageText, 0); keyboardLayout .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } } break; case R.id.icn_message_translate: translate = !translate; if (translate) messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red)); else messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray)); break; case R.id.icn_message_clock: tiempoMensaje = false; temporizadorAcept.setVisibility(View.INVISIBLE); temporizadorSeek.setInitPosition(0); SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings1.getInt("INPUTKEY", 0) != 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (!isShowCustomKeyboard) { if (!isShowKeyboard) { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); customKeyboardLayout.setVisibility(View.VISIBLE); customKeyboardAudio.setVisibility(View.GONE); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); isShowCustomKeyboard = true; isShowKeyboard = false; } else { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); hideKeyBoard(); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } customKeyboardLayout.setVisibility(View.VISIBLE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = true; isShowKeyboard = false; } } else { customKeyboardAudio.setVisibility(View.GONE); if (!customKeyboardLayout.isShown()) { customKeyboardLayout.setVisibility(View.VISIBLE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } } else { temporizadorAcept.setVisibility(View.INVISIBLE); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; tiempoMensaje = false; if (tiempoMensaje) { messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } } } break; case R.id.temporizador_cancel: temporizadorAcept.setVisibility(View.INVISIBLE); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); temporizadorSeek.setInitPosition(0); isShowCustomKeyboard = false; tiempoMensaje = false; break; case R.id.temporizador_acept: temporizadorAcept.setVisibility(View.INVISIBLE); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; tiempoMensaje = true; if (!isShowKeyboard) { if (!isShowCustomKeyboard) { messagesListScroll.setVerticalScrollBarEnabled(false); final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } imm.showSoftInput(messageText, 0); keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; ((MainActivity) activity).setOnBackPressedListener(null); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } else { keyboardLayout.setVisibility(View.GONE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set.setDuration(220).start(); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); ((MainActivity) activity).setOnBackPressedListener(null); messagesListScroll.setVerticalScrollBarEnabled(false); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } final InputMethodManager imm = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(messageText, 0); keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); isShowKeyboard = true; customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } break; case R.id._1: temporizadorSeek.setInitPosition(15); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._2: temporizadorSeek.setInitPosition(30); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._3: temporizadorSeek.setInitPosition(45); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._4: temporizadorSeek.setInitPosition(60); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._5: temporizadorSeek.setInitPosition(75); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._6: temporizadorSeek.setInitPosition(90); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._7: temporizadorSeek.setInitPosition(105); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._8: temporizadorSeek.setInitPosition(120); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._9: temporizadorSeek.setInitPosition(135); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._10: temporizadorSeek.setInitPosition(150); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._11: temporizadorSeek.setInitPosition(165); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id._12: temporizadorSeek.setInitPosition(180); temporizadorAcept.setVisibility(View.VISIBLE); break; case R.id.adjunt_image: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_contact: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); startActivityForResult(i, 34); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_audio: menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(), Context.MODE_PRIVATE); if (settings2.getInt("INPUTKEY", 0) != 0) { getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (!isShowCustomKeyboard) { if (!isShowKeyboard) { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } keyboardLayout.setVisibility(View.GONE); AnimatorSet set4 = new AnimatorSet(); set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set4.setDuration(220).start(); set4.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.VISIBLE); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); isShowCustomKeyboard = true; isShowKeyboard = false; } else { keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus)); keyboardLayout.setVisibility(View.GONE); AnimatorSet set5 = new AnimatorSet(); set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1)); set5.setDuration(220).start(); set5.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { keyboardLayout.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); hideKeyBoard(); ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; ((MainActivity) activity).setOnBackPressedListener(null); } }); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); } customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.VISIBLE); isShowCustomKeyboard = true; isShowKeyboard = false; } } else { customKeyboardLayout.setVisibility(View.GONE); if (!customKeyboardAudio.isShown()) { customKeyboardAudio.setVisibility(View.VISIBLE); if (tiempoMensaje) { messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString()); messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray)); } } else { temporizadorAcept.setVisibility(View.INVISIBLE); keyboardLayout.setVisibility(View.GONE); customKeyboardLayout.setVisibility(View.GONE); customKeyboardAudio.setVisibility(View.GONE); isShowCustomKeyboard = false; } } break; case R.id.add_to_contacts: try { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put(C.c_id_contact, contact.idContacto); RequestParams params = new RequestParams(); params.put("contacts", jsonArr.put(jsonObj)); addToContacts(params); } catch (JSONException e) { e.printStackTrace(); } break; case R.id.adjunt_photo: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); File imagesFolder = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent"); imagesFolder.mkdirs(); adjuntLayout.setVisibility(View.GONE); dateToCamera = Calendar.getInstance().getTimeInMillis(); File image = new File(imagesFolder, dateToCamera + ".png"); Uri uriSavedImage = Uri.fromFile(image); Intent pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); startActivityForResult(pictureActionIntent, 23); break; case R.id.adjunt_video: System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent videoPickerIntent = new Intent(Intent.ACTION_PICK); videoPickerIntent.setType("video/*"); startActivityForResult(videoPickerIntent, 18); menuAdjunt = false; adjuntLayout.setVisibility(View.GONE); break; case R.id.adjunt_location: adjuntLayout.setVisibility(View.GONE); hideKeyBoard(); menuAdjunt = false; milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> allProviders = milocManager.getAllProviders(); boolean gpsProvider = false; boolean netProvider = false; for (String providerName : allProviders) { if (providerName.equals(LocationManager.GPS_PROVIDER)) { gpsProvider = true; } if (providerName.equals(LocationManager.NETWORK_PROVIDER)) { netProvider = true; } } checkCountryLocation(gpsProvider, netProvider); break; } }
From source file:de.j4velin.mapsmeasure.Map.java
@SuppressLint("NewApi") @Override/* www .j ava 2 s.c o m*/ public void onCreate(final Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); } catch (final BadParcelableException bpe) { bpe.printStackTrace(); } setContentView(R.layout.activity_map); formatter_no_dec.setMaximumFractionDigits(0); formatter_two_dec.setMaximumFractionDigits(2); final SharedPreferences prefs = getSharedPreferences("settings", Context.MODE_PRIVATE); // use metric a the default everywhere, except in the US metric = prefs.getBoolean("metric", !Locale.getDefault().equals(Locale.US)); final View topCenterOverlay = findViewById(R.id.topCenterOverlay); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); final View menuButton = findViewById(R.id.menu); if (menuButton != null) { menuButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { mDrawerLayout.openDrawer(GravityCompat.START); } }); } if (mDrawerLayout != null) { mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { private boolean menuButtonVisible = true; @Override public void onDrawerStateChanged(int newState) { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onDrawerSlide(final View drawerView, final float slideOffset) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setAlpha(1 - slideOffset); if (menuButtonVisible && menuButton != null && slideOffset > 0) { menuButton.setVisibility(View.INVISIBLE); menuButtonVisible = false; } } @Override public void onDrawerOpened(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.INVISIBLE); } @Override public void onDrawerClosed(final View drawerView) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) topCenterOverlay.setVisibility(View.VISIBLE); if (menuButton != null) { menuButton.setVisibility(View.VISIBLE); menuButtonVisible = true; } } }); } mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mMap == null) { Dialog d = GooglePlayServicesUtil .getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0); d.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finish(); } }); d.show(); return; } marker = BitmapDescriptorFactory.fromResource(R.drawable.marker); mMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker click) { addPoint(click.getPosition()); return true; } }); mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { if (mMap.getMyLocation() != null) { LatLng myLocation = new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude()); double distance = SphericalUtil.computeDistanceBetween(myLocation, mMap.getCameraPosition().target); // Only if the distance is less than 50cm we are on our location, add the marker if (distance < 0.5) { Toast.makeText(Map.this, R.string.marker_on_current_location, Toast.LENGTH_SHORT).show(); addPoint(myLocation); } } return false; } }); // check if open with csv file if (Intent.ACTION_VIEW.equals(getIntent().getAction())) { try { Util.loadFromFile(getIntent().getData(), this); if (!trace.isEmpty()) mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(trace.peek(), 16)); } catch (IOException e) { Toast.makeText(this, getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(final Bundle bundle) { Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (l != null && mMap.getCameraPosition().zoom <= 2) { mMap.moveCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 16)); } mGoogleApiClient.disconnect(); } @Override public void onConnectionSuspended(int cause) { } }).build(); mGoogleApiClient.connect(); valueTv = (TextView) findViewById(R.id.distance); updateValueText(); valueTv.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { if (type == MeasureType.DISTANCE) changeType(MeasureType.AREA); // only switch to elevation mode is an internet connection is // available and user has access to this feature else if (type == MeasureType.AREA && Util.checkInternetConnection(Map.this) && PRO_VERSION) changeType(MeasureType.ELEVATION); else changeType(MeasureType.DISTANCE); } }); View delete = findViewById(R.id.delete); delete.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { removeLast(); } }); delete.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(final View v) { AlertDialog.Builder builder = new AlertDialog.Builder(Map.this); builder.setMessage(getString(R.string.delete_all, trace.size())); builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clear(); dialog.dismiss(); } }); builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); return true; } }); mMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(final LatLng center) { addPoint(center); } }); // Drawer stuff ListView drawerList = (ListView) findViewById(R.id.left_drawer); drawerListAdapert = new DrawerListAdapter(this); drawerList.setAdapter(drawerListAdapert); drawerList.setDivider(null); drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, int position, long id) { switch (position) { case 0: // Search before Android 5.0 Dialogs.getSearchDialog(Map.this).show(); closeDrawer(); break; case 2: // Units Dialogs.getUnits(Map.this, distance, SphericalUtil.computeArea(trace)).show(); closeDrawer(); break; case 3: // distance changeType(MeasureType.DISTANCE); break; case 4: // area changeType(MeasureType.AREA); break; case 5: // elevation if (PRO_VERSION) { changeType(MeasureType.ELEVATION); } else { Dialogs.getElevationAccessDialog(Map.this, mService).show(); } break; case 7: // map changeView(GoogleMap.MAP_TYPE_NORMAL); break; case 8: // satellite changeView(GoogleMap.MAP_TYPE_HYBRID); break; case 9: // terrain changeView(GoogleMap.MAP_TYPE_TERRAIN); break; case 11: // save Dialogs.getSaveNShare(Map.this, trace).show(); closeDrawer(); break; case 12: // more apps try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (ActivityNotFoundException anf) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=j4velin")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 13: // about Dialogs.getAbout(Map.this).show(); closeDrawer(); break; default: break; } } }); changeView(prefs.getInt("mapView", GoogleMap.MAP_TYPE_NORMAL)); changeType(MeasureType.DISTANCE); // KitKat translucent decor enabled? -> Add some margin/padding to the // drawer and the map if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { int statusbar = Util.getStatusBarHeight(this); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) topCenterOverlay.getLayoutParams(); lp.setMargins(0, statusbar + 10, 0, 0); topCenterOverlay.setLayoutParams(lp); // on most devices and in most orientations, the navigation bar // should be at the bottom and therefore reduces the available // display height int navBarHeight = Util.getNavigationBarHeight(this); DisplayMetrics total, available; total = new DisplayMetrics(); available = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(available); API17Wrapper.getRealMetrics(getWindowManager().getDefaultDisplay(), total); boolean navBarOnRight = getResources() .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE && (total.widthPixels - available.widthPixels > 0); if (navBarOnRight) { // in landscape on phones, the navigation bar might be at the // right side, reducing the available display width mMap.setPadding(mDrawerLayout == null ? Util.dpToPx(this, 200) : 0, statusbar, navBarHeight, 0); drawerList.setPadding(0, statusbar + 10, 0, 0); if (menuButton != null) menuButton.setPadding(0, 0, 0, 0); } else { mMap.setPadding(0, statusbar, 0, navBarHeight); drawerList.setPadding(0, statusbar + 10, 0, 0); drawerListAdapert.setMarginBottom(navBarHeight); if (menuButton != null) menuButton.setPadding(0, 0, 0, navBarHeight); } } mMap.setMyLocationEnabled(true); PRO_VERSION |= prefs.getBoolean("pro", false); if (!PRO_VERSION) { bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND") .setPackage("com.android.vending"), mServiceConn, Context.BIND_AUTO_CREATE); } }