Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic breakout lock screen #596

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4907b49
アプリが bg にいても JS のコールバックを呼び出すように変更。
Jun 23, 2015
47e855c
android.suport.v13 を使用しないように変更。
Jun 23, 2015
35133b0
android-support-v13.jar に含まれている v4 とオリジナルの android-support-v4 が
Jul 3, 2015
3183303
Merge pull request #1 from Nextremer/topic-notification-v4
Jul 3, 2015
284c00f
APIサーバからのGeolocation情報取得要求に HttpRequest で応答する機能を実装した。
Jul 7, 2015
bfaa5e8
Merge pull request #2 from Nextremer/topic-request-geolocation
Jul 7, 2015
aae0a96
onError() メソッドを間違えて消していた。
Jul 7, 2015
58dc703
Merge branch 'master' of github.com:Nextremer/PushPlugin into topic-r…
Jul 7, 2015
029db42
Merge pull request #3 from Nextremer/topic-request-geolocation
Jul 7, 2015
6bb3126
HttpRequest の終了ステータス判定を 200 番台は成功とみなすように修正した。
Jul 7, 2015
59d8e81
Merge pull request #4 from Nextremer/topic-request-geolocation
Jul 7, 2015
a810fb1
バイブレーションのパターンとアイコンを GCM のペイロードで伝えるように実装した。
Jul 8, 2015
e0d2f1c
Merge pull request #5 from Nextremer/topic-long-vibration
Jul 8, 2015
0014c4c
テキスト表示対応。
Jul 8, 2015
2600e47
Merge pull request #6 from Nextremer/topic-long-vibration
Jul 8, 2015
0a7cd8d
ポップアップダイアログ実装。スクリーンロック突破は未実装。
Jul 10, 2015
0eac16f
バイブレーション対応。ダイアログを出すときにバイブレーションを開始、[OK]/[Cancel]ボタンを押下したときに停止する。
Jul 10, 2015
6c67456
コミット漏れ。
Jul 10, 2015
f3f3ced
アイコン表示対応、ダイアログ外をタッチできない対応。
Jul 10, 2015
49a71c3
不要なパーミッションの削除。
Jul 10, 2015
b3e142a
AlertDialogActivity#onStop() にバイブレーション停止処理を追加した。
Jul 10, 2015
0906fd5
キーガードを検出し、ロック画面のときはバイブレーションを停止しないようにした。
Jul 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="$PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="$PACKAGE_NAME.permission.C2D_MESSAGE" />
Expand All @@ -56,14 +57,27 @@
</intent-filter>
</receiver>
<service android:name="com.plugin.gcm.GCMIntentService" />
<service android:name="com.plugin.gcm.LocationUpdateService" />

<activity
android:name="com.plugin.gcm.AlertDialogActivity"
android:theme="@style/Translucent"
android:launchMode="singleInstance">
</activity>
</config-file>

<source-file src="src/android/libs/gcm.jar" target-dir="libs/" />
<source-file src="src/android/com/plugin/gcm/CordovaGCMBroadcastReceiver.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/GCMIntentService.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/PushHandlerActivity.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/PushPlugin.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/LocationUpdateService.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/AssetUtil.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/AlertDialogActivity.java" target-dir="src/com/plugin/gcm/" />
<source-file src="src/android/com/plugin/gcm/AlertDialogFragment.java" target-dir="src/com/plugin/gcm/" />

<source-file src="src/android/com/plugin/android-support-v13.jar" target-dir="libs/" />
<source-file src="src/android/com/plugin/styles.xml" target-dir="res/values/" />

</platform>

Expand Down
Binary file modified src/android/com/plugin/android-support-v13.jar
Binary file not shown.
55 changes: 55 additions & 0 deletions src/android/com/plugin/gcm/AlertDialogActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.plugin.gcm;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.os.Vibrator;
import android.content.Context;
import android.app.KeyguardManager;
import android.content.Context;

public class AlertDialogActivity extends FragmentActivity {
private static final String TAG = "AlertDialogActivity";

private KeyguardManager _KeyguardManager;
private boolean _bScreenLocked = false;

public AlertDialogActivity() {
Log.d(TAG, "AlertDialogActivity#AlertDialogActivity(): check-1");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle extras = getIntent().getExtras();
AlertDialogFragment fragment = new AlertDialogFragment(extras);
fragment.show(getSupportFragmentManager(), "alert_dialog");
Log.d(TAG, "AlertDialogActivity#onCreate(): check-1");

_KeyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
_bScreenLocked = _KeyguardManager.inKeyguardRestrictedInputMode();
}

@Override
public void onAttachedToWindow() {
Log.d(TAG, "AlertDialogActivity#onAttachedToWindow(): check-1");
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON // スクリーンをONにする
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED // ロック画面の場合でも表示する
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
@Override
public void onStop() {
super.onStop();
_bScreenLocked = _KeyguardManager.inKeyguardRestrictedInputMode();
if(!_bScreenLocked)
{
final Vibrator vibrator =
(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.cancel();
}
}
}
112 changes: 112 additions & 0 deletions src/android/com/plugin/gcm/AlertDialogFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.plugin.gcm;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.graphics.Bitmap;
import android.net.Uri;
import android.graphics.drawable.BitmapDrawable;

import com.google.gson.Gson;

public class AlertDialogFragment extends DialogFragment {
private static final String TAG = "AlertDialogFragment";
private Bundle extras;
private AssetUtil assets;

public AlertDialogFragment(Bundle extras) {
this.extras = extras;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final Bundle originalExtras = extras.getBundle("pushBundle");
final Context context = getActivity().getApplicationContext();
final NotificationManager notificationManager =
(NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
final Vibrator vibrator =
(Vibrator)getActivity().getSystemService(Context.VIBRATOR_SERVICE);
String vibrateStrValue = originalExtras.getString("vibrate");
final long[] pattern = strValueToLongArray(vibrateStrValue);
Log.v(TAG, "onCreateDialog(): icon = "+ originalExtras.getString("icon"));
assets = AssetUtil.getInstance(context);
final Bitmap largeIcon = getLargeIcon(originalExtras.getString("icon"));

final int notId = Integer.parseInt(originalExtras.getString("notId"));
final String appName = GCMIntentService.getAppName(context);
Log.v(TAG, "onCreateDialog(): notId = "+ notId);
Dialog dialog = builder
.setTitle(originalExtras.getString("title"))
.setMessage(originalExtras.getString("text"))
.setIcon(new BitmapDrawable(largeIcon))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(context, PushHandlerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("pushBundle", originalExtras);
startActivity(intent);
notificationManager.cancel(appName, notId);
vibrator.cancel();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
vibrator.cancel();
}
})
.create();
dialog.setCanceledOnTouchOutside(false);
vibrator.vibrate(pattern, -1);

return dialog;
}

private long[] strValueToLongArray(String vibrateStrValue) {
Gson gson = new Gson();

return gson.fromJson(vibrateStrValue, long[].class);
}

@Override
public void onStop() {
super.onStop();
getActivity().finish();
}

public int getSmallIcon(String smallIcon) {
int resId = assets.getResIdForDrawable(smallIcon);

if (resId == 0) {
resId = android.R.drawable.ic_menu_mylocation;
}

return resId;
}

public Bitmap getLargeIcon(String icon) {
Bitmap bmp;

Log.d(TAG, "getLargeIcon(): icon = "+ icon);

try{
Uri uri = assets.parse(icon);
Log.d(TAG, "getLargeIcon(): uri = "+ uri);
bmp = assets.getIconFromUri(uri);
} catch (Exception e){
bmp = assets.getIconFromDrawable(icon);
}
Log.d(TAG, "getLargeIcon(): bmp = "+ bmp);

return bmp;
}
}
Loading