diff --git a/README.md b/README.md index 1023d87..33627a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # CarbUp Calculate cost-effectiveness of foods on a High Carb Low Fat lifestyle. -# Status -Working on open sourcing my free app that has existed on the Play Store for years. -This was my first app and will likely also be the first to get a Kotlin rewrite since it looks ancient on newer devices! ;D +## Status +No new features planned, only updates are to keep the app available on newer Android versions. + +## Update Notes + +### 2025-07-11 +[This article](https://sijus.medium.com/resurrecting-a-5-year-old-android-app-a-developers-journey-59d8f5689e5b) + was very helpful in getting this app updated from SDK 25 to 36. diff --git a/app/build.gradle b/app/build.gradle index 4784072..a9ebcb3 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,26 +1,34 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "23.0.2" - + namespace "com.hyperling.carbupbeta" + compileSdkVersion 36 defaultConfig { applicationId "com.hyperling.carbupbeta" - minSdkVersion 8 - targetSdkVersion 23 - versionCode 6 - versionName "0.11" + minSdkVersion 14 + targetSdkVersion 36 + versionCode 7 + versionName "1.0.0" } buildTypes { release { - minifyEnabled false + minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { + /* compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.google.android.gms:play-services-ads:8.3.0' + */ + + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + // https://mvnrepository.com/artifact/com.android.support/appcompat-v7 + implementation group: 'com.android.support', name: 'appcompat-v7', version: '28.0.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index edc1a42..8c7980c 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,39 +8,30 @@ + android:theme="@style/CarbUp"> + android:exported="true" + android:screenOrientation="fullSensor"> - :) - if (Build.VERSION.SDK_INT >= 9) { - // Load an ad into the AdMob banner view. - AdView adView = (AdView) findViewById(R.id.adViewHome); - AdRequest adRequest = new AdRequest.Builder() - .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) - .addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7 - .addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G - .addTestDevice("") // Cappy, even though it doesn't support ads - .setRequestAgent("android_studio:ad_template") - .build(); - adView.loadAd(adRequest); - } - //////////////////////////////////////////////////////////////////////////////////////////// } @Override diff --git a/app/src/main/java/com/hyperling/carbupbeta/List.java b/app/src/main/java/com/hyperling/carbupbeta/List.java index 31103ea..2f9dc24 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/List.java +++ b/app/src/main/java/com/hyperling/carbupbeta/List.java @@ -1,6 +1,7 @@ package com.hyperling.carbupbeta; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Color; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; @@ -56,14 +57,27 @@ public class List extends ListInfo{ setName(listInfo.getName()); // ========== Style the buttons ========== - // Color! - linearLayout.setBackgroundColor(Color.BLACK); - btnDelete.setBackgroundColor(Color.LTGRAY); - btnDelete.setTextColor(Color.BLACK); - btnEdit.setBackgroundColor(Color.LTGRAY); - btnEdit.setTextColor(Color.BLACK); - btnItem.setBackgroundColor(Color.WHITE); - btnItem.setTextColor(getRandomColor()); + /* Color! */ + int currentNightMode = + context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK + ; + switch (currentNightMode) { + // Light Mode + case Configuration.UI_MODE_NIGHT_NO: + linearLayout.setBackgroundColor(Color.BLACK); + btnDelete.setBackgroundColor(Color.LTGRAY); + btnDelete.setTextColor(Color.BLACK); + btnEdit.setBackgroundColor(Color.LTGRAY); + btnEdit.setTextColor(Color.BLACK); + btnItem.setBackgroundColor(Color.WHITE); + btnItem.setTextColor(getRandomColor()); + break;// Dark Mode + case Configuration.UI_MODE_NIGHT_YES: + // Night mode is active, we're using dark theme + btnItem.setBackgroundColor(Color.DKGRAY); + break; + } + /* */ // Size! //textSize = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()/30; btnDelete.setTextSize(16); //textSize-10); diff --git a/app/src/main/java/com/hyperling/carbupbeta/ListItem.java b/app/src/main/java/com/hyperling/carbupbeta/ListItem.java index b57bc57..f9d7b53 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/ListItem.java +++ b/app/src/main/java/com/hyperling/carbupbeta/ListItem.java @@ -1,6 +1,7 @@ package com.hyperling.carbupbeta; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Color; import android.widget.LinearLayout; import android.view.WindowManager; @@ -64,13 +65,26 @@ public class ListItem extends ListItemInfo { setName(listItemInfo.getName ()); // ========== Style the buttons ========== - // Color! - linearLayout.setBackgroundColor(Color.BLACK); - btnDelete.setBackgroundColor(Color.LTGRAY); - btnDelete.setTextColor(Color.BLACK); - btnEdit.setBackgroundColor(Color.LTGRAY); - btnEdit.setTextColor(Color.BLACK); - btnItem.setBackgroundColor(Color.WHITE); + /* Color! */ + int currentNightMode = + context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK + ; + switch (currentNightMode) { + // Light Mode + case Configuration.UI_MODE_NIGHT_NO: + linearLayout.setBackgroundColor(Color.BLACK); + btnDelete.setBackgroundColor(Color.LTGRAY); + btnDelete.setTextColor(Color.BLACK); + btnEdit.setBackgroundColor(Color.LTGRAY); + btnEdit.setTextColor(Color.BLACK); + btnItem.setBackgroundColor(Color.WHITE); + break; + // Dark Mode + case Configuration.UI_MODE_NIGHT_YES: + btnItem.setBackgroundColor(Color.DKGRAY); + break; + } + /* */ int[] colors = getColors(carbPerCal); btnItem.setTextColor(Color.rgb(colors[0], colors[1], colors[2])); // Size! diff --git a/app/src/main/java/com/hyperling/carbupbeta/MySettingItem.java b/app/src/main/java/com/hyperling/carbupbeta/MySettingItem.java index fe0469f..2f645e8 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/MySettingItem.java +++ b/app/src/main/java/com/hyperling/carbupbeta/MySettingItem.java @@ -10,6 +10,7 @@ import android.widget.RelativeLayout; import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; +import android.widget.TextView; /** * Created by ling on 1/1/16. @@ -18,7 +19,7 @@ public class MySettingItem extends MySettingInfo{ private LinearLayout linearLayout; private RelativeLayout relativeLayout; - Button btnItem; + TextView btnItem; CheckBox checkBox; private int textSize; @@ -27,7 +28,7 @@ public class MySettingItem extends MySettingInfo{ // Instantiate the Views linearLayout = new LinearLayout(context); relativeLayout = new RelativeLayout(context); - btnItem = new Button(context); + btnItem = new TextView(context); checkBox = new CheckBox(context); // Give the views their required attributes (Wrap Content) @@ -36,7 +37,7 @@ public class MySettingItem extends MySettingInfo{ LayoutParams item_lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams check_lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); - lay_lp.setMargins(1, 1, 1, 1); + lay_lp.setMargins(4,4,4,4); linearLayout.setLayoutParams(lay_lp); linearLayout.setOrientation(LinearLayout.HORIZONTAL); @@ -55,15 +56,17 @@ public class MySettingItem extends MySettingInfo{ setName(info.getName()); setEnabled(info.getEnabled()); - // ========== Style the buttons ========== - // Color! + /* ========== Style the buttons ========== */ + /* Color! * / linearLayout.setBackgroundColor(Color.LTGRAY); - relativeLayout.setBackgroundColor(Color.LTGRAY); + relativeLayout.setBackgroundColor(Color.DKGRAY); btnItem.setBackgroundColor(Color.LTGRAY); btnItem.setTextColor(Color.BLACK); + /* */ // Size! //textSize = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth()/30; btnItem.setTextSize(24); // textSize); + btnItem.setPadding(4,4,4,4); // Add the items to the layout! relativeLayout.addView(checkBox); diff --git a/app/src/main/java/com/hyperling/carbupbeta/MySettings.java b/app/src/main/java/com/hyperling/carbupbeta/MySettings.java index 1722806..fe424c1 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/MySettings.java +++ b/app/src/main/java/com/hyperling/carbupbeta/MySettings.java @@ -17,7 +17,7 @@ public class MySettings extends Activity { Context context; LinearLayout settingsArea; - MySettingItem quickLoad, adsEnabled, rainbowLists, whiteOnBlack; + MySettingItem quickLoad, rainbowLists, whiteOnBlack; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,16 +35,13 @@ public class MySettings extends Activity { // Instantiate settings quickLoad = new MySettingItem(context, new MySettingInfo()); - adsEnabled = new MySettingItem(context, new MySettingInfo()); // Name them quickLoad.setName("Quick Load:"); - adsEnabled.setName("Ads Enabled:"); // Set the checkboxes dalih.open(); quickLoad.setEnabled(dalih.getQuickLoad()); - adsEnabled.setEnabled(dalih.getAdsEnabled()); dalih.close(); // Set the checkbox actions @@ -62,26 +59,8 @@ public class MySettings extends Activity { } }); - adsEnabled.btnItem.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dalih.setAdsEnabled(!dalih.getAdsEnabled()); - adsEnabled.checkBox.setChecked(dalih.getAdsEnabled()); - } - }); - adsEnabled.checkBox.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - dalih.setAdsEnabled(adsEnabled.checkBox.isChecked()); - } - }); - // Throw them onto the screen settingsArea.addView(quickLoad.getView()); - - if (Build.VERSION.SDK_INT >= 9) { - settingsArea.addView(adsEnabled.getView()); - } } @Override diff --git a/app/src/main/java/com/hyperling/carbupbeta/Tab1.java b/app/src/main/java/com/hyperling/carbupbeta/Tab1.java index 416c41b..35bdc01 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/Tab1.java +++ b/app/src/main/java/com/hyperling/carbupbeta/Tab1.java @@ -15,9 +15,6 @@ import android.widget.Toast; import java.util.ArrayList; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; - /** * Created by usb on 9/28/14. * @@ -35,7 +32,6 @@ public class Tab1 extends Activity{ Button btnCreate; LinearLayout layListArea; TextView tvLeft, tvRight, selectHeader; - AdView mAdView; // The lists! ArrayList lists = new ArrayList(); @@ -58,7 +54,6 @@ public class Tab1 extends Activity{ tvLeft = (TextView) findViewById(R.id.leftEditView); tvRight = (TextView) findViewById(R.id.rightEditView); selectHeader = (TextView) findViewById(R.id.selectListHeader); - mAdView = (AdView) findViewById(R.id.adView); return; } @@ -266,26 +261,6 @@ public class Tab1 extends Activity{ dalih.open(); - if (Build.VERSION.SDK_INT >= 9) { - if (dalih.getAdsEnabled()) { - if (mAdView.getVisibility() != View.VISIBLE) { - AdRequest adRequest = new AdRequest.Builder() - .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) - .addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7 - .addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G - .addTestDevice("") // Cappy, even though it can't get ads - .build(); - mAdView.setVisibility(View.VISIBLE); - mAdView.loadAd(adRequest); - } - } - else{ - if (mAdView.getVisibility() == View.VISIBLE) { - mAdView.setVisibility(View.GONE); - } - } - } - setButtonInsert(); super.onResume(); diff --git a/app/src/main/java/com/hyperling/carbupbeta/Tab2.java b/app/src/main/java/com/hyperling/carbupbeta/Tab2.java index 7167174..12e052e 100755 --- a/app/src/main/java/com/hyperling/carbupbeta/Tab2.java +++ b/app/src/main/java/com/hyperling/carbupbeta/Tab2.java @@ -11,9 +11,6 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; - import java.util.ArrayList; /** @@ -35,7 +32,6 @@ public class Tab2 extends Activity{ LinearLayout layListArea; EditText txtName, txtCost, txtServings, txtCalories, txtCarbs, txtFiber; Button btnClear, btnAdd; - AdView mAdView; // List ArrayList items = new ArrayList(); @@ -61,7 +57,6 @@ public class Tab2 extends Activity{ txtFiber = (EditText) findViewById(R.id.etItemFiber); btnClear = (Button) findViewById(R.id.btnClear); btnAdd = (Button) findViewById(R.id.btnAddToList); - mAdView = (AdView) findViewById(R.id.adView); // Give the Buttons their power btnClear.setOnClickListener(new View.OnClickListener() { @@ -91,26 +86,6 @@ public class Tab2 extends Activity{ dalih.open(); - if (Build.VERSION.SDK_INT >= 9) { - if (dalih.getAdsEnabled()) { - if (mAdView.getVisibility() != View.VISIBLE) { - AdRequest adRequest = new AdRequest.Builder() - .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) - .addTestDevice("C6A494DC6E7C9AC29102694D48487084") // nexus 7 - .addTestDevice("B8B7561B850A9AB24E0D5B560FC50628") // Moto G - .addTestDevice("") // Cappy, even though it can't get ads - .build(); - mAdView.setVisibility(View.VISIBLE); - mAdView.loadAd(adRequest); - } - } - else{ - if (mAdView.getVisibility() == View.VISIBLE) { - mAdView.setVisibility(View.GONE); - } - } - } - setButtonInsert(); super.onResume(); diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index e0c5551..08d3430 100755 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -50,7 +50,8 @@ android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight=".45" - android:weightSum="1"> + android:weightSum="1" + style="?android:attr/buttonBarStyle">