Android Open Source - blogwriter Main Activity






From Project

Back to project page blogwriter.

License

The source code is released under:

GNU General Public License

If you think the Android project blogwriter 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.example.blogerwriter;
/*w w w. j  a v  a2s.c om*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{

  private final String TAG="MainActivity";
//  private WebView webView;
  private Button btnAdd;
  private EditText edtContent;
  private TextView txContent;
  private final String url="";
  private final String isaidUrl="";
  String sdpath=Environment.getExternalStorageDirectory().getAbsolutePath();
  String fileName="blog_isaid";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
//    webView=(WebView) findViewById(R.id.webview);
    btnAdd=(Button) findViewById(R.id.button);
    edtContent=(EditText) findViewById(R.id.editText);
    txContent=(TextView) findViewById(R.id.textView);
    btnAdd.setOnClickListener(this);
    String contents=readIsaid();
    Log.v(TAG,"contents---"+contents);
    txContent.setText(contents);
    
  
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.button:
      String newStr=edtContent.getText().toString();
      Log.v(TAG, "newStr----"+newStr);
      Log.v(TAG,"data---"+getTimeStr(System.currentTimeMillis()));
      appendIsaid2Sdcard(newStr+"\n");
      appendIsaid2Sdcard(getTimeStr(System.currentTimeMillis())+"\n");
      break;

    default:
      break;
    }
    
  }

  private String readIsaid(){
    File isaidFile=new File(sdpath, fileName);
    StringBuilder sb=new StringBuilder();
//    FileInputStream fin=new FileInputStream(isaidFile);
    try {
      String str="";
      BufferedReader bReader=new BufferedReader(new FileReader(isaidFile));
      while((str=bReader.readLine())!=null){
        sb.append(str+"\n");
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return sb.toString();
    
  }
  private void appendIsaid2Sdcard(String data){
    File isaidFile=new File(sdpath, fileName);
    if(!isaidFile.exists()){
      try {
        isaidFile.createNewFile();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    FileWriter fwr;
    try {
      fwr = new FileWriter(isaidFile,true);
      fwr.write(data);
      fwr.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  private String getTimeStr(long time){
     Date d = new Date(time);
       //?????????????????????
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String s = sdf.format(d);
       return s;
  }
}




Java Source Code List

com.example.blogerwriter.DBHelper.java
com.example.blogerwriter.DataExporter.java
com.example.blogerwriter.ItemEditActivity.java
com.example.blogerwriter.MainActivity.java
com.example.blogerwriter.MemoActivity.java
com.example.blogerwriter.VersionTransfer.java