Layoutduaactivity - Java: Txttinggiair Btnbuka Btntutup Txtpintu Imgair
Layoutduaactivity - Java: Txttinggiair Btnbuka Btntutup Txtpintu Imgair
Layoutduaactivity - Java: Txttinggiair Btnbuka Btntutup Txtpintu Imgair
java
package com.sc.semicolon.pintusawah;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout_dua);
initView();
ambilAir();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
/*
Kemudian kita harus menambahkan Notification dengan menggunakan NotificationManager
*/
notificationManager.notify(NOTIFICATION_ID, builder.build()
);
}
private void notifDua() {
Intent intent = new Intent(getApplicationContext(),LayoutDuaActivity.class);
//menginisialiasasi intent
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
/*
Kemudian kita harus menambahkan Notification dengan menggunakan NotificationManager
*/
notificationManager.notify(NOTIFICATION_ID, builder.build()
);
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sc.semicolon.pintusawah">
<application
android:allowBackup="true"
android:icon="@drawable/dam"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:icon="@drawable/dam"
android:label=" Monitoring Saluran Irigasi"
android:screenOrientation="portrait"></activity>
<activity
android:name=".SplashActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
MainActivity.java
package com.sc.semicolon.pintusawah;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.irrigationatas);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.activity_main);
initView();
ambilAir();
databaseRef.child("kontroling").child("pintu2").setValue(false);
txtPintu.setText("Pintu Buka");
btnBuka.setClickable(false);
btnTutup.setClickable(true);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("User", databaseError.getMessage());
}
});
}
});
btnTutup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
databaseRef.child("kontroling").addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
databaseRef.child("kontroling").child("pintu2").setValue(true);
txtPintu.setText("Pintu Tutup");
btnBuka.setClickable(true);
btnTutup.setClickable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("User", databaseError.getMessage());
}
});
}
});
btnIrigasi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new
Intent(getApplicationContext(),LayoutDuaActivity.class));
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
/*
Kemudian kita harus menambahkan Notification dengan menggunakan NotificationManager
*/
notificationManager.notify(NOTIFICATION_ID, builder.build()
);
}
/*
Kemudian kita harus menambahkan Notification dengan menggunakan NotificationManager
*/
notificationManager.notify(NOTIFICATION_ID, builder.build()
);
}
}
SpalshActivity.java
package com.sc.semicolon.pintusawah;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);