Aplikasi Pekerja Lepas Berbasis Android

1

LAMPIRAN PROGRAM

JAVA

ListArrayAdapterPost.java
package com.example.win.api.Adapter;
import
import
import
import
import
import
import

android.content.Context;
android.support.annotation.NonNull;
android.view.LayoutInflater;
android.view.View;
android.view.ViewGroup;

android.widget.ArrayAdapter;
android.widget.TextView;

import com.example.win.api.Model.ModelDataPost;
import com.example.win.api.R;
import java.util.ArrayList;
/**
* Created by JhonDev on 07/10/2016.
*/
public class ListArrayAdapterPost extends ArrayAdapter {
private
private
private
private

ArrayList list;
LayoutInflater inflater;
int res;
Context c;


public ListArrayAdapterPost(Context context, int resource,
ArrayList list) {
super(context, resource, list);
this.c=context;
this.list = list;
this.inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.res = resource;
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup
parent) {
MyHolder holder = null;

Universitas Sumatera Utara

2
if (convertView == null) {
convertView = inflater.inflate(res, parent, false);

holder = new MyHolder();
holder.ID = (TextView) convertView.findViewById(R.id.listID);
holder.Nama = (TextView)
convertView.findViewById(R.id.listNama);
holder.Jenis = (TextView)
convertView.findViewById(R.id.listKeterangan);

convertView.setTag(holder);
} else {
holder = (MyHolder) convertView.getTag();
}
holder.ID.setText("Id Postt : "+list.get(position).getidPost());
holder.Nama.setText(" "+list.get(position).gettitlepost());
return convertView;
}
@Override
public int getCount() {
return list.size();
}
@Override

public void remove(ModelDataPost object) {
super.remove(object);
}
@Override
public void clear() {
super.clear();
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
static class MyHolder {
TextView ID;
TextView Nama;
TextView Jenis;

Universitas Sumatera Utara

3


}
}

ApiServicePost.java
package com.example.win.api.API;

import com.example.win.api.Model.ModelDataPost;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

public interface ApiServicePost {
@GET("show_post.php")
Call getSemuaMhs();
@GET("detail_post.php")
Call getSingleData(@Query("id_post") String id);

}


ModelDataPost.java
package com.example.win.api.Model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ModelDataPost {
@SerializedName("id_post")
@Expose
private String idPost;
@SerializedName("title")
@Expose
private String titlePost;
@SerializedName("komen")
@Expose
private String komenPost;

Universitas Sumatera Utara

4

@SerializedName("phone")

@Expose
private String keteranganPhone;

public
public
public
public

static
static
static
static

final
final
final
final

String
String

String
String

idpost = "ID_POST";
titlepost = "ID_POST";
komenpost = "ID_POST";
phonee = "ID_POST";

public ModelDataPost(String id, String title, String komen, String
keteranganPhone) {
this.idPost = id;
this.titlePost = title;
this.komenPost = komen;
this.keteranganPhone=keteranganPhone;
}

public ModelDataPost(String id, String title, String komen, String
keteranganPhone, String gambar) {
this.idPost = id;
this.titlePost = title;

this.komenPost = komen;
this.keteranganPhone=keteranganPhone;

}
/**
*
* @return
*
The idFlora
*/
public String getidPost() {
return idPost;
}
/**
*
* @param idPost
*
The idFlora
*/
public void setIdpost(String idPost) {

this.idPost = idPost;
}
/**
*
* @return
*
The nama
*/

Universitas Sumatera Utara

5
public String gettitlepost() {
return titlePost;
}
/**
*
* @param titlePost
*
The Nama

*/
public void setnamatitle(String titlePost) {
this.titlePost = titlePost;
}
/**
*
* @return
*
The jenis
*/
public String getkomenpos() {
return komenPost;
}
/**
*
* @param komenPos
*
The Jenis
*/
public void setkomenpos(String komenPos) {
this.komenPost = komenPost;
}
/**
*
* @return
*
The jenis
*/
public String getKeteranganPhone() {
return keteranganPhone;
}
/**
*
* @param keteranganPhone
*
The Jenis
*/
public void setKeteranganPhone(String keteranganPhone) {
this.keteranganPhone = keteranganPhone;
}

}

Universitas Sumatera Utara

6

Akunku.java
package com.example.win.api;
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.app.ProgressDialog;
android.content.Intent;
android.os.Bundle;
android.text.Html;
android.view.View;
android.widget.Button;
android.widget.ListView;
android.widget.TextView;
android.widget.Toast;

import org.json.JSONArray;
import java.util.HashMap;
public class Akunku extends Activity {
Button logout, post, home;
SessionManager session;
ListView lv;
ProgressDialog pDialog;
JSONArray contacts = null;
String username, first_name;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.akunku);
//membuat session untuk user
session = new SessionManager(getApplicationContext());
Toast.makeText(getApplicationContext(), "User Login Status:" +
session.isLoggedIn(), Toast.LENGTH_LONG).show();
session.checkLogin();
HashMap user = session.getUserDetails();
username = user.get(SessionManager.KEY_USERNAME);
first_name = user.get(SessionManager.KEY_FIRST_NAME);
TextView status = (TextView)findViewById(R.id.status);
status.setText(Html.fromHtml("Welcome, "+first_name+""));
//inisiasi tombol Logout dan memberi fungsi klik

Universitas Sumatera Utara

7
logout = (Button)findViewById(R.id.btn_logout);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { session.logoutUser();
finish();
}
});
post = (Button)findViewById(R.id.btn_post);
post.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(Akunku.this, Post.class);
startActivity(i);
}
});
home = (Button)findViewById(R.id.btn_home);
home.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(Akunku.this, Postt.class);
startActivity(i);
}
});
}
@Override
public void onBackPressed(){
Intent i = new Intent(getApplicationContext(), Login.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);
finish();
}
}

AlertDialogManager.java
package com.example.win.api;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

Universitas Sumatera Utara

8

public class AlertDialogManager {
@SuppressWarnings("deprecation")
public void showAlertDialog(Context context, String title, String
message, Boolean status)
{
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
//setting DoalogTitle
alertDialog.setTitle(title);
//setting Dialog Message
alertDialog.setMessage(message);
//setting OK Button
alertDialog.setButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
//showing alert message
alertDialog.show();
}
}

JSONParser.java
package com.example.win.api;
import android.util.Log;
import
import
import
import
import
import
import
import
import
import
import

org.apache.http.HttpEntity;
org.apache.http.HttpResponse;
org.apache.http.NameValuePair;
org.apache.http.client.ClientProtocolException;
org.apache.http.client.entity.UrlEncodedFormEntity;
org.apache.http.client.methods.HttpGet;
org.apache.http.client.methods.HttpPost;
org.apache.http.client.utils.URLEncodedUtils;
org.apache.http.impl.client.DefaultHttpClient;
org.json.JSONException;
org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;

Universitas Sumatera Utara

9
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {

e.printStackTrace();
} catch (ClientProtocolException e) { e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new
InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " +
e.toString());
}
// try parse the string to a JSON object

Universitas Sumatera Utara

10
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
public JSONObject makeHttpRequest(String url, String method,
List params) {
// Making HTTP request
try {
// check for request method
if (method == "POST") {
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new
DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new
UrlEncodedFormEntity(params));
HttpResponse httpResponse =
httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} else if (method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new
DefaultHttpClient();
String paramString =
URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse =
httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();

Universitas Sumatera Utara

11
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new
InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " +
e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}

Login.java
package com.example.win.api;
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.app.ProgressDialog;
android.content.Intent;
android.os.AsyncTask;
android.os.Bundle;
android.util.Log;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;
android.widget.Toast;

Universitas Sumatera Utara

12
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class Login extends Activity {
Button login;
Intent a;
EditText username, password;
TextView verify;
String url, success;
SessionManager session;
AlertDialogManager alert = new AlertDialogManager();
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState) ;
setContentView(R.layout.login);
session = new SessionManager(getApplicationContext());
Toast.makeText(getApplicationContext(),"user Login Status:" +
session.isLoggedIn(), Toast.LENGTH_LONG).show();
login
username
password
verify

= (Button)findViewById(R.id.btn_login);
= (EditText)findViewById(R.id.fld_username);
= (EditText)findViewById(R.id.fld_pwd);
= (TextView)findViewById(R.id.verify);

login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
url="http://192.168.43.219/login/login.php?" +
"username=" + username.getText().toString() + "&password="
+ password.getText().toString();
if(username.getText().toString().trim().length()>0
&& password.getText().toString().trim().length()>0){
new AmbilData().execute();
}else{

Universitas Sumatera Utara

13
alert.showAlertDialog(Login.this,"Login Failed...!",
"Please insert your username and password",false);
}
}
});
verify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = new Intent(Login.this, Register.class);
startActivity(a);
}
});
}
public class AmbilData extends AsyncTask {
ArrayList contactList = new ArrayList<
HashMap>(); ProgressDialog pDialog;
@Override
protected void onPreExecute() { super.onPreExecute();
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Loading Data..."); pDialog.setIndeterminate(false);
pDialog.show();
}

@Override
protected String doInBackground(String... arg0) { JSONParser
jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
try {
success = json.getString("success");
Log.e("error", "nilai sukses=" + success);
JSONArray hasil = json.getJSONArray("login");
if (success.equals("1")) {

Universitas Sumatera Utara

14
for (int i = 0; i < hasil.length(); i++) { JSONObject c
= hasil.getJSONObject(i);
//Storing each json item in variable
String username = c.getString("username").trim();
String email = c.getString("email").trim();
session.createLoginSession(username, email); Log.e("ok", "ambil data");
}
} else {
Log.e("Error", "tidak bisa ambil data 0");
}
} catch (Exception e) {
Log.e("Error", "Tidak bisa ambil data 1");
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result); pDialog.dismiss(); if(success.equals("1")){
a = new Intent(Login.this, Akunku.class); startActivity(a);
finish();
}else{
Toast.makeText(getBaseContext(), "Username/password
incorrect!!", Toast.LENGTH_SHORT).show();
alert.showAlertDialog(Login.this, "Login Failed..",
"Username/Password is incorrect",false);
}
}
}
}

Universitas Sumatera Utara

15

MainPost.java
package com.example.win.api;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainPost extends AppCompatActivity {
public static final String ROOT_URL = "http://192.168.43.219/login/";
//192.168.43.16
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
}
}

Post.java
package com.example.win.api;
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.app.ProgressDialog;
android.content.Intent;
android.os.AsyncTask;
android.os.Bundle;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.Toast;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class Post extends Activity {
ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
EditText title, komen, phone;
Intent a;

private static String url = "http://192.168.43.219/login/post.php";

Universitas Sumatera Utara

16

Button submit;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.post);
submit
title
komen
phone

=
=
=
=

(Button)findViewById(R.id.btn_submit);
(EditText)findViewById(R.id.fld_title);
(EditText)findViewById(R.id.fld_komen);
(EditText)findViewById(R.id.fld_phone);

submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new InputData().execute();
}
});

}
public class InputData extends AsyncTask {
String success;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Post.this);
pDialog.setMessage("Process...");
pDialog.setIndeterminate(false);
pDialog.show();

}
@Override
protected String doInBackground(String... args) {
String strtitle =title.getText().toString();
String strkomen =komen.getText().toString();
String strphone
=phone.getText().toString();

List params = new ArrayList();

Universitas Sumatera Utara

17
params.add(new BasicNameValuePair("title",strtitle));
params.add(new BasicNameValuePair("komen",strkomen));
params.add(new BasicNameValuePair("phone",strphone));

JSONObject json =
jsonParser.makeHttpRequest(url,
"POST", params);
try {
success = json.getString("success");
} catch (Exception e) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Error",
Toast.LENGTH_SHORT).show();
}
});
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
if (success.equals("1")) {
Toast.makeText(getApplicationContext(),"Succesed",
Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"Failed",
Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onBackPressed(){
Intent i = new Intent(getApplicationContext(),Akunku.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);
finish();
}
}

Universitas Sumatera Utara

18

Postt.java
package com.example.win.api;
import
import
import
import
import
import
import
import
import
import
import
import

android.content.Intent;
android.graphics.Bitmap;
android.graphics.BitmapFactory;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.util.Log;
android.view.View;
android.widget.AdapterView;
android.widget.ImageView;
android.widget.LinearLayout;
android.widget.ListView;
android.widget.TextView;

import com.example.win.api.API.ApiServicePost;
import com.example.win.api.Adapter.ListArrayAdapterPost;
import com.example.win.api.Model.ModelDataPost;
import java.util.ArrayList;
import java.util.List;
import
import
import
import
import

retrofit2.Call;
retrofit2.Callback;
retrofit2.Response;
retrofit2.Retrofit;
retrofit2.converter.gson.GsonConverterFactory;

public class Postt extends AppCompatActivity implements
AdapterView.OnItemClickListener {

ArrayList datapost = new ArrayList();
ListView listview;
ListArrayAdapterPost adapter;
LinearLayout layout_loading;
TextView text_load;
ImageView icon_load;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.postt);
layout_loading = (LinearLayout) findViewById(R.id.layout_loading);
text_load = (TextView) findViewById(R.id.text_load);
icon_load = (ImageView) findViewById(R.id.icon_load);
listview = (ListView) findViewById(R.id.listMhsMhs);

Universitas Sumatera Utara

19
listview.setOnItemClickListener(Postt.this);
listview.setDividerHeight(0);
setup();

}
public void setup() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MainPost.ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiServicePost service = retrofit.create(ApiServicePost.class);
Call call = service.getSemuaMhs();
call.enqueue(new Callback() {
@Override
public void onResponse(Call call,
Response response) {
if (response.isSuccessful()) {
int jumlah = response.body().size();
for (int i = 0; i < jumlah; i++) {
ModelDataPost data = new ModelDataPost(
response.body().get(i).getidPost(),
response.body().get(i).gettitlepost(),
response.body().get(i).getkomenpos(),
response.body().get(i).getKeteranganPhone());
datapost.add(data);
Log.d("RESPON", "onResponse: " +
response.body().get(i).getidPost());
}
listview.setVisibility(View.VISIBLE);
adapter = new ListArrayAdapterPost(Postt.this,
R.layout.row_post, datapost);
listview.setAdapter(adapter);
if (adapter.getCount() < 1 ) {
layout_loading.setVisibility(View.VISIBLE);
String error = "Daftar Postt Kosong";
text_load.setText(error);
Bitmap icon =
BitmapFactory.decodeResource(getResources(), R.drawable.ic_data_kosong);
icon_load.setImageBitmap(icon);
} else {
layout_loading.setVisibility(View.GONE);
}

Universitas Sumatera Utara

20
} else {
String error = "Error Retrive Data from Server !!!";
text_load.setText(error);
Bitmap icon =
BitmapFactory.decodeResource(getResources(), R.drawable.ic_network);
icon_load.setImageBitmap(icon);
}
}
@Override
public void onFailure(Call call, Throwable
t) {
String error = "Error Retrive Data from Server wwaau!!!\n"
+ t.getMessage();
text_load.setText(error);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_network);
icon_load.setImageBitmap(icon);
}
});
}
@Override
public void onItemClick(AdapterView parent, View view, int position,
long id) {
Intent intent = new Intent(Postt.this, TampilPost.class);

intent.putExtra(ModelDataPost.idpost,datapost.get(position).getidPost());
startActivity(intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
adapter.clear();
setup();
}
}
}

Register.java
package com.example.win.api;
import android.app.Activity;

Universitas Sumatera Utara

21
import
import
import
import
import
import
import
import
import

android.app.ProgressDialog;
android.content.Intent;
android.os.AsyncTask;
android.os.Bundle;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;
android.widget.Toast;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class Register extends Activity {
ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
EditText first_name,last_name,email,username,password;
Intent a;

private static String url = "http://192.168.43.219/login/register.php";
Button register;
TextView verify;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
register
verify
first_name
last_name
email
username
password

=
=
=
=
=
=
=

(Button)findViewById(R.id.btn_register);
(TextView)findViewById(R.id.verify);
(EditText)findViewById(R.id.fld_first);
(EditText)findViewById(R.id.fld_last);
(EditText)findViewById(R.id.fld_email);
(EditText)findViewById(R.id.fld_username);
(EditText)findViewById(R.id.fld_pwd);

register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

Universitas Sumatera Utara

22
new InputData().execute();
}
});
verify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = new Intent(Register.this, Login.class);
startActivity(a);
}
});
}
public class InputData extends AsyncTask {
String success;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Register.this);
pDialog.setMessage("Registering Account...");
pDialog.setIndeterminate(false);
pDialog.show();

}
@Override
protected String doInBackground(String... args) {
String strfirst_name=first_name.getText().toString();
String strlast_name=last_name.getText().toString();
String stremail
=email.getText().toString();
String strusername=username.getText().toString();
String strpassword=password.getText().toString();
List params = new ArrayList();
params.add(new BasicNameValuePair("first_name",strfirst_name));
params.add(new BasicNameValuePair("last_name",strlast_name));
params.add(new BasicNameValuePair("email",stremail));
params.add(new BasicNameValuePair("username",strusername));
params.add(new BasicNameValuePair("password",strpassword));
JSONObject json =
jsonParser.makeHttpRequest(url,
"POST", params);
try {
success = json.getString("success");
} catch (Exception e) {
runOnUiThread(new Runnable() {

Universitas Sumatera Utara

23
public void run() {
Toast.makeText(getApplicationContext(), "Error",
Toast.LENGTH_SHORT).show();
}
});
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
if (success.equals("1")) {
Toast.makeText(getApplicationContext(),"Registration
Succesed", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),"Registration
Failed", Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onBackPressed(){
Intent i = new Intent(getApplicationContext(),Login.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i);
finish();
}
}

SessionManager.java
package com.example.win.api;
import
import
import
import
import

android.annotation.SuppressLint;
android.content.Context;
android.content.Intent;
android.content.SharedPreferences;
android.content.SharedPreferences.Editor;

import java.util.HashMap;

Universitas Sumatera Utara

24
@SuppressLint("CommitPrefEdits")
public class SessionManager {
//Shared Preferences
SharedPreferences pref;
//Editor for Shared preferences
Editor editor;
//context
Context _context;
//shared pref mode
int PRIVATE_MODE = 0;
//nama sharepreference
private static final String PREF_NAME = "Sesi";
// All Shared Preferences Keys
private static final String IS_LOGIN = "IsLoggedIn";
public static final String KEY_USERNAME = "username";
public static final String KEY_FIRST_NAME = "first_name";
//constructor
public SessionManager(Context context){
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
//Create Login Session
public void createLoginSession(String username, String first_name){
//Storing Login value as TRUE
editor.putBoolean(IS_LOGIN, true);
editor.putString(KEY_USERNAME, username);
editor.putString(KEY_FIRST_NAME, first_name);
editor.commit();
}
/**
* Check Login method wil check user Login status
* If false it will redirect user to Login page
* Else won't do anything
* */

public void checkLogin(){
// Check Login status

Universitas Sumatera Utara

25
if(!this.isLoggedIn()) {
Intent i = new Intent(_context, Login.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(i);
}
}
/**
* Get stored session data
* */
public HashMap getUserDetails(){
HashMap user = new HashMap();
user.put(KEY_USERNAME, pref.getString(KEY_USERNAME, null));
user.put(KEY_FIRST_NAME, pref.getString(KEY_FIRST_NAME, null));
return user;
}
/**
* Clear session details
* */
public void logoutUser(){
// Clearing all data from Shared Preferences editor.clear();
editor.commit();
Intent i = new Intent(_context, Login.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(i);
}
public boolean isLoggedIn(){
return pref.getBoolean(IS_LOGIN, false);
}
}

Universitas Sumatera Utara

26

SplashScreen.java
package com.example.win.api;
import
import
import
import
import
import

android.app.Activity;
android.content.Intent;
android.os.Bundle;
android.os.Handler;
android.view.Window;
android.view.WindowManager;

public class SplashScreen extends Activity {
//Set waktu lama splashscreen
private static int splashInterval = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Intent i = new Intent(SplashScreen.this, Login.class);
startActivity(i);

//jeda selesai Splashscreen
this.finish();
}
private void finish() {
// TODO Auto-generated method stub
}
}, splashInterval);
}
;
}

Universitas Sumatera Utara

27

TampilPost.java
package com.example.win.api;
import
import
import
import
import

android.net.Uri;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.widget.ImageView;
android.widget.TextView;

import
import
import
import
import

com.example.win.api.API.ApiServicePost;
com.example.win.api.Model.ModelDataPost;
com.google.android.gms.appindexing.Action;
com.google.android.gms.appindexing.AppIndex;
com.google.android.gms.common.api.GoogleApiClient;

import java.util.List;
import
import
import
import
import

retrofit2.Call;
retrofit2.Callback;
retrofit2.Response;
retrofit2.Retrofit;
retrofit2.converter.gson.GsonConverterFactory;

public class TampilPost extends AppCompatActivity {
String ID_POST;
TextView et_id, et_nama, et_keterangan, et_phone;
ImageView et_gambar;
/**
* ATTENTION: This was auto-generated to implement the App Indexing
API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_post);
ID_POST = getIntent().getStringExtra(ModelDataPost.idpost);
et_id = (TextView) findViewById(R.id.tampil_id);
et_nama = (TextView) findViewById(R.id.tampil_nama);
et_keterangan = (TextView) findViewById(R.id.tampil_keterangan);
et_phone = (TextView) findViewById(R.id.tampil_phone);
et_gambar = (ImageView) findViewById(R.id.tampil_gambar);
bindData();
// ATTENTION: This was auto-generated to implement the App Indexing
API.

Universitas Sumatera Utara

28
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new
GoogleApiClient.Builder(this).addApi(AppIndex.API).build();

}
public void bindData() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MainPost.ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
ApiServicePost service = retrofit.create(ApiServicePost.class);
Call call = service.getSingleData(ID_POST);
call.enqueue(new Callback() {

@Override
public void onResponse(Call call, final
Response response) {
if (response.isSuccessful()) {
try {
int jumlah = response.body().size();
for (int i = 0; i < jumlah; i++) {
final int finalI = i;
runOnUiThread(new Runnable() {
@Override
public void run() {

et_id.setText(response.body().get(finalI).getidPost());
et_nama.setText(response.body().get(finalI).gettitlepost());
et_keterangan.setText(response.body().get(finalI).getkomenpos());
et_phone.setText(response.body().get(finalI).getKeteranganPhone());

}
});
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

Universitas Sumatera Utara

29
@Override
public void onFailure(Call call, Throwable
t) {

}
});
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing
API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"TampilPost Page", // TODO: Define a title for the content
shown.
// TODO: If you have web page content that matches this app
activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("androidapp://com.example.win.api/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing
API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"TampilPost Page", // TODO: Define a title for the content
shown.
// TODO: If you have web page content that matches this app
activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("androidapp://com.example.win.api/http/host/path")

Universitas Sumatera Utara

30
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}

}

XML

activity_detail_post.xml






















activity_post.xml





akunku.xml















Universitas Sumatera Utara

35

loading_and_result.xml








login.xml










Universitas Sumatera Utara

37







Universitas Sumatera Utara

38




post.xml




















Universitas Sumatera Utara

41





postt.xml








register.xml




Universitas Sumatera Utara

42