Skip to content

Commit 6dc30f2

Browse files
committed
Change Picture Location
1 parent 11dc8ca commit 6dc30f2

File tree

10 files changed

+115
-74
lines changed

10 files changed

+115
-74
lines changed

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.pimp.companionforband"
99
minSdkVersion 17
1010
targetSdkVersion 23
11-
versionCode 23
12-
versionName "2.5.2"
11+
versionCode 24
12+
versionName "2.5.3"
1313
}
1414
buildTypes {
1515
release {
@@ -22,6 +22,7 @@ android {
2222
repositories {
2323
jcenter()
2424
mavenCentral()
25+
maven { url 'http://guardian.github.com/maven/repo-releases' }
2526
}
2627

2728
dependencies {
@@ -41,6 +42,7 @@ dependencies {
4142
exclude group: 'com.google.android', module: 'support-v4'
4243
}
4344
compile 'cat.ereza:customactivityoncrash:1.4.0'
45+
compile 'net.rdrei.android.dirchooser:library:3.2'
4446
compile('com.mikepenz:materialdrawer:5.1.6@aar') {
4547
transitive = true
4648
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
android:allowBackup="true"
2020
android:icon="@mipmap/ic_launcher"
2121
android:label="@string/app_name"
22-
android:supportsRtl="true"
23-
android:theme="@style/AppTheme">
22+
android:supportsRtl="true">
2423
<activity
2524
android:name=".MainActivity"
2625
android:label="@string/app_name"
@@ -43,8 +42,12 @@
4342
</intent-filter>
4443
</receiver>
4544

46-
<activity android:name=".DonateActivity" />
47-
<activity android:name=".ChangelogActivity" />
45+
<activity
46+
android:name=".DonateActivity"
47+
android:theme="@style/AppTheme" />
48+
<activity
49+
android:name=".ChangelogActivity"
50+
android:theme="@style/AppTheme" />
4851

4952
<meta-data
5053
android:name="com.google.android.gms.version"
@@ -59,5 +62,7 @@
5962
android:name="com.yalantis.ucrop.UCropActivity"
6063
android:screenOrientation="portrait"
6164
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
65+
66+
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
6267
</application>
6368
</manifest>

app/src/main/java/com/pimp/companionforband/CameraActivity.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import android.Manifest;
44
import android.content.Intent;
5+
import android.content.SharedPreferences;
56
import android.content.pm.PackageManager;
67
import android.hardware.Camera;
78
import android.os.Bundle;
8-
import android.os.Environment;
99
import android.support.v4.content.ContextCompat;
1010
import android.support.v7.app.AppCompatActivity;
1111
import android.view.SurfaceHolder;
@@ -49,19 +49,22 @@ protected void onCreate(Bundle savedInstanceState) {
4949
surfaceHolder.addCallback(this);
5050
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
5151

52+
SharedPreferences s = getApplicationContext().getSharedPreferences("MyPrefs", 0);
53+
final String location = s.getString("pic_location",
54+
"/storage/emulated/0/CompanionForBand/Camera");
55+
5256
jpegCallback = new Camera.PictureCallback() {
5357

5458
@Override
5559
public void onPictureTaken(byte[] data, Camera camera) {
5660
FileOutputStream outStream = null;
5761
try {
58-
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "CompanionForBand" + File.separator + "Camera");
62+
File file = new File(location);
5963
if (!file.exists() && !file.isDirectory())
6064
file.mkdirs();
6165

62-
outStream = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()
63-
+ File.separator + "CompanionForBand" + File.separator
64-
+ "Camera" + File.separator + System.currentTimeMillis() + ".jpg");
66+
outStream = new FileOutputStream(location + File.separator +
67+
System.currentTimeMillis() + ".jpg");
6568

6669
outStream.write(data);
6770
outStream.close();
@@ -72,8 +75,8 @@ public void onPictureTaken(byte[] data, Camera camera) {
7275
} finally {
7376
}
7477

75-
Toast.makeText(getApplicationContext(), getString(R.string.picture_saved) + " CompanionForBand/Camera",
76-
Toast.LENGTH_SHORT).show();
78+
Toast.makeText(getApplicationContext(), getString(R.string.picture_saved) + " " +
79+
location, Toast.LENGTH_SHORT).show();
7780
refreshCamera();
7881
}
7982
};

app/src/main/java/com/pimp/companionforband/DonateActivity.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.view.View;
1111
import android.widget.AdapterView;
1212
import android.widget.ListView;
13-
import android.widget.Toast;
1413

1514
import com.pimp.companionforband.util.IabHelper;
1615
import com.pimp.companionforband.util.IabResult;
@@ -57,26 +56,8 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
5756
};
5857
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
5958
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
60-
if (mHelper == null) return;
61-
62-
if (result.isFailure()) {
63-
complain("Failed to query inventory: " + result);
64-
return;
65-
}
66-
67-
String cokePrice = "Coke";
68-
String coffeePrice = "Coffee";
69-
String burgerPrice = "Burger";
70-
String pizzaPrice = "Pizza";
71-
String mealPrice = "Meal";
72-
String[] title = {cokePrice, coffeePrice, burgerPrice, pizzaPrice, mealPrice};
73-
74-
cokePrice = inventory.getSkuDetails(SKU_COKE).getPrice();
75-
coffeePrice = inventory.getSkuDetails(SKU_COFFEE).getPrice();
76-
burgerPrice = inventory.getSkuDetails(SKU_BURGER).getPrice();
77-
pizzaPrice = inventory.getSkuDetails(SKU_PIZZA).getPrice();
78-
mealPrice = inventory.getSkuDetails(SKU_MEAL).getPrice();
79-
String[] price = {cokePrice, coffeePrice, burgerPrice, pizzaPrice, mealPrice};
59+
String[] title = {"Coke", "Coffee", "Burger", "Pizza", "Meal"};
60+
String[] price = {"Rs. 10.00", "Rs. 50.00", "Rs. 100.00", "Rs. 500.00", "Rs. 1,000.00"};
8061

8162
ListView listView = (ListView) findViewById(R.id.list);
8263
listView.setAdapter(new CustomAdapter(DonateActivity.this, title, price));
@@ -119,8 +100,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
119100
setTitle(getString(R.string.support));
120101
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
121102

122-
Toast.makeText(DonateActivity.this, "Loading...", Toast.LENGTH_SHORT).show();
123-
124103
String base64EncodedPublicKey = getString(R.string.base64);
125104

126105
mHelper = new IabHelper(this, base64EncodedPublicKey);

app/src/main/java/com/pimp/companionforband/ExtrasFragment.java

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public class ExtrasFragment extends Fragment {
8181
private UUID barcodeTileId = UUID.fromString("23d392df-dd0c-4e93-8c0d-63dd7b02eb52");
8282
private UUID flashlightTileId = UUID.fromString("c2187a9c-db5c-4e73-9f9d-d742113f91e8");
8383

84+
String barcode39 = "MK12345509";
85+
String barcode417 = "901234567890123456";
86+
8487
public static ExtrasFragment newInstance() {
8588
return new ExtrasFragment();
8689
}
@@ -149,28 +152,28 @@ public void onClick(View v) {
149152
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
150153
switch (position) {
151154
case 1:
152-
name.setText(sharedPreferences.getString("name1", "CODE39"));
153-
number.setText(sharedPreferences.getString("no1", "MK12345509"));
155+
name.setText(sharedPreferences.getString("name1", "Barcode 1"));
156+
number.setText(sharedPreferences.getString("no1", barcode39));
154157
typeSpinner.setSelection(sharedPreferences.getInt("type1", 1));
155158
break;
156159
case 2:
157-
name.setText(sharedPreferences.getString("name2", "PDF417"));
158-
number.setText(sharedPreferences.getString("no2", "901234567890123456"));
160+
name.setText(sharedPreferences.getString("name2", "Barcode 2"));
161+
number.setText(sharedPreferences.getString("no2", barcode417));
159162
typeSpinner.setSelection(sharedPreferences.getInt("type2", 2));
160163
break;
161164
case 3:
162-
name.setText(sharedPreferences.getString("name3", "CODE39"));
163-
number.setText(sharedPreferences.getString("no3", "MK12345509"));
165+
name.setText(sharedPreferences.getString("name3", "Barcode 3"));
166+
number.setText(sharedPreferences.getString("no3", barcode39));
164167
typeSpinner.setSelection(sharedPreferences.getInt("type3", 1));
165168
break;
166169
case 4:
167-
name.setText(sharedPreferences.getString("name4", "PDF417"));
168-
number.setText(sharedPreferences.getString("no4", "901234567890123456"));
170+
name.setText(sharedPreferences.getString("name4", "Barcode 4"));
171+
number.setText(sharedPreferences.getString("no4", barcode417));
169172
typeSpinner.setSelection(sharedPreferences.getInt("type4", 2));
170173
break;
171174
case 5:
172-
name.setText(sharedPreferences.getString("name5", "CODE39"));
173-
number.setText(sharedPreferences.getString("no5", "MK12345509"));
175+
name.setText(sharedPreferences.getString("name5", "Barcode 5"));
176+
number.setText(sharedPreferences.getString("no5", barcode39));
174177
typeSpinner.setSelection(sharedPreferences.getInt("type5", 1));
175178
break;
176179
}
@@ -529,11 +532,11 @@ private boolean addBarcodeTile() throws Exception {
529532
SharedPreferences sharedPreferences = getContext().getSharedPreferences("MyPrefs", 0);
530533
BandTile tile = new BandTile.Builder(barcodeTileId, getString(R.string.barcode_tile), tileIcon)
531534
.setTileSmallIcon(badgeIcon).setPageLayouts(
532-
createBarcodeLayout(sharedPreferences.getInt("type1", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417, 50, 51),
533-
createBarcodeLayout(sharedPreferences.getInt("type2", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417, 52, 53),
534-
createBarcodeLayout(sharedPreferences.getInt("type3", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417, 54, 55),
535-
createBarcodeLayout(sharedPreferences.getInt("type4", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417, 56, 57),
536-
createBarcodeLayout(sharedPreferences.getInt("type5", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417, 58, 59)).build();
535+
createBarcodeLayout(sharedPreferences.getInt("type5", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417),
536+
createBarcodeLayout(sharedPreferences.getInt("type4", 2) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417),
537+
createBarcodeLayout(sharedPreferences.getInt("type3", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417),
538+
createBarcodeLayout(sharedPreferences.getInt("type2", 2) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417),
539+
createBarcodeLayout(sharedPreferences.getInt("type1", 1) == 1 ? BarcodeType.CODE39 : BarcodeType.PDF417)).build();
537540
appendToUI(getString(R.string.barcode_tile_adding), Style.INFO);
538541
if (client.getTileManager().addTile(getActivity(), tile).await()) {
539542
appendToUI(getString(R.string.barcode_tile_added), Style.CONFIRM);
@@ -544,38 +547,42 @@ private boolean addBarcodeTile() throws Exception {
544547
}
545548
}
546549

547-
private PageLayout createBarcodeLayout(BarcodeType type, int id1, int id2) {
550+
private PageLayout createBarcodeLayout(BarcodeType type) {
548551
return new PageLayout(
549552
new FlowPanel(15, 0, 245, 105, FlowPanelOrientation.VERTICAL)
550553
.addElements(new Barcode(0, 0, 221, 70, type)
551-
.setId(id1).setMargins(3, 0, 0, 0))
554+
.setId(11).setMargins(3, 0, 0, 0))
552555
.addElements(new TextBlock(0, 0, 230, 30, TextBlockFont.SMALL, 0)
553-
.setId(id2).setColor(Color.RED)));
556+
.setId(21).setColor(Color.RED)));
554557
}
555558

556559
private void updateBarcodePages() throws BandIOException {
557-
SharedPreferences sharedPreferences = getContext().getSharedPreferences("MyPrefs", 0);
560+
final SharedPreferences sharedPreferences = getContext().getSharedPreferences("MyPrefs", 0);
561+
final String no1 = sharedPreferences.getString("no1", barcode39);
562+
final String no2 = sharedPreferences.getString("no2", barcode417);
563+
final String no3 = sharedPreferences.getString("no3", barcode39);
564+
final String no4 = sharedPreferences.getString("no4", barcode417);
565+
final String no5 = sharedPreferences.getString("no5", barcode39);
558566
client.getTileManager().setPages(barcodeTileId,
559-
new PageData(barcodeId5, 4)
560-
.update(new BarcodeData(59, sharedPreferences.getString("no5", "MK12345509"),
561-
(sharedPreferences.getInt("type5", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
562-
.update(new TextBlockData(58, sharedPreferences.getString("no5", "MK12345509"))),
563-
new PageData(barcodeId4, 3)
564-
.update(new BarcodeData(57, sharedPreferences.getString("no4", "901234567890123456"),
565-
(sharedPreferences.getInt("type4", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
566-
.update(new TextBlockData(56, sharedPreferences.getString("no4", "901234567890123456"))),
567+
new PageData(barcodeId1, 0)
568+
.update(new BarcodeData(11, no5, (sharedPreferences.getInt("type5", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
569+
.update(new TextBlockData(21, no5)),
570+
new PageData(barcodeId2, 1)
571+
.update(new BarcodeData(11, no4,
572+
(sharedPreferences.getInt("type4", 2) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
573+
.update(new TextBlockData(21, no4)),
567574
new PageData(barcodeId3, 2)
568-
.update(new BarcodeData(55, sharedPreferences.getString("no3", "MK12345509"),
575+
.update(new BarcodeData(11, no3,
569576
(sharedPreferences.getInt("type3", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
570-
.update(new TextBlockData(54, sharedPreferences.getString("no3", "MK12345509"))),
571-
new PageData(barcodeId2, 1)
572-
.update(new BarcodeData(53, sharedPreferences.getString("no2", "901234567890123456"),
573-
(sharedPreferences.getInt("type2", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
574-
.update(new TextBlockData(52, sharedPreferences.getString("no2", "901234567890123456"))),
575-
new PageData(barcodeId1, 0)
576-
.update(new BarcodeData(51, sharedPreferences.getString("no1", "MK12345509"),
577+
.update(new TextBlockData(21, no3)),
578+
new PageData(barcodeId4, 3)
579+
.update(new BarcodeData(11, no2,
580+
(sharedPreferences.getInt("type2", 2) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
581+
.update(new TextBlockData(21, no2)),
582+
new PageData(barcodeId5, 4)
583+
.update(new BarcodeData(11, no1,
577584
(sharedPreferences.getInt("type1", 1) == 1) ? BarcodeType.CODE39 : BarcodeType.PDF417))
578-
.update(new TextBlockData(50, sharedPreferences.getString("no1", "MK12345509"))));
585+
.update(new TextBlockData(21, no1)));
579586
}
580587

581588
private PageLayout createFlashlight1Layout() {

app/src/main/java/com/pimp/companionforband/MainActivity.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
4848
import com.yalantis.ucrop.UCrop;
4949

50+
import net.rdrei.android.dirchooser.DirectoryChooserConfig;
51+
import net.rdrei.android.dirchooser.DirectoryChooserFragment;
52+
5053
import java.io.File;
5154

5255
import angtrim.com.fivestarslibrary.FiveStarsDialog;
@@ -55,7 +58,8 @@
5558
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
5659
import de.keyboardsurfer.android.widget.crouton.Crouton;
5760

58-
public class MainActivity extends AppCompatActivity implements NegativeReviewListener, ReviewListener {
61+
public class MainActivity extends AppCompatActivity implements NegativeReviewListener, ReviewListener,
62+
DirectoryChooserFragment.OnFragmentInteractionListener {
5963

6064
protected static final int REQUEST_STORAGE_READ_ACCESS_PERMISSION = 101;
6165
protected static final int REQUEST_STORAGE_WRITE_ACCESS_PERMISSION = 102;
@@ -463,6 +467,16 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
463467
AppUpdater appUpdater = new AppUpdater(this);
464468
appUpdater.start();
465469

470+
settings = getApplicationContext().getSharedPreferences("MyPrefs", 0);
471+
editor = settings.edit();
472+
473+
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
474+
.allowNewDirectoryNameModification(true)
475+
.newDirectoryName("CfBCamera")
476+
.initialDirectory(settings.getString("pic_location", "/storage/emulated/0/CompanionForBand/Camera"))
477+
.build();
478+
mDialog = DirectoryChooserFragment.newInstance(config);
479+
466480
CustomActivityOnCrash.install(this);
467481
}
468482

@@ -736,4 +750,22 @@ public CharSequence getPageTitle(int position) {
736750
return null;
737751
}
738752
}
753+
754+
public void changePictureLocation(View view) {
755+
mDialog.show(getFragmentManager(), null);
756+
}
757+
758+
private DirectoryChooserFragment mDialog;
759+
760+
@Override
761+
public void onSelectDirectory(@NonNull String path) {
762+
editor.putString("pic_location", path);
763+
editor.apply();
764+
mDialog.dismiss();
765+
}
766+
767+
@Override
768+
public void onCancelChooser() {
769+
mDialog.dismiss();
770+
}
739771
}

app/src/main/res/layout/fragment_extras.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
android:text="@string/camera_tile" />
5555
</LinearLayout>
5656

57+
<Button
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:onClick="changePictureLocation"
61+
android:text="@string/change_picture_location" />
62+
5763
<LinearLayout
5864
android:layout_width="match_parent"
5965
android:layout_height="wrap_content"

app/src/main/res/raw/changelog.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<changelog bulletedList="true">
3+
<changelogversion changeDate="APR 16, 2016" versionName="2.5.3">
4+
<changelogimprovement>Change Picture Location</changelogimprovement>
5+
<changelogbug>Fix Barcode Tile</changelogbug>
6+
</changelogversion>
7+
38
<changelogversion changeDate="MAR 27, 2016" versionName="2.5.2">
49
<changelogtext>Update to band sdk - 1.3.20307.2</changelogtext>
510
</changelogversion>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,6 @@
201201
<string name="toast_unexpected_error">Unexpected error</string>
202202

203203
<string name="changelog">Changelog</string>
204+
205+
<string name="change_picture_location">CHANGE PICTURE LOCATION</string>
204206
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.1.0-alpha4'
9+
classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
1010
classpath 'com.google.gms:google-services:2.0.0-alpha3'
1111

1212
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)