Blame view

app/src/main/java/com/sunvote/xpadapp/PDFContextShowActivity.java 3.84 KB
27983dbe   孙向锦   project init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  package com.sunvote.xpadapp;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.widget.Toast;
  
  import com.reader.bookreadpdf.bookreadslideview.PDFViewShowActivity;
  import com.sunvote.xpadapp.utils.MyStringUtil;
  import com.ycanfunc.func.LibHttpOperate;
  
  import java.io.File;
  
  /**
   *
   * Created by wutaian on 2017/9/19 0019.
   */
  
  public class PDFContextShowActivity extends Activity {
  
      String strUserName = "";
      String filetype = "0";  // 必须为0
      String filename = "";//
      String fileauthor = "";
      String filepagenum = "1";
      String fileid = "1"; // 必须存在
      String filepath = "";
      String coverpath = "";
      String filekey = "";
      String filecover = "";
      String lockpage= "0";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_pdf);
           //获取数据
          Bundle bundle=this.getIntent().getExtras();
          String filepathTemp= bundle.get("filepath").toString();
          if(!MyStringUtil.isEmpty(filepathTemp)){
              filepath = filepathTemp;
          }
          String filenameTemp= bundle.get("filename").toString();
          if(!MyStringUtil.isEmpty(filenameTemp)){
              filename = filenameTemp;
          }
          String filepagenumTemp= bundle.get("filepagenum").toString();
          if(!MyStringUtil.isEmpty(filepagenumTemp)){
              filepagenum = filepagenumTemp;
          }
          String lockpageTemp= bundle.get("lockpage").toString();
          if(!MyStringUtil.isEmpty(lockpageTemp)){
              lockpage = lockpageTemp;
          }
          openFile();
      }
  
      /**
       * 设置pdf信息
       * @param filepathTemp
       *          文件路径
       * @param filenameTemp
       *          文件名
       * @param filepagenumTemp
       *          页面页数
       * @param lockpageTemp
       *          是否锁屏(0不锁屏,1锁屏)
       */
      public void setInfo(String filepathTemp,String filenameTemp,String filepagenumTemp,String lockpageTemp){
          filepath=filepathTemp;
          filename=filenameTemp;
          filepagenum=filepagenumTemp;
          lockpage=lockpageTemp;
      }
  
  
      // 打开文件
      private void openFile() {
          File fpath = new File(filepath);
          if (!fpath.exists()) {
              Toast.makeText(this,
                      "文件不存在", Toast.LENGTH_LONG).show();
              return;
          }
          Intent intent = new Intent();
          if (filetype.equalsIgnoreCase("0")) {
              LibHttpOperate LibHttpOperate = new LibHttpOperate(this);
              PDFViewShowActivity.SetLibHttpOperate(LibHttpOperate);
              intent.setClass(this, PDFViewShowActivity.class);
          } else {
              Toast.makeText(this,
                      "文件类型错误", Toast.LENGTH_LONG).show();
              return;
          }
          // 文件id
          intent.putExtra("bookId", fileid);
          // 文件名
          intent.putExtra("bookName", filename);
          // 文件作者
          intent.putExtra("author", fileauthor);
          // 文件阅读初始化页面页数
          intent.putExtra("pageNum", filepagenum);
          // 文件路径
          intent.putExtra("path", filepath);
          intent.putExtra("key", filekey);
          // 用户名
          intent.putExtra("username", strUserName);
          // 封面路径
          intent.putExtra("coverpath", filecover);
          // 头像路径
          intent.putExtra("portraitpath", coverpath);
          // 是否锁屏(0不锁屏,1锁屏)
          intent.putExtra("lockpage",lockpage);
          // app授权key(优看提供,用户提供项目包名)
          intent.putExtra("appkey","3F28FD12C0EB74833639901D785F1E6F");
          // app授权secret(优看提供,用户提供项目包名)
          intent.putExtra("appsecret","D63C0B90F584B0BE1A100B0406F2C");
          startActivityForResult(intent, 4);
      }
  }