mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Add Google Feedback for ICS+ devices.
This commit is contained in:
@@ -103,9 +103,14 @@ limitations under the License.
|
||||
android:id="@+id/track_detail_settings"
|
||||
android:orderInCategory="14"
|
||||
android:title="@string/menu_settings"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_feedback"
|
||||
android:id="@+id/track_detail_feedback"
|
||||
android:orderInCategory="15"
|
||||
android:title="@string/menu_feedback"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_help"
|
||||
android:id="@+id/track_detail_help"
|
||||
android:orderInCategory="15"
|
||||
android:orderInCategory="16"
|
||||
android:title="@string/menu_help"/>
|
||||
</menu>
|
||||
@@ -38,6 +38,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.settings.SettingsActivity;
|
||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
||||
import com.google.android.apps.mytracks.util.GoogleFeedbackUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
@@ -104,6 +105,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
private MenuItem saveMenuItem;
|
||||
private MenuItem voiceFrequencyMenuItem;
|
||||
private MenuItem splitFrequencyMenuItem;
|
||||
private MenuItem feedbackMenuItem;
|
||||
|
||||
private final Runnable bindChangedCallback = new Runnable() {
|
||||
@Override
|
||||
@@ -309,7 +311,9 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
saveMenuItem = menu.findItem(R.id.track_detail_save);
|
||||
voiceFrequencyMenuItem = menu.findItem(R.id.track_detail_voice_frequency);
|
||||
splitFrequencyMenuItem = menu.findItem(R.id.track_detail_split_frequency);
|
||||
|
||||
feedbackMenuItem = menu.findItem(R.id.track_detail_split_frequency);
|
||||
feedbackMenuItem.setVisible(GoogleFeedbackUtils.isAvailable(this));
|
||||
|
||||
updateMenuItems(trackId == recordingTrackId, recordingTrackPaused);
|
||||
return true;
|
||||
}
|
||||
@@ -407,6 +411,9 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
intent = IntentUtils.newIntent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_feedback:
|
||||
GoogleFeedbackUtils.bindFeedback(this);
|
||||
return true;
|
||||
case R.id.track_detail_help:
|
||||
intent = IntentUtils.newIntent(this, HelpActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.google.android.apps.mytracks.settings.SettingsActivity;
|
||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.EulaUtils;
|
||||
import com.google.android.apps.mytracks.util.GoogleFeedbackUtils;
|
||||
import com.google.android.apps.mytracks.util.GoogleLocationUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.ListItemUtils;
|
||||
@@ -55,27 +56,17 @@ import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtil
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.userfeedback.android.api.UserFeedback;
|
||||
import com.google.userfeedback.android.api.UserFeedbackSpec;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.database.Cursor;
|
||||
import android.location.Location;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
@@ -97,7 +88,6 @@ import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -362,6 +352,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
private MenuItem saveAllMenuItem;
|
||||
private MenuItem deleteAllMenuItem;
|
||||
private MenuItem syncNowMenuItem;
|
||||
private MenuItem feedbackMenuItem;
|
||||
|
||||
private boolean startNewRecording = false; // true to start a new recording
|
||||
private boolean startGps = false;
|
||||
@@ -556,6 +547,8 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
saveAllMenuItem = menu.findItem(R.id.track_list_save_all);
|
||||
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
||||
syncNowMenuItem = menu.findItem(R.id.track_list_sync_now);
|
||||
feedbackMenuItem = menu.findItem(R.id.track_list_feedback);
|
||||
feedbackMenuItem.setVisible(GoogleFeedbackUtils.isAvailable(this));
|
||||
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem);
|
||||
updateMenuItems(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
@@ -619,30 +612,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_list_feedback:
|
||||
if (isFeedbackAvailable()) {
|
||||
intent = new Intent(Intent.ACTION_BUG_REPORT);
|
||||
ServiceConnection conn = new ServiceConnection() {
|
||||
|
||||
public void onServiceDisconnected(ComponentName name) {}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
try {
|
||||
service.transact(Binder.FIRST_CALL_TRANSACTION, Parcel.obtain(), null, 0);
|
||||
} catch (RemoteException e) {
|
||||
// TODO(jshih): Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
// Bind to the service after creating it if necessary
|
||||
bindService(intent, conn, BIND_AUTO_CREATE);
|
||||
} else {
|
||||
UserFeedbackSpec spec = new UserFeedbackSpec(this, "com.google.android.maps.mytracks:V *:S",
|
||||
"com.google.android.maps.mytracks.USER_INITIATED_FEEDBACK_REPORT");
|
||||
UserFeedback userFeedback = new UserFeedback();
|
||||
userFeedback.startFeedback(spec);
|
||||
}
|
||||
GoogleFeedbackUtils.bindFeedback(this);
|
||||
return true;
|
||||
case R.id.track_list_help:
|
||||
intent = IntentUtils.newIntent(this, HelpActivity.class);
|
||||
@@ -652,18 +622,6 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFeedbackAvailable() {
|
||||
List<ResolveInfo> infos = getPackageManager().queryIntentServices(
|
||||
new Intent(Intent.ACTION_BUG_REPORT), PackageManager.MATCH_DEFAULT_ONLY);
|
||||
for (ResolveInfo info : infos) {
|
||||
if (info.serviceInfo != null && info.serviceInfo.packageName != null
|
||||
&& info.serviceInfo.packageName.equals("com.google.android.feedback")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for Google Feedback.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class GoogleFeedbackUtils {
|
||||
|
||||
private static final String GOOGLE_FEEDBACK_PACKAGE_NAME = "com.google.android.feedback";
|
||||
private static final String TAG = GoogleFeedbackUtils.class.getSimpleName();
|
||||
|
||||
private static Boolean available = null;
|
||||
|
||||
/**
|
||||
* Returns true if the Google Feedback is available.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isAvailable(Context context) {
|
||||
if (available == null) {
|
||||
List<ResolveInfo> infos = context.getPackageManager().queryIntentServices(
|
||||
new Intent(Intent.ACTION_BUG_REPORT), PackageManager.MATCH_DEFAULT_ONLY);
|
||||
for (ResolveInfo info : infos) {
|
||||
if (info.serviceInfo != null && info.serviceInfo.packageName != null
|
||||
&& info.serviceInfo.packageName.equals(GOOGLE_FEEDBACK_PACKAGE_NAME)) {
|
||||
available = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (available == null) {
|
||||
available = false;
|
||||
}
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the Google Feedback service.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static void bindFeedback(Context context) {
|
||||
Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
|
||||
ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
try {
|
||||
service.transact(Binder.FIRST_CALL_TRANSACTION, Parcel.obtain(), null, 0);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {}
|
||||
};
|
||||
// Bind to the service after creating it if necessary
|
||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user