Exemple #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View boardView = convertView;

    if (convertView == null) {
      LayoutInflater vi =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      boardView = vi.inflate(resource, null);
    }

    Board item;
    //		try {
    item = getItem(position);
    //		} catch (IndexOutOfBoundsException e) {
    //			item = null;
    //		}

    if (item != null) {
      String boardName = item.name;
      boolean isFavorite = item.favorite;
      // ImageView test = (ImageView)boardView.findViewById(R.id.BoardListNew);
      // test.setVisibility(View.VISIBLE);

      ((ImageView) boardView.findViewById(R.id.BoardListNew))
          .setVisibility(item.newt ? View.VISIBLE : View.GONE);
      ((ImageView) boardView.findViewById(R.id.BoardListComment))
          .setVisibility(item.comment ? View.VISIBLE : View.GONE);
      ((CheckBox) boardView.findViewById(R.id.favorite)).setChecked(isFavorite);
      ((TextView) boardView.findViewById(R.id.BoardListTitle)).setText(boardName);
      ((CheckBox) boardView.findViewById(R.id.favorite)).setClickable(false);
    }

    return boardView;
  }
  /** It is used to create/recreate the list of rubrics It should be called in onResume method */
  private void generateRubricsList() {
    LayoutInflater layoutInflater =
        (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rubricView;
    HorizontalScrollView rubricScroll;

    rubricsViews = new HashMap<Integer, View>();

    for (Rubric rubric : articleFeed.getRubrics()) {
      rubricView = layoutInflater.inflate(R.layout.articles_row, null);
      rubricsViews.put(rubric.getId(), rubricView);

      rubricScroll = (HorizontalScrollView) rubricView.findViewById(R.id.rubric_scroll);

      rubricScroll.setTag(rubric);
      rubricScroll.setOnTouchListener(touchListener);

      for (RssArticle article : rubric.getArticles()) {
        insertArticleView(article);
      }

      rubricsList.addView(rubricView);

      updateRubricTitle(rubric);
    }
  }
  private void showUserHashDialog() {
    String userHash = NavigineApp.Settings.getString("user_hash", "");

    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.user_hash_dialog, null);
    _userEdit = (EditText) view.findViewById(R.id.user_hash_edit);
    _userEdit.setText(userHash);
    _userEdit.setTypeface(Typeface.MONOSPACE);
    // _userEdit.addTextChangedListener(new TextWatcher()
    //  {
    //    public void afterTextChanged(Editable s) { }
    //    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
    //    public void onTextChanged(CharSequence s, int start, int before, int count)
    //    {
    //      String text = _userEdit.getText().toString();
    //      int length  = _userEdit.getText().length();
    //
    //      if (text.endsWith("-"))
    //        return;
    //
    //      if (count <= before)
    //        return;
    //
    //      if (length == 4 || length == 9 || length == 14)
    //      {
    //        _userEdit.setText((text + "-"));
    //        _userEdit.setSelection(length + 1);
    //      }
    //    }
    //  });

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    alertBuilder.setView(view);
    alertBuilder.setTitle("Enter user ID");
    alertBuilder.setNegativeButton(
        getString(R.string.cancel_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {}
        });

    alertBuilder.setPositiveButton(
        getString(R.string.ok_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            String userHash = _userEdit.getText().toString();
            SharedPreferences.Editor editor = NavigineApp.Settings.edit();
            editor.putString("user_hash", userHash);
            editor.commit();
            NavigineApp.applySettings();
            refreshMapList();
          }
        });

    AlertDialog dialog = alertBuilder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
  }
    public View getView(int position, View convertView, ViewGroup parent) {
      final View view =
          (convertView != null)
              ? convertView
              : LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.bookmark_item, parent, false);
      final ImageView imageView = (ImageView) view.findViewById(R.id.bookmark_item_icon);
      final TextView textView = (TextView) view.findViewById(R.id.bookmark_item_text);
      final TextView bookTitleView = (TextView) view.findViewById(R.id.bookmark_item_booktitle);

      final Bookmark bookmark = getItem(position);
      if (bookmark == null) {
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.drawable.ic_list_plus);
        textView.setText(ZLResource.resource("bookmarksView").getResource("new").getValue());
        bookTitleView.setVisibility(View.GONE);
      } else {
        imageView.setVisibility(View.GONE);
        textView.setText(bookmark.getText());
        if (myCurrentBook) {
          bookTitleView.setVisibility(View.GONE);
        } else {
          bookTitleView.setVisibility(View.VISIBLE);
          bookTitleView.setText(bookmark.getBookTitle());
        }
      }
      return view;
    }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.estadistica_view, container, false);

    int idEstadistica = this.mPageNumber;

    // Titulo y descripcion de estadistica
    TextView tituloEstadistica = (TextView) rootView.findViewById(R.id.TxtTituloEstadistica);
    TextView descEstadistica = (TextView) rootView.findViewById(R.id.TxtDescEstadistica);

    tituloEstadistica.setText(RelacionEstadisticas.getRelacion().get(idEstadistica).getTitulo());
    descEstadistica.setText(RelacionEstadisticas.getRelacion().get(idEstadistica).getDescripcion());

    rootView.addView(
        new EstadisticaViewLayout(Utilidades.getAppContext())
            .getView(RelacionEstadisticas.getRelacion().get(idEstadistica)));
    // }
    // catch (Exception e)
    // {
    //	Toast.makeText(Utilidades.getAppContext(), "error: " + e.getLocalizedMessage(),
    // Toast.LENGTH_LONG).show();
    //	Log.e("ERROR", e.getLocalizedMessage());
    // }
    // Set the title view to show the page number.
    /*((TextView) rootView.findViewById(android.R.id.text1)).setText(
    getString(R.string.title_template_step, mPageNumber + 1));*/

    return rootView;
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   if (v == null) {
     LayoutInflater vi =
         (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     v = vi.inflate(R.layout.row, null);
   }
   Message m = items.get(position);
   // if (m != null) {
   m.createColorFromString(m.from);
   TextView tt = (TextView) v.findViewById(R.id.username);
   TextView bt = (TextView) v.findViewById(R.id.message);
   if (isMonospaced) {
     tt.setTypeface(Typeface.MONOSPACE);
     bt.setTypeface(Typeface.MONOSPACE);
   }
   tt.setText(m.getFrom());
   tt.setTextColor(m.color);
   bt.setText(m.getMessage());
   // }
   return v;
 }
  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    final SearchManager manager = (SearchManager) getSystemService(SEARCH_SERVICE);
    manager.setOnCancelListener(null);

    final TabHost host = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true);

    myBook = SerializerUtil.deserializeBook(getIntent().getStringExtra(FBReader.BOOK_KEY));
  }
  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Thread.setDefaultUncaughtExceptionHandler(
        new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));

    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    final TabHost host = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.bookmarks, host.getTabContentView(), true);

    AllBooksBookmarks = Bookmark.bookmarks();
    Collections.sort(AllBooksBookmarks, new Bookmark.ByTimeComparator());
    final FBReader fbreader = (FBReader) FBReader.Instance();

    if (fbreader.Model != null) {
      final long bookId = fbreader.Model.Book.getId();
      for (Bookmark bookmark : AllBooksBookmarks) {
        if (bookmark.getBookId() == bookId) {
          myThisBookBookmarks.add(bookmark);
        }
      }

      myThisBookView = createTab("thisBook", R.id.this_book);
      new BookmarksAdapter(myThisBookView, myThisBookBookmarks, true);
    } else {
      findViewById(R.id.this_book).setVisibility(View.GONE);
    }

    myAllBooksView = createTab("allBooks", R.id.all_books);
    new BookmarksAdapter(myAllBooksView, AllBooksBookmarks, false);

    findViewById(R.id.search_results).setVisibility(View.GONE);
  }
 private MonthAdapter() {
   inflater = LayoutInflater.from(getContext());
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.quran_page_layout, container, false);
    view.setBackgroundDrawable((mPageNumber % 2 == 0 ? mLeftGradient : mRightGradient));
    int lineImageId = R.drawable.dark_line;
    int leftBorderImageId = R.drawable.border_left;
    int rightBorderImageId = R.drawable.border_right;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

    Resources res = getResources();
    if (!prefs.getBoolean(Constants.PREF_USE_NEW_BACKGROUND, true)) {
      view.setBackgroundColor(res.getColor(R.color.page_background));
    }

    boolean nightMode = false;
    if (prefs.getBoolean(Constants.PREF_NIGHT_MODE, false)) {
      leftBorderImageId = R.drawable.night_left_border;
      rightBorderImageId = R.drawable.night_right_border;
      lineImageId = R.drawable.light_line;
      view.setBackgroundColor(Color.BLACK);
      nightMode = true;
    }

    ImageView leftBorder = (ImageView) view.findViewById(R.id.left_border);
    ImageView rightBorder = (ImageView) view.findViewById(R.id.right_border);
    if (mPageNumber % 2 == 0) {
      rightBorder.setVisibility(View.GONE);
      leftBorder.setBackgroundResource(leftBorderImageId);
    } else {
      rightBorder.setVisibility(View.VISIBLE);
      rightBorder.setBackgroundResource(rightBorderImageId);
      leftBorder.setBackgroundResource(lineImageId);
    }

    mImageView = (HighlightingImageView) view.findViewById(R.id.page_image);
    mImageView.setNightMode(nightMode);

    mScrollView = (ScrollView) view.findViewById(R.id.page_scroller);

    final GestureDetector gestureDetector = new GestureDetector(new PageGestureDetector());
    OnTouchListener gestureListener =
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
          }
        };
    mImageView.setOnTouchListener(gestureListener);
    mImageView.setClickable(true);
    mImageView.setLongClickable(true);

    mOverlayText = prefs.getBoolean(Constants.PREF_OVERLAY_PAGE_INFO, true);

    if (mCoordinateData != null) {
      mImageView.setCoordinateData(mCoordinateData);
    }

    if (mPageBoundsRect != null) {
      mImageView.setPageBounds(mPageBoundsRect);
      if (mOverlayText) {
        mImageView.setOverlayText(mPageNumber, true);
      }
    }

    return view;
  }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      View view = convertView;
      if (view == null) {
        LayoutInflater inflater =
            (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.content_list_item, null);
      }
      TextView titleTextView = (TextView) view.findViewById(R.id.list_item_title);
      TextView stateTextView = (TextView) view.findViewById(R.id.list_item_state);
      TextView downTextView = (TextView) view.findViewById(R.id.list_item_downbar);
      Button downloadButton = (Button) view.findViewById(R.id.list_item_download_button);
      Button uploadButton = (Button) view.findViewById(R.id.list_item_upload_button);

      LocationInfo info = mInfoList.get(position);
      String titleText = info.title;
      String stateText = "";

      if (titleText.length() > 30) titleText = titleText.substring(0, 28) + "...";

      synchronized (mLoaderMap) {
        if (mLoaderMap.containsKey(info.title)) {
          LoaderState loader = mLoaderMap.get(info.title);
          if (loader.state < 100) stateText = String.format(Locale.ENGLISH, "%d%%", loader.state);
          else if (loader.state == 100) stateText = String.format(Locale.ENGLISH, "Done!");
          else stateText = String.format(Locale.ENGLISH, "Failed!");
        }
      }

      if (info.localVersion < 0) titleText += " (?)";
      else {
        if (info.localModified)
          titleText += String.format(Locale.ENGLISH, " (v. %d+)", info.localVersion);
        else titleText += String.format(Locale.ENGLISH, " (v. %d)", info.localVersion);
      }

      String mapFile = NavigineApp.Settings.getString("map_file", "");
      if (mapFile.equals(info.archiveFile)) {
        titleTextView.setTypeface(null, Typeface.BOLD);
        view.setBackgroundColor(Color.parseColor("#590E0E"));
      } else {
        titleTextView.setTypeface(null, Typeface.NORMAL);
        view.setBackgroundColor(Color.BLACK);
      }

      titleTextView.setText(titleText);
      stateTextView.setText(stateText);

      if (info.localModified) {
        downloadButton.setVisibility(View.GONE);
        uploadButton.setVisibility(View.VISIBLE);
        downTextView.setText("Version is modified. Upload?");
      } else if (info.serverVersion > info.localVersion) {
        downloadButton.setVisibility(View.VISIBLE);
        uploadButton.setVisibility(View.GONE);
        String downText =
            String.format(Locale.ENGLISH, "Version available: %d", info.serverVersion);
        downTextView.setText(downText);
      } else {
        downloadButton.setVisibility(View.INVISIBLE);
        uploadButton.setVisibility(View.GONE);
        downTextView.setText("Version is up to date");
      }

      downloadButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startDownload(position);
            }
          });

      uploadButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              startUpload(position);
            }
          });

      return view;
    }
  /**
   * Add article thumbnail to the appropriate rubric
   *
   * @param article
   */
  private void insertArticleView(RssArticle article) {
    LayoutInflater layoutInflater;
    View articleView;
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    LinearLayout rubricLayout;

    Bitmap thumbnailBitmap;

    TextView articleTitle;
    ImageView thumbnailImageView;

    int rubricId = article.getRubricId();
    Rubric rubric = articleFeed.getRubric(rubricId);
    int articlePosition = rubric.getPosition(article);

    updateRubricTitle(rubric);

    if (articlePosition >= rubric.getViewCount()
        && articlePosition > rubric.getMaximumViewCount()) {
      return;
    }

    rubric.increaseViewCount(1);

    layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    articleView = layoutInflater.inflate(R.layout.article_thumbnail, null);

    thumbnailImageView = (ImageView) articleView.findViewById(R.id.article_image);
    articleTitle = (TextView) articleView.findViewById(R.id.article_title);
    articleTitle.setText(article.getTitle());

    thumbnailBitmap = ThumbnailCache.getInstance().getBitmap(article.getEnclosure());
    if (thumbnailBitmap != null) {
      thumbnailImageView.setImageBitmap(thumbnailBitmap);
    } else {
      ThumbnailCache.getInstance().load(thumbnailImageView, article.getEnclosure());
    }
    listArticlesViews.add(articleView);

    if (article.isRead()) {
      thumbnailImageView.setColorFilter(0x99ffffff, PorterDuff.Mode.MULTIPLY);
      articleTitle.setTextColor(0xffb7b7b7);
    }

    String fontSize = preferences.getString("font_list_size", "medium");
    float imageSize = 12;
    float density = getResources().getDisplayMetrics().density;
    if (fontSize.equalsIgnoreCase("small")) {
      articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_small) / density);
      imageSize = getResources().getDimension(R.dimen.image_size_small);
    } else if (fontSize.equalsIgnoreCase("medium")) {
      articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_medium) / density);
      imageSize = getResources().getDimension(R.dimen.image_size_medium);
    } else if (fontSize.equalsIgnoreCase("large")) {
      articleTitle.setTextSize(getResources().getDimension(R.dimen.tile_text_large) / density);
      imageSize = getResources().getDimension(R.dimen.image_size_large);
    }
    thumbnailImageView.setLayoutParams(
        new RelativeLayout.LayoutParams((int) imageSize, (int) imageSize));

    articleView.setOnClickListener(this);
    articleView.setTag(article);

    rubricLayout = (LinearLayout) rubricsViews.get(rubricId).findViewById(R.id.rubric_layout);

    rubricLayout.addView(articleView, articlePosition);
  }