Java Code Examples for android.widget.TextView.setTypeface()

The following are Jave code examples for showing how to use setTypeface() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: encdroidMC   File: FontTypePreference.java   View Source Code Vote up 6 votes
/****************************************************************
 * getView
 * 		the overroad getView method */
public View getView(int position, View convertView, ViewGroup parent) 
{
	// get the view that would normally be returned
	View v = super.getView(position, convertView, parent);
	final TextView tv = (TextView) v;
	
	final String option = tv.getText().toString();			
	if (option.equals("Serif"))
		tv.setTypeface(Typeface.SERIF);
	else if (option.equals("Sans Serif"))
		tv.setTypeface(Typeface.SANS_SERIF);
	else if (option.equals("Monospace"))
		tv.setTypeface(Typeface.MONOSPACE);

	// general options
	tv.setTextColor(Color.BLACK);
	tv.setPadding(10, 3, 3, 3);

	return v;	
}
 
Example 2
Project: Moment   File: MainActivity.java   View Source Code Vote up 6 votes
private void applyFontsToTitle(Toolbar toolbar) {
    int childCount = toolbar.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = toolbar.getChildAt(i);
        if (child instanceof TextView) {
            TextView tv = (TextView) child;
            tv.setTextSize(getResources().getDimensionPixelSize(R.dimen.font_text_size));
            Typeface titleFont = Typeface.
                    createFromAsset(getAssets(), "fonts/AlexBrush-Regular.ttf");
            if (tv.getText().equals(toolbar.getTitle())) {
                tv.setTypeface(titleFont);
                break;
            }
        }
    }
}
 
Example 3
Project: fefereader   File: PostListItem.java   View Source Code Vote up 6 votes
/**
 * Fill list item with data from Post object.
 *
 * @param post Object to load data from.
 */
public void fill(Post post) {
    checkNotNull(post);

    // Set text values
    TextView preview = ButterKnife.findById(this, R.id.contents_preview);
    String previewText = Html.fromHtml(post.getContents()).toString();
    preview.setText(previewText);
    preview.setTypeface((post.isRead() && !post.isUpdated()) ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);

    View bookmarkView = ButterKnife.findById(this, R.id.bookmark_image);
    bookmarkView.setVisibility(post.isBookmarked() ? VISIBLE : GONE);

    View updatedView = ButterKnife.findById(this, R.id.updated_image);
    updatedView.setVisibility(post.isUpdated() ? VISIBLE : GONE);

    // Attach dispenser to view
    setTag(post);
}
 
Example 4
Project: GitHub   File: ViewHolder.java   View Source Code Vote up 5 votes
public ViewHolder setTypeface(Typeface typeface, int... viewIds)
{
    for (int viewId : viewIds)
    {
        TextView view = getView(viewId);
        view.setTypeface(typeface);
        view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    }
    return this;
}
 
Example 5
Project: airgram   File: PhotoPickerAlbumsCell.java   View Source Code Vote up 5 votes
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.setTypeface(FontManager.instance().getTypeface());
    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.setTypeface(FontManager.instance().getTypeface());
    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 6
Project: ifcalc   File: PoliticaPrivacidadeActivity.java   View Source Code Vote up 5 votes
private void setUpViews() {
    TextView textView1  = (TextView) findViewById(R.id.textView1);
    TextView textView2  = (TextView) findViewById(R.id.textView2);
    TextView textView3  = (TextView) findViewById(R.id.textView3);
    TextView textView4  = (TextView) findViewById(R.id.textView4);

    textView1.setTypeface(pfBeausans);
    textView2.setTypeface(pfBeausans);
    textView3.setTypeface(pfBeausans);
    textView4.setTypeface(pfBeausans);
}
 
Example 7
Project: aarLibrary   File: Toasty.java   View Source Code Vote up 5 votes
@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
                           @ColorInt int tintColor, int duration,
                           boolean withIcon, boolean shouldTint) {
    final Toast currentToast = new Toast(context);
    final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.toast_layout, null);
    final ImageView toastIcon = (ImageView) toastLayout.findViewById(R.id.toast_icon);
    final TextView toastTextView = (TextView) toastLayout.findViewById(R.id.toast_text);
    Drawable drawableFrame;

    if (shouldTint)
        drawableFrame = ToastyUtils.tint9PatchDrawableFrame(context, tintColor);
    else
        drawableFrame = ToastyUtils.getDrawable(context, R.drawable.toast_frame);
    ToastyUtils.setBackground(toastLayout, drawableFrame);

    if (withIcon) {
        if (icon == null)
            throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
        if (tintIcon)
            icon = ToastyUtils.tintIcon(icon, DEFAULT_TEXT_COLOR);
        ToastyUtils.setBackground(toastIcon, icon);
    } else {
        toastIcon.setVisibility(View.GONE);
    }

    toastTextView.setTextColor(DEFAULT_TEXT_COLOR);
    toastTextView.setText(message);
    toastTextView.setTypeface(currentTypeface);
    toastTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);

    currentToast.setView(toastLayout);
    currentToast.setDuration(duration);
    return currentToast;
}
 
Example 8
Project: wallpaperboard   File: Popup.java   View Source Code Vote up 5 votes
private int getMeasuredWidth(@NonNull Context context) {
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int maxWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_max_width);
    int minWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_min_width);
    String longestText = "";
    for (PopupItem item : mAdapter.getItems()) {
        if (item.getTitle().length() > longestText.length())
            longestText = item.getTitle();
    }

    int padding = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
    int iconSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size_small);
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setTypeface(TypefaceHelper.getRegular(context));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
            .getDimension(R.dimen.text_content_subtitle));
    textView.setPadding(padding + iconSize + padding, 0, padding, 0);
    textView.setText(longestText);

    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);

    int measuredWidth = textView.getMeasuredWidth() + padding;
    if (measuredWidth <= minWidth) {
        return minWidth;
    }

    if (measuredWidth >= minWidth && measuredWidth <= maxWidth) {
        return measuredWidth;
    }
    return maxWidth;
}
 
Example 9
Project: buildAPKsApps   File: BloodType.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.bloodtype);
	
	prefs = this.getSharedPreferences("BloodType", Context.MODE_PRIVATE);
	
	strAndroidInfo = prefs.getString("BloodVal", "");
	inPrefConv = Integer.parseInt(strAndroidInfo);
	
	tvG = (TextView) findViewById(R.id.tvGiveTo);
	tvR = (TextView) findViewById(R.id.tvReceiveFrom);
	
	tvB = (TextView) findViewById(R.id.tvBloodDetail);
	tvB.setText(strBloodType[inPrefConv]);
	
	tvD = (TextView) findViewById(R.id.tvData);
	tvD.setTypeface(Typeface.createFromAsset(BloodType.this.getAssets(), "fonts/gbold.otf"));
	
	tvA = (TextView) findViewById(R.id.tvGive);
	tvC = (TextView) findViewById(R.id.tvReceive);
	
	animAnticipateOvershoot = AnimationUtils.loadAnimation(this, R.anim.overshoot);
	tvB.startAnimation(animAnticipateOvershoot);
	animAnticipateOvershootX = AnimationUtils.loadAnimation(this, R.anim.overshootx);
	tvC.startAnimation(animAnticipateOvershootX);
	tvA.startAnimation(animAnticipateOvershootX);
	
	//Handler handler = new Handler();
       //handler.postDelayed(task, 1000);
	
	PerformBloodCheck(inPrefConv);
	
	getActionBar().setDisplayHomeAsUpEnabled(true);
}
 
Example 10
Project: DigitSpeedView   File: DigitSpeedView.java   View Source Code Vote up 5 votes
private void init(Context context) {
    speedTextColor = ContextCompat.getColor(context, R.color.green);
    unitTextColor = ContextCompat.getColor(context, R.color.green);
    final View rootView = LayoutInflater.from(context).inflate(R.layout.digit_speed_view, this, true);
    mainLayout = (RelativeLayout) rootView.findViewById(R.id.digit_speed_main);
    mSpeedTextView = (TextView) rootView.findViewById(R.id.digit_speed);
    mSpeedBgTextView = (TextView) rootView.findViewById(R.id.digit_speed_bg);
    mSpeedUnitTextView = (TextView) rootView.findViewById(R.id.digit_speed_unit);
    Typeface tf = Typeface.createFromAsset(getResources().getAssets(), "fonts/digital-7_mono.ttf");
    mSpeedTextView.setTypeface(tf);
    mSpeedBgTextView.setTypeface(tf);
    mSpeedUnitTextView.setTypeface(tf);
}
 
Example 11
Project: Rey-MusicPlayer   File: PlaylistAdapter.java   View Source Code Vote up 5 votes
public ItemHolder(View itemView) {
    super(itemView);
    mPlaylistName = (TextView) itemView.findViewById(R.id.gridViewTitleText);
    mPlaylistName.setTypeface(TypefaceHelper.getTypeface(itemView.getContext().getApplicationContext(), TypefaceHelper.FUTURA_BOOK));

    mOverFlow = (ImageView) itemView.findViewById(R.id.overflow);
    mOverFlow.setOnClickListener(this);
    itemView.setOnClickListener(this);
}
 
Example 12
Project: QuranAndroid   File: PartShowAdapter.java   View Source Code Vote up 5 votes
ViewHolder(View layout) {
    super(layout);

    eelativeLayout=(RelativeLayout)layout.findViewById(R.id.eelativeLayout);
    soraName = (TextView) layout.findViewById(R.id.textView5);
    ayaCount = (TextView) layout.findViewById(R.id.textView6);
    pageNumbers = (TextView) layout.findViewById(R.id.textView7);
    number = (TextView) layout.findViewById(R.id.textView4);
    soraName.setTypeface(customFont);
    ayaCount.setTypeface(customFont);
    pageNumbers.setTypeface(customFont);

}
 
Example 13
Project: MuslimMateAndroid   File: AzkarAdapter.java   View Source Code Vote up 5 votes
public ViewHolder(View itemView) {
    super(itemView);
    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/simple.otf");
    title = (TextView) itemView.findViewById(R.id.textView14);
    title.setTypeface(tf);
    ID = (TextView) itemView.findViewById(R.id.hidden);
    counter = (TextView) itemView.findViewById(R.id.textView16);
}
 
Example 14
Project: Rey-MusicPlayer   File: MusicUtils.java   View Source Code Vote up 5 votes
public static void applyFontForToolbarTitle(Activity context) {
    Toolbar toolbar = context.findViewById(R.id.toolbar);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View view = toolbar.getChildAt(i);
        if (view instanceof TextView) {
            TextView tv = (TextView) view;

            if (tv.getText().equals(toolbar.getTitle())) {
                tv.setTypeface(TypefaceHelper.getTypeface(context, TypefaceHelper.FUTURA_BOLD));
                break;
            }
        }
    }
}
 
Example 15
Project: PagerSlidingTabStrip   File: PagerSlidingTabStrip.java   View Source Code Vote up 5 votes
private void updateTabStyles() {

        for (int i = 0; i < tabCount; i++) {
            View v = tabsContainer.getChildAt(i);
            if (selectedPosition == i) {
                v.setBackgroundResource(0);
            } else {
                v.setBackgroundResource(tabBackgroundResId);
            }

            if (v.findViewById(R.id.tv_content) instanceof TextView) {

                TextView tab = (TextView) v.findViewById(R.id.tv_content);
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                tab.setTextColor(tabTextColor);
//                Drawable rightDrawable = getResources().getDrawable(R.drawable.bg_msg);
//                int tvWidth = (int) tab.getPaint().measureText(tab.getText().toString() + "");
//                Log.d("tvlog", "rightDrawable.getMinimumWidth()=" + rightDrawable.getMinimumWidth() + ",rightDrawable.getMinimumHeight()=" + rightDrawable.getMinimumHeight());
//                Log.d("tvlog", "tab.getMeasuredWidth()="+tab.getMeasuredWidth()+",tvWidth="+tvWidth);
//
//                rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
//                tab.setCompoundDrawables(null, null, rightDrawable, null);

                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
//                if (textAllCaps) {
//                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
//                        tab.setAllCaps(true);
//                    } else {
//                        tab.setText(tab.getText().toString().toUpperCase(locale));
//                    }
//                }
                if (i == selectedPosition) {
                    tab.setTextColor(selectedTabTextColor);
                }
            }
        }

    }
 
Example 16
Project: healthgo   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) toolbar.getLayoutParams();
//        params.setMargins(0,getStatusBarHeight(), 0, 0);
//        toolbar.setLayoutParams(params);
        setSupportActionBar(toolbar);
        btn = (TextView) findViewById(R.id.bt);
        Typeface Font = Typeface.createFromAsset(this.getAssets(), "iconfont.ttf");
        btn.setText(getResources().getText(R.string.setting));
        btn.setTypeface(Font);

        Log.d("eee", "on create()");
        showSteps = (TextView) findViewById(R.id.showSteps);
        mLayout = findViewById(R.id.mylayout);
        on_off = (Switch) findViewById(R.id.on_off);
        foreground_model = (Switch) findViewById(R.id.foreground_model);


        sharedPreferences = getSharedPreferences("conf", MODE_PRIVATE);

        detectService();

        bus = EventBus.getDefault();
        bus.register(this);

        Realm realm = Realm.getDefaultInstance();
        StepModel result = realm.where(StepModel.class)
                .equalTo("date", DateTimeHelper.getToday())
                .findFirst();
        numSteps = result == null ? 0 : result.getNumSteps();
        bus.post(true);
        updateShowSteps();
        realm.close();

        drawChart();


    }
 
Example 17
Project: Quiz-Game   File: MainGameActivity.java   View Source Code Vote up 4 votes
public void correctDialog() {
    final Dialog dialogCorrect = new Dialog(MainGameActivity.this);
    dialogCorrect.requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (dialogCorrect.getWindow() != null) {
        ColorDrawable colorDrawable = new ColorDrawable(Color.TRANSPARENT);
        dialogCorrect.getWindow().setBackgroundDrawable(colorDrawable);
    }
    dialogCorrect.setContentView(R.layout.dialog_correct);
    dialogCorrect.setCancelable(false);
    dialogCorrect.show();

    //Since the dialog is show to user just pause the timer in background
    onPause();


    TextView correctText = (TextView) dialogCorrect.findViewById(R.id.correctText);
    FButton buttonNext = (FButton) dialogCorrect.findViewById(R.id.dialogNext);

    //Setting type faces
    correctText.setTypeface(sb);
    buttonNext.setTypeface(sb);

    //OnCLick listener to go next que
    buttonNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //This will dismiss the dialog
            dialogCorrect.dismiss();
            //it will increment the question number
            qid++;
            //get the que and 4 option and store in the currentQuestion
            currentQuestion = list.get(qid);
            //Now this method will set the new que and 4 options
            updateQueAndOptions();
            //reset the color of buttons back to white
            resetColor();
            //Enable button - remember we had disable them when user ans was correct in there particular button methods
            enableButton();
        }
    });
}
 
Example 18
Project: ifcalc   File: CalculatorAnualFragment.java   View Source Code Vote up 4 votes
private void setUpViews(View view) {
    txtBimestre1 = (TextView) view.findViewById(R.id.textbimestre1);
    txtBimestre2 = (TextView) view.findViewById(R.id.textbimestre2);
    txtBimestre3 = (TextView) view.findViewById(R.id.textbimestre3);
    txtBimestre4 = (TextView) view.findViewById(R.id.textbimestre4);
    txtProvaFinal = (TextView) view.findViewById(R.id.textprovaf);
    btCalcular = (Button) view.findViewById(R.id.btcalcular);
    edtBimestre1 = (EditText) view.findViewById(R.id.bimestre1);
    edtBimestre2 = (EditText) view.findViewById(R.id.bimestre2);
    edtBimestre3 = (EditText) view.findViewById(R.id.bimestre3);
    edtBimestre4 = (EditText) view.findViewById(R.id.bimestre4);
    edtProvaFinal = (EditText) view.findViewById(R.id.provafinal);
    situacaoStatus  = (TextView) view.findViewById(R.id.situaresult);
    txtMensagem  = (TextView) view.findViewById(R.id.textprecisa);
    txtResultado  = (TextView) view.findViewById(R.id.resultadotext);
    txtMedia  = (TextView) view.findViewById(R.id.media);
    txtNota  = (TextView) view.findViewById(R.id.textNota);

    resultShow = (LinearLayout) view.findViewById(R.id.resultShow);

    //set font in views
    txtBimestre1.setTypeface(pfBeausans);
    txtBimestre2.setTypeface(pfBeausans);
    txtBimestre3.setTypeface(pfBeausans);
    txtBimestre4.setTypeface(pfBeausans);
    txtProvaFinal.setTypeface(pfBeausans);
    btCalcular.setTypeface(pfBeausans);
    edtBimestre1.setTypeface(pfBeausans);
    edtBimestre2.setTypeface(pfBeausans);
    edtBimestre3.setTypeface(pfBeausans);
    edtBimestre4.setTypeface(pfBeausans);
    edtProvaFinal.setTypeface(pfBeausans);

    situacaoStatus.setTypeface(pfBeausans);
    txtMensagem.setTypeface(pfBeausans);
    txtResultado.setTypeface(pfBeausans);
    txtMedia.setTypeface(pfBeausans);
    txtNota.setTypeface(pfBeausans);

    if (zeroAcem)
        txtNota.setText(getString(R.string.nota100));
    else
        txtNota.setText(getString(R.string.nota10));


    //set onClick Buttons
    btCalcular.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            calculaNotas(v);
        }
    });
}
 
Example 19
Project: Appmatic-Android   File: ViewParsingUtils.java   View Source Code Vote up 4 votes
private static TableLayout inflateTable(Context context, String tableContent, String[] extras,
                                        boolean isFirstView, boolean isLastView) {
    TableLayout tableLayout = new TableLayout(context);
    String[] rows = tableContent.split(Content.TABLE_ROW_DIVIDER);
    int primaryColor = ContextCompat.getColor(context, R.color.colorPrimary);
    int stripColor = Color.argb(35, Color.red(primaryColor), Color.green(primaryColor), Color.blue(primaryColor));
    TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    TableRow.LayoutParams rowParams = new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tableLayout.setLayoutParams(tableParams);
    tableLayout.setStretchAllColumns(true);
    for (int i = 0; i < rows.length; i++) {
        TableRow tableRow = new TableRow(context);
        tableRow.setLayoutParams(rowParams);
        if (Arrays.asList(extras).contains(Content.EXTRA_HAS_STRIPES) && i % 2 != 0)
            tableRow.setBackgroundColor(stripColor);
        if (Arrays.asList(extras).contains(Content.EXTRA_HAS_HEADER) && i == 0)
            tableRow.setBackgroundResource(R.drawable.bottom_tablerow_border);
        String[] rowCells = rows[i].split(Content.TABLE_COLUMN_DIVIDER);
        for (int j = 0; j < rowCells.length; j++) {
            TextView tvCell = new TextView(context);
            tvCell.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16.0f);
            tvCell.setText(rowCells[j]);
            tvCell.setTextColor(ContextCompat.getColor(context, R.color.mainTextColor));
            int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                    context.getResources().getDisplayMetrics());
            tvCell.setPadding(padding, i == 0 ? 0 : padding, padding, padding);
            if (Arrays.asList(extras).contains(Content.EXTRA_HAS_HEADER) && i == 0) {
                tableRow.setBackgroundResource(R.drawable.bottom_tablerow_border);
                tvCell.setTypeface(null, Typeface.BOLD);
            }
            if (j == rowCells.length - 1)
                tvCell.setGravity(GravityCompat.END);
            tableRow.addView(tvCell);
        }
        tableLayout.addView(tableRow);
    }

    if (isFirstView && isLastView)
        setViewMargins(tableLayout, 0, defaultMargin, 0, 0);
    else if (isFirstView)
        setViewMargins(tableLayout, 0, defaultMargin, 0, halfMargin);
    else if (isLastView)
        setViewMargins(tableLayout, 0, halfMargin, 0, 0);
    else
        setViewMargins(tableLayout, 0, halfMargin, 0, halfMargin);

    return tableLayout;
}
 
Example 20
Project: Rey-MusicPlayer   File: ABRepeatDialog.java   View Source Code Vote up 2 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    mApp = (Common) getActivity().getApplicationContext();

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.a_b_repeat);
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_ab_repeat, null);
    mSeekBar = view.findViewById(R.id.repeat_song_range_placeholder_seekbar);

    repeatSongATime = view.findViewById(R.id.repeat_song_range_A_time);
    repeatSongBTime = view.findViewById(R.id.repeat_song_range_B_time);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mSeekBar.getLayoutParams();
    viewGroup = (ViewGroup) mSeekBar.getParent();
    viewGroup.removeView(mSeekBar);


    repeatSongATime.setTypeface(TypefaceHelper.getTypeface(getActivity().getApplicationContext(), "Futura-Condensed-Font"));
    repeatSongBTime.setTypeface(TypefaceHelper.getTypeface(getActivity().getApplicationContext(), "Futura-Condensed-Font"));

    TextView textView = view.findViewById(R.id.repeat_song_range_instructions);
    textView.setTypeface(TypefaceHelper.getTypeface(getActivity().getApplicationContext(), "Futura-Condensed-Font"));

    currentSongDurationMillis = mApp.getService().getMediaPlayer().getDuration();

    mRangeSeekBar = new RangeSeekBar<>(0, currentSongDurationMillis, getActivity().getApplicationContext());

    mRangeSeekBar.setLayoutParams(params);
    viewGroup.addView(mRangeSeekBar);


    if (PreferencesHelper.getInstance().getInt(PreferencesHelper.Key.REPEAT_MODE, Constants.REPEAT_OFF) == Constants.A_B_REPEAT) {

        repeatSongATime.setText(MusicUtils.convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointA()));
        repeatSongBTime.setText(MusicUtils.convertMillisToMinsSecs(mApp.getService().getRepeatSongRangePointB()));


        repeatPointA = mApp.getService().getRepeatSongRangePointA();
        repeatPointB = mApp.getService().getRepeatSongRangePointB();

        mRangeSeekBar.setSelectedMinValue(repeatPointA);
        mRangeSeekBar.setSelectedMaxValue(repeatPointB);

    } else {
        repeatSongATime.setText("0:00");
        repeatSongBTime.setText(MusicUtils.convertMillisToMinsSecs(currentSongDurationMillis));

        repeatPointA = 0;
        repeatPointB = currentSongDurationMillis;
    }

    mRangeSeekBar.setOnRangeSeekBarChangeListener((bar, minValue, maxValue) -> {
        repeatPointA = minValue;
        repeatPointB = maxValue;
        repeatSongATime.setText(MusicUtils.convertMillisToMinsSecs(minValue));
        repeatSongBTime.setText(MusicUtils.convertMillisToMinsSecs(maxValue));
    });

    repeatSongATime.setText(MusicUtils.convertMillisToMinsSecs(repeatPointA));
    repeatSongBTime.setText(MusicUtils.convertMillisToMinsSecs(repeatPointB));


    builder.setView(view);

    builder.setPositiveButton(R.string.repeat, (arg0, arg1) -> {
        PreferencesHelper.getInstance().put(PreferencesHelper.Key.REPEAT_MODE, Constants.A_B_REPEAT);
        mApp.getService().setRepeatSongRange(repeatPointA, repeatPointB);
        ((NowPlayingActivity) getActivity()).applyRepeatButton();
        dismiss();
    });

    builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
    return builder.create();
}