Pages - Menu

2016年4月24日 星期日

[編譜 | 演奏Anima's Piano Cover ] 求譜系統 使用

[ 求譜系統 ] 正式上線 !
連結:http://goo.gl/1fDDvn
粉絲專頁即將達到700個讚
有很多琴友向粉專推薦了幾首曲子都好好聽 > <
我做了一個求譜系統,每周會挑出投票數最高的曲子寫譜~
如何使用求譜系統:
(1) 用FB帳號授權即可登入
(2) 列表裡的曲子 待表決的都可以按愛心投票,一人一天有5個投票機會
(3) 如果沒有自己想要的曲子可以新增,一人一天可以新增3首曲子
(4) 輸入歌名,歌手,還有Youtube連結即可新增
在使用上有什麼問題都可以詢問粉專~


有想要的其他曲子? 求譜系統連結:http://goo.gl/1fDDvn
 









2016年4月22日 星期五

[程式開發] 如何 用javascript 呼叫 jQuery function

一般jQuery 函式變數都會放再

$(document).ready(function() {
    alert("function is ready to use now");
});
ready 表示當頁面圖文載入完畢後才做裡面的動作

但是當想要在javascript 呼叫 jQuery function 時 就在外面動作即可

比如說javascript call $.fn.test()
function dofunc() {
    $.fn.test();  
}
$.fn.test()就要宣告成function 不用在document ready 裡面宣告

$.fn.test= function() { 
    alert("I am calling form jquery");
};





2016年4月21日 星期四

[程式開發] 如何 用jQuery或javascript 操作 Bootstrap 的Modal

一般用Bootstrap的Modal 都是用Button去觸發

<!-- Large modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

如果想要在jQuery或是javascript 操作Modal的觸發 可以這樣用

(1) 在要使用的Modal加入id 比如說 id="myModal"

(2)用下面語法即可操作

 $('#myModal').modal('show')
$('#myModal').modal('hide')
$('#myModal').modal('toggle')

參考資料
(1)http://getbootstrap.com/javascript/#modals
(2)http://getbootstrap.com/javascript/#modals-methods



2016年4月15日 星期五

[ 編譜 | 演奏Anima's Piano Cover ] Always - t尹美萊 t윤미래 鋼琴譜pdf ( 太陽的後裔 OST )

演奏:





 琴譜預覽:
 

有想要的其他曲子? 求譜系統連結:http://goo.gl/1fDDvn
 
追蹤Facebook,取得最新琴譜:

Youtube訂閱網址:https://goo.gl/VNHBqt

原key PDF連結 

轉貼請標明出處哦 > <

2016年4月8日 星期五

[編譜 | 演奏Anima's Piano Cover ] 忘了如何遺忘 How to forget - 郭靜 Claire Kuo 鋼琴譜pdf (電視劇《聶小倩》片尾曲)

演奏:





琴譜預覽:
 


有想要的其他曲子? 求譜系統連結:http://goo.gl/1fDDvn
 

Youtube訂閱網址:https://goo.gl/VNHBqt

原key PDF連結 

轉貼請標明出處哦 > <

2016年4月4日 星期一

[Android 開發筆記] BroadcastReceiver 與 WakefulBroadcastReceiver 的 差別 與用法 教學

差別在於 WakefulBroadcastReceiver 可以確保CPU一直在喚醒狀態 不會睡眠!

當接收到Broadcast時,用WakefulBroadcastReceiver 去接,WakefulBroadcastReceiver 在function startWakefulService 之後會擁有WAKE_LOCK (需要uses-permission) ,並且在completeWakefulIntent之後釋放WAKE_LOCK

Eample
 public class SimpleWakefulReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // This is the Intent to deliver to our service.
        Intent service = new Intent(context, SimpleWakefulService.class);

        // Start the service, keeping the device awake while it is launching.
        Log.i("SimpleWakefulReceiver", "Starting service @ " + SystemClock.elapsedRealtime());
        startWakefulService(context, service);
    }
}

    public class SimpleWakefulService extends IntentService {
    public SimpleWakefulService() {
        super("SimpleWakefulService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        // At this point SimpleWakefulReceiver is still holding a wake lock
        // for us.  We can do whatever we need to here and then tell it that
        // it can release the wakelock.  This sample just does some slow work,
        // but more complicated implementations could take their own wake
        // lock here before releasing the receiver's.
        //
        // Note that when using this approach you should be aware that if your
        // service gets killed and restarted while in the middle of such work
        // (so the Intent gets re-delivered to perform the work again), it will
        // at that point no longer be holding a wake lock since we are depending
        // on SimpleWakefulReceiver to that for us.  If this is a concern, you can
        // acquire a separate wake lock here.
        for (int i=0; i<5; i++) {
            Log.i("SimpleWakefulReceiver", "Running service " + (i+1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
        }
        Log.i("SimpleWakefulReceiver", "Completed service @ " + SystemClock.elapsedRealtime());
        SimpleWakefulReceiver.completeWakefulIntent(intent);
    }
}
參考資料: Android Dev

[Android 開發筆記] 解決 Gradle DSL method not found: 'compile()' 問題

dependencies 要寫在 build.gradle(Module.app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.simplemaker.pushtest"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:18.0.+'
}


















[Android 開發筆記] Scheduling Repeating Alarms 範例教學 (鬧鐘,定時器)

想要用Android 作鬧鐘或是定時器,就會用到此class

clock 分兩種:  "elapsed real time" 與 "real time clock" (RTC)

elapsed real time: 從開機時間開始計算

real time clock: 實際時鐘時間

兩種各別都有"wakeup" version : 如果螢幕關閉了,喚醒CPU

elapsed real time用在周期性作業上

real time clock用在特定時間點上(要注意時區問題,使用者更改時區會產生問題)

type有以下這四種:

  • ELAPSED_REALTIME—Fires the pending intent based on the amount of time since the device was booted, but doesn't wake up the device. The elapsed time includes any time during which the device was asleep.
  • ELAPSED_REALTIME_WAKEUP—Wakes up the device and fires the pending intent after the specified length of time has elapsed since device boot.
  • RTC—Fires the pending intent at the specified time but does not wake up the device.
  • RTC_WAKEUP—Wakes up the device to fire the pending intent at the specified time.

使用setInexactRepeating設定Alarm (setRepeating的省電版,但interval只能輸入規定常數)

public void setInexactRepeating (int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)

1. int type 可以輸入上述的ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC, or RTC_WAKEUP

2. triggerAtMillis 輸入第一次的時間 (1sec = 1000 millisec)

3.intervalMillis則是輸入周期,如果輸入INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY, or INTERVAL_DAY,Android會自動與其他Alarm比較並對齊,減少手機wake up 的次數

4. 則是輸入要做的動作 型態為PendingIntent

ELAPSED_REALTIME_WAKEUP examples
以下範例為30分鐘後trigger,之後每30分鐘做一次

// Hopefully your alarm will have a lower frequency than this!
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        AlarmManager.INTERVAL_HALF_HOUR,
        AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
另一個範例為60秒後trigger但不重複

private AlarmManager alarmMgr;
private PendingIntent alarmIntent;
...
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
        SystemClock.elapsedRealtime() +
        60 * 1000, alarmIntent);

RTC examples

以下範例為2:00p.m. Trigger 並且每天循環一次的Alarm(一般的鬧鐘)

// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
// With setInexactRepeating(), you have to use one of the AlarmManager interval
// constants--in this case, AlarmManager.INTERVAL_DAY.
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        AlarmManager.INTERVAL_DAY, alarmIntent);
另一個範例 8:30a.m.Trigger ,並且之後每20分鐘循環一次(貪睡鬧鐘~)

private AlarmManager alarmMgr;
private PendingIntent alarmIntent;
...
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);
// setRepeating() lets you specify a precise custom interval--in this case,
// 20 minutes.
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        1000 * 60 * 20, alarmIntent);


要選擇哪一個Function ?  setInexactRepeating() or setRepeating()  ?

前述說過 setInexactRepeating() 的 interval只能輸入規定常數,Android可以達到省電目的,一般使用這個就好,除非你需要非常精準的時間(如8:30) ,那才需要用到 setRepeating() ,但就比較耗電一點

如何取消Alarm ?

cancel掉不要產生的pendingIntent即可

// If the alarm has been set, cancel it.
if (alarmMgr!= null) {
    alarmMgr.cancel(alarmIntent);
}

如何在開機時就自動開啟Alarm ?

Android預設關機後Alarm就會Cancel掉
1.加入uses-permission:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

2.實作 BroadcastReceiver :
public class SampleBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            // Set the alarm here.
        }
    }
}

3.manifest 設定receiver,此處anable設為false的原因在於,如果有設定Alarm再開啟,沒有則關掉,避免不必要的動作
<receiver android:name=".SampleBootReceiver"
        android:enabled="false">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

當Alarm開啟後,開啟Receiver :
ComponentName receiver = new ComponentName(context, SampleBootReceiver.class);
PackageManager pm = context.getPackageManager();

pm.setComponentEnabledSetting(receiver,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

關閉:
ComponentName receiver = new ComponentName(context, SampleBootReceiver.class);
PackageManager pm = context.getPackageManager();

pm.setComponentEnabledSetting(receiver,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

延伸:
1.定時執行除了Alarm 還有 利用  Timer and Thread   的 Handler class
2.如果考慮到定時抓取Server資訊(例如更新天氣資訊) 可以使用 Google Cloud Messaging (GCM)

資料來源: Android Dev