- 「…」メニューから「通称と色と通知音」で通知音を指定すると、そのユーザによって発生して通知の音が変わります
This commit is contained in:
tateisu 2017-07-27 16:33:34 +09:00
parent 60b4d4dcb2
commit ad05badb95
13 changed files with 171 additions and 24 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 25
versionCode 105
versionName "1.0.5"
versionCode 106
versionName "1.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -159,7 +159,7 @@
<activity
android:name=".ActNickname"
android:label="@string/nickname_and_color"
android:label="@string/nickname_and_color_and_notification_sound"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
/>
<activity

View File

@ -267,10 +267,11 @@ public class ActAccountSetting extends AppCompatActivity
case R.id.btnOpenBrowser:
open_browser( "https://" + account.host + "/" );
break;
case R.id.btnUserCustom:
ActNickname.open( this, full_acct, REQUEST_CODE_ACCT_CUSTOMIZE );
ActNickname.open( this, full_acct, false, REQUEST_CODE_ACCT_CUSTOMIZE );
break;
case R.id.btnNotificationSoundEdit:
openNotificationSoundPicker();
break;

View File

@ -2,6 +2,8 @@ package jp.juggler.subwaytooter;
import android.app.Activity;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
@ -10,6 +12,7 @@ import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@ -22,10 +25,12 @@ import jp.juggler.subwaytooter.util.Utils;
public class ActNickname extends AppCompatActivity implements View.OnClickListener, ColorPickerDialogListener {
static final String EXTRA_ACCT = "acct";
static final String EXTRA_SHOW_NOTIFICATION_SOUND = "show_notification_sound";
public static void open( Activity activity, String full_acct, int requestCode ){
public static void open( Activity activity, String full_acct, boolean bShowNotificationSound, int requestCode ){
Intent intent = new Intent( activity, ActNickname.class );
intent.putExtra( EXTRA_ACCT, full_acct );
intent.putExtra( EXTRA_SHOW_NOTIFICATION_SOUND, bShowNotificationSound );
activity.startActivityForResult( intent, requestCode );
}
@ -34,16 +39,22 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
super.onBackPressed();
}
boolean show_notification_sound;
String acct;
int color_fg;
int color_bg;
String notification_sound_uri;
@Override protected void onCreate( @Nullable Bundle savedInstanceState ){
super.onCreate( savedInstanceState );
App1.setActivityTheme( this, false );
Intent intent = getIntent();
this.acct = intent.getStringExtra( EXTRA_ACCT );
this.show_notification_sound = intent.getBooleanExtra( EXTRA_SHOW_NOTIFICATION_SOUND ,false);
initUI();
this.acct = getIntent().getStringExtra( EXTRA_ACCT );
load();
}
@ -56,8 +67,12 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
View btnBackgroundColorReset;
View btnSave;
View btnDiscard;
Button btnNotificationSoundEdit;
Button btnNotificationSoundReset;
private void initUI(){
setTitle( getString( show_notification_sound ? R.string.nickname_and_color_and_notification_sound : R.string.nickname_and_color ) );
setContentView( R.layout.act_nickname );
Styler.fixHorizontalPadding(findViewById( R.id.llContent ));
@ -81,6 +96,12 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
btnSave.setOnClickListener( this );
btnDiscard.setOnClickListener( this );
btnNotificationSoundEdit = (Button) findViewById( R.id.btnNotificationSoundEdit );
btnNotificationSoundReset = (Button) findViewById( R.id.btnNotificationSoundReset );
btnNotificationSoundEdit.setOnClickListener( this );
btnNotificationSoundReset.setOnClickListener( this );
etNickname.addTextChangedListener( new TextWatcher() {
@Override
public void beforeTextChanged( CharSequence s, int start, int count, int after ){
@ -102,6 +123,8 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
private void load(){
bLoading = true;
findViewById( R.id.llNotificationSound ).setVisibility( show_notification_sound ? View.VISIBLE: View.GONE );
tvAcct.setText( acct );
AcctColor ac = AcctColor.load( acct );
@ -109,6 +132,7 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
color_bg = ac.color_bg;
color_fg = ac.color_fg;
etNickname.setText( ac.nickname == null ? "" : ac.nickname );
notification_sound_uri = ac.notification_sound;
}
bLoading = false;
@ -122,6 +146,7 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
,etNickname.getText().toString().trim()
,color_fg
,color_bg
,notification_sound_uri
).save( System.currentTimeMillis() );
}
@ -180,6 +205,15 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
setResult( RESULT_CANCELED );
finish();
break;
case R.id.btnNotificationSoundEdit:
openNotificationSoundPicker();
break;
case R.id.btnNotificationSoundReset:
notification_sound_uri = "";
break;
}
}
@ -197,4 +231,42 @@ public class ActNickname extends AppCompatActivity implements View.OnClickListen
@Override public void onDialogDismissed( int dialogId ){
}
private void openNotificationSoundPicker(){
Intent intent = new Intent( RingtoneManager.ACTION_RINGTONE_PICKER );
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION );
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TITLE, R.string.notification_sound );
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false );
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false );
try{
Uri uri = TextUtils.isEmpty( notification_sound_uri ) ? null : Uri.parse( notification_sound_uri );
if( uri != null ){
intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri );
}
}catch( Throwable ignored ){
}
Intent chooser = Intent.createChooser( intent, getString( R.string.notification_sound ) );
startActivityForResult( chooser, REQUEST_CODE_NOTIFICATION_SOUND );
}
static final int REQUEST_CODE_NOTIFICATION_SOUND = 2;
@Override protected void onActivityResult( int requestCode, int resultCode, Intent data ){
if( resultCode == RESULT_OK && requestCode == REQUEST_CODE_NOTIFICATION_SOUND ){
// RINGTONE_PICKERからの選択されたデータを取得する
Uri uri = (Uri) data.getExtras().get( RingtoneManager.EXTRA_RINGTONE_PICKED_URI );
if( uri != null ){
notification_sound_uri = uri.toString();
// Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), uri);
// TextView ringView = (TextView) findViewById(R.id.ringtone);
// ringView.setText(ringtone.getTitle(getApplicationContext()));
// ringtone.setStreamType(AudioManager.STREAM_ALARM);
// ringtone.play();
// SystemClock.sleep(1000);
// ringtone.stop();
}
}
super.onActivityResult( requestCode, resultCode, data );
}
}

View File

@ -38,6 +38,7 @@ import jp.juggler.subwaytooter.api.TootApiClient;
import jp.juggler.subwaytooter.api.TootApiResult;
import jp.juggler.subwaytooter.api.entity.TootNotification;
import jp.juggler.subwaytooter.api.entity.TootStatus;
import jp.juggler.subwaytooter.table.AcctColor;
import jp.juggler.subwaytooter.table.MutedApp;
import jp.juggler.subwaytooter.table.MutedWord;
import jp.juggler.subwaytooter.table.NotificationTracking;
@ -722,12 +723,26 @@ public class AlarmService extends IntentService {
int iv = 0;
if( pref.getBoolean( Pref.KEY_NOTIFICATION_SOUND, true ) ){
Uri sound_uri = null;
try{
String sv = account.sound_uri;
sound_uri = TextUtils.isEmpty( sv ) ? null : Uri.parse( sv );
String acct = item.access_info.getFullAcct( item.notification.account );
if( acct != null){
String sv = AcctColor.getNotificationSound( acct );
sound_uri = TextUtils.isEmpty( sv ) ? null : Uri.parse( sv );
}
}catch( Throwable ignored ){
}
if( sound_uri == null ){
try{
String sv = account.sound_uri;
sound_uri = TextUtils.isEmpty( sv ) ? null : Uri.parse( sv );
}catch( Throwable ignored ){
}
}
if( sound_uri != null ){
builder.setSound( sound_uri );
}else{

View File

@ -51,7 +51,7 @@ public class App1 extends Application {
static final LogCategory log = new LogCategory( "App1" );
static final String DB_NAME = "app_db";
static final int DB_VERSION = 16;
static final int DB_VERSION = 17;
public static final String FILE_PROVIDER_AUTHORITY = "jp.juggler.subwaytooter.FileProvider";
// 2017/4/25 v10 1=>2 SavedAccount に通知設定を追加
// 2017/4/25 v10 1=>2 NotificationTracking テーブルを追加
@ -67,6 +67,7 @@ public class App1 extends Application {
// 2017/5/25 v69 13=>14 SavedAccountに項目追加
// 2017/5/27 v73 14=>15 TagSetテーブルの追加
// 2017/7/22 v99 15=>16 SavedAccountに項目追加
// 2017/7/22 v106 16=>17 AcctColor に項目追加
private static DBOpenHelper db_open_helper;

View File

@ -429,7 +429,7 @@ class DlgContextMenu implements View.OnClickListener, View.OnLongClickListener {
case R.id.btnNickname:
if( who != null ){
ActNickname.open( activity, access_info.getFullAcct( who ), ActMain.REQUEST_CODE_NICKNAME );
ActNickname.open( activity, access_info.getFullAcct( who ), true, ActMain.REQUEST_CODE_NICKNAME );
}
break;

View File

@ -28,6 +28,7 @@ public class AcctColor {
private static final String COL_COLOR_FG = "cf"; // 未設定なら0それ以外は色
private static final String COL_COLOR_BG = "cb"; // 未設定なら0それ以外は色
private static final String COL_NICKNAME = "nick"; // 未設定ならnullか空文字列
private static final String COL_NOTIFICATION_SOUND = "notification_sound"; // 未設定ならnullか空文字列
public static void onDBCreate( SQLiteDatabase db ){
log.d( "onDBCreate!" );
@ -39,6 +40,7 @@ public class AcctColor {
+ "," + COL_COLOR_FG + " integer"
+ "," + COL_COLOR_BG + " integer"
+ "," + COL_NICKNAME + " text "
+ "," + COL_NOTIFICATION_SOUND + " text default ''"
+ ")"
);
db.execSQL(
@ -52,6 +54,15 @@ public class AcctColor {
public static void onDBUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ){
if( oldVersion < 9 && newVersion >= 9 ){
onDBCreate( db );
return;
}
if( oldVersion < 17 && newVersion >= 17 ){
try{
db.execSQL( "alter table " + table + " add column " + COL_NOTIFICATION_SOUND + " text default ''" );
}catch( Throwable ex ){
ex.printStackTrace();
}
}
}
@ -59,12 +70,14 @@ public class AcctColor {
public int color_fg;
public int color_bg;
public String nickname;
public String notification_sound ;
public AcctColor( @NonNull String acct, String nickname, int color_fg, int color_bg ){
public AcctColor( @NonNull String acct, String nickname, int color_fg, int color_bg ,String notification_sound){
this.acct = acct;
this.nickname = nickname;
this.color_fg = color_fg;
this.color_bg = color_bg;
this.notification_sound = notification_sound;
}
private AcctColor( @NonNull String acct ){
@ -82,6 +95,7 @@ public class AcctColor {
cv.put( COL_COLOR_FG, color_fg );
cv.put( COL_COLOR_BG, color_bg );
cv.put( COL_NICKNAME, nickname == null ? "" : nickname );
cv.put( COL_NOTIFICATION_SOUND, notification_sound == null ? "" : notification_sound );
App1.getDB().replace( table, null, cv );
mMemoryCache.remove( acct );
}catch( Throwable ex ){
@ -127,6 +141,9 @@ public class AcctColor {
idx = cursor.getColumnIndex( COL_NICKNAME );
dst.nickname = cursor.isNull( idx ) ? null : cursor.getString( idx );
idx = cursor.getColumnIndex( COL_NOTIFICATION_SOUND );
dst.notification_sound = cursor.isNull( idx ) ? null : cursor.getString( idx );
mMemoryCache.put( acct, dst );
return dst;
}
@ -149,6 +166,11 @@ public class AcctColor {
return ac != null && ! TextUtils.isEmpty( ac.nickname ) ? Utils.sanitizeBDI( ac.nickname ) : acct;
}
@Nullable public static String getNotificationSound( @NonNull String acct ){
AcctColor ac = load( acct );
return ac != null && ! TextUtils.isEmpty( ac.notification_sound ) ? ac.notification_sound : null;
}
public static boolean hasNickname( @Nullable AcctColor ac ){
return ac != null && ! TextUtils.isEmpty( ac.nickname );
}
@ -164,4 +186,5 @@ public class AcctColor {
public static void clearMemoryCache(){
mMemoryCache.evictAll ();
}
}

View File

@ -2,21 +2,20 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/llContent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingEnd="12dp"
android:paddingStart="12dp"
android:layout_marginTop="4dp"
android:text="@string/preview"
/>
@ -48,7 +47,6 @@
android:padding="12dp"
>
<View style="@style/setting_divider"/>
<TextView
@ -69,8 +67,8 @@
<TextView
style="@style/setting_row_label"
android:text="@string/nickname_label"
android:labelFor="@+id/etNickname"
android:text="@string/nickname"
/>
<LinearLayout style="@style/setting_row_form">
@ -141,6 +139,40 @@
<View style="@style/setting_divider"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llNotificationSound"
>
<TextView
style="@style/setting_row_label"
android:text="@string/notification_sound"
/>
<LinearLayout style="@style/setting_row_form">
<Button
android:id="@+id/btnNotificationSoundEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/edit"
android:textAllCaps="false"
/>
<Button
android:id="@+id/btnNotificationSoundReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:textAllCaps="false"
/>
</LinearLayout>
<View style="@style/setting_divider"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -451,7 +451,7 @@
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:text="@string/nickname_and_color"
android:text="@string/nickname_and_color_and_notification_sound"
android:textAllCaps="false"
/>

View File

@ -197,7 +197,8 @@
<string name="network_error">Erreur réseau.</string>
<string name="network_error_arg">Erreur réseau. %1$s</string>
<string name="nickname">Pseudonyme</string>
<string name="nickname_and_color">Pseudo et couleur</string>
<string name="nickname_and_color_and_notification_sound">Pseudo, Couleur, Notification sound</string>
<string name="nickname_and_color">Pseudo et Couleur</string>
<string name="nickname_applied_after_reload">Le changement de pseudo/couleur sera appliqué après actualisation.</string>
<string name="nickname_label">Pseudo et couleur. (s\'il est spécifié, il remplacera le nom du compte affiché)</string>
<string name="not_available_for_pseudo_account">Non disponible pour les personnes non connectés</string>
@ -325,7 +326,7 @@
<string name="app_data_export">Exporter les données de Subway Tooter</string>
<string name="app_data_import">Importer les données dans Subway Tooter</string>
<string name="app_data_import_confirm">Toutes les données actuelles seront remplacées lors de l\'importation.\nÊtes-vous sur ?</string>
<string name="app_data_import_desc">Vous pouvez exporter les données vers toute application qui pourra les recevoir. L\'importation ne peut s\'effectuer que depuis le stockage de votre appareil ou Google Drive !</string>
<string name="app_data_import_desc">Vous pouvez exporter les données vers toute application qui pourra les recevoir. L\'importation ne peut s\'effectuer que depuis le stockage de votre appareil ou Google Drive !\nColumn background image may be not exported/imported over device.\nTimeline font is not exported/imported.\nCustom notification sound may be not exported/imported over device.</string>
<string name="user_id_conversion_failed">Conversion de l\'identification utilisateur échouée.</string>
<string name="draft_deleted">Brouillon effacé !</string>

View File

@ -450,7 +450,7 @@
<!---->
<string name="edit">編集</string>
<!---->
<string name="nickname"></string>
<string name="nickname">通称</string>
<!---->
<string name="nickname_label">通称と色 (指定するとAcctの代わりに表示されます)</string>
<!---->
@ -462,6 +462,7 @@
<!---->
<string name="text_color">文字色</string>
<!---->
<string name="nickname_and_color_and_notification_sound">通称と色と通知音</string>
<string name="nickname_and_color">通称と色</string>
<!---->
<string name="nickname_applied_after_reload">通称と色の変更はカラムをリロードした後に反映されます</string>
@ -613,7 +614,7 @@
<string name="app_data_export">アプリデータのエクスポート</string>
<string name="app_data_import">アプリデータのインポート</string>
<string name="app_data_import_confirm">アプリに今あるデータは消えてしまいます。よろしいですか?</string>
<string name="app_data_import_desc">エクスポート先はいくつか選べますが、インポートするには端末のストレージかGoogleドライブにデータを置く必要があります。カラム背景画像とタイムラインのフォントはエクスポート/インポートの対象外です。</string>
<string name="app_data_import_desc">エクスポート先はいくつか選べますが、インポートするには端末のストレージかGoogleドライブにデータを置く必要があります。カラム背景画像、タイムラインのフォント、カスタム通知音はエクスポート/インポートの対象外です。</string>
<string name="user_id_conversion_failed">ユーザIDを変換できません</string>
<string name="draft_deleted">下書きを削除しました</string>
<string name="draft_picker_desc">長押しで削除</string>

View File

@ -233,6 +233,7 @@
<string name="background_color">Background color</string>
<string name="save">Save</string>
<string name="discard">Discard</string>
<string name="nickname_and_color_and_notification_sound">Nickname, Color, Notification sound</string>
<string name="nickname_and_color">Nickname and Color</string>
<string name="nickname_applied_after_reload">The change of nickname/color will be applied after reload column.</string>
<string name="show_follow_button_in_button_bar">Show follow button in button bar (app restart required)</string>
@ -321,7 +322,7 @@
<string name="attachment_in_draft_is_lost">Some of media attachment in the draft have been lost.</string>
<string name="app_data_export">Export app data</string>
<string name="app_data_import">Import app data</string>
<string name="app_data_import_desc">You can export data to any app that can receive data, But maybe you can import data only from device\'s storage or Google drive.\nColumn background image may be not exported/imported over device.\nTimeline font is not exported/imported.</string>
<string name="app_data_import_desc">You can export data to any app that can receive data, But maybe you can import data only from device\'s storage or Google drive.\nColumn background image may be not exported/imported over device.\nTimeline font is not exported/imported.\nCustom notification sound may be not exported/imported over device.</string>
<string name="app_data_import_confirm">existing data ( before import ) will be cleared. Are you sure?</string>
<string name="user_id_conversion_failed">User id conversion failed.</string>
<string name="draft_picker_desc">Long tap to delete.</string>