Android Open Source - GMIMediaAndroid Text File Dialog Builder






From Project

Back to project page GMIMediaAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project GMIMediaAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Gospel Ministries International
 *//from   w  ww  .  j a  v a2 s .c  o  m
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gospelministries.gmimedia.ui.dialog;

import android.app.AlertDialog;
import android.content.Context;

import java.io.*;

/**
 * Dialog builder where the message is read from a file.
 *
 * @since 1.0.0
 */
public class TextFileDialogBuilder {

    /**
     * The context of the dialog. From here the Strings will be pulled.
     */
    private Context context;

    /**
     * The resource ID of the text file.
     */
    private int rawTextFileId;

    /**
     * Creates a new dialog.
     *
     * @param context       The context where the dialog will be shown. From
     *                      here the Strings will be pulled.
     * @param rawTextFileId The ID of the text file. It should be located in the
     *                      `raw` directory.
     */
    public TextFileDialogBuilder(Context context, int rawTextFileId) {
        this.context = context;
        this.rawTextFileId = rawTextFileId;
    }

    /**
     * Returns the builder
     *
     * @return an {@link android.app.AlertDialog.Builder} for more customizations.
     *
     * @throws IllegalStateException
     */
    public AlertDialog.Builder getAlertDialogBuilder() {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

        try {
            alertDialogBuilder.setMessage(readTextFile());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }

        return alertDialogBuilder;
    }

    /**
     * Reads the text file and sets it.
     *
     * @return the content of the text file.
     *
     * @throws IOException
     */
    private String readTextFile() throws IOException {
        InputStream inputStream = context.getResources().openRawResource(rawTextFileId);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        StringWriter stringWriter = new StringWriter();

        String line;
        while ((line = reader.readLine()) != null) {
            stringWriter.append(line).append("\n");
        }

        return stringWriter.toString();
    }
}




Java Source Code List

com.gospelministries.gmimedia.adapter.MainFragmentPagerAdapter.java
com.gospelministries.gmimedia.adapter.StreamArrayAdapter.java
com.gospelministries.gmimedia.bean.AudioStream.java
com.gospelministries.gmimedia.bean.StreamList.java
com.gospelministries.gmimedia.bean.Stream.java
com.gospelministries.gmimedia.bean.Streampoint.java
com.gospelministries.gmimedia.bean.VideoStream.java
com.gospelministries.gmimedia.ui.activity.AbstractStreamListFragment.java
com.gospelministries.gmimedia.ui.activity.InfoActivity.java
com.gospelministries.gmimedia.ui.activity.MainActivity.java
com.gospelministries.gmimedia.ui.activity.RadioListFragment.java
com.gospelministries.gmimedia.ui.activity.TvListFragment.java
com.gospelministries.gmimedia.ui.activity.VideoPlayerActivity.java
com.gospelministries.gmimedia.ui.dialog.SelectStreampointDialog.java
com.gospelministries.gmimedia.ui.dialog.TextFileDialogBuilder.java
com.gospelministries.gmimedia.util.Constants.java
com.gospelministries.gmimedia.util.SerializerHelper.java
com.gospelministries.gmimedia.widget.MutableVideoView.java
com.gospelministries.gmimedia.widget.MuteableVideoView.java