Translate

BTemplates.com

Powered by Blogger.

2017年9月13日水曜日

2017-09-13 到達点メモ


中間報告としてのメモ

//通知部分の作成

        NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_notification_clock)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                        RemoteViews customView = new RemoteViews(this.getPackageName(), R.layout.notification_layout);
        customView.setTextViewText(R.id.notification_title_id, "VoiceTimer");
        customView.setTextViewText(R.id.notification_text_id, mConstRParams.finish_button_name);

        Intent intent = new Intent(this, MyBroadcastReceiver.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setAction(FINISH_ACTION);

        int request_code = ACTING_REQUEST_CODE;
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this,request_code,intent, PendingIntent.FLAG_UPDATE_CURRENT);
mConstRParams.finish_button_name, pendingIntent);
        customView.setOnClickPendingIntent(R.id.notification_button_id,pendingIntent);
        mBuilder.setContent(customView);
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(mId, mBuilder.build());

//通知部分のレイアウトの作成

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView
        android:id="@+id/notification_icon_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"/>
    <TextView
        android:id="@+id/notification_title_id"
        android:textColor="@color/gradient_start_color"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/notification_icon_id"
        style="@android:style/TextAppearance.StatusBar.EventContent.Title" />
    <TextView
        android:id="@+id/notification_text_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/notification_icon_id"
        android:layout_below="@id/notification_title_id"
        style="@android:style/TextAppearance.StatusBar.EventContent" />
    <Button
        android:id="@+id/notification_button_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/notification_text_id"
        android:layout_below="@id/notification_title_id"/>
</LinearLayout>


これで、表示はめちゃくちゃだが、ロック画面でもアプリ操作をすることができる。
現状アイコンの表示ができないのと、普段の表示と変わるので
これで統一する必要がある。

参考サイト
AndroidのNotificationでカスタムViewの高さを広げる
Adding button action in custom notification
NotificationのUIをカスタマイズする


Vector画像をbitmapに変換する際に参考にしたサイト
Getting Bitmap from vector drawable


メモ事項として
・remotelayoutを使う場合でも、setSmallIconは定義しなくてはいけない
・layout_marginを使用した後に、layout_marginLeftは適応されない
・layout_toRightOf系はLinearLayoutでは使用できない。きちんとRelativeLayoutになっているか確認すること

形は大体見えてきたので、あとは通常時の表示と合わせるのと
停止ボタン以外をタップした場合は、アプリを立ち上げる処理を入れることをやればよい。
これで大体の処理は終わるはず。
今日はここまで

0 コメント:

コメントを投稿