Skip to content

Commit 8be85a9

Browse files
committed
geo work
1 parent 5eea230 commit 8be85a9

11 files changed

Lines changed: 221 additions & 125 deletions

File tree

android/app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
1919
<!-- uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/-->
2020
<uses-permission android:name="android.permission.INTERNET"/>
21+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2122
<!-- Stop TTS on incoming call -->
2223
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
2324
<!-- Hide Android3 soft buttons on Archos -->
@@ -1179,6 +1180,15 @@
11791180
<action android:name="android.intent.action.PHONE_STATE" />
11801181
</intent-filter>
11811182
</receiver>
1183+
<provider
1184+
android:name=".GenericFileProvider"
1185+
android:authorities="org.coolreader.mod.plotn.fileprovider"
1186+
android:exported="false"
1187+
android:grantUriPermissions="true">
1188+
<meta-data
1189+
android:name="android.support.FILE_PROVIDER_PATHS"
1190+
android:resource="@xml/provider_paths"/>
1191+
</provider>
11821192
</application>
11831193

11841194
</manifest>

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
maven { url "https://jitpack.io" }
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.0'
11+
classpath 'com.android.tools.build:gradle:3.5.1'
1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
1414
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun Jun 02 13:21:41 MSK 2019
1+
#Wed Aug 21 20:36:45 MSK 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

android/res/values-ru/strings.xml

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@
963963
<string name="options_app_geo_add_info">Показывает всплывающее сообщение, когда вы находитесь рядом с остановками общественного транспорта или метро</string>
964964
<string name="options_app_geo_1">Выключено</string>
965965
<string name="options_app_geo_2">Показывать станции метро рядом</string>
966-
<string name="options_app_geo_2_add_info">Только Москва, Санкт-Петербург, Екатеринбург и Новосибирск</string>
966+
<string name="options_app_geo_2_add_info">Только в Москве, Санкт-Петербурге, Екатеринбурге и Новосибирске</string>
967967
<string name="options_app_geo_3">Показывать остановки общественного транспорта</string>
968968
<string name="options_app_geo_3_add_info">Только в Москве</string>
969969
<string name="options_app_geo_4">Показывать остановки и метро</string>

android/res/values/strings.xml

100755100644
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,11 @@
975975
<string name="options_app_geo_add_info">Allows to show popup window informing about transport stops and metro stations nearby</string>
976976
<string name="options_app_geo_1">Off</string>
977977
<string name="options_app_geo_2">Show metro stations nearby</string>
978-
<string name="options_app_geo_2_add_info">Only Moscow, St.Petersburg, Ekaterinburg and Novosibirsk</string>
978+
<string name="options_app_geo_2_add_info">Only in Moscow, St.Petersburg, Ekaterinburg and Novosibirsk</string>
979979
<string name="options_app_geo_3">Show transport stops</string>
980980
<string name="options_app_geo_3_add_info">Only in Moscow</string>
981981
<string name="options_app_geo_4">Show both</string>
982+
<string name="title_location_permission">Location permission</string>
983+
<string name="text_location_permission">Location permission is required, grant?</string>
984+
<string name="ok">Ok</string>
982985
</resources>

android/src/org/coolreader/CoolReader.java

100755100644
Lines changed: 41 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.coolreader.crengine.ReaderView;
6868
import org.coolreader.crengine.ReaderViewLayout;
6969
import org.coolreader.crengine.Services;
70+
import org.coolreader.crengine.Settings;
7071
import org.coolreader.crengine.StrUtils;
7172
import org.coolreader.crengine.TTS;
7273
import org.coolreader.crengine.TTS.OnTTSCreatedListener;
@@ -93,6 +94,7 @@
9394
import android.Manifest;
9495
import android.annotation.TargetApi;
9596
import android.app.Activity;
97+
import android.app.AlertDialog;
9698
import android.content.BroadcastReceiver;
9799
import android.content.ComponentName;
98100
import android.content.Context;
@@ -118,6 +120,8 @@
118120
import android.os.Bundle;
119121
import android.os.Debug;
120122
import android.os.Environment;
123+
import android.support.v4.app.ActivityCompat;
124+
import android.support.v4.content.ContextCompat;
121125
import android.support.v4.provider.DocumentFile;
122126
import android.view.LayoutInflater;
123127
import android.view.View;
@@ -145,6 +149,7 @@ public class CoolReader extends BaseActivity implements SensorEventListener
145149
public static final Logger log = L.create("cr");
146150

147151
public static int REQUEST_CODE_OPEN_DOCUMENT_TREE = 200001;
152+
public static int REQUEST_CODE_LOCATION_PERMISSION = 200002;
148153
public Uri sdCardUri = null;
149154
private FileInfo fileToDelete = null;
150155

@@ -1060,8 +1065,11 @@ protected void onResume() {
10601065
mSensorManager.registerListener(deviceOrientation.getEventListener(), accelerometer, SensorManager.SENSOR_DELAY_UI);
10611066
mSensorManager.registerListener(deviceOrientation.getEventListener(), magnetometer, SensorManager.SENSOR_DELAY_UI);
10621067

1063-
geoLastData.gps.start(geoLastData.geoListener);
1064-
geoLastData.netw.start(geoLastData.netwListener);
1068+
int iGeo = settings().getInt(Settings.PROP_APP_GEO, 0);
1069+
if (iGeo>1) {
1070+
geoLastData.gps.start(geoLastData.geoListener);
1071+
geoLastData.netw.start(geoLastData.netwListener);
1072+
}
10651073

10661074
if(mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).size()!=0){
10671075
Sensor s = mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
@@ -3200,107 +3208,40 @@ public void onUpdate(Location oldLoc, long oldTime, Location newLoc,
32003208
}
32013209

32023210
};
3203-
3204-
String s ="";
3205-
try {
3206-
InputStream is = getResources().openRawResource(R.raw.metro_coords);
3207-
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
3208-
String str = "";
3209-
while ((str = reader.readLine()) != null) s=s + " " +str;
3210-
is.close();
3211-
} catch (Exception e) {
3212-
// showToast("Could not parse genres from file: genres_rus.txt. "+
3213-
// e.getClass().getSimpleName()+" "+e.getMessage());
3214-
}
3215-
if (geoLastData.metroLocations == null) geoLastData.metroLocations = new ArrayList<MetroLocation>();
3216-
geoLastData.metroLocations.clear();
3217-
try {
3218-
JSONArray jsonA = new JSONArray(s);
3219-
if (jsonA != null) {
3220-
int i = 0;
3221-
while (i < jsonA.length()) {
3222-
JSONObject jso = (JSONObject) jsonA.get(i);
3223-
MetroLocation metroLocation = new MetroLocation();
3224-
if (jso.has("id")) { metroLocation.id = jso.getInt("id"); }
3225-
if (jso.has("name")) { metroLocation.name = jso.getString("name"); }
3226-
if (jso.has("url")) { metroLocation.url = jso.getString("url"); }
3227-
ArrayList<MetroLine> metroLines = null;
3228-
if (jso.has("lines")) {
3229-
JSONArray jsonL = jso.getJSONArray("lines");
3230-
metroLines = new ArrayList<MetroLine>();
3231-
int j = 0;
3232-
while (j < jsonL.length()) {
3233-
JSONObject jsoL = (JSONObject) jsonL.get(j);
3234-
MetroLine metroLine = new MetroLine();
3235-
if (jsoL.has("id")) { metroLine.id = jsoL.getInt("id"); }
3236-
if (jsoL.has("hex_color")) { metroLine.hexColor = jsoL.getString("hex_color"); }
3237-
if (jsoL.has("name")) { metroLine.name = jsoL.getString("name"); }
3238-
ArrayList<MetroStation> metroStations = null;
3239-
if (jsoL.has("stations")) {
3240-
JSONArray jsonS = jsoL.getJSONArray("stations");
3241-
metroStations = new ArrayList<MetroStation>();
3242-
int k = 0;
3243-
while (k < jsonS.length()) {
3244-
JSONObject jsoS = (JSONObject) jsonS.get(k);
3245-
MetroStation metroStation = new MetroStation();
3246-
if (jsoS.has("id")) { metroStation.id = jsoS.getDouble("id"); }
3247-
if (jsoS.has("name")) { metroStation.name = jsoS.getString("name"); }
3248-
if (metroStation.name.contains("окоссов")) geoLastData.tempStation = metroStation; // !!!!
3249-
if (jsoS.has("lat")) { metroStation.lat = jsoS.getDouble("lat"); }
3250-
if (jsoS.has("lng")) { metroStation.lon = jsoS.getDouble("lng"); }
3251-
if (jsoS.has("order")) { metroStation.order = jsoS.getInt("order"); }
3252-
metroStations.add(metroStation);
3253-
k++;
3254-
}
3255-
metroLine.metroStations = metroStations;
3256-
}
3257-
metroLines.add(metroLine);
3258-
j++;
3259-
}
3211+
int iGeo = settings().getInt(Settings.PROP_APP_GEO, 0);
3212+
if ((iGeo==2)||(iGeo==4)) geoLastData.loadMetroStations(this);
3213+
if ((iGeo==3)||(iGeo==4)) geoLastData.loadTransportStops(this);
3214+
if (iGeo>1) {
3215+
geoLastData.gps.start(geoLastData.geoListener);
3216+
geoLastData.netw.start(geoLastData.netwListener);
3217+
}
3218+
}
3219+
3220+
public boolean checkLocationPermission() {
3221+
if (ContextCompat.checkSelfPermission(this,
3222+
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
3223+
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
3224+
Manifest.permission.ACCESS_FINE_LOCATION)) {
3225+
new AlertDialog.Builder(this)
3226+
.setTitle(R.string.title_location_permission)
3227+
.setMessage(R.string.text_location_permission)
3228+
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
3229+
@Override
3230+
public void onClick(DialogInterface dialogInterface, int i) {
3231+
ActivityCompat.requestPermissions(CoolReader.this,
3232+
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
3233+
REQUEST_CODE_LOCATION_PERMISSION);
32603234
}
3261-
metroLocation.metroLines = metroLines;
3262-
geoLastData.metroLocations.add(metroLocation);
3263-
i++;
3264-
}
3265-
}
3266-
} catch (JSONException e) {
3267-
3268-
}
3269-
if (geoLastData.transportStops == null) geoLastData.transportStops = new ArrayList<TransportStop>();
3270-
geoLastData.transportStops.clear();
3271-
String sT ="";
3272-
try {
3273-
InputStream is = getResources().openRawResource(R.raw.data_398);
3274-
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "windows-1251"));
3275-
String str = "";
3276-
while ((str = reader.readLine()) != null) sT=sT + " " +str;
3277-
is.close();
3278-
} catch (Exception e) {
3279-
e.printStackTrace();
3280-
}
3281-
try {
3282-
JSONArray jsonA = new JSONArray(sT);
3283-
if (jsonA != null) {
3284-
int i = 0;
3285-
while (i < jsonA.length()) {
3286-
JSONObject jso = (JSONObject) jsonA.get(i);
3287-
TransportStop transportStop = new TransportStop();
3288-
if (jso.has("Street")) { transportStop.street = jso.getString("Street"); }
3289-
if (jso.has("Name")) { transportStop.name = jso.getString("Name"); }
3290-
if (jso.has("Latitude_WGS84")) { transportStop.lat = jso.getDouble("Latitude_WGS84"); }
3291-
if (jso.has("Longitude_WGS84")) { transportStop.lon = jso.getDouble("Longitude_WGS84"); }
3292-
if (jso.has("District")) { transportStop.district = jso.getString("District"); }
3293-
if (jso.has("RouteNumbers")) { transportStop.routeNumbers = jso.getString("RouteNumbers"); }
3294-
geoLastData.transportStops.add(transportStop);
3295-
geoLastData.tempStop = transportStop;
3296-
i++;
3297-
}
3235+
}).create().show();
3236+
} else {
3237+
ActivityCompat.requestPermissions(CoolReader.this,
3238+
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
3239+
REQUEST_CODE_LOCATION_PERMISSION);
32983240
}
3299-
} catch (JSONException e) {
3300-
3241+
return false;
3242+
} else {
3243+
return true;
33013244
}
3302-
geoLastData.gps.start(geoLastData.geoListener);
3303-
geoLastData.netw.start(geoLastData.netwListener);
33043245
}
33053246

33063247
}

android/src/org/coolreader/cloud/dropbox/DBXConfig.java

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import java.io.InputStreamReader;
2525

2626
public class DBXConfig {
27-
public static final String DBX_KEY = "put_yours";
28-
public static final String DBX_SECRET = "put_yours";
27+
public static final String DBX_KEY = "r8s8q13icp2fynx"; //"put_yours";
28+
public static final String DBX_SECRET = "ascdad2ohiix1em"; //"put_yours";
2929
public static final String DBX_REDIRECT_URL = "https://github.com/plotn/coolreader";
3030
public static DbxRequestConfig mDbxRequestConfig = null;
3131
public static DbxClientV2 mDbxClient = null;

android/src/org/coolreader/cloud/yandex/YNDConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import okhttp3.OkHttpClient;
2828

2929
public class YNDConfig {
30-
public static final String YND_ID = "put_yours";
31-
public static final String YND_PASSW = "put_yours";
30+
public static final String YND_ID = "da6aa587a2924b49b072cd5729fd03e2";//"put_yours";
31+
public static final String YND_PASSW = "c5f96c0876854504ba7420e4b2a44b7b";//"put_yours";
3232
public static final String YND_CALLBACK_URL = "https://yxda6aa587a2924b49b072cd5729fd03e2.oauth.yandex.ru/auth/finish?platform=android";
3333
public static final String YND_REDIRECT_URL = "https://github.com/plotn/coolreader/ynd";
3434
public static final String YND_AUTH_URL = "https://oauth.yandex.ru/authorize";

android/src/org/coolreader/crengine/OptionsDialog.java

100755100644
Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.coolreader.R;
1717
import org.coolreader.cloud.CloudSyncFolder;
1818
import org.coolreader.crengine.ColorPickerDialog.OnColorChangedListener;
19+
import org.coolreader.geo.MetroLocation;
20+
import org.coolreader.geo.TransportStop;
1921
import org.coolreader.plugins.OnlineStorePluginManager;
2022

2123
import android.app.SearchManager;
@@ -1105,16 +1107,44 @@ public LangOption(OptionOwner owner, String filter) {
11051107

11061108
class GeoOption extends ListOption {
11071109
public GeoOption(OptionOwner owner, String filter) {
1108-
super(owner, getString(R.string.options_app_locale), PROP_APP_LOCALE, getString(R.string.options_app_locale_add_info), filter);
1109-
for (Lang lang : Lang.values()) {
1110-
Locale l = lang.getLocale();
1111-
String s = "";
1112-
if (l!=null) s = lang.getLocale().getDisplayName();
1113-
add(lang.code, getString(lang.nameId), s);
1114-
}
1110+
super(owner, getString(R.string.options_app_geo), PROP_APP_GEO,
1111+
getString(R.string.options_app_geo_add_info), filter);
1112+
add("1", getString(R.string.options_app_geo_1),"");
1113+
add("2", getString(R.string.options_app_geo_2),getString(R.string.options_app_geo_2_add_info));
1114+
add("3", getString(R.string.options_app_geo_3),getString(R.string.options_app_geo_3_add_info));
1115+
add("4", getString(R.string.options_app_geo_4),"");
11151116
if ( mProperties.getProperty(property)==null )
1116-
mProperties.setProperty(property, Lang.DEFAULT.code);
1117-
this.updateFilteredMark(Lang.DEFAULT.code);
1117+
mProperties.setProperty(property, "1");
1118+
}
1119+
1120+
@Override
1121+
public void onClick( Three item ) {
1122+
super.onClick(item);
1123+
CoolReader cr = (CoolReader)mActivity;
1124+
if ((item.value.equals("2"))||(item.value.equals("3"))||(item.value.equals("4"))) {
1125+
if (cr.geoLastData != null) {
1126+
cr.geoLastData.gps.stop();
1127+
cr.geoLastData.netw.stop();
1128+
if ((item.value.equals("2")) || (item.value.equals("4")))
1129+
cr.geoLastData.loadMetroStations(cr);
1130+
if ((item.value.equals("3")) || (item.value.equals("4")))
1131+
cr.geoLastData.loadTransportStops(cr);
1132+
cr.geoLastData.gps.start(cr.geoLastData.geoListener);
1133+
cr.geoLastData.netw.start(cr.geoLastData.netwListener);
1134+
}
1135+
((CoolReader) mActivity).checkLocationPermission();
1136+
} else {
1137+
if (cr.geoLastData != null) {
1138+
cr.geoLastData.gps.stop();
1139+
cr.geoLastData.netw.stop();
1140+
if (cr.geoLastData.metroLocations == null)
1141+
cr.geoLastData.metroLocations = new ArrayList<MetroLocation>();
1142+
cr.geoLastData.metroLocations.clear();
1143+
if (cr.geoLastData.transportStops == null)
1144+
cr.geoLastData.transportStops = new ArrayList<TransportStop>();
1145+
cr.geoLastData.transportStops.clear();
1146+
}
1147+
}
11181148
}
11191149
}
11201150

@@ -2331,7 +2361,6 @@ public Three OnPreClick ( Three item ) {
23312361
public void onClick( Three item ) {
23322362
mProperties.setProperty(property, OnPreClick(item).value);
23332363
refreshList();
2334-
mActivity.showToast("asdf "+item.value);
23352364
if ( onChangeHandler!=null )
23362365
onChangeHandler.run();
23372366
if ( optionsListView!=null )
@@ -3299,13 +3328,9 @@ public OptionsListView( Context context, OptionBase root )
32993328
public boolean performItemClick(View view, int position, long id) {
33003329
if (mOptionsThis!=null) {
33013330
mOptionsThis.get(position).onSelect();
3302-
//asdf
3303-
mActivity.showToast(mOptionsThis.get(position).label);
33043331
}
33053332
else {
33063333
mOptions.get(position).onSelect();
3307-
//asdf
3308-
mActivity.showToast(mOptions.get(position).label);
33093334
}
33103335
return true;
33113336
}
@@ -4020,7 +4045,9 @@ public void onTabChanged(String tabId) {
40204045
mOptionsPage.add(new ListOption(this, getString(R.string.options_rounded_corners_margin), PROP_ROUNDED_CORNERS_MARGIN,
40214046
getString(R.string.options_rounded_corners_margin_add_info), filter).add(mRoundedCornersMargins).setDefaultValue("0")
40224047
.setIconIdByAttr(R.attr.attr_icons8_rounded_corners_margin, R.drawable.icons8_rounded_corners_margin));
4023-
mOptionsControls = new OptionsListView(getContext(), null);
4048+
mOptionsPage.add(new GeoOption(this, filter).
4049+
setIconIdByAttr(R.attr.cr3_button_more_drawable, R.drawable.cr3_button_more));
4050+
mOptionsControls = new OptionsListView(getContext(), null);
40244051
OptionBase kmO = new KeyMapOption(this, getString(R.string.options_app_key_actions),
40254052
getString(R.string.options_app_key_actions_add_info), filter).setIconIdByAttr(R.attr.cr3_option_controls_keys_drawable, R.drawable.cr3_option_controls_keys);
40264053
((KeyMapOption)kmO).updateFilterEnd();

android/src/org/coolreader/crengine/Settings.java

100755100644
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public interface Settings {
175175
public static final String PROP_APP_STARTUP_ACTION = "app.startup.action";
176176

177177
public static final String PROP_APP_PLUGIN_ENABLED = "app.plugin.enabled.litres";
178-
178+
179+
public static final String PROP_APP_GEO = "app.geo.locations";
179180

180181
// available options for PROP_APP_SELECTION_ACTION setting
181182
public static final int SELECTION_ACTION_TOOLBAR = 0;

0 commit comments

Comments
 (0)