Android Open Source - foodroid Branch Page






From Project

Back to project page foodroid.

License

The source code is released under:

GNU General Public License

If you think the Android project foodroid 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

package com.wmc.ReservationClient;
/* www  .j  av a  2s  .  co m*/
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.TextView;

public class BranchPage extends Activity
{
  ListView listComment;
  RatingBar ratingbar;
  ImageButton btnMap;
  public static final String Branch_ID = "com.wmc.ReservationClient.Branch_ID";
  String branchID, lat, lon;
  String Server;
  private List<Comment> comments=new ArrayList<Comment>();
  DatabaseHelper db;
  
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.branchpage);
        
        listComment = (ListView)findViewById(R.id.listComment);
        btnMap = (ImageButton)findViewById(R.id.imageButtonMap);
    ratingbar = (RatingBar)findViewById(R.id.ratingBarbranch);
    ratingbar.setEnabled(false);
        branchID = getIntent().getExtras().getString(Branch_ID);
      Server = getString(R.string.Server);
        try 
        {
          db = new DatabaseHelper(this);
          
      loadBranch();
      
      LoadRating();
      
      LoadComment();
    } 
        catch (Exception e) 
    {
      e.printStackTrace();
    }
        
    }
     
  private void loadBranch()
  {
    try 
    {
      String[] select = {"Name","Picture","Address","Tel","lat","lon"};
      Cursor branchCursor = db.SelectTable("branch", select, "ID=" + branchID, "");
      branchCursor.moveToFirst();
      
      TextView txtName = (TextView)findViewById(R.id.txtName);
      txtName.setText(branchCursor.getString(0));
      
      TextView txtTel = (TextView)findViewById(R.id.txtTel);
      txtTel.setText(branchCursor.getString(3));
      
      TextView txtAddress = (TextView)findViewById(R.id.txtAddress);
      txtAddress.setText(branchCursor.getString(2));
      
      ImageView imageBranch = (ImageView)findViewById(R.id.imageView1);  
      String urlImage = "/data/data/com.wmc.ReservationClient/" + branchCursor.getString(1);
        InputStream is = new FileInputStream(urlImage);
        Bitmap bmp = BitmapFactory.decodeStream(is);
        imageBranch.setImageBitmap(bmp);
        
        lat = branchCursor.getString(4);
        lon = branchCursor.getString(5);

    } 
    catch (Exception e) 
    {
      e.printStackTrace();
    }    
  }
  
  void LoadRating()
  {
    try
    {
      String[] select2 = {"sum(rate)","count(rate)"};
      Cursor rateCursor = db.SelectTable("comment", select2, "BranchID=" + branchID, "");
      rateCursor.moveToFirst();
      if(rateCursor.getFloat(1) != 0)
      {
        float starRate = (float)rateCursor.getFloat(0)/rateCursor.getFloat(1);
        ratingbar.setRating(starRate);
      }
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  void LoadComment()
  {
    try 
    {
      String[] select = {"ID","message","rate"};
      Cursor commentCursor = db.SelectTable("comment", select, "BranchID=" + branchID, "");
      commentCursor.moveToFirst();
      
          for(int i=0;i<commentCursor.getCount();i++)
          {
            Comment newComment = new Comment();
            newComment.id = "" + commentCursor.getInt(0);
            newComment.message = commentCursor.getString(1);
            newComment.rate = commentCursor.getString(2);
            comments.add(newComment);
            commentCursor.moveToNext();
          }
      
      String[] commentItems = new String[comments.size()];
      for(int i = 0; i< comments.size(); i++)
        commentItems[i] = comments.get(i).message;
    
      listComment.setAdapter(new ArrayAdapter<String>(this,
          R.layout.rowcomment, R.id.txtCommentMessage,
          commentItems));
    }
    catch (Exception e) 
    {
      e.printStackTrace();
    }
  }
  
  public void onClick(View v)
  {
    switch(v.getId())
    {
      case R.id.BtnAddComment:
        
        final View addComment=getLayoutInflater().inflate(R.layout.dialogcomment, null);
        new AlertDialog.Builder(this)
        .setTitle("??? ???")
        .setView(addComment)
        .setPositiveButton("?????",
        new DialogInterface.OnClickListener() 
        {
          public void onClick(DialogInterface dialog,  int whichButton) 
          {
            EditText message=(EditText)addComment.findViewById(R.id.txtMessage);
            RatingBar rb = (RatingBar)addComment.findViewById(R.id.ratingBar);
            CheckBox chkFavorite = (CheckBox)addComment.findViewById(R.id.checkBoxFavorite);
                  
            try 
            {
              InsertComment(message.getText().toString(), chkFavorite.isChecked(), rb.getRating());  
              
              LoadRating();
              
              LoadComment();
              
            } 
            catch (Exception e) 
            {
              e.printStackTrace();
            }
          }
        }
        )
        .setNegativeButton("???????", null)
        .show();
        
        break;
        
      case R.id.imageButtonMap:
        Uri uri=Uri.parse("geo:"+lat+","+lon);
        startActivity(new Intent(Intent.ACTION_VIEW, uri));
        break;
        
      case R.id.buttonOrder:
        Intent i = new Intent().setClass(this, FoodList.class);
        i.putExtra(FoodList.Branch_ID, branchID);
        startActivity(i);
        break;
    }
  }
  
  void InsertComment(String message, boolean favorite, float rate)
  {
    try 
    {
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      String username = prefs.getString("login", "");
      
      if(!message.equals("") || rate != 0)
      {
        String[] fields = {"BranchID","message","rate"};
        String[] values = {branchID, message, "" + rate};
        db.InsertRow("comment", fields, values);
        
        if(Utility.isNetworkAvailable(this))
        {
          HttpClient client=new DefaultHttpClient();
              HttpPut putMethod=new HttpPut(
                  "http://" + Server + "/RestaurantReservation/resources/comment/" +
                  (favorite ? "true" : "false") + "/" + rate +
                  "/" + branchID + "/" + username + "/" + message.replace(' ', '-'));
          client.execute(putMethod);
        }
        else
        {
          Utility.sendSMS("InsertComment/" + (favorite ? "true" : "false") + "/" + 
            rate + "/" + branchID + "/" + username + "/" + message, this);
        }
      }
      
      if(favorite)
      {
        try 
        {
          String[] select = {"count(ID)"};
          Cursor favoriteCursor = db.SelectTable("Vw_favorite", select, "BranchID=" +
          branchID + " AND Username='" + username + "'", "");
          favoriteCursor.moveToFirst();
          if(favoriteCursor.getInt(0) == 0)
          {
            String[] fields = {"UserID","BranchID"};
            String[] values = {Utility.getCurrentUserID(this),branchID};
            db.InsertRow("favorite", fields, values);
          }
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }
    }
    catch (Exception e) 
    {
      e.printStackTrace();
    }
  }
  
}




Java Source Code List

com.adp.ADPWsSample.java
com.adp.BalanceResult.java
com.adp.ChangePasswordResponse.java
com.adp.ChangePassword.java
com.adp.GetBalanceResponse.java
com.adp.GetBalance.java
com.adp.GetStatusResponse.java
com.adp.GetStatus.java
com.adp.IncomingMessage.java
com.adp.JaxRpcMessagingServiceServiceLocator.java
com.adp.JaxRpcMessagingServiceService.java
com.adp.JaxRpcMessagingService.java
com.adp.MessageObject.java
com.adp.MessagingServiceSoapBindingStub.java
com.adp.MultiAddressMessageObject.java
com.adp.OutgoingMessage.java
com.adp.ReceiveResponse.java
com.adp.ReceiveResult.java
com.adp.Receive.java
com.adp.ReportResponse.java
com.adp.ReportResult.java
com.adp.Report.java
com.adp.Result.java
com.adp.SendMultipleResponse.java
com.adp.SendMultiple.java
com.adp.SendResponse.java
com.adp.SendResult.java
com.adp.Send.java
com.adp.StatusReportResponse.java
com.adp.StatusReportResult.java
com.adp.StatusReportType0.java
com.adp.StatusReport.java
com.sba.util.DateFields.java
com.sba.util.PersianCalendar.java
com.wmc.Registration.BranchlistResource.java
com.wmc.Registration.CommentListBean.java
com.wmc.Registration.CommentResource.java
com.wmc.Registration.CommentlistResource.java
com.wmc.Registration.FoodListResource.java
com.wmc.Registration.LoginResource.java
com.wmc.Registration.OrderBean.java
com.wmc.Registration.OrderListBean.java
com.wmc.Registration.OrderResource.java
com.wmc.Registration.RegisterResource.java
com.wmc.Registration.ReserveListBean.java
com.wmc.Registration.Settings.java
com.wmc.ReservationClient.Account.java
com.wmc.ReservationClient.BranchList.java
com.wmc.ReservationClient.BranchPage.java
com.wmc.ReservationClient.Branch.java
com.wmc.ReservationClient.Comment.java
com.wmc.ReservationClient.DatabaseHelper.java
com.wmc.ReservationClient.Favorite.java
com.wmc.ReservationClient.FoodList.java
com.wmc.ReservationClient.FoodPage.java
com.wmc.ReservationClient.Food.java
com.wmc.ReservationClient.Login.java
com.wmc.ReservationClient.Main.java
com.wmc.ReservationClient.OrderList.java
com.wmc.ReservationClient.Order.java
com.wmc.ReservationClient.Search.java
com.wmc.ReservationClient.SmsMessageReceiver.java
com.wmc.ReservationClient.Table.java
com.wmc.ReservationClient.Update.java
com.wmc.ReservationClient.Utility.java
smsserver.CommentSMS.java
smsserver.LoginSMS.java
smsserver.OrderSMS.java
smsserver.Settings.java
smsserver.SmsServer.java