Android Open Source - KendaliPintuAndroid Device Status Activity






From Project

Back to project page KendaliPintuAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project KendaliPintuAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2014 Dimas Rullyan Danu
 * /*  www  . j  a  v a 2 s  .com*/
 * Kendali Pintu is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kendali Pintu is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kendali Pintu. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package com.dimasdanz.kendalipintu;

import com.dimasdanz.kendalipintu.R;
import com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusLoadData;
import com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusSendData;
import com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusLoadData.DeviceStatusLoadDataListener;
import com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusSendData.DeviceStatusSendDataListener;
import com.dimasdanz.kendalipintu.util.CommonUtilities;
import com.dimasdanz.kendalipintu.util.StaticString;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.Toast;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;

public class DeviceStatusActivity extends FragmentActivity implements OnCheckedChangeListener, DeviceStatusLoadDataListener, DeviceStatusSendDataListener {
  private Switch statusSwitch;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_device_status);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    statusSwitch = (Switch)findViewById(R.id.swStatus);
    
    new DeviceStatusLoadData(this).execute();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.device_status, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
      NavUtils.navigateUpFromSameTask(this);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    new DeviceStatusSendData(this).execute(isChecked);
  }

  @Override
  public void onLoadDataProgress() {
    setView(0);
  }

  @Override
  public void onLoadDataComplete(String results) {
    if(results != null){
      if(results.equals(StaticString.TAG_STATUS_ACTIVE)){
        setView(2);
        statusSwitch.setChecked(true);
        statusSwitch.setOnCheckedChangeListener(this);
      }else if(results.equals(StaticString.TAG_STATUS_INACTIVE)){
        setView(2);
        statusSwitch.setChecked(false);
        statusSwitch.setOnCheckedChangeListener(this);
      }else{
        setView(1);
      }
    }else{
      CommonUtilities.dialogConnectionError(this);
    }
  }

  @Override
  public void onSendDataComplete(Boolean result) {
    if(result != null){
      if(result){
        Toast.makeText(this, R.string.toast_device_status_on, Toast.LENGTH_SHORT).show();
      }else{
        Toast.makeText(this, R.string.toast_device_status_off, Toast.LENGTH_SHORT).show();
      }
    }else{
      Toast.makeText(this, R.string.toast_connection_error, Toast.LENGTH_SHORT).show();
    }
  }
  
  public void setView(int type){
    switch (type) {
    case 0:
      findViewById(R.id.layout_progress_bar).setVisibility(View.VISIBLE);
      findViewById(R.id.layout_device_offline).setVisibility(View.GONE);
      findViewById(R.id.layout_status).setVisibility(View.GONE);
      break;
    case 1:
      findViewById(R.id.layout_progress_bar).setVisibility(View.GONE);
      findViewById(R.id.layout_device_offline).setVisibility(View.VISIBLE);
      findViewById(R.id.layout_status).setVisibility(View.GONE);
      break;
    case 2:
      findViewById(R.id.layout_progress_bar).setVisibility(View.GONE);
      findViewById(R.id.layout_device_offline).setVisibility(View.GONE);
      findViewById(R.id.layout_status).setVisibility(View.VISIBLE);
      break;
    default:
      findViewById(R.id.layout_progress_bar).setVisibility(View.GONE);
      findViewById(R.id.layout_device_offline).setVisibility(View.GONE);
      findViewById(R.id.layout_status).setVisibility(View.GONE);
      break;
    }
  }  
}




Java Source Code List

com.dimasdanz.kendalipintu.BarcodeOpenDoorActivity.java
com.dimasdanz.kendalipintu.DeviceStatusActivity.java
com.dimasdanz.kendalipintu.LogActivity.java
com.dimasdanz.kendalipintu.LoginActivity.java
com.dimasdanz.kendalipintu.MainActivity.java
com.dimasdanz.kendalipintu.NFCOpenDoorActivity.java
com.dimasdanz.kendalipintu.RemoteOpenDoor.java
com.dimasdanz.kendalipintu.SettingsActivity.java
com.dimasdanz.kendalipintu.SettingsFragment.java
com.dimasdanz.kendalipintu.SetupActivity.java
com.dimasdanz.kendalipintu.UserActivity.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusLoadData.java
com.dimasdanz.kendalipintu.devicestatusmodel.DeviceStatusSendData.java
com.dimasdanz.kendalipintu.logmodel.LogAdapter.java
com.dimasdanz.kendalipintu.logmodel.LogLoadData.java
com.dimasdanz.kendalipintu.logmodel.LogLoadDetail.java
com.dimasdanz.kendalipintu.logmodel.LogModel.java
com.dimasdanz.kendalipintu.opendoor.BarcodePreview.java
com.dimasdanz.kendalipintu.usermodel.UserAdapter.java
com.dimasdanz.kendalipintu.usermodel.UserDialogManager.java
com.dimasdanz.kendalipintu.usermodel.UserListView.java
com.dimasdanz.kendalipintu.usermodel.UserLoadData.java
com.dimasdanz.kendalipintu.usermodel.UserModel.java
com.dimasdanz.kendalipintu.usermodel.UserSendData.java
com.dimasdanz.kendalipintu.util.AdminLoginDialog.java
com.dimasdanz.kendalipintu.util.CommonUtilities.java
com.dimasdanz.kendalipintu.util.GcmBroadcastReceiver.java
com.dimasdanz.kendalipintu.util.GcmIntentService.java
com.dimasdanz.kendalipintu.util.JSONParser.java
com.dimasdanz.kendalipintu.util.LoginAuth.java
com.dimasdanz.kendalipintu.util.ServerUtilities.java
com.dimasdanz.kendalipintu.util.SharedPreferencesManager.java
com.dimasdanz.kendalipintu.util.StaticString.java
com.dimasdanz.kendalipintu.util.UniversalDialogManager.java