mirror of
https://github.com/Findus23/kurzparkzonen-wien.git
synced 2024-09-18 14:53:48 +02:00
add Settings to App
This commit is contained in:
parent
6bd9f304a6
commit
baa4af8bfd
14 changed files with 276 additions and 24 deletions
1
android/.gitignore
vendored
1
android/.gitignore
vendored
|
@ -8,3 +8,4 @@
|
|||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
app/release/
|
||||
|
|
|
@ -6,8 +6,8 @@ android {
|
|||
applicationId "at.lw1.kurzparkzonen.wien"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 3
|
||||
versionName "0.0.1"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -22,8 +22,10 @@ dependencies {
|
|||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
implementation 'com.android.support:support-v4:27.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
implementation 'io.sentry:sentry-android:1.7.5'
|
||||
}
|
||||
|
|
|
@ -13,14 +13,17 @@
|
|||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="false"
|
||||
android:theme="@style/AppTheme.Launcher"
|
||||
android:usesCleartextTraffic="false"
|
||||
tools:targetApi="m">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:label="@string/app_name" android:name=".MyPreferencesActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,109 @@
|
|||
package at.lw1.kurzparkzonen.wien;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
|
||||
* to be used with AppCompat.
|
||||
*/
|
||||
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
private AppCompatDelegate mDelegate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getDelegate().installViewFactory();
|
||||
getDelegate().onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
getDelegate().onPostCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public ActionBar getSupportActionBar() {
|
||||
return getDelegate().getSupportActionBar();
|
||||
}
|
||||
|
||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
||||
getDelegate().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return getDelegate().getMenuInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
getDelegate().setContentView(layoutResID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
getDelegate().setContentView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().setContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().addContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
getDelegate().onPostResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTitleChanged(CharSequence title, int color) {
|
||||
super.onTitleChanged(title, color);
|
||||
getDelegate().setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
getDelegate().onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
getDelegate().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
getDelegate().onDestroy();
|
||||
}
|
||||
|
||||
public void invalidateOptionsMenu() {
|
||||
getDelegate().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private AppCompatDelegate getDelegate() {
|
||||
if (mDelegate == null) {
|
||||
mDelegate = AppCompatDelegate.create(this, null);
|
||||
}
|
||||
return mDelegate;
|
||||
}
|
||||
}
|
|
@ -7,17 +7,24 @@ import android.app.AlertDialog;
|
|||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.WebResourceError;
|
||||
|
@ -32,12 +39,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.sentry.Sentry;
|
||||
import io.sentry.android.AndroidSentryClientFactory;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
final private int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
|
||||
private int webViewPreviousState;
|
||||
private final int PAGE_STARTED = 0x1;
|
||||
private final int PAGE_REDIRECTED = 0x2;
|
||||
private CoordinatorLayout rootView;
|
||||
private WebView webView;
|
||||
|
||||
|
@ -45,11 +52,27 @@ public class MainActivity extends AppCompatActivity {
|
|||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// setTheme(R.style.AppTheme);
|
||||
setTheme(R.style.AppTheme);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
Boolean crash_reports = sharedPref.getBoolean("crash_reports", false);
|
||||
|
||||
String userAgent = System.getProperty("http.agent") + " Kurzparkzonen";
|
||||
|
||||
if (crash_reports) {
|
||||
Context ctx = this.getApplicationContext();
|
||||
|
||||
// Use the Sentry DSN (client key) from the Project Settings page on Sentry
|
||||
String sentryDsn = "https://31e14ecca4964ecaa8debcc38357f87e@sentry.lw1.at/8";
|
||||
Sentry.init(sentryDsn, new AndroidSentryClientFactory(ctx));
|
||||
} else {
|
||||
userAgent += " PrivateMode";
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
webView = (WebView) findViewById(R.id.activity_main_webview);
|
||||
rootView = (CoordinatorLayout) findViewById(R.id.action_bar_root);
|
||||
webView = findViewById(R.id.activity_main_webview);
|
||||
rootView = findViewById(R.id.action_bar_root);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
handleMarshMallowAndAbove();
|
||||
|
@ -69,6 +92,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
webView.getSettings().setAppCacheEnabled(true);
|
||||
webView.getSettings().setDatabaseEnabled(true);
|
||||
webView.getSettings().setDomStorageEnabled(true);
|
||||
webView.getSettings().setUserAgentString(userAgent);
|
||||
|
||||
webView.getSettings().setGeolocationDatabasePath(getFilesDir().getPath());
|
||||
|
||||
|
@ -184,10 +208,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: {
|
||||
Map<String, Integer> perms = new HashMap<String, Integer>();
|
||||
Map<String, Integer> perms = new HashMap<>();
|
||||
// Initial
|
||||
perms.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
|
@ -201,18 +225,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
) {
|
||||
Log.i("permissions:", "allowed");
|
||||
// All Permissions Granted
|
||||
|
||||
// Permission Denied
|
||||
Toast.makeText(MainActivity.this, "All Permission GRANTED !! Thank You :)", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
// Toast.makeText(MainActivity.this, "All Permission GRANTED !! Thank You :)", Toast.LENGTH_SHORT)
|
||||
// .show();
|
||||
|
||||
} else {
|
||||
// Permission Denied
|
||||
Toast.makeText(MainActivity.this, "One or More Permissions are DENIED Exiting App :(", Toast.LENGTH_SHORT)
|
||||
Toast.makeText(MainActivity.this, R.string.permissions_denied, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -223,9 +245,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private void handleMarshMallowAndAbove() {
|
||||
List<String> permissionsNeeded = new ArrayList<String>();
|
||||
List<String> permissionsNeeded = new ArrayList<>();
|
||||
|
||||
final List<String> permissionsList = new ArrayList<String>();
|
||||
final List<String> permissionsList = new ArrayList<>();
|
||||
if (!addPermission(permissionsList, Manifest.permission.ACCESS_FINE_LOCATION))
|
||||
permissionsNeeded.add("Show Location");
|
||||
|
||||
|
@ -251,8 +273,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
Toast.makeText(MainActivity.this, "No new Permission Required- Launching App .You are Awesome!!", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
Log.i("permission", "already allowed");
|
||||
}
|
||||
|
||||
|
||||
|
@ -275,4 +296,23 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle presses on the action bar items
|
||||
switch (item.getItemId()) {
|
||||
case R.id.to_preferences:
|
||||
Intent i = new Intent(this, MyPreferencesActivity.class);
|
||||
startActivity(i);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package at.lw1.kurzparkzonen.wien;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MyPreferencesActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(R.style.AppTheme);
|
||||
super.onCreate(savedInstanceState);
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
|
||||
}
|
||||
|
||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
9
android/app/src/main/res/drawable/ic_info_black_24dp.xml
Normal file
9
android/app/src/main/res/drawable/ic_info_black_24dp.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm1,15h-2v-6h2v6zm0,-8h-2V7h2v2z" />
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11.5,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zm6.5,-6v-5.5c0,-3.07 -2.13,-5.64 -5,-6.32V3.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,2.67 10,3.5v0.68c-2.87,0.68 -5,3.25 -5,6.32V16l-2,2v1h17v-1l-2,-2z" />
|
||||
</vector>
|
9
android/app/src/main/res/drawable/ic_sync_black_24dp.xml
Normal file
9
android/app/src/main/res/drawable/ic_sync_black_24dp.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01,-.25 1.97,-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0,-4.42,-3.58,-8,-8,-8zm0 14c-3.31 0,-6,-2.69,-6,-6 0,-1.01.25,-1.97.7,-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4,-4,-4,-4v3z" />
|
||||
</vector>
|
6
android/app/src/main/res/menu/main_menu.xml
Normal file
6
android/app/src/main/res/menu/main_menu.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/to_preferences"
|
||||
android:title="@string/settings" />
|
||||
</menu>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
|
@ -1,4 +1,12 @@
|
|||
<resources>
|
||||
<string name="app_name">Kurzparkzonen Wien</string>
|
||||
<string name="location_permission_reason">Um die aktuelle Position anzuzeigen, benötigt die App zugriff auf den Standort.</string>
|
||||
<string name="location_permission_reason">Um die aktuelle Position anzuzeigen, benötigt die App Zugriff auf den Standort.</string>
|
||||
<string name="permissions_denied">Der Zugriff auf die Position wurde abgelehnt. Die App kann dennoch verwendet werden.</string>
|
||||
<string name="settings">Einstellungen</string>
|
||||
<string name="source_code">Programmcode</string>
|
||||
<string name="source_code_summary">Kurzparkzonen Wien ist Open Source</string>
|
||||
<string name="licenses">Lizenzen</string>
|
||||
<string name="privacy_policy">Datenschutzerklärung</string>
|
||||
<string name="crash_reports">Absturzberichte senden</string>
|
||||
<string name="crash_reprts_summary">Alle Daten werden mit Sentry, einer Open Source Software, anonymisiert gespeichert.</string>
|
||||
</resources>
|
||||
|
|
29
android/app/src/main/res/xml/preferences.xml
Normal file
29
android/app/src/main/res/xml/preferences.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:theme="@style/AppTheme">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="crash_reports"
|
||||
android:summary="@string/crash_reprts_summary"
|
||||
android:title="@string/crash_reports" />
|
||||
<Preference
|
||||
android:summary="@string/source_code_summary"
|
||||
android:title="@string/source_code">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/Findus23/kurzparkzonen-wien" />
|
||||
</Preference>
|
||||
<Preference
|
||||
android:title="@string/licenses">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://example.com" />
|
||||
</Preference>
|
||||
<Preference
|
||||
android:title="@string/privacy_policy">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://lw1.at/i" />
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue