Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya committed Apr 28, 2021
1 parent 7045b39 commit 4fedb8c
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 174 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId "com.aditya.smartplantwateringsystem"
minSdkVersion 29
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand All @@ -36,9 +36,9 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.airbnb.android:lottie:3.4.0'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
testImplementation 'junit:junit:4.+'
implementation 'com.google.firebase:firebase-database:19.7.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:fullBackupContent="@xml/backup_descriptor"
android:theme="@style/Theme.SmartPlantWateringSystem">
<activity android:name=".MainActivity">
<intent-filter>
Expand All @@ -16,6 +17,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".backgroundNotificationService" />
</application>

</manifest>
243 changes: 125 additions & 118 deletions app/src/main/java/com/aditya/smartplantwateringsystem/MainActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.aditya.smartplantwateringsystem;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;


public class backgroundNotificationService extends Service {
private int moisturepercentage = 100;

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

public void createNotificationChannel() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("plantnotification", "moistureChannel", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Channel for smart plant watering system notification");
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
createNotificationChannel();
DatabaseReference moistureRef = FirebaseDatabase.getInstance().getReference().child("Plant").child("Moisture");
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intentz = PendingIntent.getActivity(this, 0, notificationIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "plantnotification")
.setSmallIcon(R.drawable.ic_baseline_warning_24)
.setContentTitle("Moisture Level is Low")
.setContentIntent(intentz)
.setContentText("Please water the plant")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
moistureRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
moisturepercentage = Integer.parseInt(snapshot.getValue().toString());
if (moisturepercentage <= 15) {
notificationManager.notify(100, builder.build());
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
return START_STICKY;
}

}
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_warning_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FF5252"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z" />
</vector>
44 changes: 24 additions & 20 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorOnPrimary"
tools:context=".MainActivity">
<include
android:id="@+id/main_toolbar"
Expand All @@ -27,16 +26,16 @@
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Soil Moisture Content"
android:layout_marginStart="5dp"
android:fontFamily="@font/odin"
android:textColor="@color/white"
android:textSize="18sp"
android:layout_marginLeft="5dp"
app:layout_constraintBottom_toBottomOf="@+id/MoistureprogressBar"
android:text="@string/soil_moisture_content"
app:layout_constraintBottom_toBottomOf="@+id/moistureProgressBar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/MoistureprogressBar" />
app:layout_constraintTop_toTopOf="@+id/moistureProgressBar" />
<ProgressBar
android:id="@+id/MoistureprogressBar"
android:id="@+id/moistureProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="200dp"
android:layout_height="200dp"
Expand All @@ -45,18 +44,19 @@
android:progressDrawable="@drawable/circle"
app:layout_constraintLeft_toRightOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/MoisturePercentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NaN"
android:text="@string/not_available"
android:fontFamily="@font/odin"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/MoistureprogressBar"
app:layout_constraintEnd_toEndOf="@+id/MoistureprogressBar"
app:layout_constraintStart_toStartOf="@+id/MoistureprogressBar"
app:layout_constraintTop_toTopOf="@+id/MoistureprogressBar" />
app:layout_constraintBottom_toBottomOf="@+id/moistureProgressBar"
app:layout_constraintEnd_toEndOf="@+id/moistureProgressBar"
app:layout_constraintStart_toStartOf="@+id/moistureProgressBar"
app:layout_constraintTop_toTopOf="@+id/moistureProgressBar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
Expand Down Expand Up @@ -87,27 +87,27 @@
android:id="@+id/automatictxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Automatic Mode"
android:text="@string/automatic_mode"
android:textColor="@color/white"
android:textSize="18sp"
android:fontFamily="@font/odin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/appCompatImageView"
app:layout_constraintTop_toTopOf="@id/appCompatImageView" />

<Switch
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/automodeswitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
app:layout_constraintStart_toEndOf="@id/automatictxt"
app:layout_constraintTop_toTopOf="@+id/automatictxt" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Minimum level:"
android:text="@string/minimum_level"
android:textColor="@color/white"
android:textSize="18sp"
android:fontFamily="@font/odin"
Expand All @@ -124,11 +124,12 @@
android:textSize="18sp"
android:fontFamily="@font/odin"
android:focusableInTouchMode="false"
android:hint="0"
android:hint="@string/default_minval"
android:maxLength="2"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/textView2"
app:layout_constraintStart_toEndOf="@+id/textView2"
android:importantForAutofill="no"
app:layout_constraintTop_toTopOf="@+id/textView2" />

<TextView
Expand All @@ -140,14 +141,15 @@
android:fontFamily="@font/odin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/minlvledittxt"
app:layout_constraintTop_toBottomOf="@+id/automodeswitch" />
app:layout_constraintTop_toBottomOf="@+id/automodeswitch"
tools:ignore="HardcodedText" />

<Button
android:id="@+id/setbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@android:color/transparent"
android:text="Set"
android:text="@string/set"
android:visibility="gone"
android:textAllCaps="false"
android:textColor="@color/white"
Expand All @@ -162,19 +164,21 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/materialCardView2">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gradient_3">

<TextView
android:id="@+id/wateringstatustxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hold to Water the Plant"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="@string/hold_to_water_the_plant"
android:fontFamily="@font/odin"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/white"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/menu/my_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/enable_dark_mode_button"
android:title="Enable Dark Mode"
android:title="@string/dark_mode"
android:checkable="true"
app:showAsAction="never" />
<item
android:id="@+id/enable_notifications"
android:checkable="true"
android:checked="true"
android:title="@string/notifications"
app:showAsAction="never" />
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="android:textColorPrimary">#A9FFFFFF</item>
<item name="android:colorBackground">@color/black</item>
<item name="android:itemBackground">@color/light_black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="light_black">#424242</color>
<color name="white">#FFFFFFFF</color>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<resources>
<string name="app_name">Smart Plant Watering System</string>
<string name="releaseTxt">Release to Stop</string>
<string name="wateringTxt">Hold to Water the Plant</string>
<string name="notifications">Notifications</string>
<string name="dark_mode">Dark Mode</string>
<string name="soil_moisture_content">Soil Moisture Content</string>
<string name="not_available">NaN</string>
<string name="automatic_mode">Automatic Mode</string>
<string name="minimum_level">Minimum level:</string>
<string name="default_minval">0</string>
<string name="set">Set</string>
<string name="hold_to_water_the_plant">Hold to Water the Plant</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">#f8f8f8</item>
<item name="android:textColorPrimary">#E6000000</item>
<item name="android:colorBackground">#f8f8f8</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/backup_descriptor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- TODO Remove the following "exclude" elements to make them a part of the auto backup -->
<!-- Exclude the shared preferences file that contains the GCM registrationId -->
<exclude
domain="sharedpref"
path="sharedPrefs.xml" />
</full-backup-content>

0 comments on commit 4fedb8c

Please sign in to comment.