mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 21:55:31 +00:00
Bug 1205216 - Tab queue prompt: Ask user to enable "Draw over other apps" if needed. r=nalexander
--HG-- extra : commitid : G98pSYlWef4 extra : rebase_source : 91f7db4a7b2d30d67074449b56289415ff20e79b
This commit is contained in:
parent
eca77a2c87
commit
e76440cbaf
@ -14,12 +14,15 @@ import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@ -48,6 +51,21 @@ public class TabQueueHelper {
|
||||
public static final int TAB_QUEUE_YES = 201;
|
||||
public static final int TAB_QUEUE_NO = 202;
|
||||
|
||||
/**
|
||||
* Checks if the specified context can draw on top of other apps. As of API level 23, an app
|
||||
* cannot draw on top of other apps unless it declares the SYSTEM_ALERT_WINDOW permission in
|
||||
* its manifest, AND the user specifically grants the app this capability.
|
||||
*
|
||||
* @return true if the specified context can draw on top of other apps, false otherwise.
|
||||
*/
|
||||
public static boolean canDrawOverlays(Context context) {
|
||||
if (AppConstants.Versions.preM) {
|
||||
return true; // We got the permission at install time.
|
||||
}
|
||||
|
||||
return Settings.canDrawOverlays(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we should show the tab queue prompt
|
||||
*
|
||||
|
@ -11,10 +11,18 @@ import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.animation.TransitionsTracker;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nineoldandroids.animation.Animator;
|
||||
import com.nineoldandroids.animation.AnimatorListenerAdapter;
|
||||
import com.nineoldandroids.animation.AnimatorSet;
|
||||
@ -24,6 +32,8 @@ import com.nineoldandroids.view.ViewHelper;
|
||||
public class TabQueuePrompt extends Locales.LocaleAwareActivity {
|
||||
public static final String LOGTAG = "Gecko" + TabQueuePrompt.class.getSimpleName();
|
||||
|
||||
private static final int SETTINGS_REQUEST_CODE = 1;
|
||||
|
||||
// Flag set during animation to prevent animation multiple-start.
|
||||
private boolean isAnimating;
|
||||
|
||||
@ -43,7 +53,8 @@ public class TabQueuePrompt extends Locales.LocaleAwareActivity {
|
||||
|
||||
final int numberOfTimesTabQueuePromptSeen = GeckoSharedPrefs.forApp(this).getInt(TabQueueHelper.PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN, 0);
|
||||
|
||||
findViewById(R.id.ok_button).setOnClickListener(new View.OnClickListener() {
|
||||
final View okButton = findViewById(R.id.ok_button);
|
||||
okButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onConfirmButtonPressed();
|
||||
@ -58,6 +69,28 @@ public class TabQueuePrompt extends Locales.LocaleAwareActivity {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
final View settingsButton = findViewById(R.id.settings_button);
|
||||
settingsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onSettingsButtonPressed();
|
||||
}
|
||||
});
|
||||
|
||||
final View tipView = findViewById(R.id.tip_text);
|
||||
final View settingsPermitView = findViewById(R.id.settings_permit_text);
|
||||
|
||||
if (TabQueueHelper.canDrawOverlays(this)) {
|
||||
okButton.setVisibility(View.VISIBLE);
|
||||
settingsButton.setVisibility(View.GONE);
|
||||
tipView.setVisibility(View.VISIBLE);
|
||||
settingsPermitView.setVisibility(View.GONE);
|
||||
} else {
|
||||
okButton.setVisibility(View.GONE);
|
||||
settingsButton.setVisibility(View.VISIBLE);
|
||||
tipView.setVisibility(View.GONE);
|
||||
settingsPermitView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
containerView = findViewById(R.id.tab_queue_container);
|
||||
buttonContainer = findViewById(R.id.button_container);
|
||||
@ -122,6 +155,31 @@ public class TabQueuePrompt extends Locales.LocaleAwareActivity {
|
||||
set.start();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private void onSettingsButtonPressed() {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, SETTINGS_REQUEST_CODE);
|
||||
|
||||
Toast.makeText(this, R.string.tab_queue_prompt_permit_drawing_over_apps, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode != SETTINGS_REQUEST_CODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (TabQueueHelper.canDrawOverlays(this)) {
|
||||
// User granted the permission in Android's settings.
|
||||
final int numberOfTimesTabQueuePromptSeen = GeckoSharedPrefs.forApp(this).getInt(TabQueueHelper.PREF_TAB_QUEUE_TIMES_PROMPT_SHOWN, 0);
|
||||
Telemetry.addToHistogram("FENNEC_TABQUEUE_PROMPT_ENABLE_YES", numberOfTimesTabQueuePromptSeen);
|
||||
|
||||
setResult(TabQueueHelper.TAB_QUEUE_YES);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slide the overlay down off the screen and destroy it.
|
||||
*/
|
||||
|
@ -243,8 +243,14 @@
|
||||
<!ENTITY tab_queue_prompt_title "Opening multiple links?">
|
||||
<!ENTITY tab_queue_prompt_text4 "Save them until the next time you open &brandShortName;.">
|
||||
<!ENTITY tab_queue_prompt_tip_text2 "You can change this later in Settings">
|
||||
<!-- Localization note (tab_queue_prompt_permit_drawing_over_apps): This additional text is shown if the
|
||||
user needs to enable an Android setting in order to enable tab queues. -->
|
||||
<!ENTITY tab_queue_prompt_permit_drawing_over_apps "Turn on Permit drawing over other apps">
|
||||
<!ENTITY tab_queue_prompt_positive_action_button "Enable">
|
||||
<!ENTITY tab_queue_prompt_negative_action_button "Not now">
|
||||
<!-- Localization note (tab_queue_prompt_settings_button): This button is shown if the user needs to
|
||||
enable a permission in Android's setting in order to enable tab queues. -->
|
||||
<!ENTITY tab_queue_prompt_settings_button "Go to Settings">
|
||||
<!ENTITY tab_queue_notification_title "&brandShortName;">
|
||||
<!-- Localization note (tab_queue_notification_text_plural2) : The
|
||||
formatD is replaced with the number of tabs queued. The
|
||||
|
@ -45,7 +45,6 @@
|
||||
android:text="@string/tab_queue_prompt_text"
|
||||
android:textColor="@color/placeholder_grey"
|
||||
android:textSize="16sp"
|
||||
|
||||
tools:text="Save them until the next time you open Firefox." />
|
||||
|
||||
<TextView
|
||||
@ -60,9 +59,22 @@
|
||||
android:textColor="@color/action_orange"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="italic"
|
||||
|
||||
tools:text="you can change this later in Settings" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_permit_text"
|
||||
android:layout_width="@dimen/overlay_prompt_content_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="30dp"
|
||||
android:paddingTop="20dp"
|
||||
android:text="@string/tab_queue_prompt_permit_drawing_over_apps"
|
||||
android:textColor="@color/action_orange"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="italic"
|
||||
tools:text="Turn on Permit drawing over other apps" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/bottom_container"
|
||||
android:layout_width="match_parent"
|
||||
@ -108,9 +120,20 @@
|
||||
android:text="@string/tab_queue_prompt_positive_action_button"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
|
||||
tools:text="Enable" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/settings_button"
|
||||
style="@style/Widget.BaseButton"
|
||||
android:layout_width="@dimen/overlay_prompt_button_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/button_background_action_orange_round"
|
||||
android:text="@string/tab_queue_prompt_settings_button"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
tools:text="Go to settings" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
@ -285,6 +285,8 @@
|
||||
<string name="tab_queue_prompt_tip_text">&tab_queue_prompt_tip_text2;</string>
|
||||
<string name="tab_queue_prompt_positive_action_button">&tab_queue_prompt_positive_action_button;</string>
|
||||
<string name="tab_queue_prompt_negative_action_button">&tab_queue_prompt_negative_action_button;</string>
|
||||
<string name="tab_queue_prompt_permit_drawing_over_apps">&tab_queue_prompt_permit_drawing_over_apps;</string>
|
||||
<string name="tab_queue_prompt_settings_button">&tab_queue_prompt_settings_button;</string>
|
||||
<string name="tab_queue_toast_message">&tab_queue_toast_message3;</string>
|
||||
<string name="tab_queue_toast_action">&tab_queue_toast_action;</string>
|
||||
<string name="tab_queue_notification_text_singular">&tab_queue_notification_text_singular2;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user