On 07/06/2012 11:31 AM, Justin Anderson wrote:
Please post the relevant code...
Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware
public class MyActivity extends FragmentActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
static final String PREFS_FILE = "InstallLog.prefs";
static final boolean DEBUG_MODE = true;
public static final int SCAN_UPDATE = 0xdeadbeef;
public static final int SCAN_DONE = 0xdeaddead;
static MyActivity MA = null;
TextView statusTextItem = null;
Handler scanDialogUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what)
{
case MyActivity.SCAN_UPDATE:
{
if(statusTextItem == null)
statusTextItem =
(TextView)MyActivity.MA.findViewById(R.id.statusTextItem);
Log.e("myapp", "detected " + (String)msg.obj);
if(statusTextItem != null)
{
Log.e("myapp","Changing the status text to '" +
(String)msg.obj +"'");
statusTextItem.setText((String)msg.obj);
statusTextItem.invalidate();
}
}break;
case MyActivity.SCAN_DONE:
{
//kill the dialog
MA.scanFrag.dismiss();
}break;
default:
super.handleMessage(msg);
}
}
};
FragmentTransaction fragTran;
FragmentManager fragMan;
ScanDialogFragment scanFrag;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyActivity.MA = this;
setContentView(R.layout.build_layout);
this.statusTextItem = (TextView)findViewById(R.id.statusTextItem);
// Create the adapter that will return a fragment for each of
the three primary sections
// of the app.
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
int entries = this.countEntries();
if( entries == 0 )
{
fragMan = getSupportFragmentManager();
fragTran = fragMan.beginTransaction();
scanFrag = new ScanDialogFragment();
scanFrag.setCancelable(false);
scanFrag.show(fragTran, "progress");
Intent serviceIntent = new Intent(this,
RecordActivityService.class);
serviceIntent.setAction(RecordActivityService.PERFORM_SCAN);
startService(serviceIntent);
// fragTran.commit(); // commented out due to crash on startup
when present
}
}
}
public class RecordActivityService extends Service implements
UncaughtExceptionHandler {
private Thread thread;
private Runnable doStartScan = new Runnable() {
public void run() {
performScan();
}
};
private void performScan()
{
Log.i("myapp", "Perform scan");
List<MyInfo> myInfo = new List<MyInfo>();
// getContentResolver().insert(Uri.parse(MyContentProvider.AC_URI), values);
Uri uri = Uri.parse(MyContentProvider.AC_URI);
ContentValues values = new ContentValues();
Message msg = null;
MyInfo info = null;
for(int index = 0 ; index < myInfo.size(); index++)
{
info = myInfo.get(index);
//populate ContentProvider; MyActivity.countEntries()
counts these entries
values.put("data_1",info.getName() );
values.put("data_2",info.getData(2) );
values.put("data_3",info.getData(3) );
getContentResolver().insert(uri, values);
values.clear();
msg = new Message();
msg.what = MyActivity.SCAN_UPDATE;
msg.obj = info.getName();
MyActivity.scanDialogUpdateHandler.sendMessage(msg);
msg = null;
}
MyActivity.scanDialogUpdateHandler.sendEmptyMessage(MyActivity.SCAN_DONE);
this.stopSelf();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
int retval = super.onStartCommand(intent, flags, startId);
thread = new Thread(null,doStartScan,"perform_scan");
thread.start();
}
}
The following is the ScanDialogFragment.
public class ScanDialogFragment extends DialogFragment
{
public ScanDialogFragment()
{
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup
container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scanningdialogview,
container);
return view;
}
}
This is the XML for the scanningdialogview layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<ProgressBar
android:id="@+id/scanningProgress"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:id="@+id/textView1"
android:layout_width="252dp"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="@string/scanning_message"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<TextView
android:id="@+id/statusTextItem"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal"
android:text="@string/standby_message"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
The strings for "scanning_message" and "standby_message" are simple
strings "Scanning..." and "One Moment Please...", the latter of which
should be getting updated in the dialog with the current information
item as the service performs its duties. The dialog appears and
disappears on cue, and the scanning service and thread does its job just
fine.
Thank you,
Raymond
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en