• Tidak ada hasil yang ditemukan

Aplikasi Pekerja Lepas Berbasis Android

N/A
N/A
Protected

Academic year: 2017

Membagikan "Aplikasi Pekerja Lepas Berbasis Android"

Copied!
60
0
0

Teks penuh

(1)

LAMPIRAN PROGRAM

JAVA

ListArrayAdapterPost.java

package com.example.win.api.Adapter;

import android.content.Context;

import android.support.annotation.NonNull; import android.view.LayoutInflater;

import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import 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<ModelDataPost> {

private ArrayList<ModelDataPost> list; private LayoutInflater inflater;

private int res; private Context c;

public ListArrayAdapterPost(Context context, int resource, ArrayList<ModelDataPost> 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) {

(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 {

(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<List<ModelDataPost>> getSemuaMhs();

@GET("detail_post.php")

Call<List<ModelDataPost>> 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

(4)

@SerializedName("phone") @Expose

private String keteranganPhone;

public static final String idpost = "ID_POST"; public static final String titlepost = "ID_POST"; public static final String komenpost = "ID_POST"; public static final String 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;

}

/** *

(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;

}

(6)

Akunku.java

package com.example.win.api;

import android.app.Activity;

import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.text.Html; import android.view.View; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import 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<String, String> 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, <b>"+first_name+"</b>"));

(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;

(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 org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair;

import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException;

import org.json.JSONObject;

(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());

}

(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<NameValuePair> 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();

(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 android.app.Activity;

(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 = (Button)findViewById(R.id.btn_login); username = (EditText)findViewById(R.id.fld_username); password = (EditText)findViewById(R.id.fld_pwd); verify = (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();

(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<String,String,String> { ArrayList<HashMap<String, String>> contactList = new ArrayList< HashMap<String, String>>(); 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");

(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);

}

}

}

(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 android.app.Activity;

import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import 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;

(16)

Button submit;

@Override

protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub

super.onCreate(savedInstanceState); setContentView(R.layout.post);

submit = (Button)findViewById(R.id.btn_submit); title = (EditText)findViewById(R.id.fld_title); komen = (EditText)findViewById(R.id.fld_komen); phone = (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, String, String> { 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();

(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();

}

(18)

Postt.java

package com.example.win.api;

import android.content.Intent; import android.graphics.Bitmap;

import android.graphics.BitmapFactory; import android.os.Bundle;

import android.support.v7.app.AppCompatActivity; import android.util.Log;

import android.view.View;

import android.widget.AdapterView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import 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 retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit;

import retrofit2.converter.gson.GsonConverterFactory;

public class Postt extends AppCompatActivity implements AdapterView.OnItemClickListener {

ArrayList<ModelDataPost> datapost = new ArrayList<ModelDataPost>(); 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);

(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<List<ModelDataPost>> call = service.getSemuaMhs(); call.enqueue(new Callback<List<ModelDataPost>>() { @Override

public void onResponse(Call<List<ModelDataPost>> call, Response<List<ModelDataPost>> 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 {

(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<List<ModelDataPost>> 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;

(21)

import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import 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 = (Button)findViewById(R.id.btn_register); verify = (TextView)findViewById(R.id.verify); first_name = (EditText)findViewById(R.id.fld_first); last_name = (EditText)findViewById(R.id.fld_last); email = (EditText)findViewById(R.id.fld_email); username = (EditText)findViewById(R.id.fld_username); password = (EditText)findViewById(R.id.fld_pwd);

register.setOnClickListener(new View.OnClickListener() { @Override

public void onClick(View arg0) {

(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, String, String> { 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<NameValuePair> params = new ArrayList<NameValuePair>(); 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) {

(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 android.annotation.SuppressLint; import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

(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

* */

(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<String, String> getUserDetails(){

HashMap<String,String> user = new HashMap<String,String>(); 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);

}

(26)

SplashScreen.java

package com.example.win.api;

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

import 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);

}

;

(27)

TampilPost.java

package com.example.win.api;

import android.net.Uri; import android.os.Bundle;

import android.support.v7.app.AppCompatActivity; import android.widget.ImageView;

import android.widget.TextView;

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

import com.google.android.gms.common.api.GoogleApiClient;

import java.util.List;

import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit;

import 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();

(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<List<ModelDataPost>> call = service.getSingleData(ID_POST); call.enqueue(new Callback<List<ModelDataPost>>() {

@Override

public void onResponse(Call<List<ModelDataPost>> call, final Response<List<ModelDataPost>> 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(); }

(29)

@Override

public void onFailure(Call<List<ModelDataPost>> call, Throwable t) {

// See https://g.co/AppIndexing/AndroidStudio for more information. client.connect();

AppIndex.AppIndexApi.start(client, viewAction); }

(30)

);

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

}

}

XML

activity_detail_post.xml

<?xml version="1.0" encoding="utf-8" ?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"

android:padding="10dp"

android:background="#ffffff" android:id="@+id/activity_main"

>

<ScrollView

android:layout_width="fill_parent" android:layout_height="fill_parent">

<RelativeLayout

android:layout_width="fill_parent" android:layout_height="fill_parent">

<TextView

android:background="@drawable/a2" android:visibility="gone"

android:gravity="center"

android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/judul"

android:text="Description" android:fontFamily="times" android:textSize="25dp"

(31)

android:textStyle="bold"/>

<ImageView

android:visibility="gone"

android:layout_below="@+id/judul" android:paddingLeft="5dp"

android:paddingRight="5dp" android:background="#f4f3f3"

android:src="@drawable/ic_download_data" android:id="@+id/tampil_gambar"

android:layout_width="match_parent" android:layout_height="250dp" />

<TextView

android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/a2" android:id="@+id/tampil_nama" android:textColor="#0e0e0e" android:paddingLeft="5dp" android:paddingTop="10dp" android:paddingBottom="10dp" android:gravity="center" android:text="Nama"

android:fontFamily="times" android:textSize="15dp"

android:layout_gravity="left" android:layout_below="@+id/judul"

android:layout_toRightOf="@+id/tampil_gambar" android:layout_toEndOf="@+id/tampil_gambar" />

<TextView

android:paddingLeft="5dp" android:paddingTop="10dp" android:paddingBottom="10dp" android:textColor="#000000"

android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tampil_keterangan" android:text="Keterangan"

android:fontFamily="times" android:textSize="15dp"

android:layout_gravity="left"

android:layout_below="@+id/tampil_nama" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" />

(32)

android:paddingLeft="5dp" android:paddingBottom="10dp" android:paddingTop="10dp" android:textColor="#000000"

android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tampil_phone"

android:text="phone"

android:layout_margin="0dp" android:fontFamily="times" android:textSize="15dp"

android:layout_below="@+id/tampil_keterangan" android:layout_gravity="left"

/>

<TextView

android:visibility="gone" android:background="#10100f" android:textColor="#fff"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tampil_id"

android:layout_marginBottom="20dp" android:layout_marginTop="350dp" android:text="Id"

android:layout_margin="0dp" android:fontFamily="casual" android:textSize="25dp"

android:layout_gravity="left"

/>

</RelativeLayout> </ScrollView>

</LinearLayout>

activity_post.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

(33)

android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.win.api.MainPost">

<TextView

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />

</RelativeLayout>

akunku.xml

<?xml version="1.0" encoding="utf-8"?> <ScrollView

android:layout_height="match_parent" android:layout_width="match_parent"

xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="false">

<RelativeLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<ImageView android:layout_width="fill_parent" android:layout_height="150dp"

(34)

android:layout_centerHorizontal="true" android:layout_marginLeft="2dp"

android:layout_marginTop="25dp" android:orientation="horizontal">

</LinearLayout>

<Button

android:id="@+id/btn_home" android:layout_width="290dp"

android:layout_height="wrap_content" android:gravity="center"

android:background="@drawable/a7" android:text="List"

android:textSize="13sp" android:textStyle="bold"

android:layout_marginTop="175dp"

android:layout_below="@+id/akun_layout" android:layout_centerHorizontal="true" />

<Button

android:id="@+id/btn_post" android:layout_width="290dp"

android:layout_height="wrap_content" android:gravity="center"

android:background="@drawable/a7" android:text="Post"

android:textSize="13sp" android:textStyle="bold"

android:layout_marginTop="5dp"

android:layout_below="@+id/btn_home" android:layout_centerHorizontal="true" />

<Button

android:id="@+id/btn_logout" android:background="@drawable/a7" android:layout_width="290dp"

android:layout_height="wrap_content" android:gravity="center"

android:text="@string/lbl_logout" android:textSize="13sp"

android:textStyle="bold"

android:layout_marginTop="5dp"

android:layout_below="@+id/btn_post" android:layout_centerHorizontal="true" />

</RelativeLayout>

(35)

loading_and_result.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

android:layout_height="match_parent">

<LinearLayout

android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"

android:id="@+id/layout_loading">

<ImageView

android:id="@+id/icon_load" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center"

android:src="@drawable/ic_download_data" />

<TextView

android:id="@+id/text_load"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="Download Data From Server\nPlease wait..." android:textColor="#000"

android:textSize="15sp" android:textStyle="bold" android:gravity="center"/>

</LinearLayout>

</RelativeLayout>

login.xml

<?xml version="1.0" encoding="utf-8"?> <ScrollView

android:layout_height="match_parent" android:layout_width="match_parent"

xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="false">

<RelativeLayout

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"

(36)

tools:context=".MainActivity">

android:background="@android:color/holo_blue_dark"/>

(37)
(38)

</LinearLayout>

</RelativeLayout>

</ScrollView>

post.xml

<?xml version="1.0" encoding="utf-8"?> <ScrollView

android:layout_height="match_parent" android:layout_width="match_parent"

xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="false">

<RelativeLayout

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView

android:id="@+id/header" android:text="Post a Job"

android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"

android:padding="10dp" android:textSize="20sp"

android:textColor="@android:color/white"

android:background="@android:color/holo_blue_dark"/>

<LinearLayout

android:id="@+id/email_block"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/header" android:layout_marginLeft="2dp" android:layout_marginTop="25dp" android:orientation="horizontal">

</LinearLayout>

<LinearLayout

(39)
(40)
(41)

</LinearLayout>

</RelativeLayout> </ScrollView>

postt.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/daftar_barang" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Postt">

<ListView

android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listMhsMhs"

android:padding="6dp"

android:clipToPadding="false" android:scrollbars="none" android:visibility="gone"/>

<include layout="@layout/loading_and_result"/>

</RelativeLayout>

register.xml

<?xml version="1.0" encoding="utf-8"?> <ScrollView

android:layout_height="match_parent" android:layout_width="match_parent"

xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="false">

<RelativeLayout

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"

(42)

<TextView

android:background="@android:color/holo_blue_dark"/>

(43)
(44)
(45)

android:layout_marginLeft="40dp" android:inputType="textPassword" android:paddingLeft="5dp"

android:textSize="13sp"

android:layout_gravity="center_vertical"/>

</LinearLayout>

<Button

android:id="@+id/btn_register" android:layout_width="290dp"

android:layout_height="wrap_content" android:layout_below="@+id/pwd_block" android:layout_centerHorizontal="true" android:gravity="center"

android:layout_marginTop="15dp" android:textSize="13sp"

android:textStyle="bold" android:text="Register"/>

<LinearLayout

android:id="@+id/verify_block" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btn_register" android:layout_marginLeft="2dp"

android:layout_marginTop="25dp" android:orientation="horizontal"

android:layout_centerHorizontal="true">

<TextView

android:id="@+id/verify"

android:text="Already have an account?! Login here" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:textSize="12sp"

android:layout_gravity="center_vertical"

android:textColor="@android:color/holo_blue_light"/>

</LinearLayout>

</RelativeLayout> </ScrollView>

row_post.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/layout"

(46)

android:background="#91f5ea"

android:orientation="horizontal">

<android.support.v7.widget.CardView android:layout_marginTop="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" app:cardElevation="5dp"

app:cardCornerRadius="7dp" android:layout_margin="2dp">

<LinearLayout

android:background="@drawable/a2"

android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="7dp"

android:orientation="vertical"

>

<TextView

android:id="@+id/listNama" android:layout_width="300dp"

android:layout_height="wrap_content" android:fontFamily="times"

android:text="Nama Barang" android:textColor="#000" android:textSize="15sp" android:padding="20dp" android:textStyle="bold" />

<TextView

android:id="@+id/listID1"

android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" />

<TextView

android:id="@+id/listID" android:visibility="gone"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp"

(47)

android:visibility="gone"

android:id="@+id/listKeterangan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp"

android:text="Keterangan" android:textColor="#fff"

android:textSize="15dp" />

</LinearLayout>

<LinearLayout

android:layout_width="match_parent" android:orientation="vertical"

android:layout_height="wrap_content">

<ImageView

android:visibility="gone" android:padding="5dp"

android:layout_marginRight="5dp" android:background="#fff"

android:id="@+id/imgExample" android:layout_width="80dp" android:layout_height="80dp" android:layout_gravity="right"/>

</LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/colorPrimaryDark">

<ImageView

android:src="@drawable/fl1" android:layout_width="300dp" android:layout_height="300dp"

android:layout_centerVertical="true"

android:foregroundGravity="center_vertical" android:layout_centerHorizontal="true" />

(48)

android:id="@+id/progressBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="60dp" />

</RelativeLayout>

PHP

login.php

<?php

include "koneksi.php";

$username = $_GET["username"];

$password = $_GET["password"];

$query = "select * from user where username='$username' and password='$password' ";

$hasil = mysql_query($query);

if(mysql_num_rows($hasil) > 0)

{

$response = array();

$response["login"] = array();

while ($data = mysql_fetch_array($hasil))

{

$h['id'] = $data['id'];

$h['first_name'] = $data['first_name'];

$h['last_name'] = $data['last_name'];

$h['email'] = $data['email'];

$h['username'] = $data['username'];

array_push($response["login"], $h);

}

$response["success"] = "1";

(49)

}

else

{

$response["success"] = "0";

$response["message"] = "Insert email and password";

echo json_encode($response);

}

?>

post.php

<?php

$title = $_POST['title'];

$komen = $_POST['komen'];

$phone = $_POST['phone'];

include "koneksi.php";

$namaTabel = "post";

header('Content-Type: text/xml');

$query = "INSERT INTO $namaTabel VALUES ('','$title','$komen','$phone')";

$hasil = mysql_query($query);

if($hasil)

{

$response["success"] = "1";

$response["message"] = "Successed";

echo json_encode($response);

}

else

(50)

$response["success"] = "0";

$response["message"] = "Failed";

echo json_encode($response);

}

?>

register.php

<?php

$first_name = $_POST['first_name'];

$last_name = $_POST['last_name'];

$email = $_POST['email'];

$username = $_POST['username'];

$password = $_POST['password'];

include "koneksi.php";

$namaTabel = "user";

header('Content-Type: text/xml');

$query = "INSERT INTO $namaTabel VALUES

('','$first_name','$last_name','$email','$username','$password')";

$hasil = mysql_query($query);

if($hasil)

{

$response["success"] = "1";

$response["message"] = "Register Successed";

echo json_encode($response);

}

else

{

(51)

$response["message"] = "Register Failed";

echo json_encode($response);

}

?>

setting_server.php

<?php

define('server', 'localhost');

define('user', 'root');

define('pass', '');

define('db', 'login');

$con= mysqli_connect( server, user, pass, db);

?>

show_post.php

<?php

require_once 'setting_server.php';

$query = "select * from post";

$sql = mysqli_query($con, $query);

$ray = array();

while ($row = mysqli_fetch_array($sql) ){

(52)

"id_post"=> $row ['id_post'],

"title" =>$row ['title'],

"komen" => $row['komen'],

"phone" => $row['phone']));

}

echo json_encode($ray);

mysqli_close($con);

?>

tampil.php

<html>

<head>

<title>Freelancer</title>

</head>

<body>

<h3 align="center">Tabel data user</h3>

<table align="center" border="1" style="border-collapse: collapse" bgcolor="white" bordercolor="black"

cellpadding="8" width="80%">

<tr bgcolor="blue">

<th>No</th>

<th>Name</th>

<th>Email</th>

<th>Username</th>

<th>Password</th>

</tr>

<?php

(53)

$no=0;

$sql = mysql_query("SELECT * FROM user");

while($tampil = mysql_fetch_array($sql)) {

$no++;

?>

<tr>

<td><?php echo $no ?></td>

<td><?php echo $tampil["first_name"] ?> <?php echo $tampil["last_name"] ?></td>

<td><?php echo $tampil["email"] ?></td>

<td><?php echo $tampil["username"] ?></td>

<td><?php echo $tampil["password"] ?></td>

</tr>

<?php

}

?>

</table>

</body>

</html>

tampil_post.php

<html>

<head>

<title>Freelancer</title>

</head>

(54)

<h3 align="center">postingan user</h3>

<table align="center" border="1" style="border-collapse: collapse" bgcolor="white" bordercolor="black"

cellpadding="8" width="80%">

<tr bgcolor="blue">

<th>No</th>

<th>Judul</th>

<th>Keterangan</th>

<th>Telepon</th>

</tr>

<?php

include "koneksi.php";

$no=0;

$sql = mysql_query("SELECT * FROM post");

while($tampil = mysql_fetch_array($sql)) {

$no++;

?>

<tr>

<td><?php echo $no ?></td>

<td><?php echo $tampil["title"] ?></td>

<td><?php echo $tampil["komen"] ?></td>

<td><?php echo $tampil["phone"] ?></td>

</tr>

<?php

}

(55)

</table>

</body>

(56)
(57)
(58)
(59)
(60)

Referensi

Dokumen terkait

Daya serap air yang ditunjukkan pada Gambar 1, memberikan kecenderungan yang linier, dengan nilai R 2 = 0.869, artinya bahwa sebanyak 86,9% dari total daya

Tujuan penelitian ini dilakukan adalah untuk menentukan kadar air dan besar bilangan penyabunan dalam minyak kelapa serta menentukan apakah kadar air dan bilangan penyabunan

The main objectives of this study are the (1) measurement and mapping of the spatial distribution of the deformation rates in the study area; (2) analysis of

Sistem penilaian dengan system KPI, selain dapat mengukur kinerja orang per orang, juga bisa dilakukan untuk melakukan pengukuran kinerja secara kelompok, baik itu

Dengan menggunakan Akibat 2.3 ini, dapat dikonstruksi sebuah aljabar graf pada graf- berhingga baris tanpa sources seperti halnya pada graf berarah, dinotasikan dengan

Level 3 ini aktor harus memakan lebih banyak keju dan dihadapkan dengan musuh yang lebih banyak maka dari itu pada level 3 ini pemain harus lebih berhati-hati

informasi manajemen rumah sakit adalah suatu sistem berbasis komputer yang.. menghasilkan sekumpulan informasi yang telah diolah dan saling

Pada tahap pelaksanaan, kegiatan pembelajaran dibagi menjadi tiga bagian yaitu kegiatan awal, kegiatan inti dan kegiatan penutup. Pada kegiatan awal dimulai dengan