Coding Menggunakan software Eclipse: Mainactivity.java (coding untuk tampilan login): package com.bella.pengontrol_otomatis;

Similar documents
<uses-permission android:name="android.permission.internet" />

Tabel mysql. Kode di PHP. Config.php. Service.php

Mobile Development Lecture 9: Android & RESTFUL Services

@Bind(R.id.input_ ) EditText EditText Button _loginbutton;


LAMPIRAN PROGRAM. public class ListArrayAdapterPost extends ArrayAdapter<ModelDataPost> {

Android - JSON Parser Tutorial

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Appendix A : Android Studio Code For Android

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Create a local SQL database hosting a CUSTOMER table. Each customer includes [id, name, phone]. Do the work inside Threads and Asynctasks.

Android/Java Lightning Tutorial JULY 30, 2018

Serious Gaming. Technical manual. This document is a collection of the code and installation process

<uses-permission android:name="android.permission.internet"/>

Android Workshop: Model View Controller ( MVC):

MyDatabaseHelper. public static final String TABLE_NAME = "tbl_bio";

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Workshop. 1. Create a simple Intent (Page 1 2) Launch a Camera for Photo Taking

ANDROID PHONE KEY MICHAEL WONG POH HONG

LAMPIRAN. byte bcdtodec(byte val) { return( (val/16*10) + (val%16) ); } void setup() {

SMAATSDK. NFC MODULE ON ANDROID REQUIREMENTS AND DOCUMENTATION RELEASE v1.0

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Basic GUI elements - exercises

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Android Programs Day 5

1 카메라 1.1 제어절차 1.2 관련주요메서드 1.3 제작철차 서피스뷰를생성하고이를제어하는서피스홀더객체를참조해야함. 매니페스트에퍼미션을지정해야한다.

ANDROID PROGRAMS DAY 3

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Type of Submission: Article Title: Watson Explorer REST API Tutorial #1 Subtitle: Java Programming. Keywords: WEX, WCA, analytics, Watson

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

TUTOR FINDER APP REPORT OF MAJOR PROJECT SUBMITTED FOR PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE DEGREE OF MASTERS OF COMPUTER APPLICATION

Press project on the left toolbar if it doesn t show an overview of the app yet.

RESTful Examples. RESTful Examples 1 Apache 3 Jersey 5 JAX-RS 7 ApplicationConfig.java 7 HelloGregg.java 8

LAMPIRAN. public class MainActivity extends AppCompatActivity {

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

android:layout_margintop="5dp" > <EditText android:layout_width="210dp"

Data Persistence. Chapter 10

Manifest.xml. Activity.java

Create Parent Activity and pass its information to Child Activity using Intents.

API Guide for Gesture Recognition Engine. Version 2.0

Android JSON Parsing Tutorial

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Android Application development for importing Vehicles to Ethiopia Tracking system. Zekir Ahmed Awol

Android Apps Development for Mobile Game Lesson Create a simple paint brush that allows user to draw something (Page 11 13)

else if(rb2.ischecked()) {

API Guide for Gesture Recognition Engine. Version 1.1

This document is downloaded from DR-NTU, Nanyang Technological University Library, Singapore.

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

B9: Việc cuối cùng cần làm là viết lại Activity. Tới Example.java và chỉnh sửa theo nội dung sau: Mã: package at.exam;

public AnimLayer(Context context, AttributeSet attrs, int defstyle) { super(context, attrs, defstyle); initlayer(); }

DAFTAR RIWAYAT HIDUP

M.A.D Assignment # 1

CONTENTS. CHAPTER:1 Introduction. CHAPTER:2 Objectives. CHAPTER:3 Tools/Environment Used. CHAPTER:4 Analysis Document CHAPTER:5 SRS.

1. Simple List. 1.1 Simple List using simple_list_item_1

Accelerating Information Technology Innovation

CS 4518 Mobile and Ubiquitous Computing Lecture 4: WebView (Part 2) Emmanuel Agu

ANN exercise session

Intents. Your first app assignment


Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

COMP61242: Task 3 1 2/05/18

Vienos veiklos būsena. Theory

Simple Currency Converter

// MainActivity.java ; Noah Spenser; Senior Design; Diabetic Breathalyzer

Hi Hsiao-Lung Chan, Ph.D. Dept Electrical Engineering Chang Gung University, Taiwan

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Android Coding. Dr. J.P.E. Hodgson. August 23, Dr. J.P.E. Hodgson () Android Coding August 23, / 27

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Android File & Storage

Sound Ecology and Acoustic Health, Part 3 A Quantitative Ghost Hunting Application

Simple Data Source Crawler Plugin to Set the Document Title

,pm-diffs.patch -408, ,13

COMP61242: Task /04/18

A Crash Course to Android Mobile Platform

Software Engineering Large Practical: Accessing remote data and XML parsing. Stephen Gilmore School of Informatics October 8, 2017

COMP4521 EMBEDDED SYSTEMS SOFTWARE

shared objects monitors run() Runnable start()

2018/2/5 话费券企业客户接入文档 语雀

Lecture 7: Data Persistence : shared preferences. Lecturer : Ali Kadhim Al-Bermani Mobile Fundamentals and Programming

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Intro to Android Development 3. Accessibility Capstone Dec 10, 2010

Trusted Source SSO. Document version 2.3 Last updated: 30/10/2017.

1D/2D android secondary development

Android Application Development. By : Shibaji Debnath

LISTING PROGRAM APLIKASI ANDROID

Network Communication. 8.1 Introduction

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

LISTING PROGRAM. com.example.jessicatamara.myapplication4;

POCKET STUDY. Divyam Kumar Mishra, Mrinmoy Kumar Das Saurav Singh, Prince Kumar

2.2 IoT Internet of Things Android Studio

APPENDIX. Application User. MainActivity.java. RegistrationActivity.java

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

Transcription:

Coding Menggunakan software Eclipse: Mainactivity.java (coding untuk tampilan login): package com.bella.pengontrol_otomatis; import android.app.activity; import android.os.bundle; import android.os.countdowntimer; import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.view.menu; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; public class MainActivity extends Activity { JSONParser jparser = new JSONParser(); ProgressDialog pdialog; CountDownTimer ctr; public static String TAG_SUCCESS = "success"; public static String TAG_PRODUCT = "product"; EditText username; EditText password; Button btnlogin; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); username = (EditText)findViewById(R.id.TxtUser); password = (EditText)findViewById(R.id.TxtPass); btnlogin = (Button)findViewById(R.id.BtnLogin); btnlogin.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { TODO Auto-generated method stub if (username.gettext().tostring().equals("myhouse") && password.gettext().tostring().equals("12345678")){ Intent a = new Intent(MainActivity.this,MenuUtama.class); startactivity(a); else{

Toast.makeText(MainActivity.this, "Salah Username & Password", Toast.LENGTH_SHORT).show(); ); MenuUtama.java (coding untuk tampilan kedua setelah login): package com.bella.pengontrol_otomatis; import java.io.bufferedreader; import java.io.console; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.util.arraylist; import java.util.list; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair; import org.json.jsonexception; import org.json.jsonobject; import com.bella.pengontrol_otomatis.jsonparser; import android.r.string; import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.os.countdowntimer; import android.text.format.dateformat; import android.util.log; import android.view.view; import android.widget.button; import android.widget.compoundbutton; import android.widget.switch; import android.widget.toast;

public class MenuUtama extends Activity { JSONParser jparser = new JSONParser(); ProgressDialog pdialog; public static String TAG_SUCCESS = "success"; public static String TAG_PRODUCT = "product"; Switch door; Switch lamp1; Switch lamp2; Switch lamp3; Switch lamp4; Button logout; String tujuan; String mylink; CountDownTimer cdt; protected void oncreate(bundle savedinstancestate) { TODO Auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.layar2); door = (Switch)findViewById(R.id.switch5); lamp1 = (Switch)findViewById(R.id.switch1); lamp2 = (Switch)findViewById(R.id.switch2); lamp3 = (Switch)findViewById(R.id.switch3); lamp4 = (Switch)findViewById(R.id.switch4); logout = (Button)findViewById(R.id.btnLogout); cdt = new CountDownTimer(3000,3000) { public void ontick(long arg0) { TODO Auto-generated method stub ; public void onfinish() { TODO Auto-generated method stub door.setenabled(true); lamp1.setenabled(true); lamp2.setenabled(true); lamp3.setenabled(true); lamp4.setenabled(true); logout.setenabled(true); pdialog.dismiss();

logout.setonclicklistener(new View.OnClickListener() { public void onclick(view v) { TODO Auto-generated method stub Intent a = new Intent (MenuUtama.this,MainActivity.class); startactivity(a); ); lamp1.setoncheckedchangelistener(new public void oncheckedchanged(compoundbutton arg0, boolean arg1) { TODO Auto-generated method stub tujuan = "led1"; Log.e("switch1", String.valueOf(arg1)); kirim_data(data); ); lamp2.setoncheckedchangelistener(new public void oncheckedchanged(compoundbutton arg0, boolean arg1) { TODO Auto-generated method stub tujuan = "led2"; Log.e("switch2", String.valueOf(arg1)); kirim_data(data); ); lamp3.setoncheckedchangelistener(new

public void oncheckedchanged(compoundbutton arg0, boolean arg1) { TODO Auto-generated method stub tujuan = "led3"; Log.e("switch3", String.valueOf(arg1)); kirim_data(data); ); lamp4.setoncheckedchangelistener(new public void oncheckedchanged(compoundbutton arg0, boolean arg1) { TODO Auto-generated method stub tujuan = "led4"; Log.e("Switch4", String.valueOf(arg1)); kirim_data(data); ); door.setoncheckedchangelistener(new public void oncheckedchanged(compoundbutton arg0, boolean arg1) { TODO Auto-generated method stub tujuan = "pintu"; Log.e("switch5", String.valueOf(arg1)); kirim_data(data); ); void kirim_data(string data){ mylink = "http:192.168.4.1/?"+tujuan+"="+data; Log.e("link", mylink); HttpAsyncTask hat = new HttpAsyncTask(); hat.execute(mylink); class ubahswitch extends AsyncTask<String, String, String> { String status = "0";

protected void onpreexecute() { TODO Auto-generated method stub super.onpreexecute(); door.setenabled(false); lamp1.setenabled(false); lamp2.setenabled(false); lamp3.setenabled(false); lamp4.setenabled(false); logout.setenabled(false); pdialog = new ProgressDialog(MenuUtama.this); pdialog.settitle("mencoba Ubah Button"); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); protected String doinbackground(string... params) { TODO Auto-generated method stub String URLLogin; ConnectionClass con = new ConnectionClass(""); URLLogin = con.getconn(); int success; String date = (DateFormat.format("dd-MM-yyyy hh:mm:ss", new java.util.date()).tostring()); try { List<NameValuePair> param1 = new ArrayList<NameValuePair>(); param1.add(new BasicNameValuePair("imei", imei)); param1.add(new BasicNameValuePair(tujuan, params[0])); JSONObject json = jparser.makehttprequest(urllogin, "GET", param1); success = json.getint(tag_success); if (success == 1) { JSONArray jarray=json.getjsonarray(tag_product); nama_toko = new String[jArray.length()]; for(int i=0;i<jarray.length();i++) { JSONObject jobject=jarray.getjsonobject(i); nama_toko[i]=jobject.getstring("nama"); JSONArray jarray=json.getjsonarray(tag_product); JSONObject jobject=jarray.getjsonobject(0);

status = "1"; else { status = "0"; catch (Exception e) { e.printstacktrace(); return null; protected void onpostexecute(string result) { cdt.start(); TODO Auto-generated method stub if (status.equals("1")) { pdialog.dismiss(); Toast.makeText(MenuUtama.this, "Sukses Merubah SWITCH", Toast.LENGTH_LONG).show(); Toast.makeText(FullscreenActivity.this, "absen cuy latitude = " + String.valueOf(latitude)+" longitude = " + String.valueOf(longitude), Toast.LENGTH_SHORT).show(); startactivity(myintent); else { pdialog.dismiss(); decrypt="null"; Toast.makeText(MenuUtama.this, "Tidak Merubah SWITCH", Toast.LENGTH_LONG).show(); private class HttpAsyncTask extends AsyncTask<String, Void, String> { protected String doinbackground(string... urls) { return httprequestresponse(urls[0]); onpostexecute displays the results of the AsyncTask.

protected void onpostexecute(string result) { For HttpAsync Functions: sending requests and receiving responses public static String httprequestresponse(string url) { InputStream inputstream = null; String result = ""; try { create HttpClient HttpClient httpclient = new DefaultHttpClient(); make GET request to the given URL HttpResponse httpresponse = httpclient.execute(new HttpGet(url)); receive response as inputstream inputstream = httpresponse.getentity().getcontent(); convert InputStream to string if (inputstream!= null) result = convertinputstreamtostring(inputstream); else result = "InputStream did not work"; catch (Exception e) { Log.d("InputStream", e.getlocalizedmessage()); return result; private static String convertinputstreamtostring(inputstream inputstream) throws IOException { BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(inputStream)); String line = ""; String result = ""; while ((line = bufferedreader.readline())!= null) result += line; inputstream.close(); return result;