@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_steprecording); // 手錶 String fromwear = getIntent().getStringExtra("reply"); if (fromwear == null) { Bundle remoteInput = RemoteInput.getResultsFromIntent(getIntent()); if (remoteInput != null) { fromwear = remoteInput.getCharSequence(Steprecording.EXTRA_VOICE_REPLY).toString(); Log.d("fromwear", fromwear); wearcontent = fromwear.split(" "); TAG_FROM_WEAR = true; } } TextView ss = (TextView) findViewById(R.id.textView6); Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); // 取得Bundle /*//是否來過 if(intent.hasExtra("TAG_BACK_TO_RECORDING")){ TAG_BACK_TO_RECORDING = true; Log.d("抓3","backtorecording"); }*/ TAG_CASE_NUMBER = bundle.getString("TAG_CASE_NUMBER"); TAG_STEP_NUMBER = bundle.getString("TAG_STEP_NUMBER"); TAG_STEP_ORDER = bundle.getInt("TAG_STEP_ORDER"); Log.d("StepRecording", TAG_STEP_NUMBER); // TAG_CASE_NUMBER = "15"; // TAG_STEP_NUMBER = "10"; // TAG_STEP_ORDER = 1; ss.setText(Integer.toString(TAG_STEP_ORDER)); // 是否來過 DatabaseHelper mDBACK = DatabaseHelper.getHelper(this); case_recordDao mcase_recordDao = new case_recordDao(); List<case_recordVo> listBACK = null; listBACK = mcase_recordDao.selectRaw( mDBACK, "Case_number=" + TAG_CASE_NUMBER + " and Step_order=" + TAG_STEP_ORDER); if (listBACK.size() != 0) { TAG_BACK_TO_RECORDING = true; } // Hashmap for ListView productsList = new ArrayList<HashMap<String, String>>(); // Loading products in Background Thread // new LoadInput().execute(); // SELECT record_order,record_text FROM step_record WHERE step_number='"+Stepnumber+"'" DatabaseHelper mDatabaseHelper = DatabaseHelper.getHelper(this); mstep_recordDao = new step_recordDao(); List<step_recordVo> list = null; list = mstep_recordDao.selectRaw(mDatabaseHelper, "Step_number =\"" + TAG_STEP_NUMBER + "\""); // Log.d("抓", list.get(0).getRecord_order()); // Log.d("抓2", list.get(0).getRecord_text()); count = list.size(); LinearLayout ly = (LinearLayout) findViewById(R.id.linearlayoutinput); for (int i = 0; i < count; i++) { TextView text1 = new TextView(Steprecording.this); text1.setText(list.get(i).getRecord_text() + "(" + list.get(i).getRecord_unit() + ")"); // 1數字2文字 if (Integer.valueOf(list.get(i).getRecord_type()) == 1) { text1.setText( text1.getText() + "(" + list.get(i).getRecord_min() + "~" + list.get(i).getRecord_max() + ")"); } edit1[i] = new EditText(Steprecording.this.getApplicationContext()); edit1[i].setTextColor(Color.rgb(0, 0, 0)); edit1[i].setOnFocusChangeListener(new MyOnFocusChangeListener()); edit1[i].setSingleLine(true); edit1[i].setBackgroundColor(Color.parseColor("#FDDCB9")); // #FEFBE6黃 if (TAG_FROM_WEAR) { if (i < wearcontent.length) { edit1[i].setText(wearcontent[i]); } } // edit1[0].setText("eee"); ly.addView(text1); ly.addView(edit1[i]); } goright = (ImageButton) findViewById(R.id.imageButton); goleft = (ImageButton) findViewById(R.id.imageButton2); detector = new GestureDetector(new MySimpleOnGestureListener()); ScrollView sv = (ScrollView) findViewById(R.id.scrollView); sv.setOnTouchListener(new MyOnTouchListener()); // LinearLayout llb = (LinearLayout)findViewById(R.id.linearLayoutbackground); // llb.setOnTouchListener(new MyOnTouchListener()); messageList = new ArrayList<>(); // 手錶 if (!TAG_BACK_TO_RECORDING) { String replyLabel = getResources().getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build(); // Create an intent for the reply action Intent replyIntent = new Intent(this, Steprecording.class); Bundle wb = new Bundle(); wb.putString("TAG_CASE_NUMBER", TAG_CASE_NUMBER); wb.putString("TAG_STEP_NUMBER", TAG_STEP_NUMBER); wb.putInt("TAG_STEP_ORDER", TAG_STEP_ORDER); replyIntent.putExtras(wb); // replyIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action.Builder( R.drawable.cast_ic_notification_0, getString(R.string.reply_label), replyPendingIntent) .addRemoteInput(remoteInput) .build(); // Create builder for the main notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Step" + Integer.toString(TAG_STEP_ORDER)) .setContentText("紀錄項(請往左滑):"); /* // Create a big text style for the second page NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.setBigContentTitle("Page 2") .bigText("A lot of text..."); // Create second page notification Notification secondPageNotification = new NotificationCompat.Builder(this) .setStyle(secondPageStyle) .build(); */ List extras = new ArrayList(); for (int i = 0; i < count; i++) { NotificationCompat.BigTextStyle extraPageStyle = new NotificationCompat.BigTextStyle(); extraPageStyle .setBigContentTitle("第" + String.valueOf(i) + "項") .bigText(list.get(i).getRecord_text()); Notification extraPageNotification = new NotificationCompat.Builder(this).setStyle(extraPageStyle).build(); extras.add(extraPageNotification); } /* //如果要跳頁 Intent mainIntent = new Intent(this, MyDisplayActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); */ // Extend the notification builder with the second page Notification notification = notificationBuilder .extend(new NotificationCompat.WearableExtender().addPages(extras).addAction(action)) // .addPage(secondPageNotification)) // .addAction(android.R.drawable.ic_media_play, "Speak", mainPendingIntent) .build(); // Issue the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplication()); Random random = new Random(); int notificationId = random.nextInt(9999 - 1000) + 1000; notificationManager.notify(notificationId, notification); /* mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle connectionHint) { Log.d(TAG, "onConnected: " + connectionHint); } @Override public void onConnectionSuspended(int cause) { Log.d(TAG, "onConnectionSuspended: " + cause); } }) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.d(TAG, "onConnectionFailed: " + result); } }) .addApi(Wearable.API) .build(); mGoogleApiClient.connect(); sendNotification();*/ } }
private void createActions( Bundle extras, NotificationCompat.Builder mBuilder, Resources resources, String packageName, int notId) { Log.d(LOG_TAG, "create actions: with in-line"); String actions = extras.getString(ACTIONS); String jsondata = extras.getString("json"); if (actions != null) { try { JSONObject jsonobj = new JSONObject(jsondata); JSONArray actionsArray = new JSONArray(actions); ArrayList<NotificationCompat.Action> wActions = new ArrayList<NotificationCompat.Action>(); for (int i = 0; i < actionsArray.length(); i++) { int min = 1; int max = 2000000000; Random random = new Random(); int uniquePendingIntentRequestCode = random.nextInt((max - min) + 1) + min; Log.d(LOG_TAG, "adding action"); JSONObject action = actionsArray.getJSONObject(i); Log.d(LOG_TAG, "adding callback = " + action.getString(CALLBACK)); boolean foreground = action.optBoolean(FOREGROUND, true); boolean inline = action.optBoolean("inline", false); Intent intent = null; Log.d(LOG_TAG, "createActions=>type==isForeground: " + String.valueOf(foreground)); PendingIntent pIntent = null; if (inline) { Log.d( LOG_TAG, "Version: " + android.os.Build.VERSION.SDK_INT + " = " + android.os.Build.VERSION_CODES.M); if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) { Log.d(LOG_TAG, "push activity"); intent = new Intent(this, PushHandlerActivity.class); } else { Log.d(LOG_TAG, "push receiver"); intent = new Intent(this, BackgroundActionButtonHandler.class); } updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId); if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) { Log.d(LOG_TAG, "push activity for notId " + notId); pIntent = PendingIntent.getActivity( this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT); } else { Log.d(LOG_TAG, "push receiver for notId " + notId); pIntent = PendingIntent.getBroadcast( this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_ONE_SHOT); } } else if (foreground) { intent = new Intent(this, PushHandlerActivity.class); updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId); pIntent = PendingIntent.getActivity( this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); } else { Log.d( LOG_TAG, "createActions=>Handling Action for background " + jsonobj.getString("type")); if (jsonobj.getString("type").equals("nowRequests")) { Log.d(LOG_TAG, "createActions=>type==nowRequests "); intent = new Intent(this, BackgroundRestActionButtonHandler.class); } else { intent = new Intent(this, BackgroundActionButtonHandler.class); } updateIntent(intent, action.getString(CALLBACK), extras, foreground, notId); pIntent = PendingIntent.getBroadcast( this, uniquePendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); } NotificationCompat.Action.Builder actionBuilder = new NotificationCompat.Action.Builder( resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent); RemoteInput remoteInput = null; if (inline) { Log.d(LOG_TAG, "create remote input"); String replyLabel = "Enter your reply here"; remoteInput = new RemoteInput.Builder(INLINE_REPLY).setLabel(replyLabel).build(); actionBuilder.addRemoteInput(remoteInput); } NotificationCompat.Action wAction = actionBuilder.build(); wActions.add(actionBuilder.build()); if (inline) { mBuilder.addAction(wAction); } else { mBuilder.addAction( resources.getIdentifier(action.optString(ICON, ""), DRAWABLE, packageName), action.getString(TITLE), pIntent); } wAction = null; pIntent = null; } mBuilder.extend(new WearableExtender().addActions(wActions)); wActions.clear(); } catch (JSONException e) { // nope } } }