Ejemplo n.º 1
0
  private void _showUri() {
    version = bible.getVersion();
    Log.d(TAG, "showuri: " + uri);
    if (uri == null) {
      Log.d(TAG, "show null uri, use default");
      uri =
          Provider.CONTENT_URI_CHAPTER
              .buildUpon()
              .appendEncodedPath(null)
              .fragment(version)
              .build();
    }
    Cursor cursor = null;
    try {
      cursor = getContentResolver().query(uri, null, null, null, null);
    } catch (SQLiteException e) {
      showContent("", getString(R.string.queryerror));
      return;
    } catch (Exception e) {
    }
    if (cursor != null) {
      cursor.moveToFirst();

      osis = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_OSIS));
      osis_next = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_NEXT));
      osis_prev = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_PREVIOUS));
      final String human = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_HUMAN));
      final String content =
          cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_CONTENT));
      cursor.close();

      showContent(human + " | " + version, content);
    } else {
      Log.d(TAG, "no such chapter, try first chapter");
      Uri nulluri =
          Provider.CONTENT_URI_CHAPTER
              .buildUpon()
              .appendEncodedPath(null)
              .fragment(version)
              .build();
      if (!nulluri.equals(uri)) {
        uri = nulluri;
        showUri();
      } else {
        showContent("", getString(R.string.queryerror));
      }
    }
  }
Ejemplo n.º 2
0
 private void _showData() {
   version = bible.getVersion();
   SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
   fontsize = sp.getInt("fontsize-" + version, 0);
   if (fontsize == 0) {
     fontsize = sp.getInt("fontsize", 16);
   }
   if (fontsize > 32) {
     fontsize = 32;
   }
   if (!osis.equals("")) {
     uri = Provider.CONTENT_URI_CHAPTER.buildUpon().appendEncodedPath(osis).build();
   }
   showView(R.id.search, true);
   if (items == null || items.size() == 0) {
     showView(R.id.items, false);
     showView(R.id.book, true);
     showView(R.id.chapter, true);
     showUri();
   } else {
     showView(R.id.items, true);
     showView(R.id.book, false);
     showView(R.id.chapter, false);
     if (this.index > -1 && this.index < items.size()) {
       showItem(this.index);
     } else {
       showItem(0);
     }
   }
 }
Ejemplo n.º 3
0
 private boolean openOsis(String newOsis, String verse, String end) {
   if (newOsis == null || newOsis.equals("")) {
     return false;
   }
   if (!osis.equals(newOsis)) {
     uri = Provider.CONTENT_URI_CHAPTER.buildUpon().appendEncodedPath(newOsis).build();
     if ("".equals(this.verse)) {
       this.verse = verse;
     }
     this.end = end;
     showUri();
   }
   return true;
 }
Ejemplo n.º 4
0
 public void onZoom(boolean zoomIn) {
   if (fontsize == 1 && !zoomIn) {
     return;
   }
   if (fontsize == 32 && zoomIn) {
     return;
   }
   fontsize += (zoomIn ? 1 : -1);
   Log.d(TAG, "update fontsize to " + fontsize);
   uri = Provider.CONTENT_URI_CHAPTER.buildUpon().appendEncodedPath(osis).build();
   showUri();
   setZoomButtonsController(webview);
   if (mZoomButtonsController != null) {
     mZoomButtonsController.setZoomOutEnabled(fontsize > 1);
     mZoomButtonsController.setZoomInEnabled(fontsize < 32);
   }
 }
Ejemplo n.º 5
0
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
   gridview.setVisibility(View.GONE);
   switch (gridviewid) {
     case R.id.book:
       int matt = getMatt();
       String newbook;
       if (matt > 0) {
         if (pos % 2 == 0) {
           newbook = bible.get(Bible.TYPE.OSIS, pos / 2);
         } else {
           newbook = bible.get(Bible.TYPE.OSIS, matt + pos / 2);
         }
       } else {
         newbook = bible.get(Bible.TYPE.OSIS, pos);
       }
       if (!newbook.equals("") && !newbook.equals(book)) {
         storeOsisVersion();
         chapter = PreferenceManager.getDefaultSharedPreferences(this).getString(newbook, "1");
         openOsis(newbook + "." + chapter);
       }
       break;
     case R.id.chapter:
       openOsis(String.format("%s.%d", book, pos + 1));
       break;
     case R.id.version:
       storeOsisVersion();
       if (pos >= bible.getCount(Bible.TYPE.VERSION)) {
         String link_market =
             "<a href=\"market://search?q="
                 + getString(R.string.bibledatalink)
                 + "&c=apps\">market://search?q="
                 + getString(R.string.bibledatahuman)
                 + "&c=apps</a>";
         String body =
             "<div id=\"pb-demo\">"
                 + getString(
                     R.string.moreversion,
                     new Object[] {
                       link_market,
                       link_github,
                       "<a href=\"mailto:[email protected]\">Liu DongMiao</a>"
                     })
                 + "</div>\n";
         showContent("", body);
         return;
       }
       version = bible.get(Bible.TYPE.VERSION, pos);
       Log.d(TAG, "version: " + version);
       bible.setVersion(version);
       fontsize =
           PreferenceManager.getDefaultSharedPreferences(this)
               .getInt("fontsize-" + version, fontsize);
       uri =
           Provider.CONTENT_URI_CHAPTER
               .buildUpon()
               .appendEncodedPath(osis)
               .fragment(version)
               .build();
       showUri();
       break;
     case R.id.items:
       if (items != null && pos < items.size()) {
         showItem(pos);
       } else {
         showView(R.id.book, true);
         showView(R.id.chapter, true);
         showView(R.id.items, false);
         items.clear();
         findViewById(R.id.book).performClick();
       }
       break;
   }
 }
Ejemplo n.º 6
0
  @Override
  @SuppressLint("SetJavaScriptEnabled")
  protected void onCreate(Bundle savedInstanceState) {
    // on MB612, the search and share icon is so dark ...
    if (Build.MODEL.equals("MB612")) {
      setTheme(android.R.style.Theme_Light_NoTitleBar);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chapter);
    findViewById(R.id.book).setOnClickListener(this);
    findViewById(R.id.chapter).setOnClickListener(this);
    findViewById(R.id.search).setOnClickListener(this);
    findViewById(R.id.version).setOnClickListener(this);
    findViewById(R.id.share).setOnClickListener(this);
    findViewById(R.id.items).setOnClickListener(this);

    adapter =
        new ArrayAdapter<String>(this, R.layout.grid) {
          private LayoutInflater inflater =
              (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView;
            ToggleButton grid = null;
            if (view == null) {
              view = inflater.inflate(R.layout.grid, null);
            }
            grid = (ToggleButton) view.findViewById(R.id.text1);
            grid.setTextOn(getItem(position));
            grid.setTextOff(getItem(position));
            grid.setChecked(getItem(position).equals(selected));
            grid.setVisibility(getItem(position).equals("") ? View.INVISIBLE : View.VISIBLE);
            return view;
          }
        };

    gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(adapter);
    gridview.setVisibility(View.GONE);
    gridview.setOnItemClickListener(this);

    setGestureDetector();
    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setSupportZoom(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webview.addJavascriptInterface(
        new Object() {
          @SuppressWarnings("unused")
          public void setVerse(String string) {
            synchronized (verseLock) {
              verse = string;
              Log.d(TAG, "verse from javascript: " + verse);
              verseLock.notifyAll();
            }
          }

          @SuppressWarnings({"unused", "deprecation"})
          public void setCopyText(String text) {
            if (!text.equals("")) {
              copytext =
                  bible
                          .getVersionFullname(version)
                          .replace("(" + getString(R.string.demo) + ")", "")
                      + " ";
              copytext +=
                  bible.get(Bible.TYPE.HUMAN, bible.getPosition(Bible.TYPE.OSIS, book))
                      + " "
                      + chapter
                      + ":"
                      + text;
              ((android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE))
                  .setText(copytext);
              Log.d(TAG, "copy from javascript: " + copytext);
            } else {
              copytext = "";
            }
            handler.sendEmptyMessage(COPYTEXT);
          }
        },
        "android");
    setZoomButtonsController(webview);

    osis = PreferenceManager.getDefaultSharedPreferences(this).getString("osis", "null");
    uri =
        Provider.CONTENT_URI_CHAPTER.buildUpon().appendEncodedPath(osis).fragment(version).build();

    setIntentData();
    int color = 0x6633B5E5;
    Integer mHighlightColor =
        (Integer) Bible.getField(findViewById(R.id.version), TextView.class, "mHighlightColor");
    if (mHighlightColor != null) {
      color = mHighlightColor.intValue();
    }
    background =
        String.format(
            "background: rgba(%d, %d, %d, %.2f);",
            (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, (color >>> 24) / 255.0);
    Log.d(TAG, "onCreate");
    hasIntentData = true;
    font =
        new File(
            new File(
                new File(
                    new File(
                        new File(Environment.getExternalStorageDirectory(), "Android"), "data"),
                    getPackageName()),
                "files"),
            "custom.ttf");
  }