OSDN Git Service

Import translations. DO NOT MERGE am: 475763d01c -s ours am: 9a22968ff8 -s ours...
[android-x86/packages-apps-Settings.git] / src / com / android / settings / BugreportPreference.java
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.settings;
18
19 import android.app.ActivityManager;
20 import android.app.AlertDialog.Builder;
21 import android.content.Context;
22 import android.content.DialogInterface;
23 import android.os.RemoteException;
24 import android.util.AttributeSet;
25 import android.util.Log;
26 import android.view.View;
27 import android.widget.CheckedTextView;
28 import android.widget.TextView;
29
30 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
31 import com.android.settings.overlay.FeatureFactory;
32
33 public class BugreportPreference extends CustomDialogPreference {
34
35     private static final String TAG = "BugreportPreference";
36
37     private CheckedTextView mInteractiveTitle;
38     private TextView mInteractiveSummary;
39     private CheckedTextView mFullTitle;
40     private TextView mFullSummary;
41
42     public BugreportPreference(Context context, AttributeSet attrs) {
43         super(context, attrs);
44     }
45
46     @Override
47     protected void onPrepareDialogBuilder(Builder builder, DialogInterface.OnClickListener listener) {
48         super.onPrepareDialogBuilder(builder, listener);
49
50         final View dialogView = View.inflate(getContext(), R.layout.bugreport_options_dialog, null);
51         mInteractiveTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_interactive_title);
52         mInteractiveSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_interactive_summary);
53         mFullTitle = (CheckedTextView) dialogView.findViewById(R.id.bugreport_option_full_title);
54         mFullSummary = (TextView) dialogView.findViewById(R.id.bugreport_option_full_summary);
55         final View.OnClickListener l = new View.OnClickListener() {
56
57             @Override
58             public void onClick(View v) {
59                 if (v == mFullTitle || v == mFullSummary) {
60                     mInteractiveTitle.setChecked(false);
61                     mFullTitle.setChecked(true);
62                 }
63                 if (v == mInteractiveTitle || v == mInteractiveSummary) {
64                     mInteractiveTitle.setChecked(true);
65                     mFullTitle.setChecked(false);
66                 }
67             }
68         };
69         mInteractiveTitle.setOnClickListener(l);
70         mFullTitle.setOnClickListener(l);
71         mInteractiveSummary.setOnClickListener(l);
72         mFullSummary.setOnClickListener(l);
73
74         builder.setPositiveButton(com.android.internal.R.string.report, listener);
75         builder.setView(dialogView);
76     }
77
78     @Override
79     protected void onClick(DialogInterface dialog, int which) {
80         if (which == DialogInterface.BUTTON_POSITIVE) {
81
82             final Context context = getContext();
83             if (mFullTitle.isChecked()) {
84                 Log.v(TAG, "Taking full bugreport right away");
85                 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
86                         MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_FULL);
87                 takeBugreport(ActivityManager.BUGREPORT_OPTION_FULL);
88             } else {
89                 Log.v(TAG, "Taking interactive bugreport right away");
90                 FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context,
91                         MetricsEvent.ACTION_BUGREPORT_FROM_SETTINGS_INTERACTIVE);
92                 takeBugreport(ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
93             }
94         }
95     }
96
97     private void takeBugreport(int bugreportType) {
98         try {
99             ActivityManager.getService().requestBugReport(bugreportType);
100         } catch (RemoteException e) {
101             Log.e(TAG, "error taking bugreport (bugreportType=" + bugreportType + ")", e);
102         }
103     }
104 }