Android Open Source - firstcodeandroid Add Content






From Project

Back to project page firstcodeandroid.

License

The source code is released under:

MIT License

If you think the Android project firstcodeandroid 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.vjia.hellonote;
/*ww w .j  a va 2s.c o  m*/
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.VideoView;

public class AddContent extends Activity implements OnClickListener {

  private String val;
  private Button savebtn, deletebtn;
  private EditText ettext;
  private ImageView c_img;
  private VideoView v_video;
  private NotesDB notesDB;
  private SQLiteDatabase dbWriter;
  private File phoneFile, videoFile;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addcontent);
    val = getIntent().getStringExtra("flag");
    savebtn = (Button) findViewById(R.id.save);
    deletebtn = (Button) findViewById(R.id.delete);
    ettext = (EditText) findViewById(R.id.ettext);
    c_img = (ImageView) findViewById(R.id.c_img);
    v_video = (VideoView) findViewById(R.id.c_video);
    savebtn.setOnClickListener(this);
    deletebtn.setOnClickListener(this);
    notesDB = new NotesDB(this);
    dbWriter = notesDB.getWritableDatabase();
    initView();
  }

  public void initView() {
    if (val.equals("1")) { // ??
      c_img.setVisibility(View.GONE);
      v_video.setVisibility(View.GONE);
    }
    if (val.equals("2")) {
      c_img.setVisibility(View.VISIBLE);
      v_video.setVisibility(View.GONE);
      Intent iimg = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      phoneFile = new File(Environment.getExternalStorageDirectory()
          .getAbsoluteFile() + "/" + getTime() + ".jpg");
      iimg.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(phoneFile));
      startActivityForResult(iimg, 1);
    }
    if (val.equals("3")) {
      c_img.setVisibility(View.GONE);
      v_video.setVisibility(View.VISIBLE);
      Intent video = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
      videoFile = new File(Environment.getExternalStorageDirectory()
          .getAbsoluteFile() + "/" + getTime() + ".mp4");
      video.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
      startActivityForResult(video, 2);
    }
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.save:
      addDB();
      finish();
      break;

    case R.id.delete:
      finish();
      break;
    }
  }

  public void addDB() {
    ContentValues cv = new ContentValues();
    cv.put(NotesDB.CONTENT, ettext.getText().toString());
    cv.put(NotesDB.TIME, getTime());
    cv.put(NotesDB.PATH, phoneFile + "");
    cv.put(NotesDB.VIDEO, videoFile + "");
    dbWriter.insert(NotesDB.TABLE_NAME, null, cv);
  }

  private String getTime() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy?MM?dd??HH:mm:ss");
    Date curDate = new Date();
    String str = format.format(curDate);
    return str;
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
      Bitmap bitmap = BitmapFactory.decodeFile(phoneFile
          .getAbsolutePath());
      c_img.setImageBitmap(bitmap);
    }
    if (requestCode == 2) {
      v_video.setVideoURI(Uri.fromFile(videoFile));
      v_video.start();
    }
  }
}




Java Source Code List

com.example.activitylifecycletest.DialogActivity.java
com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.NormalActivity.java
com.example.activitytest.FirstActivity.java
com.example.listviewtest.FruitAdapter.java
com.example.listviewtest.Fruit.java
com.example.listviewtest.MainActivity.java
com.jikexueyuan.counttime.MainActivity.java
com.jikexueyuan.getmyphonenumber.GetNumber.java
com.jikexueyuan.getmyphonenumber.MainActivity.java
com.jikexueyuan.getmyphonenumber.MyAdapter.java
com.jikexueyuan.getmyphonenumber.PhoneInfo.java
com.vjia.bookcollector.MainActivity.java
com.vjia.coolweather.MainActivity.java
com.vjia.coolweather.activity.ChooseAreaActivity.java
com.vjia.coolweather.activity.WeatherActivity.java
com.vjia.coolweather.db.CoolWeatherDB.java
com.vjia.coolweather.db.CoolWeatherOpenHelper.java
com.vjia.coolweather.model.City.java
com.vjia.coolweather.model.County.java
com.vjia.coolweather.model.Province.java
com.vjia.coolweather.util.HttpCallbackListener.java
com.vjia.coolweather.util.HttpUtil.java
com.vjia.coolweather.util.Utility.java
com.vjia.helloandroid.FirstActivity.java
com.vjia.helloandroid.HelloAndroidActivity.java
com.vjia.hellonote.AddContent.java
com.vjia.hellonote.MainActivity.java
com.vjia.hellonote.MyAdapter.java
com.vjia.hellonote.NotesDB.java
com.vjia.hellonote.SelectAct.java
com.vjia.jokeking.GetJoke.java
com.vjia.jokeking.HttpCallbackListener.java
com.vjia.jokeking.HttpUtil.java
com.vjia.jokeking.Joke.java
com.vjia.jokeking.MainActivity.java
com.vjia.jokeking.MyAdapter.java
com.vjia.locationtest.MainActivity.java