Android Open Source - android-textlater Detail Activity






From Project

Back to project page android-textlater.

License

The source code is released under:

Apache License

If you think the Android project android-textlater 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) 2013 The Android Open Source Project
 */*w  w  w  .  j ava 2 s. co m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.michael.feng.textlater;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockListActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class DetailActivity extends SherlockListActivity {

  private ListView detailList;
  private MessageDAO messageDAO;
  private List<Message> messageList;
  private TextView detailTitle;
  private TextView toTitle;
  private ImageView backButton;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Remove title bar
    //requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_detail);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(R.layout.abs_layout_detail);
    
    // Init Contact Text View
    detailTitle = (TextView) findViewById(R.id.detailTitle);
    toTitle = (TextView) findViewById(R.id.toTitle);
    
    // Init Back Button
    backButton = (ImageView) findViewById(R.id.back);
    backButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View arg0) {
        finish();
      }
    });
    backButton.setOnTouchListener(new OnTouchListener() {
      @Override
      public boolean onTouch(View arg0, MotionEvent event) {
        switch(event.getAction()){
          case MotionEvent.ACTION_DOWN:
              // touch down code
            backButton.setBackgroundColor(Color.rgb(104, 156, 210));
              break;

          case MotionEvent.ACTION_MOVE:
              // touch move code
              break;

          case MotionEvent.ACTION_UP:
              // touch up code
            backButton.setBackgroundColor(Color.TRANSPARENT);
              break;
          }
        return false;
      }
    });
    
    // Init Message Detail ListView
    detailList = (ListView) findViewById(android.R.id.list);
    detailList.setClickable(false);
    listMessages();
    
    getListView().setTextFilterEnabled(true);
  }

  @Override
  protected void onResume() {
    listMessages();
    super.onResume();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.detailactivity_itemlist, menu);
    return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home || item.getItemId() == 0) {
      return false;
    }
    
    if("new".equals(item.getTitle())) {
      Intent intent = new Intent("com.michael.feng.textlater.NewActivity");
      startActivity(intent);
    } else if("edit".equals(item.getTitle())) {
      //TODO
    }
    Toast.makeText(this, "Theme changed to \"" + item.getTitle() + "\"", Toast.LENGTH_SHORT)
        .show();
    return true;
  }

  public void listMessages() {
    String contactStr = "";
    Intent intent = getIntent();
    contactStr = intent.getStringExtra("textContact");
    detailTitle.setText(contactStr);
    if(contactStr.indexOf(";") > 0) {
      detailTitle.setText("Outgoing");
      toTitle.setText("To: " + contactStr);
      toTitle.setVisibility(View.VISIBLE);
    }
    
    // Get all messages by TextContact from DB
    messageDAO = new MessageDAO(this);
    messageDAO.open();
    messageList = messageDAO.getMessagesByContact(contactStr);
    messageDAO.close();

    // Put data into list
    ArrayList<HashMap<String, String>> contentList = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map = null;
    for (Message message : messageList) {
      map = new HashMap<String, String>();
      map.put("ItemWhen", message.getTextWhen());
      String status = "";
      if ("1".equals(message.getHasSent())) {
        status = "Done";
      } else {
        status = "Pending";
      }
      map.put("ItemStatus", status);
      map.put("ItemText", message.getTextContent());
      contentList.add(map);
    }

    // Give data list to view adapter and Display
    SimpleAdapter mSchedule = new SimpleAdapter(this, contentList,
        R.layout.listitem_detail, new String[] { "ItemWhen",
            "ItemText", "ItemStatus" }, new int[] { R.id.ItemWhen,
            R.id.ItemText, R.id.ItemStatus });
    detailList.setAdapter(mSchedule);
    
    // Remove border line in listview
//    detailList.setDivider(null);
    detailList.setClickable(false);
  }

}




Java Source Code List

com.michael.feng.textlater.AlarmReceiver.java
com.michael.feng.textlater.ContactsActivity.java
com.michael.feng.textlater.DetailActivity.java
com.michael.feng.textlater.MainActivity.java
com.michael.feng.textlater.MessageDAO.java
com.michael.feng.textlater.Message.java
com.michael.feng.textlater.NewActivity.java
com.michael.feng.textlater.SQLiteHelper.java
com.michael.feng.textlater.SendActivity.java