Skip to content

Commit

Permalink
Add emoticon head prompt and fix double permission asking dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
KTachibanaM committed Jun 29, 2016
1 parent 8e100af commit 2e54732
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,29 @@ protected void onStart() {
// Setup notification
setupNotification();

// Show overlay rationale if needed
showOverlayRationaleIfNeeded();

// Setup emoticon head
setupEmoticonHead();

// DO NOT PUT ANY INIT CODE AFTER THIS
}

@TargetApi(23)
private void showOverlayRationaleIfNeeded() {
if (!EmoticonHeadUtils.isOverlayAllowed(this)) {
new AlertDialogWrapper.Builder(this)
.setMessage(R.string.overlay_rationale)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);
}
})
.show();
}
private void showOverlayRationale() {
new AlertDialogWrapper.Builder(this)
.setMessage(R.string.overlay_rationale)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);
}
})
.show();
}

private void setupEmoticonHead() {
if (EmoticonHeadUtils.isOverlayAllowed(this)) {
EmoticonHeadUtils.setupEmoticonHeadWithPref(this, mPreferences.getBoolean(Constants.PREF_EMOTICON_HEAD_VISIBILITY, Constants.EMOTICON_HEAD_DEFAULT_VISIBILITY));
} else {
showOverlayRationale();
}
}

Expand Down Expand Up @@ -308,12 +303,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Coming back from preference
// Favorites may be changed
// Need to re-render favorites
if (requestCode == Constants.PREFERENCE_REQUEST_CODE) {
else if (requestCode == Constants.PREFERENCE_REQUEST_CODE) {
render();
}

// Coming back from overlay permission
if (requestCode == OVERLAY_PERMISSION_REQUEST_CODE) {
else if (requestCode == OVERLAY_PERMISSION_REQUEST_CODE) {
if (EmoticonHeadUtils.isOverlayAllowed(this)) {
setupEmoticonHead();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class EmoticonHeadService extends Service {
@Bind(R.id.icon)
ImageView icon;

@Bind(R.id.prompt)
TextView prompt;

List<Favorite> favorites;
Adapter adapter;
@Bind(R.id.list)
Expand Down Expand Up @@ -123,8 +126,10 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
// When clicked, show/hide window
if (showing) {
list.setVisibility(View.GONE);
prompt.setVisibility(View.GONE);
} else {
list.setVisibility(View.VISIBLE);
prompt.setVisibility(View.VISIBLE);
}
showing = !showing;
return true;
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/view_emoticon_head.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list"
android:background="#EEEEEE"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/icon"
android:paddingBottom="18dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="18dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/emoticon_head_prompt"
android:textColor="@android:color/black"
android:id="@+id/prompt"
android:layout_toRightOf="@+id/icon"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/list" />
</RelativeLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
<string name="emoticon_head">Emoticon head</string>
<string name="emoticon_head_visibility">Emoticon head visibility</string>
<string name="show_emoticon_head_after_boot_up">Show emoticon head after boot-up</string>
<string name="overlay_rationale">We need overlay permission in order to show emoticon head.\nDon\'t worry, you can always disable it.</string>
<string name="overlay_rationale">We need overlay permission in order to show emoticon head.\nEmoticon head is a floating icon on top of your screen from which you can quickly access your bookmarks without opening the app.\nDon\'t worry, you can always disable it.</string>
<string name="emoticon_head_prompt">Single tap to show/hide, double tap to refresh from bookmarks</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
<string name="emoticon_head">颜文字大头</string>
<string name="emoticon_head_visibility">颜文字大头可见性</string>
<string name="show_emoticon_head_after_boot_up">启动后显示颜文字大头</string>
<string name="overlay_rationale">需要系统窗口权限以显示颜文字大头\n不用担心, 你可以随时关闭它.</string>
<string name="overlay_rationale">需要系统窗口权限以显示颜文字大头\n颜文字大头是一个悬浮于屏幕之上的图标,你可以从那里迅速使用收藏而不用打开应用\n不用担心, 你可以随时关闭它.</string>
<string name="emoticon_head_prompt">单击以显示/隐藏,双击以从收藏刷新</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
<string name="emoticon_head">Emoticon head</string>
<string name="emoticon_head_visibility">Emoticon head visibility</string>
<string name="show_emoticon_head_after_boot_up">Show emoticon head after boot-up</string>
<string name="overlay_rationale">We need overlay permission in order to show emoticon head.\nDon\'t worry, you can always disable it.</string>
<string name="overlay_rationale">We need overlay permission in order to show emoticon head.\nEmoticon head is a floating icon on top of your screen from which you can quickly access your bookmarks without opening the app.\nDon\'t worry, you can always disable it.</string>
<string name="emoticon_head_prompt">Single tap to show/hide, double tap to refresh from bookmarks</string>
</resources>

0 comments on commit 2e54732

Please sign in to comment.