Example #1
0
 /**
  * Set the alignment mode of the specified TextView with the desired align mode from preferences.
  *
  * <p>See @array/audio_title_alignment_values
  *
  * @param alignMode Align mode as read from preferences
  * @param t Reference to the textview
  */
 public static void setAlignModeByPref(int alignMode, TextView t) {
   if (alignMode == 1) t.setEllipsize(TruncateAt.END);
   else if (alignMode == 2) t.setEllipsize(TruncateAt.START);
   else if (alignMode == 3) {
     t.setEllipsize(TruncateAt.MARQUEE);
     t.setMarqueeRepeatLimit(-1);
     t.setSelected(true);
   }
 }
Example #2
0
 /** Expand or collapse a TextView by removing or adding the 2 lines limitation */
 private void expand(TextView v, boolean expand) {
   if (expand) {
     v.setMaxLines(Integer.MAX_VALUE);
     v.setEllipsize(null);
   } else {
     v.setMaxLines(2);
     v.setEllipsize(android.text.TextUtils.TruncateAt.END);
   }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View return_view = null;

    return_view = _inflater.inflate(R.layout.album_view_item, null);

    ImageView cover = (ImageView) return_view.findViewById(R.id.album_view_item_cover);
    TextView name = (TextView) return_view.findViewById(R.id.album_view_name);

    try {
      if (_albums.get(position) != null) {
        if (_albums.get(position).isLocked() && !_albums.get(position).getPassword().equals("")) {
          cover.setImageResource(R.drawable.album_cover_locked);
        } else {
          cover.setImageResource(R.drawable.album_cover_default);
        }

        name.setText(_albums.get(position).getAlbumName());
        name.setEllipsize(TruncateAt.MARQUEE);
        name.setMarqueeRepeatLimit(-1);
        name.setSelected(true);
      }
    } catch (Exception e) {
    }

    return_view.startAnimation(AnimationUtils.loadAnimation(_activity, android.R.anim.fade_in));
    return return_view;
  }
  /**
   * onCreate之后调用,可以用来初始化view
   *
   * @param savedInstanceState the saved instance state
   */
  @Override
  public final void onCreateAfter(Bundle savedInstanceState) {
    parseIntent();

    enableJavascript();
    enableCaching();
    enableClient();
    enableAdjust();
    zoomedOut();
    // 网页标题
    mTextSwitcher.setFactory(
        () -> {
          TextView textView = new TextView(this);
          textView.setTextAppearance(this, R.style.WebTitle);
          textView.setSingleLine(true);
          textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
          textView.postDelayed(() -> textView.setSelected(true), 1738);
          return textView;
        });
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
    if (title != null) setTitle(title);

    if (mProgressBar != null)
      mProgressBar.setReachedBarColor(BaseApplication.color(R.color.colorPrimary));

    // 设置滑动监听
    mWebView.setOnScrollChangedCallback(
        (dx, dy, x, y) -> { // 滑动监听
        });

    onCreateAfterLater();
  }
Example #5
0
 /** apply ellipsize property in textView */
 public static void applyEllipsize(View view, DynamicProperty property) {
   if (view instanceof TextView) {
     ((TextView) view)
         .setEllipsize(
             TextUtils.TruncateAt.valueOf(property.getValueString().toUpperCase().trim()));
   }
 }
    public AttachButton(Context context) {
      super(context);

      imageView = new ImageView(context);
      imageView.setScaleType(ImageView.ScaleType.CENTER);
      addView(imageView, LayoutHelper.createFrame(64, 64, Gravity.CENTER_HORIZONTAL | Gravity.TOP));

      textView = new TextView(context);
      textView.setLines(1);
      textView.setSingleLine(true);
      textView.setGravity(Gravity.CENTER_HORIZONTAL);
      textView.setEllipsize(TextUtils.TruncateAt.END);
      textView.setTextColor(0xff757575);
      textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
      addView(
          textView,
          LayoutHelper.createFrame(
              LayoutHelper.MATCH_PARENT,
              LayoutHelper.WRAP_CONTENT,
              Gravity.LEFT | Gravity.TOP,
              0,
              64,
              0,
              0));
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
    mContext = this;
    mUrl = getIntent().getStringExtra(EXTRA_URL);
    mTitle = getIntent().getStringExtra(EXTRA_TITLE);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setAppCacheEnabled(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setSupportZoom(true);
    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new LoveClient());

    mWebView.loadUrl(mUrl);

    mTextSwitcher.setFactory(
        () -> {
          TextView textView = new TextView(this);
          textView.setTextAppearance(this, R.style.WebTitle);
          textView.setSingleLine(true);
          textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
          textView.postDelayed(() -> textView.setSelected(true), 1738);
          return textView;
        });
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
    if (mTitle != null) setTitle(mTitle);
  }
 private void addTab(@NonNull List<String> tabTexts, int i) {
   final TextView tab = new TextView(getContext());
   tab.setSingleLine();
   tab.setEllipsize(TextUtils.TruncateAt.END);
   tab.setGravity(Gravity.CENTER);
   tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
   tab.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
   tab.setTextColor(textUnselectedColor);
   tab.setCompoundDrawablesWithIntrinsicBounds(
       null, null, getResources().getDrawable(menuUnselectedIcon), null);
   tab.setText(tabTexts.get(i));
   tab.setPadding(dpTpPx(5), dpTpPx(12), dpTpPx(5), dpTpPx(12));
   // 添加点击事件
   tab.setOnClickListener(
       new OnClickListener() {
         @Override
         public void onClick(View v) {
           switchMenu(tab);
           if (mDropDownMenuListener != null) mDropDownMenuListener.onClickListener(v);
         }
       });
   tabMenuView.addView(tab);
   // 添加分割线
   if (i < tabTexts.size() - 1) {
     View view = new View(getContext());
     view.setLayoutParams(new LayoutParams(dpTpPx(0.5f), ViewGroup.LayoutParams.MATCH_PARENT));
     view.setBackgroundColor(dividerColor);
     tabMenuView.addView(view);
   }
 }
Example #9
0
 public void addItem(Item item) {
   int size = icon + padding + padding;
   ViewGroup.LayoutParams params =
       new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, size);
   TextView row = new TextView(getContext());
   row.setId(item.getId());
   row.setLayoutParams(params);
   row.setMaxLines(1);
   row.setEllipsize(TextUtils.TruncateAt.END);
   row.setGravity(Gravity.CENTER_VERTICAL);
   row.setText(item.getTitle());
   row.setTypeface(Typeface.DEFAULT_BOLD);
   row.setOnClickListener(this);
   row.setTextColor(BottomUtils.colorStateListText(getContext()));
   TypedValue typedValue = new TypedValue();
   getContext()
       .getTheme()
       .resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
   row.setBackgroundResource(typedValue.resourceId);
   if (item.getIcon() != null) {
     row.setCompoundDrawablesWithIntrinsicBounds(icon(item.getIcon()), null, null, null);
     row.setCompoundDrawablePadding(padding);
     row.setPadding(padding, padding, padding, padding);
   } else {
     row.setPadding(size, padding, padding, padding);
   }
   container.addView(row);
 }
    private View createViewFromResource(
        int position, View convertView, ViewGroup parent, int resource) {
      TextView textView;

      if (convertView == null) {
        textView = (TextView) mInflater.inflate(resource, parent, false);
        textView.setAllCaps(true);
        textView.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        textView.setTextAppearance(mContext, android.R.style.TextAppearance_Small);
        textView.setTextColor(mTextColor);
        textView.setEllipsize(TruncateAt.MIDDLE);
      } else {
        textView = (TextView) convertView;
      }

      EditType type = getItem(position);
      String text;
      if (type == CUSTOM_SELECTION) {
        text = mEntry.getAsString(mType.customColumn);
      } else {
        text = getContext().getString(type.labelRes);
      }
      textView.setText(text);
      return textView;
    }
Example #11
0
 public MessageViewHolder(View v) {
   super(v);
   title = (TextView) v.findViewById(R.id.title);
   title.setMaxLines(1);
   title.setEllipsize(TextUtils.TruncateAt.END);
   content = (SpoilerRobotoTextView) v.findViewById(R.id.content);
   time = (TextView) v.findViewById(R.id.time);
   commentOverflow = (CommentOverflow) v.findViewById(R.id.commentOverflow);
   user = (TextView) v.findViewById(R.id.user);
 }
Example #12
0
  public PagerTitleStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    addView(mPrevText = new TextView(context));
    addView(mCurrText = new TextView(context));
    addView(mNextText = new TextView(context));

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    final int textAppearance = a.getResourceId(0, 0);
    if (textAppearance != 0) {
      mPrevText.setTextAppearance(context, textAppearance);
      mCurrText.setTextAppearance(context, textAppearance);
      mNextText.setTextAppearance(context, textAppearance);
    }
    if (a.hasValue(1)) {
      final int textColor = a.getColor(1, 0);
      mPrevText.setTextColor(textColor);
      mCurrText.setTextColor(textColor);
      mNextText.setTextColor(textColor);
    }
    final int textSize = a.getDimensionPixelSize(2, 0);
    if (textSize != 0) {
      mPrevText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
      mCurrText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
      mNextText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    a.recycle();

    final int defaultColor = mPrevText.getTextColors().getDefaultColor();
    final int transparentColor = (SIDE_ALPHA << 24) | (defaultColor & 0xFFFFFF);
    mPrevText.setTextColor(transparentColor);
    mNextText.setTextColor(transparentColor);

    mPrevText.setEllipsize(TruncateAt.END);
    mCurrText.setEllipsize(TruncateAt.END);
    mNextText.setEllipsize(TruncateAt.END);
    mPrevText.setSingleLine();
    mCurrText.setSingleLine();
    mNextText.setSingleLine();

    final float density = context.getResources().getDisplayMetrics().density;
    mScaledTextSpacing = (int) (TEXT_SPACING * density);
  }
    public AlbumView(Context context) {
      super(context);

      imageView = new BackupImageView(context);
      addView(
          imageView,
          LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

      LinearLayout linearLayout = new LinearLayout(context);
      linearLayout.setOrientation(LinearLayout.HORIZONTAL);
      linearLayout.setBackgroundColor(0x7f000000);
      addView(
          linearLayout,
          LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));

      nameTextView = new TextView(context);
      nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
      nameTextView.setTextColor(0xffffffff);
      nameTextView.setSingleLine(true);
      nameTextView.setEllipsize(TextUtils.TruncateAt.END);
      nameTextView.setMaxLines(1);
      nameTextView.setGravity(Gravity.CENTER_VERTICAL);
      linearLayout.addView(
          nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 0));

      countTextView = new TextView(context);
      countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
      countTextView.setTextColor(0xffaaaaaa);
      countTextView.setSingleLine(true);
      countTextView.setEllipsize(TextUtils.TruncateAt.END);
      countTextView.setMaxLines(1);
      countTextView.setGravity(Gravity.CENTER_VERTICAL);
      linearLayout.addView(
          countTextView,
          LayoutHelper.createLinear(
              LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 4, 0));

      selector = new View(context);
      selector.setBackgroundResource(R.drawable.list_selector);
      addView(
          selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    }
Example #14
0
 private void initializeAllObjects(LinearLayout v, int position) {
   ImageView imgViewSignal = (ImageView) v.findViewById(R.id.imgViewSignalCatagory);
   TextView txtSignal = (TextView) v.findViewById(R.id.txtSignalCatagory);
   mImageLoader.DisplayImage(
       Constants.BASE_IMAGE_URL + mSignalList.get(position).image_thumbnail, imgViewSignal);
   imgViewSignal.setScaleType(ScaleType.FIT_XY);
   imgViewSignal.setPadding(0, 15, 0, 0);
   // imgViewSignal.setBackgroundResource(mSignalsResult.getCatagories().get(position).image_thumbnail);
   txtSignal.setEllipsize(TruncateAt.MARQUEE);
   txtSignal.setText(mSignalList.get(position).getText_heading());
 }
 private TextView makeCrumbView(String name) {
   TextView tv = new TextView(mContext);
   tv.setTextAppearance(mContext, android.R.style.TextAppearance_Medium);
   tv.setPadding(mCrumbPadding, 0, mCrumbPadding, 0);
   tv.setGravity(Gravity.CENTER_VERTICAL);
   tv.setText(name);
   tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
   tv.setSingleLine();
   tv.setEllipsize(TextUtils.TruncateAt.END);
   return tv;
 }
Example #16
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    TextView shopName = null;
    TextView themeContent = null;
    TextView receiveDate = null;

    if (convertView == null) {

      convertView = inflater.inflate(listViewItem, null);
      shopName = (TextView) convertView.findViewById(R.id.shop_name);
      shopName.setEllipsize(TruncateAt.END);
      themeContent = (TextView) convertView.findViewById(R.id.theme_content);
      receiveDate = (TextView) convertView.findViewById(R.id.receive_date);
      convertView.setTag(new DataWrapper(shopName, themeContent, receiveDate));
    } else {

      DataWrapper dataWrapper = (DataWrapper) convertView.getTag();
      shopName = dataWrapper.shopName;
      themeContent = dataWrapper.themeContent;
      receiveDate = dataWrapper.receiveData;
    }

    ShopMsgInfo shopMsgInfo = datas.get(position);

    if (TextFormater.isEmpty(shopMsgInfo.getReceiveDate())) {
      receiveDate.setText(
          com.samuel.downloader.utils.TimeUtils.getTime(System.currentTimeMillis()));
    } else {
      receiveDate.setText(
          com.samuel.downloader.utils.TimeUtils.getTime(
              Long.parseLong(shopMsgInfo.getReceiveDate())));
    }
    //		receiveDate.setText(shopMsgInfo.getReceiveDate());
    if (flag == SHOPLIST) {
      shopName.setText(shopMsgInfo.getShopName());
      String theme = shopMsgInfo.getMsgTheme();
      if (theme.length() > 26) {
        theme = theme.substring(0, 25) + "...";
      }
      themeContent.setText(theme);
    } else if (flag == INFOLIST) {
      shopName.setText(shopMsgInfo.getMsgTheme());
      String content = shopMsgInfo.getMsgContent();
      if (content.length() > 34) {
        content = content.substring(0, 34) + " ...";
      }
      themeContent.setText(content);
    }

    return convertView;
  }
  @Override
  public void onBindView(View view) {

    super.onBindView(view);

    TextView textSummary = (TextView) view.findViewById(android.R.id.summary);

    if (textSummary != null) {
      textSummary.setSingleLine();
      textSummary.setEllipsize(TextUtils.TruncateAt.MIDDLE);
    }

    Xlog.i(TAG, "summary is +" + this.getSummary());
  }
 /** Creates a view into which preview text can be placed. */
 private TextView createPreviewTextView() {
   final LayoutParams params =
       new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   // final Resources res = getContext().getResources();
   // final float textSize = res.getDimensionPixelSize(R.dimen.fastscroll_overlay_text_size);
   final TextView textView = new TextView(getContext());
   textView.setLayoutParams(params);
   textView.setTextColor(Color.WHITE);
   textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mToastTextSize);
   textView.setSingleLine(true);
   textView.setEllipsize(TruncateAt.MIDDLE);
   textView.setGravity(Gravity.CENTER);
   textView.setAlpha(0f);
   return textView;
 }
  public void clickTextView(final TextView textView, final int skillId) {
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEms(13);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setClickable(true);
    textView.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            skillPageFlag = true;
            sellerSkillId = skillId;
            new regTask().execute("SellerMarket profile");
          }
        });
  }
 private void init(Context context) {
   this.mContext = context;
   this.mTextView = new TextView(mContext);
   // some config
   setClickable(true);
   setFocusable(true);
   setGravity(Gravity.CENTER);
   mTextView.setTextSize(22);
   RelativeLayout.LayoutParams params =
       new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   params.addRule(RelativeLayout.CENTER_HORIZONTAL);
   mTextView.setSelected(true);
   mTextView.setSingleLine(true);
   mTextView.setEllipsize(TruncateAt.MARQUEE);
   mTextView.setTransformationMethod(SingleLineTransformationMethod.getInstance());
   mTextView.setLayoutParams(params);
   mTextView.setTextColor(getResources().getColor(R.color.white));
   mTextView.getPaint().setFakeBoldText(true);
   addView(mTextView);
 }
  protected TextView buildTextViewWithValue(String value, TextType type) {
    TextView label = new TextView(MBApplicationController.getInstance().getBaseContext());
    if (value == null) {
      // If the value is null we don't want it to be parsed as HTML since that will break the
      // application
      label.setText("");
    } else {
      label.setEllipsize(TruncateAt.END);

      if (type == TextType.html) {
        label.setText(Html.fromHtml(value));
      } else {
        label.setText(value);
      }
    }

    getStyleHandler().styleLabel(label, null);

    return label;
  }
Example #22
0
  public final void bind(Context context, final MultiDeleteListItemData ch) {
    setMultiDeleteHeader(ch);

    // Date
    mDateView.setText(ch.getDate());

    // From.
    mFromView.setText(formatMessage(ch));

    // Register for updates in changes of any of the contacts in this conversation.
    ContactList contacts = ch.getContacts();
    Contact.addListener(this);

    // Subject
    mSubjectView.setText(ch.getSubject());
    mSubjectView.setSingleLine(true);
    mSubjectView.setEllipsize(TextUtils.TruncateAt.END);
    updateAvatarView();
    mCheckbox.setChecked(ch.isSelected());
  }
 @Override
 public View getView(final int position, final View convertView, final ViewGroup parent) {
   final View view = super.getView(position, convertView, parent);
   final TextView text =
       (TextView) (view instanceof TextView ? view : view.findViewById(android.R.id.text1));
   final File file = getItem(position);
   if (file == null || text == null) return view;
   if (mCurrentPath != null && file.equals(mCurrentPath.getParentFile())) {
     text.setText("..");
   } else {
     text.setText(file.getName());
   }
   text.setSingleLine(true);
   text.setEllipsize(TruncateAt.MARQUEE);
   text.setPadding(mPadding, mPadding, position, mPadding);
   final Drawable icon =
       mResources.getDrawable(file.isDirectory() ? R.drawable.ic_folder : R.drawable.ic_file);
   icon.mutate();
   icon.setColorFilter(mActionIconColor, PorterDuff.Mode.MULTIPLY);
   text.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
   return view;
 }
Example #24
0
  public void notifyDataSetChange() {
    currentIndex = 0;
    if (type == 0) {
      setAutoStart(false);
      stopFlipping();
      clearAnimation();
      TitleAdItem item = vInfos.get(currentIndex);
      tView.setText(item.getMsg());
    } else if (type == 1) {
      tView.setText(vInfos.get(currentIndex).getMsg());
      Animation animation = getInAnimation();
      if (animation != null) {
        animation.setAnimationListener(
            new Animation.AnimationListener() {
              public void onAnimationStart(Animation animation) {
                if (currentIndex < (vInfos.size() - 1)) {
                  currentIndex++;
                } else {
                  currentIndex = 0;
                }
                tView.setText(vInfos.get(currentIndex).getMsg());
              }

              public void onAnimationRepeat(Animation animation) {}

              public void onAnimationEnd(Animation animation) {}
            });
      }
      this.startFlipping();
      setAutoStart(true);
    }
    tView.setSingleLine(true);
    tView.setFocusableInTouchMode(true);
    tView.setHorizontallyScrolling(true);
    tView.setEllipsize(TruncateAt.MARQUEE);
    tView.setMarqueeRepeatLimit(-1);
    tView.setFocusable(true);
    tView.requestFocus();
  }
  public void reset() {
    Log.d(TAG, "Resetting animation.");

    mCancelled = true;

    if (mAnimation1StartRunnable != null) {
      removeCallbacks(mAnimation1StartRunnable);
    }

    mTextField1.clearAnimation();

    prepareTextFields();

    mMoveText1TextOut.reset();
    mMoveText1TextIn.reset();

    mScrollView1.removeView(mTextField1);
    mScrollView1.addView(mTextField1);

    mTextField1.setEllipsize(TextUtils.TruncateAt.END);

    invalidate();
  }
  private void initView(Context context) {
    setOrientation(LinearLayout.VERTICAL);
    setLayoutParams(
        new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.LEFT));
    setPadding(5, 0, 0, 0);

    // Scroll View 1
    LayoutParams sv1lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    sv1lp.gravity = Gravity.CENTER_HORIZONTAL;
    mScrollView1 = new ScrollView(context);

    // Scroll View 1 - Text Field
    mTextField1 = new TextView(context);
    mTextField1.setSingleLine(true);
    mTextField1.setTextColor(Color.WHITE);
    mTextField1.setEllipsize(TextUtils.TruncateAt.END);
    mTextField1.setTypeface(null, Typeface.BOLD);
    mScrollView1.addView(
        mTextField1,
        new ScrollView.LayoutParams(TEXTVIEW_VIRTUAL_WIDTH, LayoutParams.WRAP_CONTENT));

    addView(mScrollView1, sv1lp);
  }
  @Override
  public View createView(Context context) {
    if (!receiverRegistered) {
      receiverRegistered = true;
      IntentFilter filter = new IntentFilter();
      filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
      filter.addAction(Intent.ACTION_MEDIA_CHECKING);
      filter.addAction(Intent.ACTION_MEDIA_EJECT);
      filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
      filter.addAction(Intent.ACTION_MEDIA_NOFS);
      filter.addAction(Intent.ACTION_MEDIA_REMOVED);
      filter.addAction(Intent.ACTION_MEDIA_SHARED);
      filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
      filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
      filter.addDataScheme("file");
      ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
    }

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            } else if (id == -2) {
              selectedFiles.clear();
              actionBar.hideActionMode();
              listView.invalidateViews();
            } else if (id == done) {
              if (delegate != null) {
                ArrayList<String> files = new ArrayList<>();
                files.addAll(selectedFiles.keySet());
                delegate.didSelectFiles(DocumentSelectActivity.this, files);
              }
            }
          }
        });
    selectedFiles.clear();
    actionModeViews.clear();

    final ActionBarMenu actionMode = actionBar.createActionMode();
    actionModeViews.add(
        actionMode.addItem(
            -2,
            R.drawable.ic_ab_back_grey,
            R.drawable.bar_selector_mode,
            null,
            AndroidUtilities.dp(54)));

    selectedMessagesCountTextView = new TextView(actionMode.getContext());
    selectedMessagesCountTextView.setTextSize(18);
    selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedMessagesCountTextView.setTextColor(0xff737373);
    selectedMessagesCountTextView.setSingleLine(true);
    selectedMessagesCountTextView.setLines(1);
    selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
    selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
    selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
    selectedMessagesCountTextView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });
    actionMode.addView(selectedMessagesCountTextView);
    LinearLayout.LayoutParams layoutParams =
        (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams();
    layoutParams.weight = 1;
    layoutParams.width = 0;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    selectedMessagesCountTextView.setLayoutParams(layoutParams);

    actionModeViews.add(
        actionMode.addItem(
            done,
            R.drawable.ic_ab_done_gray,
            R.drawable.bar_selector_mode,
            null,
            AndroidUtilities.dp(54)));

    fragmentView =
        getParentActivity()
            .getLayoutInflater()
            .inflate(R.layout.document_select_layout, null, false);
    listAdapter = new ListAdapter(context);
    emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
    emptyView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });
    listView = (ListView) fragmentView.findViewById(R.id.listView);
    listView.setEmptyView(emptyView);
    listView.setAdapter(listAdapter);

    listView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            scrolling = scrollState != SCROLL_STATE_IDLE;
          }

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
        });

    listView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
            if (actionBar.isActionModeShowed() || i < 0 || i >= items.size()) {
              return false;
            }
            ListItem item = items.get(i);
            File file = item.file;
            if (file != null && !file.isDirectory()) {
              if (!file.canRead()) {
                showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
                return false;
              }
              if (sizeLimit != 0) {
                if (file.length() > sizeLimit) {
                  showErrorBox(
                      LocaleController.formatString(
                          "FileUploadLimit",
                          R.string.FileUploadLimit,
                          AndroidUtilities.formatFileSize(sizeLimit)));
                  return false;
                }
              }
              if (file.length() == 0) {
                return false;
              }
              selectedFiles.put(file.toString(), item);
              selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
              if (Build.VERSION.SDK_INT >= 11) {
                AnimatorSetProxy animatorSet = new AnimatorSetProxy();
                ArrayList<Object> animators = new ArrayList<>();
                for (int a = 0; a < actionModeViews.size(); a++) {
                  View view2 = actionModeViews.get(a);
                  AndroidUtilities.clearDrawableAnimation(view2);
                  if (a < 1) {
                    animators.add(
                        ObjectAnimatorProxy.ofFloat(
                            view2, "translationX", -AndroidUtilities.dp(56), 0));
                  } else {
                    animators.add(ObjectAnimatorProxy.ofFloat(view2, "scaleY", 0.1f, 1.0f));
                  }
                }
                animatorSet.playTogether(animators);
                animatorSet.setDuration(250);
                animatorSet.start();
              }
              scrolling = false;
              if (view instanceof SharedDocumentCell) {
                ((SharedDocumentCell) view).setChecked(true, true);
              }
              actionBar.showActionMode();
            }
            return true;
          }
        });

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (i < 0 || i >= items.size()) {
              return;
            }
            ListItem item = items.get(i);
            File file = item.file;
            if (file == null) {
              if (item.icon == R.drawable.ic_storage_gallery) {
                if (delegate != null) {
                  delegate.startDocumentSelectActivity();
                }
                finishFragment(false);
              } else {
                HistoryEntry he = history.remove(history.size() - 1);
                actionBar.setTitle(he.title);
                if (he.dir != null) {
                  listFiles(he.dir);
                } else {
                  listRoots();
                }
                listView.setSelectionFromTop(he.scrollItem, he.scrollOffset);
              }
            } else if (file.isDirectory()) {
              HistoryEntry he = new HistoryEntry();
              he.scrollItem = listView.getFirstVisiblePosition();
              he.scrollOffset = listView.getChildAt(0).getTop();
              he.dir = currentDir;
              he.title = actionBar.getTitle();
              history.add(he);
              if (!listFiles(file)) {
                history.remove(he);
                return;
              }
              actionBar.setTitle(item.title);
              listView.setSelection(0);
            } else {
              if (!file.canRead()) {
                showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
                file = new File("/mnt/sdcard");
              }
              if (sizeLimit != 0) {
                if (file.length() > sizeLimit) {
                  showErrorBox(
                      LocaleController.formatString(
                          "FileUploadLimit",
                          R.string.FileUploadLimit,
                          AndroidUtilities.formatFileSize(sizeLimit)));
                  return;
                }
              }
              if (file.length() == 0) {
                return;
              }
              if (actionBar.isActionModeShowed()) {
                if (selectedFiles.containsKey(file.toString())) {
                  selectedFiles.remove(file.toString());
                } else {
                  selectedFiles.put(file.toString(), item);
                }
                if (selectedFiles.isEmpty()) {
                  actionBar.hideActionMode();
                } else {
                  selectedMessagesCountTextView.setText(String.format("%d", selectedFiles.size()));
                }
                scrolling = false;
                if (view instanceof SharedDocumentCell) {
                  ((SharedDocumentCell) view)
                      .setChecked(selectedFiles.containsKey(item.file.toString()), true);
                }
              } else {
                if (delegate != null) {
                  ArrayList<String> files = new ArrayList<>();
                  files.add(file.getAbsolutePath());
                  delegate.didSelectFiles(DocumentSelectActivity.this, files);
                }
              }
            }
          }
        });

    listRoots();

    return fragmentView;
  }
Example #28
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // how to adjust the height of toolbar
    // http://stackoverflow.com/questions/17439683/how-to-change-action-bar-size
    // zsmth_actionbar_size @ dimen ==> ThemeOverlay.ActionBar @ styles ==> theme @ app_bar_main.xml

    // init floating action button & circular action menu
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    initCircularActionMenu(fab);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(mToggle);
    mToggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mNavigationView.setCheckedItem(R.id.nav_guidance);

    // http://stackoverflow.com/questions/33161345/android-support-v23-1-0-update-breaks-navigationview-get-find-header
    View headerView = mNavigationView.getHeaderView(0);
    mAvatar = (WrapContentDraweeView) headerView.findViewById(R.id.nav_user_avatar);
    mAvatar.setOnClickListener(this);

    mUsername = (TextView) headerView.findViewById(R.id.nav_user_name);
    mUsername.setOnClickListener(this);

    // http://stackoverflow.com/questions/27097126/marquee-title-in-toolbar-actionbar-in-android-with-lollipop-sdk
    TextView titleTextView = null;
    try {
      Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
      f.setAccessible(true);
      titleTextView = (TextView) f.get(toolbar);
      titleTextView.setEllipsize(TextUtils.TruncateAt.START);
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    }

    // init all fragments
    initFragments();

    FragmentManager fm = getSupportFragmentManager();
    if (Settings.getInstance().isLaunchHotTopic()) {
      fm.beginTransaction().replace(R.id.content_frame, hotTopicFragment).commit();
    } else {
      fm.beginTransaction().replace(R.id.content_frame, favoriteBoardFragment).commit();
    }

    getSupportFragmentManager()
        .addOnBackStackChangedListener(
            new FragmentManager.OnBackStackChangedListener() {
              public void onBackStackChanged() {
                // Enable Up button only  if there are entries in the back stack
                boolean canback = getSupportFragmentManager().getBackStackEntryCount() > 0;
                if (canback) {
                  mToggle.setDrawerIndicatorEnabled(false);
                  getSupportActionBar().setDisplayShowHomeEnabled(true);
                  getSupportActionBar().setHomeButtonEnabled(true);
                  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                } else {
                  getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                  mToggle.setDrawerIndicatorEnabled(true);
                  mDrawer.addDrawerListener(mToggle);
                }
              }
            });

    // start service to maintain user status
    setupUserStatusReceiver();
    updateUserStatusNow();
    UpdateNavigationViewHeader();

    // schedule the periodical run
    MaintainUserStatusService.schedule(MainActivity.this, mReceiver);

    if (Settings.getInstance().isFirstRun()) {
      // show info dialog after 5 seconds for the first run
      final Handler handler = new Handler();
      handler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              showInfoDialog();
            }
          },
          2000);
    }
  }
Example #29
0
  protected void buildRow(
      final View view,
      Drawable icon,
      final String text,
      final String textPrefix,
      int textColor,
      boolean isWiki,
      boolean isText,
      boolean needLinks) {
    boolean light = app.getSettings().isLightContent();

    if (!isFirstRow()) {
      buildRowDivider(view, false);
    }

    final String txt;
    if (!Algorithms.isEmpty(textPrefix)) {
      txt = textPrefix + ": " + text;
    } else {
      txt = text;
    }

    LinearLayout ll = new LinearLayout(view.getContext());
    ll.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams llParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    ll.setLayoutParams(llParams);
    ll.setBackgroundResource(
        resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
    ll.setOnLongClickListener(
        new View.OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            copyToClipboard(txt, view.getContext());
            return true;
          }
        });

    // Icon
    LinearLayout llIcon = new LinearLayout(view.getContext());
    llIcon.setOrientation(LinearLayout.HORIZONTAL);
    llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), dpToPx(48f)));
    llIcon.setGravity(Gravity.CENTER_VERTICAL);
    ll.addView(llIcon);

    ImageView iconView = new ImageView(view.getContext());
    LinearLayout.LayoutParams llIconParams =
        new LinearLayout.LayoutParams(dpToPx(24f), dpToPx(24f));
    llIconParams.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(32f), dpToPx(12f));
    llIconParams.gravity = Gravity.CENTER_VERTICAL;
    iconView.setLayoutParams(llIconParams);
    iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iconView.setImageDrawable(icon);
    llIcon.addView(iconView);

    // Text
    LinearLayout llText = new LinearLayout(view.getContext());
    llText.setOrientation(LinearLayout.VERTICAL);
    ll.addView(llText);

    TextView textView = new TextView(view.getContext());
    LinearLayout.LayoutParams llTextParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextParams.setMargins(0, dpToPx(8f), 0, dpToPx(8f));
    textView.setLayoutParams(llTextParams);
    textView.setTextSize(16);
    textView.setTextColor(
        app.getResources()
            .getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));

    if (needLinks) {
      textView.setAutoLinkMask(Linkify.ALL);
      textView.setLinksClickable(true);
    }
    textView.setEllipsize(TextUtils.TruncateAt.END);
    if (isWiki) {
      textView.setMinLines(1);
      textView.setMaxLines(15);
    } else if (isText) {
      textView.setMinLines(1);
      textView.setMaxLines(10);
    }
    textView.setText(txt);
    if (textColor > 0) {
      textView.setTextColor(view.getResources().getColor(textColor));
    }

    LinearLayout.LayoutParams llTextViewParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
    llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
    llText.setLayoutParams(llTextViewParams);
    llText.addView(textView);

    ((LinearLayout) view).addView(ll);

    if (isWiki) {
      ll.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              POIMapLayer.showWikipediaDialog(view.getContext(), app, amenity);
            }
          });
    } else if (isText && text.length() > 200) {
      ll.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              POIMapLayer.showDescriptionDialog(view.getContext(), app, text, textPrefix);
            }
          });
    }

    rowBuilt();
  }
Example #30
0
  static void populateEntryView(
      final View view,
      final Entry entry,
      final EntryManager entryManager,
      final UIHelper uiHelper) {
    final Resources resources = entryManager.getContext().getResources();

    // swipe
    final SwipeRelativeLayout swipeContainer =
        (SwipeRelativeLayout) view.findViewById(R.id.swipe_container);

    final View outterContainer = view.findViewById(R.id.outter_container);
    outterContainer.setPadding(0, 0, 0, 0);

    swipeContainer.setSwipeListener(
        new SwipeRelativeLayout.ISwipeListener() {

          private final int selectionFeedbackColor = resources.getColor(R.color.selection_feedback);

          public boolean swipeTopToBottom(final View v) {
            return false;
          }

          public boolean swipeRightToLeft(final View v) {

            view.setBackgroundColor(selectionFeedbackColor);
            entryManager.increaseUnreadLevel(entry);
            return true;
          }

          public boolean swipeLeftToRight(final View v) {

            view.setBackgroundColor(selectionFeedbackColor);
            entryManager.increaseReadLevel(entry);
            return true;
          }

          public boolean swipeBottomToTop(final View v) {
            return false;
          }

          public boolean onLongClick(final View v, final MotionEvent e) {
            return view.performLongClick();
          }

          public boolean onClick(final View v, final MotionEvent e) {
            return view.performClick();
          }
        });

    swipeContainer.setSwipeEnabeld(entryManager.isSwipeOnArticleDetailViewEnabled());
    swipeContainer.setBackgroundResource(R.drawable.article_header_background_thin);

    final TextView entryTitleView = (TextView) view.findViewById(R.id.entry_title);
    final TextView feedTitleView = (TextView) view.findViewById(R.id.feed_title);

    if (feedTitleView == null || entryTitleView == null) {
      Log.e(TAG, "feedTitleView or entryTitleView were null.");
      return;
    }

    if (entry == null) {
      Log.d(TAG, "entry was null");
      return;
    }

    if (entry.getFeedTitle() == null) {
      Log.e(TAG, "entry.getFeedTitle() was null.");
      return;
    }

    feedTitleView.setText(entry.getFeedTitle());
    entryTitleView.setText(entry.getTitle());

    if (entryManager.shouldTitlesBeEllipsized()) {
      entryTitleView.setEllipsize(TruncateAt.MIDDLE);
      entryTitleView.setLines(2);
    }

    // final int backgroundColor = resources.getColor(entry.isRead() ?
    // R.color.article_read_background
    // : R.color.article_unread_background);
    // final int textColor = resources.getColor(entry.isRead() ?
    // R.color.article_read_text
    // : R.color.article_unread_text);

    final TextView readIndicator = (TextView) view.findViewById(R.id.read_status_indicator);
    final int readIndicatorBackground =
        entryManager.isLightColorSchemeSelected()
            ? R.drawable.read_indicator
            : R.drawable.read_indicator_dark;
    final int pinnedIndicatorBackground =
        entryManager.isLightColorSchemeSelected()
            ? R.drawable.pinned_indicator
            : R.drawable.pinned_indicator_dark;

    int bgReadIndicator = -1;

    switch (entry.getReadState()) {
      case READ:
        bgReadIndicator = R.drawable.read_indicator_invisible;
        break;
      case UNREAD:
        bgReadIndicator = readIndicatorBackground;
        break;
      default:
        bgReadIndicator = pinnedIndicatorBackground;
    }

    readIndicator.setBackgroundResource(bgReadIndicator);

    // view.setBackgroundColor(backgroundColor);
    View container = view.findViewById(R.id.outter_container);
    if (entryManager.isLightColorSchemeSelected())
      container.setBackgroundColor(resources.getColor(R.color.article_read_background));
    else
      container.setBackgroundDrawable(
          resources.getDrawable(R.drawable.article_header_background_dark));

    // entryTitleView.setTextColor(textColor);
    // feedTitleView.setTextColor(textColor);

    //
    feedTitleView.setCompoundDrawablePadding(3);
    feedTitleView.setCompoundDrawablesWithIntrinsicBounds(
        resources.getDrawable(
            uiHelper.getArticleDownloadIndicatorDrawable(
                entry.getDownloaded(), entry.getDownloadPref(), resources)),
        null,
        null,
        null);

    // star check box
    final CheckBox starCheckBox = (CheckBox) view.findViewById(R.id.star_checkbox);
    starCheckBox.setVisibility(View.VISIBLE);
    starCheckBox.setChecked(entry.isStarred());
    starCheckBox.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(final View v) {
            entryManager.updateStarredState(entry, starCheckBox.isChecked());
          }
        });
    starCheckBox.requestFocus();

    if (false) {
      // changed
      final TextView changedView = (TextView) view.findViewById(R.id.article_changed);

      final boolean stateChanged = entry.isReadStatePending() || entry.isStarredStatePending();
      changedView.setText(stateChanged ? "*" : "");
    }
  }