Search in sources :

Example 1 with SQLiteDownloadDataSource

use of us.shandian.giga.get.sqlite.SQLiteDownloadDataSource in project NewPipe by TeamNewPipe.

the class DownloadManagerService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (DEBUG) {
        Log.d(TAG, "onCreate");
    }
    mBinder = new DMBinder();
    if (mDataSource == null) {
        mDataSource = new SQLiteDownloadDataSource(this);
    }
    if (mManager == null) {
        ArrayList<String> paths = new ArrayList<>(2);
        paths.add(NewPipeSettings.getVideoDownloadPath(this));
        paths.add(NewPipeSettings.getAudioDownloadPath(this));
        mManager = new DownloadManagerImpl(paths, mDataSource);
        if (DEBUG) {
            Log.d(TAG, "mManager == null");
            Log.d(TAG, "Download directory: " + paths);
        }
    }
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.setClass(this, DownloadActivity.class);
    Drawable icon = this.getResources().getDrawable(R.mipmap.ic_launcher);
    Builder builder = new Builder(this).setContentIntent(PendingIntent.getActivity(this, 0, i, 0)).setSmallIcon(android.R.drawable.stat_sys_download).setLargeIcon(((BitmapDrawable) icon).getBitmap()).setContentTitle(getString(R.string.msg_running)).setContentText(getString(R.string.msg_running_detail));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DownloadActivity.class).setAction(DownloadActivity.INTENT_LIST), PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    mNotification = builder.build();
    HandlerThread thread = new HandlerThread("ServiceMessenger");
    thread.start();
    mHandler = new Handler(thread.getLooper()) {

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case UPDATE_MESSAGE:
                    {
                        int runningCount = 0;
                        for (int i = 0; i < mManager.getCount(); i++) {
                            if (mManager.getMission(i).running) {
                                runningCount++;
                            }
                        }
                        updateState(runningCount);
                        break;
                    }
            }
        }
    };
}
Also used : DownloadManagerImpl(us.shandian.giga.get.DownloadManagerImpl) Message(android.os.Message) SQLiteDownloadDataSource(us.shandian.giga.get.sqlite.SQLiteDownloadDataSource) Builder(android.support.v4.app.NotificationCompat.Builder) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HandlerThread(android.os.HandlerThread) PendingIntent(android.app.PendingIntent)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Message (android.os.Message)1 Builder (android.support.v4.app.NotificationCompat.Builder)1 ArrayList (java.util.ArrayList)1 DownloadManagerImpl (us.shandian.giga.get.DownloadManagerImpl)1 SQLiteDownloadDataSource (us.shandian.giga.get.sqlite.SQLiteDownloadDataSource)1