Example usage for android.os Bundle getByteArray

List of usage examples for android.os Bundle getByteArray

Introduction

In this page you can find the example usage for android.os Bundle getByteArray.

Prototype

@Override
@Nullable
public byte[] getByteArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:org.jboss.aerogear.android.pipe.loader.LoaderAdapter.java

@Override
public Loader<HeaderAndBody> onCreateLoader(int id, Bundle bundle) {
    addId(name, id);/*from  ww  w  .  j  a  va 2  s  .  co  m*/

    Methods method = (Methods) bundle.get(METHOD);
    Callback callback = (Callback) bundle.get(CALLBACK);
    verifyCallback(callback);
    AbstractPipeLoader loader = null;
    switch (method) {
    case READ: {
        ReadFilter filter = (ReadFilter) bundle.get(FILTER);
        loader = new ReadLoader(applicationContext, callback, pipe.getHandler(), filter, this);
    }
        break;
    case READ_ID: {
        ReadFilter filter = (ReadFilter) bundle.get(FILTER);
        loader = new IdReadLoader(applicationContext, callback, pipe.getHandler(), filter, this);
    }
        break;
    case REMOVE: {
        String toRemove = bundle.getString(REMOVE_ID, "-1");
        loader = new RemoveLoader(applicationContext, callback, pipe.getHandler(), toRemove);
    }
        break;
    case SAVE: {
        byte[] data = bundle.getByteArray(ITEM);
        String dataId = bundle.getString(SAVE_ID);
        loader = new SaveLoader(applicationContext, callback, pipe.getHandler(), data, dataId);
    }
        break;
    }
    return loader;
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindFragmentArgument(Fragment receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*from   www  .j av  a 2  s . com*/
        FragmentArgument fragmentArgument = field.getAnnotation(FragmentArgument.class);
        if (fragmentArgument != null) {
            try {
                Bundle bundle = receiver.getArguments();
                if (bundle != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, bundle.getBoolean(fragmentArgument.value()));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, bundle.getByte(fragmentArgument.value()));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, bundle.getChar(fragmentArgument.value()));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, bundle.getDouble(fragmentArgument.value()));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, bundle.getFloat(fragmentArgument.value()));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, bundle.getInt(fragmentArgument.value()));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, bundle.getLong(fragmentArgument.value()));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, bundle.getShort(fragmentArgument.value()));
                    } else if (type == String.class) {
                        field.set(receiver, bundle.getString(fragmentArgument.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, bundle.getBooleanArray(fragmentArgument.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, bundle.getByteArray(fragmentArgument.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, bundle.getCharArray(fragmentArgument.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, bundle.getDoubleArray(fragmentArgument.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, bundle.getFloatArray(fragmentArgument.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, bundle.getIntArray(fragmentArgument.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, bundle.getLongArray(fragmentArgument.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, bundle.getShortArray(fragmentArgument.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, bundle.getStringArray(fragmentArgument.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, bundle.getSerializable(fragmentArgument.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, bundle.getBundle(fragmentArgument.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.sufficientlysecure.keychain.ui.CreateKeyActivity.java

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

    // React on NDEF_DISCOVERED from Manifest
    // NOTE: ACTION_NDEF_DISCOVERED and not ACTION_TAG_DISCOVERED like in BaseNfcActivity
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {

        mNfcTagDispatcher.interceptIntent(getIntent());

        setTitle(R.string.title_manage_my_keys);

        // done/*ww w  .j  a va2  s. c o  m*/
        return;
    }

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore value of members from saved state
        mName = savedInstanceState.getString(EXTRA_NAME);
        mEmail = savedInstanceState.getString(EXTRA_EMAIL);
        mAdditionalEmails = savedInstanceState.getStringArrayList(EXTRA_ADDITIONAL_EMAILS);
        mPassphrase = savedInstanceState.getParcelable(EXTRA_PASSPHRASE);
        mFirstTime = savedInstanceState.getBoolean(EXTRA_FIRST_TIME);
        mCreateSecurityToken = savedInstanceState.getBoolean(EXTRA_CREATE_SECURITY_TOKEN);
        mSecurityTokenAid = savedInstanceState.getByteArray(EXTRA_SECURITY_TOKEN_AID);
        mSecurityTokenPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_PIN);
        mSecurityTokenAdminPin = savedInstanceState.getParcelable(EXTRA_SECURITY_TOKEN_ADMIN_PIN);

        mCurrentFragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
    } else {

        Intent intent = getIntent();
        // Initialize members with default values for a new instance
        mName = intent.getStringExtra(EXTRA_NAME);
        mEmail = intent.getStringExtra(EXTRA_EMAIL);
        mFirstTime = intent.getBooleanExtra(EXTRA_FIRST_TIME, false);
        mCreateSecurityToken = intent.getBooleanExtra(EXTRA_CREATE_SECURITY_TOKEN, false);

        if (intent.hasExtra(EXTRA_SECURITY_FINGERPRINTS)) {
            byte[] nfcFingerprints = intent.getByteArrayExtra(EXTRA_SECURITY_FINGERPRINTS);
            String nfcUserId = intent.getStringExtra(EXTRA_SECURITY_TOKEN_USER_ID);
            byte[] nfcAid = intent.getByteArrayExtra(EXTRA_SECURITY_TOKEN_AID);

            if (containsKeys(nfcFingerprints)) {
                Fragment frag = CreateSecurityTokenImportResetFragment.newInstance(nfcFingerprints, nfcAid,
                        nfcUserId);
                loadFragment(frag, FragAction.START);

                setTitle(R.string.title_import_keys);
            } else {
                Fragment frag = CreateSecurityTokenBlankFragment.newInstance(nfcAid);
                loadFragment(frag, FragAction.START);
                setTitle(R.string.title_manage_my_keys);
            }

            // done
            return;
        }

        // normal key creation
        CreateKeyStartFragment frag = CreateKeyStartFragment.newInstance();
        loadFragment(frag, FragAction.START);
    }

    if (mFirstTime) {
        setTitle(R.string.app_name);
        mToolbar.setNavigationIcon(null);
        mToolbar.setNavigationOnClickListener(null);
    } else {
        setTitle(R.string.title_manage_my_keys);
    }
}

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);//  w ww  .  j  a v  a  2  s  .c o m
    setHasOptionsMenu(true);
    View layout = inflater.inflate(R.layout.lyrics_view, container, false);
    if (savedInstanceState != null)
        try {
            Lyrics l = Lyrics.fromBytes(savedInstanceState.getByteArray("lyrics"));
            if (l != null)
                this.mLyrics = l;
            mSearchQuery = savedInstanceState.getString("searchQuery");
            mSearchFocused = savedInstanceState.getBoolean("searchFocused");
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    else {
        Bundle args = getArguments();
        if (args != null)
            try {
                Lyrics lyrics = Lyrics.fromBytes(args.getByteArray("lyrics"));
                this.mLyrics = lyrics;
                if (lyrics != null && lyrics.getText() == null && lyrics.getArtist() != null) {
                    String artist = lyrics.getArtist();
                    String track = lyrics.getTitle();
                    String url = lyrics.getURL();
                    fetchLyrics(artist, track, url);
                    mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
                    startRefreshAnimation();
                }
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
    }
    if (layout != null) {
        Bundle args = savedInstanceState != null ? savedInstanceState : getArguments();

        boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity())
                .getBoolean("pref_force_screen_on", false);

        TextSwitcher textSwitcher = (TextSwitcher) layout.findViewById(R.id.switcher);
        textSwitcher.setFactory(new LyricsTextFactory(layout.getContext()));
        ActionMode.Callback callback = new CustomSelectionCallback(getActivity());
        ((TextView) textSwitcher.getChildAt(0)).setCustomSelectionActionModeCallback(callback);
        ((TextView) textSwitcher.getChildAt(1)).setCustomSelectionActionModeCallback(callback);
        textSwitcher.setKeepScreenOn(screenOn);
        layout.findViewById(R.id.lrc_view).setKeepScreenOn(screenOn);

        EditText artistTV = (EditText) getActivity().findViewById(R.id.artist);
        EditText songTV = (EditText) getActivity().findViewById(R.id.song);

        if (args != null && args.containsKey("editedLyrics")) {
            EditText editedLyrics = (EditText) layout.findViewById(R.id.edit_lyrics);
            textSwitcher.setVisibility(View.GONE);
            editedLyrics.setVisibility(View.VISIBLE);
            songTV.setInputType(InputType.TYPE_CLASS_TEXT);
            artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
            songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
            editedLyrics.setText(args.getCharSequence("editedLyrics"), TextView.BufferType.EDITABLE);
            songTV.setText(args.getCharSequence("editedTitle"), TextView.BufferType.EDITABLE);
            artistTV.setText(args.getCharSequence("editedArtist"), TextView.BufferType.EDITABLE);
        }

        artistTV.setTypeface(LyricsTextFactory.FontCache.get("regular", getActivity()));
        songTV.setTypeface(LyricsTextFactory.FontCache.get("medium", getActivity()));

        final RefreshIcon refreshFab = (RefreshIcon) getActivity().findViewById(R.id.refresh_fab);
        refreshFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mRefreshLayout.isRefreshing())
                    fetchCurrentLyrics(true);
            }
        });
        if (args != null)
            refreshFab.setEnabled(args.getBoolean("refreshFabEnabled", true));

        mScrollView = (NestedScrollView) layout.findViewById(R.id.scrollview);
        mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
        TypedValue primaryColor = new TypedValue();
        TypedValue accentColor = new TypedValue();
        getActivity().getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
        getActivity().getTheme().resolveAttribute(R.attr.colorAccent, accentColor, true);
        mRefreshLayout.setColorSchemeResources(primaryColor.resourceId, accentColor.resourceId);
        float offset = getResources().getDisplayMetrics().density * 64;
        mRefreshLayout.setProgressViewEndTarget(true, (int) offset);
        mRefreshLayout.setOnRefreshListener(this);

        final ImageButton editTagsButton = (ImageButton) getActivity().findViewById(R.id.edit_tags_btn);

        View.OnClickListener startEditClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startEditTagsMode();
                final View.OnClickListener startEditClickListener = this;
                editTagsButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        exitEditTagsMode();
                        editTagsButton.setOnClickListener(startEditClickListener);
                    }
                });
            }
        };
        editTagsButton.setOnClickListener(startEditClickListener);

        if (mLyrics == null) {
            if (!startEmpty)
                fetchCurrentLyrics(false);
        } else if (mLyrics.getFlag() == Lyrics.SEARCH_ITEM) {
            mRefreshLayout = (SwipeRefreshLayout) layout.findViewById(R.id.refresh_layout);
            startRefreshAnimation();
            if (mLyrics.getArtist() != null)
                fetchLyrics(mLyrics.getArtist(), mLyrics.getTitle());
            ((TextView) (getActivity().findViewById(R.id.artist))).setText(mLyrics.getArtist());
            ((TextView) (getActivity().findViewById(R.id.song))).setText(mLyrics.getTitle());
        } else //Rotation, resume
            update(mLyrics, layout, false);
    }
    if (broadcastReceiver == null)
        broadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                searchResultLock = false;
                String artist = intent.getStringExtra("artist");
                String track = intent.getStringExtra("track");
                if (artist != null && track != null && mRefreshLayout.isEnabled()) {
                    startRefreshAnimation();
                    new ParseTask(LyricsViewFragment.this, false, true).execute(mLyrics);
                }
            }
        };
    return layout;
}

From source file:org.kontalk.ui.NumberValidation.java

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

    mName = savedInstanceState.getString("name");
    mPhoneNumber = savedInstanceState.getString("phoneNumber");
    mKey = savedInstanceState.getParcelable("key");
    mPassphrase = savedInstanceState.getString("passphrase");
    mImportedPublicKey = savedInstanceState.getByteArray("importedPublicKey");
    mImportedPrivateKey = savedInstanceState.getByteArray("importedPrivateKey");
}

From source file:com.TagFu.facebook.Session.java

/**
 * Restores the saved session from a Bundle, if any. Returns the restored Session or null if it could not be
 * restored. This method is intended to be called from an Activity or Fragment's onCreate method when a Session has
 * previously been saved into a Bundle via saveState to preserve a Session across Activity lifecycle events.
 *
 * @param context the Activity or Service creating the Session, must not be null
 * @param cachingStrategy the TokenCachingStrategy to use to load and store the token. If this is null, a default
 *            token cachingStrategy that stores data in SharedPreferences will be used
 * @param callback the callback to notify for Session state changes, can be null
 * @param bundle the bundle to restore the Session from
 * @return the restored Session, or null
 *//*from   w  w  w  .  j av  a  2  s  .  c  o  m*/
public static final Session restoreSession(final Context context, final TokenCachingStrategy cachingStrategy,
        final StatusCallback callback, final Bundle bundle) {

    if (bundle == null) {
        return null;
    }
    final byte[] data = bundle.getByteArray(SESSION_BUNDLE_SAVE_KEY);
    if (data != null) {
        final ByteArrayInputStream is = new ByteArrayInputStream(data);
        try {
            final Session session = (Session) (new ObjectInputStream(is)).readObject();
            initializeStaticContext(context);
            if (cachingStrategy != null) {
                session.tokenCachingStrategy = cachingStrategy;
            } else {
                session.tokenCachingStrategy = new SharedPreferencesTokenCachingStrategy(context);
            }
            if (callback != null) {
                session.addCallback(callback);
            }
            session.authorizationBundle = bundle.getBundle(AUTH_BUNDLE_SAVE_KEY);
            return session;
        } catch (final ClassNotFoundException e) {
            Log.w(TAG, "Unable to restore session", e);
        } catch (final IOException e) {
            Log.w(TAG, "Unable to restore session.", e);
        }
    }
    return null;
}

From source file:com.mbientlab.metawear.app.ModuleActivity.java

@SuppressWarnings("unchecked")
@Override//ww  w .  ja v a 2s.  co  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (!bluetoothManager.getAdapter().isEnabled()) {
        final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    }

    getApplicationContext().bindService(new Intent(this, MetaWearBleService.class), this,
            Context.BIND_AUTO_CREATE);

    if (savedInstanceState != null) {
        device = (BluetoothDevice) savedInstanceState.getParcelable(EXTRA_BLE_DEVICE);
        moduleFragment = (ModuleFragment) getSupportFragmentManager().getFragment(savedInstanceState,
                "mContent");

        tapType = savedInstanceState.getInt(Extra.TAP_TYPE);
        tapAxis = savedInstanceState.getInt(Extra.TAP_AXIS);
        shakeAxis = savedInstanceState.getInt(Extra.SHAKE_AXIS);
        dataRange = savedInstanceState.getInt(Extra.DATA_RANGE);
        samplingRate = savedInstanceState.getInt(Extra.SAMPLING_RATE);
        ffMovement = savedInstanceState.getBoolean(Extra.FF_MOVEMENT);
        newFirmware = savedInstanceState.getBoolean(Extra.NEW_FIRMWARE);
        samplingConfigBytes = savedInstanceState.getByteArray(Extra.SAMPLING_CONFIG_BYTES);
        polledData = (ArrayList<byte[]>) savedInstanceState.getSerializable(Extra.POLLED_DATA);
    }
}

From source file:com.shurik.droidzebra.DroidZebra.java

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

    setContentView(R.layout.spash_layout);

    // start your engines
    mDroidZebraHandler = new DroidZebraHandler();
    mZebraThread = new ZebraEngine(this, mDroidZebraHandler);

    // preferences
    mSettings = getSharedPreferences(SHARED_PREFS_NAME, 0);
    mSettings.registerOnSharedPreferenceChangeListener(this);

    if (savedInstanceState != null && savedInstanceState.containsKey("moves_played_count")) {
        mZebraThread.setInitialGameState(savedInstanceState.getInt("moves_played_count"),
                savedInstanceState.getByteArray("moves_played"));
    }
    /*else {
       //byte[] init = {56,66,65,46,35,64,47,34,33,36,57,24,43,25,37,23,63,26,16,15,14,13,12,53, 52, 62, 75, 41, 42, 74, 51, 31, 32, 61, 83, 84, 73, 82, 17, 21, 72, 68, 58, 85, 76, 67, 86, 87, 78, 38, 48, 88, 27, 77 };
       byte[] init = {
       65 , 46 , 35 , 64 , 53 , 36 , 56 , 24 , 27 , 34 , 26 , 43 , 33 , 25 , 47 , 18 ,
       15 , 14 , 37 , 16 , 17 , 62 , 23 , 52 , 13 , 66 , 74 , 12 , 63 , 42 , 32 , 41 ,
       31 , 51 , 22 , 21 , 72 , 11 , 67 , 28 , 38 , 58 , 48 , 61 , 68 , 57 , -1 , 71 ,
       -1 , 81 , 82 , 78 , -1 , 77 , -1 , 83 , 84 , 73 , 75 , 86 , 76 , 87 
       };
       mZebraThread.setInitialGameState(init.length, init);
    }*/

    mZebraThread.start();

    newCompletionPort(ZebraEngine.ES_READY2PLAY, new Runnable() {
        @Override
        public void run() {
            DroidZebra.this.setContentView(R.layout.board_layout);
            DroidZebra.this.mBoardView = (BoardView) DroidZebra.this.findViewById(R.id.board);
            DroidZebra.this.mStatusView = (StatusView) DroidZebra.this.findViewById(R.id.status_panel);
            DroidZebra.this.mBoardView.setDroidZebra(DroidZebra.this);
            DroidZebra.this.mBoardView.requestFocus();
            DroidZebra.this.initBoard();
            DroidZebra.this.loadSettings();
            DroidZebra.this.mZebraThread.setEngineState(ZebraEngine.ES_PLAY);
            DroidZebra.this.mIsInitCompleted = true;
        }
    });
}

From source file:com.wareninja.opensource.common.wsrequest.WebServiceNew.java

public String webPost(String methodName, Bundle params) throws MalformedURLException, IOException {

    // random string as boundary for multi-part http post
    String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
    String endLine = "\r\n";
    OutputStream os;//from w  ww. j a  v  a2 s  .c  o m

    ret = null;

    String postUrl = webServiceUrl + methodName;

    if (LOGGING.DEBUG) {
        Log.d(TAG, "POST URL: " + postUrl);
    }
    HttpURLConnection conn = (HttpURLConnection) new URL(postUrl).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " WareNinjaAndroidSDK");
    HttpParams httpParams = httpClient.getParams();
    HttpProtocolParams.setUseExpectContinue(httpParams, false);

    Bundle dataparams = new Bundle();
    for (String key : params.keySet()) {

        byte[] byteArr = null;
        try {
            byteArr = (byte[]) params.get(key);
        } catch (Exception ex1) {
        }
        if (byteArr != null)
            dataparams.putByteArray(key, byteArr);
    }

    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary);
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setRequestProperty("Connection", "Keep-Alive");
    appendRequestHeaders(conn, headers);
    conn.connect();
    os = new BufferedOutputStream(conn.getOutputStream());

    os.write(("--" + strBoundary + endLine).getBytes());
    os.write((WareNinjaUtils.encodePostBody(params, strBoundary)).getBytes());
    os.write((endLine + "--" + strBoundary + endLine).getBytes());

    if (!dataparams.isEmpty()) {

        for (String key : dataparams.keySet()) {
            os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes());
            os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
            os.write(dataparams.getByteArray(key));
            os.write((endLine + "--" + strBoundary + endLine).getBytes());

        }
    }
    os.flush();

    String response = "";
    try {
        response = WareNinjaUtils.read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = WareNinjaUtils.read(conn.getErrorStream());
    }
    if (LOGGING.DEBUG)
        Log.d(TAG, "POST response: " + response);

    return response;
}

From source file:com.shurik.droidzebra.ZebraActivity.java

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

    CommonUtils.updateLanguageLocal(this);

    setContentView(R.layout.spash_layout);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        new ActionBarHelper().hide();
    }

    // start your engines
    mDroidZebraHandler = new DroidZebraHandler();
    mZebraThread = new ZebraEngine(this, mDroidZebraHandler);

    // preferences
    mSettings = getSharedPreferences(Constants.SHARED_PREFS_NAME, 0);
    mSettings.registerOnSharedPreferenceChangeListener(this);

    if (savedInstanceState != null && savedInstanceState.containsKey("moves_played_count")) {
        mZebraThread.setInitialGameState(savedInstanceState.getInt("moves_played_count"),
                savedInstanceState.getByteArray("moves_played"));
    }
    /*else {
    //byte[] init = {56,66,65,46,35,64,47,34,33,36,57,24,43,25,37,23,63,26,16,15,14,13,12,53, 52, 62, 75, 41, 42, 74, 51, 31, 32, 61, 83, 84, 73, 82, 17, 21, 72, 68, 58, 85, 76, 67, 86, 87, 78, 38, 48, 88, 27, 77 };
     byte[] init = {
       65 , 46 , 35 , 64 , 53 , 36 , 56 , 24 , 27 , 34 , 26 , 43 , 33 , 25 , 47 , 18 ,
       15 , 14 , 37 , 16 , 17 , 62 , 23 , 52 , 13 , 66 , 74 , 12 , 63 , 42 , 32 , 41 ,
       31 , 51 , 22 , 21 , 72 , 11 , 67 , 28 , 38 , 58 , 48 , 61 , 68 , 57 , -1 , 71 ,
       -1 , 81 , 82 , 78 , -1 , 77 , -1 , 83 , 84 , 73 , 75 , 86 , 76 , 87
     };
     mZebraThread.setInitialGameState(init.length, init);
    }*/

    mZebraThread.start();

    newCompletionPort(ZebraEngine.ES_READY2PLAY, new Runnable() {
        @Override
        public void run() {
            ZebraActivity.this.setContentView(R.layout.board_layout);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                new ActionBarHelper().show();
            }
            ZebraActivity.this.mBoardView = (BoardView) ZebraActivity.this.findViewById(R.id.board);
            ZebraActivity.this.mStatusView = (StatusView) ZebraActivity.this.findViewById(R.id.status_panel);
            ZebraActivity.this.mBoardView.setDroidZebra(ZebraActivity.this);
            ZebraActivity.this.mBoardView.requestFocus();
            ZebraActivity.this.initBoard();
            ZebraActivity.this.loadSettings();
            ZebraActivity.this.mZebraThread.setEngineState(ZebraEngine.ES_PLAY);
            ZebraActivity.this.mIsInitCompleted = true;
        }
    });
}