Skip to content

Commit

Permalink
Add option to start scan on app open
Browse files Browse the repository at this point in the history
Close #127
  • Loading branch information
itchix committed Sep 30, 2016
1 parent f77eec7 commit 48a07df
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ apply plugin: 'com.neenbedankt.android-apt'
dependencies {

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:preference-v14:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.4.0'
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="openfoodfacts.github.scrachx.openfood"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto">

<uses-feature
android:name="android.hardware.camera"
Expand Down Expand Up @@ -60,7 +61,7 @@
<meta-data
android:name="VERSION"
android:value="7"/>
<meta-data
<meta-datas
android:name="QUERY_LOG"
android:value="true"/>
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package openfoodfacts.github.scrachx.openfood.fragments;

import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;
import openfoodfacts.github.scrachx.openfood.R;

public class PreferencesFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
setPreferencesFromResource(R.xml.preferences, rootKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
Expand Down Expand Up @@ -41,6 +43,7 @@
import openfoodfacts.github.scrachx.openfood.fragments.FindProductFragment;
import openfoodfacts.github.scrachx.openfood.fragments.HomeFragment;
import openfoodfacts.github.scrachx.openfood.fragments.OfflineEditFragment;
import openfoodfacts.github.scrachx.openfood.fragments.PreferencesFragment;
import openfoodfacts.github.scrachx.openfood.fragments.SearchProductsFragment;
import openfoodfacts.github.scrachx.openfood.utils.Utils;

Expand Down Expand Up @@ -147,8 +150,7 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
}

if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment).commit();
} else {
// error in creating fragment
Expand Down Expand Up @@ -178,6 +180,14 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
//set the active profile
headerResult.setActiveProfile(profile);
}


SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean lauchScan = settings.getBoolean("startScan",false);
if(lauchScan) {
Intent cameraIntent = new Intent(MainActivity.this, ScannerFragmentActivity.class);
startActivity(cameraIntent);
}
}

private IProfile getProfile() {
Expand Down Expand Up @@ -243,11 +253,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_about:
new MaterialDialog.Builder(this)
.title(R.string.action_about)
.content(R.string.txtAbout)
.neutralText(R.string.txtOk)
.show();
return true;
.title(R.string.action_about)
.content(R.string.txtAbout)
.neutralText(R.string.txtOk)
.show();
return true;
case R.id.action_preferences:
getSupportActionBar().setTitle(R.string.action_preferences);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new PreferencesFragment()).commit();
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package openfoodfacts.github.scrachx.openfood.views;

import android.content.Intent;
import android.os.Bundle;

import openfoodfacts.github.scrachx.openfood.R;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_about" android:title="@string/action_about"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_preferences" android:title="@string/action_preferences"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,8 @@
<!-- Strings related to login -->
<string name="error_invalid_password">The password needs to be a least 6 characters long.</string>
<string name="error_field_required">This field is required</string>
<string name="action_preferences">Preferences</string>
<string name="prefs_scan_startup">Scan on startup</string>
<string name="prefs_scan_startup_summary">This option if selected will start scan when app is opened.</string>

</resources>
9 changes: 8 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<item name="colorPrimary">@color/indigo_400</item>
<item name="colorPrimaryDark">@color/indigo_600</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

<style name="AppTheme.NoActionBar">
Expand All @@ -16,4 +17,10 @@
<item name="android:windowBackground">@drawable/background_splash</item>
</style>

<style name="PreferenceThemeOverlay.v14">
<item name="android:textColor">@color/grey_800</item>
<item name="android:textColorSecondary">@color/grey_500</item>
<item name="android:summary">@color/grey_500</item>
</style>

</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<CheckBoxPreference android:title="@string/prefs_scan_startup"
android:defaultValue="false"
android:summary="@string/prefs_scan_startup_summary"
android:key="startScan"/>

</PreferenceScreen>

0 comments on commit 48a07df

Please sign in to comment.