Back to project page Now_Manager.
The source code is released under:
Apache License
If you think the Android project Now_Manager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.collinguarino.nowmanager; /*from w ww. j a v a 2s . co m*/ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.media.MediaPlayer; import android.net.Uri; import android.text.format.DateFormat; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.collinguarino.nowmanager.ui.Dialogs; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class TimeCardAdapter extends CursorAdapter { private Context mContext; private final LayoutInflater mInflater; public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMM dd"); public static final SimpleDateFormat TIME_FORMAT_MILITARY = new SimpleDateFormat("kk:mm"); public static final SimpleDateFormat TIME_FORMAT_STANDARD = new SimpleDateFormat("hh:mm a"); // voice recording MediaPlayer mediaPlayer; boolean audioPlaying = false; public TimeCardAdapter(Context context, Cursor c) { super(context, c); mInflater = LayoutInflater.from(context); mContext = context; } @Override public void bindView(View view, final Context context, final Cursor cursor) { final ViewHolder viewHolder = (ViewHolder) view.getTag(); final TimeCardObject timeCard = new TimeCardObject(cursor); if (timeCard.getEventNameInput().length() == 0 && timeCard.isImage()) { viewHolder.eventNameInput.setText("Picture"); } else { viewHolder.eventNameInput.setText(timeCard.getEventNameInput()); } viewHolder.eventNameInput.setLinksClickable(true); viewHolder.eventNameInput.setAutoLinkMask(Linkify.ALL); viewHolder.eventNameInput.setMovementMethod(EditTextMovement.getInstance()); Linkify.addLinks(viewHolder.eventNameInput, Linkify.ALL); // setting left side button icon if (timeCard.isImage()) viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_camera); else if (timeCard.isLocation()) viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_location); else if (timeCard.isVoice()) viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_voice_start); else viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_event); // Amending the event name viewHolder.activityLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (timeCard.isLocation()) { String uriString = "geo:0,0?q=" + timeCard.getAddress(); Uri uri = Uri.parse(uriString); Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri); mContext.startActivity(intent); } else if (timeCard.isImage()) { Dialogs.displayPictureFullPreview(context, timeCard); } else if (timeCard.isVoice()) { if (!audioPlaying) { mediaPlayer = MediaPlayer.create(context, Uri.parse(timeCard.getFilePath())); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mediaPlayer.stop(); mediaPlayer.release(); audioPlaying = false; viewHolder.eventNameInput.setText("Tap to play."); viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_voice_start); } }); mediaPlayer.start(); audioPlaying = true; viewHolder.eventNameInput.setText("Tap to stop."); viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_voice_stop); } else { mediaPlayer.stop(); mediaPlayer.release(); viewHolder.eventNameInput.setText("Tap to play."); audioPlaying = false; viewHolder.logTypeIdentifier.setImageResource(R.drawable.round_image_voice_start); } } else { // is event Dialogs.displayEventFullPreview(context, timeCard); } } }); // setting date and time final Calendar datetimeCalendar = Calendar.getInstance(); datetimeCalendar.setTimeInMillis(timeCard.getTimestamp()); final Date dateTime = datetimeCalendar.getTime(); String timeText = ""; if (!DateFormat.is24HourFormat(mContext)) { timeText = TimeCardAdapter.TIME_FORMAT_STANDARD.format(dateTime); } else if (DateFormat.is24HourFormat(mContext)) { timeText = TimeCardAdapter.TIME_FORMAT_MILITARY.format(dateTime); } viewHolder.dateTimeText.setText(TimeCardAdapter.DATE_FORMAT.format(dateTime) + " " + timeText); } @Override public View getView(int position, View convertView, ViewGroup parent) { final View view = super.getView(position, convertView, parent); return view; } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { final View view = mInflater.inflate(R.layout.fragment_time_card, parent, false); final ViewHolder viewHolder = new ViewHolder(); viewHolder.eventNameInput = (TextView) view.findViewById(R.id.eventNameInput); viewHolder.dateTimeText = (TextView) view.findViewById(R.id.dateTimeText); viewHolder.logTypeIdentifier = (ImageView) view.findViewById(R.id.logTypeIdentifier); viewHolder.activityLayout = (LinearLayout) view.findViewById(R.id.activityLayout); view.setTag(viewHolder); return view; } /** * Helper method to get a TimeCard object from this adapter at a position. * * @param position Position to get timecard from * @return A TimeCard object or null if the position is invalid. */ public TimeCardObject getTimeCard(final int position) { final Cursor cursor = getCursor(); TimeCardObject timeCard = null; if (cursor.moveToPosition(position)) { timeCard = new TimeCardObject(cursor); } return timeCard; } private class ViewHolder { TextView eventNameInput, dateTimeText; ImageView logTypeIdentifier; LinearLayout activityLayout; } }