Example usage for android.content.res Resources getAssets

List of usage examples for android.content.res Resources getAssets

Introduction

In this page you can find the example usage for android.content.res Resources getAssets.

Prototype

public final AssetManager getAssets() 

Source Link

Document

Retrieve underlying AssetManager storage for these resources.

Usage

From source file:com.t2.compassionMeditation.DeviceManagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mInstance = this;
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    //this.sendBroadcast(new Intent(BioFeedbackService.ACTION_SERVICE_START));

    this.setContentView(R.layout.device_manager_activity_layout);

    this.findViewById(R.id.bluetoothSettingsButton).setOnClickListener(this);

    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();
    try {/*from   w w  w .  j  a  v  a  2 s . c om*/
        mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, this.getClass().getSimpleName() + " Exception creating SPINE manager: " + e.toString());
        e.printStackTrace();
    }
    // ... then we need to register a SPINEListener implementation to the SPINE manager instance
    // to receive sensor node data from the Spine server
    // (I register myself since I'm a SPINEListener implementation!)
    mSpineManager.addListener(this);

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);
    // Set up filter intents so we can receive broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.t2.biofeedback.service.status.BROADCAST");
    filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    filter.addAction(BioFeedbackService.ACTION_STATUS_BROADCAST);

    this.registerReceiver(this.mCommandReceiver, filter);

    // Tell the bluetooth service to send us a list of bluetooth devices and system status
    // Response comes in public void onStatusReceived(BioFeedbackStatus bfs) STATUS_PAIRED_DEVICES      
    mSpineManager.pollBluetoothDevices();

    //      this.deviceManager = DeviceManager.getInstance(this.getBaseContext(), null);
    this.deviceList = (ListView) this.findViewById(R.id.list);

    this.deviceListAdapter = new ManagerItemAdapter(this, R.layout.manager_item);
    this.deviceList.setAdapter(this.deviceListAdapter);

    this.bluetoothDisabledDialog = new AlertDialog.Builder(this).setMessage("Bluetooth is not enabled.")
            .setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    finish();
                }
            }).setPositiveButton("Setup Bluetooth", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    startBluetoothSettings();
                }
            }).create();

    try {
        PackageManager packageManager = this.getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0);
        mVersionName = info.versionName;
        Log.i(TAG, this.getClass().getSimpleName() + " Spine server Test Application Version " + mVersionName);
    } catch (NameNotFoundException e) {
        Log.e(TAG, this.getClass().getSimpleName() + e.toString());
    }
}

From source file:com.t2.androidspineexample.AndroidSpineExampleActivity.java

/** Called when the activity is first created. */
@Override//w w w  .jav  a2  s . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(TAG, this.getClass().getSimpleName() + ".onCreate()");
    mInstance = this;
    setContentView(R.layout.main);

    // Set up member variables to UI Elements
    mTextViewDataMindset = (TextView) findViewById(R.id.textViewData);
    mTextViewDataShimmerEcg = (TextView) findViewById(R.id.textViewDataShimmerEcg);
    mTextViewDataShimmerGsr = (TextView) findViewById(R.id.textViewDataShimmerGsr);
    mTextViewDataShimmerEmg = (TextView) findViewById(R.id.textViewDataShimmerEmg);

    // ----------------------------------------------------
    // Initialize SPINE by passing the fileName with the configuration properties
    // ----------------------------------------------------
    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();
    try {
        mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, "Exception creating SPINE manager: " + e.toString());
        Log.e(TAG,
                "Check to see that valid defaults.properties, and SpineTestApp.properties files exist in the Assets folder!");
        e.printStackTrace();
    }

    // ... then we need to register a SPINEListener implementation to the SPINE manager instance
    // to receive sensor node data from the Spine server
    // (I register myself since I'm a SPINEListener implementation!)
    mSpineManager.addListener(this);

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);

    // Set up filter intents so we can receive broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.t2.biofeedback.service.status.BROADCAST");
    this.registerReceiver(this.mCommandReceiver, filter);

    try {
        mCurrentMindsetData = new MindsetData(this);
    } catch (Exception e1) {
        Log.e(TAG, "Exception creating MindsetData: " + e1.toString());
    }

    // Since Mindset is a static node we have to manually put it in the active node list
    // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor
    Node MindsetNode = null;
    MindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET));
    mSpineManager.getActiveNodes().add(MindsetNode);

    // Since Shimmer is a static node we have to manually put it in the active node list
    mShimmerNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_SHIMMER));
    mSpineManager.getActiveNodes().add(mShimmerNode);

    // Set up graph(s)
    mSeries = new XYSeries("parameter");
    generateChart();

}

From source file:com.android.leanlauncher.IconCache.java

public void loadIconPackDrawables(boolean forceReload) {
    final long t = SystemClock.uptimeMillis();
    synchronized (mIconPackDrawables) {
        if (!forceReload && mIconPackDrawables.size() > 0) {
            return;
        }/*  w w  w.  j a v  a  2s.  c  o m*/

        // load appfilter.xml from the icon pack package
        try {
            XmlPullParser xpp = null;

            final Resources iconPackRes = getIconPackResources();
            if (iconPackRes == null) {
                return;
            }

            int appfilterid = iconPackRes.getIdentifier("appfilter", "xml", mCurrentIconTheme);
            if (appfilterid > 0) {
                xpp = iconPackRes.getXml(appfilterid);
            } else {
                // no resource found, try to open it from assets folder
                try {
                    InputStream is = iconPackRes.getAssets().open("appfilter.xml");

                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    xpp = factory.newPullParser();
                    xpp.setInput(is, "utf-8");
                } catch (IOException e) {
                    Log.d(TAG, "Can't find appfilter.xml file in : " + mCurrentIconTheme);
                }
            }

            if (xpp != null) {
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG) {
                        if ("item".equals(xpp.getName())) {
                            String componentName = null;
                            String drawableName = null;

                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if ("component".equals(xpp.getAttributeName(i))) {
                                    componentName = xpp.getAttributeValue(i);
                                } else if ("drawable".equals(xpp.getAttributeName(i))) {
                                    drawableName = xpp.getAttributeValue(i);
                                }
                            }

                            if (TextUtils.isEmpty(componentName) || TextUtils.isEmpty(drawableName)) {
                                eventType = xpp.next();
                                continue;
                            }

                            try {
                                componentName = componentName.substring(componentName.indexOf('{') + 1,
                                        componentName.indexOf('}'));
                            } catch (StringIndexOutOfBoundsException e) {
                                Log.d(TAG, "Can't parse icon for package = " + componentName);
                                eventType = xpp.next();
                                continue;
                            }

                            ComponentName componentNameKey = ComponentName.unflattenFromString(componentName);
                            if (componentNameKey != null) {
                                mIconPackDrawables.put(componentNameKey, drawableName);
                            } else {
                                Log.d(TAG, "ComponentName can't be obtained from: " + componentName);
                            }
                        } else if ("iconback".equals(xpp.getName())) {
                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if (xpp.getAttributeName(i).startsWith("img")) {
                                    mIconBackgrounds.add(loadBitmapFromIconPack(xpp.getAttributeValue(i)));
                                }
                            }
                        } else if ("iconmask".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconMask = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("iconupon".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconFront = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("scale".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "factor".equals(xpp.getAttributeName(0))) {
                                mIconScaleFactor = Float.valueOf(xpp.getAttributeValue(0));
                            }
                        }
                    }
                    eventType = xpp.next();
                }
            }
            Log.d(TAG, "Finished parsing icon pack: " + (SystemClock.uptimeMillis() - t) + "ms");
        } catch (XmlPullParserException e) {
            Log.d(TAG, "Cannot parse icon pack appfilter.xml" + e);
        } catch (IOException e) {
            Log.d(TAG, "Exception loading icon pack " + e);
        }
    }
}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()");

    // We don't want the screen to timeout in this activity
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView
    setContentView(R.layout.graphs_activity_layout);
    mInstance = this;

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true);
    mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false);
    mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false);

    mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false);

    if (mAntHrmEnabled) {
        mHeartRateSource = HEARTRATE_ANT;
    } else {/*w w  w . j a v  a  2 s .  c  o m*/
        mHeartRateSource = HEARTRATE_ZEPHYR;
    }

    // The session start time will be used as session id
    // Note this also sets session start time
    // **** This session ID will be prepended to all JSON data stored
    //      in the external database until it's changed (by the start
    //      of a new session.
    Calendar cal = Calendar.getInstance();
    SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US);
    String sessionDate = sdf.format(new Date());
    String userId = SharedPref.getString(this, "SelectedUser", "");
    long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0);

    mDataOutHandler = new DataOutHandler(this, userId, sessionDate, mAppId,
            DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId);

    if (mDatabaseEnabled) {
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String myNumber = telephonyManager.getLine1Number();

        String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name",
                getString(R.string.database_uri));
        //            remoteDatabaseUri += myNumber; 

        Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove
        try {
            mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName,
                    remoteDatabaseUri);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }
        mDataOutHandler.setRequiresAuthentication(false);

    }

    mBioDataProcessor.initialize(mDataOutHandler);

    if (mLoggingEnabled) {
        mDataOutHandler.enableLogging(this);
    }

    if (mLogCatEnabled) {
        mDataOutHandler.enableLogCat();
    }

    // Log the version
    try {
        PackageManager packageManager = getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0);
        mApplicationVersion = info.versionName;
        String versionString = mAppId + " application version: " + mApplicationVersion;

        DataOutPacket packet = new DataOutPacket();
        packet.add(DataOutHandlerTags.version, versionString);
        try {
            mDataOutHandler.handleDataOut(packet);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    // Set up UI elements
    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();

    mPauseButton = (Button) findViewById(R.id.buttonPause);
    mAddMeasureButton = (Button) findViewById(R.id.buttonAddMeasure);
    mTextInfoView = (TextView) findViewById(R.id.textViewInfo);
    mMeasuresDisplayText = (TextView) findViewById(R.id.measuresDisplayText);

    // Don't actually show skin conductance meter unless we get samples
    ImageView image = (ImageView) findViewById(R.id.imageView1);
    image.setImageResource(R.drawable.signal_bars0);

    // Check to see of there a device configured for EEG, if so then show the skin conductance meter
    String tmp = SharedPref.getString(this, "EEG", null);

    if (tmp != null) {
        image.setVisibility(View.VISIBLE);
    } else {
        image.setVisibility(View.INVISIBLE);
    }

    // Initialize SPINE by passing the fileName with the configuration properties
    try {
        mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, "Exception creating SPINE manager: " + e.toString());
        e.printStackTrace();
    }

    try {
        currentMindsetData = new MindsetData(this);
    } catch (Exception e1) {
        Log.e(TAG, "Exception creating MindsetData: " + e1.toString());
        e1.printStackTrace();
    }

    // Establish nodes for BSPAN

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);

    int itemId = 0;
    eegPos = itemId; // eeg always comes first
    mBioParameters.clear();

    // First create GraphBioParameters for each of the EEG static params (ie mindset)
    for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation
        GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true);
        param.isShimmer = false;
        mBioParameters.add(param);
    }

    // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, EEG, HR, Skin Temp, Resp Rate
    //       String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names);
    String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names_less_eeg);

    for (String paramName : paramNamesStringArray) {
        if (paramName.equalsIgnoreCase("not assigned"))
            continue;

        GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true);

        if (paramName.equalsIgnoreCase("gsr")) {
            gsrPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("emg")) {
            emgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("ecg")) {
            ecgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("heart rate")) {
            heartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("resp rate")) {
            respRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("skin temp")) {
            skinTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Airflow")) {
            eHealthAirFlowPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Temp")) {
            eHealthTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth SpO2")) {
            eHealthSpO2Pos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Heartrate")) {
            eHealthHeartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth GSR")) {
            eHealthGSRPos = itemId;
            param.isShimmer = false;
        }

        itemId++;
        mBioParameters.add(param);
    }

    // Since These are static nodes (Non-spine) we have to manually put them in the active node list
    Node mindsetNode = null;
    mindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET)); // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor
    mManager.getActiveNodes().add(mindsetNode);

    Node zepherNode = null;
    zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR));
    mManager.getActiveNodes().add(zepherNode);

    // The arduino node is programmed to look like a static Spine node
    // Note that currently we don't have  to turn it on or off - it's always streaming
    // Since Spine (in this case) is a static node we have to manually put it in the active node list
    // Since the 
    final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001
    mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE));
    mManager.getActiveNodes().add(mSpineNode);

    final String sessionName;

    // Check to see if we were requested to play back a previous session
    try {
        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            sessionName = bundle.getString(BioZenConstants.EXTRA_SESSION_NAME);

            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle("Replay Session " + sessionName + "?");
            alert.setMessage("Make sure to turn off all Bluetooth Sensors!");

            alert.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    try {
                        mDataOutHandler.logNote("Replaying data from session " + sessionName);
                    } catch (DataOutHandlerException e) {
                        Log.e(TAG, e.toString());
                        e.printStackTrace();
                    }

                    replaySessionData(sessionName);
                    AlertDialog.Builder alert1 = new AlertDialog.Builder(mInstance);
                    alert1.setTitle("INFO");
                    alert1.setMessage("Replay of session complete!");
                    alert1.show();

                }
            });
            alert.show();
        }

    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    if (mInternalSensorMonitoring) {
        // IntentSender Launches our service scheduled with with the alarm manager 
        mBigBrotherService = PendingIntent.getService(Graphs1Activity.this, 0,
                new Intent(Graphs1Activity.this, BigBrotherService.class), 0);

        long firstTime = SystemClock.elapsedRealtime();
        // Schedule the alarm!
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000,
                mBigBrotherService);

        // Tell the user about what we did.
        Toast.makeText(Graphs1Activity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show();

    }

    //testFIRFilter();

    //       testHR();

}

From source file:com.t2.compassionMeditation.MeditationActivity.java

/** Called when the activity is first created. */
@Override//from www  .j a va  2s  .  c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()");

    mInstance = this;
    mRateOfChange = new RateOfChange(mRateOfChangeSize);

    mIntroFade = 255;

    // We don't want the screen to timeout in this activity
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView

    setContentView(R.layout.buddah_activity_layout);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    currentMindsetData = new MindsetData(this);
    mSaveRawWave = SharedPref.getBoolean(this, BioZenConstants.PREF_SAVE_RAW_WAVE,
            BioZenConstants.PREF_SAVE_RAW_WAVE_DEFAULT);

    mShowAGain = SharedPref.getBoolean(this, BioZenConstants.PREF_SHOW_A_GAIN,
            BioZenConstants.PREF_SHOW_A_GAIN_DEFAULT);

    mAllowComments = SharedPref.getBoolean(this, BioZenConstants.PREF_COMMENTS,
            BioZenConstants.PREF_COMMENTS_DEFAULT);

    mShowForeground = SharedPref.getBoolean(this, "show_lotus", true);
    mShowToast = SharedPref.getBoolean(this, "show_toast", true);

    mAudioTrackResourceName = SharedPref.getString(this, "audio_track", "None");
    mBaseImageResourceName = SharedPref.getString(this, "background_images", "Sunset");

    mBioHarnessParameters = getResources().getStringArray(R.array.bioharness_parameters_array);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    String s = SharedPref.getString(this, BioZenConstants.PREF_SESSION_LENGTH, "10");
    mSecondsRemaining = Integer.parseInt(s) * 60;
    mSecondsTotal = mSecondsRemaining;

    s = SharedPref.getString(this, BioZenConstants.PREF_ALPHA_GAIN, "5");
    mAlphaGain = Float.parseFloat(s);

    mMovingAverage = new TMovingAverageFilter(mMovingAverageSize);
    mMovingAverageROC = new TMovingAverageFilter(mMovingAverageSizeROC);

    View v1 = findViewById(R.id.buddahView);
    v1.setOnTouchListener(this);

    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();

    // Set up member variables to UI Elements
    mTextInfoView = (TextView) findViewById(R.id.textViewInfo);
    mTextBioHarnessView = (TextView) findViewById(R.id.textViewBioHarness);
    mCountdownTextView = (TextView) findViewById(R.id.countdownTextView);
    mCountdownImageView = (ImageView) findViewById(R.id.imageViewCountdown);

    mPauseButton = (ImageButton) findViewById(R.id.buttonPause);
    mSignalImage = (ImageView) findViewById(R.id.imageView1);
    mTextViewInstructions = (TextView) findViewById(R.id.textViewInstructions);

    // Note that the seek bar is a debug thing - used only to set the
    // alpha of the buddah image manually for visual testing
    mSeekBar = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBar.setOnSeekBarChangeListener(this);

    // Scale such that values to the right of center are scaled 1 - 10
    // and values to the left of center are scaled 0 = .99999
    if (mAlphaGain > 1.0) {
        mSeekBar.setProgress(50 + (int) (mAlphaGain * 5));
    } else {
        int i = (int) (mAlphaGain * 50);
        mSeekBar.setProgress(i);
    }
    //      mSeekBar.setProgress((int) mAlphaGain * 10);      

    // Controls start as invisible, need to touch screen to activate them
    mCountdownTextView.setVisibility(View.INVISIBLE);
    mCountdownImageView.setVisibility(View.INVISIBLE);
    mTextInfoView.setVisibility(View.INVISIBLE);
    mTextBioHarnessView.setVisibility(View.INVISIBLE);
    mPauseButton.setVisibility(View.INVISIBLE);
    mPauseButton.setVisibility(View.VISIBLE);
    mSeekBar.setVisibility(View.INVISIBLE);

    mBackgroundImage = (ImageView) findViewById(R.id.buddahView);
    mForegroundImage = (ImageView) findViewById(R.id.lotusView);
    mBaseImage = (ImageView) findViewById(R.id.backgroundView);

    if (!mShowForeground) {
        mForegroundImage.setVisibility(View.INVISIBLE);
    }

    int resource = 0;
    if (mBaseImageResourceName.equalsIgnoreCase("Buddah")) {
        mBackgroundImage.setImageResource(R.drawable.buddha);
        mForegroundImage.setImageResource(R.drawable.lotus_flower);
        mBaseImage.setImageResource(R.drawable.none_bg);
    } else if (mBaseImageResourceName.equalsIgnoreCase("Bob")) {
        mBackgroundImage.setImageResource(R.drawable.bigbob);
        mForegroundImage.setImageResource(R.drawable.red_nose);
        mBaseImage.setImageResource(R.drawable.none_bg);
    } else if (mBaseImageResourceName.equalsIgnoreCase("Sunset")) {
        mBackgroundImage.setImageResource(R.drawable.eeg_layer);
        mForegroundImage.setImageResource(R.drawable.breathing_rate);
        mBaseImage.setImageResource(R.drawable.meditation_bg);
    }

    // Initialize SPINE by passing the fileName with the configuration properties
    try {
        mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, "Exception creating SPINE manager: " + e.toString());
        e.printStackTrace();
    }

    // Since Mindset is a static node we have to manually put it in the active node list
    // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor
    Node mindsetNode = null;
    mindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET));
    mManager.getActiveNodes().add(mindsetNode);

    Node zepherNode = null;
    zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR));
    mManager.getActiveNodes().add(zepherNode);

    // The arduino node is programmed to look like a static Spine node
    // Note that currently we don't have  to turn it on or off - it's always streaming
    // Since Spine (in this case) is a static node we have to manually put it in the active node list
    // Since the 
    final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001
    mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE));
    mManager.getActiveNodes().add(mSpineNode);

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);

    try {
        PackageManager packageManager = this.getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0);
        mApplicationVersion = info.versionName;
        Log.i(TAG, "BioZen Application Version: " + mApplicationVersion + ", Activity Version: "
                + mActivityVersion);
    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    // First create GraphBioParameters for each of the ECG static params (ie mindset)      
    int itemId = 0;
    eegPos = itemId; // eeg always comes first
    mBioParameters.clear();

    for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation
        GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true);
        param.isShimmer = false;
        mBioParameters.add(param);
    }

    // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, HR, Skin Temp, Resp Rate
    String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names);

    for (String paramName : paramNamesStringArray) {
        if (paramName.equalsIgnoreCase("not assigned"))
            continue;

        if (paramName.equalsIgnoreCase("EEG"))
            continue;

        GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true);

        if (paramName.equalsIgnoreCase("gsr")) {
            gsrPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("emg")) {
            emgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("ecg")) {
            ecgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("heart rate")) {
            heartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("resp rate")) {
            respRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("skin temp")) {
            skinTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Airflow")) {
            eHealthAirFlowPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Temp")) {
            eHealthTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth SpO2")) {
            eHealthSpO2Pos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Heartrate")) {
            eHealthHeartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth GSR")) {
            eHealthGSRPos = itemId;
            param.isShimmer = false;
        }

        itemId++;
        mBioParameters.add(param);
    }

    // The session start time will be used as session id
    // Note this also sets session start time
    // **** This session ID will be prepended to all JSON data stored
    //      in the external database until it's changed (by the start
    //      of a new session.
    Calendar cal = Calendar.getInstance();
    SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US);
    String sessionDate = sdf.format(new Date());
    long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0);

    mUserId = SharedPref.getString(this, "SelectedUser", "");

    // Now get the database object associated with this user

    try {
        mBioUserDao = getHelper().getBioUserDao();
        mBioSessionDao = getHelper().getBioSessionDao();

        QueryBuilder<BioUser, Integer> builder = mBioUserDao.queryBuilder();
        builder.where().eq(BioUser.NAME_FIELD_NAME, mUserId);
        builder.limit(1);
        //         builder.orderBy(ClickCount.DATE_FIELD_NAME, false).limit(30);
        List<BioUser> list = mBioUserDao.query(builder.prepare());

        if (list.size() == 1) {
            mCurrentBioUser = list.get(0);
        } else if (list.size() == 0) {
            try {
                mCurrentBioUser = new BioUser(mUserId, System.currentTimeMillis());
                mBioUserDao.create(mCurrentBioUser);
            } catch (SQLException e1) {
                Log.e(TAG, "Error creating user " + mUserId, e1);
            }
        } else {
            Log.e(TAG, "General Database error" + mUserId);
        }

    } catch (SQLException e) {
        Log.e(TAG, "Can't find user: " + mUserId, e);

    }

    mSignalImage.setImageResource(R.drawable.signal_bars0);

    // Check to see of there a device configured for EEG, if so then show the skin conductance meter
    String tmp = SharedPref.getString(this, "EEG", null);

    if (tmp != null) {
        mSignalImage.setVisibility(View.VISIBLE);
        mTextViewInstructions.setVisibility(View.VISIBLE);

    } else {
        mSignalImage.setVisibility(View.INVISIBLE);
        mTextViewInstructions.setVisibility(View.INVISIBLE);
    }

    mDataOutHandler = new DataOutHandler(this, mUserId, sessionDate, mAppId,
            DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId);

    if (mDatabaseEnabled) {
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String myNumber = telephonyManager.getLine1Number();

        String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name",
                getString(R.string.database_uri));
        //            remoteDatabaseUri += myNumber; 

        Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove
        try {
            mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName,
                    remoteDatabaseUri);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }
        mDataOutHandler.setRequiresAuthentication(false);
    }

    mBioDataProcessor.initialize(mDataOutHandler);

    mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true);
    mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false);
    mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false);

    mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false);

    if (mAntHrmEnabled) {
        mHeartRateSource = HEARTRATE_ANT;
    } else {
        mHeartRateSource = HEARTRATE_ZEPHYR;
    }

    if (mLoggingEnabled) {
        mDataOutHandler.enableLogging(this);
    }

    if (mLogCatEnabled) {
        mDataOutHandler.enableLogCat();
    }

    // Log the version
    try {
        PackageManager packageManager = getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0);
        mApplicationVersion = info.versionName;
        String versionString = mAppId + " application version: " + mApplicationVersion;

        DataOutPacket packet = new DataOutPacket();
        packet.add(DataOutHandlerTags.version, versionString);
        try {
            mDataOutHandler.handleDataOut(packet);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    if (mInternalSensorMonitoring) {
        // IntentSender Launches our service scheduled with with the alarm manager 
        mBigBrotherService = PendingIntent.getService(MeditationActivity.this, 0,
                new Intent(MeditationActivity.this, BigBrotherService.class), 0);

        long firstTime = SystemClock.elapsedRealtime();
        // Schedule the alarm!
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000,
                mBigBrotherService);

        // Tell the user about what we did.
        Toast.makeText(MeditationActivity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show();

    }

}

From source file:org.openintents.notepad.NoteEditor.java

private boolean setRemoteStyle(String styleName, int size) {
    if (TextUtils.isEmpty(styleName)) {
        if (DEBUG) {
            Log.e(TAG, "Empty style name: " + styleName);
        }//  w  w w.jav  a 2  s  .c o  m
        return false;
    }

    PackageManager pm = getPackageManager();

    String packageName = ThemeUtils.getPackageNameFromStyle(styleName);

    if (packageName == null) {
        Log.e(TAG, "Invalid style name: " + styleName);
        return false;
    }

    Context c = null;
    try {
        c = createPackageContext(packageName, 0);
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Package for style not found: " + packageName + ", " + styleName);
        return false;
    }

    Resources res = c.getResources();

    int themeid = res.getIdentifier(styleName, null, null);
    if (DEBUG) {
        Log.d(TAG, "Retrieving theme: " + styleName + ", " + themeid);
    }

    if (themeid == 0) {
        Log.e(TAG, "Theme name not found: " + styleName);
        return false;
    }

    try {
        ThemeAttributes ta = new ThemeAttributes(c, packageName, themeid);

        mTextTypeface = ta.getString(ThemeNotepad.TEXT_TYPEFACE);
        if (DEBUG) {
            Log.d(TAG, "textTypeface: " + mTextTypeface);
        }

        mCurrentTypeface = null;

        // Look for special cases:
        if ("monospace".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL);
        } else if ("sans".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
        } else if ("serif".equals(mTextTypeface)) {
            mCurrentTypeface = Typeface.create(Typeface.SERIF, Typeface.NORMAL);
        } else if (!TextUtils.isEmpty(mTextTypeface)) {

            try {
                if (DEBUG) {
                    Log.d(TAG, "Reading typeface: package: " + packageName + ", typeface: " + mTextTypeface);
                }
                Resources remoteRes = pm.getResourcesForApplication(packageName);
                mCurrentTypeface = Typeface.createFromAsset(remoteRes.getAssets(), mTextTypeface);
                if (DEBUG) {
                    Log.d(TAG, "Result: " + mCurrentTypeface);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Package not found for Typeface", e);
            }
        }

        mTextUpperCaseFont = ta.getBoolean(ThemeNotepad.TEXT_UPPER_CASE_FONT, false);

        mTextColor = ta.getColor(ThemeNotepad.TEXT_COLOR, android.R.color.white);

        if (DEBUG) {
            Log.d(TAG, "textColor: " + mTextColor);
        }

        if (size == 0) {
            mTextSize = getTextSizeTiny(ta);
        } else if (size == 1) {
            mTextSize = getTextSizeSmall(ta);
        } else if (size == 2) {
            mTextSize = getTextSizeMedium(ta);
        } else {
            mTextSize = getTextSizeLarge(ta);
        }
        if (DEBUG) {
            Log.d(TAG, "textSize: " + mTextSize);
        }

        if (mText != null) {
            mBackgroundPadding = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING, -1);
            int backgroundPaddingLeft = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_LEFT,
                    mBackgroundPadding);
            int backgroundPaddingTop = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_TOP,
                    mBackgroundPadding);
            int backgroundPaddingRight = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_RIGHT,
                    mBackgroundPadding);
            int backgroundPaddingBottom = ta.getDimensionPixelOffset(ThemeNotepad.BACKGROUND_PADDING_BOTTOM,
                    mBackgroundPadding);

            if (DEBUG) {
                Log.d(TAG,
                        "Padding: " + mBackgroundPadding + "; " + backgroundPaddingLeft + "; "
                                + backgroundPaddingTop + "; " + backgroundPaddingRight + "; "
                                + backgroundPaddingBottom + "; ");
            }

            try {
                Resources remoteRes = pm.getResourcesForApplication(packageName);
                int resid = ta.getResourceId(ThemeNotepad.BACKGROUND, 0);
                if (resid != 0) {
                    Drawable d = remoteRes.getDrawable(resid);
                    mText.setBackgroundDrawable(d);
                } else {
                    // remove background
                    mText.setBackgroundResource(0);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Package not found for Theme background.", e);
            } catch (Resources.NotFoundException e) {
                Log.e(TAG, "Resource not found for Theme background.", e);
            }

            // Apply padding
            if (mBackgroundPadding >= 0 || backgroundPaddingLeft >= 0 || backgroundPaddingTop >= 0
                    || backgroundPaddingRight >= 0 || backgroundPaddingBottom >= 0) {
                mText.setPadding(backgroundPaddingLeft, backgroundPaddingTop, backgroundPaddingRight,
                        backgroundPaddingBottom);
            } else {
                // 9-patches do the padding automatically
                // todo clear padding
            }
        }

        mLinesMode = ta.getInteger(ThemeNotepad.LINE_MODE, 2);
        mLinesColor = ta.getColor(ThemeNotepad.LINE_COLOR, 0xFF000080);

        if (DEBUG) {
            Log.d(TAG, "line color: " + mLinesColor);
        }

        return true;

    } catch (UnsupportedOperationException e) {
        // This exception is thrown e.g. if one attempts
        // to read an integer attribute as dimension.
        Log.e(TAG, "UnsupportedOperationException", e);
        return false;
    } catch (NumberFormatException e) {
        // This exception is thrown e.g. if one attempts
        // to read a string as integer.
        Log.e(TAG, "NumberFormatException", e);
        return false;
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Finds all the views we need and configure them properly.
 *//*from  w w w . j  a  v  a2s. c om*/
private void setupViews() {
    //CERTIFICATE
    layout = (LinearLayout) findViewById(R.id.launcher_parent_layout);

    /*   if(!PersonaMainActivity.isRovaPoliciesOn)
          layout.setBackgroundResource(R.drawable.pr_bg);*/

    mDragLayer = (PersonaDragLayer) findViewById(R.id.drag_layer);
    final PersonaDragLayer personaDragLayer = mDragLayer;

    mWorkspace = (PersonaWorkspace) personaDragLayer.findViewById(R.id.workspace);
    final PersonaWorkspace personaWorkspace = mWorkspace;
    // ADW: The app drawer is now a ViewStub and we load the resource
    // depending on custom settings
    ViewStub tmp = (ViewStub) personaDragLayer.findViewById(R.id.stub_drawer);
    int drawerStyle = PersonaAlmostNexusSettingsHelper.getDrawerStyle(this);
    tmp.setLayoutResource(mDrawerStyles[drawerStyle]);
    mAllAppsGrid = (PersonaDrawer) tmp.inflate();
    mDeleteZone = (PersonaDeleteZone) personaDragLayer.findViewById(R.id.delete_zone);

    mHandleView = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_mab);
    mHandleView.setFocusable(true);
    mHandleView.setLauncher(this);
    mHandleView.setOnClickListener(this);
    personaDragLayer.addDragListener(mHandleView);
    /*
     * mHandleView.setOnTriggerListener(new OnTriggerListener() { public
     * void onTrigger(View v, int whichHandle) { mDockBar.open(); } public
     * void onGrabbedStateChange(View v, boolean grabbedState) { } public
     * void onClick(View v) { if (allAppsOpen) { closeAllApps(true); } else
     * { showAllApps(true, null); } } });
     */
    mAllAppsGrid.setTextFilterEnabled(false);
    mAllAppsGrid.setDragger(personaDragLayer);
    mAllAppsGrid.setLauncher(this);

    personaWorkspace.setOnLongClickListener(this);
    personaWorkspace.setDragger(personaDragLayer);
    personaWorkspace.setLauncher(this);

    mDeleteZone.setLauncher(this);
    mDeleteZone.setDragController(personaDragLayer);

    personaDragLayer.setIgnoredDropTarget((View) mAllAppsGrid);
    personaDragLayer.setDragScoller(personaWorkspace);
    personaDragLayer.addDragListener(mDeleteZone);
    // ADW: Dockbar inner icon viewgroup (PersonaMiniLauncher.java)
    mMiniLauncher = (PersonaMiniLauncher) personaDragLayer.findViewById(R.id.mini_content);
    mMiniLauncher.setLauncher(this);
    mMiniLauncher.setOnLongClickListener(this);
    mMiniLauncher.setDragger(personaDragLayer);
    personaDragLayer.addDragListener(mMiniLauncher);

    // ADW: Action Buttons (LAB/RAB)
    mLAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab);
    PersonaLog.d("personalauncher", "lab rab componenets initialized");
    mLAB.setLauncher(this);
    mLAB.setSpecialIcon(R.drawable.pr_arrow_left);
    mLAB.setSpecialAction(ACTION_CATALOG_PREV);
    personaDragLayer.addDragListener(mLAB);
    mRAB = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab);
    mRAB.setLauncher(this);
    mRAB.setSpecialIcon(R.drawable.pr_arrow_right);
    mRAB.setSpecialAction(ACTION_CATALOG_NEXT);
    personaDragLayer.addDragListener(mRAB);
    mLAB.setOnClickListener(this);
    mRAB.setOnClickListener(this);
    // ADW: secondary aActionButtons
    mLAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_lab2);
    mLAB2.setLauncher(this);
    personaDragLayer.addDragListener(mLAB2);
    mRAB2 = (PersonaActionButton) personaDragLayer.findViewById(R.id.btn_rab2);
    mRAB2.setLauncher(this);
    personaDragLayer.addDragListener(mRAB2);
    mLAB2.setOnClickListener(this);
    mRAB2.setOnClickListener(this);
    // ADW: Dots ImageViews
    mPreviousView = (ImageView) findViewById(R.id.btn_scroll_left);
    mNextView = (ImageView) findViewById(R.id.btn_scroll_right);
    mPreviousView.setOnLongClickListener(this);
    mNextView.setOnLongClickListener(this);

    // ADW: ActionButtons swipe gestures
    mHandleView.setSwipeListener(this);
    mLAB.setSwipeListener(this);
    mLAB2.setSwipeListener(this);
    mRAB.setSwipeListener(this);
    mRAB2.setSwipeListener(this);

    // mHandleView.setDragger(dragLayer);
    // mLAB.setDragger(dragLayer);
    // mRAB.setDragger(dragLayer);
    mRAB2.setDragger(personaDragLayer);
    mLAB2.setDragger(personaDragLayer);

    // ADW linearlayout with apptray, lab and rab
    mDrawerToolbar = findViewById(R.id.drawer_toolbar);
    mHandleView.setNextFocusUpId(R.id.drag_layer);
    mHandleView.setNextFocusLeftId(R.id.drag_layer);
    mLAB.setNextFocusUpId(R.id.drag_layer);
    mLAB.setNextFocusLeftId(R.id.drag_layer);
    mRAB.setNextFocusUpId(R.id.drag_layer);
    mRAB.setNextFocusLeftId(R.id.drag_layer);
    mLAB2.setNextFocusUpId(R.id.drag_layer);
    mLAB2.setNextFocusLeftId(R.id.drag_layer);
    mRAB2.setNextFocusUpId(R.id.drag_layer);
    mRAB2.setNextFocusLeftId(R.id.drag_layer);
    // ADW add a listener to the dockbar to show/hide the app-drawer-button
    // and the dots
    mDockBar = (PersonaDockBar) findViewById(R.id.dockbar);
    mDockBar.setDockBarListener(new DockBarListener() {
        public void onOpen() {
            mDrawerToolbar.setVisibility(View.GONE);
            if (mNextView.getVisibility() == View.VISIBLE) {
                mNextView.setVisibility(View.INVISIBLE);
                mPreviousView.setVisibility(View.INVISIBLE);
            }
        }

        public void onClose() {
            if (mDockStyle != DOCK_STYLE_NONE)
                mDrawerToolbar.setVisibility(View.VISIBLE);
            if (showDots && !isAllAppsVisible()) {
                mNextView.setVisibility(View.VISIBLE);
                mPreviousView.setVisibility(View.VISIBLE);
            }

        }
    });
    if (PersonaAlmostNexusSettingsHelper.getDesktopIndicator(this)) {
        mDesktopIndicator = (PersonaDesktopIndicator) (findViewById(R.id.desktop_indicator));
    }
    // ADW: Add focusability to screen items
    mLAB.setFocusable(true);
    mRAB.setFocusable(true);
    mLAB2.setFocusable(true);
    mRAB2.setFocusable(true);
    mPreviousView.setFocusable(true);
    mNextView.setFocusable(true);

    // ADW: Load the specified theme
    String themePackage = PersonaAlmostNexusSettingsHelper.getThemePackageName(this, THEME_DEFAULT);
    PackageManager pm = getPackageManager();
    Resources themeResources = null;
    if (!themePackage.equals(THEME_DEFAULT)) {
        try {
            themeResources = pm.getResourcesForApplication(themePackage);
        } catch (NameNotFoundException e) {
            // ADW The saved theme was uninstalled so we save the default
            // one
            PersonaAlmostNexusSettingsHelper.setThemePackageName(this, PersonaLauncher.THEME_DEFAULT);
        }
    }
    if (themeResources != null) {
        // Action Buttons
        loadThemeResource(themeResources, themePackage, "lab_bg", mLAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab_bg", mRAB, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "lab2_bg", mLAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "rab2_bg", mRAB2, THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "mab_bg", mHandleView, THEME_ITEM_BACKGROUND);
        // App drawer button
        // loadThemeResource(themeResources,themePackage,"handle_icon",mHandleView,THEME_ITEM_FOREGROUND);
        // View appsBg=findViewById(R.id.appsBg);
        // loadThemeResource(themeResources,themePackage,"handle",appsBg,THEME_ITEM_BACKGROUND);
        // Deletezone
        loadThemeResource(themeResources, themePackage, "ic_delete", mDeleteZone, THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "delete_zone_selector", mDeleteZone,
                THEME_ITEM_BACKGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_left", mPreviousView,
                THEME_ITEM_FOREGROUND);
        loadThemeResource(themeResources, themePackage, "home_arrows_right", mNextView, THEME_ITEM_FOREGROUND);
        // Dockbar
        loadThemeResource(themeResources, themePackage, "dockbar_bg", mMiniLauncher, THEME_ITEM_BACKGROUND);
        try {
            themeFont = Typeface.createFromAsset(themeResources.getAssets(), "themefont.ttf");
        } catch (RuntimeException e) {
            // TODO: handle exception
        }
    }
    Drawable previous = mPreviousView.getDrawable();
    Drawable next = mNextView.getDrawable();
    mWorkspace.setIndicators(previous, next);

    // ADW: EOF Themes
    updateAlmostNexusUI();
}