Permalink
Browse files

добавил импорт ТТ

  • Loading branch information...
1 parent 6c09519 commit c43216c8879238880dfaedec2225d526d01ecf9c @ookami-kb committed Apr 17, 2012
View
@@ -0,0 +1,2 @@
+bin/
+
View
@@ -5,6 +5,7 @@
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
+ <uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
@@ -20,6 +21,8 @@
</activity>
<activity android:name=".Salepoints"
android:label="Точки продаж"></activity>
+ <activity android:name=".SalepointDetails"
+ android:label="Точка продаж"></activity>
</application>
</manifest>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Deleted file not rendered
Deleted file not rendered
Deleted file not rendered
View
Binary file not shown.
@@ -0,0 +1,6 @@
+/** Automatically generated file. DO NOT MODIFY */
+package com.webgranula.prices;
+
+public final class BuildConfig {
+ public final static boolean DEBUG = true;
+}
@@ -14,18 +14,27 @@
public static final int ic_launcher=0x7f020000;
}
public static final class id {
- public static final int editText1=0x7f050001;
- public static final int editText2=0x7f050003;
- public static final int get_task=0x7f050004;
- public static final int textView1=0x7f050000;
- public static final int textView2=0x7f050002;
+ public static final int address=0x7f050002;
+ public static final int button1=0x7f05000a;
+ public static final int editText1=0x7f050004;
+ public static final int editText2=0x7f050006;
+ public static final int get_task=0x7f050007;
+ public static final int rowid=0x7f050000;
+ public static final int salepointAddress=0x7f050009;
+ public static final int salepointName=0x7f050008;
+ public static final int textView1=0x7f050003;
+ public static final int textView2=0x7f050005;
+ public static final int title=0x7f050001;
}
public static final class layout {
- public static final int main=0x7f030000;
- public static final int salepoints=0x7f030001;
+ public static final int item=0x7f030000;
+ public static final int main=0x7f030001;
+ public static final int salepoint_details=0x7f030002;
+ public static final int salepoints=0x7f030003;
}
public static final class string {
public static final int app_name=0x7f040001;
+ public static final int empty=0x7f040002;
public static final int hello=0x7f040000;
}
}
View
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal"
+ android:padding="10sp" >
+ <TextView
+ android:id = "@+id/rowid"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ <TextView
+ android:id = "@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/rowid" />
+ <TextView
+ android:id = "@+id/address"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@id/title" />
+</RelativeLayout>
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/salepointName"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Medium Text"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <TextView
+ android:id="@+id/salepointAddress"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Medium Text"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <Button
+ android:id="@+id/button1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Начать мониторинг" />
+
+</LinearLayout>
View
@@ -1,7 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
-<ListView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
-
-</ListView>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+ <!-- Note built-in ids for 'list' and 'empty' -->
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ <TextView
+ android:id="@android:id/empty"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/empty" />
+</LinearLayout>
View
@@ -3,5 +3,6 @@
<string name="hello">Hello World, PricesActivity!</string>
<string name="app_name">Prices</string>
+ <string name="empty">Нет доступных торговых точек</string>
</resources>
@@ -0,0 +1,11 @@
+package com.webgranula.prices;
+
+import android.provider.BaseColumns;
+
+public interface Constants extends BaseColumns {
+ public static final String TABLE_NAME = "salepoints";
+
+ // Columns in Salepoints table
+ public static final String TITLE = "title";
+ public static final String ADDRESS = "address";
+}
@@ -1,28 +1,122 @@
package com.webgranula.prices;
+import static com.webgranula.prices.Constants.ADDRESS;
+import static com.webgranula.prices.Constants.TABLE_NAME;
+import static com.webgranula.prices.Constants.TITLE;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
import android.app.Activity;
+import android.content.ContentValues;
import android.content.Intent;
+import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
public class PricesActivity extends Activity implements OnClickListener {
- /** Called when the activity is first created. */
+ private PricesData pricesData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
+ pricesData = new PricesData(this);
+
View getTaskBtn = findViewById(R.id.get_task);
getTaskBtn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.get_task:
+ // здесь надо импортировать все данные для текущего задания
+ // удаляем сохраненные ТТ
+ deleteSalepoints();
+ // импортируем ТТ
+ String getSalepointsJson = getSalepointsJson();
+
+ try {
+ JSONObject result = new JSONObject(getSalepointsJson);
+ JSONArray objects = result.getJSONArray("objects");
+ for (int i = 0; i < objects.length(); i++) {
+ JSONObject jsonObject = objects.getJSONObject(i);
+ String title = jsonObject.getString("name");
+ String address = jsonObject.getString("address");
+ float lat = (float)jsonObject.getDouble("latitude");
+ float lon = (float)jsonObject.getDouble("longitude");
+ addSalepoint(title, address, lat, lon);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Log.i("importer", "call activity");
Intent i = new Intent(this, Salepoints.class);
startActivity(i);
break;
}
}
+
+ private void deleteSalepoints() {
+ SQLiteDatabase db = pricesData.getWritableDatabase();
+ db.delete(TABLE_NAME, null, null);
+ db.close();
+ }
+
+ private void addSalepoint(String title, String address, float lat, float lon) {
+ // TODO: вставлять остальные данные для торговой точки
+ SQLiteDatabase db = pricesData.getWritableDatabase();
+ ContentValues values = new ContentValues();
+ values.put(TITLE, title);
+ values.put(ADDRESS, address);
+ db.insertOrThrow(TABLE_NAME, null, values);
+ db.close();
+ }
+
+ private String getSalepointsJson() {
+ StringBuilder builder = new StringBuilder();
+ // настраиваем загрузку JSON-объекта
+ HttpClient client = new DefaultHttpClient();
+ // TODO: подставлять имя пользователя и пароль из базы
+ HttpGet httpGet = new HttpGet(
+ "http://upload.v-zabote.ru/api/v1/salepoint/?format=json&username=test&password=test");
+ try {
+ HttpResponse response = client.execute(httpGet);
+ StatusLine statusLine = response.getStatusLine();
+ int statusCode = statusLine.getStatusCode();
+ if (statusCode == 200) {
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(content));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line);
+ }
+ } else {
+ Log.e(PricesActivity.class.toString(), "Failed to download file");
+ }
+
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return builder.toString();
+ }
}
@@ -0,0 +1,33 @@
+package com.webgranula.prices;
+
+import static android.provider.BaseColumns._ID;
+import static com.webgranula.prices.Constants.TABLE_NAME;
+import static com.webgranula.prices.Constants.TITLE;
+import static com.webgranula.prices.Constants.ADDRESS;
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+
+public class PricesData extends SQLiteOpenHelper {
+ private static final String DATABASE_NAME = "prices.db";
+ private static final int DATABASE_VERSION = 2;
+
+ public PricesData(Context ctx) {
+ super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ + " INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE
+ + " TEXT NOT NULL, " + ADDRESS + " TEXT, "
+ + "STATUS TEXT);");
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
+ onCreate(db);
+ }
+}
@@ -0,0 +1,52 @@
+package com.webgranula.prices;
+
+import static android.provider.BaseColumns._ID;
+import static com.webgranula.prices.Constants.TABLE_NAME;
+import android.app.Activity;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.widget.TextView;
+
+
+public class SalepointDetails extends Activity {
+ private long salepoint_id;
+ private PricesData pricesData;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.salepoint_details);
+
+ // вытаскиваем переданные параметры
+ // сейчас это только Salepoint ID
+ Bundle bundle = this.getIntent().getExtras();
+ salepoint_id = bundle.getLong("salepoint_id");
+
+ try {
+ pricesData = new PricesData(this);
+ getSalepointDetails();
+ } finally {
+ pricesData.close();
+ }
+ }
+
+ private void setActiveSalepoint() {
+ SQLiteDatabase db = pricesData.getReadableDatabase();
+ db.rawQuery("UPDATE " + TABLE_NAME + " SET status='monitoring' WHERE " + _ID + "=?", new String[] {Long.toString(salepoint_id)});
+ }
+
+ private Cursor getSalepointDetails() {
+ SQLiteDatabase db = pricesData.getReadableDatabase();
+ Cursor cursor = db.rawQuery("SELECT _id, title, address FROM " + TABLE_NAME + " where " + _ID + "=?", new String[] {Long.toString(salepoint_id)});
+ cursor.moveToFirst();
+
+ // устанавливаем значения в соответствии с выбранной торговой точкой
+ TextView spName = (TextView)findViewById(R.id.salepointName);
+ spName.setText(cursor.getString(1));
+ TextView spAddress = (TextView)findViewById(R.id.salepointAddress);
+ spAddress.setText(cursor.getString(2));
+
+ return cursor;
+ }
+}
Oops, something went wrong.

0 comments on commit c43216c

Please sign in to comment.