Android Open Source - Tacere Bug Report Activity






From Project

Back to project page Tacere.

License

The source code is released under:

MIT License

If you think the Android project Tacere 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 Jonathan Nelson/*from w  ww .  j  a  v a  2  s. c  o m*/
 * Released under the BSD license.  For details see the COPYING file.
 */

package org.ciasaboark.tacere.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.Toast;

import org.ciasaboark.tacere.R;
import org.ciasaboark.tacere.billing.KeySet;
import org.ciasaboark.tacere.versioning.Versioning;
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Label;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.User;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.IssueService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.egit.github.core.service.UserService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BugReportActivity extends ActionBarActivity {
    private static final String TAG = "BugReportActivity";
    private static final String REPORT_MESSAGE = "reportMessage";
    private static final String REPORT_EMAIL = "reportEmail";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar == null) {
            Log.w(TAG, "could not get reference to actionbar, can not hide.");
        } else {
            actionBar.hide();
        }
        setContentView(R.layout.activity_bug_report);

        final Spinner spinner = (Spinner) findViewById(R.id.spinner);
        // Create an ArrayAdapter using the string array and a default spinner layout
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.report_types, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        spinner.setAdapter(adapter);


        Button closeButton = (Button) findViewById(R.id.bug_report_button_cancel);
        closeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        final Button sendButton = (Button) findViewById(R.id.bug_report_button_send);
        sendButton.setEnabled(false);
        sendButton.setVisibility(View.INVISIBLE);
        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendButton.setEnabled(false);

                final ProgressBar busySpinner = (ProgressBar) findViewById(R.id.bug_report_progressbar);
                busySpinner.setVisibility(View.VISIBLE);

                EditText messageEditText = (EditText) findViewById(R.id.bug_report_message);
                final String messageText = messageEditText.getText().toString();

                EditText emailEditText = (EditText) findViewById(R.id.bug_report_email);
                String emailText = emailEditText.getText().toString();
                final String emailString = emailText.length() == 0 ? "no email address given" : emailText;

                final String spinnerSelection = spinner.getSelectedItem() == null ?
                        "bug" :
                        spinner.getSelectedItem().toString();

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        boolean reportSent = false;
                        GitHubClient client = new GitHubClient();
                        client.setOAuth2Token(KeySet.GITHUB_OAUTH);

                        RepositoryService repositoryService = new RepositoryService(client);
                        try {
                            Repository repository = repositoryService.getRepository("ciasaboark", "Tacere");

                            IssueService issueService = new IssueService();
                            issueService.getClient().setOAuth2Token(KeySet.GITHUB_OAUTH);
                            Issue issue = new Issue();
                            issue.setTitle("Tacere issue submit");


                            String bodyText = "";
                            bodyText += messageText;
                            bodyText += "\n\nEmail : " + emailString;
                            bodyText += "\nAndroid Version: " + Build.VERSION.RELEASE;
                            bodyText += "\nTacere version: " + Versioning.getVersionCode();
                            bodyText += "\nDevice: " + Build.MANUFACTURER + " - " + Build.MODEL;
                            bodyText += "\nRom: " + Build.DISPLAY;

                            issue.setBody(bodyText);

                            Label label = new Label();
                            label.setName("autosubmit");
                            List<Label> labels = new ArrayList<Label>();
                            labels.add(label);

                            String reportTypeLabel;
                            switch (spinnerSelection.toLowerCase()) {
                                case "bug":
                                    reportTypeLabel = "bug";
                                    break;
                                case "wishlist":
                                    reportTypeLabel = "wishlist";
                                    break;
                                default:
                                    Log.w(TAG, "unknown reportType " + spinnerSelection + ", assuming to " +
                                            "be a bug report");
                                    reportTypeLabel = "bug";
                            }

                            Label reportLabel = new Label();
                            reportLabel.setName(reportTypeLabel);
                            labels.add(reportLabel);
                            issue.setLabels(labels);

                            UserService userService = new UserService(client);
                            User user = userService.getUser("ciasaboark");
                            issue.setAssignee(user);

                            try {
                                issueService.createIssue(repository, issue);
                                reportSent = true;
                            } catch (IOException e) {
                                Log.e(TAG, "unable to create issue in repository");
                            }

                        } catch (IOException e) {
                            Log.e(TAG, "unable to get list of user repositories");
                        }


                        if (reportSent) {
                            BugReportActivity.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    Toast.makeText(BugReportActivity.this, R.string.bug_report_toast_sent, Toast.LENGTH_LONG).show();
                                    finish();
                                }
                            });
                        } else {
                            BugReportActivity.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    Toast.makeText(BugReportActivity.this, R.string.bug_report_toast_failed, Toast.LENGTH_LONG).show();
                                    busySpinner.setVisibility(View.INVISIBLE);
                                    sendButton.setEnabled(true);
                                    sendButton.setVisibility(View.VISIBLE);
                                }
                            });
                        }
                    }
                }).start();

            }
        });

        EditText messageEditText = (EditText) findViewById(R.id.bug_report_message);
        messageEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                //nothing to do here
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //nothing to do here
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    sendButton.setVisibility(View.VISIBLE);
                    sendButton.setEnabled(true);
                } else {
                    sendButton.setVisibility(View.INVISIBLE);
                    sendButton.setEnabled(false);
                }
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_bug_report, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

.EventInstanceTest.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java
org.ciasaboark.tacere.ApplicationTest.java
org.ciasaboark.tacere.Tacere.java
org.ciasaboark.tacere.activity.AboutActivity.java
org.ciasaboark.tacere.activity.AboutLicenseActivity.java
org.ciasaboark.tacere.activity.AdvancedSettingsActivity.java
org.ciasaboark.tacere.activity.BetaReleaseActivity.java
org.ciasaboark.tacere.activity.BetaSettingsActivity.java
org.ciasaboark.tacere.activity.BugReportActivity.java
org.ciasaboark.tacere.activity.DonationActivityTest.java
org.ciasaboark.tacere.activity.LicenseCheckWrapper.java
org.ciasaboark.tacere.activity.MainActivity.java
org.ciasaboark.tacere.activity.ProUpgradeActivity.java
org.ciasaboark.tacere.activity.SelectCalendarsActivity.java
org.ciasaboark.tacere.activity.SettingsActivity.java
org.ciasaboark.tacere.activity.ShowUpdatesActivity.java
org.ciasaboark.tacere.activity.TutorialActivity.java
org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.BetaSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java
org.ciasaboark.tacere.activity.fragment.MainSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.SelectCalendarsFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialCrashReporterFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEndFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEventListFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialProVersionFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialRingerPriorityFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialWelcomeFragment.java
org.ciasaboark.tacere.adapter.EventCursorAdapter.java
org.ciasaboark.tacere.billing.Authenticator.java
org.ciasaboark.tacere.billing.google.Base64DecoderException.java
org.ciasaboark.tacere.billing.google.Base64.java
org.ciasaboark.tacere.billing.google.IabException.java
org.ciasaboark.tacere.billing.google.IabHelper.java
org.ciasaboark.tacere.billing.google.IabResult.java
org.ciasaboark.tacere.billing.google.Inventory.java
org.ciasaboark.tacere.billing.google.Purchase.java
org.ciasaboark.tacere.billing.google.Security.java
org.ciasaboark.tacere.billing.google.SkuDetails.java
org.ciasaboark.tacere.bug.CrashReportManager.java
org.ciasaboark.tacere.converter.DateConverterTest.java
org.ciasaboark.tacere.converter.DateConverter.java
org.ciasaboark.tacere.converter.TimeConverter.java
org.ciasaboark.tacere.database.Columns.java
org.ciasaboark.tacere.database.DataSetManager.java
org.ciasaboark.tacere.database.DatabaseInterface.java
org.ciasaboark.tacere.database.EventDatabaseOpenHelper.java
org.ciasaboark.tacere.database.NoSuchEventInstanceException.java
org.ciasaboark.tacere.database.TooltipManager.java
org.ciasaboark.tacere.event.Calendar.java
org.ciasaboark.tacere.event.EventInstance.java
org.ciasaboark.tacere.event.EventManager.java
org.ciasaboark.tacere.event.ringer.Intervals.java
org.ciasaboark.tacere.event.ringer.RingerSource.java
org.ciasaboark.tacere.event.ringer.RingerType.java
org.ciasaboark.tacere.key.ApplicationTest.java
org.ciasaboark.tacere.key.MainActivity.java
org.ciasaboark.tacere.manager.AlarmManagerWrapper.java
org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
org.ciasaboark.tacere.manager.RingerStateManager.java
org.ciasaboark.tacere.manager.ServiceStateManager.java
org.ciasaboark.tacere.manager.VolumesManager.java
org.ciasaboark.tacere.notifier.WidgetNotifier.java
org.ciasaboark.tacere.prefs.BetaPrefs.java
org.ciasaboark.tacere.prefs.DefaultPrefs.java
org.ciasaboark.tacere.prefs.PrefsTest.java
org.ciasaboark.tacere.prefs.Prefs.java
org.ciasaboark.tacere.prefs.Updates.java
org.ciasaboark.tacere.receiver.BootCompletedReceiver.java
org.ciasaboark.tacere.receiver.ProviderChangedReceiver.java
org.ciasaboark.tacere.service.EventSilencerService.java
org.ciasaboark.tacere.service.ExtendEventService.java
org.ciasaboark.tacere.service.ExtendQuicksilenceService.java
org.ciasaboark.tacere.service.RequestTypes.java
org.ciasaboark.tacere.service.ResetEventServiceTest.java
org.ciasaboark.tacere.service.ResetEventService.java
org.ciasaboark.tacere.service.SkipEventService.java
org.ciasaboark.tacere.versioning.Versioning.java
org.ciasaboark.tacere.view.EventListItem.java
org.ciasaboark.tacere.widget.ActiveEventWidgetProvider.java
org.ciasaboark.tacere.widget.EventListWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceTinyWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceWidgetProvider.java
org.ciasaboark.tacere.widget.activity.WidgetPopupRinger.java
org.ciasaboark.tacere.widget.adapter.WidgetEventListAdapter.java
org.ciasaboark.tacere.widget.service.WidgetService.java