Android Open Source - RSSFeedReader-App Add Source Dialog Fragment






From Project

Back to project page RSSFeedReader-App.

License

The source code is released under:

GNU General Public License

If you think the Android project RSSFeedReader-App 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

package tan.chesley.rssfeedreader;
//w  w  w.ja  v  a  2s.  c  o  m
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddSourceDialogFragment extends DialogFragment{

    private AddSourceCallbacks mCallback;

    interface AddSourceCallbacks {
        void onAddSourceCallback();
    }

    @Override
    public void onAttach (Activity activity) {
        super.onAttach(activity);
        if (!(activity instanceof AddSourceCallbacks)) {
            throw new ClassCastException(activity.toString() + " must implement AddSourceCallbacks");
        }
        else {
            mCallback = (AddSourceCallbacks) activity;
        }
    }

    @Override
    public Dialog onCreateDialog (Bundle savedInstanceState) {
        final Dialog dialog = new Dialog(getActivity(), R.style.SemiTransparentDialog);
        dialog.setContentView(R.layout.add_source_dialog);
        dialog.setTitle(getResources().getString(R.string.addSourceTitle));
        final EditText addSourceDialogEditText = (EditText) dialog.findViewById(R.id.addSourceDialogEditText);
        final Button addSourceDialogButton = (Button) dialog.findViewById(R.id.addSourceDialogButton);
        ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboardManager.hasPrimaryClip()) {
            if (clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                String pasteUrl = clipboardManager.getPrimaryClip().getItemAt(0).getText().toString();
                if (pasteUrl != null && pasteUrl.startsWith("http")) {
                    addSourceDialogEditText.setText(pasteUrl);
                }
            }
        }
        addSourceDialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view) {
                String s = addSourceDialogEditText.getText().toString();
                if (!s.startsWith("http://") && !s.startsWith("https://")) {
                    s = "http://" + s;
                    Log.e("URL", "URL modified to " + s);
                }
                ((ModifySources)getActivity()).validateAndAddSource(s);
                dialog.dismiss();
            }
        });
        return dialog;
    }
}




Java Source Code List

android.support.v4.app.FixedFragmentStatePagerAdapter.java
tan.chesley.rssfeedreader.AddSourceDialogFragment.java
tan.chesley.rssfeedreader.ArticleAgeLimitNumberPickerDialog.java
tan.chesley.rssfeedreader.ArticleViewFragment.java
tan.chesley.rssfeedreader.ArticleView.java
tan.chesley.rssfeedreader.AutosyncTimePickerDialog.java
tan.chesley.rssfeedreader.BrightnessControl.java
tan.chesley.rssfeedreader.DepthPageTransformer.java
tan.chesley.rssfeedreader.HeadlinesFragment.java
tan.chesley.rssfeedreader.MaxArticlesNumberPickerDialog.java
tan.chesley.rssfeedreader.MaxDatabaseSizeNumberPickerDialog.java
tan.chesley.rssfeedreader.ModifySourceDialogFragment.java
tan.chesley.rssfeedreader.ModifySources.java
tan.chesley.rssfeedreader.NumberPickerDialogPreference.java
tan.chesley.rssfeedreader.RSSDataBundleOpenHelper.java
tan.chesley.rssfeedreader.RSSDataBundle.java
tan.chesley.rssfeedreader.RSSFeed.java
tan.chesley.rssfeedreader.RSSHandler.java
tan.chesley.rssfeedreader.RssSyncService.java
tan.chesley.rssfeedreader.SettingsActivity.java
tan.chesley.rssfeedreader.SettingsFragment.java
tan.chesley.rssfeedreader.SourcesOpenHelper.java
tan.chesley.rssfeedreader.SyncTimeoutNumberPickerDialog.java
tan.chesley.rssfeedreader.TaskFragment.java
tan.chesley.rssfeedreader.TimePickerDialogPreference.java
tan.chesley.rssfeedreader.Toaster.java