Chrome Custom Tabsを優先するかどうかをアプリ設定で選択可能にした

This commit is contained in:
tateisu 2017-06-02 09:21:50 +09:00
parent 25d57b166f
commit 7cdf582439
10 changed files with 100 additions and 71 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 25
versionCode 75
versionName "0.7.5"
versionCode 76
versionName "0.7.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -92,7 +92,7 @@ public class ActAppSetting extends AppCompatActivity
Switch swDontScreenOff;
Switch swDisableTabletMode;
Switch swDontCropMediaThumb;
Switch swPriorChrome;
Spinner spBackButtonAction;
Spinner spUITheme;
@ -169,6 +169,8 @@ public class ActAppSetting extends AppCompatActivity
swDontCropMediaThumb = (Switch) findViewById( R.id.swDontCropMediaThumb );
swDontCropMediaThumb.setOnCheckedChangeListener( this );
swPriorChrome = (Switch) findViewById( R.id.swPriorChrome );
swPriorChrome.setOnCheckedChangeListener( this );
cbNotificationSound = (CheckBox) findViewById( R.id.cbNotificationSound );
cbNotificationVibration = (CheckBox) findViewById( R.id.cbNotificationVibration );
@ -234,15 +236,13 @@ public class ActAppSetting extends AppCompatActivity
}
{
AccountAdapter adapter = new AccountAdapter();
spDefaultAccount = (Spinner) findViewById( R.id.spDefaultAccount );
spDefaultAccount.setAdapter( adapter );
spDefaultAccount.setOnItemSelectedListener( this );
}
findViewById( R.id.btnFooterBackgroundEdit ).setOnClickListener( this );
findViewById( R.id.btnFooterBackgroundReset ).setOnClickListener( this );
findViewById( R.id.btnFooterForegroundColorEdit ).setOnClickListener( this );
@ -253,14 +253,13 @@ public class ActAppSetting extends AppCompatActivity
findViewById( R.id.btnTabDividerColorReset ).setOnClickListener( this );
findViewById( R.id.btnTabIndicatorColorEdit ).setOnClickListener( this );
findViewById( R.id.btnTabIndicatorColorReset ).setOnClickListener( this );
findViewById( R.id.btnTimelineFontEdit ).setOnClickListener( this );
findViewById( R.id.btnTimelineFontReset ).setOnClickListener( this );
findViewById( R.id.btnSettingExport ).setOnClickListener( this );
findViewById( R.id.btnSettingImport ).setOnClickListener( this );
findViewById( R.id.btnCustomStreamListenerEdit ).setOnClickListener( this );
findViewById( R.id.btnCustomStreamListenerReset ).setOnClickListener( this );
ivFooterToot = (ImageView) findViewById( R.id.ivFooterToot );
ivFooterMenu = (ImageView) findViewById( R.id.ivFooterMenu );
@ -285,7 +284,6 @@ public class ActAppSetting extends AppCompatActivity
swDontConfirmBeforeCloseColumn.setChecked( pref.getBoolean( Pref.KEY_DONT_CONFIRM_BEFORE_CLOSE_COLUMN, false ) );
swPriorLocalURL.setChecked( pref.getBoolean( Pref.KEY_PRIOR_LOCAL_URL, false ) );
swDisableFastScroller.setChecked( pref.getBoolean( Pref.KEY_DISABLE_FAST_SCROLLER, true ) );
swSimpleList.setChecked( pref.getBoolean( Pref.KEY_SIMPLE_LIST, false ) );
swExitAppWhenCloseProtectedColumn.setChecked( pref.getBoolean( Pref.KEY_EXIT_APP_WHEN_CLOSE_PROTECTED_COLUMN, false ) );
swShowFollowButtonInButtonBar.setChecked( pref.getBoolean( Pref.KEY_SHOW_FOLLOW_BUTTON_IN_BUTTON_BAR, false ) );
@ -296,6 +294,10 @@ public class ActAppSetting extends AppCompatActivity
swDisableTabletMode.setChecked( pref.getBoolean( Pref.KEY_DISABLE_TABLET_MODE, false ) );
swDontCropMediaThumb.setChecked( pref.getBoolean( Pref.KEY_DONT_CROP_MEDIA_THUMBNAIL, false ) );
// Switch with default true
swDisableFastScroller.setChecked( pref.getBoolean( Pref.KEY_DISABLE_FAST_SCROLLER, true ) );
swPriorChrome.setChecked( pref.getBoolean( Pref.KEY_PRIOR_CHROME, true ) );
cbNotificationSound.setChecked( pref.getBoolean( Pref.KEY_NOTIFICATION_SOUND, true ) );
cbNotificationVibration.setChecked( pref.getBoolean( Pref.KEY_NOTIFICATION_VIBRATION, true ) );
cbNotificationLED.setChecked( pref.getBoolean( Pref.KEY_NOTIFICATION_LED, true ) );
@ -306,7 +308,7 @@ public class ActAppSetting extends AppCompatActivity
spRefreshAfterToot.setSelection( pref.getInt( Pref.KEY_REFRESH_AFTER_TOOT, 0 ) );
spDefaultAccount.setSelection(
((AccountAdapter)spDefaultAccount.getAdapter()).getIndexFromId( pref.getLong( Pref.KEY_TABLET_TOOT_DEFAULT_ACCOUNT, -1L ))
( (AccountAdapter) spDefaultAccount.getAdapter() ).getIndexFromId( pref.getLong( Pref.KEY_TABLET_TOOT_DEFAULT_ACCOUNT, - 1L ) )
);
footer_button_bg_color = pref.getInt( Pref.KEY_FOOTER_BUTTON_BG_COLOR, 0 );
@ -341,7 +343,7 @@ public class ActAppSetting extends AppCompatActivity
.putBoolean( Pref.KEY_DONT_SCREEN_OFF, swDontScreenOff.isChecked() )
.putBoolean( Pref.KEY_DISABLE_TABLET_MODE, swDisableTabletMode.isChecked() )
.putBoolean( Pref.KEY_DONT_CROP_MEDIA_THUMBNAIL, swDontCropMediaThumb.isChecked() )
.putBoolean( Pref.KEY_PRIOR_CHROME, swPriorChrome.isChecked() )
.putBoolean( Pref.KEY_NOTIFICATION_SOUND, cbNotificationSound.isChecked() )
.putBoolean( Pref.KEY_NOTIFICATION_VIBRATION, cbNotificationVibration.isChecked() )
@ -357,14 +359,13 @@ public class ActAppSetting extends AppCompatActivity
.putInt( Pref.KEY_FOOTER_TAB_BG_COLOR, footer_tab_bg_color )
.putInt( Pref.KEY_FOOTER_TAB_DIVIDER_COLOR, footer_tab_divider_color )
.putInt( Pref.KEY_FOOTER_TAB_INDICATOR_COLOR, footer_tab_indicator_color )
.putLong( Pref.KEY_TABLET_TOOT_DEFAULT_ACCOUNT,((AccountAdapter)spDefaultAccount.getAdapter())
.getIdFromIndex(spDefaultAccount.getSelectedItemPosition() ) )
.putLong( Pref.KEY_TABLET_TOOT_DEFAULT_ACCOUNT, ( (AccountAdapter) spDefaultAccount.getAdapter() )
.getIdFromIndex( spDefaultAccount.getSelectedItemPosition() ) )
.putString( Pref.KEY_TIMELINE_FONT, timeline_font )
.putString( Pref.KEY_COLUMN_WIDTH, etColumnWidth.getText().toString().trim() )
.putString( Pref.KEY_MEDIA_THUMB_HEIGHT, etMediaThumbHeight.getText().toString().trim() )
.apply();
@ -392,7 +393,7 @@ public class ActAppSetting extends AppCompatActivity
switch( v.getId() ){
case R.id.btnFooterBackgroundEdit:
openColorPicker( COLOR_DIALOG_ID_FOOTER_BUTTON_BG, footer_button_bg_color ,false);
openColorPicker( COLOR_DIALOG_ID_FOOTER_BUTTON_BG, footer_button_bg_color, false );
break;
case R.id.btnFooterBackgroundReset:
@ -402,7 +403,7 @@ public class ActAppSetting extends AppCompatActivity
break;
case R.id.btnFooterForegroundColorEdit:
openColorPicker( COLOR_DIALOG_ID_FOOTER_BUTTON_FG, footer_button_fg_color ,false);
openColorPicker( COLOR_DIALOG_ID_FOOTER_BUTTON_FG, footer_button_fg_color, false );
break;
case R.id.btnFooterForegroundColorReset:
@ -412,7 +413,7 @@ public class ActAppSetting extends AppCompatActivity
break;
case R.id.btnTabBackgroundColorEdit:
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_BG, footer_tab_bg_color ,false);
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_BG, footer_tab_bg_color, false );
break;
case R.id.btnTabBackgroundColorReset:
@ -422,7 +423,7 @@ public class ActAppSetting extends AppCompatActivity
break;
case R.id.btnTabDividerColorEdit:
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_DIVIDER, footer_tab_divider_color ,false);
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_DIVIDER, footer_tab_divider_color, false );
break;
case R.id.btnTabDividerColorReset:
@ -432,7 +433,7 @@ public class ActAppSetting extends AppCompatActivity
break;
case R.id.btnTabIndicatorColorEdit:
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_INDICATOR, footer_tab_indicator_color ,true);
openColorPicker( COLOR_DIALOG_ID_FOOTER_TAB_INDICATOR, footer_tab_indicator_color, true );
break;
case R.id.btnTabIndicatorColorReset:
@ -469,17 +470,17 @@ public class ActAppSetting extends AppCompatActivity
case R.id.btnCustomStreamListenerEdit:
ActCustomStreamListener.open( this );
break;
case R.id.btnCustomStreamListenerReset:
pref
.edit()
.remove(Pref.KEY_STREAM_LISTENER_CONFIG_URL)
.remove( Pref.KEY_STREAM_LISTENER_SECRET)
.remove( Pref.KEY_STREAM_LISTENER_CONFIG_DATA)
.remove( Pref.KEY_STREAM_LISTENER_CONFIG_URL )
.remove( Pref.KEY_STREAM_LISTENER_SECRET )
.remove( Pref.KEY_STREAM_LISTENER_CONFIG_DATA )
.apply();
SavedAccount.clearRegistrationCache();
AlarmService.startCheck( this );
Utils.showToast( this,false,getString(R.string.custom_stream_listener_was_reset) );
Utils.showToast( this, false, getString( R.string.custom_stream_listener_was_reset ) );
break;
}
}
@ -509,7 +510,7 @@ public class ActAppSetting extends AppCompatActivity
super.onActivityResult( requestCode, resultCode, data );
}
void openColorPicker( int id, int color ,boolean bShowAlphaSlider ){
void openColorPicker( int id, int color, boolean bShowAlphaSlider ){
ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder()
.setDialogType( ColorPickerDialog.TYPE_CUSTOM )
.setAllowPresets( true )
@ -789,12 +790,12 @@ public class ActAppSetting extends AppCompatActivity
private class AccountAdapter extends BaseAdapter {
final ArrayList<SavedAccount> list = new ArrayList<>( );
final ArrayList< SavedAccount > list = new ArrayList<>();
AccountAdapter(){
for( SavedAccount a : SavedAccount.loadAccountList( log ) ){
if( a.isPseudo() ) continue;
list.add(a);
list.add( a );
}
Collections.sort( list, new Comparator< SavedAccount >() {
@Override
@ -806,11 +807,11 @@ public class ActAppSetting extends AppCompatActivity
}
@Override public int getCount(){
return 1+list.size();
return 1 + list.size();
}
@Override public Object getItem( int position ){
return position == 0 ? null : list.get(position-1);
return position == 0 ? null : list.get( position - 1 );
}
@Override public long getItemId( int position ){
@ -818,31 +819,33 @@ public class ActAppSetting extends AppCompatActivity
}
@Override public View getView( int position, View view, ViewGroup parent ){
if( view == null ) view = getLayoutInflater().inflate( android.R.layout.simple_spinner_item,parent,false );
((TextView)view.findViewById(android.R.id.text1 )).setText(
position == 0 ? getString(R.string.ask_always) : AcctColor.getNickname( list.get(position-1).acct )
if( view == null )
view = getLayoutInflater().inflate( android.R.layout.simple_spinner_item, parent, false );
( (TextView) view.findViewById( android.R.id.text1 ) ).setText(
position == 0 ? getString( R.string.ask_always ) : AcctColor.getNickname( list.get( position - 1 ).acct )
);
return view;
}
@Override public View getDropDownView( int position, View view, ViewGroup parent ){
if( view ==null ) view = getLayoutInflater().inflate( R.layout.lv_spinner_dropdown,parent,false );
((TextView)view.findViewById(android.R.id.text1 )).setText(
position == 0 ? getString(R.string.ask_always) : AcctColor.getNickname( list.get(position-1).acct )
if( view == null )
view = getLayoutInflater().inflate( R.layout.lv_spinner_dropdown, parent, false );
( (TextView) view.findViewById( android.R.id.text1 ) ).setText(
position == 0 ? getString( R.string.ask_always ) : AcctColor.getNickname( list.get( position - 1 ).acct )
);
return view;
}
int getIndexFromId( long db_id ){
for( int i=0,ie=list.size();i<ie;++i){
if( list.get(i).db_id == db_id ) return i+1;
for( int i = 0, ie = list.size() ; i < ie ; ++ i ){
if( list.get( i ).db_id == db_id ) return i + 1;
}
return 0;
}
long getIdFromIndex( int position ){
if( position > 0 ) return list.get( position -1).db_id;
return -1L;
if( position > 0 ) return list.get( position - 1 ).db_id;
return - 1L;
}
}
}

View File

@ -1531,24 +1531,29 @@ public class ActMain extends AppCompatActivity
}
}
try{
// 初回はChrome指定で試す
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor( Styler.getAttributeColor( this, R.attr.colorPrimary ) ).setShowTitle( true );
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setComponent( new ComponentName( "com.android.chrome", "com.google.android.apps.chrome.Main" ) );
customTabsIntent.launchUrl( this, Uri.parse( url ) );
}catch( Throwable ex2 ){
log.e( ex2, "openChromeTab: missing chrome. retry to other application." );
do{
if( pref.getBoolean( Pref.KEY_PRIOR_CHROME,true )){
try{
// 初回はChrome指定で試す
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor( Styler.getAttributeColor( this, R.attr.colorPrimary ) ).setShowTitle( true );
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setComponent( new ComponentName( "com.android.chrome", "com.google.android.apps.chrome.Main" ) );
customTabsIntent.launchUrl( this, Uri.parse( url ) );
break;
}catch( Throwable ex2 ){
log.e( ex2, "openChromeTab: missing chrome. retry to other application." );
}
}
// chromeがないなら ResolverActivity でアプリを選択させる
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor( Styler.getAttributeColor( this, R.attr.colorPrimary ) ).setShowTitle( true );
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl( this, Uri.parse( url ) );
}
}while(false);
}catch( Throwable ex ){
// ex.printStackTrace();
log.e( ex, "openChromeTab failed. url=%s", url );

View File

@ -295,6 +295,7 @@ public class AppDataExporter {
case Pref.KEY_DONT_SCREEN_OFF:
case Pref.KEY_DISABLE_TABLET_MODE:
case Pref.KEY_DONT_CROP_MEDIA_THUMBNAIL:
case Pref.KEY_PRIOR_CHROME:
boolean bv = reader.nextBoolean();
e.putBoolean( k, bv );
break;

View File

@ -2532,25 +2532,24 @@ class Column implements StreamReader.Callback {
@Override public void onStreamingMessage( String event_type, Object o ){
if( is_dispose.get() ) return;
if( o instanceof Long ){
removeStatus( access_info, (Long) o );
return;
if( "delete".equals( event_type ) ){
if( o instanceof Long ){
removeStatus( access_info, (Long) o );
}
}else{
if( o instanceof TootNotification ){
TootNotification notification = (TootNotification) o;
if( column_type != TYPE_NOTIFICATIONS ) return;
if( isFiltered( notification ) ) return;
}else if( o instanceof TootStatus ){
TootStatus status = (TootStatus) o;
if( column_type == TYPE_NOTIFICATIONS ) return;
if( column_type == TYPE_LOCAL && status.account.acct.indexOf( '@' ) != - 1 ) return;
if( isFiltered( status ) ) return;
}
stream_data_queue.addFirst( o );
proc_stream_data.run();
}
if( o instanceof TootNotification ){
TootNotification notification = (TootNotification) o;
if( column_type != TYPE_NOTIFICATIONS ) return;
if( isFiltered( notification ) ) return;
}else if( o instanceof TootStatus ){
TootStatus status = (TootStatus) o;
if( column_type == TYPE_NOTIFICATIONS ) return;
if( column_type == TYPE_LOCAL && status.account.acct.indexOf( '@' ) != - 1 ) return;
if( isFiltered( status ) ) return;
}
stream_data_queue.addFirst( o );
proc_stream_data.run();
}
// onPauseの時はまとめて止められるが

View File

@ -56,5 +56,7 @@ public class Pref {
static final String KEY_STREAM_LISTENER_CONFIG_DATA = "stream_listener_config_data";
static final String KEY_TABLET_TOOT_DEFAULT_ACCOUNT = "tablet_toot_default_account";
static final String KEY_PRIOR_CHROME = "prior_chrome";
// 項目を追加したらAppDataExporter#importPref のswitch文も更新すること
}

View File

@ -191,6 +191,22 @@
<View style="@style/setting_divider"/>
<TextView
style="@style/setting_row_label"
android:text="@string/prior_chrome_custom_tabs"
/>
<LinearLayout style="@style/setting_row_form">
<Switch
android:id="@+id/swPriorChrome"
style="@style/setting_horizontal_stretch"
/>
</LinearLayout>
<View style="@style/setting_divider"/>
<!-- =============================================== -->

View File

@ -353,8 +353,9 @@
<string name="toot_button_default_account">Default acount when toot button tapped</string>
<string name="account_change_failed_old_draft_has_no_in_reply_to_url">Account change failed. Old draft data has no in_reply_to_url, can\'t convert in_repley_to for selected instance.</string>
<string name="in_reply_to_id_conversion_failed">\"in_reply_to\" ID conversion failed.</string>
<string name="prior_chrome_custom_tabs">Prior Chrome Custom Tabs</string>
<!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>-->
<!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>-->
<!--<string name="abc_action_bar_home_description_format">%1$s, %2$s</string>-->
<!--<string name="abc_action_bar_home_subtitle_description_format">%1$s, %2$s, %3$s</string>-->
<!--<string name="abc_action_bar_up_description">Revenir en haut de la page</string>-->

View File

@ -640,5 +640,6 @@
<string name="toot_button_default_account">トゥートボタンを押した時のデフォルトアカウント</string>
<string name="account_change_failed_old_draft_has_no_in_reply_to_url">アカウント切り替えできません。古い下書きデータにはin_reply_to_urlがなくて、別タンスへの切り替えができません。</string>
<string name="in_reply_to_id_conversion_failed">アカウント切り替えできません。in_reply_toのID変換に失敗しました。</string>
<string name="prior_chrome_custom_tabs">Chrome Custom Tabs を優先的に利用する</string>
</resources>

View File

@ -349,4 +349,5 @@
<string name="toot_button_default_account">Default acount when toot button tapped</string>
<string name="account_change_failed_old_draft_has_no_in_reply_to_url">Account change failed. Old draft data has no in_reply_to_url, can\'t convert in_repley_to for selected instance.</string>
<string name="in_reply_to_id_conversion_failed">\"in_reply_to\" ID conversion failed.</string>
<string name="prior_chrome_custom_tabs">Prior Chrome Custom Tabs</string>
</resources>