この記事の内容は、次のページに移動しました。 Java における byte 型について (あるいはバイナリデータを扱うためのキャスト) - ひだまりソケットは壊れない
この記事の内容は、次のページに移動しました。 Java における byte 型について (あるいはバイナリデータを扱うためのキャスト) - ひだまりソケットは壊れない
View クラスのメソッドで位置やサイズを取得するメソッドがいくつかあるので紹介します。 ■ getLocationInWindow(int[] location) ウィンドウ上でのこの View の位置を計算します。引数は長さが2以上の int 配列で、Index 0 に x 座標、Index 1 に y 座標の値が入ります。 http://tools.oesf.biz/android-4.0.1_r1.0/xref/frameworks/base/core/java/android/view/View.java#12047 12047 public void getLocationInWindow(int[] location) { 12048 if (location == null || location.length < 2) { 12049 throw new IllegalA
マルチタッチを使って、タッチしたところに赤色と青色の丸を描画するサンプルを作ってみました。 画面をタッチすると、赤や青の丸が描画される。(イメージ) タッチしたまま移動すると、丸もそれに合わせて移動する(イメージ) 画面から手を放すと丸が消えてしまう(イメージ) マルチタッチを使うには、onTouchEvent()内の処理を以下のようにします。 public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); int index = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; int eventID = event.getPointerId(index)
名前:kenken 装備:革の服 武器:ひのきの棒 Lv:13 職業:旅人になりたい 初心者のためご指摘等歓迎です また質問も随時受け付けております 今回はタッチの応用系マルチタッチイベントです マルチタッチとはその名の通り2点以上を同時にタッチしたものを検出することです Androidでは 2.0(API 5)以降でマルチタッチがサポートされ使用可能です それぞれの発生イベント一覧 ACTION_DOWN: タッチパネルがまだタッチされていない状態で、タッチパネルを押した場合 ACTION_MOVE: タッチパネルを押したままスライドさせた場合 ACTION_POINTER_DOWN: タッチパネルの一箇所以上をタッチしている状態で、さらにタッチパネルを押した場合 ACTION_POINTER_UP: タッチパネルの二箇所以上をタッチしている状態で、うち一箇所を離した場合 ACTION_
自分のアプリから Intent で別のアプリに飛ぶと onPause() が呼ばれて別のアプリが foreground に来ます。ここから自分のアプリに戻る場合、background にいる時間が短かったり他のアプリがメモリを要求しなければ onResume() が呼ばれて、Intent が呼ばれる前の画面の状態に戻れます。 しかし、Activity が長時間表示されなかったり、別のアプリがメモリを要求したりすると、自分のアプリに戻ったときに、前の画面の状態にはなりません。この場合に前の画面の状態にするには、その状態を意識的に保存する必要があります。 では、どうやって保存するのか、 1.タイミング onSaveInstanceState(Bundle) で保存し、 onRestoreInstanceState(Bundle) で読み出します。 こんな感じ @Override protect
画面の向きはAndroidManifest.xml内でActivityに対してandroid:screenOrientationで設定します。 <!-- ScreenOrientationSample --> <activity android:name="android.wiki.sample.ScreenOrientationSampleActivity" android:label="@string/app_name" android:screenOrientation="unspecified"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filte
android.app.AlertDialog 画面上にダイアログを表示させるAlertDialogの使い方を紹介します。 以下の手順でダイアログを表示します。 AlertDialog.Builderを作成 AlertDialog.Builderに表示内容や挙動を設定(詳細はAlertDialog.Builderを参照) AlertDialog.Builderのcreate()メソッドを呼び出し、AlertDialogを作成 AlertDialogのshow()メソッドでダイアログを表示 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final AlertDialog.Builder
How to change the orientation of the activity. Androidのアプリケーション(Activity)は画面の向き(縦・横)を設定できます。 設定する方法はいくつかあります。 1.マニフェスト(AndroidManifest.xml)のandroid:screenOrientationに設定する 2.ActivityのsetRequestedOrientationで設定する 今回は「2.ActivityのsetRequestedOrientationで設定する」の方法で画面の向きを自由に変更するアプリケーションを作ってみます。 (パーミッションは不要なのでマニフェストは省略します) レイアウト(main.xml) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=
Androidプログラマへの道 〜 Moonlight 明日香 〜 C/C++プログラマの管理者が, Androidプログラムにチャレンジ. AndroidプログラミングのTipsをメモっていく予定です. トップページページ一覧メンバー編集 画面の向きを取得する 最終更新: moonlight_aska 2011年09月17日(土) 23:15:51履歴 Tweet 現在の画面の向きを取得するには, コンフィギュレーション(Configuration)クラスを利用する. 画面向きの取得 getResourcesメソッドで, Resourcesクラスのインスタンスを取得する. Resources#getConfigurationメソッドで, Configurationクラスのインスタンスを取得する. Configuration.orientationフィールドを調べる. package co
端末の液晶画面は基本的に長方形です。アプリによっては端末の向きを変えることで、縦長のポートレートモード(portrait)と横長のランドスケープモード(landscape)でレイアウトが変わるものや、向きを変えてもレイアウトが固定されているものがあります。 例えば、エミュレータの電話アプリでは下記の画像のように、ポートレートとランドスケープでレイアウトが変わります。 エミュレータで端末(画面)の向きを変える場合は「CTRL + F11」を押してください。 それでは、実際に横向き用、縦向き用のレイアウトを用意したい場合にどのようにしたらよいかなどを続きで説明します。 layout-landフォルダ res以下にlayout-landフォルダを準備します。 ですがその前に、まず準備しないとどうなるか試してみましょう。以下のようなレイアウトファイルを準備します。 main.xml <pre><?
Androidプログラマへの道 〜 Moonlight 明日香 〜 C/C++プログラマの管理者が, Androidプログラムにチャレンジ. AndroidプログラミングのTipsをメモっていく予定です. トップページページ一覧メンバー編集 加速度センサーの値を取得する 最終更新: moonlight_aska 2013年07月07日(日) 10:27:44履歴 Tweet 加速度センサーは, 物が動くときに働く加速度(重力の影響あり)を測定するセンサーである. Androidの加速度センサーでは, 以下のようにx, y, z軸の加速度(m/s^2)を取得できる. x軸 : 端末の右側から受ける加速度 y軸 : 端末の上部から受ける加速度 z軸 : 端末の正面から受ける加速度 加速度センサー値の取得 Sensor02.java センサーイベントを取得するために, SensorEventLi
2009年9月30日水曜日 XMLで自作のViewを使う為に androidSDKのXMLデザイナはとても便利。XMLでGUIデザインするときれいにすばやく出来るのでありがたいです。自作のViewをXMLでレイアウトして使うのに手間取ったのでメモ。 View側 Viewを継承したクラスを作成します。ここではViewを継承した自作ViewクラスをTestView.java パッケージをcom.testとします。 TestView.java側 以下のXMLで読み込まれるときのためのコンストラクタを記述します。普通のコンストラクタの下でいいかと。 /** * xml用コンストラクタ * @param context * @param attrs */ public AllowView(Context context, AttributeSet attrs) { super(
layout.xmlではstyle属性でStyleを適用できるが、ソース内で直接newしたViewに適用する方法が少しややこしかったのでメモ。 1. 適用したいstyleを作る <?xml version="1.0" encoding="utf-8"?> <resources> <style name="test"> <item name="android:textSize">20dip</item> <item name="android:textColor">#FF0000</item> </style> </resources> 2. styleを指定するための属性を作る <?xml version="1.0" encoding="utf-8"?> <resources> <attr name="testStyle" format="integer|reference" /> </r
AndroidアプリのButtonやViewに動的にstyleを設定したい。 例えばActivityからnew Button()したようなオブジェクトに共通で使っているstyleを設定したい。 かなり探したけど全然見つからなかった。 唯一ここに発見。 ソースコード内で生成したViewインスタンスにStyleを適用 はじめは書いてある内容が理解できなかったので、備忘録として以下メモ。 #リンク先と同じこと書いてるだけ。 ・アウトライン Viewのコンストラクタを見てると View(Context context) View(Context context, AttributeSet attrs) View(Context context, AttributeSet attrs, int defStyle) こんな風に定義されている。 Contextはクラスのオブジェクトを指定。この辺りを参照
編集中に別のページに遷移しようとした時に確認ダイアログを出したい。 以下のように onbeforeunload イベントを使えばOK。 window.onbeforeunload = function (e) { var e = e || window.event; // For IE and Firefox prior to version 4 if (e) { e.returnValue = 'Any string'; } // For Safari return 'Any string'; }; jQueryの場合 $(window).bind('beforeunload', function(event) { return 'Any string'; }); ただし、IEの場合は以下のような遷移しないaタグでもonbeforeunloadが発生してしまう。 <a href="jav
php数年やってますが、知らなかったという話。 単に私の知識不足なのかもしれませんが、 おそらく知らない人の方が圧倒的に多いと思う(妄想?)ので、 もっと宣伝?すべきだと思う。 結論から言うと、 文字列比較に「==」を使ってはいけません! 絶対に「===」を使いましょう。 ネタ元は、 がるの健忘録 - 素晴らしき自動的な世界〜或いは「型のない」世界〜: http://d.hatena.ne.jp/gallu/20061108/p1 ようは「==」と「===」の違いの話、そんなことはわかってる。 数値対文字列で比較してるから、想定しづらい状況になってるだけで 型を意識しておけばよいこと。(だとこのときは思ってた) ところが、上記ネタ元のコメント欄みて愕然とした。 文字列対文字列の比較なら「==」で比較しても何ら問題ない。 と思っていませんか? 私は思ってました。 しかし、それは間違いなんです
localStorageを使って見た.食わず嫌いでした.すごく便利ですね cookieで保存するより相当便利です. cookie VS localstorage 比較 Cookieの特長 ドメイン毎にデータが保存される.(SameOriginの原則) Stringが保存される. HTTPリクエストで毎回サーバーに送られる JavaScriptからアクセス可能 有効期限がある LocalStorageの特長 ドメイン毎にデータが保存される.(SameOriginの原則) Stringが保存される. HTTPリクエストで毎回サーバーに送られない JavaScriptからアクセス可能 有効期限が特にない 比較まとめ Cookieの特質から、HTTP通信で送る特性を省いたものHTTP通信で送る必要がないので,Expires(期限)も省略される localStorageの保存方法 js> local
コンストラクタとデストラクタ デストラクタって・・・何??? 「コンストラクタ」は“オブジェクトの生成時に自動的にコールされる特殊なメンバ関数”でした。これはPHP4にもありましたが、PHP5になって「デストラクタ」という愉快な仲間が新登場しました。で、「デストラクタ」は“オブジェクトが消滅する時に自動的にコールされる特殊なメンバ関数”です。 PHP5式コンストラクタ/デストラクタ PHP4では、クラス名と同じ名前のメンバ関数を定義すると、それが「コンストラクタ」になりました。PHP5でも、互換性のためにPHP4と同様にして「コンストラクタ」をつくれますが、“PHP5式”では「__construct()(アンダーライン2本で始まる)」が「コンストラクタ」となり、また「__destruct()(アンダーライン2本で始まる)」が「デストラクタ」になります。 ちなみに、“PHP4式”のコンストラ
はてなグループの終了日を2020年1月31日(金)に決定しました 以下のエントリの通り、今年末を目処にはてなグループを終了予定である旨をお知らせしておりました。 2019年末を目処に、はてなグループの提供を終了する予定です - はてなグループ日記 このたび、正式に終了日を決定いたしましたので、以下の通りご確認ください。 終了日: 2020年1月31日(金) エクスポート希望申請期限:2020年1月31日(金) 終了日以降は、はてなグループの閲覧および投稿は行えません。日記のエクスポートが必要な方は以下の記事にしたがって手続きをしてください。 はてなグループに投稿された日記データのエクスポートについて - はてなグループ日記 ご利用のみなさまにはご迷惑をおかけいたしますが、どうぞよろしくお願いいたします。 2020-06-25 追記 はてなグループ日記のエクスポートデータは2020年2月28
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く