Skip to content

Commit

Permalink
我的行程 实现了 分页加载
Browse files Browse the repository at this point in the history
  • Loading branch information
gaolei committed Mar 5, 2017
1 parent 249084f commit bd2cece
Show file tree
Hide file tree
Showing 120 changed files with 4,342 additions and 40 deletions.
1 change: 1 addition & 0 deletions BiuBike/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions BiuBike/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions BiuBike/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ dependencies {
compile 'com.android.support:recyclerview-v7:25.0.0'
compile files('libs/baidumapapi_util_v4_1_1.jar')
compile files('libs/gson-2.2.1.jar')
compile project(':xrecyclerview')
}
23 changes: 15 additions & 8 deletions BiuBike/app/src/main/java/com/biubike/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public void onReceiveLocation(BDLocation bdLocation) {
mBaiduMap.setMyLocationData(locData);
currentLatitude = bdLocation.getLatitude();
currentLongitude = bdLocation.getLongitude();
current_addr.setText(bdLocation.getAddrStr());
currentLL = new LatLng(bdLocation.getLatitude(),
bdLocation.getLongitude());
startNodeStr = PlanNode.withLocation(currentLL);
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(bdLocation.getLatitude(),
Expand All @@ -225,11 +229,7 @@ public void onReceiveLocation(BDLocation bdLocation) {
changeLatitude = bdLocation.getLatitude();
changeLongitude = bdLocation.getLongitude();

currentLL = new LatLng(bdLocation.getLatitude(),
bdLocation.getLongitude());
startNodeStr = PlanNode.withLocation(currentLL);

current_addr.setText(bdLocation.getAddrStr());
if (!isServiceLive) {
addOverLayout(currentLatitude, currentLongitude);
}
Expand Down Expand Up @@ -373,7 +373,7 @@ public void onClick(View view) {
routeOverlay.removeFromMap();
Log.d("gaolei", "currentLatitude-----btn_locale--------" + currentLatitude);
Log.d("gaolei", "currentLongitude-----btn_locale--------" + currentLongitude);
startNodeStr = PlanNode.withLocation(currentLL);
// startNodeStr = PlanNode.withLocation(currentLL);
addOverLayout(currentLatitude, currentLongitude);
break;
case R.id.btn_refresh:
Expand Down Expand Up @@ -894,10 +894,17 @@ public LocationReceiver() {
public void onReceive(Context context, Intent intent) {
Log.d("gaolei", "onReceive-------location-------");
if (Utils.isTopActivity(context)) {
bike_time.setText(RouteService.totalTime + "分钟");
bike_distance.setText(RouteService.totalDistance + "米");
bike_price.setText(RouteService.totalPrice + "元");

String time = intent.getStringExtra("totalTime");
String distance = intent.getStringExtra("totalDistance");
String price = intent.getStringExtra("totalPrice");
bike_time.setText(time);
bike_distance.setText(distance);
bike_price.setText(price);
Log.d("gaolei", "MainActivity-------TopActivity---------true");
Log.d("gaolei", "MainActivity-------time:"+time);
Log.d("gaolei", "MainActivity-------distance:"+distance);
Log.d("gaolei", "MainActivity-------price:"+price);
} else {
Log.d("gaolei", "MainActivity-------TopActivity---------false");
}
Expand Down
131 changes: 110 additions & 21 deletions BiuBike/app/src/main/java/com/biubike/activity/MyRouteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

Expand All @@ -15,6 +14,8 @@
import com.biubike.base.BaseActivity;
import com.biubike.bean.RouteRecord;
import com.biubike.database.RouteDBHelper;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -25,31 +26,82 @@

public class MyRouteActivity extends BaseActivity implements MyRouteAdapter.OnItemClickListener {

RecyclerView routeRecyclerView;
XRecyclerView routeRecyclerView;
MyRouteAdapter routeAdapter;
List<RouteRecord> routeList;
String TABLE_NAME = "cycle_route";
int PageId = 0, PageSize = 10;
long itemCount = 0;
SQLiteDatabase db;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_route);
setStatusBar();
routeRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_route);
routeRecyclerView = (XRecyclerView) findViewById(R.id.recyclerview_route);
routeRecyclerView.setLayoutManager(new LinearLayoutManager(this));

routeList = getAllPoints();
if(routeList!=null) {
MyRouteAdapter routeAdapter = new MyRouteAdapter(this, routeList);
// routeList = getAllPoints();
routeList = new ArrayList<RouteRecord>();

RouteDBHelper helper = new RouteDBHelper(this);
db = helper.getWritableDatabase();
itemCount = getItemCount();
routeList = loadPage();
if (routeList != null) {
routeAdapter = new MyRouteAdapter(this, routeList);
routeRecyclerView.setAdapter(routeAdapter);
routeRecyclerView.addItemDecoration(new MyRouteDividerDecoration(10));

routeAdapter.setOnClickListener(this);
}

routeRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
routeRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallScale);
routeRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
routeRecyclerView.setPullRefreshEnabled(false);

// View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
// routeRecyclerView.addHeaderView(header);

routeRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
// Toast.makeText(MyRouteActivity.this, "onRefresh", Toast.LENGTH_SHORT).show();
routeRecyclerView.refreshComplete();
}

@Override
public void onLoadMore() {
// Toast.makeText(MyRouteActivity.this, "onLoadMore", Toast.LENGTH_SHORT).show();
loadPage();
routeRecyclerView.loadMoreComplete();
routeAdapter.notifyDataSetChanged();
}
});
}

@Override
public void onItemClick(View v, int position) {
Intent intent = new Intent(MyRouteActivity.this, RouteDetailActivity.class);
RouteRecord routeRecord = routeList.get(position);
// bundle.putParcelable("routeContent",routeRecord );
Log.d("gaolei", "getCycle_date------pass-------" + routeRecord.getCycle_date());
Log.d("gaolei", "getCycle_points----pass---------" + routeRecord.getCycle_points());
Bundle bundle = new Bundle();
bundle.putString("totalTime", routeRecord.getCycle_time());
bundle.putString("totalDistance", routeRecord.getCycle_distance());
bundle.putString("totalPrice", routeRecord.getCycle_price());
bundle.putString("routePoints", routeRecord.getCycle_points());
intent.putExtras(bundle);
startActivity(intent);
}

public List<RouteRecord> getAllPoints() {
String sql = "select * from cycle_route order by route_id DESC ";
RouteDBHelper helper = new RouteDBHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
routeList = new ArrayList<RouteRecord>();

Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
RouteRecord point = new RouteRecord();
Expand All @@ -69,19 +121,56 @@ public List<RouteRecord> getAllPoints() {
}


@Override
public void onItemClick(View v, int position) {
Intent intent = new Intent(MyRouteActivity.this, RouteDetailActivity.class);
RouteRecord routeRecord=routeList.get(position);
// bundle.putParcelable("routeContent",routeRecord );
Log.d("gaolei","getCycle_date------pass-------"+routeRecord.getCycle_date());
Log.d("gaolei","getCycle_points----pass---------"+routeRecord.getCycle_points());
Bundle bundle = new Bundle();
bundle.putString("totalTime", routeRecord.getCycle_time());
bundle.putString("totalDistance", routeRecord.getCycle_distance());
bundle.putString("totalPrice", routeRecord.getCycle_price());
bundle.putString("routePoints", routeRecord.getCycle_points());
intent.putExtras(bundle);
startActivity(intent);
/*
* 读取指定ID的分页数据
* SQL:Select * From TABLE_NAME Limit 9 Offset 10;
* 表示从TABLE_NAME表获取数据,跳过10行,取9行
*/
public List<RouteRecord> loadPage() {
if (routeList.size() >= itemCount) {
routeRecyclerView.setNoMore(true);
return null;
}
String sql = "select * from " + TABLE_NAME + " order by route_id DESC" +
" " + "limit " + String.valueOf(PageSize) + " offset " + PageId * PageSize;
Cursor cursor = db.rawQuery(sql, null);
Log.d("gaolei", "PageId--------------" + PageId);

Log.d("gaolei", "cursor.getCount()--------------" + cursor.getCount());
Log.d("gaolei", "routeList.size()--------------" + routeList.size());
Log.d("gaolei", "itemCount--------------" + itemCount);

while (cursor.moveToNext()) {
RouteRecord point = new RouteRecord();
point.setCycle_date(cursor.getString(cursor
.getColumnIndex("cycle_date")));
point.setCycle_time(cursor.getString(cursor
.getColumnIndex("cycle_time")));
point.setCycle_distance(cursor.getString(cursor
.getColumnIndex("cycle_distance")));
point.setCycle_price(cursor.getString(cursor
.getColumnIndex("cycle_price")));
point.setCycle_points(cursor.getString(cursor
.getColumnIndex("cycle_points")));
routeList.add(point);
}
PageId++;
cursor.close();
return routeList;

}

public long getItemCount() {
String sql = "select count(*) from " + TABLE_NAME;
Cursor cursor = db.rawQuery(sql, null);
cursor.moveToFirst();
long count = cursor.getLong(0);
cursor.close();
return count;
}

public void onDestroy() {
super.onDestroy();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.map.UiSettings;
import com.baidu.mapapi.model.LatLng;
import com.biubike.R;
import com.biubike.base.BaseActivity;
Expand Down Expand Up @@ -103,7 +104,6 @@ public void onCreate(Bundle savedInstanceState) {
}

private void initMap() {

mlocationClient = new LocationClient(this);
// mlistener = new MylocationListener();
// mlocationClient.registerLocationListener(mlistener);
Expand All @@ -123,6 +123,8 @@ private void initMap() {
if (!mlocationClient.isStarted()) {
mlocationClient.start();
}
UiSettings settings=routeBaiduMap.getUiSettings();
settings.setScrollGesturesEnabled(true);
}

public class MylocationListener implements BDLocationListener {
Expand Down Expand Up @@ -183,4 +185,6 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
return super.onKeyDown(keyCode, event);
}


}
20 changes: 12 additions & 8 deletions BiuBike/app/src/main/java/com/biubike/service/RouteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public class RouteService extends Service {
private MyLocationConfiguration.LocationMode locationMode;
AllInterface.IUpdateLocation iUpdateLocation;
public ArrayList<RoutePoint> routPointList = new ArrayList<RoutePoint>();
public static int totalDistance = 0;
public static float totalPrice = 0;
public static long beginTime = 0, totalTime = 0;
public int totalDistance = 0;
public float totalPrice = 0;
public long beginTime = 0, totalTime = 0;
Notification notification;
RemoteViews contentView;

Expand Down Expand Up @@ -249,15 +249,19 @@ public void onReceiveLocation(BDLocation bdLocation) {
}
}
}
Intent intent = new Intent("com.locationreceiver");
// Bundle bundle = new Bundle();
// bundle.putParcelable("location", bdLocation);

totalTime = (int) (System.currentTimeMillis() - beginTime) / 1000 / 60;
totalPrice = (float) (Math.floor(totalTime / 30) * 0.5 + 0.5);
// Log.d("gaolei", "biginTime--------------" + beginTime);
// Log.d("gaolei", "totalTime--------------" + totalTime);
// Log.d("gaolei", "totalDistance--------------" + totalDistance);
Log.d("gaolei", "totalTime--------------" + totalTime);
Log.d("gaolei", "totalDistance--------------" + totalDistance);
startNotifi(totalTime + "分钟", totalDistance + "米", totalPrice + "元");
Intent intent = new Intent("com.locationreceiver");
Bundle bundle = new Bundle();
bundle.putString("totalTime", totalTime + "分钟");
bundle.putString("totalDistance", totalDistance + "米");
bundle.putString("totalPrice", totalPrice + "元");
intent.putExtras(bundle);
sendBroadcast(intent);
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion BiuBike/app/src/main/res/layout/activity_my_route.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</RelativeLayout>
</LinearLayout>

<android.support.v7.widget.RecyclerView
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/recyclerview_route"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion BiuBike/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app'
include ':app', ':xrecyclerview'
1 change: 1 addition & 0 deletions BiuBike/xrecyclerview/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions BiuBike/xrecyclerview/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:design:25.0.0'

testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions BiuBike/xrecyclerview/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/gaolei/Work/Software/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Loading

0 comments on commit bd2cece

Please sign in to comment.