Add sample ATSC TvInputService app.
Change-Id: I67204020bf1eb0c833d507cb0c9e4914e5985b3c
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.atsctvinput;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentValues;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.TvContract;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.example.android.atsctvinput.SampleTsStream.TsStream;
|
||||
import com.example.android.atsctvinput.SectionParser.EITItem;
|
||||
import com.example.android.atsctvinput.SectionParser.VCTItem;
|
||||
import com.example.atsctvinput.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The scan/setup activity for ATSC TvInput app.
|
||||
*/
|
||||
public class AtscTvInputScanActivity extends Activity {
|
||||
private static final String TAG = "AtscTvInputScanActivity";
|
||||
private static final long FAKE_SCANTIME_PER_CHANNEL_MS = 1000;
|
||||
private ProgressDialog mProgressDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mProgressDialog = new ProgressDialog(this);
|
||||
mProgressDialog.setMessage(getResources().getString(R.string.channel_scan_message));
|
||||
mProgressDialog.setCancelable(false);
|
||||
|
||||
mProgressDialog.show();
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
clearChannels();
|
||||
doAutoScan();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
mProgressDialog.hide();
|
||||
AtscTvInputScanActivity.this.finish();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void clearChannels() {
|
||||
String selection = TvContract.Channels.SERVICE_NAME + " = ?";
|
||||
String[] selectionArgs = new String[] {
|
||||
AtscTvInputService.class.getName()
|
||||
};
|
||||
getContentResolver().delete(TvContract.Channels.CONTENT_URI, selection, selectionArgs);
|
||||
}
|
||||
|
||||
private void doAutoScan() {
|
||||
for (TsStream s : SampleTsStream.SAMPLES) {
|
||||
Pair<VCTItem, List<EITItem>> result = SampleTsStream.extractChannelInfo(this, s);
|
||||
if (result != null) {
|
||||
insertChannel(result.first, s);
|
||||
try {
|
||||
Thread.sleep(FAKE_SCANTIME_PER_CHANNEL_MS);
|
||||
} catch (InterruptedException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void insertChannel(VCTItem channel, TsStream stream) {
|
||||
Log.d(TAG, "Channel " + channel.getShortName() + " " + channel.getMajorChannelNumber()
|
||||
+ "-" + channel.getMinorChannelNumber() + " is detected.");
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TvContract.Channels.SERVICE_NAME, AtscTvInputService.class.getName());
|
||||
values.put(TvContract.Channels.DISPLAY_NUMBER,
|
||||
channel.getMajorChannelNumber() + "-" + channel.getMinorChannelNumber());
|
||||
values.put(TvContract.Channels.DISPLAY_NAME, channel.getShortName());
|
||||
values.put(TvContract.Channels.DATA, SampleTsStream.getTuneInfo(stream));
|
||||
getContentResolver().insert(TvContract.Channels.CONTENT_URI, values);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user