2015/10/06

ChromeでGmailやYouTubeなどGoogleのサービスが重いときの対処方法

最近ChromeからGmailやYouTubeなどGoogleのサービスが重かったり繋がらなかったりすることが多かったのでいろいろ調べた結果、chrome://flags/ からQUICプロトコルを無効にしたらあっさり解決した。

ChromeでのGoogleサービスが遅い - Google プロダクト フォーラム
https://productforums.google.com/forum/#!topic/chrome-ja/HCoHi6O0j-0


Google、高速プロトコル「QUIC」をChromeとモバイルのデフォルトに - ITmedia ニュース
http://www.itmedia.co.jp/news/articles/1504/20/news046.html

どうやらアップデートでQUICというプロトコルに勝手に切り替わっていたようです。

高速どころか遅くなったり繋がらなくなったりしたんですが…
自動アップデートだとなかなか気づかないよなあ。

2015/09/01

Activityの二重起動を防止する

Activityを起動するようにしてあるボタンを連打したとき、Activityが2つぐらい開いてしまうのを防ぎたい。

AndroidManifestで起動するactivity内に
android:launchMode="singleTask"
を追加する。

2015/04/28

WebViewのテキスト選択を無効にする

Javascriptでも無効にできるみたいですがJavaのコードで無効にしてみました。
WebView webView = new WebView(this);
webView.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        return true;
    }
});
webView.setLongClickable(false);

2015/04/24

Preferenceのマテリアルデザイン

AppCompat_v7 ver.21以上を導入しマテリアルデザインにしてプリファレンスにtoolbarを使う場合、
継承をActionBarActivityにしてtoolbarやFragmentを含んだlayoutをsetContentViewする。

継承がPreferenceActivityだとマテリアルデザインのチェックボックスの色などを変更した
スタイルが反映されなかった。

追記:ver.22からActionBarActivityが非奨励になりAppCompatActivityというものが導入されました。 そのまま置き換えたところ問題なく動きました。

preference_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        layout="@layout/settings_toolbar" />

    <fragment
        android:id="@+id/settings_fragment"
        android:name="com.sample.PrefFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar" />

</RelativeLayout>


settings_toolbar.xml
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:navigationContentDescription="@string/abc_action_bar_up_description"
    android:background="?attr/colorPrimary"
    app:navigationIcon="?attr/homeAsUpIndicator"
    app:title="@string/menu_setting" />


Preference.java
public class Preference extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preference_layout);

        //ツールバーを表示
        Toolbar actionbar = (Toolbar) findViewById(R.id.toolbar);
        actionbar.setTitle(getString(R.string.menu_setting));
        actionbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

2015/04/15

There are unrecoverable errors which must be corrected first.

Google Play services をインストールしていないと出る模様。

SDK Managerを起動させて、Eclipseのときと同じように
Extrasにある Google Play services にチェックしてインストールする。

ただ、Eclipseで使用したものと同じものをインストールすることになるので
Android Studioで使用するAndroid SDKをEclipseで使用していた場所に
変更することにした。

変更方法
[ファイル]⇒[Other Settings]⇒[Default Project Structure]で
Android SDK locationを変更する。

また、この変更によってEclipseで作ったGoogle Play servicesのライブラリを使用している
Android projectのインポートがすんなりできた。