Android Open Source - chat.android Resources Activity






From Project

Back to project page chat.android.

License

The source code is released under:

GNU General Public License

If you think the Android project chat.android 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 org.chat.android;
//w w w .  j  a va2  s .  co  m
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.chat.android.models.Resource;
import org.chat.android.models.ResourceAccessed;

import com.j256.ormlite.dao.Dao;

import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class ResourcesActivity extends BaseActivity {
  Context context = null;
  Bundle bundle;
  ArrayList<Resource> resources;
  ArrayList<String> resourceNames;
  
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getApplicationContext();
    setContentView(R.layout.activity_resources);
    
    ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    
    bundle = getIntent().getExtras();
    resources = new ArrayList<Resource>();
    resourceNames = new ArrayList<String>();

    // grab all the resources
    try {
      Dao<Resource, Integer> resDao = getHelper().getResourcesDao();
      List<Resource> resList = resDao.queryBuilder().query();
      Iterator<Resource> iter = resList.iterator();
      while (iter.hasNext()) {
        Resource res = iter.next();
        resources.add(res);
        resourceNames.add(res.getName());
      }
    } catch (SQLException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
  
//    setListAdapter(new ArrayAdapter<String>(this, R.layout.resource_listview_row, resourceNames));
//    ListView rList = getListView();
    
    ListView lv = (ListView) findViewById(R.id.resources_listview);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.resource_listview_row, resourceNames);
    lv.setAdapter(adapter);
    
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //String res = (String)parent.getItemAtPosition(position);
        Resource res = resources.get(position);
        markResourceAccessed(res);
        openResource(res.getURI());
      }
      });
  }
  
  public void openResource(String resURI) {
        // determining path to sdcard (readable by video player)
        File sdCard = Environment.getExternalStorageDirectory();
        // adding chat dir to path (copyAsset func ensures dir exists)
      File dir = new File (sdCard.getAbsolutePath() + "/chat");
      
      // create file that points at the resource in the sdcard dir (to retrieve URI)
      File resFile = new File(dir, resURI);
      
      Intent i = new Intent();
      i.setAction(Intent.ACTION_VIEW);
      i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
      i.setDataAndType(Uri.fromFile(resFile), "application/pdf");
      startActivity(i);
  }
  
  public void markResourceAccessed(Resource res) {
    int workerId = 0;
    int visitId = 0;
    Date date = new Date();
    if (bundle.getInt("workerId") != 0) {
      workerId = bundle.getInt("workerId");
    }
    if (bundle.getInt("visitId") != 0) {
      visitId = bundle.getInt("visitId");
    }
    
    ResourceAccessed ra = new ResourceAccessed(res.getId(), visitId, workerId, date);
      try {
        Dao<ResourceAccessed, Integer> raDao = getHelper().getResourceAccessedDao();
        raDao.create(ra);
      } catch (SQLException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }  
  }
  
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
          Intent homeI = new Intent(this, HomeActivity.class);
          Bundle homeB = new Bundle();
          homeB.putInt("visitId",bundle.getInt("visitId"));
          homeB.putBoolean("fromBack", true);
          homeI.putExtras(homeB);
          startActivity(homeI);
            return true;          
        default:
            return super.onOptionsItemSelected(item);
        }
    }
}




Java Source Code List

org.chat.android.BaseActivity.java
org.chat.android.CHADelivery.java
org.chat.android.CHAOverviewActivity.java
org.chat.android.CHASelectChildActivity.java
org.chat.android.CHASelectChildAdapter.java
org.chat.android.ChatUtil.java
org.chat.android.ClientsAdapter.java
org.chat.android.DatabaseHelper.java
org.chat.android.GPSTracker.java
org.chat.android.HealthDeliveryActivity.java
org.chat.android.HealthDetailsActivity.java
org.chat.android.HealthOverviewActivity.java
org.chat.android.HealthOverviewRecordActivity.java
org.chat.android.HomeActivity.java
org.chat.android.ImmunizationsReceivedActivity.java
org.chat.android.ImmunizationsSummaryActivity.java
org.chat.android.LoginActivity.java
org.chat.android.Mail.java
org.chat.android.ModelHelper.java
org.chat.android.MyApplication.java
org.chat.android.ResourcesActivity.java
org.chat.android.RestoreVisitActivity.java
org.chat.android.ServiceDeliveryActivity.java
org.chat.android.ServiceDeliveryAdapter.java
org.chat.android.ServiceDetailsActivity.java
org.chat.android.ServiceOtherActivity.java
org.chat.android.ServiceOverviewActivity.java
org.chat.android.ServicesAdapter.java
org.chat.android.SetupDB.java
org.chat.android.SetupVisitActivity.java
org.chat.android.SyncResourcesActivity.java
org.chat.android.Auth.AccountGeneral.java
org.chat.android.Auth.AuthenticatorService.java
org.chat.android.Auth.Authenticator.java
org.chat.android.Auth.ChatAuthServerAuthenticate.java
org.chat.android.Auth.MainActivity.java
org.chat.android.Auth.ServerAuthenticate.java
org.chat.android.Sync.StubProvider.java
org.chat.android.Sync.SyncAdapter.java
org.chat.android.Sync.SyncService.java
org.chat.android.Sync.provider.ChatContentProvider.java
org.chat.android.models.Attendance.java
org.chat.android.models.CHAAccessed.java
org.chat.android.models.Client.java
org.chat.android.models.HealthPage.java
org.chat.android.models.HealthSelectRecorded.java
org.chat.android.models.HealthSelect.java
org.chat.android.models.HealthTheme.java
org.chat.android.models.HealthTopicAccessed.java
org.chat.android.models.HealthTopic.java
org.chat.android.models.Household.java
org.chat.android.models.PageAssessment1.java
org.chat.android.models.PageSelect1.java
org.chat.android.models.PageText1.java
org.chat.android.models.PageVideo1.java
org.chat.android.models.ResourceAccessed.java
org.chat.android.models.Resource.java
org.chat.android.models.Role.java
org.chat.android.models.ServiceAccessed.java
org.chat.android.models.Service.java
org.chat.android.models.TopicVideo.java
org.chat.android.models.Util.java
org.chat.android.models.VaccineRecorded.java
org.chat.android.models.Vaccine.java
org.chat.android.models.VideoAccessed.java
org.chat.android.models.Video.java
org.chat.android.models.Visit.java
org.chat.android.models.Worker.java
org.chat.android.pages.Assessment1Fragment.java
org.chat.android.pages.BaseFragment.java
org.chat.android.pages.ReferralFragment.java
org.chat.android.pages.Select1Fragment.java
org.chat.android.pages.Text1Fragment.java
org.chat.android.pages.Video1Fragment.java