https://qiita.com/watame/items/5f82abead68db483d6f2
PDFを作成するやつに、独自フォントを入れる方法。
https://qiita.com/watame/items/5f82abead68db483d6f2
PDFを作成するやつに、独自フォントを入れる方法。
ここのテンプレートは素晴らしい、簡素でいてわかりやすく。0から構築するのに大変便利、金額も高くない。
見栄えもする、しばらくの決定版として使っていいと思われます。
最近さがしたり、参考にしたサイトをまとめてリンクしておく。
Modern UI Pack
https://assetstore.unity.com/packages/tools/gui/modern-ui-pack-150824
Pro Cartoon UI Pack
https://assetstore.unity.com/packages/2d/gui/icons/pro-cartoon-ui-pack-129756
Airy UI – Easy UI Animation
https://assetstore.unity.com/packages/tools/gui/airy-ui-easy-ui-animation-135898
Youtube動画からサムネイル画像を取得する方法
https://www.billionwallet.com/goods/youtube_image.html
firebase確認
https://apps-gcp.com/firebase-authentication/
https://firebase.google.com/docs/auth/unity/twitter-login?hl=ja
UnityのUpdate()をマネージャで管理`
https://www.weed.nagoya/entry/2017/09/20/135611
Crowi
国産のWikiソフトで、もともとは社内用に開発したWikiをオープンソース化した物
https://qiita.com/Bakudankun/items/740ac8ba1395fe4e40a6
無限スクロール
http://kohki.hatenablog.jp/entry/Unity-uGUI-Fixed-Scroll-Rect
http://www.asset-sale.net/entry/EnhancedScroller_1
スクロールアセット
https://qiita.com/ayumegu/items/556d0385bbd4e00b89f5
Unity Apple
https://gurutaka-log.com/unity-ios-release
http://bob-jpn-heuer0925.hatenablog.com/entry/2017/09/09/035351
Unity Android署名
https://ideacloud.tokyo/develop-days/development/apk_rerease_setting.html
備忘録 Unity アプリからURLを開く
https://ameblo.jp/10soba/entry-12445527586.html
アプリのバックグラウンド移動と終了の検知
起動時に電源をOFFにし、いったんバックグラウンドにいったときの処理
http://greenkour.hateblo.jp/entry/2018/08/20/070000
https://qiita.com/wapa5pow/items/2cbad14267d2ad3433f5
誰でも簡単に使える最強のAudio(BGM, SE)Manager【Unity】
https://kan-kikuchi.hatenablog.com/entry/AudioManager_2019
Unity で自動でスリープに入らないようにする設定
https://loumo.jp/wp/archive/20140205000312/
https://www.urablog.xyz/entry/2017/06/11/230753
ソーシャルログイン’ を90秒で導入する方法 / OAuth認証
https://qiita.com/RingCaptcha/items/60db56ed24567718fe80
Twitterを使った認証機能
https://blog.mbaas.nifcloud.com/entry/8046
みんな大好きグリッドビュー。
1 2 3 |
// 入れ込むべきレイアウト GridView gridView = (GridView) v.findViewById(R.id.gridView); gridView.setAdapter(new ImageAdapter(context, imageUrlList)); |
こうやって使いまっさ。ImageAdapterは独自のもの。そこに、context imageUrlListを渡します。
しかし、GridView、文字をいれるだけだと楽勝であるのだが、ネットから画像をよみこんでいれるとなるときっついのだ。それぞれの大きさがバラバラになったりして泣きそうになるのだ。他のサイトではすごく簡単にやり遂げているが。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.support.v4.util.LruCache; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import com.android.volley.RequestQueue; import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.Volley; import java.util.List; /** * イメージローダー */ public class ImageAdapter extends ArrayAdapter<String> { public final String TAG = "ImageAdapter"; private Context context; private RequestQueue mQueue; private ImageLoader mImageLoader; public ImageAdapter(Context context, List<String> objects) { super(context, 0, objects); this.context = context; mQueue = Volley.newRequestQueue(getContext()); mImageLoader = new ImageLoader(mQueue, new BitmapCache()); } @Override public View getView(int position, View convertView, ViewGroup parent) { String url = getItem(position); ImageView imageView; if (convertView == null) { imageView = new ImageView(getContext()); } else { imageView = (ImageView) convertView; } // 画像取得処理 ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, android.R.drawable.ic_menu_rotate, android.R.drawable.ic_delete); // BASIC認証 mImageLoader = new BasicAuthImageLoader(mQueue, new ImageLoader.ImageCache() { private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(100); public void putBitmap(String url, Bitmap bitmap) { mCache.put(url, bitmap); } public Bitmap getBitmap(String url) { return mCache.get(url); } }); mImageLoader.get(url, listener); // 画像のサイズをここで固定 imageView.setMinimumWidth(300); imageView.setMinimumHeight(200); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // クリックイベント imageView.setOnClickListener(new View.OnClickListener() { public String url; public View.OnClickListener setUrl(String url) { this.url = url; return this; } public void onClick(View v) { // イメージ画像がクリックされたときに実行される処理 Log.d(TAG, "url= " + url); // 画面遷移 Intent intent = new Intent(context, TSUGINO_GAMEN.class); intent.putExtra("photoUrlAddress", url); context.startActivity(intent); } }.setUrl(url) ); return imageView; } } |
ここで、
// 画像のサイズをここで固定
imageView.setMinimumWidth(300);
imageView.setMinimumHeight(200);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
これが必要だった。setScaleTypeはおこのみで。
クリックイベントにも注目。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// クリックイベント imageView.setOnClickListener(new View.OnClickListener() { public String url; public View.OnClickListener setUrl(String url) { this.url = url; return this; } public void onClick(View v) { // イメージ画像がクリックされたときに実行される処理 Log.d(TAG, "url= " + url); // 画面遷移 Intent intent = new Intent(context, TSUGINO_GAMEN.class); intent.putExtra("photoUrlAddress", url); context.startActivity(intent); } }.setUrl(url) ); |
setUrlを使ってurlをイベントリスナー内に入れ込んでいる。イベントに値を渡す方法。少し凝ったことをしたいなら必要になってくるだろう。
BASIC認証は使わないだろうからはずしてもいいじゃろう。
1 2 3 4 5 6 7 8 9 10 11 12 |
// BASIC認証 mImageLoader = new BasicAuthImageLoader(mQueue, new ImageLoader.ImageCache() { private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(100); public void putBitmap(String url, Bitmap bitmap) { mCache.put(url, bitmap); } public Bitmap getBitmap(String url) { return mCache.get(url); } }); |
こちらを参考にして、
intent.setFlagsメソッドの引数について
定数 | 内容 |
---|---|
FLAG_ACTIVITY_NEW_TASK | 常に新しいタスクで起動する ※デフォルト |
FLAG_ACTIVITY_SINGLE_TOP | 現在のActivityと同じアクティビティは起動しない |
FLAG_ACTIVITY_CLEAR_TOP | スタックをクリアしてから起動する |
FLAG_ACTIVITY_NO_ANIMATION | トランジションアニメーションを行わずに起動する |
FLAG_ACTIVITY_NO_HISTORY | スタックに追加せずに起動する |
FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | スタック内のActivityを利用して起動する(使いまわす) |
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | 履歴内の同一Acrivityを利用して起動する(使いまわす) |
FLAG_ACTIVITY_PREVIOUS_IS_TOP | 呼び出し元のActivityをタスクのトップと見なして起動する |
FLAG_ACTIVITY_REORDER_TO_FRONT | スタック内の同一Activityを最前面に移動させる |
画面を遷移するときなどにこれを渡せばいいらしい。使い方は以下のような、
1 2 3 4 5 6 7 8 |
// 引数1:自身のActivity、引数2:移動先のActivity名 Intent intent = new Intent(MainActivity.this, SubActivity.class); // オプションを指定 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Activityの移動 startActivity(intent); |
あとタスクに関係するのであればマニフェストの、
android:launchMode=”singleTask”
なども考慮するといいかもしれない。
また一つ賢くなったね!!
アラートダイアログの外側を押せないようにする、ダイアログは便利ですが外側を押しても反応しちゃう。
そこで
1 2 |
// ダイアログ表示 public AlertDialog.Builder builder; |
こんな感じで、アラートダイアログを宣言して
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
builder = new AlertDialog.Builder(this); builder.setTitle("登録しました"); // 外側を押せないようにする <strong>builder.setCancelable(false);</strong> builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // 遷移 Intent intent = new Intent(getApplicationContext(), hogehoge.class); startActivity(intent); } }); // 表示 builder.create().show(); |
こうすればいいですね。
builder.create().show(); の create() はわけわかめ。なんだろうか、こいつは。
alphaを指定する。
AlphaAnimationをつかって指定。
1 2 3 4 5 6 |
Button buttonKakunin = (Button) findViewById(R.id.buttonKakunin); buttonKakunin.setEnabled(true); <strong>float alpha = 0.50f; AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha); alphaUp.setFillAfter(true); buttonKakunin.startAnimation(alphaUp);</strong> |
自分的Volleyの定番コード
CustomRequestクラスを作成して以下の文章でvolley使う。例文はPOSTを使用する場合です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
HashMap<String, String> postMap = new HashMap<String, String>(); postMap.put("uuid", uuId); RequestQueue requestQueue = Volley.newRequestQueue(this); CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST, Constant.USER_ADD_URL, postMap, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.v("初期ユーザー登録、JSON", response.toString()); // ここでタイマー起動 // 3秒カウント開始のスケジュール timer = new Timer(); timer.schedule(new MyTimer(), Constant.TITLE_COUNT_SEC); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.v("初期ユーザー登録、VolleyErr", "" + error); } }); requestQueue.add(jsObjRequest); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
public class CustomRequest extends Request<JSONObject> { private Response.Listener<JSONObject> listener; private Map<String, String> params; public CustomRequest(String url, Map<String, String> params, Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener) { super(Request.Method.GET, url, errorListener); this.listener = reponseListener; this.params = params; } public CustomRequest(int method, String url, Map<String, String> params, Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener) { super(method, url, errorListener); this.listener = reponseListener; this.params = params; } protected Map<String, String> getParams() throws com.android.volley.AuthFailureError { return params; } ; @Override protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(new JSONObject(jsonString), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException je) { return Response.error(new ParseError(je)); } } @Override protected void deliverResponse(JSONObject response) { // TODO Auto-generated method stub listener.onResponse(response); } } |
タイマーをよく使うのですが、備忘録として。
1 2 3 4 |
// タイマー作動 Timer timer1 = new Timer(); Handler handler1 = new Handler(); timer1.schedule(new DownloadTimer(), 0, 2000); |
タイマー、ハンドラーを宣言。その後のスケジュールで0秒から開始、その後2000ミリ秒ごと(2秒)にタイマー作動。となっています。 new DownloadTimer() を宣言してそれを実行することになっています。
実際の処理内は、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class DownloadTimer extends TimerTask { @Override public void run() { handler1.post(new Runnable(){ @Override public void run() { } }); } } |
こんな感じでクラスをつくり public void run() { } に処理をかきます。それが実行されます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
public class ImageManager { private Context mContext; private String fileFullPath; public ImageManager(Context context) { mContext = context; } /** * 画像の保存 * * @param bitmap * @param albumName */ public void save(Bitmap bitmap, String albumName) { if (!canUseSd()) { Log.e("Error", "Can't use SD Card"); return; } saveToSd(getSdStorageDir(albumName), bitmap); } /** * ストレージに画像保存 * * @param dir * @param bitmap */ private void saveToSd(File dir, Bitmap bitmap) { String fileName = getFileName(); fileFullPath = dir.getAbsolutePath() + "/" + fileName; Log.d("保存パス","fileFullPath= " + fileFullPath); try { // 保存処理 FileOutputStream fos = new FileOutputStream(fileFullPath); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { Log.e("Error", "" + e.toString()); } finally { // アルバムに反映 addGallery(fileName); } } /** * 保存した画像をギャラリーに追加 * * @param fileName */ private void addGallery(String fileName) { try { ContentValues values = new ContentValues(); ContentResolver contentResolver = mContext.getContentResolver(); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.TITLE, fileName); values.put("_data", fileFullPath); contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (Exception e) { Log.e("Error", "" + e); } } /** * 画像のファイル名を日付から生成し取得 * * @return */ private String getFileName() { Date mDate = new Date(); SimpleDateFormat fileNameFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH); String fileName = fileNameFormat.format(mDate) + ".jpg"; return fileName; } /** * ストレージのストレージパス取得 * * @param albumName * @return */ private File getSdStorageDir(String albumName) { File dir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), albumName); if (!dir.exists()) { if (!dir.mkdirs()) { Log.e("Error", "Directory not created"); } } return dir; } /** * ストレージが読み込み可能か * * @return */ public boolean canReadSd() { String status = Environment.getExternalStorageState(); if (!status.equals(Environment.MEDIA_MOUNTED)) { return false; } File file = Environment.getExternalStorageDirectory(); if (file.canRead()) { return true; } return false; } /** * ストレージに書き込み可能か * * @return */ public boolean canWriteSd() { String status = Environment.getExternalStorageState(); if (!status.equals(Environment.MEDIA_MOUNTED)) { return false; } File file = Environment.getExternalStorageDirectory(); if (file.canWrite()) { return true; } return false; } /** * ストレージが使用可能か * * @return */ public boolean canUseSd() { return canReadSd() && canWriteSd(); } } |
使い方は、
1 2 3 4 5 6 7 8 9 10 |
ImageView imageView = (ImageView) findViewById(R.id.photo_image); Bitmap imageForScale = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); ImageManager imageManager = new ImageManager(this); try { String albumName = "Save image sample"; imageManager.save(imageForScale, albumName); } catch (Error e) { Log.e("MainActivity", "onCreate: " + e); } |
1 2 3 4 5 6 7 |
FrameLayout main = (FrameLayout) findViewById(R.id.main); // 移動アニメーション TranslateAnimation2 translateAnimation = new TranslateAnimation2(1400.0f, 0.0f, 0.0f, 0.0f, Easing.easeInOutQuart); translateAnimation.setDuration(1200); translateAnimation.setFillAfter(true); main.startAnimation(translateAnimation); |
TranslateAnimation2クラスとか
Easingクラスとかいるからね
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
public class Easing { public static String easeInQuad = "easeInQuad"; public static String easeOutQuad = "easeOutQuad"; public static String easeInOutQuad = "easeInOutQuad"; public static String easeInCubic = "easeInCubic"; public static String easeOutCubic = "easeOutCubic"; public static String easeInOutCubic = "easeInOutCubic"; public static String easeInQuart = "easeInQuart"; public static String easeOutQuart = "easeOutQuart"; public static String easeInOutQuart = "easeInOutQuart"; public static String easeInQuint = "easeInQuint"; public static String easeOutQuint = "easeOutQuint"; public static String easeInOutQuint = "easeInOutQuint"; public static String easeInSine = "easeInSine"; public static String easeOutSine = "easeOutSine"; public static String easeInOutSine = "easeInOutSine"; public static String easeInExpo = "easeInExpo"; public static String easeOutExpo = "easeOutExpo"; public static String easeInOutExpo = "easeInOutExpo"; public static String easeInCirc = "easeInCirc"; public static String easeOutCirc = "easeOutCirc"; public static String easeInOutCirc = "easeInOutCirc"; public static String easeInElastic = "easeInElastic"; public static String easeOutElastic = "easeOutElastic"; public static String easeInOutElastic = "easeInOutElastic"; public static String easeInBack = "easeInBack"; public static String easeOutBack = "easeOutBack"; public static String easeInOutBack = "easeInOutBack"; public static String easeInBounce = "easeInBounce"; public static String easeOutBounce = "easeOutBounce"; public static String easeInOutBounce = "easeInOutBounce"; public static float move(float t, String easing) { if (easing.equals(easeInQuad)) { return easeInQuad(t); } else if (easing.equals(easeOutQuad)) { return easeOutQuad(t); } else if (easing.equals(easeInOutQuad)) { return easeInOutQuad(t); } else if (easing.equals(easeInCubic)) { return easeInCubic(t); } else if (easing.equals(easeOutCubic)) { return easeOutCubic(t); } else if (easing.equals(easeInOutCubic)) { return easeInOutCubic(t); } else if (easing.equals(easeInQuart)) { return easeInQuart(t); } else if (easing.equals(easeOutQuart)) { return easeOutQuart(t); } else if (easing.equals(easeInOutQuart)) { return easeInOutQuart(t); } else if (easing.equals(easeInQuint)) { return easeInQuint(t); } else if (easing.equals(easeOutQuint)) { return easeOutQuint(t); } else if (easing.equals(easeInOutQuint)) { return easeInOutQuint(t); } else if (easing.equals(easeInSine)) { return easeInSine(t); } else if (easing.equals(easeOutSine)) { return easeOutSine(t); } else if (easing.equals(easeInOutSine)) { return easeInOutSine(t); } else if (easing.equals(easeInExpo)) { return easeInExpo(t); } else if (easing.equals(easeOutExpo)) { return easeOutExpo(t); } else if (easing.equals(easeInOutExpo)) { return easeInOutExpo(t); } else if (easing.equals(easeInCirc)) { return easeInCirc(t); } else if (easing.equals(easeOutCirc)) { return easeOutCirc(t); } else if (easing.equals(easeInOutCirc)) { return easeInOutCirc(t); } else if (easing.equals(easeInElastic)) { return easeInElastic(t); } else if (easing.equals(easeOutElastic)) { return easeOutElastic(t); } else if (easing.equals(easeInOutElastic)) { return easeInOutElastic(t); } else if (easing.equals(easeInBack)) { return easeInBack(t); } else if (easing.equals(easeOutBack)) { return easeOutBack(t); } else if (easing.equals(easeInOutBack)) { return easeInOutBack(t); } else if (easing.equals(easeInBounce)) { return easeInBounce(t); } else if (easing.equals(easeOutBounce)) { return easeOutBounce(t); } else if (easing.equals(easeInOutBounce)) { return easeInOutBounce(t); } return t; } public static float easeInQuad(float t) { return easeInQuad(t, 0f, 1f, 1f); } public static float easeOutQuad(float t) { return easeInQuad(t, 0f, 1f, 1f); } public static float easeInOutQuad(float t) { return easeInOutQuad(t, 0f, 1f, 1f); } public static float easeInCubic(float t) { return easeInCubic(t, 0f, 1f, 1f); } public static float easeOutCubic(float t) { return easeOutCubic(t, 0f, 1f, 1f); } public static float easeInOutCubic(float t) { return easeInOutCubic(t, 0f, 1f, 1f); } public static float easeInQuart(float t) { return easeInQuart(t, 0f, 1f, 1f); } public static float easeOutQuart(float t) { return easeOutQuart(t, 0f, 1f, 1f); } public static float easeInOutQuart(float t) { return easeInOutQuart(t, 0f, 1f, 1f); } public static float easeInQuint(float t) { return easeInQuint(t, 0f, 1f, 1f); } public static float easeOutQuint(float t) { return easeOutQuint(t, 0f, 1f, 1f); } public static float easeInOutQuint(float t) { return easeInOutQuint(t, 0f, 1f, 1f); } public static float easeInSine(float t) { return easeInSine(t, 0f, 1f, 1f); } public static float easeOutSine(float t) { return easeOutSine(t, 0f, 1f, 1f); } public static float easeInOutSine(float t) { return easeInOutSine(t, 0f, 1f, 1f); } public static float easeInExpo(float t) { return easeInExpo(t, 0f, 1f, 1f); } public static float easeOutExpo(float t) { return easeOutExpo(t, 0f, 1f, 1f); } public static float easeInOutExpo(float t) { return easeInOutExpo(t, 0f, 1f, 1f); } public static float easeInCirc(float t) { return easeInCirc(t, 0f, 1f, 1f); } public static float easeOutCirc(float t) { return easeOutCirc(t, 0f, 1f, 1f); } public static float easeInOutCirc(float t) { return easeInOutCirc(t, 0f, 1f, 1f); } public static float easeInElastic(float t) { return easeInElastic(t, 0f, 1f, 1f); } public static float easeOutElastic(float t) { return easeOutElastic(t, 0f, 1f, 1f); } public static float easeInOutElastic(float t) { return easeInOutElastic(t, 0f, 1f, 1f); } public static float easeInBack(float t) { return easeInBack(t, 0f, 1f, 1f, 1.70158f); } public static float easeOutBack(float t) { return easeOutBack(t, 0f, 1f, 1f, 1.70158f); } public static float easeInOutBack(float t) { return easeInOutBack(t, 0f, 1f, 1f, 1.70158f); } public static float easeInBounce(float t) { return easeInBounce(t, 0f, 1f, 1f); } public static float easeOutBounce(float t) { return easeOutBounce(t, 0f, 1f, 1f); } public static float easeInOutBounce(float t) { return easeInOutBounce(t, 0f, 1f, 1f); } /**/ public static float easeInQuad(float t, float b, float c, float d) { return c * (t /= d) * t + b; } public static float easeOutQuad(float t, float b, float c, float d) { return -c * (t /= d) * (t - 2f) + b; } public static float easeInOutQuad(float t, float b, float c, float d) { if ((t /= d / 2f) < 1) return c / 2f * t * t + b; return -c / 2f * ((--t) * (t - 2f) - 1) + b; } public static float easeInCubic(float t, float b, float c, float d) { return c * (t /= d) * t * t + b; } public static float easeOutCubic(float t, float b, float c, float d) { return c * ((t = t / d - 1f) * t * t + 1f) + b; } public static float easeInOutCubic(float t, float b, float c, float d) { if ((t /= d / 2f) < 1) return c / 2f * t * t * t + b; return c / 2f * ((t -= 2f) * t * t + 2f) + b; } public static float easeInQuart(float t, float b, float c, float d) { return c * (t /= d) * t * t * t + b; } public static float easeOutQuart(float t, float b, float c, float d) { return -c * ((t = t / d - 1f) * t * t * t - 1f) + b; } public static float easeInOutQuart(float t, float b, float c, float d) { if ((t /= d / 2f) < 1f) return c / 2f * t * t * t * t + b; return -c / 2f * ((t -= 2f) * t * t * t - 2f) + b; } public static float easeInQuint(float t, float b, float c, float d) { return c * (t /= d) * t * t * t * t + b; } public static float easeOutQuint(float t, float b, float c, float d) { return c * ((t = t / d - 1f) * t * t * t * t + 1f) + b; } public static float easeInOutQuint(float t, float b, float c, float d) { if ((t /= d / 2f) < 1f) return c / 2f * t * t * t * t * t + b; return c / 2f * ((t -= 2f) * t * t * t * t + 2f) + b; } public static float easeInSine(float t, float b, float c, float d) { return (float) (-c * Math.cos(t / d * (Math.PI / 2f)) + c + b); } public static float easeOutSine(float t, float b, float c, float d) { return (float) (c * Math.sin(t / d * (Math.PI / 2f)) + b); } public static float easeInOutSine(float t, float b, float c, float d) { return (float) (-c / 2f * (Math.cos(Math.PI * t / d) - 1) + b); } public static float easeInExpo(float t, float b, float c, float d) { return (float) ((t == 0) ? b : c * Math.pow(2, 10f * (t / d - 1f)) + b); } public static float easeOutExpo(float t, float b, float c, float d) { return (float) ((t == d) ? b + c : c * (-Math.pow(2, -10f * t / d) + 1f) + b); } public static float easeInOutExpo(float t, float b, float c, float d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2f) < 1f) return (float) (c / 2f * Math.pow(2, 10f * (t - 1f)) + b); return (float) (c / 2f * (-Math.pow(2, -10f * --t) + 2f) + b); } public static float easeInCirc(float t, float b, float c, float d) { return (float) (-c * (Math.sqrt(1f - (t /= d) * t) - 1f) + b); } public static float easeOutCirc(float t, float b, float c, float d) { return (float) (c * Math.sqrt(1 - (t = t / d - 1) * t) + b); } public static float easeInOutCirc(float t, float b, float c, float d) { if ((t /= d / 2) < 1) return (float) (-c / 2 * (Math.sqrt(1 - t * t) - 1) + b); return (float) (c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b); } public static float easeInElastic(float t, float b, float c, float d) { float s = 1.70158f; float p = 0; float a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; p = d * 0.3f; if (a < Math.abs(c)) { a = c; s = p / 4f; } else s = (float) (p / (2f * Math.PI) * Math.asin(c / a)); return (float) (-(a * Math.pow(2, 10f * (t -= 1f)) * Math.sin((t * d - s) * (2f * Math.PI) / p)) + b); } public static float easeOutElastic(float t, float b, float c, float d) { float s = 1.70158f; float p = 0; float a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; p = d * 0.3f; if (a < Math.abs(c)) { a = c; s = p / 4f; } else s = (float) (p / (2f * Math.PI) * Math.asin(c / a)); return (float) (a * Math.pow(2, -10f * t) * Math.sin((t * d - s) * (2f * Math.PI) / p) + c + b); } public static float easeInOutElastic(float t, float b, float c, float d) { float s = 1.70158f; float p = 0; float a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; p = d * (0.3f * 1.5f); if (a < Math.abs(c)) { a = c; s = p / 4f; } else s = (float) (p / (2f * Math.PI) * Math.asin(c / a)); if (t < 1) return (float) (-0.5f * (a * Math.pow(2, 10f * (t -= 1f)) * Math.sin((t * d - s) * (2f * Math.PI) / p)) + b); return (float) (a * Math.pow(2, -10f * (t -= 1f)) * Math.sin((t * d - s) * (2f * Math.PI) / p) * 0.5f + c + b); } public static float easeInBack(float t, float b, float c, float d, float s) { return c * (t /= d) * t * ((s + 1f) * t - s) + b; } public static float easeOutBack(float t, float b, float c, float d, float s) { return c * ((t = t / d - 1f) * t * ((s + 1f) * t + s) + 1f) + b; } public static float easeInOutBack(float t, float b, float c, float d, float s) { if ((t /= d / 2f) < 1) return c / 2f * (t * t * (((s *= (1.525f)) + 1f) * t - s)) + b; return c / 2f * ((t -= 2f) * t * (((s *= (1.525f)) + 1f) * t + s) + 2f) + b; } public static float easeInBounce(float t, float b, float c, float d) { return c - easeOutBounce(d - t, 0, c, d) + b; } public static float easeOutBounce(float t, float b, float c, float d) { if ((t /= d) < (1f / 2.75f)) { return c * (7.5625f * t * t) + b; } else if (t < (2f / 2.75f)) { return c * (7.5625f * (t -= (1.5f / 2.75f)) * t + 0.75f) + b; } else if (t < (2.5f / 2.75f)) { return c * (7.5625f * (t -= (2.25f / 2.75f)) * t + 0.9375f) + b; } else { return c * (7.5625f * (t -= (2.625f / 2.75f)) * t + 0.984375f) + b; } } public static float easeInOutBounce(float t, float b, float c, float d) { if (t < d / 2f) return easeInBounce(t * 2f, 0, c, d) * 0.5f + b; return easeOutBounce(t * 2f - d, 0, c, d) * 0.5f + c * 0.5f + b; } } |
そんでもって
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.Transformation; public class TranslateAnimation2 extends Animation { private int mFromXType = ABSOLUTE; private int mToXType = ABSOLUTE; private int mFromYType = ABSOLUTE; private int mToYType = ABSOLUTE; private float mFromXValue = 0.0f; private float mToXValue = 0.0f; private float mFromYValue = 0.0f; private float mToYValue = 0.0f; private float mFromXDelta; private float mToXDelta; private float mFromYDelta; private float mToYDelta; private String easing; /** * Constructor to use when building a TranslateAnimation from code * * @param fromXDelta * Change in X coordinate to apply at the start of the animation * @param toXDelta * Change in X coordinate to apply at the end of the animation * @param fromYDelta * Change in Y coordinate to apply at the start of the animation * @param toYDelta * Change in Y coordinate to apply at the end of the animation */ public TranslateAnimation2(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,String _easing) { mFromXValue = fromXDelta; mToXValue = toXDelta; mFromYValue = fromYDelta; mToYValue = toYDelta; mFromXType = ABSOLUTE; mToXType = ABSOLUTE; mFromYType = ABSOLUTE; mToYType = ABSOLUTE; easing = _easing; setInterpolator(new LinearInterpolator()); } /** * Constructor to use when building a TranslateAnimation from code * * @param fromXType * Specifies how fromXValue should be interpreted. One of * Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or * Animation.RELATIVE_TO_PARENT. * @param fromXValue * Change in X coordinate to apply at the start of the animation. * This value can either be an absolute number if fromXType is * ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise. * @param toXType * Specifies how toXValue should be interpreted. One of * Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or * Animation.RELATIVE_TO_PARENT. * @param toXValue * Change in X coordinate to apply at the end of the animation. * This value can either be an absolute number if toXType is * ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise. * @param fromYType * Specifies how fromYValue should be interpreted. One of * Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or * Animation.RELATIVE_TO_PARENT. * @param fromYValue * Change in Y coordinate to apply at the start of the animation. * This value can either be an absolute number if fromYType is * ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise. * @param toYType * Specifies how toYValue should be interpreted. One of * Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or * Animation.RELATIVE_TO_PARENT. * @param toYValue * Change in Y coordinate to apply at the end of the animation. * This value can either be an absolute number if toYType is * ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise. */ public TranslateAnimation2(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue,String _easing) { mFromXValue = fromXValue; mToXValue = toXValue; mFromYValue = fromYValue; mToYValue = toYValue; mFromXType = fromXType; mToXType = toXType; mFromYType = fromYType; mToYType = toYType; setInterpolator(new LinearInterpolator()); easing = _easing; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { float dx = mFromXDelta; float dy = mFromYDelta; if (mFromXDelta != mToXDelta) { dx = mFromXDelta + ((mToXDelta - mFromXDelta) * Easing.move(interpolatedTime,easing)); } if (mFromYDelta != mToYDelta) { dy = mFromYDelta + ((mToYDelta - mFromYDelta) * Easing.move(interpolatedTime,easing)); } t.getMatrix().setTranslate(dx, dy); } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); mFromXDelta = resolveSize(mFromXType, mFromXValue, width, parentWidth); mToXDelta = resolveSize(mToXType, mToXValue, width, parentWidth); mFromYDelta = resolveSize(mFromYType, mFromYValue, height, parentHeight); mToYDelta = resolveSize(mToYType, mToYValue, height, parentHeight); } } |
つかうときはこげな感じ
1 2 3 4 5 6 7 8 |
FrameLayout main = (FrameLayout) findViewById(R.id.main); //てけとーなレイアウトとかを TranslateAnimation2 translateAnimation = new TranslateAnimation2(-1400.0f, 0.0f, 0.0f, 0.0f, Easing.easeOutBounce); translateAnimation.setDuration(1000); translateAnimation.setFillAfter(true); main.startAnimation(translateAnimation); |
こんな風にすると、びっくりただのアニメーションにバウンスついたりする。これはJavaScriptでもよくある手法だよぬ!
TranslateAnimation2(-1400.0f, 0.0f, 0.0f, 0.0f, Easing.easeOutBounce);
ポイントは上の一行ですね。
クラスファイルを2つ使用するだけでいけるので、ちょびっとアニメーションしたいときなんか簡単でいいですよね。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("登録しました"); builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 遷移 Intent intent = new Intent(getApplication(), testActivity.class); startActivity(intent); } }); // 表示 builder.create().show(); |
これでウインドメッセージが出てきます。
“OK” を押した場合は、
1 2 3 4 5 6 7 8 9 10 |
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 遷移 Intent intent = new Intent(getApplication(), G_2_0_4_SeijinshikiActivity.class); startActivity(intent); } }); |
この中にかくといいよ!
でもダイアログ以外をおしたときは、どう判定すればいいのか、、、、
1 2 |
ImageView photo_thum = (ImageView) view2.findViewById(R.id.photo_thum); photo_thum.setMargin(); |
みたいにできると思うやん?できんから。
1 2 3 |
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)photo_thum.getLayoutParams(); lp.rightMargin = 10; photo_thum.setLayoutParams(lp); |
一度、MarginLayoutParams に通すのね。これを利用すればなんでもオッケーオッケー。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// 端末の横幅を元に、3分割した横幅を計算 public int getTanmatsuWidth(int width) { width -= 20; int w = (int)(width/3); Log.d(TAG, "w= " + w); return w; } // 端末の横幅を元に、3分割した横幅を計算 public int getTamatsuHeight(int width) { width -= 20; int width2 = (width/3); int h = (int)(width2/1.618); Log.d(TAG, "h= " + h); return h; } |
端末に画像を3つ並べて、間に10dpの隙間がはいることを想定しています。
なんちゃないよ。