Архив рубрики: Android

Загрузка данных на сервер в асинхронном режиме Android Studio

private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {//функция формирования POST данных для отправки на сервер StringBuilder result = new StringBuilder(); boolean first = true; for(Map.Entry<String, String> entry : params.entrySet()){ if (first) first = false; else result.append(«&»); result.append(URLEncoder.encode(entry.getKey(), «UTF-8»)); result.append(«=»); result.append(URLEncoder.encode(entry.getValue(), «UTF-8»)); } return result.toString();//возвращаем сформированную строку для POST данных которые будут отправляться на сервер rateandshare.kz… Читать далее »

Android studio Проект по работе с картой. Геолокация.

package com.example.admin.myapplication; import android.Manifest; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapView; import com.google.android.gms.maps.MapsInitializer; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; public class MainActivity extends AppCompatActivity { GoogleMap googleMap;//объект гугл карты MapView mMapView;//объект для отображения карты static double TARGET_LATITUDE = 49.8240877;//координаты на карте static double TARGET_LONGITUDE = 72.8887742; @Override protected… Читать далее »

Асинхронная загрузка веб страницы в Android studio

private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String… params) { URL url = null; String response = «»; String requestURL=»https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22karagandy%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys»; try { url = new URL(requestURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(15000); conn.setConnectTimeout(15000); conn.setRequestMethod(«GET»); int responseCode=conn.getResponseCode(); if (responseCode == HttpsURLConnection.HTTP_OK) { String line; BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line=br.readLine()) != null)… Читать далее »

Код прогноза погоды в JSON формате

{ «query»: { «count»: 1, «created»: «2016-04-02T10:13:17Z», «lang»: «ru-RU», «results»: { «channel»: { «units»: { «distance»: «mi», «pressure»: «in», «speed»: «mph», «temperature»: «F» }, «title»: «Yahoo! Weather — Qaraghandy, KZ», «link»: «http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-20070178/», «description»: «Yahoo! Weather for Qaraghandy, KZ», «language»: «en-us», «lastBuildDate»: «Sat, 02 Apr 2016 04:13 PM ALMT», «ttl»: «60», «location»: { «city»: «Qaraghandy», «country»:… Читать далее »

Асинхронная загрузка веб страницы в Android Studio

private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String… urls) { String response = «»; for (String url : urls) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse execute = client.execute(httpGet); InputStream content = execute.getEntity().getContent(); BufferedReader buffer = new BufferedReader( new InputStreamReader(content)); String s = «»;… Читать далее »

Коды на прогноз погоды от Yahoo

Прогноз погоды в XML JSON форматах https://developer.yahoo.com/weather/ 0-tornado-Торнадо-5 1-tropical storm-Шторм-7 2-hurricane-Ураган-5 3-severe thunderstorms-Сильная гроза-7 4-thunderstorms-Сильный шторм-7 5-mixed rain and snow-Снег с дождем-5 6-mixed rain and sleet-Дождь и мокрый снег-4 7-mixed snow and sleet-Снег и мокрый снег-6 8-freezing drizzle-Изморозь-6 9-drizzle-Изморозь-6 10-freezing rain-град-4 11-showers-Ливень-4 12-showers-Ливень-4 13-snow flurries-Снег-6 14-light snow showers-Снег-6 15-blowing snow-Снег-6 16-snow-Снег-6 17-hail-Град-5 18-sleet-Мокрый снег-6 19-dust-Пыль-2… Читать далее »

Меню XML для пятнашек

<?xml version=»1.0″ encoding=»utf-8″?> <menu xmlns:android=»http://schemas.android.com/apk/res/android» xmlns:tools=»http://schemas.android.com/tools» tools:context=».MainActivity»> <item android:id=»@+id/action_menu» android:title=»menu»> <menu > <item android:id=»@+id/menu_item1″ android:title=»Новая игра»></item> <item android:id=»@+id/menu_item2″ android:title=»Выход»></item> </menu> </item> </menu>

Пятнашки на Андроид последняя версия

package sunshine.ikurs.kz.myapplication; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.google.android.gms.appindexing.Action; import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.common.api.GoogleApiClient; import java.util.Random; public class MainActivity extends AppCompatActivity { //Объявляем массив кнопок Button[] B; /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information.… Читать далее »

Код XML для пятнашек на Андроид

<?xml version=»1.0″ encoding=»utf-8″?> <RelativeLayout xmlns:android=»http://schemas.android.com/apk/res/android» xmlns:tools=»http://schemas.android.com/tools» android:layout_width=»match_parent» android:layout_height=»match_parent» android:paddingBottom=»@dimen/activity_vertical_margin» android:paddingLeft=»@dimen/activity_horizontal_margin» android:paddingRight=»@dimen/activity_horizontal_margin» android:paddingTop=»@dimen/activity_vertical_margin» tools:context=»sunshine.ikurs.kz.myapplication.MainActivity»> <TableLayout android:layout_width=»match_parent» android:layout_height=»match_parent» android:layout_alignParentTop=»true» android:layout_centerHorizontal=»true»> <TableRow android:layout_width=»match_parent» android:layout_height=»match_parent» android:layout_weight=».25″> <Button android:layout_width=»fill_parent» android:layout_height=»fill_parent» android:text=»1″ android:tag=»1″ android:id=»@+id/button1″ android:layout_column=»0″ android:layout_weight=».25″ android:onClick=»buttonOnClick» android:textSize=»26sp» /> <Button android:layout_width=»fill_parent» android:layout_height=»fill_parent» android:text=»2″ android:tag=»2″ android:id=»@+id/button2″ android:layout_column=»1″ android:layout_weight=».25″ android:textSize=»26sp» android:onClick=»buttonOnClick» /> <Button android:layout_width=»fill_parent» android:layout_height=»fill_parent» android:text=»3″ android:tag=»3″ android:id=»@+id/button3″ android:layout_column=»2″ android:layout_weight=».25″ android:textSize=»26sp» android:onClick=»buttonOnClick» />… Читать далее »

Код для пятнашек на Андроид

package sunshine.ikurs.kz.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { //Объявляем массив кнопок Button [] B; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Создаем массив кнопок. B=new Button[16]; //Записываем кнопки в массив. B[0]=(Button)findViewById(R.id.button1); B[1]=(Button)findViewById(R.id.button2); B[2]=(Button)findViewById(R.id.button3); B[3]=(Button)findViewById(R.id.button4); B[4]=(Button)findViewById(R.id.button5); B[5]=(Button)findViewById(R.id.button6); B[6]=(Button)findViewById(R.id.button7); B[7]=(Button)findViewById(R.id.button8); B[8]=(Button)findViewById(R.id.button9); B[9]=(Button)findViewById(R.id.button10); B[10]=(Button)findViewById(R.id.button11); B[11]=(Button)findViewById(R.id.button12); B[12]=(Button)findViewById(R.id.button13); B[13]=(Button)findViewById(R.id.button14); B[14]=(Button)findViewById(R.id.button15); B[15]=(Button)findViewById(R.id.button16);… Читать далее »