Browse Source

代码更新

huyuguo 4 years ago
parent
commit
6583b0289e

+ 3 - 109
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

1772
    public void onLocationChanged(AMapLocation amapLocation) {
1772
    public void onLocationChanged(AMapLocation amapLocation) {
1773
1773
1774
        if (mListener != null && amapLocation != null) {
1774
        if (mListener != null && amapLocation != null) {
1775
            if (amapLocation != null
1775
            if (amapLocation != null && amapLocation.getErrorCode() == 0) {
1776
1777
                    && amapLocation.getErrorCode() == 0) {
1778
//                Log.e("---------------", "--------------");
1779
                try {
1776
                try {
1780
                    MainApplication.atCity = amapLocation.getCity().substring(0,
1777
                    MainApplication.atCity = amapLocation.getCity().substring(0, amapLocation.getCity().length() - 1);
1781
                            amapLocation.getCity().length() - 1);
1782
                    location_city = MainApplication.atCity;
1778
                    location_city = MainApplication.atCity;
1783
                    tv_atCity.setText(MainApplication.atCity);
1779
                    tv_atCity.setText(MainApplication.atCity);
1784
                } catch (NullPointerException e) {
1780
                } catch (NullPointerException e) {
1788
                center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
1784
                center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
1789
                MainApplication.center = center;
1785
                MainApplication.center = center;
1790
                ete("{\"fun\":\"timer\"}");
1786
                ete("{\"fun\":\"timer\"}");
1791
//                Log.e("!!!!!!!!!!!!!!!!!!!", "!!!!!!!!!!!!!!!!!!!!!!");
1792
                mlocationClient.stopLocation();
1787
                mlocationClient.stopLocation();
1793
//                Log.e("!@#$", amapLocation.getLatitude() + "```" + amapLocation.getLongitude());
1794
//                Toast.makeText(this, amapLocation.getAddress(), Toast.LENGTH_SHORT).show();
1795
//                Toast.makeText(this, amapLocation.getCity(), Toast.LENGTH_SHORT).show();
1796
//                ete("{\"fun\":\"timer\"}");
1797
1798
//                Log.e("123456==", url);
1799
                if (MainApplication.haveActivity == false) {
1788
                if (MainApplication.haveActivity == false) {
1800
                    getBaidu(amapLocation.getLongitude(), amapLocation.getLatitude());
1789
                    getBaidu(amapLocation.getLongitude(), amapLocation.getLatitude());
1801
                    String uid;
1790
                    String uid;
3970
3959
3971
            if (MainApplication.search_jing != 0.0 && MainApplication.search_wei != 0.0) {
3960
            if (MainApplication.search_jing != 0.0 && MainApplication.search_wei != 0.0) {
3972
                LatLng latLng = new LatLng(MainApplication.search_wei, MainApplication.search_jing);
3961
                LatLng latLng = new LatLng(MainApplication.search_wei, MainApplication.search_jing);
3973
                search_marker = aMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
3962
                search_marker = aMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_search_address))));
3974
                        .decodeResource(getResources(), R.drawable.icon_search_address))));
3975
                search_marker.setPeriod(8);
3963
                search_marker.setPeriod(8);
3976
            }
3964
            }
3977
            ete("{\"fun\":\"timer\"}");
3965
            ete("{\"fun\":\"timer\"}");
4452
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
4440
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
4453
        gg_lon = z * Math.cos(theta);
4441
        gg_lon = z * Math.cos(theta);
4454
        bg_jing = String.valueOf(gg_lon);
4442
        bg_jing = String.valueOf(gg_lon);
4455
//        Log.e("gg_lon",gg_lon+"");
4456
        gg_lat = z * Math.sin(theta);
4443
        gg_lat = z * Math.sin(theta);
4457
        bg_wei = String.valueOf(gg_lat);
4444
        bg_wei = String.valueOf(gg_lat);
4458
//        Log.e("gg_lat", gg_lat + "");
4459
    }
4445
    }
4460
4446
4461
4447
4482
            MainApplication.selectexpressway = ProfileManager.getInstance().getSelectExpressway(this);
4468
            MainApplication.selectexpressway = ProfileManager.getInstance().getSelectExpressway(this);
4483
            MainApplication.selectjingdian = ProfileManager.getInstance().getSelectJingdian(this);
4469
            MainApplication.selectjingdian = ProfileManager.getInstance().getSelectJingdian(this);
4484
            MainApplication.logid = ProfileManager.getInstance().getLogid(this);
4470
            MainApplication.logid = ProfileManager.getInstance().getLogid(this);
4485
//            Log.i("MainApplication.costWay", MainApplication.costWay);
4486
            MainApplication.messageToken = ProfileManager.getInstance().getKeyMessageToken(this);
4471
            MainApplication.messageToken = ProfileManager.getInstance().getKeyMessageToken(this);
4487
        }
4472
        }
4488
    }
4473
    }
4599
            String sql = "";
4584
            String sql = "";
4600
            if (level == 3) {
4585
            if (level == 3) {
4601
                sql = "SELECT count(*) as cnt,substr(poi_jing,0,4) as pjing,substr(poi_wei,0,3) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list where city != '1'" + MainApplication.sql + "GROUP BY pjing,pwei";
4586
                sql = "SELECT count(*) as cnt,substr(poi_jing,0,4) as pjing,substr(poi_wei,0,3) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list where city != '1'" + MainApplication.sql + "GROUP BY pjing,pwei";
4602
//                sql = "SELECT count(*) as cnt,substr(poi_jing,0,4) as pjing,substr(poi_wei,0,3) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list WHERE  suit_car = '国标'  AND  belong_attribute = '公共'  AND  ( status = '3' OR status = '4' )  AND  own_pay = '1'  AND  charge_cost_way = '可使用本APP扫码支付'  GROUP BY pjing,pwei";
4603
            } else if (level == 2) {
4587
            } else if (level == 2) {
4604
                sql = "SELECT count(*) as cnt,substr(poi_jing,0,6) as pjing,substr(poi_wei,0,5) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list where city != '1'" + MainApplication.sql + "GROUP BY pjing,pwei";
4588
                sql = "SELECT count(*) as cnt,substr(poi_jing,0,6) as pjing,substr(poi_wei,0,5) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list where city != '1'" + MainApplication.sql + "GROUP BY pjing,pwei";
4605
//                    sql="SELECT count(*) as cnt,substr(poi_jing,0,4) as pjing,substr(poi_wei,0,3) as pwei,avg(poi_jing) as pjing2,avg(poi_wei) as pwei2 FROM zhan_list WHERE  suit_car = '国标'  AND  belong_attribute = '公共'  AND  ( status = '3' OR status = '4' )  AND  own_pay = '1'  AND  charge_cost_way = '可使用本APP扫码支付'  GROUP BY pjing,pwei";
4606
            }
4589
            }
4607
//            Log.e("sql===", sql);
4608
            Cursor cursor = db.rawQuery(sql, null);
4590
            Cursor cursor = db.rawQuery(sql, null);
4609
            ZhanDB zhan_db;
4591
            ZhanDB zhan_db;
4610
            while (cursor.moveToNext()) {
4592
            while (cursor.moveToNext()) {
4614
                zhan_db.setPwei2(cursor.getString(cursor.getColumnIndex("pwei2")));
4596
                zhan_db.setPwei2(cursor.getString(cursor.getColumnIndex("pwei2")));
4615
                list_db.add(zhan_db);
4597
                list_db.add(zhan_db);
4616
            }
4598
            }
4617
//            Log.e("size===",list_db.size()+"");
4618
//            initOver(list_db);
4619
            cursor.close();
4599
            cursor.close();
4620
            db.endTransaction();
4600
            db.endTransaction();
4621
            db.close();
4601
            db.close();
4625
    }
4605
    }
4626
4606
4627
    private void delData(List<DataRefresh> list_del) {
4607
    private void delData(List<DataRefresh> list_del) {
4628
//        DaoMaster daoMaster = new DaoMaster(SQLiteDatabase.openOrCreateDatabase(getDatabasePath("zhan_list"), null));
4629
//        DaoSession daoSession = daoMaster.newSession();
4630
//        zhan_listDao = daoSession.getZhan_listDao();
4631
//        for (int i = 0 ;i<list_del.size();i++) {
4632
//
4633
//            zhan_list findUser = zhan_listDao.queryBuilder().where(com.electric.chargingpile.gen.zhan_listDao.Properties.Id.eq(list_del.get(i).getId())).build().unique();
4634
//            if (findUser != null) {
4635
//                zhan_listDao.deleteByKey();
4636
//            }
4637
//        }
4638
4608
4639
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4609
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4640
//        ZhanDBHelper dbHelper = new ZhanDBHelper(this);
4641
        try {
4610
        try {
4642
//            dbHelper.createDataBase();
4643
//            SQLiteDatabase db = dbHelper.getWritableDatabase();
4644
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4611
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4645
//            String sql ="DELETE from zhan_list where id = '"+dr.getId()+"'";
4646
            db.beginTransaction();//开始事务
4612
            db.beginTransaction();//开始事务
4647
//            Cursor cursor = null;
4648
            try {
4613
            try {
4649
                for (int i = 0; i < list_del.size(); i++) {
4614
                for (int i = 0; i < list_del.size(); i++) {
4650
//                    String sql ="DELETE from zhan_list where id = '"+list_del.get(i).getId()+"'";
4651
//                    db.execSQL(sql);
4652
//                    cursor = db.rawQuery(sql, null);
4653
                    String[] args = {String.valueOf(list_del.get(i).getId())};
4615
                    String[] args = {String.valueOf(list_del.get(i).getId())};
4654
//
4655
                    int mub = db.delete("zhan_list", "id=?", args);
4616
                    int mub = db.delete("zhan_list", "id=?", args);
4656
                    if (mub > 0) {
4617
                    if (mub > 0) {
4657
//                        Log.e(TAG, "删除成功");
4618
//                        Log.e(TAG, "删除成功");
4661
4622
4662
                }
4623
                }
4663
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4624
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4664
4665
4666
            } finally {
4625
            } finally {
4667
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4626
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4668
            }
4627
            }
4669
4670
//            cursor.close();
4671
            db.close();
4628
            db.close();
4672
        } catch (Exception e) {
4629
        } catch (Exception e) {
4673
            e.printStackTrace();
4630
            e.printStackTrace();
4676
4633
4677
    private void addData(List<DataRefresh> list_add) {
4634
    private void addData(List<DataRefresh> list_add) {
4678
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4635
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4679
//        ZhanDBHelper dbHelper = new ZhanDBHelper(this);
4680
        try {
4636
        try {
4681
//            dbHelper.createDataBase();
4682
//            SQLiteDatabase db = dbHelper.getWritableDatabase();
4683
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4637
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4684
            db.beginTransaction();//开始事务
4638
            db.beginTransaction();//开始事务
4685
//            Cursor cursor = null;
4686
            try {
4639
            try {
4687
                for (int i = 0; i < list_add.size(); i++) {
4640
                for (int i = 0; i < list_add.size(); i++) {
4688
//                    String sql ="INSERT INTO zhan_list (id,status,poi_jing,poi_wei,total_num,fast_num,slow_num,charge_cost_way," +
4689
//                            "belong_attribute,suit_car,own_pay,city) values ('"
4690
//                            +list_add.get(i).getId()+"','"+list_add.get(i).getStatus()+"','"+list_add.get(i).getPoi_jing()+"','"
4691
//                            +list_add.get(i).getPoi_wei()+"','"+list_add.get(i).getTotal_num()+"','"
4692
//                            +list_add.get(i).getFast_num()+"','"+list_add.get(i).getSlow_num()+"','"+list_add.get(i).getCharge_cost_way()+"','"
4693
//                            +list_add.get(i).getBelong_attribute()+"','"+list_add.get(i).getSuit_car()+
4694
//                            "','"+list_add.get(i).getOwn_pay()+"','"+list_add.get(i).getCity()+"')";
4695
////                    cursor = db.rawQuery(sql, null);
4696
//                    db.execSQL(sql);
4697
4698
                    ContentValues cv = new ContentValues();
4641
                    ContentValues cv = new ContentValues();
4699
                    cv.put("id", list_add.get(i).getId());
4642
                    cv.put("id", list_add.get(i).getId());
4700
                    cv.put("status", list_add.get(i).getStatus());
4643
                    cv.put("status", list_add.get(i).getStatus());
4713
                    long mub = db.insert("zhan_list", null, cv);
4656
                    long mub = db.insert("zhan_list", null, cv);
4714
                    if (mub > 0) {
4657
                    if (mub > 0) {
4715
                        Log.e(TAG, "添加成功");
4658
                        Log.e(TAG, "添加成功");
4716
//                        s++;
4717
                    } else {
4659
                    } else {
4718
                        Log.e(TAG, "添加失败---" + list_add.get(i).getId());
4660
                        Log.e(TAG, "添加失败---" + list_add.get(i).getId());
4719
//                        f++;
4720
                    }
4661
                    }
4721
4662
4722
                }
4663
                }
4723
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4664
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4724
4725
4726
            } finally {
4665
            } finally {
4727
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4666
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4728
            }
4667
            }
4729
//            cursor.close();
4730
            db.close();
4668
            db.close();
4731
        } catch (Exception e) {
4669
        } catch (Exception e) {
4732
            e.printStackTrace();
4670
            e.printStackTrace();
4735
4673
4736
    private void upData(List<DataRefresh> list_up) {
4674
    private void upData(List<DataRefresh> list_up) {
4737
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4675
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
4738
//        ZhanDBHelper dbHelper = new ZhanDBHelper(this);
4739
        try {
4676
        try {
4740
//            dbHelper.createDataBase();
4741
//            SQLiteDatabase db = dbHelper.getWritableDatabase();
4742
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4677
            SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
4743
//            String sql ="DELETE from zhan_list where id = '"+dr.getId()+"'";
4744
            db.beginTransaction();//开始事务
4678
            db.beginTransaction();//开始事务
4745
4746
//            Cursor cursor = null;
4747
            try {
4679
            try {
4748
                for (int i = 0; i < list_up.size(); i++) {
4680
                for (int i = 0; i < list_up.size(); i++) {
4749
//                    String sql ="UPDATE zhan_list SET status = '"+list_up.get(i).getStatus()+"',poi_jing = '"+list_up.get(i).getPoi_jing()+"',poi_wei = '"+list_up.get(i).getPoi_wei()+"',total_num = '"+list_up.get(i).getTotal_num()+"',fast_num = '"+list_up.get(i).getFast_num()+"',slow_num = '"+list_up.get(i).getSlow_num()+"',charge_cost_way = '"+list_up.get(i).getCharge_cost_way()+"',belong_attribute = '"+list_up.get(i).getBelong_attribute()+"',suit_car = '"+list_up.get(i).getSuit_car()+"',own_pay = '"+list_up.get(i).getOwn_pay()+"',city = '"+list_up.get(i).getCity()+"' where id = '"+list_up.get(i).getId()+"'";
4750
////                    cursor = db.rawQuery(sql, null);
4751
//                db.execSQL(sql);
4752
                    String[] args = {String.valueOf(list_up.get(i).getId())};
4681
                    String[] args = {String.valueOf(list_up.get(i).getId())};
4753
4754
                    ContentValues cv = new ContentValues();
4682
                    ContentValues cv = new ContentValues();
4755
                    cv.put("id", list_up.get(i).getId());
4683
                    cv.put("id", list_up.get(i).getId());
4756
                    cv.put("status", list_up.get(i).getStatus());
4684
                    cv.put("status", list_up.get(i).getStatus());
4775
4703
4776
                }
4704
                }
4777
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4705
                db.setTransactionSuccessful();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
4778
4779
4780
            } finally {
4706
            } finally {
4781
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4707
                db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务
4782
            }
4708
            }
4783
4784
//            cursor.close();
4785
            db.close();
4709
            db.close();
4786
        } catch (Exception e) {
4710
        } catch (Exception e) {
4787
            e.printStackTrace();
4711
            e.printStackTrace();
4809
        } catch (IOException e) {
4733
        } catch (IOException e) {
4810
            e.printStackTrace();
4734
            e.printStackTrace();
4811
        }
4735
        }
4812
//        Log.d("db_path", cacheFile.getAbsolutePath());
4813
        getZhanData();
4736
        getZhanData();
4814
        return cacheFile.getAbsolutePath();
4737
        return cacheFile.getAbsolutePath();
4815
    }
4738
    }
4835
        if (mClusterOverlay != null) {
4758
        if (mClusterOverlay != null) {
4836
            mClusterOverlay.onDestroy();
4759
            mClusterOverlay.onDestroy();
4837
        }
4760
        }
4838
//        DaoMaster.DevOpenHelper mHelper = new DaoMaster.DevOpenHelper(this, "zhan_list", null);
4839
//        SQLiteDatabase db = mHelper.getWritableDatabase();
4840
//        // 注意:该数据库连接属于 DaoMaster,所以多个 Session 指的是相同的数据库连接。
4841
//        DaoMaster mDaoMaster = new DaoMaster(db);
4842
//        DaoSession mDaoSession = mDaoMaster.newSession();
4843
//        MyOpenHelper helper = new MyOpenHelper(this, "zhan_list",
4844
//                null);
4845
//        DaoMaster daoMaster = new DaoMaster(helper.getWritableDatabase());
4846
4761
4847
        DaoMaster daoMaster = new DaoMaster(SQLiteDatabase.openOrCreateDatabase(getDatabasePath("zhan_list"), null));
4762
        DaoMaster daoMaster = new DaoMaster(SQLiteDatabase.openOrCreateDatabase(getDatabasePath("zhan_list"), null));
4848
        DaoSession mDaoSession = daoMaster.newSession();
4763
        DaoSession mDaoSession = daoMaster.newSession();
4849
//        DaoSession mDaoSession = MainApplication.getInstance().getDaoSession();
4850
        zhan_listDao = mDaoSession.getZhan_listDao();
4764
        zhan_listDao = mDaoSession.getZhan_listDao();
4851
4765
4852
//        final List<zhan_list> list = zhan_listDao.loadAll();
4853
//        new Thread(new Runnable() {
4854
//            @Override
4855
//            public void run() {
4856
//                LogUtils.e("add is begin");
4857
//                for (int i = 0;i<list.size();i++){
4858
//                    MainApplication.getInstance().getDaoSession().getZhan_listDao().insert(list.get(i));
4859
//
4860
//                }
4861
//                LogUtils.e("add is ok");
4862
//            }
4863
//        }).start();
4864
4865
//        MainApplication.getInstance().getDaoSession().getZhan_listDao().get
4866
4867
4868
//        zhan_lists = zhan_listDao.loadAll();
4869
        zhan_lists = zhan_listDao.queryRaw("where status = ? " + MainApplication.sql, new String[]{"4"});
4766
        zhan_lists = zhan_listDao.queryRaw("where status = ? " + MainApplication.sql, new String[]{"4"});
4870
        if (onResumeRefresh == true) {
4767
        if (onResumeRefresh == true) {
4871
            ToastUtil.showToast(getApplicationContext(), "共" + zhan_lists.size() + "个符合条件的站点", Toast.LENGTH_SHORT);
4768
            ToastUtil.showToast(getApplicationContext(), "共" + zhan_lists.size() + "个符合条件的站点", Toast.LENGTH_SHORT);
4872
//            isShow = false;
4873
        }
4769
        }
4874
//        Log.e(TAG, "getZhanData===" + zhan_lists.size());
4875
4876
        new Thread() {
4770
        new Thread() {
4877
            public void run() {
4771
            public void run() {
4878
                List<ClusterItem> items = new ArrayList<ClusterItem>();
4772
                List<ClusterItem> items = new ArrayList<ClusterItem>();

+ 96 - 29
app/src/main/java/com/electric/chargingpile/activity/SearchActivity.java

15
import android.text.Html;
15
import android.text.Html;
16
import android.text.TextUtils;
16
import android.text.TextUtils;
17
import android.text.TextWatcher;
17
import android.text.TextWatcher;
18
import android.util.Log;
19
import android.view.KeyEvent;
18
import android.view.KeyEvent;
20
import android.view.LayoutInflater;
19
import android.view.LayoutInflater;
21
import android.view.View;
20
import android.view.View;
42
import com.amap.api.services.poisearch.PoiResult;
41
import com.amap.api.services.poisearch.PoiResult;
43
import com.amap.api.services.poisearch.PoiSearch;
42
import com.amap.api.services.poisearch.PoiSearch;
44
import com.amap.api.services.poisearch.PoiSearch.OnPoiSearchListener;
43
import com.amap.api.services.poisearch.PoiSearch.OnPoiSearchListener;
44
import com.electric.chargingpile.BuildConfig;
45
import com.electric.chargingpile.R;
45
import com.electric.chargingpile.R;
46
import com.electric.chargingpile.application.MainApplication;
46
import com.electric.chargingpile.application.MainApplication;
47
import com.electric.chargingpile.data.HistoryInfo;
47
import com.electric.chargingpile.data.HistoryInfo;
48
import com.electric.chargingpile.data.RecommendZhan;
48
import com.electric.chargingpile.manager.ProfileManager;
49
import com.electric.chargingpile.manager.ProfileManager;
49
import com.electric.chargingpile.util.BarColorUtil;
50
import com.electric.chargingpile.util.BarColorUtil;
50
import com.electric.chargingpile.util.DBOpenHandler;
51
import com.electric.chargingpile.util.DBOpenHandler;
52
import com.electric.chargingpile.util.DES3S;
53
import com.electric.chargingpile.util.JsonUtils;
51
import com.umeng.analytics.MobclickAgent;
54
import com.umeng.analytics.MobclickAgent;
55
import com.zhy.http.okhttp.OkHttpUtils;
56
import com.zhy.http.okhttp.callback.StringCallback;
52

57

53
import java.util.ArrayList;
58
import java.util.ArrayList;
54
import java.util.HashMap;
59
import java.util.HashMap;
55
import java.util.List;
60
import java.util.List;
56
import java.util.Map;
61
import java.util.Map;
57

62

63
import okhttp3.Call;
64

58
public class SearchActivity extends Activity implements OnClickListener, Inputtips.InputtipsListener, OnPoiSearchListener {
65
public class SearchActivity extends Activity implements OnClickListener, Inputtips.InputtipsListener, OnPoiSearchListener {
59
    private TextView tvSearch;
66
    private TextView tvSearch;
60
    private Toast toast = null;
67
    private Toast toast = null;
67
    private List<HistoryInfo> historyInfoList = new ArrayList<HistoryInfo>();
74
    private List<HistoryInfo> historyInfoList = new ArrayList<HistoryInfo>();
68
    private HistoryInfo history;
75
    private HistoryInfo history;
69

76

77
    private List<RecommendZhan> pointList = new ArrayList<>();
78
    private List<RecommendZhan> pointFullList = new ArrayList<>();
79

70
    private Map<String, String> map;
80
    private Map<String, String> map;
71

81

72
    private View convertView = null;
82
    private View convertView = null;
126
                historyList.setAdapter(adapter);
136
                historyList.setAdapter(adapter);
127
            }
137
            }
128
        });
138
        });
129
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
139

130
            @Override
131
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
132
                imm.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
133
                return true;
134
            }
135
        });
136
        etSearch.addTextChangedListener(new TextWatcher() {
140
        etSearch.addTextChangedListener(new TextWatcher() {
137
            @Override
141
            @Override
138
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
142
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
140

144

141
            @Override
145
            @Override
142
            public void onTextChanged(CharSequence s, int start, int before, int count) {
146
            public void onTextChanged(CharSequence s, int start, int before, int count) {
143
                String newText = s.toString().trim();
147
                if (TextUtils.isEmpty(s.toString().trim())) {
144
                if (!TextUtils.isEmpty(newText)) {
145
                    keyWord = newText;
146
                    doSearchQuery();
147
                    lvContent.setVisibility(View.VISIBLE);
148
                    historyList.setVisibility(View.GONE);
149
                    ivClear.setVisibility(View.VISIBLE);
150
                } else {
151
                    addressList.clear();
152
                    addressAllList.clear();
153
                    historyList.setVisibility(View.VISIBLE);
154
                    lvContent.setVisibility(View.GONE);
155
                    ivClear.setVisibility(View.GONE);
148
                    ivClear.setVisibility(View.GONE);
149
                } else {
150
                    ivClear.setVisibility(View.VISIBLE);
156
                }
151
                }
157
            }
152
            }
158

153

160
            public void afterTextChanged(Editable s) {
155
            public void afterTextChanged(Editable s) {
161
            }
156
            }
162
        });
157
        });
158

163
        etSearch.setOnKeyListener(new OnKeyListener() {
159
        etSearch.setOnKeyListener(new OnKeyListener() {
164
            @Override
160
            @Override
165
            public boolean onKey(View v, int keyCode, KeyEvent event) {
161
            public boolean onKey(View v, int keyCode, KeyEvent event) {
166
                if (keyCode == KeyEvent.KEYCODE_ENTER
162
                if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { // 点击搜索键进行搜索。
167
                        && event.getAction() == KeyEvent.ACTION_DOWN) { // 点击搜索键进行搜索。
168
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
163
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
169
                    if (imm.isActive()) {
164
                    if (imm.isActive()) {
170
                        View view = getWindow().peekDecorView();
165
                        View view = getWindow().peekDecorView();
172
                            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
167
                            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
173
                        }
168
                        }
174
                    }
169
                    }
175
                    if (TextUtils.isEmpty(etSearch.getText().toString().trim())) {
170
                    String s = etSearch.getText().toString().trim();
176
                        Toast.makeText(SearchActivity.this, "搜索内容不能为空",
171
                    if (TextUtils.isEmpty(s)) {
177
                                Toast.LENGTH_SHORT).show();
172
                        Toast.makeText(SearchActivity.this, "搜索内容不能为空", Toast.LENGTH_SHORT).show();
173
                        addressList.clear();
174
                        addressAllList.clear();
175
                        historyList.setVisibility(View.VISIBLE);
176
                        lvContent.setVisibility(View.GONE);
178
                    } else {
177
                    } else {
178
                        keyWord = s;
179
                        doSearchQuery();
180
                        doPointNameSearchQuery();
181
                        lvContent.setVisibility(View.VISIBLE);
182
                        historyList.setVisibility(View.GONE);
183

184
                        System.out.println("hello www");
179
                    }
185
                    }
180
                    return true;
186
                    return true;
181
                }
187
                }
183
            }
189
            }
184
        });
190
        });
185
        String search_address = ProfileManager.getInstance().getSearchAddress(this);
191
        String search_address = ProfileManager.getInstance().getSearchAddress(this);
186
        if (search_address.equals("")) {
192
        if (TextUtils.isEmpty(search_address)) {
187
            etSearch.setText("");
193
            etSearch.setText("");
194
            etSearch.setSelection(etSearch.getText().length());
195

196
            addressList.clear();
197
            addressAllList.clear();
198
            historyList.setVisibility(View.VISIBLE);
199
            lvContent.setVisibility(View.GONE);
200
            ivClear.setVisibility(View.GONE);
188
        } else {
201
        } else {
189
            etSearch.setText(search_address);
202
            etSearch.setText(search_address);
190
            etSearch.setSelection(etSearch.getText().length());
204
            keyWord = search_address;
205
            doSearchQuery();
206
            doPointNameSearchQuery();
207
            lvContent.setVisibility(View.VISIBLE);
208
            historyList.setVisibility(View.GONE);
209
            ivClear.setVisibility(View.VISIBLE);
191
        }
210
        }
192

211

193
        lvContent.setOnScrollListener(new AbsListView.OnScrollListener() {
212
        lvContent.setOnScrollListener(new AbsListView.OnScrollListener() {
412

431

413
                            for (Map<String, String> address : addressAllList) {
432
                            for (Map<String, String> address : addressAllList) {
414
                                addressList.add(address);
433
                                addressList.add(address);
415
                                if (addressList.size() == 5) {
434
                                if (addressList.size() >= 5) {
416
                                    break;
435
                                    break;
417
                                }
436
                                }
418
                            }
437
                            }
509
                viewHolder.query_all_addresses.setOnClickListener(new View.OnClickListener() {
528
                viewHolder.query_all_addresses.setOnClickListener(new View.OnClickListener() {
510

529

511
                    @Override
530
                    @Override
512
                    public void onClick(View v) {
531
                    public void onClick(View v) { // 查看所有
513
                        // TODO by hyg add
532
                        // TODO by hyg add
514
                    }
533
                    }
515
                });
534
                });
521
        class ViewHolder {
540
        class ViewHolder {
522
            TextView name, address, header_title, query_all_addresses;
541
            TextView name, address, header_title, query_all_addresses;
523
        }
542
        }
543

524
    }
544
    }
525

545

526
    @Override
546
    @Override
560
        poiSearch.setOnPoiSearchListener(this);
580
        poiSearch.setOnPoiSearchListener(this);
561
        poiSearch.searchPOIAsyn();
581
        poiSearch.searchPOIAsyn();
562
    }
582
    }
583

584
    private void doPointNameSearchQuery() {
585
        double longitude = 0;
586
        double latitude = 0;
587
        if (MainApplication.center != null) {
588
            longitude = MainApplication.center.longitude;
589
            latitude = MainApplication.center.latitude;
590
        }
591
        String url = MainApplication.url + "/zhannew/basic/web/index.php/name_search?city=" + MainApplication.atCity + "&poi_jing=" + longitude + "&poi_wei=" + latitude + "&version=" + MainApplication.current_code + "&zhan_name=" + keyWord + "&version_code=" + BuildConfig.VERSION_CODE;
592
        OkHttpUtils.get().url(url).build().readTimeOut(30000).connTimeOut(30000).execute(new StringCallback() {
593
            @Override
594
            public void onError(Call call, Exception e) {
595
                e.printStackTrace();
596
            }
597

598
            @Override
599
            public void onResponse(String response) {
600
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
601
                if ("0".equals(rtnCode)) {
602
                    String data = JsonUtils.getKeyResult(response, "data");
603

604
                    String info_decode = "";
605
                    try {
606
                        info_decode = DES3S.decode(data);
607
                    } catch (Exception e) {
608
                        e.printStackTrace();
609
                    }
610
                    if (null != info_decode && !info_decode.equals("")) {
611
                        pointFullList.clear();
612
                        pointList.clear();
613

614
                        List<RecommendZhan> list = JsonUtils.parseToObjectList(info_decode, RecommendZhan.class);
615
                        pointFullList.addAll(list);
616

617
                        for (RecommendZhan point : pointFullList) {
618
                            pointList.add(point);
619
                            if (pointList.size() >= 3) {
620
                                break;
621
                            }
622
                        }
623
                        System.out.println(info_decode);
624
                    }
625
                }
626
            }
627
        });
628

629
    }
563
}
630
}

+ 1 - 1
app/src/main/java/com/electric/chargingpile/application/MainApplication.java

119
    public static boolean isIgnore = true;
119
    public static boolean isIgnore = true;
120
    public static Double search_jing = 0.0, search_wei = 0.0;
120
    public static Double search_jing = 0.0, search_wei = 0.0;
121
    public static Context context;
121
    public static Context context;
122
    public static String current_code = "3.3";
122
    public static String current_code = "3.5";
123
    public static String storePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "cdz_android";
123
    public static String storePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "cdz_android";
124
    public static String q_content = "";
124
    public static String q_content = "";
125
    public static Map<String, String> q_map = new HashMap<>();
125
    public static Map<String, String> q_map = new HashMap<>();

+ 2 - 1
app/src/main/java/com/electric/chargingpile/util/DES3S.java

17
public class DES3S {
17
public class DES3S {
18
    // 密钥
18
    // 密钥
19
//    private final static String secretKey = "D1EVD1EVD1EVD1EVD1EVD1EV" ;
19
//    private final static String secretKey = "D1EVD1EVD1EVD1EVD1EVD1EV" ;
20
    private final static String secretKey = "W4DSE3DK5J7HEGS7D6F9G5GF";
20
//    private final static String secretKey = "W4DSE3DK5J7HEGS7D6F9G5GF";
21
    private final static String secretKey = "W4DSE3DK599HEGS7D6F9G5GF";
21
    // 向量
22
    // 向量
22
    private final static String iv = "01234567";
23
    private final static String iv = "01234567";
23
    // 加解密统一使用的编码方式
24
    // 加解密统一使用的编码方式

+ 1 - 0
app/src/main/res/layout/activity_search.xml

36
                android:hint="请输入要查找的地名"
36
                android:hint="请输入要查找的地名"
37
                android:imeOptions="actionSearch"
37
                android:imeOptions="actionSearch"
38
                android:singleLine="true"
38
                android:singleLine="true"
39
                android:text=""
39
                android:textColorHint="@color/ui_68"
40
                android:textColorHint="@color/ui_68"
40
                android:textCursorDrawable="@drawable/search_biao"
41
                android:textCursorDrawable="@drawable/search_biao"
41
                android:textSize="14sp" />
42
                android:textSize="14sp" />

+ 11 - 19
app/src/main/res/layout/item_clear.xml

1
<?xml version="1.0" encoding="utf-8"?>
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:orientation="vertical" android:layout_width="match_parent"
4
    android:layout_height="wrap_content">
5
6
7
    <!--<View-->
8
    <!--android:layout_width="match_parent"-->
9
    <!--android:layout_height="0.5dp"-->
10
    <!--android:background="#dddddd"/>-->
11
12
13
    <TextView
14
    android:id="@+id/tv_historyClear"
15
    android:layout_width="match_parent"
3
    android:layout_width="match_parent"
16
    android:layout_height="45dp"
4
    android:layout_height="wrap_content"
17
    android:background="@color/white"
5
    android:orientation="vertical">
18
    android:text="清除历史记录"
19
    android:textColor="@color/hintColor"
20
    android:gravity="center"
21
    android:textSize="15sp"/>
22
23
6
7
    <TextView
8
        android:id="@+id/tv_historyClear"
9
        android:layout_width="match_parent"
10
        android:layout_height="45dp"
11
        android:background="@color/white"
12
        android:gravity="center"
13
        android:text="清除历史记录"
14
        android:textColor="@color/hintColor"
15
        android:textSize="15sp" />
24
16
25
</LinearLayout>
17
</LinearLayout>